@@ -154,6 +154,10 @@ class PDBLinker {
154
154
std::pair<CVIndexMap &, bool /* already there*/ >
155
155
registerPrecompiledHeaders (uint32_t Signature);
156
156
157
+ void mergeSymbolRecords (ObjFile *File, const CVIndexMap &IndexMap,
158
+ std::vector<ulittle32_t *> &StringTableRefs,
159
+ BinaryStreamRef SymData);
160
+
157
161
// / Add the section map and section contributions to the PDB.
158
162
void addSections (ArrayRef<OutputSection *> OutputSections,
159
163
ArrayRef<uint8_t > SectionTable);
@@ -1028,20 +1032,15 @@ static void addGlobalSymbol(pdb::GSIStreamBuilder &Builder, ObjFile &File,
1028
1032
}
1029
1033
}
1030
1034
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) {
1039
1038
ArrayRef<uint8_t > SymsBuffer;
1040
1039
cantFail (SymData.readBytes (0 , SymData.getLength (), SymsBuffer));
1041
1040
SmallVector<SymbolScope, 4 > Scopes;
1042
1041
1043
1042
auto EC = forEachCodeViewRecord<CVSymbol>(
1044
- SymsBuffer, [&](const CVSymbol & Sym) -> llvm::Error {
1043
+ SymsBuffer, [&](CVSymbol Sym) -> llvm::Error {
1045
1044
// Discover type index references in the record. Skip it if we don't
1046
1045
// know where they are.
1047
1046
SmallVector<TiReference, 32 > TypeRefs;
@@ -1051,8 +1050,10 @@ static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
1051
1050
return Error::success ();
1052
1051
}
1053
1052
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.
1055
1055
MutableArrayRef<uint8_t > NewData = copySymbolForPdb (Sym, Alloc);
1056
+ Sym = CVSymbol (Sym.kind (), NewData);
1056
1057
1057
1058
// Re-map all the type index references.
1058
1059
MutableArrayRef<uint8_t > Contents =
@@ -1062,32 +1063,29 @@ static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
1062
1063
1063
1064
// An object file may have S_xxx_ID symbols, but these get converted to
1064
1065
// "real" symbols in a PDB.
1065
- translateIdSymbols (NewData, IDTable);
1066
+ translateIdSymbols (NewData, getIDTable ());
1067
+ Sym = CVSymbol (symbolKind (NewData), NewData);
1066
1068
1067
1069
// If this record refers to an offset in the object file's string table,
1068
1070
// add that item to the global PDB string table and re-write the index.
1069
1071
recordStringTableReferences (Sym.kind (), Contents, StringTableRefs);
1070
1072
1071
- SymbolKind NewKind = symbolKind (NewData);
1072
-
1073
1073
// 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 ()))
1079
1077
scopeStackClose (Scopes, File->ModuleDBI ->getNextSymbolOffset (), File);
1080
1078
1081
1079
// Add the symbol to the globals stream if necessary. Do this before
1082
1080
// adding the symbol to the module since we may need to get the next
1083
1081
// symbol offset, and writing to the module's symbol stream will update
1084
1082
// that offset.
1085
- if (symbolGoesInGlobalsStream (NewSym ))
1086
- addGlobalSymbol (GsiBuilder , *File, NewSym );
1083
+ if (symbolGoesInGlobalsStream (Sym ))
1084
+ addGlobalSymbol (Builder. getGsiBuilder () , *File, Sym );
1087
1085
1088
1086
// Add the symbol to the module.
1089
- if (symbolGoesInModuleStream (NewSym ))
1090
- File->ModuleDBI ->addSymbol (NewSym );
1087
+ if (symbolGoesInModuleStream (Sym ))
1088
+ File->ModuleDBI ->addSymbol (Sym );
1091
1089
return Error::success ();
1092
1090
});
1093
1091
cantFail (std::move (EC));
@@ -1181,9 +1179,8 @@ void DebugSHandler::handleDebugS(lld::coff::SectionChunk &DebugS) {
1181
1179
break ;
1182
1180
}
1183
1181
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 ());
1187
1184
break ;
1188
1185
}
1189
1186
default :
0 commit comments