[llvm] [BOLT][DWARF] Avoid invalid work if DWO id is zero (PR #154749)
Jinjie Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 06:59:11 PDT 2025
https://github.com/Jinjie-Huang updated https://github.com/llvm/llvm-project/pull/154749
>From b6c3f3c5f3b2651b989462cc4f0d2614bc418f76 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Thu, 21 Aug 2025 21:29:01 +0800
Subject: [PATCH 1/2] Avoid unnecessary work if DWO id is zero
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 0c1a1bac6c72e..bcde3ccfa691e 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -613,6 +613,7 @@ void DWARFRewriter::updateDebugInfo() {
auto createRangeLocListAddressWriters = [&](DWARFUnit &CU) {
std::lock_guard<std::mutex> Lock(AccessMutex);
const uint16_t DwarfVersion = CU.getVersion();
+ std::optional<uint64_t> DWOId = CU.getDWOId();
if (DwarfVersion >= 5) {
auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
&BC, CU.getAddressByteSize(), CU.getAddrOffsetSectionBase());
@@ -620,7 +621,7 @@ void DWARFRewriter::updateDebugInfo() {
LocListWritersByCU[CUIndex] =
std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false, *AddrW);
- if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
+ if (DWOId && *DWOId != 0) {
assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
"RangeLists writer for DWO unit already exists.");
auto DWORangeListsSectionWriter =
@@ -635,7 +636,7 @@ void DWARFRewriter::updateDebugInfo() {
std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
- if (std::optional<uint64_t> DWOId = CU.getDWOId()) {
+ if (DWOId && *DWOId != 0) {
assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
"LegacyRangeLists writer for DWO unit already exists.");
auto LegacyRangesSectionWriterByCU =
>From f8c96a9654a51edbe476eb9a5ec265e8db61d8f9 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Thu, 28 Aug 2025 21:57:48 +0800
Subject: [PATCH 2/2] Skip updating DWO CUs whose DWO ID is 0.
---
bolt/lib/Rewrite/DWARFRewriter.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index bcde3ccfa691e..1eb7932edbc2b 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -614,6 +614,8 @@ void DWARFRewriter::updateDebugInfo() {
std::lock_guard<std::mutex> Lock(AccessMutex);
const uint16_t DwarfVersion = CU.getVersion();
std::optional<uint64_t> DWOId = CU.getDWOId();
+ if (DWOId && *DWOId == 0)
+ return;
if (DwarfVersion >= 5) {
auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
&BC, CU.getAddressByteSize(), CU.getAddrOffsetSectionBase());
@@ -621,7 +623,7 @@ void DWARFRewriter::updateDebugInfo() {
LocListWritersByCU[CUIndex] =
std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false, *AddrW);
- if (DWOId && *DWOId != 0) {
+ if (DWOId) {
assert(RangeListsWritersByCU.count(*DWOId) == 0 &&
"RangeLists writer for DWO unit already exists.");
auto DWORangeListsSectionWriter =
@@ -636,7 +638,7 @@ void DWARFRewriter::updateDebugInfo() {
std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize());
AddressWritersByCU[CU.getOffset()] = std::move(AddrW);
LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
- if (DWOId && *DWOId != 0) {
+ if (DWOId) {
assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
"LegacyRangeLists writer for DWO unit already exists.");
auto LegacyRangesSectionWriterByCU =
@@ -733,7 +735,7 @@ void DWARFRewriter::updateDebugInfo() {
createRangeLocListAddressWriters(*CU);
std::optional<DWARFUnit *> SplitCU;
std::optional<uint64_t> DWOId = CU->getDWOId();
- if (DWOId)
+ if (DWOId && *DWOId != 0)
SplitCU = BC.getDWOCU(*DWOId);
if (!SplitCU)
continue;
More information about the llvm-commits
mailing list