[clang] [clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases (PR #133037)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 22:44:24 PDT 2025
https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/133037
>From dfe49e826705a5e9371e17e66e40c31602beea8e Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Wed, 26 Mar 2025 10:33:37 +0530
Subject: [PATCH 1/2] Implement LoadDynamicLibrary for clang-repl wasm use
cases
---
clang/lib/Interpreter/Interpreter.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index fa4c1439c9261..b4c68f340abc0 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/VirtualFileSystem.h"
#ifdef __EMSCRIPTEN__
#include "Wasm.h"
+#include <dlfcn.h>
#endif // __EMSCRIPTEN__
#include "clang/AST/ASTConsumer.h"
@@ -711,6 +712,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
}
llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
+#ifdef __EMSCRIPTEN__
+ void* handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
+ if (!handle) {
+ llvm::errs() << dlerror() << '\n';
+ return llvm::make_error<llvm::StringError>(
+ "Failed to load dynamic library", llvm::inconvertibleErrorCode());
+ }
+#else
auto EE = getExecutionEngine();
if (!EE)
return EE.takeError();
@@ -722,6 +731,7 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
EE->getMainJITDylib().addGenerator(std::move(*DLSG));
else
return DLSG.takeError();
+#endif
return llvm::Error::success();
}
>From cb274780d84c5355c4aede7b8fe7501dc300bc02 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Wed, 26 Mar 2025 11:14:06 +0530
Subject: [PATCH 2/2] formatting
---
clang/lib/Interpreter/Interpreter.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index b4c68f340abc0..f8c8d0a425659 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -713,11 +713,11 @@ llvm::Error Interpreter::Undo(unsigned N) {
llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
#ifdef __EMSCRIPTEN__
- void* handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
+ void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
llvm::errs() << dlerror() << '\n';
- return llvm::make_error<llvm::StringError>(
- "Failed to load dynamic library", llvm::inconvertibleErrorCode());
+ return llvm::make_error<llvm::StringError>("Failed to load dynamic library",
+ llvm::inconvertibleErrorCode());
}
#else
auto EE = getExecutionEngine();
More information about the cfe-commits
mailing list