fearless_fool
fearless_fool

Reputation: 35179

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?

Upvotes: 1

Views: 3885

Answers (2)

Battlechicken
Battlechicken

Reputation: 335

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

Upvotes: 1

user3629249
user3629249

Reputation: 16540

the LD manual states, for MEMORY :

"The origin is an expression for the start address of the memory region. The expression must evaluate to a constant before memory allocation is performed, which means that you may not use any section relative symbols. The keyword ORIGIN may be abbreviated to org or o (but not, for example, ORG). "

And the expression: BASE_ADDR = 0X4000; is a section relative symbol

The following text also pertains:

"However, other values (such as symbol values) are not known or needed until after storage allocation. Such values are evaluated later, when other information (such as the sizes of output sections) is available for use in the symbol assignment expression. "

Suggest using hard coded values in the MEMORY allocations

Upvotes: 1

Related Questions