[PATCH] D104084: [lld-macho] Add options -(no_)keep_dwarf_unwind
Greg McGary via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 10 18:18:30 PDT 2021
gkm created this revision.
gkm added a reviewer: lld-macho.
Herald added a subscriber: dang.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
gkm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
DWARF unwind info was superseded by compact unwind as-of macOS 10.9 and iOS 7.0
(circa 2013). Most often, DWARF unwind info is entirely redundant and can be
discarded. In rare instances, complex unwind info cannot be represented by a
compact-unwind entry, and we fall-back to the DWARF frame info.
The intelligent approach is to filter-out all redundant entries in the
`__TEXT,__eh_frame` section, leaving only those that are necessary fallbacks
when compact unwind is insufficient. However, that's not easy, so unless and
until we have a use case that requires the intelligent approach, we offer the
choice of all or nothing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104084
Files:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
lld/test/MachO/eh_frame.s
Index: lld/test/MachO/eh_frame.s
===================================================================
--- /dev/null
+++ lld/test/MachO/eh_frame.s
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: rm -rf %t; mkdir -p %t
+
+## Verify that __TEXT,__eh_frame is either retained or omitted from the
+## linker output, according to command-line options -(no_)keep_dwarf_unwind
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
+# RUN: %lld -o %t/keep %t/main.o -lSystem -keep_dwarf_unwind
+# RUN: %lld -o %t/toss %t/main.o -lSystem -no_keep_dwarf_unwind
+# RUN: %lld -o %t/default %t/main.o -lSystem
+
+# RUN: llvm-objdump -h %t/keep | FileCheck %s --check-prefixes=KEEP
+# RUN: llvm-objdump -h %t/toss | FileCheck %s --check-prefixes=TOSS
+# RUN: llvm-objdump -h %t/default | FileCheck %s --check-prefixes=TOSS
+
+# KEEP-LABEL: {{^}}Sections:
+# KEEP: [[#]] __eh_frame {{.*}} DATA
+
+# TOSS-LABEL: {{^}}Sections:
+# TOSS-NOT: [[#]] __eh_frame {{.*}} DATA
+
+.text
+.global _main
+_main:
+ ret
+
+.section __TEXT,__eh_frame
+.fill 8, 8
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -1245,12 +1245,10 @@
Flags<[HelpHidden]>,
Group<grp_undocumented>;
def keep_dwarf_unwind : Flag<["-"], "keep_dwarf_unwind">,
- HelpText<"This option is undocumented in ld64">,
- Flags<[HelpHidden]>,
+ HelpText<"Retain the __TEXT,__eh_frame section">,
Group<grp_undocumented>;
def no_keep_dwarf_unwind : Flag<["-"], "no_keep_dwarf_unwind">,
- HelpText<"This option is undocumented in ld64">,
- Flags<[HelpHidden]>,
+ HelpText<"Omit the __TEXT,__eh_frame section (default)">,
Group<grp_undocumented>;
def kext : Flag<["-"], "kext">,
HelpText<"This option is undocumented in ld64">,
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -265,6 +265,9 @@
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
for (const Section &sec : sections) {
+ if (!config->keepDwarfUnwind &&
+ strcmp(sec.sectname, section_names::ehFrame) == 0)
+ continue;
if (config->dedupLiterals && sectionType(sec.flags) == S_CSTRING_LITERALS) {
if (sec.nreloc)
fatal(toString(this) + " contains relocations in " + sec.segname + "," +
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1185,6 +1185,9 @@
(config->arch() == AK_arm64 || config->arch() == AK_arm64e) &&
config->platform() == PlatformKind::macOS);
+ config->keepDwarfUnwind =
+ args.hasFlag(OPT_keep_dwarf_unwind, OPT_no_keep_dwarf_unwind, false);
+
if (args.hasArg(OPT_v)) {
message(getLLDVersion());
message(StringRef("Library search paths:") +
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -128,6 +128,7 @@
bool deadStripDylibs = false;
bool demangle = false;
bool deadStrip = false;
+ bool keepDwarfUnwind = false;
PlatformInfo platformInfo;
NamespaceKind namespaceKind = NamespaceKind::twolevel;
UndefinedSymbolTreatment undefinedSymbolTreatment =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104084.351322.patch
Type: text/x-patch
Size: 3351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/01f4fa8f/attachment.bin>
More information about the llvm-commits
mailing list