[lld] r336873 - [coff] Remove dots in path pointing to PDB file.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 17:44:15 PDT 2018


Author: zturner
Date: Wed Jul 11 17:44:15 2018
New Revision: 336873

URL: http://llvm.org/viewvc/llvm-project?rev=336873&view=rev
Log:
[coff] Remove dots in path pointing to PDB file.

Some Microsoft tools (e.g. new versions of WPA) fail when the
COFF Debug Directory contains a path to the PDB that contains
dots, such as D:\foo\./bar.pdb.  Remove dots before writing this
path.

This fixes pr38126.

Added:
    lld/trunk/test/COFF/pdb-exe-path-dots.test
Modified:
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=336873&r1=336872&r2=336873&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Jul 11 17:44:15 2018
@@ -122,7 +122,7 @@ private:
 class CVDebugRecordChunk : public Chunk {
 public:
   size_t getSize() const override {
-    return sizeof(codeview::DebugInfo) + Config->PDBAltPath.size() + 1;
+    return sizeof(codeview::DebugInfo) + Path.size() + 1;
   }
 
   void writeTo(uint8_t *B) const override {
@@ -132,11 +132,12 @@ public:
 
     // variable sized field (PDB Path)
     char *P = reinterpret_cast<char *>(B + OutputSectionOff + sizeof(*BuildId));
-    if (!Config->PDBAltPath.empty())
-      memcpy(P, Config->PDBAltPath.data(), Config->PDBAltPath.size());
-    P[Config->PDBAltPath.size()] = '\0';
+    if (!Path.empty())
+      memcpy(P, Path.data(), Path.size());
+    P[Path.size()] = '\0';
   }
 
+  SmallString<128> Path;
   mutable codeview::DebugInfo *BuildId = nullptr;
 };
 
@@ -509,6 +510,8 @@ void Writer::createMiscChunks() {
     // if we're ultimately not going to write CodeView data to the PDB.
     auto *CVChunk = make<CVDebugRecordChunk>();
     BuildId = CVChunk;
+    CVChunk->Path = Config->PDBAltPath;
+    llvm::sys::path::remove_dots(CVChunk->Path);
     DebugRecords.push_back(CVChunk);
 
     RdataSec->addChunk(DebugDirectory);

Added: lld/trunk/test/COFF/pdb-exe-path-dots.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-exe-path-dots.test?rev=336873&view=auto
==============================================================================
--- lld/trunk/test/COFF/pdb-exe-path-dots.test (added)
+++ lld/trunk/test/COFF/pdb-exe-path-dots.test Wed Jul 11 17:44:15 2018
@@ -0,0 +1,10 @@
+RUN: yaml2obj < %p/Inputs/pdb1.yaml > %t1.obj
+RUN: yaml2obj < %p/Inputs/pdb2.yaml > %t2.obj
+RUN: rm -rf %t
+RUN: mkdir %t
+RUN: mkdir %t/foo
+RUN: lld-link /debug /pdb:%t/foo/./out.pdb /out:%t/out.exe /entry:main /nodefaultlib \
+RUN:   %t1.obj %t2.obj
+RUN: llvm-readobj -coff-debug-directory %t/out.exe | FileCheck %s
+
+CHECK: PDBFileName: {{.*}}tmp{{/|\\}}foo{{/|\\}}out.pdb
\ No newline at end of file




More information about the llvm-commits mailing list