[lld] 99cd569 - [ELF] --wrap: set isUsedInRegularObj of __wrap_ if it is defined or shared

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 8 09:24:40 PDT 2020


Author: Fangrui Song
Date: 2020-08-08T09:24:31-07:00
New Revision: 99cd56906a4dd00db25b045eccddcb6802d39f8d

URL: https://github.com/llvm/llvm-project/commit/99cd56906a4dd00db25b045eccddcb6802d39f8d
DIFF: https://github.com/llvm/llvm-project/commit/99cd56906a4dd00db25b045eccddcb6802d39f8d.diff

LOG: [ELF] --wrap: set isUsedInRegularObj of __wrap_ if it is defined or shared

Fixes PR47017 (a regression when fixing PR46169): if __wrap_ is shared,
it is not exported.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/test/ELF/wrap-shlib-undefined.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 012da1485acb..e18392430329 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1862,7 +1862,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
 
     // Tell LTO not to eliminate these symbols.
     sym->isUsedInRegularObj = true;
-    if (wrap->isDefined())
+    if (!wrap->isUndefined())
       wrap->isUsedInRegularObj = true;
   }
   return v;

diff  --git a/lld/test/ELF/wrap-shlib-undefined.s b/lld/test/ELF/wrap-shlib-undefined.s
index b0451b2865ab..175f2ec8d091 100644
--- a/lld/test/ELF/wrap-shlib-undefined.s
+++ b/lld/test/ELF/wrap-shlib-undefined.s
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: split-file %s %t.dir
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/main.s -o %t.o
 # RUN: echo '.globl bar; bar: call __real_foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
 # RUN: ld.lld -shared -soname=t.so %t1.o -o %t.so
 
@@ -19,7 +20,28 @@
 # CHECK-NEXT: NOTYPE  GLOBAL DEFAULT  UND bar
 # CHECK-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
 
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/wrap.s -o %twrap.o
+# RUN: ld.lld -shared --soname=fixed %twrap.o -o %twrap.so
+# RUN: ld.lld %t.o %twrap.so --wrap bar -o %t1
+# RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=DYNSYM
+# RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=ASM
+
+## FIXME GNU ld does not export bar
+# DYNSYM:      Symbol table '.dynsym' contains 3 entries:
+# DYNSYM:      NOTYPE  LOCAL  DEFAULT  UND
+# DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT  UND bar
+# DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT  UND __wrap_bar
+
+# ASM:      <_start>:
+# ASM-NEXT:   callq {{.*}} <__wrap_bar at plt>
+
+#--- main.s
 .globl _start, foo
 _start:
   call bar
 foo:
+
+#--- wrap.s
+.globl __wrap_bar
+__wrap_bar:
+  retq


        


More information about the llvm-commits mailing list