diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -509,8 +509,13 @@ encodingFrequencies[cuEntries[idx].encoding]++; // Make a vector of encodings, sorted by descending frequency - for (const auto &frequency : encodingFrequencies) + for (const auto &frequency : encodingFrequencies) { + // Don't put encodings with only 1 usage into the table. + if (frequency.second < 2) continue; + commonEncodings.emplace_back(frequency); + } + llvm::sort(commonEncodings, [](const std::pair &a, const std::pair &b) { diff --git a/lld/test/MachO/fold-common-encoding.s b/lld/test/MachO/fold-common-encoding.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/fold-common-encoding.s @@ -0,0 +1,71 @@ +# REQUIRES: x86 +# RUN: rm -rf %t; split-file %s %t + +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/main.s -o %t/main.o +# RUN: %lld -arch x86_64 -lSystem -lc++ %t/main.o -o %t/a.out + +# RUN: llvm-objdump --macho --unwind-info %t/a.out | FileCheck %s + +CHECK: Contents of __unwind_info section: +CHECK: Version: 0x1 +CHECK: Common encodings array section offset: 0x1c +CHECK: Number of common encodings in array: 0x1 +CHECK: Personality function array section offset: 0x20 +CHECK: Number of personality functions in array: 0x1 +CHECK: Index array section offset: 0x24 +CHECK: Number of indices in array: 0x2 +CHECK: Common encodings: (count = 1) +CHECK: encoding[0]: 0x[[#%x, COMMON_ENC:]] +CHECK: Second level indices: +CHECK: Second level index[0]: offset in section={{.+}} +CHECK: Page encodings: (count = 1) +CHECK: encoding[1]: 0x[[#%x, SINGLE_ENC:]] +CHECK: [0]: function offset=0x{{.+}}, encoding[0]=0x[[#%.8x, COMMON_ENC]] +CHECK: [1]: function offset=0x{{.+}}, encoding[0]=0x[[#%.8x, COMMON_ENC]] +CHECK: [2]: function offset=0x{{.+}}, encoding[1]=0x[[#%.8x, SINGLE_ENC]] + + +#--- main.s +.globl _main + +.globl _f +.p2align 4, 0x90 +_f: + .cfi_startproc + subq $3272, %rsp + .cfi_def_cfa_offset 3280 + addq $3272, %rsp + retq + .cfi_endproc + +.globl _ff +.p2align 4, 0x90 +_ff: + .cfi_startproc + subq $3272, %rsp + .cfi_def_cfa_offset 3280 + retq + .cfi_endproc + +.text +.p2align 2 +_main: + .cfi_startproc + callq _f + callq _ff + .cfi_personality 155, ___gxx_personality_v0 + .cfi_lsda 16, _exception1 + .cfi_def_cfa_offset 16 + ret + .cfi_endproc + ret + + +.globl _exception1 +.section __TEXT,__gcc_except_tab +_exception1: + .space 1 + + + +.subsections_via_symbols