-
Notifications
You must be signed in to change notification settings - Fork 34
[interp] Register runtime symbols for clang-repl #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
b912765
9c6be69
e8a6b27
740bcb3
4ef7df9
8d91bcd
e15be64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -90,6 +90,18 @@ | |||||
#include <unistd.h> | ||||||
#endif // WIN32 | ||||||
|
||||||
#if CLANG_VERSION_MAJOR > 22 | ||||||
extern "C" void* __clang_Interpreter_SetValueWithAlloc(void* This, void* OutVal, | ||||||
void* OpaqueType) | ||||||
#else | ||||||
void* __clang_Interpreter_SetValueWithAlloc(void* This, void* OutVal, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function '__clang_Interpreter_SetValueWithAlloc' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for function '__clang_Interpreter_SetValueWithAlloc' [readability-identifier-naming] void* __clang_Interpreter_SetValueWithAlloc(void* This, void* OutVal,
^ this fix will not be applied because it overlaps with another fix |
||||||
void* OpaqueType); | ||||||
#endif | ||||||
|
||||||
extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: declaration uses identifier '__clang_Interpreter_SetValueNoAlloc', which is a reserved identifier [bugprone-reserved-identifier] extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This,
^ this fix will not be applied because it overlaps with another fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for function '__clang_Interpreter_SetValueNoAlloc' [readability-identifier-naming] extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This,
^ this fix will not be applied because it overlaps with another fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: declaration uses identifier '__clang_Interpreter_SetValueNoAlloc', which is a reserved identifier [bugprone-reserved-identifier] extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This,
^ this fix will not be applied because it overlaps with another fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: invalid case style for function '__clang_Interpreter_SetValueNoAlloc' [readability-identifier-naming] extern "C" void __clang_Interpreter_SetValueNoAlloc(void* This,
^ this fix will not be applied because it overlaps with another fix |
||||||
void* OutVal, | ||||||
void* OpaqueType, ...); | ||||||
|
||||||
namespace Cpp { | ||||||
|
||||||
using namespace clang; | ||||||
|
@@ -3330,6 +3342,37 @@ | |||||
} | ||||||
|
||||||
namespace { | ||||||
#ifndef CPPINTEROP_USE_CLING | ||||||
static bool DefineAbsoluteSymbol(compat::Interpreter& I, | ||||||
aaronj0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
const char* linker_mangled_name, | ||||||
uint64_t address) { | ||||||
|
||||||
using namespace llvm; | ||||||
using namespace llvm::orc; | ||||||
|
||||||
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine(I); | ||||||
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "llvm::orc::ExecutionSession" is directly included [misc-include-cleaner] lib/CppInterOp/CppInterOp.cpp:41: - #if CLANG_VERSION_MAJOR >= 19
+ #include <llvm/ExecutionEngine/Orc/Core.h>
+ #if CLANG_VERSION_MAJOR >= 19 |
||||||
JITDylib& DyLib = *Jit.getProcessSymbolsJITDylib().get(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "llvm::orc::JITDylib" is directly included [misc-include-cleaner] JITDylib& DyLib = *Jit.getProcessSymbolsJITDylib().get();
^ |
||||||
|
||||||
llvm::orc::SymbolMap InjectedSymbols; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "llvm::orc::SymbolMap" is directly included [misc-include-cleaner] lib/CppInterOp/CppInterOp.cpp:41: - #if CLANG_VERSION_MAJOR >= 19
+ #include <llvm/ExecutionEngine/Orc/CoreContainers.h>
+ #if CLANG_VERSION_MAJOR >= 19 |
||||||
auto& DL = compat::getExecutionEngine(I)->getDataLayout(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'auto &DL' can be declared as 'const auto &DL' [readability-qualified-auto]
Suggested change
|
||||||
char GlobalPrefix = DL.getGlobalPrefix(); | ||||||
std::string tmp(linker_mangled_name); | ||||||
if (GlobalPrefix != '\0') { | ||||||
tmp = std::string(1, GlobalPrefix) + tmp; | ||||||
} | ||||||
auto Name = ES.intern(tmp); | ||||||
InjectedSymbols[Name] = | ||||||
ExecutorSymbolDef(ExecutorAddr(address), JITSymbolFlags::Exported); | ||||||
|
||||||
if (Error Err = DyLib.define(absoluteSymbols(InjectedSymbols))) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "llvm::orc::absoluteSymbols" is directly included [misc-include-cleaner] lib/CppInterOp/CppInterOp.cpp:41: - #if CLANG_VERSION_MAJOR >= 19
+ #include <llvm/ExecutionEngine/Orc/AbsoluteSymbols.h>
+ #if CLANG_VERSION_MAJOR >= 19 |
||||||
logAllUnhandledErrors(std::move(Err), errs(), | ||||||
"DefineAbsoluteSymbol error: "); | ||||||
return true; | ||||||
} | ||||||
return false; | ||||||
} | ||||||
#endif | ||||||
|
||||||
static std::string MakeResourcesPath() { | ||||||
StringRef Dir; | ||||||
#ifdef LLVM_BINARY_DIR | ||||||
|
@@ -3442,6 +3485,26 @@ | |||||
sInterpreters->back().get()}); | ||||||
|
||||||
assert(sInterpreters->size() == sInterpreterASTMap->size()); | ||||||
|
||||||
// Define runtime symbols in the JIT dylib for clang-repl | ||||||
#ifndef CPPINTEROP_USE_CLING | ||||||
#if CLANG_VERSION_MAJOR > 22 | ||||||
DefineAbsoluteSymbol(*I, "__clang_Interpreter_SetValueWithAlloc", | ||||||
(uint64_t)&__clang_Interpreter_SetValueNoAlloc); | ||||||
#else | ||||||
auto* D = static_cast<clang::Decl*>( | ||||||
Cpp::GetNamed("__clang_Interpreter_SetValueWithAlloc")); | ||||||
if (auto* FD = llvm::dyn_cast<FunctionDecl>(D)) { | ||||||
auto GD = GlobalDecl(FD); | ||||||
std::string mangledName; | ||||||
compat::maybeMangleDeclName(GD, mangledName); | ||||||
DefineAbsoluteSymbol(*I, mangledName.c_str(), | ||||||
(uint64_t)&__clang_Interpreter_SetValueWithAlloc); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] (uint64_t)&__clang_Interpreter_SetValueWithAlloc);
^ |
||||||
} | ||||||
#endif | ||||||
DefineAbsoluteSymbol(*I, "__clang_Interpreter_SetValueNoAlloc", | ||||||
(uint64_t)&__clang_Interpreter_SetValueNoAlloc); | ||||||
aaronj0 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] (uint64_t)&__clang_Interpreter_SetValueNoAlloc);
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] (uint64_t)&__clang_Interpreter_SetValueNoAlloc);
^ |
||||||
#endif | ||||||
return I; | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: declaration uses identifier '__clang_Interpreter_SetValueWithAlloc', which is a reserved identifier [bugprone-reserved-identifier]
this fix will not be applied because it overlaps with another fix