[lld] 2bfa5ca - [lld][WebAssembly] Reset context object after each link (#78770)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 13:51:38 PST 2024
Author: Sam Clegg
Date: 2024-01-19T13:51:35-08:00
New Revision: 2bfa5ca9277a7320358501c8fa0f1741c5134859
URL: https://github.com/llvm/llvm-project/commit/2bfa5ca9277a7320358501c8fa0f1741c5134859
DIFF: https://github.com/llvm/llvm-project/commit/2bfa5ca9277a7320358501c8fa0f1741c5134859.diff
LOG: [lld][WebAssembly] Reset context object after each link (#78770)
This mirrors how the ELF linker works. I wasn't able to find anywhere
where this is currently tested.
Followup to #78640, which triggered a regression.
Added:
Modified:
lld/wasm/Config.h
lld/wasm/Driver.cpp
Removed:
################################################################################
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index dc7ca265e9a2cb..97c508bda6a1c3 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -124,7 +124,7 @@ struct Ctx {
llvm::SmallVector<InputTable *, 0> syntheticTables;
// True if we are creating position-independent code.
- bool isPic;
+ bool isPic = false;
// True if we have an MVP input that uses __indirect_function_table and which
// requires it to be allocated to table number 0.
@@ -138,6 +138,8 @@ struct Ctx {
llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>,
0>
whyExtractRecords;
+
+ void reset();
};
extern Ctx ctx;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 4a4f9a96227946..716a2d9ebfe306 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -47,6 +47,20 @@ namespace lld::wasm {
Configuration *config;
Ctx ctx;
+void Ctx::reset() {
+ objectFiles.clear();
+ stubFiles.clear();
+ sharedFiles.clear();
+ bitcodeFiles.clear();
+ syntheticFunctions.clear();
+ syntheticGlobals.clear();
+ syntheticTables.clear();
+ whyExtractRecords.clear();
+ isPic = false;
+ legacyFunctionTable = false;
+ emitBssSegments = false;
+}
+
namespace {
// Create enum with OPT_xxx values for each option in Options.td
@@ -90,6 +104,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
auto *ctx = new CommonLinkerContext;
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
+ ctx->e.cleanupCallback = []() { wasm::ctx.reset(); };
ctx->e.logName = args::getFilenameWithoutExe(args[0]);
ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
"-error-limit=0 to see all errors)";
More information about the llvm-commits
mailing list