Skip to content
Snippets Groups Projects
Commit cad193e2 authored by Frederich Munch's avatar Frederich Munch Committed by Axel Naumann
Browse files

Implement atexit override. Windows uses atexit is to drive invoke static...

Implement atexit override. Windows uses atexit is to drive invoke static destructors, and using atexit on other platforms will cause cling to crash.
parent ca397448
No related branches found
No related tags found
No related merge requests found
......@@ -282,6 +282,10 @@ namespace cling {
///
void IncludeCRuntime();
///\brief Init atexit runtime delegation.
///
void InitAExit();
///\brief The target constructor to be called from both the delegating
/// constructors. parentInterp might be nullptr.
///
......
......@@ -216,6 +216,8 @@ namespace cling {
// Prevents stripping the symbol due to dead-code optimization.
internal::symbol_requester();
}
InitAExit();
}
///\brief Constructor for the child Interpreter.
......@@ -276,6 +278,25 @@ namespace cling {
}
}
void Interpreter::InitAExit() {
if (isInSyntaxOnlyMode())
return;
const char* Linkage = getCI()->getLangOpts().CPlusPlus ? "extern \"C\"" : "";
llvm::SmallString<512> Buf;
llvm::raw_svector_ostream Strm(Buf);
Strm << Linkage << " int __cxa_atexit(void (*f) (void*), void*, void*);\n"
<< Linkage << " int atexit(void(*f)()) {"
"return __cxa_atexit((void(*)(void*))f, nullptr, (void*)"
<< m_Executor.get() << "); }\n";
Transaction *T = nullptr;
declare(Strm.str(), &T);
if (llvm::Module* M = T ? T->getModule() : nullptr) {
if (const llvm::GlobalValue* GV = M->getNamedValue("atexit"))
m_Executor->getPointerToGlobalFromJIT(*GV);
}
}
void Interpreter::IncludeCXXRuntime() {
// Set up common declarations which are going to be available
// only at runtime
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment