Author: Vladimir Vereschaka Date: 2026-08-22T09:14:18-07:00 New Revision: 503b56c8aff947022a124ae5ba0bfe848991c1ac
URL: https://github.com/llvm/llvm-project/commit/503b56c8aff947022a124ae5ba0bfe848991c1ac DIFF: https://github.com/llvm/llvm-project/commit/503b56c8aff947022a124ae5ba0bfe848991c1ac.diff LOG: [DebugInfo][CodeView] Emit path prefix substitution for COFF object file name. (#205729) The `S_OBJNAME` field value gets by bypassing `CGDebugInfo` and its path prefix does not get remapped if requested `fdebug-prefix-map=` option as the other pathes in the debug info. This patch fixes it and does remapping for the object file path either. Added: Modified: clang/include/clang/Basic/CodeGenOptions.h clang/lib/Basic/CodeGenOptions.cpp clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/test/DebugInfo/Generic/codeview-buildinfo.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index babc5cf76d44a..17f367bc02607 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -723,6 +723,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 substitution 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..8627d73bb0aae 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<256> 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 f311c91895d53..6aa6bc1bd41e8 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -473,7 +473,8 @@ 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 37ee3765fd7c4..39c99d4114a69 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -672,11 +672,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) { diff --git a/clang/test/DebugInfo/Generic/codeview-buildinfo.c b/clang/test/DebugInfo/Generic/codeview-buildinfo.c index b930e3cc642c4..36e8663b799f7 100644 --- a/clang/test/DebugInfo/Generic/codeview-buildinfo.c +++ b/clang/test/DebugInfo/Generic/codeview-buildinfo.c @@ -24,6 +24,13 @@ // 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 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 /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; } // CHECK: Types (.debug$T) @@ -78,3 +85,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` _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
