diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index bb75a4b12d9b..a5712f964d3f 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -276,6 +276,17 @@ LinkerScript::createSections(OutputSectionFactory &Factory) { return Result; } +template +void LinkerScript::dispatchAssignment(SymbolAssignment *Cmd) { + uint64_t Val = evalExpr(Cmd->Expr, Dot); + if (Cmd->Name == ".") { + Dot = Val; + } else { + auto *D = cast>(Symtab::X->find(Cmd->Name)); + D->Value = Val; + } +} + template void LinkerScript::assignAddresses( ArrayRef *> Sections) { @@ -297,14 +308,7 @@ void LinkerScript::assignAddresses( for (const std::unique_ptr &Base : Opt.Commands) { if (auto *Cmd = dyn_cast(Base.get())) { - uint64_t Val = evalExpr(Cmd->Expr, Dot); - if (Cmd->Name == ".") { - - Dot = Val; - } else { - auto *D = cast>(Symtab::X->find(Cmd->Name)); - D->Value = Val; - } + dispatchAssignment(Cmd); continue; } diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index c4fa455f2656..0af38b4a4010 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -121,6 +121,7 @@ private: int getSectionIndex(StringRef Name); std::vector getPhdrIndicesForSection(StringRef Name); + void dispatchAssignment(SymbolAssignment *Cmd); uintX_t Dot; };