[clang] 1833848 - [clang-repl] Support wasm64 execution (#225311)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 22 00:42:01 PDT 2026
Author: Anutosh Bhat
Date: 2026-09-22T07:41:55Z
New Revision: 1833848c3e6ddc1d670cc0adea027867b9ed742b
URL: https://github.com/llvm/llvm-project/commit/1833848c3e6ddc1d670cc0adea027867b9ed742b
DIFF: https://github.com/llvm/llvm-project/commit/1833848c3e6ddc1d670cc0adea027867b9ed742b.diff
LOG: [clang-repl] Support wasm64 execution (#225311)
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 !
Added:
Modified:
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Interpreter/Wasm.cpp
Removed:
################################################################################
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",
More information about the cfe-commits
mailing list