[llvm] [NFC][BOLT] fix DIE traversal incorrect loop termination condition. (PR #208450)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 00:01:42 PDT 2026
https://github.com/Thrrreeee updated https://github.com/llvm/llvm-project/pull/208450
>From 7650fb1d4e73f088c2460f9093559add36607408 Mon Sep 17 00:00:00 2001
From: shijinrui <shijinrui at bytedance.com>
Date: Thu, 9 Jul 2026 20:30:29 +0800
Subject: [PATCH 1/3] [NFC][BOLT] fix DIE traversal incorrect loop termination
condition
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 31bb74a6488a6..5e7b2a9e05aa8 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -591,6 +591,8 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
DWARFDataExtractor DebugInfoData = CU->getDebugInfoExtractor();
DWARFDebugInfoEntry DIEEntry;
SmallVector<uint32_t, 8> ParentIndex;
+ // The initial entry is an artificial root. The unit's terminating null DIE
+ // only pops back to this root, so stop before reading past NextCUOffset.
ParentIndex.push_back(UINT32_MAX);
do {
if (!DIEEntry.extractFast(*CU, &DIEOffset, DebugInfoData, NextCUOffset,
@@ -622,7 +624,7 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
} else {
ParentIndex.pop_back();
}
- } while (!ParentIndex.empty());
+ } while (DIEOffset < NextCUOffset);
}
DenseMap<DWARFUnit *, SmallVector<DWARFUnit *>> MembersByLeader;
>From 591262266b75b5a13fe6dde83ab45ab2270bf8d7 Mon Sep 17 00:00:00 2001
From: shijinrui <shijinrui at bytedance.com>
Date: Fri, 10 Jul 2026 14:57:32 +0800
Subject: [PATCH 2/3] fix
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 16 +++++-----------
bolt/test/X86/dwarf4-cross-cu-ranges.test | 4 +++-
bolt/test/X86/dwarf5-debug-names-cross-cu.s | 4 +++-
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 5e7b2a9e05aa8..713a39ede161c 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -590,13 +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;
- // The initial entry is an artificial root. The unit's terminating null DIE
- // only pops back to this root, so stop before reading past NextCUOffset.
- 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();
@@ -619,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 (DIEOffset < NextCUOffset);
+ }
}
DenseMap<DWARFUnit *, SmallVector<DWARFUnit *>> MembersByLeader;
diff --git a/bolt/test/X86/dwarf4-cross-cu-ranges.test b/bolt/test/X86/dwarf4-cross-cu-ranges.test
index 2e784311c2af2..860af97901fbb 100644
--- a/bolt/test/X86/dwarf4-cross-cu-ranges.test
+++ b/bolt/test/X86/dwarf4-cross-cu-ranges.test
@@ -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>:
diff --git a/bolt/test/X86/dwarf5-debug-names-cross-cu.s b/bolt/test/X86/dwarf5-debug-names-cross-cu.s
index 73c50d6d41db0..3f4188240d698 100644
--- a/bolt/test/X86/dwarf5-debug-names-cross-cu.s
+++ b/bolt/test/X86/dwarf5-debug-names-cross-cu.s
@@ -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 {
>From aa30ddac14443eba53a3556a9712cff153c9b073 Mon Sep 17 00:00:00 2001
From: shijinrui <shijinrui at bytedance.com>
Date: Fri, 10 Jul 2026 15:01:17 +0800
Subject: [PATCH 3/3] fix format
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 713a39ede161c..6c322be095c92 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -590,8 +590,8 @@ static SmallVector<SmallVector<DWARFUnit *>> partitionCUs(DWARFContext &DwCtx,
const uint64_t NextCUOffset = CU->getNextUnitOffset();
DWARFDataExtractor DebugInfoData = CU->getDebugInfoExtractor();
DWARFDebugInfoEntry DIEEntry;
- // extractFast() here only attributes are inspected here, so ParentIdx is passed
- // as a dummy value.
+ // 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,
/*ParentIdx=*/0))
More information about the llvm-commits
mailing list