Can GNU AS .equ directives take values from global symbols in external objects specified with -R?

Viewed 55

The setup I am working with is a bit convoluted, so I will briefly explain the basic usage in play here. Rather than having individual linker scripts for modules which can appear in various places in a given memory range, I have specified the origin/length within a generic linker script as a global symbol. So each module can specify its origin/length for itself as global symbols, and this works perfectly. No issues here.

A somewhat more complicated scenario involves taking the initial program (IP) which does have its own unique linker script, and refer to the global symbols generated from ld when creating the IP in later modules. For example, if the IP starts at 0xff0000 and is only 0x100 bytes, then _ip_text_end is created via the link script as 0xff0100.

The idea is to take that _ip_text_end symbol and assign it to the module origin global symbol, to make the module appear in memory right after it. That is to say, instead of hardcoding a value:

.equ MODULE_ROM_ORIGIN, 0xff0100
.global MODULE_ROM_ORIGIN

To use this instead:

.equ MODULE_ROM_ORIGIN, _ip_text_end
.global MODULE_ROM_ORIGIN

However, no matter how I try it, it appears that MODULE_ROM_ORIGIN is not being set with the _ip_text_end value. To be clear, setting a hardcoded value works fine, and _ip_text_end is definitely set. Using the -y option to trace the symbol:

Linking MMD build/src/ipx.elf...
m68k-elf-ld -nostdlib -M -y _ip_text_end -y MODULE_ROM_ORIGIN -L/home/ryou/Projects/megadev/examples/bram/src -T/home/ryou/Projects/megadev/cfg/module_mmd.ld -obuild/src/ipx.elf build/src/ipx_layout.o build/src/ipx.o -Rbuild/src/ip.elf
m68k-elf-ld: build/src/ipx_layout.o: reference to _ip_text_end
m68k-elf-ld: build/src/ip.elf: definition of _ip_text_end
m68k-elf-ld: invalid origin for memory region MODULE_ROM

It indicates the symbol is referenced, and that a definition is found when referencing the IP object with -R, but the MODULE_ROM_ORIGIN symbol ultimately remains undefined...

I've read through the as and ld manuals a few times now, and I don't see why this wouldn't work. Any input would be greatly, greatly appreciated.

0 Answers
Related