Skip to content

Commit 944843c

Browse files
committed
[PDB] Simplify symbol handling code, NFC
- Make mergeSymbolRecords a method of PDBLinker to reduce the number of parameters it needs. - Remove a stale FIXME comment about error handling. We already drop unknown symbol records, log them, and continue. - Update a comment about why we're copying the symbol record. We do it to realign the record. We can already mutate the symbol record memory, it's memory allocated by relocateDebugChunk. - Avoid the extra `CVSymbol NewSym` variable. We can mutate Sym in place, which is best, since we're mutating the underlying record anyway. llvm-svn: 346817
1 parent 4e97ec9 commit 944843c

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

lld/COFF/PDB.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class PDBLinker {
154154
std::pair<CVIndexMap &, bool /*already there*/>
155155
registerPrecompiledHeaders(uint32_t Signature);
156156

157+
void mergeSymbolRecords(ObjFile *File, const CVIndexMap &IndexMap,
158+
std::vector<ulittle32_t *> &StringTableRefs,
159+
BinaryStreamRef SymData);
160+
157161
/// Add the section map and section contributions to the PDB.
158162
void addSections(ArrayRef<OutputSection *> OutputSections,
159163
ArrayRef<uint8_t> SectionTable);
@@ -1028,20 +1032,15 @@ static void addGlobalSymbol(pdb::GSIStreamBuilder &Builder, ObjFile &File,
10281032
}
10291033
}
10301034

1031-
static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
1032-
pdb::GSIStreamBuilder &GsiBuilder,
1033-
const CVIndexMap &IndexMap,
1034-
TypeCollection &IDTable,
1035-
std::vector<ulittle32_t *> &StringTableRefs,
1036-
BinaryStreamRef SymData) {
1037-
// FIXME: Improve error recovery by warning and skipping records when
1038-
// possible.
1035+
void PDBLinker::mergeSymbolRecords(ObjFile *File, const CVIndexMap &IndexMap,
1036+
std::vector<ulittle32_t *> &StringTableRefs,
1037+
BinaryStreamRef SymData) {
10391038
ArrayRef<uint8_t> SymsBuffer;
10401039
cantFail(SymData.readBytes(0, SymData.getLength(), SymsBuffer));
10411040
SmallVector<SymbolScope, 4> Scopes;
10421041

10431042
auto EC = forEachCodeViewRecord<CVSymbol>(
1044-
SymsBuffer, [&](const CVSymbol &Sym) -> llvm::Error {
1043+
SymsBuffer, [&](CVSymbol Sym) -> llvm::Error {
10451044
// Discover type index references in the record. Skip it if we don't
10461045
// know where they are.
10471046
SmallVector<TiReference, 32> TypeRefs;
@@ -1051,8 +1050,10 @@ static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
10511050
return Error::success();
10521051
}
10531052

1054-
// Copy the symbol record so we can mutate it.
1053+
// Copy the symbol and fix the symbol record alignment. The symbol
1054+
// record in the object file may not be aligned.
10551055
MutableArrayRef<uint8_t> NewData = copySymbolForPdb(Sym, Alloc);
1056+
Sym = CVSymbol(Sym.kind(), NewData);
10561057

10571058
// Re-map all the type index references.
10581059
MutableArrayRef<uint8_t> Contents =
@@ -1062,32 +1063,29 @@ static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
10621063

10631064
// An object file may have S_xxx_ID symbols, but these get converted to
10641065
// "real" symbols in a PDB.
1065-
translateIdSymbols(NewData, IDTable);
1066+
translateIdSymbols(NewData, getIDTable());
1067+
Sym = CVSymbol(symbolKind(NewData), NewData);
10661068

10671069
// If this record refers to an offset in the object file's string table,
10681070
// add that item to the global PDB string table and re-write the index.
10691071
recordStringTableReferences(Sym.kind(), Contents, StringTableRefs);
10701072

1071-
SymbolKind NewKind = symbolKind(NewData);
1072-
10731073
// Fill in "Parent" and "End" fields by maintaining a stack of scopes.
1074-
CVSymbol NewSym(NewKind, NewData);
1075-
if (symbolOpensScope(NewKind))
1076-
scopeStackOpen(Scopes, File->ModuleDBI->getNextSymbolOffset(),
1077-
NewSym);
1078-
else if (symbolEndsScope(NewKind))
1074+
if (symbolOpensScope(Sym.kind()))
1075+
scopeStackOpen(Scopes, File->ModuleDBI->getNextSymbolOffset(), Sym);
1076+
else if (symbolEndsScope(Sym.kind()))
10791077
scopeStackClose(Scopes, File->ModuleDBI->getNextSymbolOffset(), File);
10801078

10811079
// Add the symbol to the globals stream if necessary. Do this before
10821080
// adding the symbol to the module since we may need to get the next
10831081
// symbol offset, and writing to the module's symbol stream will update
10841082
// that offset.
1085-
if (symbolGoesInGlobalsStream(NewSym))
1086-
addGlobalSymbol(GsiBuilder, *File, NewSym);
1083+
if (symbolGoesInGlobalsStream(Sym))
1084+
addGlobalSymbol(Builder.getGsiBuilder(), *File, Sym);
10871085

10881086
// Add the symbol to the module.
1089-
if (symbolGoesInModuleStream(NewSym))
1090-
File->ModuleDBI->addSymbol(NewSym);
1087+
if (symbolGoesInModuleStream(Sym))
1088+
File->ModuleDBI->addSymbol(Sym);
10911089
return Error::success();
10921090
});
10931091
cantFail(std::move(EC));
@@ -1181,9 +1179,8 @@ void DebugSHandler::handleDebugS(lld::coff::SectionChunk &DebugS) {
11811179
break;
11821180
}
11831181
case DebugSubsectionKind::Symbols: {
1184-
mergeSymbolRecords(Linker.Alloc, &File, Linker.Builder.getGsiBuilder(),
1185-
IndexMap, Linker.getIDTable(), StringTableReferences,
1186-
SS.getRecordData());
1182+
Linker.mergeSymbolRecords(&File, IndexMap, StringTableReferences,
1183+
SS.getRecordData());
11871184
break;
11881185
}
11891186
default:

0 commit comments

Comments
 (0)