Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -115,6 +115,7 @@ // ScriptConfiguration holds linker script parse results. struct ScriptConfiguration { + std::vector> Assignments; // Used to assign addresses to sections. std::vector> Commands; @@ -139,6 +140,7 @@ public: LinkerScript(); ~LinkerScript(); + void createSymbols(); void createSections(OutputSectionFactory &Factory); std::vector> createPhdrs(); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -259,6 +259,16 @@ } template +void LinkerScript::createSymbols() { + for (const std::unique_ptr &Cmd : Opt.Assignments) { + if (shouldDefine(Cmd.get())) + addRegular(Cmd.get()); + if (Cmd->Sym) + cast>(Cmd->Sym)->Value = Cmd->Expression(0); + } +} + +template void LinkerScript::createSections(OutputSectionFactory &Factory) { for (const std::unique_ptr &Base1 : Opt.Commands) { if (auto *Cmd = dyn_cast(Base1.get())) { @@ -657,7 +667,7 @@ if (Handler Fn = Cmd.lookup(Tok)) (this->*Fn)(); else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok)) - Opt.Commands.emplace_back(Cmd); + Opt.Assignments.emplace_back(Cmd); else setError("unknown directive: " + Tok); } Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -246,6 +246,8 @@ CommonInputSection Common(getCommonSymbols()); CommonInputSection::X = &Common; + Script::X->createSymbols(); + Script::X->OutputSections = &OutputSections; if (ScriptConfig->HasContents) Script::X->createSections(Factory);