[lld] r307356 - [PDB] Teach libpdb to write DBI Stream ECNames.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 22:04:36 PDT 2017


Author: zturner
Date: Thu Jul  6 22:04:36 2017
New Revision: 307356

URL: http://llvm.org/viewvc/llvm-project?rev=307356&view=rev
Log:
[PDB] Teach libpdb to write DBI Stream ECNames.

Based strictly on the name, this seems to have something to do
width edit & continue.  The goal of this patch has nothing to do
with supporting edit and continue though.  msvc link.exe writes
very basic information into this area even when *not* compiling
with support for E&C, and so the goal here is to bring lld-link
to parity.  Since we cannot know what assumptions standard tools
make about the content of PDB files, we need to be as close as
possible.

This ECNames data structure is a standard PDB string hash table.
link.exe puts a single string into this hash table, which is the
full path to the PDB file on disk.  It then references this string
from the module descriptor for the compiler generated `* Linker *`
module.

With this patch, lld-link will generate the exact same sequence of
bytes as MSVC link for this subsection for a given object file
input (as reported by `llvm-pdbutil bytes -ec`).

Modified:
    lld/trunk/COFF/PDB.cpp

Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=307356&r1=307355&r2=307356&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Jul  6 22:04:36 2017
@@ -411,6 +411,10 @@ void coff::createPDB(StringRef Path, Sym
   auto &InfoBuilder = Builder.getInfoBuilder();
   InfoBuilder.setAge(DI ? DI->PDB70.Age : 0);
 
+  llvm::SmallString<128> NativePath(Path.begin(), Path.end());
+  llvm::sys::fs::make_absolute(NativePath);
+  llvm::sys::path::native(NativePath);
+
   pdb::PDB_UniqueId uuid{};
   if (DI)
     memcpy(&uuid, &DI->PDB70.Signature, sizeof(uuid));
@@ -419,10 +423,13 @@ void coff::createPDB(StringRef Path, Sym
   InfoBuilder.setSignature(0);
   InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70);
 
-  // Add an empty DPI stream.
+  // Add an empty DBI stream.
   pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
   DbiBuilder.setVersionHeader(pdb::PdbDbiV110);
 
+  // It's not entirely clear what this is, but the * Linker * module uses it.
+  uint32_t PdbFilePathNI = DbiBuilder.addECName(NativePath);
+
   TypeTableBuilder TypeTable(BAlloc);
   TypeTableBuilder IDTable(BAlloc);
   addObjectsToPDB(Alloc, Symtab, Builder, TypeTable, IDTable);
@@ -438,7 +445,8 @@ void coff::createPDB(StringRef Path, Sym
       pdb::DbiStreamBuilder::createSectionMap(Sections);
   DbiBuilder.setSectionMap(SectionMap);
 
-  ExitOnErr(DbiBuilder.addModuleInfo("* Linker *"));
+  auto &LinkerModule = ExitOnErr(DbiBuilder.addModuleInfo("* Linker *"));
+  LinkerModule.setPdbFilePathNI(PdbFilePathNI);
 
   // Add COFF section header stream.
   ExitOnErr(




More information about the llvm-commits mailing list