This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Variable order and location within the section - optimization level dependent
- From: Ian Lance Taylor <iant at google dot com>
- To: Janáček Jiří <jiri dot janacek at skoda dot cz>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 16 Oct 2013 06:55:46 -0700
- Subject: Re: Variable order and location within the section - optimization level dependent
- Authentication-results: sourceware.org; auth=none
- References: <65513286F68AA34992CFC96B7C77DF397697A7FF at srv-exch-mbx2 dot skoda dot cz>
On Wed, Oct 16, 2013 at 4:25 AM, JanÃÄek JiÅÃ <jiri.janacek@skoda.cz> wrote:
>
> We have discussed the topic regarding the compiler flag -fno-toplevel-reorder and relative stuff at the GCC ARM forum (https://answers.launchpad.net/gcc-arm-embedded/+question/237324).
>
> GCC documentation (http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options) states:
>
> "Do not reorder top-level functions, variables, and asm statements. Output them in the same order that they appear in the input file. When this option is used, unreferenced static variables are not removed. This option is intended to support existing code that relies on a particular ordering. For new code, it is better to use attributes."
>
>
> The major question sounds - which attributes should be applied in such a case?
Well, what are you trying to do?
There are various different things that people used to do based on
specific ordering in the source file. One common use was to force
functions into particular sections by writing code like
asm (".section mysec");
int f() { return 0; }
asm (".text");
The way to do that without relying on -fno-toplevel-reorder is to use
an attribute for the function.
int f() __attribute__ ((section ("mysec")));
int f() { return 0; }
Ian