[PATCH] D23751: [ELF] Linkerscript: define symbols outside SECTIONS
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 08:39:42 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280252: [ELF] Linkerscript: define symbols outside SECTIONS (authored by phosek).
Changed prior to commit:
https://reviews.llvm.org/D23751?vs=69757&id=69863#toc
Repository:
rL LLVM
https://reviews.llvm.org/D23751
Files:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/linkerscript/linkerscript-symbols.s
Index: lld/trunk/test/ELF/linkerscript/linkerscript-symbols.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-symbols.s
+++ lld/trunk/test/ELF/linkerscript/linkerscript-symbols.s
@@ -67,6 +67,15 @@
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN5 %s
# HIDDEN5: 0000000000000000 *ABS* 00000000 somesym
+# Simple symbol assignment. All three symbols should have the
+# same value.
+# RUN: echo "foo = 0x100; SECTIONS { bar = foo; } baz = bar;" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE2 %s
+# SIMPLE2: 0000000000000100 *ABS* 00000000 foo
+# SIMPLE2: 0000000000000100 *ABS* 00000000 bar
+# SIMPLE2: 0000000000000100 *ABS* 00000000 baz
+
.global _start
_start:
nop
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -249,6 +249,8 @@
CommonInputSection<ELFT> Common(getCommonSymbols<ELFT>());
CommonInputSection<ELFT>::X = &Common;
+ Script<ELFT>::X->createAssignments();
+
Script<ELFT>::X->OutputSections = &OutputSections;
if (ScriptConfig->HasContents)
Script<ELFT>::X->createSections(Factory);
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -259,6 +259,16 @@
}
template <class ELFT>
+void LinkerScript<ELFT>::createAssignments() {
+ for (const std::unique_ptr<SymbolAssignment> &Cmd : Opt.Assignments) {
+ if (shouldDefine<ELFT>(Cmd.get()))
+ addRegular<ELFT>(Cmd.get());
+ if (Cmd->Sym)
+ cast<DefinedRegular<ELFT>>(Cmd->Sym)->Value = Cmd->Expression(0);
+ }
+}
+
+template <class ELFT>
void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) {
if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) {
@@ -714,12 +724,16 @@
void ScriptParser::readLinkerScript() {
while (!atEOF()) {
StringRef Tok = next();
- if (Handler Fn = Cmd.lookup(Tok))
+ if (Handler Fn = Cmd.lookup(Tok)) {
(this->*Fn)();
- else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok))
- Opt.Commands.emplace_back(Cmd);
- else
+ } else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok)) {
+ if (Opt.HasContents)
+ Opt.Commands.emplace_back(Cmd);
+ else
+ Opt.Assignments.emplace_back(Cmd);
+ } else {
setError("unknown directive: " + Tok);
+ }
}
}
Index: lld/trunk/ELF/LinkerScript.h
===================================================================
--- lld/trunk/ELF/LinkerScript.h
+++ lld/trunk/ELF/LinkerScript.h
@@ -118,6 +118,8 @@
// ScriptConfiguration holds linker script parse results.
struct ScriptConfiguration {
+ // Used to create symbol assignments outside SECTIONS command.
+ std::vector<std::unique_ptr<SymbolAssignment>> Assignments;
// Used to assign addresses to sections.
std::vector<std::unique_ptr<BaseCommand>> Commands;
@@ -142,6 +144,7 @@
public:
LinkerScript();
~LinkerScript();
+ void createAssignments();
void createSections(OutputSectionFactory<ELFT> &Factory);
std::vector<PhdrEntry<ELFT>> createPhdrs();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23751.69863.patch
Type: text/x-patch
Size: 3418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160831/5ae61a9e/attachment.bin>
More information about the llvm-commits
mailing list