mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-12 17:25:49 +00:00
Add runStaticConstructorsDestructors which runs ctors / dtors of a single module. Patch by David Chisnall.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56849 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -157,9 +157,13 @@ public:
|
|||||||
const std::vector<GenericValue> &ArgValues) = 0;
|
const std::vector<GenericValue> &ArgValues) = 0;
|
||||||
|
|
||||||
/// runStaticConstructorsDestructors - This method is used to execute all of
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
||||||
/// the static constructors or destructors for a module, depending on the
|
/// the static constructors or destructors for a program, depending on the
|
||||||
/// value of isDtors.
|
/// value of isDtors.
|
||||||
void runStaticConstructorsDestructors(bool isDtors);
|
void runStaticConstructorsDestructors(bool isDtors);
|
||||||
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
||||||
|
/// the static constructors or destructors for a module, depending on the
|
||||||
|
/// value of isDtors.
|
||||||
|
void runStaticConstructorsDestructors(Module *module, bool isDtors);
|
||||||
|
|
||||||
|
|
||||||
/// runFunctionAsMain - This is a helper function which wraps runFunction to
|
/// runFunctionAsMain - This is a helper function which wraps runFunction to
|
||||||
|
@@ -230,43 +230,51 @@ static void *CreateArgv(ExecutionEngine *EE,
|
|||||||
|
|
||||||
|
|
||||||
/// runStaticConstructorsDestructors - This method is used to execute all of
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
||||||
/// the static constructors or destructors for a program, depending on the
|
/// the static constructors or destructors for a module, depending on the
|
||||||
/// value of isDtors.
|
/// value of isDtors.
|
||||||
void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
|
void ExecutionEngine::runStaticConstructorsDestructors(Module *module, bool isDtors) {
|
||||||
const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
|
const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
|
||||||
|
|
||||||
// Execute global ctors/dtors for each module in the program.
|
// Execute global ctors/dtors for each module in the program.
|
||||||
for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
|
|
||||||
GlobalVariable *GV = Modules[m]->getModule()->getNamedGlobal(Name);
|
|
||||||
|
|
||||||
// If this global has internal linkage, or if it has a use, then it must be
|
|
||||||
// an old-style (llvmgcc3) static ctor with __main linked in and in use. If
|
|
||||||
// this is the case, don't execute any of the global ctors, __main will do
|
|
||||||
// it.
|
|
||||||
if (!GV || GV->isDeclaration() || GV->hasInternalLinkage()) continue;
|
|
||||||
|
|
||||||
// Should be an array of '{ int, void ()* }' structs. The first value is
|
GlobalVariable *GV = module->getNamedGlobal(Name);
|
||||||
// the init priority, which we ignore.
|
|
||||||
ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
// If this global has internal linkage, or if it has a use, then it must be
|
||||||
if (!InitList) continue;
|
// an old-style (llvmgcc3) static ctor with __main linked in and in use. If
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
// this is the case, don't execute any of the global ctors, __main will do
|
||||||
if (ConstantStruct *CS =
|
// it.
|
||||||
dyn_cast<ConstantStruct>(InitList->getOperand(i))) {
|
if (!GV || GV->isDeclaration() || GV->hasInternalLinkage()) return;
|
||||||
if (CS->getNumOperands() != 2) break; // Not array of 2-element structs.
|
|
||||||
|
// Should be an array of '{ int, void ()* }' structs. The first value is
|
||||||
Constant *FP = CS->getOperand(1);
|
// the init priority, which we ignore.
|
||||||
if (FP->isNullValue())
|
ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
||||||
break; // Found a null terminator, exit.
|
if (!InitList) return;
|
||||||
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
|
if (ConstantStruct *CS =
|
||||||
if (CE->isCast())
|
dyn_cast<ConstantStruct>(InitList->getOperand(i))) {
|
||||||
FP = CE->getOperand(0);
|
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
||||||
if (Function *F = dyn_cast<Function>(FP)) {
|
|
||||||
// Execute the ctor/dtor function!
|
Constant *FP = CS->getOperand(1);
|
||||||
runFunction(F, std::vector<GenericValue>());
|
if (FP->isNullValue())
|
||||||
}
|
break; // Found a null terminator, exit.
|
||||||
}
|
|
||||||
}
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
|
||||||
|
if (CE->isCast())
|
||||||
|
FP = CE->getOperand(0);
|
||||||
|
if (Function *F = dyn_cast<Function>(FP)) {
|
||||||
|
// Execute the ctor/dtor function!
|
||||||
|
runFunction(F, std::vector<GenericValue>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// runStaticConstructorsDestructors - This method is used to execute all of
|
||||||
|
/// the static constructors or destructors for a program, depending on the
|
||||||
|
/// value of isDtors.
|
||||||
|
void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
|
||||||
|
// Execute global ctors/dtors for each module in the program.
|
||||||
|
for (unsigned m = 0, e = Modules.size(); m != e; ++m)
|
||||||
|
runStaticConstructorsDestructors(Modules[m]->getModule(), isDtors);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
Reference in New Issue
Block a user