Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to prevent implicit linker script changing the LMA of a section
    primarykey
    data
    text
    <p>I'm using a modular build system for software than runs on an ARM embedded target as well as on a normal X86 (linux) machine. I'm compiling with a GNU toolchain, thus linking using <code>ld</code>.</p> <p>One of the modules makes use of a linkerscript trick to assemble an array of 'registered' objects. The objects are created with a macro like this:</p> <pre><code>#define RegObject(name, arg1, arg2, etc) \ static TRegObject name \ __attribute__((section ("regobj_table"), used)) = \ { arg1, arg2, etc } </code></pre> <p>The module also adds an <a href="http://sourceware.org/binutils/docs/ld/Implicit-Linker-Scripts.html" rel="nofollow">implicit linker script</a> to the link step, which looks like this:</p> <pre><code>SECTIONS { .data : ALIGN(4) { regobj_table_start = .; KEEP(*(regobj_table)) regobj_table_end = .; } } </code></pre> <p>The <code>regobj_table_start</code> and <code>regobj_table_end</code> symbols are used by the code to find the registered objects. This solution works just fine for native (Linux) compiled targets.</p> <p>This doesn't work for the ARM target however. The reason is that I have a custom default linker script for the target (it's a tiny microcontroller, running without an OS), which defines a load memory address for the <code>.data</code> section. This is because the section is stored in Flash memory, but once the microcontroller boots it's copied to RAM. The relevant part of the linker script looks like this:</p> <pre><code>MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 512k RAM (rwx) : ORIGIN = 0x40000000, LENGTH = 32k } SECTIONS { /* ... other stuff ... */ .data : { _data = .; *(.data) *(.data.*) } &gt;RAM AT&gt;ROM /* ... even more stuff ... */ } </code></pre> <p>This sets the VMA of the <code>.data</code> section to somewhere in the 0x4000000 range, and the LMA in the 0x00000000 range.</p> <p><strong>The problem is</strong> that when the implicit linker script is added to the command-line of <code>ld</code>, it just forgets about the LMA and it becomes equal to the VMA again. I'm desperately looking for a method to tell <code>ld</code> to not touch the LMA when loading the implicit linker script.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload