RE: Variable order and location within the section - optimization level dependent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Ian,

I do know this approach. I have created sections with the appropriate address ranges and located the variables into those sections by the below mentioned attribute.
If no optimization is turned on, then the order (means also the address offset of the variable) is correct.
If -O1 is turned on, the variables order within the section is exactly opposite.
If -O1 is turned on and the flag -fno-toplevel-reorder is turned on as well, then the order is equal to the requested one. But I would like to apply such a behavior (no reorder) just for some variables in some modules. Other modules should be optimized by -O1 level.
So I am curious which attributes can define this behavior.

Hope this clarifies that a bit.

Thanks,
JiriJ


-----Original Message-----
From: Ian Lance Taylor [mailto:iant@xxxxxxxxxx] 
Sent: Wednesday, October 16, 2013 3:56 PM
To: Janáček Jiří
Cc: gcc-help@xxxxxxxxxxx
Subject: Re: Variable order and location within the section - optimization level dependent

On Wed, Oct 16, 2013 at 4:25 AM, Janáček Jiří <jiri.janacek@xxxxxxxx> 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





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux