-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
Conversation
@llvm/pr-subscribers-lld-wasm @llvm/pr-subscribers-lld Author: Sam Clegg (sbc100) ChangesThis 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. Full diff: https://github.com/llvm/llvm-project/pull/78770.diff 3 Files Affected:
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 5ccc65600dcb910..9c040de1e47e66b 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -130,7 +130,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
ctx->e.cleanupCallback = []() {
- elf::ctx.reset();
+ //elf::ctx.reset();
symtab = SymbolTable();
outputSections.clear();
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index dc7ca265e9a2cb1..308f8ab3eb0ebed 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -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 4a4f9a96227946d..96a214f76ebd70b 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -47,6 +47,16 @@ namespace lld::wasm {
Configuration *config;
Ctx ctx;
+void Ctx::reset() {
+ objectFiles.clear();
+ stubFiles.clear();
+ sharedFiles.clear();
+ bitcodeFiles.clear();
+ syntheticFunctions.clear();
+ syntheticGlobals.clear();
+ syntheticTables.clear();
+}
+
namespace {
// Create enum with OPT_xxx values for each option in Options.td
@@ -90,6 +100,9 @@ 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)";
|
I wonder if we can replace these elaborate |
✅ With the latest revision this PR passed the C/C++ code formatter. |
Or just |
Yeah, I'm guessing there was some reason the original author didn't take that much simpler approach. I'll go with the same method for now for consistency and we can perhaps followup with a simplification. |
@MaskRay what would you think of such a simplification here? Maybe it would result in a little more allocator churn.. but that doesn't seem like a big concern if it only happens between lldMain operations (i.e. infrequently) |
Hard to imagine that the single assignment would be anything more than noise in comparison to doing an object-linkage operation. |
@@ -47,6 +47,16 @@ namespace lld::wasm { | |||
Configuration *config; | |||
Ctx ctx; | |||
|
|||
void Ctx::reset() { | |||
objectFiles.clear(); |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as this seems urgent.
wasm should have a unittest similar to unittests/AsLibELF/SomeDrivers.cpp
for library users, which can be done in the future.
This mirrors who the ELF linker works. I wasn't able to find anywhere where this is currently tested. Followup to llvm#78640, which triggered a regression.
Thanks for the pointer to unittests/AsLibELF/SomeDrivers.cpp. Will land this now and followup there. |
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.