[PATCH] D115092: [lld-macho] Unreferenced weak dylib symbols shouldn't fetch archive symbols
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 3 18:33:27 PST 2021
int3 updated this revision to Diff 391800.
int3 added a comment.
tweak
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115092/new/
https://reviews.llvm.org/D115092
Files:
lld/MachO/SymbolTable.cpp
lld/test/MachO/weak-definition-direct-fetch.s
Index: lld/test/MachO/weak-definition-direct-fetch.s
===================================================================
--- lld/test/MachO/weak-definition-direct-fetch.s
+++ lld/test/MachO/weak-definition-direct-fetch.s
@@ -55,7 +55,7 @@
# RUN: %lld -lSystem -o %t/nonweak-weak-archives %t/foo.a %t/weakfoo.a %t/test.o
# RUN: llvm-objdump --macho --lazy-bind --syms %t/nonweak-weak-archives | FileCheck %s --check-prefix=PREFER-NONWEAK-OBJECT
-## The remaining lines test symbol pairs of different types.
+## The next 5 chunks test symbol pairs of different types.
## (Weak) archive symbols take precedence over weak dylib symbols.
# RUN: %lld -lSystem -o %t/weak-dylib-weak-ar -L%t -lweakfoo %t/weakfoo.a %t/test.o
@@ -87,6 +87,16 @@
# RUN: %lld -lSystem -o %t/nonweak-ar-weak-obj %t/foo.a %t/weakfoo.o %t/test.o
# RUN: llvm-objdump --macho --lazy-bind --syms %t/nonweak-ar-weak-obj | FileCheck %s --check-prefix=PREFER-WEAK-OBJECT
+## Regression test: A weak dylib symbol that isn't referenced by an undefined
+## symbol should not cause an archive symbol to get loaded.
+# RUN: %lld -dylib -lSystem -o %t/weak-ar-weak-unref-dylib -L%t %t/weakfoo.a -lweakfoo
+# RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-ar-weak-unref-dylib | FileCheck %s --check-prefix=NO-SYM
+# RUN: %lld -dylib -lSystem -o %t/weak-unref-dylib-weak-ar -L%t -lweakfoo %t/weakfoo.a
+# RUN: llvm-objdump --macho --lazy-bind --syms %t/weak-unref-dylib-weak-ar | FileCheck %s --check-prefix=NO-SYM
+
+# NO-SYM: SYMBOL TABLE:
+# NO-SYM-NOT: _foo
+
#--- foo.s
.globl _foo
.section __TEXT,nonweak
Index: lld/MachO/SymbolTable.cpp
===================================================================
--- lld/MachO/SymbolTable.cpp
+++ lld/MachO/SymbolTable.cpp
@@ -184,10 +184,18 @@
bool wasInserted;
std::tie(s, wasInserted) = insert(name, file);
- if (wasInserted)
+ if (wasInserted) {
replaceSymbol<LazySymbol>(s, file, sym);
- else if (isa<Undefined>(s) || (isa<DylibSymbol>(s) && s->isWeakDef()))
+ } else if (isa<Undefined>(s)) {
file->fetch(sym);
+ } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {
+ if (dysym->isWeakDef()) {
+ if (dysym->getRefState() != RefState::Unreferenced)
+ file->fetch(sym);
+ else
+ replaceSymbol<LazySymbol>(s, file, sym);
+ }
+ }
return s;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115092.391800.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211204/8d62bb12/attachment.bin>
More information about the llvm-commits
mailing list