2026-05-27
The asker has two bare-metal ELF images that will be co-resident in physical memory and wants them to share a region containing both data and code. Their instinct is to drop my_object_file.o(.data) into a fixed-address section (.my_section 0x10000) in both linker scripts and hope the resulting symbols line up.
Why it's tricky: two independent link invocations are exactly that — independent. Even with the same object file and the same address, the linker is free to:
--gc-sections) entries that look unused from one ELF's perspective but not the other's.So "include the same .o in the same fixed section" is necessary but not sufficient. You need the addresses, not the inputs, to be the contract between the two ELFs.
A more robust approach:
0x10000. Generate a symbol file from it (nm or --just-symbols).INCLUDE shared.syms or pass -Wl,--just-symbols=shared.elf. Now both ELFs reference identical absolute addresses without re-linking the shared code.PROVIDE(my_func = 0x10010); in both scripts. Ugly, but explicit.NOLOAD in one of the ELFs if only the other should actually deposit bytes there — otherwise both loaders will write the region and the second write wins.Gotchas:
--just-symbols from a pre-linked shared image gives you.--gc-sections here; mark the shared section with KEEP(...).