[PATCH] D45276: Fix a couple of incorrect fields in our generated PDBs.

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 13:37:20 PDT 2018


zturner updated this revision to Diff 141728.
zturner added a comment.

Use `Config->Machine` instead of `Config->is64()`


https://reviews.llvm.org/D45276

Files:
  lld/COFF/PDB.cpp
  llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
  llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp


Index: llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
===================================================================
--- llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
+++ llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
@@ -37,6 +37,14 @@
 
 void DbiStreamBuilder::setBuildNumber(uint16_t B) { BuildNumber = B; }
 
+void DbiStreamBuilder::setBuildNumber(uint8_t Major, uint8_t Minor) {
+  BuildNumber = (uint16_t(Major) << DbiBuildNo::BuildMajorShift) &
+                DbiBuildNo::BuildMajorMask;
+  BuildNumber |= (uint16_t(Minor) << DbiBuildNo::BuildMinorShift) &
+                 DbiBuildNo::BuildMinorMask;
+  BuildNumber |= DbiBuildNo::NewVersionFormatMask;
+}
+
 void DbiStreamBuilder::setPdbDllVersion(uint16_t V) { PdbDllVersion = V; }
 
 void DbiStreamBuilder::setPdbDllRbld(uint16_t R) { PdbDllRbld = R; }
@@ -251,7 +259,7 @@
   H->TypeServerSize = 0;
   H->SymRecordStreamIndex = SymRecordStreamIndex;
   H->PublicSymbolStreamIndex = PublicsStreamIndex;
-  H->MFCTypeServerIndex = kInvalidStreamIndex;
+  H->MFCTypeServerIndex = 0; // Not sure what this is, but link.exe writes 0.
   H->GlobalSymbolStreamIndex = GlobalsStreamIndex;
 
   Header = H;
Index: llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
===================================================================
--- llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
+++ llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
@@ -46,6 +46,7 @@
   void setVersionHeader(PdbRaw_DbiVer V);
   void setAge(uint32_t A);
   void setBuildNumber(uint16_t B);
+  void setBuildNumber(uint8_t Major, uint8_t Minor);
   void setPdbDllVersion(uint16_t V);
   void setPdbDllRbld(uint16_t R);
   void setFlags(uint16_t F);
Index: lld/COFF/PDB.cpp
===================================================================
--- lld/COFF/PDB.cpp
+++ lld/COFF/PDB.cpp
@@ -978,6 +978,23 @@
   }
 }
 
+static codeview::CPUType toCodeViewMachine(COFF::MachineTypes Machine) {
+  switch (Machine) {
+  case COFF::IMAGE_FILE_MACHINE_AMD64:
+    return codeview::CPUType::X64;
+  case COFF::IMAGE_FILE_MACHINE_ARM:
+    return codeview::CPUType::ARM7;
+  case COFF::IMAGE_FILE_MACHINE_ARM64:
+    return codeview::CPUType::ARM64;
+  case COFF::IMAGE_FILE_MACHINE_ARMNT:
+    return codeview::CPUType::ARMNT;
+  case COFF::IMAGE_FILE_MACHINE_I386:
+    return codeview::CPUType::Intel80386;
+  default:
+    llvm_unreachable("Unsupported CPU Type");
+  }
+}
+
 static void addCommonLinkerModuleSymbols(StringRef Path,
                                          pdb::DbiModuleDescriptorBuilder &Mod,
                                          BumpPtrAllocator &Allocator) {
@@ -988,7 +1005,7 @@
   ONS.Name = "* Linker *";
   ONS.Signature = 0;
 
-  CS.Machine = Config->is64() ? CPUType::X64 : CPUType::Intel80386;
+  CS.Machine = toCodeViewMachine(Config->Machine);
   // Interestingly, if we set the string to 0.0.0.0, then when trying to view
   // local variables WinDbg emits an error that private symbols are not present.
   // By setting this to a valid MSVC linker version string, local variables are
@@ -1085,6 +1102,13 @@
   pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
   DbiBuilder.setAge(BuildId.PDB70.Age);
   DbiBuilder.setVersionHeader(pdb::PdbDbiV70);
+  DbiBuilder.setMachineType(Config->is64() ? pdb::PDB_Machine::Amd64
+                                           : pdb::PDB_Machine::x86);
+  // Technically we are not link.exe 14.11, but there are known cases where
+  // debugging tools on Windows expect Microsoft-specific version numbers or
+  // they fail to work at all.  Since we know we produce PDBs that are
+  // compatible with LINK 14.11, we set that version number here.
+  DbiBuilder.setBuildNumber(14, 11);
 }
 
 void PDBLinker::addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45276.141728.patch
Type: text/x-patch
Size: 3820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180409/15fbbb7b/attachment.bin>


More information about the llvm-commits mailing list