summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorThomas Anderson <thomasanderson@google.com>2019-01-02 19:28:00 +0000
committerThomas Anderson <thomasanderson@google.com>2019-01-02 19:28:00 +0000
commit29d463ba20529be708f964a9376779af32e00cd1 (patch)
treea76bcf467e4c87368fe9ef2652c7e25c30a80401 /lld
parent7e369ad53bf6de25bb3ba92f6741f14edfe0e643 (diff)
Fix linker-defined symbols possibly not being defined when -wrap is used
Fixes https://bugs.llvm.org/show_bug.cgi?id=40134 addWrappedSymbols() must be called before addReservedSymbols() because the latter only defines reserved symbols when they are undefined in the symbol table. If addWrappedSymbols() is called after, then addUndefined() is called which may lazily pull in more object files that could reference reserved symbols. Differential Revision: https://reviews.llvm.org/D56110
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Driver.cpp6
-rw-r--r--lld/test/ELF/Inputs/wrap-with-archive.s5
-rw-r--r--lld/test/ELF/wrap-with-archive.s13
3 files changed, 21 insertions, 3 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 51daa81edc8..13b6119e2dc 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1550,6 +1550,9 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
Out::ElfHeader->Size = sizeof(typename ELFT::Ehdr);
+ // Create wrapped symbols for -wrap option.
+ std::vector<WrappedSymbol> Wrapped = addWrappedSymbols<ELFT>(Args);
+
// We need to create some reserved symbols such as _end. Create them.
if (!Config->Relocatable)
addReservedSymbols();
@@ -1562,9 +1565,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
if (!Config->Relocatable)
Symtab->scanVersionScript();
- // Create wrapped symbols for -wrap option.
- std::vector<WrappedSymbol> Wrapped = addWrappedSymbols<ELFT>(Args);
-
// Do link-time optimization if given files are LLVM bitcode files.
// This compiles bitcode files into real object files.
//
diff --git a/lld/test/ELF/Inputs/wrap-with-archive.s b/lld/test/ELF/Inputs/wrap-with-archive.s
new file mode 100644
index 00000000000..93aaddc8806
--- /dev/null
+++ b/lld/test/ELF/Inputs/wrap-with-archive.s
@@ -0,0 +1,5 @@
+.global __executable_start
+.global __wrap_get_executable_start
+
+__wrap_get_executable_start:
+ movabs $__executable_start,%rdx
diff --git a/lld/test/ELF/wrap-with-archive.s b/lld/test/ELF/wrap-with-archive.s
new file mode 100644
index 00000000000..1bfbdcef30d
--- /dev/null
+++ b/lld/test/ELF/wrap-with-archive.s
@@ -0,0 +1,13 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/wrap-with-archive.s -o %t2
+// RUN: llvm-ar rcs %t3 %t2
+// RUN: ld.lld -o %t4 %t %t3 -wrap get_executable_start
+
+// Regression test for https://bugs.llvm.org/show_bug.cgi?id=40134
+
+.global get_executable_start
+.global _start
+
+_start:
+ jmp get_executable_start