[LLVMdev] [lld] Current ways to position memory sections (e.g. .text, .data, .bss) with lld?

ed at modk.it ed at modk.it
Wed Jul 1 08:00:57 PDT 2015


Hi All,

Congratulations on the major progress on the llvm linker lld over the past
year including the new linker script support.  This really makes it
possible to ditch binutils altogether.  It looks like lld's MEMORY sections
are currently parsed but not evaluated, but so far that hasn't been a
problem.

The only snag is I can't figure out how to define the start of the .data
section in a sane way.  Let's say we want our flash (.text) section to
start at address 0x20000 with a max size of 0x8000 bytes and a data section
start at 0x20005000 with a max length of 0x3000 bytes.  We'd usually
accomplish this with a combination of MEMORY and SECTION entries in the
linker script tied together by region aliases, the "AT" directive and the
">" operator:

MEMORY

{

    flash (rx) : ORIGIN = 0x20000, LENGTH = 0x8000

    ram (rwx) : ORIGIN = 0x20005000, LENGTH = 0x00003000

}


 REGION_ALIAS("REGION_TEXT", flash);

REGION_ALIAS("REGION_RAM", ram);


 SECTIONS

{

    .text :

    {

        ...

    } > REGION_TEXT



    _etext = .;

    .data :

    {

       ...

    } > REGION_RAM AT > REGION_TEXT


}


But the MEMORY entries don't seem to be evaluated and ">", "AT", and
"REGION_ALIAS" don't seem to be hooked up either.  Command line options
like "-Tdata=org=0x20005000" or "--section-start=.data= 0x20005000" are
also not working.


However, the following linker script gets us close:


SECTIONS

    {

        . = 0x20000;

        .text :

        {

           ...

        }



        _etext = .;

        . = 0x20005000;

        _data = .;

        .data :

        {

           ...

        }

}


The only problem is the resulting elf and binary files are HUGE (e.g. elf
is 500mb vs 50k) as the linker seems to be filling the space between the
end of text and the beginning of data.  A "llvm-readobj -s" on the
resulting elf is nearly identical to one created with binutils except
binults-ld puts .data at Address: 0x20005000 Offset: 0xD000 and llvm-lld
has data at Address: 0x20005000 Offset: 0x1FFED000 (based on start address
of 0x18000.)

Any thoughts on a supported linker flag or linker script option that can
help here?  Or a source file to dive into to get something working?  I'd be
willing to take a pass at completing the MEMORY section implementation if
that's the most sane way to move forward but would love a pointer in the
right direction.


Thanks,

Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150701/40bf8d86/attachment.html>


More information about the llvm-dev mailing list