Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter.
Previously, we had two expression types, ExprKind and SymbolAssignmentKind
for `.` and all the other symbol names, respectively. But we could merge
them because the former is a special case of the latter.
llvm-svn: 275527
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index f25d6d4..65265fb 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -227,23 +227,22 @@
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<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
+ D->Value = Val;
+ }
continue;
- case SymbolAssignmentKind: {
- auto *D =
- cast<DefinedRegular<ELFT>>(Symtab<ELFT>::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<ELFT> *Sec : Sections) {
if (Sec->getName() != Cmd.Name)
continue;
@@ -312,8 +311,9 @@
template <class ELFT>
void LinkerScript<ELFT>::addScriptedSymbols() {
for (SectionsCommand &Cmd : Opt.Commands)
- if (Cmd.Kind == SymbolAssignmentKind)
- Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
+ if (Cmd.Kind == AssignmentKind)
+ if (Cmd.Name != ".")
+ Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
}
class elf::ScriptParser : public ScriptParserBase {
@@ -525,7 +525,7 @@
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 @@
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<StringRef> ScriptParser::readSectionsCommandExpr() {