Order of variables in specific sections when enabling optimization in gcc
Freddie Chopin
freddie_chopin@op.pl
Thu Mar 7 12:17:00 GMT 2019
Hello Segher!
On Thu, 2019-03-07 at 06:08 -0600, Segher Boessenkool wrote:
> You probably should use a linker script for this.
You think of anything better than placing each variable in its own
section and placing them manually in the linker script in the order I
like? I would like to avoid any messing with linker script if that's
possible... If there's nothing better I may end up using suffixes
("section.1", "section.2", "section.3", ...) and sort the sections in
the linker script (`*(SORT(.section.*));`), but I would still prefer to
solve that in the source file only.
> The compiler can optimise away (some of) those variables even, or not
> always keep them in memory, etc., unless you use volatile on the
> vars.
No worries, it won't optimize them away, there's also a header where
these variables are declared with `extern ...` (omitted that in the
example, as this doesn't change anything) and all of them will be used
in the project. I'm just concerned about their order.
Regards,
FCh
More information about the Gcc-help
mailing list