[PATCH] D64136: [ELF] resolveUndefined: ignore undefined symbols in SharedFile
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 08:09:27 PDT 2019
MaskRay created this revision.
MaskRay added reviewers: grimar, peter.smith, ruiu.
Herald added subscribers: llvm-commits, jfb, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
libstdc++ std::call_once creates a weak reference of pthread_once.
If %t1.o has a weak reference, %t2.so has a non-weak reference.
ld.lld %t1.o %t2.so -o %t
The reference in %t should be weak.
This fixes an (-z defs) error when linking libLLVMCore.so with lld after D63974 <https://reviews.llvm.org/D63974>.
ld.lld: error: undefined symbol: pthread_once
Object files with std::call_once calls have weak references of pthread_once.
libLLVMSupport.so.9svn has a non-weak reference that changes the binding. It should be ignored instead.
We happened to work before D63974 <https://reviews.llvm.org/D63974> because libgcc_s.so.1 was linked the last and it changed the binding again to weak.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D64136
Files:
ELF/Symbols.cpp
test/ELF/weak-undef-shared.s
Index: test/ELF/weak-undef-shared.s
===================================================================
--- test/ELF/weak-undef-shared.s
+++ test/ELF/weak-undef-shared.s
@@ -24,6 +24,11 @@
# RUN: ld.lld %t2.o %t.so %t1.o -o %t
# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=GLOBAL %s
+## Check the binding (weak) is not affected by the STB_GLOBAL undefined
+## reference in %t2.so
+# RUN: ld.lld %t1.o %t2.so -o %t
+# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
+
# WEAK: NOTYPE WEAK DEFAULT UND foo
# GLOBAL: NOTYPE GLOBAL DEFAULT UND foo
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -410,6 +410,10 @@
if (Traced)
printTraceSymbol(&Other);
+ // Ignore undefined symbols in a SharedFile.
+ if (isa_and_nonnull<SharedFile>(Other.File))
+ return;
+
if (isUndefined()) {
// The binding may "upgrade" from weak to non-weak.
if (Other.Binding != STB_WEAK)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64136.207800.patch
Type: text/x-patch
Size: 1017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190703/7f5db8d0/attachment.bin>
More information about the llvm-commits
mailing list