This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Zephyr compiled with debug data, despite setting CONFIG_OPTIMIZE_SPEED=y

Hi

I'm trying to create a release build but I have the problem that I can't seem to get zephyr to build without debug data included. I would really appriciate some help with this as I can't seem to figure it out.

I'm sure there must be some config option I'm setting wrong somewhere that is causing them to be included, but I can't figure which...

I have tried setting the compile flags explicitly in CMakeList.txt, but that just caused them to be prepended to the C_FLAGS variable below.

I've set the following config options explicitly:

CONFIG_SPEED_OPTIMIZATIONS=y
CONFIG_COMPILER_OPT="-Wall"


From what I can tell all other relevant options are 'n' selected by default, e.g CONFIG_DEBUG

Despite this the '-g' flag is included when compiling, causing our image size to be too large.
E.g
from ./build_output/zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/flags.make

C_FLAGS =   -O2 -imacros [censored]/build_output/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mcpu=cortex-m4 -mthumb -mabi=aapcs -imacros /home/wj/.local/opt/ncs/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/lll/sigma/projects/holmbergs/git/buckle=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/lll/.local/opt/ncs/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/lll/.local/opt/ncs=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc

Parents
  • Hi,

     

    Despite this the '-g' flag is included when compiling, causing our image size to be too large.

    -g emits debug info, it will not make your binary grow, but it will provide you with symbol information so that you can successfully debug your project.

     

    I have tried setting the compile flags explicitly in CMakeList.txt, but that just caused them to be prepended to the C_FLAGS variable below.

    I've set the following config options explicitly:

    CONFIG_SPEED_OPTIMIZATIONS=y
    CONFIG_COMPILER_OPT="-Wall"


    From what I can tell all other relevant options are 'n' selected by default, e.g CONFIG_DEBUG

    Try disabling CONFIG_LOG, CONFIG_CONSOLE, and serial/rtt backend.

     

    Kind regards,

    Håkon

  • Hi

    Thanks for helping me.

    I originally thought that debug data was stored in a file separate from the hex file, but looking at the map file lead me to believe that it was actually stored in flash.

    Is that incorrect? See the screenshot below from a program called amap, looking at the zephyr.map file.

    I have tried disabling CONFIG_LOG, CONFIG_CONSOLE and RTT, but even with that the usage appears to be ~200kiB
    124kB of that appears to be the softdevice, which I think is to be expected. But 80kiB for zephyr et. al feels excessive. But maybe that is a normal amount?



  • Hi,

     

    Poorp said:
    I originally thought that debug data was stored in a file separate from the hex file, but looking at the map file lead me to believe that it was actually stored in flash.

    They are generated and stored in objects, but removed by your linker from the created binary.

    You can manually compile "hello_world" and check the .map file. The binary is ~16k, while the .debug_info section is approx ~360kB.

    Poorp said:
    I have tried disabling CONFIG_LOG, CONFIG_CONSOLE and RTT, but even with that the usage appears to be ~200kiB
    124kB of that appears to be the softdevice, which I think is to be expected. But 80kiB for zephyr et. al feels excessive. But maybe that is a normal amount?

    If size is something that you need to consider, you should consider to use the size optimization as an overall option. If you have specific functions that you need to run faster, then you should wrap these functions/files with the #pragma modifier in gcc to change the optimization level on specific scopes:

    https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Poorp said:
    I originally thought that debug data was stored in a file separate from the hex file, but looking at the map file lead me to believe that it was actually stored in flash.

    They are generated and stored in objects, but removed by your linker from the created binary.

    You can manually compile "hello_world" and check the .map file. The binary is ~16k, while the .debug_info section is approx ~360kB.

    Poorp said:
    I have tried disabling CONFIG_LOG, CONFIG_CONSOLE and RTT, but even with that the usage appears to be ~200kiB
    124kB of that appears to be the softdevice, which I think is to be expected. But 80kiB for zephyr et. al feels excessive. But maybe that is a normal amount?

    If size is something that you need to consider, you should consider to use the size optimization as an overall option. If you have specific functions that you need to run faster, then you should wrap these functions/files with the #pragma modifier in gcc to change the optimization level on specific scopes:

    https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

     

    Kind regards,

    Håkon

Children
No Data
Related