Simplify cxa_atexit(), first part.
Remove trigger__cxa_atexit(), we will just remap until successful. Remove unused dso parameter. Instead of friending just provide a function. Pass a transaction, the typesafe way.
This commit is contained in:
parent
1e86611693
commit
baca204185
@ -49,9 +49,6 @@ namespace clang {
|
||||
namespace cling {
|
||||
namespace runtime {
|
||||
namespace internal {
|
||||
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso,
|
||||
void* interp);
|
||||
|
||||
class DynamicExprInfo;
|
||||
template <typename T>
|
||||
T EvaluateT(DynamicExprInfo* ExprInfo, clang::DeclContext* DC);
|
||||
@ -586,11 +583,14 @@ namespace cling {
|
||||
///
|
||||
void* getAddressOfGlobal(llvm::StringRef SymName, bool* fromJIT = 0) const;
|
||||
|
||||
friend class runtime::internal::LifetimeHandler;
|
||||
friend int runtime::internal::local_cxa_atexit(void (*func) (void*),
|
||||
void* arg, void* dso,
|
||||
void* interp);
|
||||
///\brief Add an atexit function.
|
||||
///
|
||||
///\param[in] Func - Function to be called.
|
||||
///\param[in] Arg - argument passed to the function.
|
||||
///
|
||||
void AddAtExitFunc(void (*Func) (void*), void* Arg);
|
||||
|
||||
friend class runtime::internal::LifetimeHandler;
|
||||
// FIXME: workaround until JIT supports exceptions
|
||||
static jmp_buf*& getNullDerefJump() { return m_JumpBuf; }
|
||||
};
|
||||
|
@ -49,8 +49,7 @@ namespace cling {
|
||||
///
|
||||
/// Implemented in Interpreter.cpp
|
||||
///
|
||||
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso,
|
||||
void* interp);
|
||||
int local_cxa_atexit(void (*func) (void*), void* arg, void* interp);
|
||||
|
||||
/// \brief Some of clang's routines rely on valid source locations and
|
||||
/// source ranges. This member can be looked up and source locations and
|
||||
@ -183,7 +182,7 @@ extern "C" {
|
||||
|
||||
extern "C" {
|
||||
int cling_cxa_atexit(void (*func) (void*), void* arg, void* dso) {
|
||||
return cling::runtime::internal::local_cxa_atexit(func, arg, dso,
|
||||
return cling::runtime::internal::local_cxa_atexit(func, arg,
|
||||
(void*)cling::runtime::gCling);
|
||||
}
|
||||
|
||||
|
@ -116,12 +116,11 @@ void IncrementalExecutor::remapCXAAtExit() {
|
||||
m_CxaAtExitRemapped = true;
|
||||
}
|
||||
|
||||
int IncrementalExecutor::CXAAtExit(void (*func) (void*), void* arg, void* dso,
|
||||
void* clingT) {
|
||||
void IncrementalExecutor::AddAtExitFunc(void (*func) (void*), void* arg,
|
||||
const cling::Transaction* clingT) {
|
||||
// Register a CXAAtExit function
|
||||
cling::Transaction* T = (cling::Transaction*)clingT;
|
||||
m_AtExitFuncs.push_back(CXAAtExitElement(func, arg, dso, T));
|
||||
return 0; // happiness
|
||||
m_AtExitFuncs.push_back(CXAAtExitElement(func, arg, T));
|
||||
}
|
||||
|
||||
void unresolvedSymbol()
|
||||
|
@ -25,13 +25,6 @@ namespace llvm {
|
||||
|
||||
namespace cling {
|
||||
class Transaction;
|
||||
namespace runtime {
|
||||
namespace internal {
|
||||
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso,
|
||||
void* interp);
|
||||
} // end namespace internal
|
||||
} // end namespace runtime
|
||||
|
||||
class StoredValueRef;
|
||||
|
||||
class IncrementalExecutor {
|
||||
@ -77,13 +70,12 @@ namespace cling {
|
||||
///\param [in] func - The function to be called on exit or unloading of
|
||||
/// shared lib.(The destructor of the object.)
|
||||
///\param [in] arg - The argument the func to be called with.
|
||||
///\param [in] dso - The dynamic shared object handle.
|
||||
///\param [in] fromT - The unloading of this transaction will trigger the
|
||||
/// atexit function.
|
||||
///
|
||||
CXAAtExitElement(void (*func) (void*), void* arg, void* dso,
|
||||
Transaction* fromT):
|
||||
m_Func(func), m_Arg(arg), m_DSO(dso), m_FromT(fromT) {}
|
||||
CXAAtExitElement(void (*func) (void*), void* arg,
|
||||
const Transaction* fromT):
|
||||
m_Func(func), m_Arg(arg), m_FromT(fromT) {}
|
||||
|
||||
///\brief The function to be called.
|
||||
///
|
||||
@ -93,14 +85,10 @@ namespace cling {
|
||||
///
|
||||
void* m_Arg;
|
||||
|
||||
/// \brief The DSO handle.
|
||||
///
|
||||
void* m_DSO;
|
||||
|
||||
///\brief Clang's top level declaration, whose unloading will trigger the
|
||||
/// call this atexit function.
|
||||
///
|
||||
Transaction* m_FromT; //FIXME: Should be bound to the llvm symbol.
|
||||
const Transaction* m_FromT; //FIXME: Should be bound to the llvm symbol.
|
||||
};
|
||||
|
||||
typedef llvm::SmallVector<CXAAtExitElement, 128> AtExitFunctions;
|
||||
@ -183,19 +171,15 @@ namespace cling {
|
||||
return m_engine.get();
|
||||
}
|
||||
|
||||
///\brief Keep track of the entities whose dtor we need to call.
|
||||
///
|
||||
void AddAtExitFunc(void (*func) (void*), void* arg,
|
||||
const cling::Transaction* clingT);
|
||||
|
||||
private:
|
||||
static void* HandleMissingFunction(const std::string&);
|
||||
static void* NotifyLazyFunctionCreators(const std::string&);
|
||||
|
||||
///\brief We keep track of the entities whose dtor we need to call.
|
||||
///
|
||||
int CXAAtExit(void (*func) (void*), void* arg, void* dso, void* clingT);
|
||||
|
||||
// This is the caller of CXAAtExit. We want to keep it private so we need
|
||||
// to make the caller a friend.
|
||||
friend int runtime::internal::local_cxa_atexit(void (*func) (void*),
|
||||
void* arg, void* dso,
|
||||
void* interp);
|
||||
};
|
||||
} // end cling
|
||||
#endif // CLING_INCREMENTAL_EXECUTOR_H
|
||||
|
@ -69,46 +69,12 @@ namespace cling {
|
||||
namespace runtime {
|
||||
namespace internal {
|
||||
// "Declared" to the JIT in RuntimeUniverse.h
|
||||
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso,
|
||||
void* interp) {
|
||||
void local_cxa_atexit(void (*func) (void*), void* arg, void* interp) {
|
||||
Interpreter* cling = (cling::Interpreter*)interp;
|
||||
IncrementalParser* incrP = cling->m_IncrParser.get();
|
||||
// FIXME: Bind to the module symbols.
|
||||
cling::Transaction* T = incrP->getLastTransaction();
|
||||
|
||||
return cling->m_Executor->CXAAtExit(func, arg, dso, T);
|
||||
cling->AddAtExitFunc(func, arg);
|
||||
}
|
||||
} // end namespace internal
|
||||
} // end namespace runtime
|
||||
}
|
||||
|
||||
|
||||
#if (!_WIN32)
|
||||
// "Declared" to the JIT in RuntimeUniverse.h
|
||||
namespace cling {
|
||||
namespace runtime {
|
||||
namespace internal {
|
||||
struct trigger__cxa_atexit {
|
||||
~trigger__cxa_atexit();
|
||||
} /*S*/;
|
||||
trigger__cxa_atexit::~trigger__cxa_atexit() {
|
||||
if (std::getenv("bar") == (char*)-1) {
|
||||
llvm::errs() <<
|
||||
"UNEXPECTED cling::runtime::internal::trigger__cxa_atexit\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace cling
|
||||
|
||||
namespace {
|
||||
cling::runtime::internal::trigger__cxa_atexit ForceTheSymbol;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace cling {
|
||||
|
||||
// FIXME: workaround until JIT supports exceptions
|
||||
jmp_buf* Interpreter::m_JumpBuf;
|
||||
@ -1078,4 +1044,8 @@ namespace cling {
|
||||
llvm::Module* module = m_IncrParser->getCodeGenerator()->GetModule();
|
||||
return m_Executor->getAddressOfGlobal(module, SymName, fromJIT);
|
||||
}
|
||||
|
||||
void Interpreter::AddAtExitFunc(void (*Func) (void*), void* Arg) {
|
||||
m_Executor->AddAtExitFunc(Func, Arg, getLastTransaction());
|
||||
}
|
||||
} // namespace cling
|
||||
|
Loading…
Reference in New Issue
Block a user