Skip to content

Commit a7ccd0e

Browse files
committed
Implement LoadDynamicLibrary for clang-repl wasm use cases
1 parent 80d5185 commit a7ccd0e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

clang/lib/Interpreter/Interpreter.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/VirtualFileSystem.h"
1919
#ifdef __EMSCRIPTEN__
2020
#include "Wasm.h"
21+
#include <dlfcn.h>
2122
#endif // __EMSCRIPTEN__
2223

2324
#include "clang/AST/ASTConsumer.h"
@@ -711,6 +712,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
711712
}
712713

713714
llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
715+
#ifdef __EMSCRIPTEN__
716+
void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
717+
if (!handle) {
718+
llvm::errs() << dlerror() << '\n';
719+
return llvm::make_error<llvm::StringError>("Failed to load dynamic library",
720+
llvm::inconvertibleErrorCode());
721+
}
722+
#else
714723
auto EE = getExecutionEngine();
715724
if (!EE)
716725
return EE.takeError();
@@ -722,6 +731,7 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
722731
EE->getMainJITDylib().addGenerator(std::move(*DLSG));
723732
else
724733
return DLSG.takeError();
734+
#endif
725735

726736
return llvm::Error::success();
727737
}

0 commit comments

Comments
 (0)