This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Setting the LMA in ld

For a ROM-based system, it is necessary to initialize the .data section of a stand-alone executable
with data stored in ROM.  The ELF LMA/VMA concept is designed to facilitate this; must be located
in RAM but can be loaded to ROM, from where it can be copied during initialization.

I would like to avoid explicitly replacing the default linker scripts of GNU ld, as they are fairly complex; I would prefer to
augment them via -Tscript commands that cause .data and other initialized RAM sections to be loaded to ROM., Output Section LMA in the GNU linker manual states the rules for assigning the LMA of a section.

If no explicit LMA is given via AT or AT>, no explicit VMA is set, the section is allocatable, a region can
be found that is compatible with the current section, and this region contains at least one section, the LMA is
set so that the difference between LMA and VMA is the same as the difference of the last section allocated
in that region (3rd bullet point).

So if a section were defined that is located to RAM but loaded to ROM, following sections that are located
To RAM should also have a load address in ROM.

However, the following implementation and some variations of it do not work:

        ROM (RX): ORIGIN = 0x8000000, LENGTH = 1M
        RAM (WAI): ORIGIN = 0x2000000, LENGTH = 96K

        .data_located : {
        } >RAM AT>ROM

INSERT AFTER .eh_frame  ;

This file is added to the link command via -Wl,-Tscript.ld.  The MEMORY command defines
a ROM and a RAM memory region; the SECTIONS command defines a new (dummy) output section that
is located to RAM but loaded to ROM.  This output section is placed after the last read-only
data section, and indeed is located in RAM but loaded to ROM.  However, the following sections
including .data, are not loaded to ROM; their LMA is equal to their VMA, which would seem to
contradict the manual.

I'd be grateful for any insight into this.

Also, the ld manual does not really define the meaning of the I (or L) memory region attribute.  E.g., which
GNU as ELF .section flags or type parameters needs to be set for a section to be considered initialized?


Konrad Schwarz

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]