linker script

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,

when using linker scripts, how can you check if the various sections
actually fit into the specified memory regions ?

Thanks,

Tom

Re: linker script
Quoted text here. Click to load it

if you are talking about linker scripts under gnu c , then the following
example (of a linker script) should help. The linker will complain f you
exceed the allowable size...

MEMORY {
        ram    : ORIGIN = 0x200000, LENGTH = 0x3000
        rom    : ORIGIN = 0x00000000, LENGTH = 0xf000
}


SECTIONS {
    .text : {
        PROVIDE(_stext = .);
        *(.text)
        . = ALIGN(4);
        PROVIDE(_etext = .);
    } > ram
    .data : {
        PROVIDE(_sdata = .);
        *(.data)
        *(.rodata)
        *(.glue_7*)
        . = ALIGN(4);
        PROVIDE(_edata = .);
    } > ram
    .bss : {
        PROVIDE(_sbss = .);
        *(.bss)
        . += 0x200;
        . = ALIGN(4);
        PROVIDE(_ebss  = .);
    } > ram
    . += 0x1000;
    PROVIDE(_stack =.);
    PROVIDE(_end =.);

}



Re: linker script

Quoted text here. Click to load it

If the question applies to the GNU linker (ld), a more appropriate group
would be gnu.utils.help. The linker is a part of the binutils package.

Normally, GCC uses the GNU assembler (as) and linker (ld) to build the
executable image.

The GNU linker complains if the sections do not fit into the memory regions
specified to them, regardless whether the linker is using the default script
or a custom one. The memory ranges are taken from the active linker script.

HTH

Tauno Voipio
tauno voipio @ iki fi



Re: linker script
Quoted text here. Click to load it

Yes, but it is fairly common to see linker scripts that don't use
named regions, they simply direct output to a starting address in the
actual linker section. It can be a subtle art to convert scripts like
that to named-region scripts.

(I must confess to being trained this way, (a) because it makes the
linker script read more like a linear assembly-language program, and
(b) because my first real under-the-covers S&M sessions with the GNU
tools dealt with thousands of lines of code from Winbond, which used
this technique exclusively).

Re: linker script
Quoted text here. Click to load it

1.  RTFM.  The linker documentation will tell you (a) how to generate a link
map (b) how the linker barfs if you blow a section allocation.

2.  If the linker doesn't come with documentation, use a different linker.

3.  If the linker won't generate a link map, use a different linker.



Site Timeline