Skip to content

Commit 2bfa5ca

Browse files
authored
[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.
1 parent 58780b8 commit 2bfa5ca

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lld/wasm/Config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct Ctx {
124124
llvm::SmallVector<InputTable *, 0> syntheticTables;
125125

126126
// True if we are creating position-independent code.
127-
bool isPic;
127+
bool isPic = false;
128128

129129
// True if we have an MVP input that uses __indirect_function_table and which
130130
// requires it to be allocated to table number 0.
@@ -138,6 +138,8 @@ struct Ctx {
138138
llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>,
139139
0>
140140
whyExtractRecords;
141+
142+
void reset();
141143
};
142144

143145
extern Ctx ctx;

lld/wasm/Driver.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ namespace lld::wasm {
4747
Configuration *config;
4848
Ctx ctx;
4949

50+
void Ctx::reset() {
51+
objectFiles.clear();
52+
stubFiles.clear();
53+
sharedFiles.clear();
54+
bitcodeFiles.clear();
55+
syntheticFunctions.clear();
56+
syntheticGlobals.clear();
57+
syntheticTables.clear();
58+
whyExtractRecords.clear();
59+
isPic = false;
60+
legacyFunctionTable = false;
61+
emitBssSegments = false;
62+
}
63+
5064
namespace {
5165

5266
// 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,
90104
auto *ctx = new CommonLinkerContext;
91105

92106
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
107+
ctx->e.cleanupCallback = []() { wasm::ctx.reset(); };
93108
ctx->e.logName = args::getFilenameWithoutExe(args[0]);
94109
ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
95110
"-error-limit=0 to see all errors)";

0 commit comments

Comments
 (0)