6.6.6.6.8 -ffunction-sections
Place each function into its own section in the output file. The name of the function determines the section’s name in the output file.
However, there are many conditions that can effect what exactly this means. Here is a summary:
- Normal (non interrupt) functions will have the current section name
and a "." prepended to them, for example:
void foo() {}will be placed into section
.text.foo(the default code section name is.text). - The default section name can be modified with the
-mtextoption. If this option has been used, then current section name will be changed. For example, if-mtext=mytextis specified, then the above function will be placed intomytext.foo. - If the function has a section attribute, then it will be placed
into that named section without any adulteration. Therefore,
void __attribute__((section("mytext"))) foo() {}will always be placed into the section
mytextregardless of whether or not-ffunction-sectionsis specified. - Interrupt functions are normally placed into a special section with
the name
.isrprepended to the normal section name (as above). Therefore if the current section name is.text(the default), then the ISR is placed into.isr.text.function_name.If the
-mtextis used to change the name of the default section name, then this will be substituted instead of.text. However, if a named section is used with a section attribute,.isrwill still be prepended to the section name.The
.isris prepended to allow the--gc-sectionsoption to not throw away interrupt functions. These must be kept.
Only use this option when there are significant benefits for doing so. When you specify this option, the assembler and linker may create larger object and executable files and will also be slower.
