Page 1 of 1

ld: giving section a load address?

Posted: Fri Sep 25, 2015 4:22 pm
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).

Re: ld: giving section a load address?

Posted: Fri Sep 25, 2015 10:33 pm
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) }

Re: ld: giving section a load address?

Posted: Sat Sep 26, 2015 1:21 am
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.

Re: ld: giving section a load address?

Posted: Sat Sep 26, 2015 2:59 am
by turboscrew
Aahh, it DOES work with ">EXEC AT>LOAD". =D>
It just couldn't take another 'location specifier': ALIGN(0x1000).