Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -281,6 +281,7 @@ void assignOffsets(OutputSectionCommand *Cmd); void createOrphanCommands(); void processNonSectionCommands(); + void resetAddressState(); void assignAddresses(); void allocateHeaders(std::vector &Phdrs); void addSymbol(SymbolAssignment *Cmd); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -834,9 +834,23 @@ return; } +// Reset the members associated with address assigment to their initial values +// this permits addressAssignment to be run again. +void LinkerScript::resetAddressState() { + LMAOffset = 0; + CurOutSec = nullptr; + CurMemRegion = nullptr; + ThreadBssOffset = 0; + for (auto &MRI : Opt.MemoryRegions) { + MemoryRegion &MR = MRI.second; + MR.Offset = MR.Origin; + } +} + void LinkerScript::assignAddresses() { // Assign addresses as instructed by linker script SECTIONS sub-commands. Dot = 0; + resetAddressState(); ErrorOnMissingSection = true; switchTo(Aether);