[llvm-branch-commits] [clang] release/19.x: [clang-repl] Improve flags responsible for generating shared wasm binaries (#116735) (PR #116766)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 25 00:33:30 PST 2024
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/116766
>From e032d7ad80f8d185626b39751f672932f92dc033 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat <andersonbhat491 at gmail.com>
Date: Tue, 19 Nov 2024 13:37:40 +0530
Subject: [PATCH] [clang-repl] Improve flags responsible for generating shared
wasm binaries (#116735)
There are a couple changes in this PR that help getting clang-repl to
run in the browser. Using a jupyterlite instance for the example pasted
below
1) Updating flags responsible for generating shared wasm binaries that
need to be dynamically loaded Most Importantly as can be seen in the
changes `shared` and `allow-undefined` are crucial.
![image](https://github.com/user-attachments/assets/1183fd44-8951-496a-899a-e4af39a48447)
2) While exiting we encounter this.
![image](https://github.com/user-attachments/assets/9487a3f4-7200-471d-ba88-09e98ccbc47a)
Now as can be seen here
https://github.com/llvm/llvm-project/blob/cd418030de7ae75750bc4e48d1238baf03c675e5/clang/lib/Interpreter/Interpreter.cpp#L421-L430
We call cleanUP in the destructor. Now cleanUP through
IncrementalExecutor tries to deinitialize the JIT which wasn't even
intialized as runCtors in wasm.cpp is a no-op
https://github.com/llvm/llvm-project/blob/cd418030de7ae75750bc4e48d1238baf03c675e5/clang/lib/Interpreter/IncrementalExecutor.cpp#L94-L101
https://github.com/llvm/llvm-project/blob/cd418030de7ae75750bc4e48d1238baf03c675e5/clang/lib/Interpreter/Wasm.cpp#L107-L109
(cherry picked from commit 752dbd6112affa418e33910ac08bf9921f9c270b)
---
clang/lib/Interpreter/IncrementalExecutor.h | 2 +-
clang/lib/Interpreter/Interpreter.cpp | 1 -
clang/lib/Interpreter/Wasm.cpp | 10 ++++++++--
clang/lib/Interpreter/Wasm.h | 1 +
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Interpreter/IncrementalExecutor.h b/clang/lib/Interpreter/IncrementalExecutor.h
index 7954cde36588bd..dbd61f0b8b1ebb 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -56,7 +56,7 @@ class IncrementalExecutor {
virtual llvm::Error addModule(PartialTranslationUnit &PTU);
virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
virtual llvm::Error runCtors() const;
- llvm::Error cleanUp();
+ virtual llvm::Error cleanUp();
llvm::Expected<llvm::orc::ExecutorAddr>
getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index b4882ab5d22363..c0b8bfebb43437 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -192,7 +192,6 @@ IncrementalCompilerBuilder::CreateCpp() {
#ifdef __EMSCRIPTEN__
Argv.push_back("-target");
Argv.push_back("wasm32-unknown-emscripten");
- Argv.push_back("-pie");
Argv.push_back("-shared");
#endif
Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end());
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index 1001410aa0f279..79efbaa03982d0 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -72,13 +72,13 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
OutputFile.close();
std::vector<const char *> LinkerArgs = {"wasm-ld",
- "-pie",
+ "-shared",
"--import-memory",
"--no-entry",
"--export-all",
"--experimental-pic",
- "--no-export-dynamic",
"--stack-first",
+ "--allow-undefined",
OutputFileName.c_str(),
"-o",
OutputFileName.c_str()};
@@ -109,6 +109,12 @@ llvm::Error WasmIncrementalExecutor::runCtors() const {
return llvm::Error::success();
}
+llvm::Error WasmIncrementalExecutor::cleanUp() const {
+ // Can't call cleanUp through IncrementalExecutor as it
+ // tries to deinitialize JIT which hasn't been initialized
+ return llvm::Error::success();
+}
+
WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
} // namespace clang
diff --git a/clang/lib/Interpreter/Wasm.h b/clang/lib/Interpreter/Wasm.h
index b1fd88024f14d7..4632613326d39b 100644
--- a/clang/lib/Interpreter/Wasm.h
+++ b/clang/lib/Interpreter/Wasm.h
@@ -28,6 +28,7 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
llvm::Error addModule(PartialTranslationUnit &PTU) override;
llvm::Error removeModule(PartialTranslationUnit &PTU) override;
llvm::Error runCtors() const override;
+ llvm::Error cleanUp() override;
~WasmIncrementalExecutor() override;
};
More information about the llvm-branch-commits
mailing list