I am trying to write a linker script such that certain sections will be relocatable and other sections will be not. I am aware of the -r flag, which makes all sections relocatable. However, for a certain section I require absolute symbols.
My linker script so far looks like:
MEMORY {
rom : ORIGIN = 0x09000000, LENGTH = 32M
ewram : ORIGIN = 0x02000000, LENGTH = 4M - 4k
}
SECTIONS {
.text :
ALIGN(4)
{
*(.text*)
}
.rodata :
ALIGN(4)
{
*(.rodata*)
} >rom = 0xff
. = 0x2003000;
not_relocatable :
ALIGN(4)
{
*(not_relocatable*)
}
/* Discard everything not specifically mentioned above. */
/DISCARD/ :
{
*(*);
}
}
When linking with ld ... -r -o linked.o, all symbols in my input files in not_relocatable* will not be located at 0x2003000. For a single symbol, I know what I want to achieve is possible using the ABSOLUTE expression, e.g.
. = 0x2003000;
not_relocatable :
ALIGN(4)
{
my_absolute_symbol = ABSOLUTE(.);
}
However, I want to place all symbols that match *(not_relocatable*) at an absolute address without explicitly listing out all such symbols.
What is the correct way to achieve this?