[PATCH] D105399: [lld/mac] Don't crash on 32-bit output binaries when dead-stripping

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 3 18:59:31 PDT 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a reviewer: int3.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
thakis requested review of this revision.

Fixes PR50974.


https://reviews.llvm.org/D105399

Files:
  lld/MachO/UnwindInfoSection.cpp
  lld/test/MachO/compact-unwind.s


Index: lld/test/MachO/compact-unwind.s
===================================================================
--- lld/test/MachO/compact-unwind.s
+++ 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
Index: lld/MachO/UnwindInfoSection.cpp
===================================================================
--- lld/MachO/UnwindInfoSection.cpp
+++ lld/MachO/UnwindInfoSection.cpp
@@ -303,7 +303,7 @@
     std::vector<CompactUnwindEntry<Ptr>> &cuVector) {
   DenseSet<Ptr> hasUnwindInfo;
   for (CompactUnwindEntry<Ptr> &cuEntry : cuVector)
-    if (cuEntry.functionAddress != UINT64_MAX)
+    if (cuEntry.functionAddress != static_cast<Ptr>(UINT64_MAX))
       hasUnwindInfo.insert(cuEntry.functionAddress);
 
   // Add explicit "has no unwind info" entries for all global and local symbols


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105399.356356.patch
Type: text/x-patch
Size: 4199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210704/14280a58/attachment-0001.bin>


More information about the llvm-commits mailing list