avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Order of variables placed in .data and .bss sections


From: Raj Sharma
Subject: Re: [avr-gcc-list] Order of variables placed in .data and .bss sections
Date: Tue, 20 May 2008 11:50:50 -0700 (PDT)

Dear Preston,

Thanks for the suggestion. But I want the solution to work for program of any size, any number of global variables.

Raj

----- Original Message ----
From: Preston Wilson <address@hidden>
To: avr-gcc-list <address@hidden>
Sent: Tuesday, May 20, 2008 1:36:41 PM
Subject: Re: [avr-gcc-list] Order of variables placed in .data and .bss sections

"Weddington, Eric" wrote:
>
>> -----Original Message-----
>> From:
>> avr-gcc-list-bounces+eweddington=address@hidden
>> [mailto:address@hidden
>> org] On Behalf Of Raj Sharma
>>
>> Dear all,
>>
>> Is there a way to force some order in the way variables
>> (global/static) are placed in .data and .bss sections ? For
>> example, let my program has 2 initialized global variables g1
>> and g2 and 5 uninitialized global variables u1,u2,u3,u4 and
>> u5. g1 and g2 are first placed in program memory after .text
>> section and __do_copy_data copies them to the starting
>> address in SRAM. u1 through u5 are not explictitly stored in
>> program memory but __do_copy_bss places them just after g1
>> and g2 in SRAM and zeroes them out. I want to know if I can
>> somehow specify the order of these variables, say  g1
>> followed by g2; then u3,u4,u5,u1,u2.
>>
>> I noticed that the order in which the variables are
>> declared/defined in C file or assembly file does not
>> correspond to the way they are placed in SRAM.
>>
>> Thanks in advance,
>> Raj
>
> Hello Raj,
>
> In theory it can be done, but you will have to use -fdata-sections, and
> a customized linker script. You may also have to either, customize the
> startup code in avr-libc, or have some custom code right after startup
> that takes care of the .data initialization and .bss clearing yourself.
>
> Why do you need to do this anyway?
>

If all you really need is the variables in order, they are few in number,
and you do not care where they otherwise end up in memory, you can put them
in a globally defined structure.

E.g.

struct ctrlblk {
  uint8_t g1;
  uint8_t g2;
  uint8_t u3;
  uint8_t u4;
  uint8_t u5;
  uint8_t u1;
  uint8_t u2;
} g_cb;

Change types and names as needed and initialize of course.

-Preston




_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]