This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Controlling the order of variables in the COMMON section


I am having difficulty with GCC for an embedded project on the Cortex-M0, but
this request applies generally to any device.

RAM is at a premium on my microcontroller. I have several global variables.
Some are 32 bit integers, some are 16 bit shorts, and some are 8 bit chars.
Each variable is carefully chosen to be the absolute smallest width it needs
to be to serve my needs.  I need these variables to be output in a specific
order so that crucial RAM bytes are not wasted on alignment. I want the 32
bit integers to be output first, then the 16 bit shorts, and then the 8 bit
bytes. What is happening now is they are being emitted completely at random,
and my BSS section is much larger than it needs to be.

I tried to put them each into a different section, and then order the
sections in the linker file, but found out when I did this that the PROGBITS
attribute is being set on the sections.  This is unacceptable because these
sections need to be NOBITS. I can not find anyway to force the linker to
make these NOBITS. In fact, in the GCC documentation it even says that the
section attribute can only be used on fully initialized variables, which
mine are not.

The only advice I can find on the web is to declare these variables in a
structure. Unfortunately, I can't change the code to access these variables
as a structure. I can only change the header files where the variables are
declared. The variables need to keep exactly the same names they are
currently using.

So how do I group non initialized global variables in GCC so that they come
out in the proper order? 

Thank you for any assistance,

Chris


-- 
View this message in context: http://old.nabble.com/Controlling-the-order-of-variables-in-the-COMMON-section-tp31338065p31338065.html
Sent from the gcc - Help mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]