[ELF] --wrap: don't copy exportDynamic
authorFangrui Song <i@maskray.me>
Sat, 5 Feb 2022 17:56:29 +0000 (09:56 -0800)
committerFangrui Song <i@maskray.me>
Sat, 5 Feb 2022 17:56:29 +0000 (09:56 -0800)
For -no-pie/-pie, when `__real_foo` is interposable in a shared object, `foo` is
exported. This rule does not match GNU ld and is unneeded because:

* the exported `foo` does not interpose `__real_foo` at run-time
* the similar `__wrap_foo` <-> `foo` relation does not have the rule

lld/ELF/SymbolTable.cpp
lld/test/ELF/wrap-no-real.s
lld/test/ELF/wrap-shlib-undefined.s

index ec425cd7e1d12b124436413c4cf3370768d86514..90a4ab93868cdfa7d0814d54ee319128a3bdc183 100644 (file)
@@ -40,8 +40,6 @@ void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) {
   idx2 = idx1;
   idx1 = idx3;
 
-  if (real->exportDynamic)
-    sym->exportDynamic = true;
   if (!real->isUsedInRegularObj && sym->isUndefined())
     sym->isUsedInRegularObj = false;
 
index 125e2cfbcce753454d76f26bcda3165ae97d03e0..4839e58a2c949c58931a9e6ecde63278136aa60c 100644 (file)
@@ -23,9 +23,9 @@
 // RUN: llvm-readelf -s -x .got %t2 | FileCheck --check-prefix=READELF --implicit-check-not=__real_ %s
 
 // CHECK2: <_start>:
-// CHECK2-NEXT: movq {{.*}}(%rip), %rax  # 0x2022e8
-// CHECK2-NEXT: movq {{.*}}(%rip), %rbx  # 0x2022e8
-// CHECK2-NEXT: movq {{.*}}(%rip), %rcx  # 0x2022e0
+// CHECK2-NEXT: movq {{.*}}(%rip), %rax  # 0x2022c0
+// CHECK2-NEXT: movq {{.*}}(%rip), %rbx  # 0x2022c0
+// CHECK2-NEXT: movq {{.*}}(%rip), %rcx  # 0x2022b8
 
 .global _start
 _start:
index 2897b7e39ce2d6cb4e6ed2a1f1a67a359f578c5f..b5546a678aca1537a589d8d93c6bb13be1c67c65 100644 (file)
 # RUN: llvm-readelf --dyn-syms %t2 | FileCheck %s --check-prefix=CHECK2
 
 ## See wrap-plt2.s why __wrap_foo is retained.
-# CHECK2:      Symbol table '.dynsym' contains 4 entries:
+# CHECK2:      Symbol table '.dynsym' contains 3 entries:
 # CHECK2:      NOTYPE  LOCAL  DEFAULT  UND
 # CHECK2-NEXT: NOTYPE  GLOBAL DEFAULT  UND bar
 # CHECK2-NEXT: NOTYPE  GLOBAL DEFAULT  UND __wrap_foo
-# CHECK2-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
 
 ## __wrap_bar is undefined.
 # RUN: ld.lld -shared %t/main.o --wrap=bar -o %t3.so