diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index f25d6d400f9f..65265fb47410 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -227,23 +227,22 @@ void LinkerScript::assignAddresses( uintX_t ThreadBssOffset = 0; for (SectionsCommand &Cmd : Opt.Commands) { - switch (Cmd.Kind) { - case ExprKind: - Dot = evalExpr(Cmd.Expr, Dot); + if (Cmd.Kind == AssignmentKind) { + uint64_t Val = evalExpr(Cmd.Expr, Dot); + + if (Cmd.Name == ".") { + Dot = Val; + } else { + auto *D = cast>(Symtab::X->find(Cmd.Name)); + D->Value = Val; + } continue; - case SymbolAssignmentKind: { - auto *D = - cast>(Symtab::X->find(Cmd.Name)); - D->Value = evalExpr(Cmd.Expr, Dot); - continue; - } - default: - break; } // Find all the sections with required name. There can be more than // ont section with such name, if the alignment, flags or type // attribute differs. + assert(Cmd.Kind == SectionKind); for (OutputSectionBase *Sec : Sections) { if (Sec->getName() != Cmd.Name) continue; @@ -312,8 +311,9 @@ int LinkerScript::compareSections(StringRef A, StringRef B) { template void LinkerScript::addScriptedSymbols() { for (SectionsCommand &Cmd : Opt.Commands) - if (Cmd.Kind == SymbolAssignmentKind) - Symtab::X->addAbsolute(Cmd.Name, STV_DEFAULT); + if (Cmd.Kind == AssignmentKind) + if (Cmd.Name != ".") + Symtab::X->addAbsolute(Cmd.Name, STV_DEFAULT); } class elf::ScriptParser : public ScriptParserBase { @@ -525,7 +525,7 @@ void ScriptParser::readLocationCounterValue() { if (Expr.empty()) error("error in location counter expression"); else - Opt.Commands.push_back({ExprKind, std::move(Expr), ""}); + Opt.Commands.push_back({AssignmentKind, std::move(Expr), "."}); } void ScriptParser::readOutputSectionDescription(StringRef OutSec) { @@ -572,7 +572,7 @@ void ScriptParser::readSymbolAssignment(StringRef Name) { if (Expr.empty()) error("error in symbol assignment expression"); else - Opt.Commands.push_back({SymbolAssignmentKind, std::move(Expr), Name}); + Opt.Commands.push_back({AssignmentKind, std::move(Expr), Name}); } std::vector ScriptParser::readSectionsCommandExpr() { diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index b515c1890097..768f78a66468 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -40,7 +40,7 @@ struct SectionRule { // This enum represents what we can observe in SECTIONS tag of script: // ExprKind is a location counter change, like ". = . + 0x1000" // SectionKind is a description of output section, like ".data :..." -enum SectionsCommandKind { ExprKind, SectionKind, SymbolAssignmentKind }; +enum SectionsCommandKind { SectionKind, AssignmentKind }; struct SectionsCommand { SectionsCommandKind Kind;