The expr '.' is not absolute.
With this patch we keep track of the fact that . is a position in the
file and therefore not absolute. This allow us to compute relative
relocations that involve symbol that are defined in linker scripts
with '.'.
This fixes https://llvm.org/bugs/show_bug.cgi?id=30406
There is still more work to track absoluteness over the various
expressions, but this should unblock linking the EFI bootloader.
llvm-svn: 285641
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 9061dac..6c5fc9e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -299,7 +299,7 @@
const std::unique_ptr<BaseCommand> &Base1 = *Iter;
if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) {
if (shouldDefine<ELFT>(Cmd))
- addRegular<ELFT>(Cmd);
+ addSymbol<ELFT>(Cmd);
continue;
}
if (auto *Cmd = dyn_cast<AssertCommand>(Base1.get())) {
@@ -621,7 +621,8 @@
if (Cmd->Name == ".") {
Dot = Cmd->Expression(Dot);
} else if (Cmd->Sym) {
- cast<DefinedRegular<ELFT>>(Cmd->Sym)->Value = Cmd->Expression(Dot);
+ assignSectionSymbol(Cmd, CurOutSec ? CurOutSec : (*OutputSections)[0],
+ Dot);
}
continue;
}
@@ -1186,7 +1187,7 @@
expect("{");
while (!Error && !consume("}")) {
StringRef Tok = next();
- BaseCommand *Cmd = readProvideOrAssignment(Tok, true);
+ BaseCommand *Cmd = readProvideOrAssignment(Tok, false);
if (!Cmd) {
if (Tok == "ASSERT")
Cmd = new AssertCommand(readAssert());
@@ -1636,7 +1637,7 @@
}
if (Tok == "CONSTANT") {
StringRef Name = readParenLiteral();
- return {[=](uint64_t Dot) { return getConstant(Name); }, true};
+ return [=](uint64_t Dot) { return getConstant(Name); };
}
if (Tok == "DEFINED") {
expect("(");
@@ -1679,23 +1680,20 @@
}
if (Tok == "SIZEOF") {
StringRef Name = readParenLiteral();
- return {
- [=](uint64_t Dot) { return ScriptBase->getOutputSectionSize(Name); },
- true};
+ return [=](uint64_t Dot) { return ScriptBase->getOutputSectionSize(Name); };
}
if (Tok == "ALIGNOF") {
StringRef Name = readParenLiteral();
- return {
- [=](uint64_t Dot) { return ScriptBase->getOutputSectionAlign(Name); },
- true};
+ return
+ [=](uint64_t Dot) { return ScriptBase->getOutputSectionAlign(Name); };
}
if (Tok == "SIZEOF_HEADERS")
- return {[=](uint64_t Dot) { return ScriptBase->getHeaderSize(); }, true};
+ return [=](uint64_t Dot) { return ScriptBase->getHeaderSize(); };
// Tok is a literal number.
uint64_t V;
if (readInteger(Tok, V))
- return {[=](uint64_t Dot) { return V; }, true};
+ return [=](uint64_t Dot) { return V; };
// Tok is a symbol name.
if (Tok != "." && !isValidCIdentifier(Tok))
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 5753620..8ab04ab 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -43,13 +43,9 @@
uint64_t operator()(uint64_t Dot) const { return Val(Dot); }
operator bool() const { return (bool)Val; }
- template <typename T>
- Expr(T Val, std::function<bool()> IsAbsolute)
+ Expr(std::function<uint64_t(uint64_t)> Val, std::function<bool()> IsAbsolute)
: Val(Val), IsAbsolute(IsAbsolute) {}
- template <typename T> Expr(T Val, bool IsAbsolute) : Val(Val) {
- this->IsAbsolute = [=]() { return IsAbsolute; };
- }
- template <typename T> Expr(T V) : Expr(V, false) {}
+ template <typename T> Expr(T V) : Expr(V, []() { return true; }) {}
Expr() : Expr(nullptr) {}
};