Help with relocating .data and .bss segments

Gopal Santhanam
Thu Nov 2 11:01:00 GMT 2000


I'm a bit new to using the GCC cross-compilation toolset.  Specifically I
am having trouble when trying to relocate the addressing for the .data
segment during linking.  I first tried sending the options "-Ttext
0x0 -Tdata 0xd1030800" to the linker.

The linker produces the arm-elf executable.  To get this executable to the
target, I found that I should dump the elf file using

> objcopy --output-target=binary program.elf

, generate a hex file, and burn it to my flash rom.  However, when I run
objcopy I get the following problem:

> arm-uclinux-objcopy --output-target=binary main.elf
> BFD: Warning: Writing section `.data' to huge (ie negative) file offset
> 0xd1030800.

Objcopy is confused by the location of the .data segment at 0xd1030800. I
was only looking to relocate the addressing of variables and keep the
binary data for .data immediately following the .text.  This would allow
my loader code to copy .data from the binary image in read-only memory to
a read-write location.  I could then copy word-by-word from __text_end__
(or is it __rodata_end__?) to __data_start__ until the the target pointer
hits the __bss_start__.  Unfortunately, I don't seen any __text_end__ or
__data_start__ link symbols in the armelf.x link script.  How do I use ld
and objcopy to get this type of setup?

This brings me to another confusion.  I've taken a look at a couple crt0.s
files for ARM and I haven't seen any of them copy the .data segment to
read-write memory.  Are these loaders just assuming that the executable is
never in read-only memory?

Ultimately I'm trying to make a scenario analagous to example provided by
the ADS environment.  Here is a snippet of the load code.

>  IMPORT  |Image$$RO$$Limit|      ; End of ROM code (=start of ROM data)
>  IMPORT  |Image$$RW$$Base|       ; Base of RAM to initialise
>  IMPORT  |Image$$ZI$$Base|       ; Base and limit of area
>  IMPORT  |Image$$ZI$$Limit|      ; to zero initialise
>        LDR     r0, =|Image$$RO$$Limit| ; Get pointer to ROM data
>        LDR     r1, =|Image$$RW$$Base|  ; and RAM copy
>        LDR     r3, =|Image$$ZI$$Base|  ; Zero init base to top of initialised data
>        CMP     r0, r1                  ; Check that they are different
>        BEQ     %F1
>0       CMP     r1, r3                  ; Copy init data
>        LDRCC   r2, [r0], #4
>        STRCC   r2, [r1], #4
>        BCC     %B0
>1       LDR     r1, =|Image$$ZI$$Limit| ; Top of zero init segment
>        MOV     r2, #0
>2       CMP     r3, r1                  ; Zero init
>        STRCC   r2, [r3], #4
>        BCC     %B2

And armlink would be called with the options "-ro-base 0x0 -rw-base

Am I approaching this from the wrong angle entirely?  Any help would be

Thanks in advance!
Gopal Santhanam                            

Hartley's Law:
  You can lead a horse to water, but if you can get him to float on his
  back you've got something.

            --->  <---

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

More information about the crossgcc mailing list