[lld/mac] Fix bug in interaction of -dead_strip and -undefined dynamic_lookup

We lost the `used` bit on the Undefined when we replaced it with a DylibSymbol
in treatUndefined().

Differential Revision: https://reviews.llvm.org/D106565
This commit is contained in:
Nico Weber 2021-07-22 11:37:29 -04:00
parent 0cf65382ad
commit 5ae39d4f97
3 changed files with 21 additions and 0 deletions

View File

@ -306,8 +306,10 @@ T *replaceSymbol(Symbol *s, ArgT &&...arg) {
"Not a Symbol");
bool isUsedInRegularObj = s->isUsedInRegularObj;
bool used = s->used;
T *sym = new (s) T(std::forward<ArgT>(arg)...);
sym->isUsedInRegularObj |= isUsedInRegularObj;
sym->used |= used;
return sym;
}

View File

@ -611,6 +611,7 @@ static bool needsBinding(const Symbol *sym) {
static void prepareSymbolRelocation(Symbol *sym, const InputSection *isec,
const Reloc &r) {
assert(sym->isLive());
const RelocAttrs &relocAttrs = target->getRelocAttrs(r.type);
if (relocAttrs.hasAttr(RelocAttrBits::BRANCH)) {

View File

@ -173,6 +173,18 @@
# RUN: %lld -lSystem -dead_strip %t/strip-dylib-ref.o %t/dylib.dylib \
# RUN: -o %t/strip-dylib-ref -U _ref_undef_fun
## Check that referenced undefs are kept with -undefined dynamic_lookup.
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
# RUN: %t/ref-undef.s -o %t/ref-undef.o
# RUN: %lld -lSystem -dead_strip %t/ref-undef.o \
# RUN: -o %t/ref-undef -undefined dynamic_lookup
# RUN: llvm-objdump --syms --lazy-bind %t/ref-undef | \
# RUN: FileCheck --check-prefix=STRIPDYNLOOKUP %s
# STRIPDYNLOOKUP: SYMBOL TABLE:
# STRIPDYNLOOKUP: *UND* _ref_undef_fun
# STRIPDYNLOOKUP: Lazy bind table:
# STRIPDYNLOOKUP: __DATA __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun
## S_ATTR_LIVE_SUPPORT tests.
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
# RUN: %t/live-support.s -o %t/live-support.o
@ -812,3 +824,9 @@ _more_data:
.quad L._bar4
.subsections_via_symbols
#--- ref-undef.s
.globl _main
_main:
callq _ref_undef_fun
.subsections_via_symbols