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:
Axel Naumann 2014-03-04 18:07:03 +01:00 committed by sftnight
parent 1e86611693
commit baca204185
6 changed files with 28 additions and 76 deletions

View File

@ -49,9 +49,6 @@ namespace clang {
namespace cling { namespace cling {
namespace runtime { namespace runtime {
namespace internal { namespace internal {
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso,
void* interp);
class DynamicExprInfo; class DynamicExprInfo;
template <typename T> template <typename T>
T EvaluateT(DynamicExprInfo* ExprInfo, clang::DeclContext* DC); T EvaluateT(DynamicExprInfo* ExprInfo, clang::DeclContext* DC);
@ -586,11 +583,14 @@ namespace cling {
/// ///
void* getAddressOfGlobal(llvm::StringRef SymName, bool* fromJIT = 0) const; void* getAddressOfGlobal(llvm::StringRef SymName, bool* fromJIT = 0) const;
friend class runtime::internal::LifetimeHandler; ///\brief Add an atexit function.
friend int runtime::internal::local_cxa_atexit(void (*func) (void*), ///
void* arg, void* dso, ///\param[in] Func - Function to be called.
void* interp); ///\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 // FIXME: workaround until JIT supports exceptions
static jmp_buf*& getNullDerefJump() { return m_JumpBuf; } static jmp_buf*& getNullDerefJump() { return m_JumpBuf; }
}; };

View File

@ -49,8 +49,7 @@ namespace cling {
/// ///
/// Implemented in Interpreter.cpp /// Implemented in Interpreter.cpp
/// ///
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso, int local_cxa_atexit(void (*func) (void*), void* arg, void* interp);
void* interp);
/// \brief Some of clang's routines rely on valid source locations and /// \brief Some of clang's routines rely on valid source locations and
/// source ranges. This member can be looked up and source locations and /// source ranges. This member can be looked up and source locations and
@ -183,7 +182,7 @@ extern "C" {
extern "C" { extern "C" {
int cling_cxa_atexit(void (*func) (void*), void* arg, void* dso) { 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); (void*)cling::runtime::gCling);
} }

View File

@ -116,12 +116,11 @@ void IncrementalExecutor::remapCXAAtExit() {
m_CxaAtExitRemapped = true; m_CxaAtExitRemapped = true;
} }
int IncrementalExecutor::CXAAtExit(void (*func) (void*), void* arg, void* dso, void IncrementalExecutor::AddAtExitFunc(void (*func) (void*), void* arg,
void* clingT) { const cling::Transaction* clingT) {
// Register a CXAAtExit function // Register a CXAAtExit function
cling::Transaction* T = (cling::Transaction*)clingT; cling::Transaction* T = (cling::Transaction*)clingT;
m_AtExitFuncs.push_back(CXAAtExitElement(func, arg, dso, T)); m_AtExitFuncs.push_back(CXAAtExitElement(func, arg, T));
return 0; // happiness
} }
void unresolvedSymbol() void unresolvedSymbol()

View File

@ -25,13 +25,6 @@ namespace llvm {
namespace cling { namespace cling {
class Transaction; 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 StoredValueRef;
class IncrementalExecutor { class IncrementalExecutor {
@ -77,13 +70,12 @@ namespace cling {
///\param [in] func - The function to be called on exit or unloading of ///\param [in] func - The function to be called on exit or unloading of
/// shared lib.(The destructor of the object.) /// shared lib.(The destructor of the object.)
///\param [in] arg - The argument the func to be called with. ///\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 ///\param [in] fromT - The unloading of this transaction will trigger the
/// atexit function. /// atexit function.
/// ///
CXAAtExitElement(void (*func) (void*), void* arg, void* dso, CXAAtExitElement(void (*func) (void*), void* arg,
Transaction* fromT): const Transaction* fromT):
m_Func(func), m_Arg(arg), m_DSO(dso), m_FromT(fromT) {} m_Func(func), m_Arg(arg), m_FromT(fromT) {}
///\brief The function to be called. ///\brief The function to be called.
/// ///
@ -93,14 +85,10 @@ namespace cling {
/// ///
void* m_Arg; void* m_Arg;
/// \brief The DSO handle.
///
void* m_DSO;
///\brief Clang's top level declaration, whose unloading will trigger the ///\brief Clang's top level declaration, whose unloading will trigger the
/// call this atexit function. /// 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; typedef llvm::SmallVector<CXAAtExitElement, 128> AtExitFunctions;
@ -183,19 +171,15 @@ namespace cling {
return m_engine.get(); 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: private:
static void* HandleMissingFunction(const std::string&); static void* HandleMissingFunction(const std::string&);
static void* NotifyLazyFunctionCreators(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 } // end cling
#endif // CLING_INCREMENTAL_EXECUTOR_H #endif // CLING_INCREMENTAL_EXECUTOR_H

View File

@ -103,7 +103,7 @@ namespace cling {
const char* llvmdir); const char* llvmdir);
~IncrementalParser(); ~IncrementalParser();
void Initialize(); void Initialize();
clang::CompilerInstance* getCI() const { return m_CI.get(); } clang::CompilerInstance* getCI() const { return m_CI.get(); }
clang::Parser* getParser() const { return m_Parser.get(); } clang::Parser* getParser() const { return m_Parser.get(); }
clang::CodeGenerator* getCodeGenerator() const { return m_CodeGen.get(); } clang::CodeGenerator* getCodeGenerator() const { return m_CodeGen.get(); }

View File

@ -69,46 +69,12 @@ namespace cling {
namespace runtime { namespace runtime {
namespace internal { namespace internal {
// "Declared" to the JIT in RuntimeUniverse.h // "Declared" to the JIT in RuntimeUniverse.h
int local_cxa_atexit(void (*func) (void*), void* arg, void* dso, void local_cxa_atexit(void (*func) (void*), void* arg, void* interp) {
void* interp) {
Interpreter* cling = (cling::Interpreter*)interp; Interpreter* cling = (cling::Interpreter*)interp;
IncrementalParser* incrP = cling->m_IncrParser.get(); cling->AddAtExitFunc(func, arg);
// FIXME: Bind to the module symbols.
cling::Transaction* T = incrP->getLastTransaction();
return cling->m_Executor->CXAAtExit(func, arg, dso, T);
} }
} // end namespace internal } // end namespace internal
} // end namespace runtime } // 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 // FIXME: workaround until JIT supports exceptions
jmp_buf* Interpreter::m_JumpBuf; jmp_buf* Interpreter::m_JumpBuf;
@ -1078,4 +1044,8 @@ namespace cling {
llvm::Module* module = m_IncrParser->getCodeGenerator()->GetModule(); llvm::Module* module = m_IncrParser->getCodeGenerator()->GetModule();
return m_Executor->getAddressOfGlobal(module, SymName, fromJIT); return m_Executor->getAddressOfGlobal(module, SymName, fromJIT);
} }
void Interpreter::AddAtExitFunc(void (*Func) (void*), void* Arg) {
m_Executor->AddAtExitFunc(Func, Arg, getLastTransaction());
}
} // namespace cling } // namespace cling