diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -227,6 +227,9 @@ return cast(isec); } +template +constexpr Ptr TombstoneValue = std::numeric_limits::max(); + // We need to apply the relocations to the pre-link compact unwind section // before converting it to post-link form. There should only be absolute // relocations here: since we are not emitting the pre-link CU section, there @@ -243,7 +246,7 @@ memcpy(buf, isec->data.data(), isec->data.size()); for (const Reloc &r : isec->relocs) { - uint64_t referentVA = UINT64_MAX; // Tombstone value + uint64_t referentVA = TombstoneValue; if (auto *referentSym = r.referent.dyn_cast()) { if (!isa(referentSym)) { assert(referentSym->isInGot()); @@ -303,7 +306,7 @@ std::vector> &cuVector) { DenseSet hasUnwindInfo; for (CompactUnwindEntry &cuEntry : cuVector) - if (cuEntry.functionAddress != UINT64_MAX) + if (cuEntry.functionAddress != TombstoneValue) hasUnwindInfo.insert(cuEntry.functionAddress); // Add explicit "has no unwind info" entries for all global and local symbols @@ -384,13 +387,13 @@ return a->functionAddress < b->functionAddress; }); - // Dead-stripped functions get a functionAddress of UINT64_MAX in + // Dead-stripped functions get a functionAddress of TombstoneValue in // relocateCompactUnwind(). Filter them out here. // FIXME: This doesn't yet collect associated data like LSDAs kept // alive only by a now-removed CompactUnwindEntry or other comdat-like // data (`kindNoneGroupSubordinate*` in ld64). CompactUnwindEntry tombstone; - tombstone.functionAddress = static_cast(UINT64_MAX); + tombstone.functionAddress = TombstoneValue; cuPtrVector.erase( std::lower_bound(cuPtrVector.begin(), cuPtrVector.end(), &tombstone, [](const CompactUnwindEntry *a, diff --git a/lld/test/MachO/compact-unwind.s b/lld/test/MachO/compact-unwind.s --- a/lld/test/MachO/compact-unwind.s +++ b/lld/test/MachO/compact-unwind.s @@ -4,21 +4,21 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/main.s -o %t/x86_64-main.o # RUN: %lld -arch x86_64 -pie -lSystem -lc++ %t/x86_64-my-personality.o %t/x86_64-main.o -o %t/x86_64-personality-first # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x100000000 -# RUN: %lld -arch x86_64 -pie -lSystem -lc++ %t/x86_64-main.o %t/x86_64-my-personality.o -o %t/x86_64-personality-second +# RUN: %lld -dead_strip -arch x86_64 -pie -lSystem -lc++ %t/x86_64-main.o %t/x86_64-my-personality.o -o %t/x86_64-personality-second # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x100000000 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 %t/my-personality.s -o %t/arm64-my-personality.o # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 %t/main.s -o %t/arm64-main.o # RUN: %lld -arch arm64 -pie -lSystem -lc++ %t/arm64-my-personality.o %t/arm64-main.o -o %t/arm64-personality-first # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x100000000 -# RUN: %lld -arch arm64 -pie -lSystem -lc++ %t/arm64-main.o %t/arm64-my-personality.o -o %t/arm64-personality-second +# RUN: %lld -dead_strip -arch arm64 -pie -lSystem -lc++ %t/arm64-main.o %t/arm64-my-personality.o -o %t/arm64-personality-second # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x100000000 # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %t/my-personality.s -o %t/arm64-32-my-personality.o # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %t/main.s -o %t/arm64-32-main.o # RUN: %lld-watchos -pie -lSystem -lc++ %t/arm64-32-my-personality.o %t/arm64-32-main.o -o %t/arm64-32-personality-first # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-32-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x4000 -# RUN: %lld-watchos -pie -lSystem -lc++ %t/arm64-32-main.o %t/arm64-32-my-personality.o -o %t/arm64-32-personality-second +# RUN: %lld-watchos -dead_strip -pie -lSystem -lc++ %t/arm64-32-main.o %t/arm64-32-my-personality.o -o %t/arm64-32-personality-second # RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-32-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x4000 # FIRST: Indirect symbols for (__DATA_CONST,__got) @@ -107,13 +107,16 @@ ## -fno-exceptions, while the previous and next TU might be Objective-C++ ## which has unwind info for Objective-C). .p2align 2 +.no_dead_strip _quux _quux: ret .globl _abs +.no_dead_strip _abs _abs = 4 .p2align 2 +.no_dead_strip _baz _baz: .cfi_startproc ## This will generate a symbol relocation. Check that we reuse the personality @@ -124,7 +127,18 @@ ret .cfi_endproc +.globl _stripped +_stripped: + .cfi_startproc + .cfi_personality 155, ___gxx_personality_v0 + .cfi_lsda 16, _exception1 + .cfi_def_cfa_offset 16 + ret + .cfi_endproc + .section __TEXT,__gcc_except_tab _exception1: .space 1 + +.subsections_via_symbols