llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Anutosh Bhat (anutosh491) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/223926.diff 1 Files Affected: - (modified) clang/lib/Interpreter/Wasm.cpp (+6) ``````````diff 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()); `````````` </details> https://github.com/llvm/llvm-project/pull/223926 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
