[lld] r310755 - [pdb] Fix linker module symbols to work with dbgeng.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 13:46:48 PDT 2017


Author: zturner
Date: Fri Aug 11 13:46:47 2017
New Revision: 310755

URL: http://llvm.org/viewvc/llvm-project?rev=310755&view=rev
Log:
[pdb] Fix linker module symbols to work with dbgeng.

The linker module contains a symbol of type S_COMPILE3 which
contains various information about the compiler and linker used
to create the PDB, such as the name of the linker, the target
machine, and the linker version.  Interestingly, if we set the
version 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 can display.

As such, even though it is not representative of LLVM's version
information, we need this for compatibility.

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=310755&r1=310754&r2=310755&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Fri Aug 11 13:46:47 2017
@@ -739,11 +739,22 @@ static void addCommonLinkerModuleSymbols
   ONS.Signature = 0;
 
   CS.Machine = Config->is64() ? CPUType::X64 : CPUType::Intel80386;
+  // 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
+  // displayed properly.   As such, even though it is not representative of
+  // LLVM's version information, we need this for compatibility.
   CS.Flags = CompileSym3Flags::None;
-  CS.VersionBackendBuild = 0;
-  CS.VersionBackendMajor = 0;
-  CS.VersionBackendMinor = 0;
+  CS.VersionBackendBuild = 25019;
+  CS.VersionBackendMajor = 14;
+  CS.VersionBackendMinor = 10;
   CS.VersionBackendQFE = 0;
+
+  // MSVC also sets the frontend to 0.0.0.0 since this is specifically for the
+  // linker module (which is by definition a backend), so we don't need to do
+  // anything here.  Also, it seems we can use "LLVM Linker" for the linker name
+  // without any problems.  Only the backend version has to be hardcoded to a
+  // magic number.
   CS.VersionFrontendBuild = 0;
   CS.VersionFrontendMajor = 0;
   CS.VersionFrontendMinor = 0;
@@ -758,7 +769,9 @@ static void addCommonLinkerModuleSymbols
   sys::fs::current_path(cwd);
   EBS.Fields.push_back(cwd);
   EBS.Fields.push_back("exe");
-  EBS.Fields.push_back(Config->Argv[0]);
+  SmallString<64> exe = Config->Argv[0];
+  llvm::sys::fs::make_absolute(exe);
+  EBS.Fields.push_back(exe);
   EBS.Fields.push_back("pdb");
   EBS.Fields.push_back(Path);
   EBS.Fields.push_back("cmd");
@@ -775,14 +788,7 @@ static void addLinkerModuleSectionSymbol
                                          OutputSection &OS,
                                          BumpPtrAllocator &Allocator) {
   SectionSym Sym(SymbolRecordKind::SectionSym);
-  Sym.Alignment = 0;
-  // We store log_2(Align), not the alignment itself.
-  auto Max = std::max_element(OS.getChunks().begin(), OS.getChunks().end(),
-                              [](const Chunk *C, const Chunk *D) {
-                                return C->getAlign() < D->getAlign();
-                              });
-  if (Max != OS.getChunks().end())
-    Sym.Alignment = Log2_32((*Max)->getAlign());
+  Sym.Alignment = 12; // 2^12 = 4KB
   Sym.Characteristics = OS.getCharacteristics();
   Sym.Length = OS.getVirtualSize();
   Sym.Name = OS.getName();




More information about the llvm-commits mailing list