[llvm] [dsymutil] Add missing validation for zero alignment section (PR #168925)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 10:13:59 PST 2025


https://github.com/Ch111p created https://github.com/llvm/llvm-project/pull/168925

Section alignments in the DWARF segment are often zero by default. Therefore, the validation logic must be placed outside the alignUp path; otherwise, dsymutil may generate an invalid Mach-O file.

>From b86d17b0e77e8031984670435166ddc6fa8810de Mon Sep 17 00:00:00 2001
From: ch1p <hduch1p at gmail.com>
Date: Fri, 21 Nov 2025 02:03:38 +0800
Subject: [PATCH] [dsymutil] Add missing validation for zero alignment section

---
 llvm/tools/dsymutil/MachOUtils.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp
index 362a999515683..fba698896618b 100644
--- a/llvm/tools/dsymutil/MachOUtils.cpp
+++ b/llvm/tools/dsymutil/MachOUtils.cpp
@@ -339,11 +339,11 @@ static bool createDwarfSegment(const MCAssembler& Asm,uint64_t VMAddr, uint64_t
     if (Alignment > 1) {
       VMAddr = alignTo(VMAddr, Alignment);
       FileOffset = alignTo(FileOffset, Alignment);
-      if (FileOffset > UINT32_MAX)
-        return error("section " + Sec->getName() +
-                     "'s file offset exceeds 4GB."
-                     " Refusing to produce an invalid Mach-O file.");
     }
+    if (FileOffset > UINT32_MAX)
+      return error("section " + Sec->getName() +
+                   "'s file offset exceeds 4GB."
+                   " Refusing to produce an invalid Mach-O file.");
     Writer.writeSection(Asm, *Sec, VMAddr, FileOffset, 0, 0, 0);
 
     FileOffset += Asm.getSectionAddressSize(*Sec);



More information about the llvm-commits mailing list