https://github.com/vvereschaka updated 
https://github.com/llvm/llvm-project/pull/205729

>From 292844e3406df022199542d914f3d39081f84d7b Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka <[email protected]>
Date: Wed, 24 Jun 2026 22:21:40 -0700
Subject: [PATCH 1/4] [DebugInfo][CodeView] Emit path prefix substitution for
 COFF object file name.

Remap a file path for the object file name in CodeView debug info (S_OBJNAME)
with the path prefix specified by `fdebug-prefix-map=` option.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 ++++
 clang/lib/Basic/CodeGenOptions.cpp         | 10 ++++++++++
 clang/lib/CodeGen/BackendUtil.cpp          |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp          |  6 +-----
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 97d68877467fd..027ccac08e879 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -700,6 +700,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
     }
     llvm_unreachable("Unknown BoolFromMem enum");
   }
+
+  /// Remap specified path prefix using provided DebugPrefixMap map.
+  /// Returns updated path or unchanged if no substituion was found.
+  std::string remapDebugPathPrefix(StringRef Path) const;
 };
 
 }  // end namespace clang
diff --git a/clang/lib/Basic/CodeGenOptions.cpp 
b/clang/lib/Basic/CodeGenOptions.cpp
index db8a77cd93cf6..a16a8a126e709 100644
--- a/clang/lib/Basic/CodeGenOptions.cpp
+++ b/clang/lib/Basic/CodeGenOptions.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang/Basic/CodeGenOptions.h"
+#include "llvm/Support/Path.h"
 
 namespace clang {
 
@@ -50,4 +51,13 @@ void CodeGenOptions::resetNonModularOptions(StringRef 
ModuleFormat) {
   RelocationModel = llvm::Reloc::PIC_;
 }
 
+std::string CodeGenOptions::remapDebugPathPrefix(StringRef Path) const {
+  SmallString<0> P = Path;
+
+  for (auto &[From, To] : llvm::reverse(DebugPrefixMap))
+    if (llvm::sys::path::replace_path_prefix(P, From, To))
+      break;
+  return P.str().str();
+}
+
 }  // end namespace clang
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e33480f6c6416..5bc0093486700 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -481,7 +481,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
-  Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
+  Options.ObjectFilenameForDebug = 
CodeGenOpts.remapDebugPathPrefix(CodeGenOpts.ObjectFilenameForDebug);
   Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7421733efcc24..5331d1231d407 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -671,11 +671,7 @@ llvm::DIFile *CGDebugInfo::createFile(
 }
 
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
-  SmallString<256> P = Path;
-  for (auto &[From, To] : llvm::reverse(CGM.getCodeGenOpts().DebugPrefixMap))
-    if (llvm::sys::path::replace_path_prefix(P, From, To))
-      break;
-  return P.str().str();
+  return CGM.getCodeGenOpts().remapDebugPathPrefix(Path);
 }
 
 unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {

>From 085e2938b52a2b3c52172e1d3138fbfde62d574f Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka <[email protected]>
Date: Wed, 24 Jun 2026 23:44:47 -0700
Subject: [PATCH 2/4] Fix code formatting

---
 clang/lib/CodeGen/BackendUtil.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 5bc0093486700..041aa3737e3d1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -481,7 +481,8 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
-  Options.ObjectFilenameForDebug = 
CodeGenOpts.remapDebugPathPrefix(CodeGenOpts.ObjectFilenameForDebug);
+  Options.ObjectFilenameForDebug =
+      CodeGenOpts.remapDebugPathPrefix(CodeGenOpts.ObjectFilenameForDebug);
   Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;

>From 010157acfd6bf81e718526b96399446cc22f449a Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka <[email protected]>
Date: Fri, 26 Jun 2026 16:03:50 -0700
Subject: [PATCH 3/4] Add test.

---
 clang/test/DebugInfo/Generic/codeview-buildinfo.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/test/DebugInfo/Generic/codeview-buildinfo.c 
b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
index b930e3cc642c4..6c02941d7c950 100644
--- a/clang/test/DebugInfo/Generic/codeview-buildinfo.c
+++ b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
@@ -24,6 +24,14 @@
 // RUN: cd %t.relpath && %clang_cl --target=i686-windows-msvc /c /Z7 
/Fo:hello.obj -- hello.cpp
 // RUN: llvm-pdbutil dump --types %t.relpath/hello.obj | FileCheck %s 
--check-prefix RELPATH
 
+// The S_OBJNAME path must be get remapped if a proper prefix map was 
specified via `/pathmap`.
+// RUN: rm -rf %t.pathmap && mkdir -p %t.pathmap
+// RUN: cp %s %t.pathmap/%{s:basename}
+// RUN: cd %t.pathmap && %clang_cl --target=i686-windows-msvc /c /Z7 \
+// RUN:   /pathmap:%t.pathmap=x:/path-to /experimental:deterministic \
+// RUN:   /Fo:%{s:basename}.obj -- %{s:basename}
+// RUN: llvm-pdbutil dump --all %{s:basename}.obj | FileCheck %s 
--check-prefix OBJNAME-PATHMAP
+
 int main(void) { return 42; }
 
 // CHECK:                       Types (.debug$T)
@@ -78,3 +86,5 @@ int main(void) { return 42; }
 // RELPATH-NEXT:           0x{{.*}}: `
 // RELPATH-NOT:   {{hello\.cpp}}
 // RELPATH-SAME:  `
+
+// OBJNAME-PATHMAP: {{^.+}} | S_OBJNAME [size = {{.+}}] sig=0, 
`x:/path-to{{[\\/]}}codeview-buildinfo.c.obj`

>From 4f7e05179f6b990c22469dfde60cac17a83f1f84 Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka <[email protected]>
Date: Fri, 3 Jul 2026 18:37:25 -0700
Subject: [PATCH 4/4] Incremental updates and fixes.

---
 clang/include/clang/Basic/CodeGenOptions.h        | 2 +-
 clang/lib/Basic/CodeGenOptions.cpp                | 2 +-
 clang/test/DebugInfo/Generic/codeview-buildinfo.c | 7 +++----
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 027ccac08e879..9a45c51b83342 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -702,7 +702,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
   }
 
   /// Remap specified path prefix using provided DebugPrefixMap map.
-  /// Returns updated path or unchanged if no substituion was found.
+  /// Returns updated path or unchanged if no substitution was found.
   std::string remapDebugPathPrefix(StringRef Path) const;
 };
 
diff --git a/clang/lib/Basic/CodeGenOptions.cpp 
b/clang/lib/Basic/CodeGenOptions.cpp
index a16a8a126e709..8627d73bb0aae 100644
--- a/clang/lib/Basic/CodeGenOptions.cpp
+++ b/clang/lib/Basic/CodeGenOptions.cpp
@@ -52,7 +52,7 @@ void CodeGenOptions::resetNonModularOptions(StringRef 
ModuleFormat) {
 }
 
 std::string CodeGenOptions::remapDebugPathPrefix(StringRef Path) const {
-  SmallString<0> P = Path;
+  SmallString<256> P = Path;
 
   for (auto &[From, To] : llvm::reverse(DebugPrefixMap))
     if (llvm::sys::path::replace_path_prefix(P, From, To))
diff --git a/clang/test/DebugInfo/Generic/codeview-buildinfo.c 
b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
index 6c02941d7c950..36e8663b799f7 100644
--- a/clang/test/DebugInfo/Generic/codeview-buildinfo.c
+++ b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
@@ -24,13 +24,12 @@
 // RUN: cd %t.relpath && %clang_cl --target=i686-windows-msvc /c /Z7 
/Fo:hello.obj -- hello.cpp
 // RUN: llvm-pdbutil dump --types %t.relpath/hello.obj | FileCheck %s 
--check-prefix RELPATH
 
-// The S_OBJNAME path must be get remapped if a proper prefix map was 
specified via `/pathmap`.
+// The S_OBJNAME path must be remapped if a proper prefix map was specified 
via `/pathmap`.
 // RUN: rm -rf %t.pathmap && mkdir -p %t.pathmap
 // RUN: cp %s %t.pathmap/%{s:basename}
 // RUN: cd %t.pathmap && %clang_cl --target=i686-windows-msvc /c /Z7 \
-// RUN:   /pathmap:%t.pathmap=x:/path-to /experimental:deterministic \
-// RUN:   /Fo:%{s:basename}.obj -- %{s:basename}
-// RUN: llvm-pdbutil dump --all %{s:basename}.obj | FileCheck %s 
--check-prefix OBJNAME-PATHMAP
+// RUN:   /pathmap:%t.pathmap=x:/path-to /Fo:%{s:basename}.obj -- %{s:basename}
+// RUN: llvm-pdbutil dump --symbols %{s:basename}.obj | FileCheck %s 
--check-prefix OBJNAME-PATHMAP
 
 int main(void) { return 42; }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to