Skip to content

Conversation

@DataCorrupted
Copy link
Member

Context: MachO defined section offset to be a 32-bit integer, meaning that each section must start within 4GB of the segment.

struct section_64 {
char sectname[16];
char segname[16];
uint64_t addr;
uint64_t size;
uint32_t offset;
uint32_t align;
uint32_t reloff;
uint32_t nreloc;
uint32_t flags;
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
};

Problem: With larger and larger dSYM we are running out of space. In our internal builds, __debug_str and __debug_line are the two biggest section each having more than 1GB, combined they pushed the last few sections out of the 4GB range.

This diff tries to mitigate that by moving one of the biggest sections to the last, buying our time to find a more permeant solutions

@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2025

@llvm/pr-subscribers-debuginfo

Author: Peter Rong (DataCorrupted)

Changes

Context: MachO defined section offset to be a 32-bit integer, meaning that each section must start within 4GB of the segment.

struct section_64 {
char sectname[16];
char segname[16];
uint64_t addr;
uint64_t size;
uint32_t offset;
uint32_t align;
uint32_t reloff;
uint32_t nreloc;
uint32_t flags;
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
};

Problem: With larger and larger dSYM we are running out of space. In our internal builds, __debug_str and __debug_line are the two biggest section each having more than 1GB, combined they pushed the last few sections out of the 4GB range.

This diff tries to mitigate that by moving one of the biggest sections to the last, buying our time to find a more permeant solutions


Full diff: https://github.com/llvm/llvm-project/pull/163603.diff

2 Files Affected:

  • (modified) llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp (+1-1)
  • (added) llvm/test/tools/dsymutil/X86/swift-ast-section-order.test (+19)
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..9d6818220c9d4
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/swift-ast-section-order.test
@@ -0,0 +1,19 @@
+# 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.
+# This is important for compatibility with tools that expect this ordering.
+# The ordering should be consistent regardless of whether the classic or parallel linker is used.
+
+# 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

@DataCorrupted
Copy link
Member Author

Closing in favor of #165940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants