Search code examples
assemblyldgnu-assembler

Is there way to use global symbols from other binary without linking it in


I'm trying to convert a game for Soviet PDP11 compatible machine. Since it has strict memory limitation - 56K of RAM, I have to load some part of code during runtime. Which means that I need to build several binary modules which cross-reference symbols from each other. I'm using GAS and LD.

Is there a way to accomplish this simply using these tools?

For example, one binary module file wants to load another binary module, to do that it has to know the size of the other binary. The size is available as a symbol like this:

.title OtherModule

begin:
  some code
end:

.equiv SizeOfTheOtherModuleInWords, ((end - begin) / 2)

Another example, each level in the game loads separately and contains code which calls subroutines from the main engine which always resides in memory.


I found a solution via linker script. I can use /DISCARD/ section to exclude files from linking.

OUTPUT_FORMAT("binary")
OUTPUT_ARCH(pdp11)

INPUT(core.o bootstrap.o)
OUTPUT(AKU.SAV)

FileSizeCoreWords = ((FileEndCore - FileBeginCore) / 2);

SECTIONS
{
    . = 0;
.text :
    {
        bootstrap.o (.text)
    }
.data :
    {
        bootstrap.o (.data)
    }
.bss :
    {
        bootstrap.o (.bss)
    }
/DISCARD/ :
    {
        core.o
    }
}

Solution

  • GNU ld has the option --just-symbols which takes an already linked file to load the symbols from.