Author: Anutosh Bhat Date: 2026-09-16T14:08:23+05:30 New Revision: 72e9411e1bd481669ca9d6f7a55fe900ea5f4b36
URL: https://github.com/llvm/llvm-project/commit/72e9411e1bd481669ca9d6f7a55fe900ea5f4b36 DIFF: https://github.com/llvm/llvm-project/commit/72e9411e1bd481669ca9d6f7a55fe900ea5f4b36.diff LOG: [clang-repl] Respect LLD's canRunAgain result (#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. Added: Modified: clang/lib/Interpreter/Wasm.cpp Removed: ################################################################################ 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
