[llvm] [BOLT][DWARF] Get DWO file via a relative path if the CompilationDir does not exist (PR #154515)
Jinjie Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 07:51:33 PDT 2025
https://github.com/Jinjie-Huang updated https://github.com/llvm/llvm-project/pull/154515
>From a21d0a85de4ce030a13600a37ae4bce85cfcf984 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Wed, 20 Aug 2025 20:24:08 +0800
Subject: [PATCH 1/2] support dwo relative path in BOLT
---
bolt/lib/Core/BinaryContext.cpp | 5 ++++-
bolt/lib/Rewrite/DWARFRewriter.cpp | 2 ++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index dd0d041692484..e20c7fc113007 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -33,6 +33,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Regex.h"
#include <algorithm>
#include <functional>
@@ -1636,7 +1637,9 @@ void BinaryContext::preprocessDWODebugInfo() {
if (!opts::CompDirOverride.empty()) {
sys::path::append(AbsolutePath, opts::CompDirOverride);
sys::path::append(AbsolutePath, DWOName);
- }
+ } else if (!sys::fs::exists(DwarfUnit->getCompilationDir()) &&
+ sys::fs::exists(DWOName))
+ AbsolutePath = DWOName;
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 0c1a1bac6c72e..80b24a5561e81 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -1851,6 +1851,8 @@ void DWARFRewriter::writeDWOFiles(
CompDir = opts::DwarfOutputPath.c_str();
else if (!opts::CompDirOverride.empty())
CompDir = opts::CompDirOverride;
+ else if (!sys::fs::exists(CompDir))
+ CompDir = ".";
SmallString<16> AbsolutePath;
sys::path::append(AbsolutePath, CompDir);
>From 85193436e42783672e5bdb07f50b9580b68564d7 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Thu, 4 Sep 2025 22:50:48 +0800
Subject: [PATCH 2/2] add test
---
bolt/lib/Core/BinaryContext.cpp | 6 +++++-
bolt/lib/Rewrite/DWARFRewriter.cpp | 4 ++--
bolt/test/dwo-name-retrieving.c | 16 ++++++++++++++++
3 files changed, 23 insertions(+), 3 deletions(-)
create mode 100755 bolt/test/dwo-name-retrieving.c
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index e20c7fc113007..06dc1e9245064 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1638,8 +1638,12 @@ void BinaryContext::preprocessDWODebugInfo() {
sys::path::append(AbsolutePath, opts::CompDirOverride);
sys::path::append(AbsolutePath, DWOName);
} else if (!sys::fs::exists(DwarfUnit->getCompilationDir()) &&
- sys::fs::exists(DWOName))
+ sys::fs::exists(DWOName)) {
+ this->outs()
+ << "BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for "
+ << DWOName << ". DWO Name will be directly used for retrieving.\n";
AbsolutePath = DWOName;
+ }
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 80b24a5561e81..a4a614e9dcd8e 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -1851,8 +1851,8 @@ void DWARFRewriter::writeDWOFiles(
CompDir = opts::DwarfOutputPath.c_str();
else if (!opts::CompDirOverride.empty())
CompDir = opts::CompDirOverride;
- else if (!sys::fs::exists(CompDir))
- CompDir = ".";
+ else if (!sys::fs::exists(CompDir) && sys::fs::exists(DWOName))
+ CompDir = "";
SmallString<16> AbsolutePath;
sys::path::append(AbsolutePath, CompDir);
diff --git a/bolt/test/dwo-name-retrieving.c b/bolt/test/dwo-name-retrieving.c
new file mode 100755
index 0000000000000..a3da78fc88ed2
--- /dev/null
+++ b/bolt/test/dwo-name-retrieving.c
@@ -0,0 +1,16 @@
+// This test checks retrieving dwo file diercetly with dwo name,
+// if the Debug Compilation Dir does not exist.
+
+int main() { return 0; }
+
+// RUN: rm -rf %t && mkdir -p %t && cd %t
+// RUN: %clang %cflags -g -gsplit-dwarf -fdebug-compilation-dir=/path/does/not/exist %s -o main.exe
+// RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s -check-prefix=NOT-EXIST
+
+// NOT-EXIST: BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for
+
+// RUN: rm -rf %t && mkdir -p %t && cd %t
+// RUN: %clang %cflags -g -gsplit-dwarf -fdebug-compilation-dir=/path/does/not/exist %s -o %t/main.exe
+// RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s -check-prefix=FOUND
+
+// FOUND-NOT: Debug Fission: DWO debug information for
More information about the llvm-commits
mailing list