3

I am building an elf target. I have a linker script where I input some of the symbol locations like(these symbols are defined in a different locations like ROM whose address is provided below),

A = 0x12345678;
B = 0x1234567c;
D = 0x1234568c;

In the C code I can use these variables A and B without declaring them which is expected. I want to know if I can override the symbol D i.e., My current executable can have its own declaration of D. In that case the linker should ignore D. Is there a way to declare the symbols in linker script as 'weak'? so that the linker can use 'input symbols' only if it is not declared in any of the linked objects.

Thomas
  • 489
  • 1
  • 8
  • 13

1 Answers1

3

Use PROVIDE directive

PROVIDE(D = 0x1234568c);

From ld documentation

In some cases, it is desirable for a linker script to define a symbol only if it is referenced and is not defined by any object included in the link. … If, on the other hand, the program defines … the linker will silently use the definition in the program.

ReAl
  • 1,231
  • 1
  • 8
  • 19