[clang] 752dbd6 - [clang-repl] Improve flags responsible for generating shared wasm binaries (#116735)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 00:07:43 PST 2024
Author: Anutosh Bhat
Date: 2024-11-19T09:07:40+01:00
New Revision: 752dbd6112affa418e33910ac08bf9921f9c270b
URL: https://github.com/llvm/llvm-project/commit/752dbd6112affa418e33910ac08bf9921f9c270b
DIFF: https://github.com/llvm/llvm-project/commit/752dbd6112affa418e33910ac08bf9921f9c270b.diff
LOG: [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
Added:
Modified:
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Interpreter/Wasm.cpp
clang/lib/Interpreter/Wasm.h
Removed:
################################################################################
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 bc96da811d44cb..73ad766e655180 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -196,7 +196,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 cfe-commits
mailing list