[PATCH] D136374: [lld-macho] Don't put entries with less than 2 usages into the common table.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 13:12:31 PDT 2022


oontvoo created this revision.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This matches LD64's handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136374

Files:
  lld/MachO/UnwindInfoSection.cpp
  lld/test/MachO/fold-common-encoding.s


Index: lld/test/MachO/fold-common-encoding.s
===================================================================
--- /dev/null
+++ 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
Index: lld/MachO/UnwindInfoSection.cpp
===================================================================
--- lld/MachO/UnwindInfoSection.cpp
+++ 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<compact_unwind_encoding_t, size_t> &a,
                 const std::pair<compact_unwind_encoding_t, size_t> &b) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136374.469330.patch
Type: text/x-patch
Size: 2825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/735fedeb/attachment.bin>


More information about the llvm-commits mailing list