ld: giving section a load address?

Programming, for all ages and all languages.
Post Reply
turboscrew
Posts: 10
Joined: Fri Jun 13, 2014 12:55 pm

ld: giving section a load address?

Post by turboscrew »

What's wrong with my loader script?
(there's more, but this should give the idea...)

Code: Select all

ENTRY(_start)

MEMORY
{
	LOAD (rwx) : ORIGIN = 0x00008000, LENGTH = 512k /* initial */
	EXEC (rwx) : ORIGIN = 0x1e000000, LENGTH = 512k /* runtime */
}

SECTIONS
{	
    /* Starts at LOADER_ADDR. */
    . = 0x8000;
    __text_start = .;
    .text :
    {
        *(.init)
        *start1.o(.text)
        *start1.o(.data)
        *start1.o(.bss)
        *(.text.startup)
    } >LOAD
    
    .text2 ALIGN(0x1000):
    {
         __code_begin = .;
        *loader.o(.text)
        *rpi2.o(.text)
        *serial.o(.text)
        *util.o(EXCLUDE_FILE(*instr_util.o).text)
        *gdb.o(.text)
        *(.text)
    } >EXEC AT>LOAD
    __text_end = .;
 

 	__data_start = .;
    .data :
    {
        *(.data)
    } >EXEC AT>LOAD
    __data_end = .;
 
The loader gives me:

Code: Select all

/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0xf8e8 of loader.elf section `.text2' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: loader.elf section `.rodata.str1.4' will not fit in region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0x1d350 of loader.elf section `.bss' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0xf8e8 of loader.elf section `.text2' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0x1d350 of loader.elf section `.bss' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0xf8e8 of loader.elf section `.text2' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: address 0x1d350 of loader.elf section `.bss' is not within region `EXEC'
/home/jaa/RasPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: region `EXEC' overflowed by -503721136 bytes
collect2: error: ld returned 1 exit status
The idea is to link stuff in .text to load and run in 0x8000 ... and .text2 and the rest to run in 0x1e000000... and to load right after the .text. (The code in .text copies the rest to 0x1e000000 on.)

If I direct everything to LOAD and and don't give a separate loading address, the code compiles and runs fine.
Only .init contains assembly code. The rest is C (except some inline asm without any absolute addresses).
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: ld: giving section a load address?

Post by Rusky »

You can put "AT(load_address)" after the : in a section, like this:

Code: Select all

.text link_address : AT(load_address) { *(.text) }
turboscrew
Posts: 10
Joined: Fri Jun 13, 2014 12:55 pm

Re: ld: giving section a load address?

Post by turboscrew »

Thanks, it works.
And this works too:

Code: Select all

   .text2 0x1e000000:
    {
         __code_begin = .;
        *loader.o(.text)
        *rpi2.o(.text)
        *serial.o(.text)
        *util.o(EXCLUDE_FILE(*instr_util.o).text)
        *gdb.o(.text)
        *(.text)
    } AT>LOAD

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         000002f0  00008000  00008000  00008000  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text2        000068f8  1e000000  000082f0  00010000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
I wonder why the ">EXEC AT>LOAD" doesn't work. It would be nicer to just 'catenate' instead of recalculating the addresses each time the output section size changes. I can leave gaps, of course...
In my case the exact locations are not important,just the region is.
turboscrew
Posts: 10
Joined: Fri Jun 13, 2014 12:55 pm

Re: ld: giving section a load address?

Post by turboscrew »

Aahh, it DOES work with ">EXEC AT>LOAD". =D>
It just couldn't take another 'location specifier': ALIGN(0x1000).
Post Reply