[lld] r309987 - [PDB] Fix section contributions
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 14:15:09 PDT 2017
Author: rnk
Date: Thu Aug 3 14:15:09 2017
New Revision: 309987
URL: http://llvm.org/viewvc/llvm-project?rev=309987&view=rev
Log:
[PDB] Fix section contributions
Summary:
PDB section contributions are supposed to use output section indices and
offsets, not input section indices and offsets.
This allows the debugger to look up the index of the module that it
should look up in the modules stream for symbol information. With this
change, windbg can now find line tables, but it still cannot print local
variables.
Fixes PR34048
Reviewers: zturner
Subscribers: hiraditya, ruiu, llvm-commits
Differential Revision: https://reviews.llvm.org/D36285
Modified:
lld/trunk/COFF/PDB.cpp
lld/trunk/COFF/PDB.h
lld/trunk/COFF/Writer.cpp
lld/trunk/test/COFF/pdb-publics-import.test
lld/trunk/test/COFF/pdb.test
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=309987&r1=309986&r2=309987&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Aug 3 14:15:09 2017
@@ -98,7 +98,11 @@ public:
TypeServer2Record &TS);
/// Add the section map and section contributions to the PDB.
- void addSections(ArrayRef<uint8_t> SectionTable);
+ void addSections(ArrayRef<OutputSection *> OutputSections,
+ ArrayRef<uint8_t> SectionTable);
+
+ void addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,
+ OutputSection *OS, Chunk *C);
/// Write the PDB to disk.
void commit();
@@ -129,14 +133,6 @@ private:
};
}
-// Returns a list of all SectionChunks.
-static void addSectionContribs(SymbolTable *Symtab,
- pdb::DbiStreamBuilder &DbiBuilder) {
- for (Chunk *C : Symtab->getChunks())
- if (auto *SC = dyn_cast<SectionChunk>(C))
- DbiBuilder.addSectionContrib(SC->File->ModuleDBI, SC->Header);
-}
-
static SectionChunk *findByName(std::vector<SectionChunk *> &Sections,
StringRef Name) {
for (SectionChunk *C : Sections)
@@ -648,12 +644,14 @@ static void addLinkerModuleSymbols(Strin
}
// Creates a PDB file.
-void coff::createPDB(SymbolTable *Symtab, ArrayRef<uint8_t> SectionTable,
+void coff::createPDB(SymbolTable *Symtab,
+ ArrayRef<OutputSection *> OutputSections,
+ ArrayRef<uint8_t> SectionTable,
const llvm::codeview::DebugInfo *DI) {
PDBLinker PDB(Symtab);
PDB.initialize(DI);
PDB.addObjectsToPDB();
- PDB.addSections(SectionTable);
+ PDB.addSections(OutputSections, SectionTable);
PDB.commit();
}
@@ -682,19 +680,30 @@ void PDBLinker::initialize(const llvm::c
ExitOnErr(DbiBuilder.addDbgStream(pdb::DbgHeaderType::NewFPO, {}));
}
-void PDBLinker::addSections(ArrayRef<uint8_t> SectionTable) {
- // Add Section Contributions.
- pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
- addSectionContribs(Symtab, DbiBuilder);
-
- // Add Section Map stream.
- ArrayRef<object::coff_section> Sections = {
- (const object::coff_section *)SectionTable.data(),
- SectionTable.size() / sizeof(object::coff_section)};
- SectionMap = pdb::DbiStreamBuilder::createSectionMap(Sections);
- DbiBuilder.setSectionMap(SectionMap);
+void PDBLinker::addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,
+ OutputSection *OS, Chunk *C) {
+ pdb::SectionContrib SC;
+ memset(&SC, 0, sizeof(SC));
+ SC.ISect = OS->SectionIndex;
+ SC.Off = C->getRVA() - OS->getRVA();
+ SC.Size = C->getSize();
+ if (auto *SecChunk = dyn_cast<SectionChunk>(C)) {
+ SC.Characteristics = SecChunk->Header->Characteristics;
+ SC.Imod = SecChunk->File->ModuleDBI->getModuleIndex();
+ } else {
+ SC.Characteristics = OS->getCharacteristics();
+ // FIXME: When we start creating DBI for import libraries, use those here.
+ SC.Imod = LinkerModule.getModuleIndex();
+ }
+ SC.DataCrc = 0; // FIXME
+ SC.RelocCrc = 0; // FIXME
+ Builder.getDbiBuilder().addSectionContrib(SC);
+}
+void PDBLinker::addSections(ArrayRef<OutputSection *> OutputSections,
+ ArrayRef<uint8_t> SectionTable) {
// It's not entirely clear what this is, but the * Linker * module uses it.
+ pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
NativePath = Config->PDBPath;
sys::fs::make_absolute(NativePath);
sys::path::native(NativePath, sys::path::Style::windows);
@@ -703,6 +712,18 @@ void PDBLinker::addSections(ArrayRef<uin
LinkerModule.setPdbFilePathNI(PdbFilePathNI);
addLinkerModuleSymbols(NativePath, LinkerModule, Alloc);
+ // Add section contributions. They must be ordered by ascending RVA.
+ for (OutputSection *OS : OutputSections)
+ for (Chunk *C : OS->getChunks())
+ addSectionContrib(LinkerModule, OS, C);
+
+ // Add Section Map stream.
+ ArrayRef<object::coff_section> Sections = {
+ (const object::coff_section *)SectionTable.data(),
+ SectionTable.size() / sizeof(object::coff_section)};
+ SectionMap = pdb::DbiStreamBuilder::createSectionMap(Sections);
+ DbiBuilder.setSectionMap(SectionMap);
+
// Add COFF section header stream.
ExitOnErr(
DbiBuilder.addDbgStream(pdb::DbgHeaderType::SectionHdr, SectionTable));
Modified: lld/trunk/COFF/PDB.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.h?rev=309987&r1=309986&r2=309987&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.h (original)
+++ lld/trunk/COFF/PDB.h Thu Aug 3 14:15:09 2017
@@ -21,9 +21,12 @@ union DebugInfo;
namespace lld {
namespace coff {
+class OutputSection;
class SymbolTable;
-void createPDB(SymbolTable *Symtab, llvm::ArrayRef<uint8_t> SectionTable,
+void createPDB(SymbolTable *Symtab,
+ llvm::ArrayRef<OutputSection *> OutputSections,
+ llvm::ArrayRef<uint8_t> SectionTable,
const llvm::codeview::DebugInfo *DI);
}
}
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=309987&r1=309986&r2=309987&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu Aug 3 14:15:09 2017
@@ -240,7 +240,7 @@ void Writer::run() {
const llvm::codeview::DebugInfo *DI = nullptr;
if (Config->DebugTypes & static_cast<unsigned>(coff::DebugType::CV))
DI = BuildId->DI;
- createPDB(Symtab, SectionTable, DI);
+ createPDB(Symtab, OutputSections, SectionTable, DI);
}
writeMapFile(OutputSections);
Modified: lld/trunk/test/COFF/pdb-publics-import.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-publics-import.test?rev=309987&r1=309986&r2=309987&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb-publics-import.test (original)
+++ lld/trunk/test/COFF/pdb-publics-import.test Thu Aug 3 14:15:09 2017
@@ -7,7 +7,7 @@ RUN: lld-link /out:%t1.dll /dll %t1.obj
RUN: /export:exportfn1 /export:exportfn2
RUN: yaml2obj < %p/Inputs/import.yaml > %t2.obj
RUN: lld-link /out:%t2.exe /pdb:%t2.pdb /debug /entry:main %t2.obj %t1.lib
-RUN: llvm-pdbutil dump %t2.pdb -publics | FileCheck %s
+RUN: llvm-pdbutil dump %t2.pdb -publics -section-contribs | FileCheck %s
CHECK: Public Symbols
CHECK-NEXT: ============================================================
@@ -21,3 +21,21 @@ CHECK-NEXT: 32 | S_PUB32 [size = 3
CHECK-NEXT: flags = none, addr = 0003:0072
CHECK-NEXT: 0 | S_PUB32 [size = 32] `__imp_exportfn1`
CHECK-NEXT: flags = none, addr = 0003:0064
+
+CHECK: Section Contributions
+CHECK-NEXT: ============================================================
+ main
+CHECK-NEXT: SC | mod = 0, 0001:0000, size = 8, data crc = 0, reloc crc = 0
+CHECK-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_EXECUTE |
+CHECK-NEXT: IMAGE_SCN_MEM_READ
+ exportfn1 thunk
+CHECK-NEXT: SC | mod = 1, 0001:0016, size = 6, data crc = 0, reloc crc = 0
+CHECK-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
+ exportfn2 thunk
+CHECK-NEXT: SC | mod = 1, 0001:0032, size = 6, data crc = 0, reloc crc = 0
+CHECK-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
+ .rdata debug directory data chunks
+CHECK-NEXT: SC | mod = 1, 0002:0000, size = 28, data crc = 0, reloc crc = 0
+CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
+CHECK-NEXT: SC | mod = 1, 0002:0028, size = 110, data crc = 0, reloc crc = 0
+CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
Modified: lld/trunk/test/COFF/pdb.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb.test?rev=309987&r1=309986&r2=309987&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb.test (original)
+++ lld/trunk/test/COFF/pdb.test Thu Aug 3 14:15:09 2017
@@ -190,16 +190,16 @@ RAW-NEXT: off = 20
RAW-NEXT: off = 0
RAW: Section Contributions
RAW-NEXT: ============================================================
-RAW-NEXT: SC | mod = 0, 65535:1288, size = 14, data crc = 0, reloc crc = 0
+RAW-NEXT: SC | mod = 0, 0001:0000, size = 12, data crc = 0, reloc crc = 0
+RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ
+RAW-NEXT: SC | mod = 0, 0002:0000, size = 14, data crc = 0, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_ALIGN_16BYTES | IMAGE_SCN_MEM_EXECUTE |
RAW-NEXT: IMAGE_SCN_MEM_READ
-RAW-NEXT: SC | mod = 0, 65535:1312, size = 8, data crc = 0, reloc crc = 0
-RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ
-RAW-NEXT: SC | mod = 0, 65535:1320, size = 12, data crc = 0, reloc crc = 0
-RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ
-RAW-NEXT: SC | mod = 1, 65535:1144, size = 6, data crc = 0, reloc crc = 0
+RAW-NEXT: SC | mod = 1, 0002:0016, size = 6, data crc = 0, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_ALIGN_16BYTES | IMAGE_SCN_MEM_EXECUTE |
RAW-NEXT: IMAGE_SCN_MEM_READ
+RAW-NEXT: SC | mod = 0, 0003:0000, size = 8, data crc = 0, reloc crc = 0
+RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ
RAW: Section Map
RAW-NEXT: ============================================================
RAW-NEXT: Section 0000 | ovl = 0, group = 0, frame = 0, name = 1
More information about the llvm-commits
mailing list