mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-21 12:38:45 +00:00
llvm.global_[cd]tor is defined to be either external, or appending with an array
of { i32, void ()* }. Teach the verifier to verify that, deleting copies of checks strewn about. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129128 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dd099e1e55
commit
2c44a80d99
@ -660,19 +660,17 @@ bool ELFWriter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
|
|||||||
/// EmitXXStructorList - Emit the ctor or dtor list. This just emits out the
|
/// EmitXXStructorList - Emit the ctor or dtor list. This just emits out the
|
||||||
/// function pointers, ignoring the init priority.
|
/// function pointers, ignoring the init priority.
|
||||||
void ELFWriter::EmitXXStructorList(Constant *List, ELFSection &Xtor) {
|
void ELFWriter::EmitXXStructorList(Constant *List, ELFSection &Xtor) {
|
||||||
// Should be an array of '{ int, void ()* }' structs. The first value is the
|
// Should be an array of '{ i32, void ()* }' structs. The first value is the
|
||||||
// init priority, which we ignore.
|
// init priority, which we ignore.
|
||||||
if (!isa<ConstantArray>(List)) return;
|
|
||||||
ConstantArray *InitList = cast<ConstantArray>(List);
|
ConstantArray *InitList = cast<ConstantArray>(List);
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
|
ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(i));
|
||||||
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
|
||||||
|
|
||||||
if (CS->getOperand(1)->isNullValue())
|
if (CS->getOperand(1)->isNullValue())
|
||||||
return; // Found a null terminator, exit printing.
|
return; // Found a null terminator, exit printing.
|
||||||
// Emit the function pointer.
|
// Emit the function pointer.
|
||||||
EmitGlobalConstant(CS->getOperand(1), Xtor);
|
EmitGlobalConstant(CS->getOperand(1), Xtor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ELFWriter::runOnMachineFunction(MachineFunction &MF) {
|
bool ELFWriter::runOnMachineFunction(MachineFunction &MF) {
|
||||||
|
@ -313,13 +313,9 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module *module,
|
|||||||
|
|
||||||
// Should be an array of '{ i32, void ()* }' structs. The first value is
|
// Should be an array of '{ i32, void ()* }' structs. The first value is
|
||||||
// the init priority, which we ignore.
|
// the init priority, which we ignore.
|
||||||
ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
ConstantArray *InitList = cast<ConstantArray>(GV->getInitializer());
|
||||||
if (!InitList) return;
|
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
ConstantStruct *CS =
|
ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(i));
|
||||||
dyn_cast<ConstantStruct>(InitList->getOperand(i));
|
|
||||||
if (!CS) continue;
|
|
||||||
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
|
||||||
|
|
||||||
Constant *FP = CS->getOperand(1);
|
Constant *FP = CS->getOperand(1);
|
||||||
if (FP->isNullValue())
|
if (FP->isNullValue())
|
||||||
|
@ -1944,35 +1944,20 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindGlobalCtors - Find the llvm.globalctors list, verifying that all
|
/// FindGlobalCtors - Find the llvm.global_ctors list, verifying that all
|
||||||
/// initializers have an init priority of 65535.
|
/// initializers have an init priority of 65535.
|
||||||
GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) {
|
GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) {
|
||||||
GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors");
|
GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors");
|
||||||
if (GV == 0) return 0;
|
if (GV == 0) return 0;
|
||||||
|
|
||||||
// Found it, verify it's an array of { int, void()* }.
|
|
||||||
const ArrayType *ATy =dyn_cast<ArrayType>(GV->getType()->getElementType());
|
|
||||||
if (!ATy) return 0;
|
|
||||||
const StructType *STy = dyn_cast<StructType>(ATy->getElementType());
|
|
||||||
if (!STy || STy->getNumElements() != 2 ||
|
|
||||||
!STy->getElementType(0)->isIntegerTy(32)) return 0;
|
|
||||||
const PointerType *PFTy = dyn_cast<PointerType>(STy->getElementType(1));
|
|
||||||
if (!PFTy) return 0;
|
|
||||||
const FunctionType *FTy = dyn_cast<FunctionType>(PFTy->getElementType());
|
|
||||||
if (!FTy || !FTy->getReturnType()->isVoidTy() ||
|
|
||||||
FTy->isVarArg() || FTy->getNumParams() != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Verify that the initializer is simple enough for us to handle. We are
|
// Verify that the initializer is simple enough for us to handle. We are
|
||||||
// only allowed to optimize the initializer if it is unique.
|
// only allowed to optimize the initializer if it is unique.
|
||||||
if (!GV->hasUniqueInitializer()) return 0;
|
if (!GV->hasUniqueInitializer()) return 0;
|
||||||
|
|
||||||
ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
|
ConstantArray *CA = cast<ConstantArray>(GV->getInitializer());
|
||||||
if (!CA) return 0;
|
|
||||||
|
|
||||||
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) {
|
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) {
|
||||||
ConstantStruct *CS = dyn_cast<ConstantStruct>(*i);
|
ConstantStruct *CS = cast<ConstantStruct>(*i);
|
||||||
if (CS == 0) return 0;
|
|
||||||
|
|
||||||
if (isa<ConstantPointerNull>(CS->getOperand(1)))
|
if (isa<ConstantPointerNull>(CS->getOperand(1)))
|
||||||
continue;
|
continue;
|
||||||
@ -1982,8 +1967,8 @@ GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Init priority must be standard.
|
// Init priority must be standard.
|
||||||
ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0));
|
ConstantInt *CI = cast<ConstantInt>(CS->getOperand(0));
|
||||||
if (!CI || CI->getZExtValue() != 65535)
|
if (CI->getZExtValue() != 65535)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,6 +471,23 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
|
|||||||
"invalid linkage type for global declaration", &GV);
|
"invalid linkage type for global declaration", &GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
|
||||||
|
GV.getName() == "llvm.global_dtors")) {
|
||||||
|
Assert1(!GV.hasInitializer() || GV.hasAppendingLinkage(),
|
||||||
|
"invalid linkage for intrinsic global variable", &GV);
|
||||||
|
// Don't worry about emitting an error for it not being an array,
|
||||||
|
// visitGlobalValue will complain on appending non-array.
|
||||||
|
if (const ArrayType *ATy = dyn_cast<ArrayType>(GV.getType())) {
|
||||||
|
const StructType *STy = dyn_cast<StructType>(ATy->getElementType());
|
||||||
|
const PointerType *FuncPtrTy =
|
||||||
|
FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo();
|
||||||
|
Assert1(STy && STy->getNumElements() == 2 &&
|
||||||
|
STy->getTypeAtIndex(0u)->isIntegerTy(32) &&
|
||||||
|
STy->getTypeAtIndex(1) == FuncPtrTy,
|
||||||
|
"wrong type for intrinsic global variable", &GV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
visitGlobalValue(GV);
|
visitGlobalValue(GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user