(this patch is only for RFC purposes)
Rationale
The long term objective here is to parallelize the PDB Type merging.
OBJ files can sometimes have a dependence on other files (precomp OBJ or PDB type server).
Once discovered, those dependencies (precomp OBJ and PDB type server) need to be merged before the dependent OBJ are merged.
Previously, this was done on the fly - whenever a dependence was encountered it was loaded in.
Of course in a single threded environment this works, but not once we want to introduce multithreading, like demonstrated in D55585.
PDB type server as-an-input
A PDB type server is simply a container for a pre-merged .debug$T stream, produced when compiling with MSVC /Zi. OBJs compiled in such way will reference a PDB type server instead of storing a regular .debug$T stream of their own.
Among other things, this demo patch moves loading of PDB type servers in InputFiles.cpp and treats them as other cmd-line inputs.
A secondary objective is to allow for opening the inputs in a multi-threaded manner in the future (ie. somehow parallelize lld::coff::LinkerDriver::run()).
Debug types
The other major change this patch introduces is a class hierarchy designed to handle the different .debug$T containers, as suggested by @rnk.
class TpiSource; // publicly visible class TypeServerSource : public TpiSource; // internal, handles PDB type server merging class UseTypeServerSource : public TpiSource; // internal, handles any OBJ that depends on a PDB type server class PrecompSource : public TpiSource; // internal, handles a precompiled headers OBJ class UsePrecompSource : public TpiSource; // inernal, handles any OBJ that depends on a precomp OBJ
This essentially moves all the type merging from PDB.cpp to a new DebugTypes.cpp
Proposed commit strategy
I propose converging this in several steps, each point is an upcoming patch:
Move dependency detection early into InputFiles.cpp out from PDB.cpp; introduce naked DebugTypes hierarchy- D59053Move PDB type server loading from PDB.cp early into InputFiles.cpp and introduce PDBInputFile- D60095Introduce TypeMerger.h- D60070Take out module DBI creation out of PDBLinker::addObjFile() and treat it separately from type merging- D59261- Implement TpiSource::mergeDebugT and move code from PDB.cpp.
- Implement TypeServerSource::mergeDebugT and UseTypeServerSource and move code from PDB.cpp
- Implement PrecompSource::mergeDebugT and UsePrecompSource and move code from PDB.cpp
"DebugT" seems specific to /Z7 object files, I'd just say "mergeTypes". I suppose this technically also merges LF_*_ID records, but I think the meaning is clear. I guess we could say mergeTpi, which includes both kinds.