5.7.7.20 Function-sections Option

The -ffunction-sections option places each function in its own section to assist with garbage collection and potential code size reductions.

When enabled, this option has each function placed in its own section named after the function. When used in conjunction with garbage collection performed by the linker (enabled using the -Wl,--gc-sections driver option) the final output might be smaller. The -ffunction-sections option can, however, hamper other code generation optimizations, so confirm whether this option is of benefit with each project.

Note also that if functions are removed, their debugging information will remain in the ELF file, potentially imperiling the debuggability of code. When displaying source code information, the debugger looks for associations between addresses and the functions whose code resides at those locations, and it might wrongly consider that an address belongs to a removed function. As removed functions are not allocated memory, their "assigned" address will not change from being 0, thus the debugger is more likely to show references to a removed function when interpreting addresses closer to 0.

The -fno-function-sections form of this option does not force each function into a unique section. This is the default action if no option is specified.