diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -292,9 +292,9 @@ continue; // Linear search is fast enough for a small array. auto it = find(personalities, cu->personality); - uint32_t personalityIndex; // 1-based index + uint32_t personalityIndex; // 0-based index if (it != personalities.end()) { - personalityIndex = std::distance(personalities.begin(), it) + 1; + personalityIndex = std::distance(personalities.begin(), it); } else { personalities.push_back(cu->personality); personalityIndex = personalities.size(); @@ -303,7 +303,8 @@ personalityIndex << countTrailingZeros( static_cast(UNWIND_PERSONALITY_MASK)); } - if (personalities.size() > 3) + + if (personalities.size() > 4) error("too many personalities (" + std::to_string(personalities.size()) + ") for compact unwind to encode"); } diff --git a/lld/test/MachO/invalid/compact-unwind-personalities.s b/lld/test/MachO/invalid/compact-unwind-personalities.s --- a/lld/test/MachO/invalid/compact-unwind-personalities.s +++ b/lld/test/MachO/invalid/compact-unwind-personalities.s @@ -2,10 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %s -o %t.o # RUN: not %lld -pie -lSystem -lc++ %t.o -o %t 2>&1 | FileCheck %s --check-prefix=TOO-MANY # RUN: not %lld -pie -lSystem %t.o -o %t 2>&1 | FileCheck %s --check-prefix=UNDEF -# TOO-MANY: error: too many personalities (4) for compact unwind to encode +# TOO-MANY: error: too many personalities (5) for compact unwind to encode # UNDEF: error: undefined symbol: ___gxx_personality_v0 -.globl _main, _personality_1, _personality_2, _personality_3 +.globl _main, _personality_1, _personality_2, _personality_3, _personality_4 .text @@ -30,6 +30,13 @@ retq .cfi_endproc +_bas: + .cfi_startproc + .cfi_personality 155, _personality_4 + .cfi_def_cfa_offset 16 + retq + .cfi_endproc + _main: .cfi_startproc .cfi_personality 155, ___gxx_personality_v0 @@ -43,3 +50,5 @@ retq _personality_3: retq +_personality_4: + retq diff --git a/lld/test/MachO/invalid/compact-unwind-personalities.s b/lld/test/MachO/valid-personalities-count.s copy from lld/test/MachO/invalid/compact-unwind-personalities.s copy to lld/test/MachO/valid-personalities-count.s --- a/lld/test/MachO/invalid/compact-unwind-personalities.s +++ b/lld/test/MachO/valid-personalities-count.s @@ -1,9 +1,9 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %s -o %t.o -# RUN: not %lld -pie -lSystem -lc++ %t.o -o %t 2>&1 | FileCheck %s --check-prefix=TOO-MANY -# RUN: not %lld -pie -lSystem %t.o -o %t 2>&1 | FileCheck %s --check-prefix=UNDEF -# TOO-MANY: error: too many personalities (4) for compact unwind to encode -# UNDEF: error: undefined symbol: ___gxx_personality_v0 +# RUN: not %lld -pie -lSystem %t.o -o %t 2>&1 | FileCheck %s +# CHECK-NOT: too many personalities (4) + + .globl _main, _personality_1, _personality_2, _personality_3