I am trying to get a simple embedded PIC32MX "Hello, World!" program to compile without using MPLAB X. For Chip-support, I am using the spicastack/pic32-parts-free library. Which is as far as I can see, just a redistribution of Microchip's XC32 header files.
With the following minimal cmake file I can get the program to compile just fine:
project(pic32example C ASM)
include_directories(pic32-parts-free/include)
add_compile_options(-mips32 -EL -nostdlib -Os -D__PIC32MX__ -D__32MX570F512L__)
set_source_files_properties(pic32-parts-free/proc/32MX570F512L/p32MX570F512L.S PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
add_executable(${PROJECT_NAME}.elf
main.c
pic32-parts-free/proc/32MX570F512L/p32MX570F512L.S
)
main.c :
int main(void) {
/* Very boring program */
}
Calling cmake with cmake -D CMAKE_C_COMPILER=/usr/bin/mipsel-linux-gnu-gcc -D CMAKE_CXX_COMPILER=/usr/bin/mipsel-linux-gnu-g++ ..
compiles the program. However, the size of the resulting elf file is much bigger than I'd expect. Even after I call mipsel-linux-gnu-strip
on it:
$ ls -lah
143K Mar 16 09:19 pic32example.elf # unstripped simple program
84K Mar 16 09:09 pic32example-stripped.elf # stripped simple program
On further inspection it looks like there is a lot of debugging information for dynamically linking glibc (roughly 23KiB of it). and it looks a lot like the rest of the program is just doing nothing. I dont use anything from glibc so I'd like that part to be cut out, but -nostdlib
doesn't seem to affect it.
So my question is: How come the program is so huge in spite of it doing absolutely nothing? And what compiler flags should I use to get it down to a reasonable size? (Other than -Os
and -nostdlib
)
NOTE: If you want to recreate my setup, spicastack/pic32-parts-free does not provide the assembler file that I use, but if you swap it out with
pic32-parts-free/proc/32MX440F256H/p32mx440f256h.S
in the cmake file it should compile. The resulting binary should be about 63KiB before stripping. Still way too big for such a small program.