Search code examples
linuxarmembeddedyoctobitbake

Yocto Dunfell how to set Compiler Flags to '-Os' Globally


I have a working Linux system image being produced for my ARM board with Yocto ( Dunfell branch ).

Space occupied by the rootfs is a premium and I am working on shrinking the image.

I want to experiment with the GCC '-Os' flag, to optimize for space. I would like to set this globally for my experiment. I found the following information in a presentation ( https://pretalx.com/yocto-project-summit-2020/talk/AY37HF/ ):

enter image description here

I added the following to my image_0.1.bb file. However, I do not see the '-Os' optimization flag being used in any package.

# Disabled until the option works properly -feliminate-dwarf2-dups
FULL_OPTIMIZATION = "-Os -pipe ${DEBUG_FLAGS}"
DEBUG_OPTIMIZATION = "-Og ${DEBUG_FLAGS} -pipe"
SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"

Is the code correct and, if so, where should I put this code? If not correct, how can I globally add the '-Os' compiler optimization flag to my project?


Solution

  • Global options must be added to one of the global configuration files.
    For testing things this would typically be conf/local.conf. You only need to add the variables you actually change as bitbake uses lazy evaluation of variables values.

    Variables in recipe files only affect the tasks for that recipe. This means that nothing you do in the image recipe can affect how tasks in other recipes are done.