[PATCH] D31147: [ELF] Allow references to reserved symbols in linker scripts
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 21:05:03 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL298577: [ELF] Allow references to reserved symbols in linker scripts (authored by phosek).
Changed prior to commit:
https://reviews.llvm.org/D31147?vs=92754&id=92756#toc
Repository:
rL LLVM
https://reviews.llvm.org/D31147
Files:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/test/ELF/linkerscript/symbol-reserved.s
Index: lld/trunk/test/ELF/linkerscript/symbol-reserved.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-reserved.s
+++ lld/trunk/test/ELF/linkerscript/symbol-reserved.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "PROVIDE_HIDDEN(newsym = __ehdr_start + 5);" > %t.script
+# RUN: ld.lld -o %t1 %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck %s
+
+# CHECK: 0000000000200005 .text 00000000 .hidden newsym
+
+# RUN: ld.lld -o %t1.so %t.script %t -shared
+# RUN: llvm-objdump -t %t1.so | FileCheck --check-prefix=SHARED %s
+
+# SHARED: 0000000000000005 .dynsym 00000000 .hidden newsym
+
+.global _start
+_start:
+ lea newsym(%rip),%rax
Index: lld/trunk/ELF/Driver.cpp
===================================================================
--- lld/trunk/ELF/Driver.cpp
+++ lld/trunk/ELF/Driver.cpp
@@ -921,6 +921,11 @@
if (ErrorCount)
return;
+ // Some symbols (such as __ehdr_start) are defined lazily only when there
+ // are undefined symbols for them, so we add these to trigger that logic.
+ for (StringRef Sym : Script->Opt.UndefinedSymbols)
+ Symtab.addUndefined(Sym);
+
for (auto *Arg : Args.filtered(OPT_wrap))
Symtab.wrap(Arg->getValue());
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -999,8 +999,8 @@
if (SymbolBody *B = findSymbol(S)) {
if (auto *D = dyn_cast<DefinedRegular>(B))
return {D->Section, D->Value};
- auto *C = cast<DefinedCommon>(B);
- return {InX::Common, C->Offset};
+ if (auto *C = dyn_cast<DefinedCommon>(B))
+ return {InX::Common, C->Offset};
}
error(Loc + ": symbol not found: " + S);
return 0;
@@ -1867,8 +1867,11 @@
return [=] { return V; };
// Tok is a symbol name.
- if (Tok != "." && !isValidCIdentifier(Tok))
- setError("malformed number: " + Tok);
+ if (Tok != ".") {
+ if (!isValidCIdentifier(Tok))
+ setError("malformed number: " + Tok);
+ Script->Opt.UndefinedSymbols.push_back(Tok);
+ }
return [=] { return Script->getSymbolValue(Location, Tok); };
}
Index: lld/trunk/ELF/LinkerScript.h
===================================================================
--- lld/trunk/ELF/LinkerScript.h
+++ lld/trunk/ELF/LinkerScript.h
@@ -217,6 +217,9 @@
// A map from memory region name to a memory region descriptor.
llvm::DenseMap<llvm::StringRef, MemoryRegion> MemoryRegions;
+
+ // A list of undefined symbols referenced by the script.
+ std::vector<llvm::StringRef> UndefinedSymbols;
};
class LinkerScript {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31147.92756.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170323/b627609d/attachment.bin>
More information about the llvm-commits
mailing list