[lld] r275527 - Merge SymbolAssignmentKind and ExprKind.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 21:19:38 PDT 2016
Author: ruiu
Date: Thu Jul 14 23:19:37 2016
New Revision: 275527
URL: http://llvm.org/viewvc/llvm-project?rev=275527&view=rev
Log:
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.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=275527&r1=275526&r2=275527&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Jul 14 23:19:37 2016
@@ -227,23 +227,22 @@ void LinkerScript<ELFT>::assignAddresses
uintX_t ThreadBssOffset = 0;
for (SectionsCommand &Cmd : Opt.Commands) {
- switch (Cmd.Kind) {
- case ExprKind:
- Dot = evalExpr(Cmd.Expr, Dot);
- continue;
- case SymbolAssignmentKind: {
- auto *D =
- cast<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
- D->Value = 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;
}
- 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 @@ int LinkerScript<ELFT>::compareSections(
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 @@ void ScriptParser::readLocationCounterVa
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(
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() {
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=275527&r1=275526&r2=275527&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Jul 14 23:19:37 2016
@@ -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;
More information about the llvm-commits
mailing list