https://github.com/anutosh491 created 
https://github.com/llvm/llvm-project/pull/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 !

>From d164b66d66bbf28ae98cad006bb925993bf08968 Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Tue, 22 Sep 2026 12:23:55 +0530
Subject: [PATCH] [clang-repl] Support wasm64 execution

---
 clang/lib/Interpreter/Interpreter.cpp | 5 +++--
 clang/lib/Interpreter/Wasm.cpp        | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 092f3ede771f65..512b28be5a544e 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 a36a7f7b027e8b..573c8910d3a414 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",

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

Reply via email to