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

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 11:53:21 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Sam Clegg (sbc100)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/78770.diff


3 Files Affected:

- (modified) lld/ELF/Driver.cpp (+1-1) 
- (modified) lld/wasm/Config.h (+2) 
- (modified) lld/wasm/Driver.cpp (+13) 


``````````diff
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)";

``````````

</details>


https://github.com/llvm/llvm-project/pull/78770


More information about the llvm-commits mailing list