Re: Array size depending on symbol address



Skarmander <invalid@xxxxxxxxxxxxxx> wrote:
> usenet@xxxxxxx wrote:
>> Hello,
>>
>> I am running my code on an embedded platform without OS. I have defined some
>> data in a section called .eeprom. The section is defined by the linker
>> script and starts at address zero. The symbol __eeprom_end is defined by the
>> linker script as well, and lies at the end of this section. The address of
>> __eeprom_end is thus equal to the number of bytes in the .eeprom section.
>>
>> My problem : I want to declare an array in .bss with the same size of this
>> section. My naive approch was :
>>
>> extern void *_eeprom;
>> char eeprom_shadow[(int)&_eeprom_end];
>>
>> This fails miserably, ofcourse : the compiler doesn't know the address of
>> __eeprom before the linker is done, so it can not declare the array.
>>
>> Is there a trick to allocate the memory for this array at compile time ?
>
> Your identifiers are all over each other. Is _eeprom the address of the
> section .eeprom? Is _eeprom_end a typo or intended to be the same as
> __eeprom_end? What is __eeprom with two underscores?

Yes, definitely all over eachother, very confusing, I'm sorry. It should
read '__eeprom_end' everywhere.

> Any reason why you can't have the linker declare a section .eeprom_shadow of
> equal size and use the address of that? Indexing would work the same; the
> only restriction is that you still don't know the size at compile time, but
> that shouldn't be too much of a problem, since you'd have __eeprom_end (or
> _eeprom_end) available at runtime.

Yes, having the linker create another section should work ofcourse, thanks
for the hint,

--
:wq
^X^Cy^K^X^C^C^C^C
.



Relevant Pages

  • Re: Array size depending on symbol address
    ... data in a section called .eeprom. ... linker script as well, and lies at the end of this section. ... Is there a trick to allocate the memory for this array at compile time? ...
    (comp.lang.c)
  • Re: IAR linker: too smart
    ... device uses a lot of configuration data which are stored within an eeprom. ... I tell the linker to place the E2PROM_DATA segment where the eeprom is ... could initialize the variables in eeprom.c and have a better chance that the ...
    (comp.arch.embedded)
  • help with scatter linking and ARM RVCT tools
    ... i'm having some difficulty with the ARM scatter linker and i could ... the linker build is 558. ... use *.o* in multiple sections. ... so the size of the object files at compile time ...
    (comp.arch.embedded)