3

I have been looking at some linker scripts for embedded ARM processors. In one of them, there's something like this (minimal example):

MEMORY {
  REGION : ORIGIN = 0x1000, LENGTH = 0x1000
}
SECTIONS {
  .text : {
    /* ... */
    . = 0x20;
    /* ... */
  } > MEMORY
}

This linker script states that the section .text should go in the memory region REGION, which starts at 0x1000. However, within the section contents, the location is explicitly set to 0x20.

Is this location assignment relative to the start of the region that the section is in? Or absolute? In general, how do regions and location assignments work together?

  • What did it say in the linker manual? – Tom V Dec 16 '21 at 19:49
  • I couldn't find any material that talked about the SECTIONS region in relation to the location assignment; otherwise I wouldn't have asked on SO. –  Dec 16 '21 at 21:06

1 Answers1

3

I did a test. I created an assembly file with the following contents:

.text
.word 0x1234

Then I wrote a basic linker script as detailed in the question:

MEMORY {
    REGION : ORIGIN = 0x100, LENGTH = 0x100
}
SECTIONS {
    .text : {
        . = 0x20;
        *(.text);
    } > REGION
}

I compiled the assembly file to an object file with GCC, then linked the object file into an "executable" with ld. Running objdump -s on the result, I found that 0x1234 was at address 0x120. This means that the location assignment is relative to the start of the memory region.