https://github.com/anutosh491 created 
https://github.com/llvm/llvm-project/pull/223926

Clang-Repl’s Wasm executor calls `lld::lldMain()` for every incremental input, 
but currently ignores `Result.canRunAgain`.

Ordinary linker errors remain recoverable:

```text
retCode=1 canRunAgain=1
```

A fatal LLD error can instead return:

```text
retCode=1 canRunAgain=0
```

In that case, LLD’s state may no longer be safe. This patch follows LLD’s 
standalone driver and calls `lld::exitLld()` rather than allowing Clang-Repl to 
perform another incremental link.

I verified this with the real Emscripten `lldWasm` library: a normal invalid 
wasm file input remained reusable (ordinary error), while a valid but 
non-relocatable Wasm module triggered `canRunAgain=false` (fatal error) and 
terminated the runtime with status 1.

>From 15905b4c9da9fc5d695d3babd3e626b7fec5025f Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Wed, 16 Sep 2026 12:13:44 +0530
Subject: [PATCH] [clang-repl] Respect LLD's canRunAgain result

---
 clang/lib/Interpreter/Wasm.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index 96600cf9fa6d0..e8dbffdff789c 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -48,6 +48,7 @@ struct Result {
 
 Result lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
                llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers);
+[[noreturn]] void exitLld(int val);
 
 namespace wasm {
 bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
@@ -132,6 +133,11 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
   lld::Result Result =
       lld::lldMain(LinkerArgs, llvm::outs(), llvm::errs(), WasmDriverArgs);
 
+  // A fatal error may have recovered control flow without restoring LLD's
+  // process state. Do not allow another incremental link in that case.
+  if (!Result.canRunAgain)
+    lld::exitLld(Result.retCode);
+
   if (Result.retCode)
     return llvm::make_error<llvm::StringError>(
         "Failed to link incremental module", llvm::inconvertibleErrorCode());

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to