[LLD] Remove global state in lld/COFF

This patch removes globals from the lldCOFF library, by moving globals
into a context class (COFFLinkingContext) and passing it around wherever
it's needed.

See https://lists.llvm.org/pipermail/llvm-dev/2021-June/151184.html for
context about removing globals from LLD.

I also haven't moved the `driver` or `config` variables yet.

Differential Revision: https://reviews.llvm.org/D109634
This commit is contained in:
Amy Huang
2021-09-03 15:28:29 -07:00
parent c96d45700f
commit b4fa71eed3
37 changed files with 692 additions and 607 deletions

View File

@@ -156,7 +156,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
// Merge all the bitcode files we have seen, codegen the result
// and return the resulting objects.
std::vector<InputFile *> BitcodeCompiler::compile() {
std::vector<InputFile *> BitcodeCompiler::compile(COFFLinkerContext &ctx) {
unsigned maxTasks = ltoObj->getMaxTasks();
buf.resize(maxTasks);
files.resize(maxTasks);
@@ -224,7 +224,7 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
if (config->saveTemps)
saveBuffer(buf[i], ltoObjName);
ret.push_back(make<ObjFile>(MemoryBufferRef(objBuf, ltoObjName)));
ret.push_back(make<ObjFile>(ctx, MemoryBufferRef(objBuf, ltoObjName)));
}
return ret;