OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:35 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ld: giving section a load address?
PostPosted: Fri Sep 25, 2015 4:22 pm 
Offline

Joined: Fri Jun 13, 2014 12:55 pm
Posts: 10
What's wrong with my loader script?
(there's more, but this should give the idea...)
Code:
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:
/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).


Top
 Profile  
 
 Post subject: Re: ld: giving section a load address?
PostPosted: Fri Sep 25, 2015 10:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 06, 2010 7:07 pm
Posts: 792
You can put "AT(load_address)" after the : in a section, like this:
Code:
.text link_address : AT(load_address) { *(.text) }

_________________
[www.abubalay.com]


Top
 Profile  
 
 Post subject: Re: ld: giving section a load address?
PostPosted: Sat Sep 26, 2015 1:21 am 
Offline

Joined: Fri Jun 13, 2014 12:55 pm
Posts: 10
Thanks, it works.
And this works too:
Code:
   .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.


Top
 Profile  
 
 Post subject: Re: ld: giving section a load address?
PostPosted: Sat Sep 26, 2015 2:59 am 
Offline

Joined: Fri Jun 13, 2014 12:55 pm
Posts: 10
Aahh, it DOES work with ">EXEC AT>LOAD". =D>
It just couldn't take another 'location specifier': ALIGN(0x1000).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group