This is the mail archive of the mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.

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

Re: elf rodata / data sections

Mark Pulver wrote:
> I'm working on a arm-elf cross compiler for a Brutus board.
> My latest problem trying to get a stand-alone system going (yet to happen)
> appears to be in a routine to init memory that does the following:
> SAir_InitBSSMemory:
>         STMFD   sp!, {v1-v5, lr}
>         LDR     v1, SA_TopOfROM         @ Copy predefined variables from here..
>         LDR     v2, SA_StartOfBSS       @ here
>         LDR     v3, SA_ZeroBSS          @ 'C' BSS starts here
>         CMP     v1, v2                  @ Make sure there are some..
>         BEQ     8f
> 7:
>         CMP     v2, v3                  @ Check if done..
>         LDRCC   v4, [v1], #4            @ if not, get word and store to RAM
>         STRCC   v4, [v2], #4
>         BCC     7b
> I've managed to the get the linker to set these to:
> SA_TopOfROM: .word      _etext
> SA_StartOfBSS: .word    .data
> SA_ZeroBSS: .word       __bss_start__
> _etext resulted to the start of .rodata section:
> % arm-elf-objdump --header bounce3.elf
> bounce3.elf:     file format elf32-littlearm
> Sections:
> Idx Name          Size      VMA       LMA       File off  Algn
>   0 .text         000049e8  00008000  00008000  00008000  2**2
>   1 .rodata       00000100  0000c9e8  0000c9e8  0000c9e8  2**2
>   2 .data         00000470  0000cbe8  0000cbe8  0000cbe8  2**2
>                   CONTENTS, ALLOC, LOAD, DATA
>   3 .bss          0013cc0c  00010000  00010000  00010000  2**15
>                   ALLOC
> So the above assembler should copy the .rodata section on top
> of the .data section until it rearches the .bss section. (Actually
> to the end of the .data section, __bss_start__ was assigned 0xd058,
> .data + 470)
> The .rodata is only 0x100 in size, and the .data
> is 0x470, so it not big enough to initialize the whole .data area.
> As a result, all the .data section is not inialize correctly.
> What happening here?

I think you have confused things a bit.

What are the sections:
'.text' is code (not modifiable) (this could stay in ROM)
'.rodata' is data that is not modified. (this could stay in ROM)
'.data' is data that could be modified. (this must be placed in RAM)
'.bss' should be zero initialized (and placed in RAM)

First of all, your example is linked for running from RAM.
Ok, now if the above is loaded to the LMA's indicated, the routine above
should be made to zero only the '.bss' section. (everything should run fine
from RAM)

If you want the above to be located in ROM, you will have to write a linker
script to make the VMA's of '.data' '.bss' go into RAM, and everything else
into ROM.  The above code should then be made to copy '.data' from it's LMA
to it's VMA, and zero the '.bss' at it's VMA. 

try: 'info ld' for information on linker scripts

The binary will be linked to _run_ with the sections placed as indicated by
the VMA's, but _load_ as indicated by the LMA's.

Ok, this got a bit confusing.  Hope it helps!

/Daniel Kahlin

Daniel Kahlin <>
Hardware System Designer
Net Insight AB

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

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