[PATCH] D128037: [ORC][LLJIT] Add atexit support.
Sunho Kim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 17 02:47:29 PDT 2022
sunho updated this revision to Diff 437831.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128037/new/
https://reviews.llvm.org/D128037
Files:
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
Index: llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
===================================================================
--- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -143,6 +143,9 @@
JITEvaluatedSymbol(pointerToJITTargetAddress(this),
JITSymbolFlags::Exported);
StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(registerCxaAtExitHelper),
+ JITSymbolFlags());
+ StdInterposes[J.mangleAndIntern("__lljit.atexit_helper")] =
JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
JITSymbolFlags());
@@ -190,6 +193,14 @@
GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
{PlatformInstanceDecl, DSOHandle});
+ auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
+ auto *AtExitCallbackTy = FunctionType::get(VoidTy, {}, false);
+ auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
+ addHelperAndWrapper(*M, "atexit",
+ FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
+ GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
+ {PlatformInstanceDecl, DSOHandle});
+
return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
}
@@ -413,16 +424,25 @@
.takeError();
}
- static void registerAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
- void *DSOHandle) {
+ static void registerCxaAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
+ void *DSOHandle) {
LLVM_DEBUG({
- dbgs() << "Registering atexit function " << (void *)F << " for JD "
+ dbgs() << "Registering cxa atexit function " << (void *)F << " for JD "
<< (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
});
static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
F, Ctx, DSOHandle);
}
+ static void registerAtExitHelper(void *Self, void *DSOHandle, void (*F)()) {
+ LLVM_DEBUG({
+ dbgs() << "Registering atexit function " << (void *)F << " for JD "
+ << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
+ });
+ static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
+ reinterpret_cast<void (*)(void *)>(F), nullptr, DSOHandle);
+ }
+
static void runAtExitsHelper(void *Self, void *DSOHandle) {
LLVM_DEBUG({
dbgs() << "Running atexit functions for JD "
@@ -450,12 +470,12 @@
auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
auto *VoidTy = Type::getVoidTy(*Ctx);
auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
- auto *AtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
- auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
+ auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
+ auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
addHelperAndWrapper(
*M, "__cxa_atexit",
- FunctionType::get(IntTy, {AtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
+ FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
false),
GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
{PlatformInstanceDecl});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128037.437831.patch
Type: text/x-patch
Size: 3524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220617/91962f7b/attachment.bin>
More information about the llvm-commits
mailing list