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.
llvm-svn: 310754
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 6f9f21a..ca044ca 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -727,13 +727,13 @@
}
}
-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 @@
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 @@
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 = {