[lld] r310754 - Output S_SECTION symbols to the Linker module.

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


Author: zturner
Date: Fri Aug 11 13:46:28 2017
New Revision: 310754

URL: http://llvm.org/viewvc/llvm-project?rev=310754&view=rev
Log:
Output S_SECTION symbols to the Linker module.

PDBs need to contain 1 module for each object file/compiland,
and a special one synthesized by the linker.  This one contains
a symbol record for each output section in the executable with
its address information.  This patch adds such symbols to the
linker module.  Note that we also are supposed to add an
S_COFFGROUP symbol for what appears to be each input section that
contributes to each output section, but it's not entirely clear
how to generate these yet, so I'm leaving that for a separate
patch.

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=310754&r1=310753&r2=310754&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Fri Aug 11 13:46:28 2017
@@ -727,13 +727,13 @@ void PDBLinker::addObjectsToPDB() {
   }
 }
 
-static void addLinkerModuleSymbols(StringRef Path,
-                                   pdb::DbiModuleDescriptorBuilder &Mod,
-                                   BumpPtrAllocator &Allocator) {
-  codeview::SymbolSerializer Serializer(Allocator, CodeViewContainer::Pdb);
-  codeview::ObjNameSym ONS(SymbolRecordKind::ObjNameSym);
-  codeview::Compile3Sym CS(SymbolRecordKind::Compile3Sym);
-  codeview::EnvBlockSym EBS(SymbolRecordKind::EnvBlockSym);
+static void addCommonLinkerModuleSymbols(StringRef Path,
+                                         pdb::DbiModuleDescriptorBuilder &Mod,
+                                         BumpPtrAllocator &Allocator) {
+  SymbolSerializer Serializer(Allocator, CodeViewContainer::Pdb);
+  ObjNameSym ONS(SymbolRecordKind::ObjNameSym);
+  Compile3Sym CS(SymbolRecordKind::Compile3Sym);
+  EnvBlockSym EBS(SymbolRecordKind::EnvBlockSym);
 
   ONS.Name = "* Linker *";
   ONS.Signature = 0;
@@ -771,6 +771,27 @@ static void addLinkerModuleSymbols(Strin
       EBS, Allocator, CodeViewContainer::Pdb));
 }
 
+static void addLinkerModuleSectionSymbol(pdb::DbiModuleDescriptorBuilder &Mod,
+                                         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.Characteristics = OS.getCharacteristics();
+  Sym.Length = OS.getVirtualSize();
+  Sym.Name = OS.getName();
+  Sym.Rva = OS.getRVA();
+  Sym.SectionNumber = OS.SectionIndex;
+  Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
+      Sym, Allocator, CodeViewContainer::Pdb));
+}
+
 // Creates a PDB file.
 void coff::createPDB(SymbolTable *Symtab,
                      ArrayRef<OutputSection *> OutputSections,
@@ -843,12 +864,14 @@ void PDBLinker::addSections(ArrayRef<Out
   uint32_t PdbFilePathNI = DbiBuilder.addECName(NativePath);
   auto &LinkerModule = ExitOnErr(DbiBuilder.addModuleInfo("* Linker *"));
   LinkerModule.setPdbFilePathNI(PdbFilePathNI);
-  addLinkerModuleSymbols(NativePath, LinkerModule, Alloc);
+  addCommonLinkerModuleSymbols(NativePath, LinkerModule, Alloc);
 
   // Add section contributions. They must be ordered by ascending RVA.
-  for (OutputSection *OS : OutputSections)
+  for (OutputSection *OS : OutputSections) {
+    addLinkerModuleSectionSymbol(LinkerModule, *OS, Alloc);
     for (Chunk *C : OS->getChunks())
       addSectionContrib(LinkerModule, OS, C);
+  }
 
   // Add Section Map stream.
   ArrayRef<object::coff_section> Sections = {




More information about the llvm-commits mailing list