[ELF] Allow output section data commands to take expressions
The current implementation of the output section data store commands
can only handle integer literals, but it should really handle arbitrary
expressions [1]. This commit fixes that.
[1] https://sourceware.org/binutils/docs-2.27/ld/Output-Section-Data.html#Output-Section-Data
Differential Revision: https://reviews.llvm.org/D27561
llvm-svn: 289152
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 1a19f55..d5e9487 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -852,7 +852,7 @@
auto *Cmd = dyn_cast<OutputSectionCommand>(Opt.Commands[I].get());
for (const std::unique_ptr<BaseCommand> &Base : Cmd->Commands)
if (auto *Data = dyn_cast<BytesDataCommand>(Base.get()))
- writeInt<ELFT>(Buf + Data->Offset, Data->Data, Data->Size);
+ writeInt<ELFT>(Buf + Data->Offset, Data->Expression(0), Data->Size);
}
template <class ELFT> bool LinkerScript<ELFT>::hasLMA(StringRef Name) {
@@ -1688,13 +1688,7 @@
if (Size == -1)
return nullptr;
- expect("(");
- uint64_t Val = 0;
- StringRef S = next();
- if (!readInteger(S, Val))
- setError("unexpected value: " + S);
- expect(")");
- return new BytesDataCommand(Val, Size);
+ return new BytesDataCommand(readParenExpr(), Size);
}
StringRef ScriptParser::readParenLiteral() {