clinkergnu

Defining a symbolic constant for GNU .ld script origin


I'm creating a GNU .ld linker script, and would like to define the origins of some of the memory sections symbolically. The following doesn't work:

BASE_ADDR = 0x4000;

MEMORY
{
  m_interrupts        (RX) : ORIGIN = BASE_ADDR, LENGTH = 0x0200
  m_bootloader_config (RX) : ORIGIN = BASE_ADDR + 0x3C0, LENGTH = 0x0040
  m_text              (RX) : ORIGIN = BASE_ADDR + 0x400, LENGTH = 0x10000 - (BASE_ADDR + 0x400)
  m_data              (RW) : ORIGIN = 0x1FFFF000, LENGTH = 0x4000
}

This results in the following error:

Invoking: Cross ARM C++ Linker
../MKL27Z64xxx4_flash.ld:67: nonconstant expression for origin
collect2: error: ld returned 1 exit status

The error is referring to the line that reads:

m_interrupts        (RX) : ORIGIN = BASE_ADDR, LENGTH = 0x0200

What baffles me is that BASE_ADDR looks pretty constant to me. Is there some special syntax that I need to invoke to convince ld that BASE_ADDR is constant?


Solution

  • As of today, this seems to be fixed, the newer versions of ld are capable of doing this.

    The new feature is tracked here: https://sourceware.org/bugzilla/show_bug.cgi?id=4643