[lld] r350251 - Fix linker-defined symbols possibly not being defined when -wrap is used

Thomas Anderson via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 2 11:28:00 PST 2019


Author: thomasanderson
Date: Wed Jan  2 11:28:00 2019
New Revision: 350251

URL: http://llvm.org/viewvc/llvm-project?rev=350251&view=rev
Log:
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

Added:
    lld/trunk/test/ELF/Inputs/wrap-with-archive.s
    lld/trunk/test/ELF/wrap-with-archive.s
Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=350251&r1=350250&r2=350251&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jan  2 11:28:00 2019
@@ -1550,6 +1550,9 @@ template <class ELFT> void LinkerDriver:
   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:
   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.
   //

Added: lld/trunk/test/ELF/Inputs/wrap-with-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/wrap-with-archive.s?rev=350251&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/wrap-with-archive.s (added)
+++ lld/trunk/test/ELF/Inputs/wrap-with-archive.s Wed Jan  2 11:28:00 2019
@@ -0,0 +1,5 @@
+.global __executable_start
+.global __wrap_get_executable_start
+
+__wrap_get_executable_start:	
+	movabs $__executable_start,%rdx

Added: lld/trunk/test/ELF/wrap-with-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/wrap-with-archive.s?rev=350251&view=auto
==============================================================================
--- lld/trunk/test/ELF/wrap-with-archive.s (added)
+++ lld/trunk/test/ELF/wrap-with-archive.s Wed Jan  2 11:28:00 2019
@@ -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




More information about the llvm-commits mailing list