"AT > region" interpreted as "> region" in linker script

Nick Clifton nickc@redhat.com
Tue Jan 13 10:41:00 GMT 2004


Hi Galit,

> Any news on this ?
>
> http://sources.redhat.com/ml/binutils/2004-01/msg00034.html

Oops  - another one that slipped through, sorry.

> While trying the patch, I noticed a similar problem (not caused by
> the patch).  The problem is similar in the sense that a virtual
> address setting is "not taken into account" with relation to a
> memory region setting:
> 
> The following scenario results in the error message:
> ld-new: section .data [00000010 -> 0000001b] overlaps section .text
> [00000010 -> 000003a7]
> 
> MEMORY {
>         ram         : ORIGIN = 0x10,     LENGTH = 0x1000
> }
> 
> SECTIONS { .text 0x10 :  { *(.text) } 
>            .data      :  { *(.data) } > ram
> }
> 
> I.e. the second output section statement allocates the ram region
> from the beginning, without taking into account that this area had
> already been allocated to another output section.

No, this one is pilot error.  It is the responsiblity of the linker
script author to make sure that overlapping regions are not created.
The linker manual explicitly states:

    The linker will set section addresses based on the
    memory regions, and will warn about regions that
    become too full.  The linker will not shuffle sections
    around to fit into the available regions.

Since the script has not set up the attributes for the "ram" region,
it cannot assign the .text section to it, so it has to put it in an
(internally defined) global memory region which covers the entire
address space.

The best way to fix this problem is either to use explicit memory
regions for all sections, or to define the attributes for enough
regions so that all of the not-explicitly-mapped-to-a-region input
sections will be allocated to linker script defined regions.  ie:

 MEMORY {
         ram      : ORIGIN = 0x10,     LENGTH = 0x1000
         rom      : ORIGIN = 0x1010,   LENGTH = 0x1000
 }
 
 SECTIONS { .text : { *(.text) } > ram
            .data : { *(.data) } > rom
 }

or:

 MEMORY {
         ram (!r) : ORIGIN = 0x10, LENGTH = 0x1000
 }
 
 SECTIONS { .text :  { *(.text) }
            .data :  { *(.data) } > ram
 }

 
Cheers
        Nick
        
    



More information about the Binutils mailing list