In order to decrease the program's I want to use the linker flag -ffunction-sections, besides -gc-sections. Without -ffunction-sections flag the size of a binary output for freertos_blinky demo for the lpc11u68 is 18KB! It seems all functions are been included from the chip library even when they are not used. However I cannot use -ffunction-sections flag because a linker error:
/usr/local/mcuxpressoide-10.0.0_344/ide/tools/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: -f may not be used without -shared
From the command line the linker instruction seems to be:
make -r -j2 all
Building target: freertos_blinky.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/lpc_chip_11u6x/Debug" -L"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/lpc_board_nxp_lpcxpresso_11u68/Debug" -Xlinker -Map="freertos_blinky.map" -Xlinker --gc-sections -Xlinker --allow-multiple-definition -flto -Os -mcpu=cortex-m0plus.small-multiply -mthumb -T "freertos_blinky_Debug.ld" -o "freertos_blinky.axf" ./freertos/src/FreeRTOSCommonHooks.o ./freertos/src/heap_3.o ./freertos/src/list.o ./freertos/src/port.o ./freertos/src/queue.o ./freertos/src/tasks.o ./example/src/aeabi_romdiv_patch.o ./example/src/cr_startup_lpc11u6x.o ./example/src/crp.o ./example/src/freertos_blinky.o ./example/src/mtb.o ./example/src/sysinit.o -llpc_board_nxp_lpcxpresso_11u68 -llpc_chip_11u6x
Finished building target: freertos_blinky.axf
make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "freertos_blinky.axf"; # arm-none-eabi-objcopy -O binary "freertos_blinky.axf" "freertos_blinky.bin" ; checksum -p LPC11U68 -d "freertos_blinky.bin";
text data bss dec hex filename
18060 8 1072 19140 4ac4 freertos_blinky.axf
If I turn on the shared flags other problems shows up. And optimizing for size only saves 3KB, from 18KB to 15KB. Any ideas?
Thank you!
FYI : The sections being removed from your image by the combined use of the compiler -ffunction-sections / -fdata-sections and linker --gc-sections options can be seen from the map file generated by the link step. Look for the section of the map file starting : "Discarded input sections".
For more details, see section 12.5.3, "Linker Map files" of the MCUXpresso IDE v10.0.0 User Guide.
Regards,
MCUXpresso IDE Support
Hi Javier,
Can you provide the compiler options you use to compile your source files. To have the linker removing code and data sections, the files need to be compiled with the 'sections' option. I use it for both functions and data, so make sure your source files are compiled with
-ffunction-sections -fdata-sections
Example command line on my side:
arm-none-eabi-gcc -DDEBUG -D__CODE_RED -DCORE_M0PLUS -D__MTB_BUFFER_SIZE=256 -D__USE_ROMDIVIDE -D__USE_LPCOPEN -DNO_BOARD_LIB -D__LPC82X__ -D__REDLIB__ -I"C:\Users\Erich Styger\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC800-DIP\lpc_chip_82x\inc" -O3 -fno-common -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -D__REDLIB__ -specs=redlib.specs -MMD -MP -MF"src/sysinit.d" -MT"src/sysinit.o" -MT"src/sysinit.d" -o "src/sysinit.o" "../src/sysinit.c"
Finished building: ../src/aeabi_romdiv_patch.s
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"C:\Users\Erich Styger\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC800-DIP\lpc_chip_82x\Debug" -Xlinker -Map="LPC800-DIP_Blinky.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m0 -mthumb -T "LPC800-DIP_Blinky_Debug.ld" -o "LPC800-DIP_Blinky.axf" ./src/LPC800-DIP_Blinky.o ./src/aeabi_romdiv_patch.o ./src/cr_startup_lpc82x.o ./src/crp.o ./src/mtb.o ./src/sysinit.o -llpc_chip_82x
I hope this helps,
Erich
Hi Erich,
Thanks for your promp reply. The options you've recommended are already set, as shown:
It seems I've been making things in the correct way, and probably those 15KB are the correct size for such a project. Turning on size optimizations I'm getting 9KB. The compiler instruction is:
Building file: ../example/src/freertos_blinky.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -std=c99 -DDEBUG -D__CODE_RED -D__USE_LPCOPEN -D__MTB_BUFFER_SIZE=256 -DCORE_M0PLUS -D__USE_ROMDIVIDE -D__NEWLIB__ -I"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/lpc_chip_11u6x/inc" -I"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/lpc_board_nxp_lpcxpresso_11u68/inc" -I"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/freertos_blinky/example/inc" -I"/home/fjrg76/Documents/MCUXpresso_10.0.0_344/workspace3/freertos_blinky/freertos/inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -v -flto -ffat-lto-objects -mcpu=cortex-m0 -mthumb -D__NEWLIB__ -MMD -MP -MF"example/src/freertos_blinky.d" -MT"example/src/freertos_blinky.d" -o "example/src/freertos_blinky.o" "../example/src/freertos_blinky.c"
In other post I stablished that a bundle is broken, so I've updated it including the latest FreeRTOS release. With a minimal configuration and size optimizations for the libraries used I got 7KB, which I consider is a reasonable size for a project that includes 3 libraries: for the chip, for the board, and for the RTOS. You can find it here.
Anyway, now I know that code that is not used is really discarded, which was my concern in first place.
Kind regards!