diff options
author | Alexandre Ganea <alexandre.ganea@legionlabs.com> | 2022-01-15 21:47:54 -0500 |
---|---|---|
committer | Alexandre Ganea <alexandre.ganea@legionlabs.com> | 2022-01-16 08:57:57 -0500 |
commit | f860fe362282ed69b9d4503a20e5d20b9a041189 (patch) | |
tree | 1f85d88798f7bd31cae0059d71c3c7817333afd6 /lld/MinGW | |
parent | 070d1034da87c94d86d1a61245ecf068141fdf14 (diff) | |
download | llvm-f860fe362282ed69b9d4503a20e5d20b9a041189.zip llvm-f860fe362282ed69b9d4503a20e5d20b9a041189.tar.gz llvm-f860fe362282ed69b9d4503a20e5d20b9a041189.tar.bz2 |
[LLD] Remove global state in lldCommon
Move all variables at file-scope or function-static-scope into a hosting structure (lld::CommonLinkerContext) that lives at lldMain()-scope. Drivers will inherit from this structure and add their own global state, in the same way as for the existing COFFLinkerContext.
See discussion in https://lists.llvm.org/pipermail/llvm-dev/2021-June/151184.html
Differential Revision: https://reviews.llvm.org/D108850
Diffstat (limited to 'lld/MinGW')
-rw-r--r-- | lld/MinGW/Driver.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 7c6b865..f0ac5ee 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -100,7 +100,7 @@ opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> argv) { unsigned missingCount; SmallVector<const char *, 256> vec(argv.data(), argv.data() + argv.size()); - cl::ExpandResponseFiles(saver, getQuotingStyle(), vec); + cl::ExpandResponseFiles(saver(), getQuotingStyle(), vec); opt::InputArgList args = this->ParseArgs(vec, missingIndex, missingCount); if (missingCount) @@ -154,12 +154,10 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) { // Convert Unix-ish command line arguments to Windows-ish ones and // then call coff::link. -bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly, - raw_ostream &stdoutOS, raw_ostream &stderrOS) { - lld::stdoutOS = &stdoutOS; - lld::stderrOS = &stderrOS; - - stderrOS.enable_colors(stderrOS.has_colors()); +bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &stdoutOS, + raw_ostream &stderrOS, bool exitEarly, bool disableOutput) { + auto *ctx = new CommonLinkerContext; + ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput); MinGWOptTable parser; opt::InputArgList args = parser.parse(argsArr.slice(1)); @@ -445,5 +443,9 @@ bool mingw::link(ArrayRef<const char *> argsArr, bool canExitEarly, // Pass the actual binary name, to make error messages be printed with // the right prefix. vec[0] = argsArr[0]; - return coff::link(vec, canExitEarly, stdoutOS, stderrOS); + + // The context will be re-created in the COFF driver. + lld::CommonLinkerContext::destroy(); + + return coff::link(vec, stdoutOS, stderrOS, exitEarly, disableOutput); } |