Skip to content

Commit e032d7a

Browse files
anutosh491tru
authored andcommitted
[clang-repl] Improve flags responsible for generating shared wasm binaries (llvm#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 752dbd6)
1 parent 02930b8 commit e032d7a

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ IncrementalCompilerBuilder::CreateCpp() {
192192
#ifdef __EMSCRIPTEN__
193193
Argv.push_back("-target");
194194
Argv.push_back("wasm32-unknown-emscripten");
195-
Argv.push_back("-pie");
196195
Argv.push_back("-shared");
197196
#endif
198197
Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end());

clang/lib/Interpreter/Wasm.cpp

Lines changed: 8 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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)