This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

application binary size significantly bigger when using GNU Toolchain

Hi,

I've recently moved my development environment from Windows + Keil uVision to Linux + ARM GNU Toolchain. I'm able to build and flash the application firmware, but I notice that the size of final binary is significantly bigger with Linux + ARM GNU Toolchain.

  • size of final binary file on Windows+KEIL: ~32kB
  • size of final binary file on Linux + ARM GNU Toolchain: ~44kB

I'm using one math routine (floor) at few places and hence linking math library(libm). The size gets reduced by 4k if I remove floor() invocation in my firmware and do not link libm. However, I still need such math libraries, hence removing them is not an option.

# Libraries to link
LIBRARIES := -lm

## Link C and assembler objects to an .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(C_OBJECTS) $(ASSEMBLER_OBJECTS) $(LIBRARIES)
  $(CC) $(LDFLAGS) $(C_OBJECTS) $(ASSEMBLER_OBJECTS) $(LIBRARIES) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out

I'm guessing that I might be missing some compiler or linker flags and/or path. They are as follows:

INCLUDE_PATHS: [-I../../sdk_v6_1/nrf51822/Include -I../../sdk_v6_1/nrf51822/Include/s110 -I../../sdk_v6_1/nrf51822/Include/ble -I../../sdk_v6_1/nrf51822/Include/ble/ble_services -I../../sdk_v6_1/nrf51822/Include/app_common -I../../sdk_v6_1/nrf51822/Include/sd_common -I../../sdk_v6_1/nrf51822/Include/sdk -I../../sdk_v6_1/nrf51822/Include/bootloader_dfu -I../../sdk_v6_1/nrf51822/../../custom_sdk -I../../sdk_v6_1/nrf51822/../../ARM/CMSIS/Include -I../../sdk_v6_1/nrf51822/Device/ARM/ARMCM0/Include -I../../tools/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/include -I../ -I../../sdk_v6_1/nrf51822/Include/gcc]

LDFLAGS: [-Wl,--gc-sections -flto -L../../tools/gcc-arm-none-eabi-4_9-2015q2/arm-none-eabi/lib/armv6-m -L../../tools/gcc-arm-none-eabi-4_9-2015q2/lib/gcc/arm-none-eabi/4.9.3/armv6-m -Xlinker -Map=_build/testing_s110_xxaa.map -mcpu=cortex-m0 -mthumb -mabi=aapcs -L../../sdk_v6_1/nrf51822/Source/templates/gcc/ -Tgcc_nrf51_s110_xxaa.ld --specs=nano.specs -lc -lnosys]

CFLAGS: [-DDEBUG_NRF_USER -DBLE_STACK_SUPPORT_REQD -DSPI_MASTER_0_ENABLE -DNRF51 -DTOOLCHAIN_GCC_ARM -fno-strict-aliasing -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -mabi=aapcs -DNRF51 -DBOARD_NRF6310 -DNRF51822_QFAA_CA --std=gnu99 -Wall -o0 -fno-common -fmessage-length=0 -mfloat-abi=soft -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer --specs=nano.specs ]

Some information about the environment:

  1. ARM Toolchain: gcc-arm-none-eabi-4_9-2015q2
  2. Target: nrf51822QF_AA (256kB flash memory)
  3. Nordic SDK: v6.1.0

Note: I'm not using Eclipse or any IDE, just plain GNU tools(make, cscope, vim etc).

Thank you for your help.

  • Try adding -Os to your CFLAGS to optimize for size. The unoptimized code from GCC is pretty bad.

  • Thank you for your suggestion, however, optimizing for size with -Os had no effect in my case :(

    $ make echostuff|grep CFLAGS
    CFLAGS: [-DDEBUG_NRF_USER -DBLE_STACK_SUPPORT_REQD -DSPI_MASTER_0_ENABLE -DNRF51 -DTOOLCHAIN_GCC_ARM -fno-strict-aliasing -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -mabi=aapcs -DNRF51 -DBOARD_NRF6310 -DNRF51822_QFAA_CA --std=gnu99 -Wall -fno-common -fmessage-length=0 -Os -mfloat-abi=soft -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer --specs=nano.specs ]
    
  • After a clean build?

    Then the best I could suggest is to look for the source of the bloat. arm-none-eabi-size and arm-none-eabi-nm be your friends. Not sure about Keil counterparts.

    nenik@localhost ~/radio $ arm-none-eabi-size bin/debug/prox_s110_xxaa.out    
       text    data     bss     dec     hex filename
      20276    1116    3456   24848    6110 bin/debug/prox_s110_xxaa.out
    nenik@localhost ~/radio $ arm-none-eabi-nm -S --size bin/debug/prox_s110_xxaa.out     
    [...]
    00016530 00000274 T ble_bondmngr_init
    00017b7c 000002ac T main
    20002790 000002bc b m_centrals_db
    00014e5a 000002da t adv_data_encode
    20002e9c 00000320 b APP_TIMER_BUF.8254
    000147bc 00000340 T SWI0_IRQHandler
    00015ea4 000003a0 T ble_bondmngr_on_ble_evt
    20002020 00000428 d impure_data
    00018a0c 000004fb T font
    200031e0 00000800 N __HeapBase
    

    ('t' or 'T' is where the code is)

Related