Skip to content

[lld][WebAssembly] Reset context object after each link #78770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lld/wasm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -138,6 +138,8 @@ struct Ctx {
llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>,
0>
whyExtractRecords;

void reset();
};

extern Ctx ctx;
Expand Down
15 changes: 15 additions & 0 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ namespace lld::wasm {
Configuration *config;
Ctx ctx;

void Ctx::reset() {
objectFiles.clear();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: shouldn't we reset all the fields, including the bool fields? (And maybe initialize isPic to some explicit value rather than leaving it as uninited?)

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
Expand Down Expand Up @@ -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)";
Expand Down