[clang] [clang-repl] Support wasm64 execution (PR #225311)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 22 00:01:10 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Anutosh Bhat (anutosh491)
<details>
<summary>Changes</summary>
Emscripten-forge is adding wasm64 builds on its emscripten 6-x branch which exposed two wasm32 hardcoded assumptions in clang-repl's WebAssembly execution path.
`IncrementalCompilerBuilder::CreateCpp()` currently hardcodes `wasm32-unknown-emscripten`, even when clang-repl itself is built for wasm64.
Once Clang emits a wasm64 object, the in-process linker must also select the correct emulation. `wasm-ld` defaults to wasm32 and otherwise fails in `InputFile::checkArch()` with:
```text
must specify -mwasm64 to process wasm64 object files
```
The pipeline is this
```
lldMain
→ lld::wasm::link
→ LinkerDriver::linkerMain
→ createFiles
→ addFile
→ createObjectFile
→ ObjFile::ObjFile
→ InputFile::checkArch
→ fatal: must specify -mwasm64 to process wasm64 object files
```
This patch introduces 2 atomic patches fixing the only 2 buggy sources !
---
Full diff: https://github.com/llvm/llvm-project/pull/225311.diff
2 Files Affected:
- (modified) clang/lib/Interpreter/Interpreter.cpp (+3-2)
- (modified) clang/lib/Interpreter/Wasm.cpp (+5)
``````````diff
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 092f3ede771f6..512b28be5a544 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -288,17 +288,18 @@ IncrementalCompilerBuilder::create(std::string TT,
llvm::Expected<std::unique_ptr<CompilerInstance>>
IncrementalCompilerBuilder::CreateCpp() {
+ std::string TT = TargetTriple ? *TargetTriple : llvm::sys::getProcessTriple();
+
std::vector<const char *> Argv;
Argv.reserve(5 + 1 + UserArgs.size());
Argv.push_back("-xc++");
#ifdef __EMSCRIPTEN__
Argv.push_back("-target");
- Argv.push_back("wasm32-unknown-emscripten");
+ Argv.push_back(TT.c_str());
Argv.push_back("-fvisibility=default");
#endif
llvm::append_range(Argv, UserArgs);
- std::string TT = TargetTriple ? *TargetTriple : llvm::sys::getProcessTriple();
return IncrementalCompilerBuilder::create(TT, Argv);
}
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index a36a7f7b027e8..573c8910d3a41 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -18,6 +18,7 @@
#include <llvm/IR/Module.h>
#include <llvm/MC/TargetRegistry.h>
#include <llvm/Target/TargetMachine.h>
+#include <llvm/TargetParser/Triple.h>
#include <clang/Interpreter/Interpreter.h>
@@ -117,7 +118,11 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
ObjectFileOutput.close();
+ std::string Emulation = "-m";
+ Emulation +=
+ llvm::Triple(PTU.TheModule->getTargetTriple()).getArchName().str();
std::vector<const char *> LinkerArgs = {"wasm-ld",
+ Emulation.c_str(),
"-shared",
"--import-memory",
"--stack-first",
``````````
</details>
https://github.com/llvm/llvm-project/pull/225311
More information about the cfe-commits
mailing list