section placement - grouping __attribute__((section (“NAME”))) statements

Segher Boessenkool segher@kernel.crashing.org
Fri Aug 20 21:02:29 GMT 2021


On Fri, Aug 20, 2021 at 08:55:54PM +0200, David Brown wrote:
> On 20/08/2021 10:22, Werthmann Luca via Gcc-help wrote:
> > I am writing to ask if there is a chance with the GNU GCC Compiler to group __attribute__((section (“NAME”))) statements.
> > 
> > IAR Supports for example the following commands:
> > 
> > # pragma default_function_attributes = @ ".MY_FUNC"                 /* start placing following functions in section .MY_FUNC */
> > # pragma default_function_attributes =                                              /* stop placing functions in section*/
> > 
> > # pragma default_variable_attributes = @ ".MY_DATA"                  /* start placing following variables in section .MY_DATA */
> > # pragma default_variable_attributes =                                               /* stop placing functions in section*/

>  To the best of my knowledge, there is no way to do this in gcc - you
> have to put the section attribute on each function.  (You can use a
> macro to reduce the typing!)

There are no such pragmas, correct.  And macros+attributes (as you
suggest) is a more flexible solution.  Is there some use case that would
make such pragmas super useful, overcoming all the obvious usability
downsides of it?

> If you are versed in linker files, it is possible to have a modified
> linker setup to put the code or data from a specific file into
> non-standard output sections.

Or you can play games with objcopy.

> I too would like to see this as a feature in gcc - it is one of the few
> features that are common to most embedded compilers but missing from gcc.

Do -ffunction-sections / -fdata-sections help your use case?


Segher


More information about the Gcc-help mailing list