[llvm] [DWARFLinker] Move __debug_str to the last section (PR #163603)
Peter Rong via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 15 15:39:21 PDT 2025
https://github.com/DataCorrupted updated https://github.com/llvm/llvm-project/pull/163603
>From 5de7371a41ebdcbab5c3076e6dd768d7243134e9 Mon Sep 17 00:00:00 2001
From: Peter Rong <PeterRong at meta.com>
Date: Wed, 15 Oct 2025 10:39:04 -0700
Subject: [PATCH] [DWARFLinker] Move __debug_str to the last section
Signed-off-by: Peter Rong <PeterRong at meta.com>
---
llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp | 2 +-
.../dsymutil/X86/swift-ast-section-order.test | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/tools/dsymutil/X86/swift-ast-section-order.test
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 8052773812a2c..ab7cd4d8d6273 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -3129,7 +3129,6 @@ Error DWARFLinker::link() {
// Emit everything that's global.
if (TheDwarfEmitter != nullptr) {
TheDwarfEmitter->emitAbbrevs(Abbreviations, Options.TargetDWARFVersion);
- TheDwarfEmitter->emitStrings(DebugStrPool);
TheDwarfEmitter->emitStringOffsets(StringOffsetPool.getValues(),
Options.TargetDWARFVersion);
TheDwarfEmitter->emitLineStrings(DebugLineStrPool);
@@ -3150,6 +3149,7 @@ Error DWARFLinker::link() {
break;
}
}
+ TheDwarfEmitter->emitStrings(DebugStrPool);
}
};
diff --git a/llvm/test/tools/dsymutil/X86/swift-ast-section-order.test b/llvm/test/tools/dsymutil/X86/swift-ast-section-order.test
new file mode 100644
index 0000000000000..b53a73b0aec76
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/swift-ast-section-order.test
@@ -0,0 +1,17 @@
+# Check that the __debug_str section is last in the output
+
+# RUN: rm -rf %t && mkdir %t
+# RUN: dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -o %t/swift-ast.dSYM -verbose -no-swiftmodule-timestamp
+# RUN: llvm-dwarfdump --show-section-sizes %t/swift-ast.dSYM/Contents/Resources/DWARF/swift-ast.macho.x86_64 | FileCheck %s
+
+# This test verifies that the __debug_str section appears last in the section list.
+
+# CHECK: SECTION
+# CHECK: __swift_ast
+# CHECK: __debug_abbrev
+# CHECK: __apple_namespac
+# CHECK: __apple_names
+# CHECK: __apple_types
+# CHECK: __apple_objc
+# CHECK-NOT: __apple
+# CHECK: __debug_str
More information about the llvm-commits
mailing list