[llvm] [BOLT] 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
Wed Aug 20 04:16:30 PDT 2025


https://github.com/Jinjie-Huang created https://github.com/llvm/llvm-project/pull/154515

None

>From d0e562405df02a879ac316ae655625f133f1005c Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Wed, 20 Aug 2025 18:35:56 +0800
Subject: [PATCH] support dwo relative path in BOLT

---
 bolt/lib/Core/BinaryContext.cpp    | 6 ++++++
 bolt/lib/Rewrite/DWARFRewriter.cpp | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 84f1853469709..6a56c8aa7cfa5 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>
@@ -1640,6 +1641,11 @@ void BinaryContext::preprocessDWODebugInfo() {
       if (!opts::CompDirOverride.empty()) {
         sys::path::append(AbsolutePath, opts::CompDirOverride);
         sys::path::append(AbsolutePath, DWOName);
+      } else {
+        std::string CompDir = DwarfUnit->getCompilationDir();
+        sys::path::append(AbsolutePath, CompDir);
+        if (!sys::fs::exists(AbsolutePath) && sys::fs::exists(DWOName))
+          AbsolutePath = DWOName;
       }
       DWARFUnit *DWOCU =
           DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
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);



More information about the llvm-commits mailing list