[PATCH] D26033: [ELF] Resolve undefined symbols from archives when linking shared objects

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 08:01:58 PDT 2016


evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.

When linking DSO lld doesn't resolve symbols from input DSOs in case those symbols are lazy. Below is an example:

input.so - has undefined symbol 'print'
libprint.a - defines 'print'

ld.lld -shared -o output.so input.so libprint.a

Even though libprint.a has definition of 'print', output.so will have it undefined.
Later when you link application with output.so, you'll also have to provide libprint.a

This patch fixes it.


Repository:
  rL LLVM

https://reviews.llvm.org/D26033

Files:
  ELF/SymbolTable.cpp
  test/ELF/Inputs/shared4.s
  test/ELF/shared-lazy.s


Index: test/ELF/shared-lazy.s
===================================================================
--- test/ELF/shared-lazy.s
+++ test/ELF/shared-lazy.s
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/archive.s -o %t2.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared4.s -o %t3.o
+# RUN: llvm-ar rcs %t2.a %t2.o
+# RUN: ld.lld -shared %t3.o -o %t3.so
+# RUN: ld.lld -shared %t.o %t2.a %t3.so -o %t.so
+# RUN: llvm-objdump -t %t.so | FileCheck --check-prefix=DEFINED %s
+
+# DEFINED: _start
+call _entry at plt
Index: test/ELF/Inputs/shared4.s
===================================================================
--- test/ELF/Inputs/shared4.s
+++ test/ELF/Inputs/shared4.s
@@ -0,0 +1,3 @@
+.globl _shared
+_shared:
+  call _start at plt
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -549,9 +549,12 @@
 template <class ELFT> void SymbolTable<ELFT>::scanShlibUndefined() {
   for (SharedFile<ELFT> *File : SharedFiles)
     for (StringRef U : File->getUndefinedSymbols())
-      if (SymbolBody *Sym = find(U))
+      if (SymbolBody *Sym = find(U)) {
         if (Sym->isDefined())
           Sym->symbol()->ExportDynamic = true;
+        else if (Sym->isLazy())
+          addUndefined(U);
+      }
 }
 
 // This function processes --export-dynamic-symbol and --dynamic-list.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26033.76012.patch
Type: text/x-patch
Size: 1501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161027/7fe4d107/attachment.bin>


More information about the llvm-commits mailing list