[BOLT] fix DIE traversal incorrect loop termination condition. (#208450)

The DIE traversal loop in partitionCUs() used an incorrect termination
condition, causing it to read past the end of the CU. Fix the loop to
stop at NextCUOffset so traversal no longer runs beyond the unit's
boundary.

Fixed [#208440](https://github.com/llvm/llvm-project/issues/208440).
This commit is contained in:
Thrrreeee authored and GitHub committed 2026-07-13 10:59:06 +08:00
1 parent 461f0b699c
commit 171ba71128
3 files changed
+11 -11

No files matched your search

+5 -9
View File
@@ -590,11 +590,11 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
const uint64_t NextCUOffset = CU->getNextUnitOffset();
DWARFDataExtractor DebugInfoData = CU->getDebugInfoExtractor();
DWARFDebugInfoEntry DIEEntry;
SmallVector<uint32_t, 8> ParentIndex;
ParentIndex.push_back(UINT32_MAX);
do {
// extractFast() here only attributes are inspected here, so ParentIdx is
// passed as a dummy value.
while (DIEOffset < NextCUOffset) {
if (!DIEEntry.extractFast(*CU, &DIEOffset, DebugInfoData, NextCUOffset,
ParentIndex.back()))
/*ParentIdx=*/0))
break;
const DWARFAbbreviationDeclaration *Abbrev =
DIEEntry.getAbbreviationDeclarationPtr();
@@ -617,12 +617,8 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
EC.unionSets(CU, TargetCU);
}
}
if (Abbrev->hasChildren())
ParentIndex.push_back(0);
} else {
ParentIndex.pop_back();
}
} while (!ParentIndex.empty());
}
}
DenseMap<DWARFUnit *, SmallVector<DWARFUnit *>> MembersByLeader;
+3 -1
View File
@@ -2,13 +2,15 @@
; RUN: llvm-mc -dwarf-version=4 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf4-cross-cu-with-loclist.s -o %t.o
; RUN: %clang %cflags -nostdlib -no-pie %t.o -o %t.exe
; RUN: llvm-bolt %t.exe -o %t.exe.bolt --update-debug-sections --always-convert-to-ranges --debug-thread-count=4
; RUN: llvm-bolt %t.exe -o %t.exe.bolt --update-debug-sections --always-convert-to-ranges --debug-thread-count=4 2>&1 | FileCheck %s --check-prefix=BOLT
; RUN: llvm-objdump --disassemble %t.exe.bolt > %t.txt
; RUN: llvm-dwarfdump --show-form --verbose --debug-info --debug-ranges %t.exe.bolt >> %t.txt
; RUN: FileCheck %s --input-file=%t.txt
;; Test that two cross-referenced CUs processed in the same bucket keep their own .debug_ranges entries.
; BOLT-NOT: warning: DWARF unit from offset {{.*}} incl. to offset {{.*}} excl. tries to read DIEs at offset {{.*}}
; CHECK: <main>:
; CHECK-NEXT: [[#%.6x,MAIN:]]
; CHECK: <_Z4foo2i>:
+3 -1
View File
@@ -3,12 +3,14 @@
# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -o %tmain.o
# RUN: %clang %cflags -dwarf-5 %tmain.o -o %t.exe -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections
# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections 2>&1 | FileCheck %s --check-prefix=BOLT
# RUN: llvm-dwarfdump --debug-info -r 0 --debug-names %t.bolt > %t.txt
# RUN: cat %t.txt | FileCheck --check-prefix=CHECK %s
## This test checks that BOLT generates Entries for DW_AT_abstract_origin when it has cross cu reference.
# BOLT-NOT: warning: DWARF unit from offset {{.*}} incl. to offset {{.*}} excl. tries to read DIEs at offset {{.*}}
# CHECK: [[OFFSET1:0x[0-9a-f]*]]: Compile Unit
# CHECK: [[OFFSET2:0x[0-9a-f]*]]: Compile Unit
# CHECK: Name Index @ 0x0 {