How to prevent an implicit linker script from changing an LMA section

I am using a modular build system for software than running on an embedded ARM target as well as a regular X86 (linux) machine. I am compiling with the GNU toolchain, thus using ld

.

One of the modules uses the linkerscript trick to assemble an array of "registered" objects. Objects are created using a macro:

#define RegObject(name, arg1, arg2, etc) \
    static TRegObject name \
    __attribute__((section ("regobj_table"), used)) = \
    { arg1, arg2, etc }

      

The module also adds an implicit linker script to the link step, which looks like this:

SECTIONS
{
    .data : ALIGN(4)
    {
        regobj_table_start = .;
        KEEP(*(regobj_table))
        regobj_table_end = .;
    }
}

      

Symbols regobj_table_start

and regobj_table_end

are used by the code to find registered objects. This solution works great for compiled targets (Linux).

However, this does not work for the ARM target. The reason is that I have a custom default script linker for the target (this is a tiny microcontroller running without an OS) that determines the boot memory address for the partition .data

. This is because the partition is stored in flash memory, but as soon as the microcontroller is loaded, it is copied to RAM. The relevant part of the linker script looks like this:

MEMORY
{
  ROM (rx)  : ORIGIN = 0x00000000, LENGTH = 512k
  RAM (rwx) : ORIGIN = 0x40000000, LENGTH = 32k
}

SECTIONS
{
    /* ... other stuff ... */

    .data :
    {
        _data = .;
        *(.data)
        *(.data.*)
    } >RAM AT>ROM

    /* ... even more stuff ... */
}

      

This sets the VMA of the partition .data

somewhere in the range 0x4000000, and the LMA in the range 0x00000000.

The problem is that when the implicit linker script is added to the command line ld

, it just forgets about the LMA and becomes equal to the VMA again. I'm desperately looking for a method to tell me ld

not to touch the LMA when loading an implicit linker script.

+3


source to share


1 answer


Try using INSERT AFTER ... as the last line. This will set your script to default.



0


source







All Articles