Skip to content

Commit 752dbd6

Browse files
authoredNov 19, 2024··
[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
1 parent e7e5541 commit 752dbd6

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed
 

‎clang/lib/Interpreter/IncrementalExecutor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class IncrementalExecutor {
5656
virtual llvm::Error addModule(PartialTranslationUnit &PTU);
5757
virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
5858
virtual llvm::Error runCtors() const;
59-
llvm::Error cleanUp();
59+
virtual llvm::Error cleanUp();
6060
llvm::Expected<llvm::orc::ExecutorAddr>
6161
getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
6262

‎clang/lib/Interpreter/Interpreter.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ IncrementalCompilerBuilder::CreateCpp() {
196196
#ifdef __EMSCRIPTEN__
197197
Argv.push_back("-target");
198198
Argv.push_back("wasm32-unknown-emscripten");
199-
Argv.push_back("-pie");
200199
Argv.push_back("-shared");
201200
#endif
202201
Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end());

‎clang/lib/Interpreter/Wasm.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
7272
OutputFile.close();
7373

7474
std::vector<const char *> LinkerArgs = {"wasm-ld",
75-
"-pie",
75+
"-shared",
7676
"--import-memory",
7777
"--no-entry",
7878
"--export-all",
7979
"--experimental-pic",
80-
"--no-export-dynamic",
8180
"--stack-first",
81+
"--allow-undefined",
8282
OutputFileName.c_str(),
8383
"-o",
8484
OutputFileName.c_str()};
@@ -109,6 +109,12 @@ llvm::Error WasmIncrementalExecutor::runCtors() const {
109109
return llvm::Error::success();
110110
}
111111

112+
llvm::Error WasmIncrementalExecutor::cleanUp() const {
113+
// Can't call cleanUp through IncrementalExecutor as it
114+
// tries to deinitialize JIT which hasn't been initialized
115+
return llvm::Error::success();
116+
}
117+
112118
WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
113119

114120
} // namespace clang

‎clang/lib/Interpreter/Wasm.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
2828
llvm::Error addModule(PartialTranslationUnit &PTU) override;
2929
llvm::Error removeModule(PartialTranslationUnit &PTU) override;
3030
llvm::Error runCtors() const override;
31+
llvm::Error cleanUp() override;
3132

3233
~WasmIncrementalExecutor() override;
3334
};

0 commit comments

Comments
 (0)
Please sign in to comment.