[PATCH] D132489: [MachO] Fix dead-stripping __eh_frame
Shoaib Meenai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 10:54:04 PDT 2022
smeenai updated this revision to Diff 454897.
smeenai added a comment.
Clear lint warning
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132489/new/
https://reviews.llvm.org/D132489
Files:
lld/MachO/InputFiles.cpp
lld/test/MachO/eh-frame-dead-strip.s
Index: lld/test/MachO/eh-frame-dead-strip.s
===================================================================
--- /dev/null
+++ lld/test/MachO/eh-frame-dead-strip.s
@@ -0,0 +1,37 @@
+# REQUIRES: aarch64
+# RUN: rm -rf %t; split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11.0 %t/strong.s -o %t/strong.o
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11.0 %t/weak.s -o %t/weak.o
+# RUN: %lld -arch arm64 -dylib -dead_strip %t/strong.o %t/weak.o -o %t/libstrongweak.dylib
+# RUN: llvm-dwarfdump --eh-frame %t/libstrongweak.dylib | FileCheck %s
+
+## Verify that unneeded FDEs (and their CIEs) are dead-stripped even if they
+## point to a live symbol. This requires arm64 because x86_64 doesn't emit
+## a relocation for the function symbol in an FDE.
+
+# CHECK: .eh_frame contents:
+# CHECK: 00000000 00000010 00000000 CIE
+# CHECK: 00000014 00000020 00000018 FDE cie=00000000
+# CHECK-NOT: CIE
+# CHECK-NOT: FDE
+
+#--- strong.s
+.globl _fun
+_fun:
+ .cfi_startproc
+ .cfi_def_cfa_offset 0
+ ## cfi_escape cannot be encoded in compact unwind
+ .cfi_escape 0x2e, 0x10
+ ret
+ .cfi_endproc
+
+#--- weak.s
+.globl _fun
+.weak_definition _fun
+_fun:
+ .cfi_startproc
+ .cfi_def_cfa_offset 0
+ ## cfi_escape cannot be encoded in compact unwind
+ .cfi_escape 0x2e, 0x10
+ ret
+ .cfi_endproc
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -1593,6 +1593,15 @@
funcSym->unwindEntry = isec;
ehRelocator.commit();
}
+
+ // __eh_frame is marked as S_ATTR_LIVE_SUPPORT in input files, because FDEs
+ // are normally required to be kept alive if they reference a live symbol.
+ // However, we've explicitly marked a dependency from a symbol to its FDE, so
+ // dead-stripping will just work as usual, and S_ATTR_LIVE_SUPPORT will just
+ // incorrectly prevent us from dead-stripping duplicate FDEs for a live symbol
+ // (e.g. if there were multiple weak copies). Remove this flag and just let
+ // dead-stripping proceed as normal.
+ ehFrameSection.flags &= ~S_ATTR_LIVE_SUPPORT;
}
std::string ObjFile::sourceFile() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132489.454897.patch
Type: text/x-patch
Size: 2196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/c48a8a4e/attachment.bin>
More information about the llvm-commits
mailing list