/* 0=disabled, 1=force no debug output, 2=force no output (for perf. testing).*/
#define MAGIC_CHECK_LEVEL 1
/* 2=extra checks, 1=standard checks, 0=no checks (for perf. testing). */
-#define MAGIC_FLATTEN_FUNCTION_ARGS 1
+#define MAGIC_FLATTEN_FUNCTION_ARGS 0 /* XXX was 1 but header was not included, seems to break on variadic functions */
#define MAGIC_CHECK_INVARIANTS 1
#define MAGIC_SHRINK_TYPE_STR 1
#define MAGIC_MAX_NAME_LEN 64
#
LLVMPREFIX?=../../../../../obj_llvm.i386/Release+Asserts
-CFLAGS += -D__MINIX -D_MINIX_SYSTEM
+CFLAGS += -D__MINIX -D_MINIX_SYSTEM -DDEBUG_TYPE=\""$PASSNAME"\"
INCLUDES += -I../../include
QUIET=@
#include <magic/support/MagicUtil.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
-#define MAGIC_IS_MAGIC_FUNC(M, F) (!(F)->getSection().compare(MAGIC_STATIC_FUNCTIONS_SECTION))
+#define MAGIC_IS_MAGIC_FUNC(M, F) (!StringRef((F)->getSection()).compare(MAGIC_STATIC_FUNCTIONS_SECTION))
using namespace llvm;
* (last found allocation instruction will be at the front), and remove it from the basic block.
* */
int hasAddressTaken = 0;
- for (Value::use_iterator UI = allocaInst->use_begin(), E = allocaInst->use_end(); UI != E; ++UI) {
+ for (Value::user_iterator UI = allocaInst->user_begin(), E = allocaInst->user_end(); UI != E; ++UI) {
/* Loop through all the Uses of this allocation function. */
assert(ret);
if(stackframe_caller_padding && max_offset > 0) {
- std::vector<User*> Users(F->use_begin(), F->use_end());
+ std::vector<User*> Users(F->user_begin(), F->user_end());
while (!Users.empty()) {
User *U = Users.back();
Users.pop_back();
#define DATA_LAYOUT_TY DataLayout
#define ATTRIBUTE_SET_RET_IDX ATTRIBUTE_SET_TY::ReturnIndex
#define ATTRIBUTE_SET_FN_IDX ATTRIBUTE_SET_TY::FunctionIndex
-#include <llvm/DebugInfo.h>
+#include <llvm/IR/DebugInfo.h>
#if LLVM_VERSION == 32
#include <llvm/DataLayout.h>
#include <llvm/IRBuilder.h>
public:
static void writeTypeSymbolic(raw_string_ostream &OS, TYPECONST Type *type, const Module *M);
static const std::string getTypeDescription(TYPECONST Type* type);
- static Value *findDbgGlobalDeclare(GlobalVariable *V);
- static Value *findDbgSubprogramDeclare(const Function *F);
+ static MDNode *findDbgGlobalDeclare(GlobalVariable *V);
+ static MDNode *findDbgSubprogramDeclare(const Function *F);
static void getDbgLocationInfoRelPath(const std::string &baseDir, const std::string &filename, const std::string &directory, std::string &relPath);
static void getDbgLocationInfo(DIDescriptor &DID, const std::string &baseDir, std::string *filename, std::string *directory, std::string *relPath);
static bool getInstrDbgLocationInfo(Instruction *I, const std::string &baseDir, std::string *filename, std::string *directory, std::string *relPath, unsigned int *lineNum, bool expand=true);
static unsigned getDbgSubrangeNumElements(const DISubrange &subrange);
static bool isDbgVectorTy(const DIType &type);
static DIType getDITypeDerivedFrom(const DIDerivedType &type);
+ static DIType getDITypeFromRef(const DITypeRef &ref);
static bool isOpaqueTy(TYPECONST Type *type);
+ static bool isPrimitiveTy(TYPECONST Type *type);
static Constant* getGetElementPtrConstant(Constant *constant, std::vector<Value*> &indexes);
static GetElementPtrInst* createGetElementPtrInstruction(Value *ptr, std::vector<Value*> &indexes, const Twine &NameStr="", Instruction *InsertBefore=0);
static GetElementPtrInst* createGetElementPtrInstruction(Value *ptr, std::vector<Value*> &indexes, const Twine &NameStr="", BasicBlock *InsertAtEnd=0);
return string;
}
-inline Value *PassUtil::findDbgGlobalDeclare(GlobalVariable *V) {
+inline MDNode *PassUtil::findDbgGlobalDeclare(GlobalVariable *V) {
#if LLVM_VERSION >= 30
const Module *M = V->getParent();
NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.cu");
#endif
}
-inline Value *PassUtil::findDbgSubprogramDeclare(const Function *V) {
+inline MDNode *PassUtil::findDbgSubprogramDeclare(const Function *V) {
#if LLVM_VERSION >= 30
const Module *M = V->getParent();
NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.cu");
#endif
}
+inline DIType PassUtil::getDITypeFromRef(const DITypeRef &ref) {
+ static DITypeIdentifierMap TypeIdentifierMap;
+ static bool TypeMapInitialized = false;
+ if (!TypeMapInitialized) {
+ /* TODO: generate the type identifier map only once! */
+ assert(PassUtil::M && "Set module first!");
+ if (NamedMDNode *CU_Nodes = PassUtil::M->getNamedMetadata("llvm.dbg.cu")) {
+ TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
+ TypeMapInitialized = true;
+ }
+ }
+ return ref.resolve(TypeIdentifierMap);
+}
+
inline bool PassUtil::isOpaqueTy(TYPECONST Type *type) {
#if LLVM_VERSION >= 30
return type->isStructTy() && (((TYPECONST StructType*)type)->isOpaque() || type->getNumContainedTypes() == 0);
#endif
}
+inline bool PassUtil::isPrimitiveTy(TYPECONST Type *type) {
+ return type->isVoidTy() || type->isFloatingPointTy() || type->isLabelTy() || type->isMetadataTy() || type->isX86_MMXTy();
+}
+
inline Constant* PassUtil::getGetElementPtrConstant(Constant *constant, std::vector<Value*> &indexes) {
#if LLVM_VERSION >= 30
ArrayRef<Value*> ref(indexes);
#include <pass.h>
#include <magic/magic.h>
-#include <magic/support/Backports.h>
#include <magic/support/MagicUtil.h>
#include <magic/support/SmartType.h>
#include <magic/support/TypeInfo.h>
+++ /dev/null
-#ifndef BACKPORTS_H
-#define BACKPORTS_H
-
-#include <pass.h>
-
-using namespace llvm;
-
-namespace llvm {
-
-class Backports {
- public:
-
- //From DbgInfoPrinter.cpp (LLVM 2.9)
- static Value *findDbgGlobalDeclare(GlobalVariable *V);
- static Value *findDbgSubprogramDeclare(Function *V);
- static const DbgDeclareInst *findDbgDeclare(const Value *V);
-
- //From Local.cpp (LLVM 2.9)
- static DbgDeclareInst *FindAllocaDbgDeclare(Value *V);
-};
-
-}
-
-#endif
const DIDerivedType& getMember(unsigned i) const;
bool isUnionOrStructTy(bool isStruct=true, bool isUnion=true) const;
bool hasInnerPointers() const;
+ unsigned int getTypeArrayNum() const;
DIArray getTypeArray() const;
const EDIType* getTopStructType(unsigned index) const;
}
inline bool EDIType::isOpaqueTy() const {
- return (isCompositeType() && getTypeArray().getNumElements() == 0);
+ return (isCompositeType() && getTypeArrayNum() == 0);
}
inline void EDIType::writeTypeSymbolic(raw_string_ostream &OS, TYPECONST Type *type, const Module *M) {
bool ret = MagicDebugFunction::inlineHookCalls(debugFunction, hooks, flags, argsMapping, trailingArgs);
assert(ret && "Unable to inline the calls to the hook functions.");
- std::vector<User*> Users(function->use_begin(), function->use_end());
+ std::vector<User*> Users(function->user_begin(), function->user_end());
std::vector<Value*> EqPointers;
while (!Users.empty()) {
User *U = Users.back();
MagicUtil::replaceCallInst(I, newInst, 1);
}
} else if (GlobalValue * GV = dyn_cast<GlobalValue>(U)) {
- Users.insert(Users.end(), GV->use_begin(), GV->use_end());
+ Users.insert(Users.end(), GV->user_begin(), GV->user_end());
EqPointers.push_back(GV);
} else if (ConstantExpr * CE = dyn_cast<ConstantExpr>(U)) {
if (CE->isCast()) {
- Users.insert(Users.end(), CE->use_begin(), CE->use_end());
+ Users.insert(Users.end(), CE->user_begin(), CE->user_end());
EqPointers.push_back(CE);
}
}
/* This assumes in-band metadata of 1 page before every mmapped region. */
inline void MagicMmapCtlFunction::fixCalls(Module &M, Function *magicGetPageSizeFunc) const {
- std::vector<User*> Users(function->use_begin(), function->use_end());
+ std::vector<User*> Users(function->user_begin(), function->user_end());
while (!Users.empty()) {
User *U = Users.back();
Users.pop_back();
#define SMART_TYPE_H
#include <pass.h>
-#include <magic/support/Backports.h>
#include <magic/support/EDIType.h>
#include <magic/support/TypeUtil.h>
#include <magic/support/BitFieldAggregation.h>
assert(type->isStructTy());
return true;
}
- return isTy(type->isPrimitiveType(), aEDIType.isPrimitiveType(), "isPrimitiveTy");
+ return isTy(PassUtil::isPrimitiveTy(type), aEDIType.isPrimitiveType(), "isPrimitiveTy");
}
inline bool SmartType::isAggregateType() const {
#include <llvm/ADT/Statistic.h>
#include <llvm/Support/Regex.h>
-#include <llvm/Assembly/Writer.h>
-#include <llvm/Support/CallSite.h>
+#include <llvm/IR/CallSite.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Analysis/LoopInfo.h>
-#include <llvm/Support/InstIterator.h>
+#include <llvm/IR/InstIterator.h>
#include <llvm/Transforms/Utils/Local.h>
#include <llvm/Transforms/Scalar.h>
#define SECTIONIFY_PASS_H
-#define DEBUG_TYPE "sectionify"
#include <pass.h>
using namespace llvm;
std::vector<Regex*> dataRegexList;
std::string moduleName;
- bool sectionifyFromRegex(GlobalValue *value, Regex *regex, std::string §ion);
- bool sectionify(GlobalValue *value, std::vector<Regex*> ®exList, std::map<Regex*, std::string> ®exMap);
+ bool sectionifyFromRegex(GlobalObject *value, Regex *regex, std::string §ion);
+ bool sectionify(GlobalObject *value, std::vector<Regex*> ®exList, std::map<Regex*, std::string> ®exMap);
void parseAndInitRegexMap(cl::list<std::string> &stringListOpt, std::vector<Regex*> ®exList, std::map<Regex*, std::string> ®exMap, std::string regexType);
bool initRegexMap(std::map<Regex*, std::string> ®exMap, std::vector<Regex*> ®exList, std::map<std::string, std::string> &stringMap, std::vector<std::string> &stringList, std::string regexType);
bool parseStringMapOpt(std::map<std::string, std::string> &map, std::vector<std::string> &keyList, std::vector<std::string> &stringList);
while(!magicMemFunctions.empty()) {
MagicMemFunction magicMemFunction = magicMemFunctions.front();
magicMemFunctions.erase(magicMemFunctions.begin());
- std::vector<User*> Users(magicMemFunction.getFunction()->use_begin(), magicMemFunction.getFunction()->use_end());
+ std::vector<User*> Users(magicMemFunction.getFunction()->user_begin(), magicMemFunction.getFunction()->user_end());
std::vector<Value*> EqPointers;
while (!Users.empty()) {
int annotation;
}
}
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(U)) {
- Users.insert(Users.end(), GV->use_begin(), GV->use_end());
+ Users.insert(Users.end(), GV->user_begin(), GV->user_end());
EqPointers.push_back(GV);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->isCast()) {
- Users.insert(Users.end(), CE->use_begin(), CE->use_end());
+ Users.insert(Users.end(), CE->user_begin(), CE->user_end());
EqPointers.push_back(CE);
}
}
DEBUG_VALUE(" ************************************************************ findPointerVariables: Unknown value: ", value);
RETURN_IF(true);
}
- for (Value::use_iterator i = value->use_begin(), e = value->use_end(); i != e; ++i) {
+ for (Value::user_iterator i = value->user_begin(), e = value->user_end(); i != e; ++i) {
User *user = *i;
Instruction *instruction = dyn_cast<Instruction>(user);
if(!instruction || instruction->getParent()->getParent() != function) {
}
}
stackIntrumentedFuncs.push_back(deepestLLFunction);
- for (Value::use_iterator i = deepestLLFunction->use_begin(), e = deepestLLFunction->use_end(); i != e; ++i) {
+ for (Value::user_iterator i = deepestLLFunction->user_begin(), e = deepestLLFunction->user_end(); i != e; ++i) {
User *user = *i;
if(Instruction *I = dyn_cast<Instruction>(user)) {
fillStackInstrumentedFunctions(stackIntrumentedFuncs, I->getParent()->getParent());
if (GV->isThreadLocal() && (GV->getName().startswith(MAGIC_PREFIX_STR) || GV->getName().startswith("rcu"))) {
return true;
}
- if (!GV->getSection().compare(MAGIC_LLVM_METADATA_SECTION)) {
+ if (!StringRef(GV->getSection()).compare(MAGIC_LLVM_METADATA_SECTION)) {
return true;
}
if (GV->getName().startswith("__start") || GV->getName().startswith("__stop") || GV->getName().startswith("llvm.")) {
PASSNAME = magic
-OBJS = support/Backports.o support/EDIType.o support/TypeUtil.o support/BitFieldAggregation.o support/SmartType.o support/VariableRefs.o support/MagicUtil.o MagicPass.o
+OBJS = support/EDIType.o support/TypeUtil.o support/BitFieldAggregation.o support/SmartType.o support/VariableRefs.o support/MagicUtil.o MagicPass.o
HEADERS = $(wildcard ../include/magic/support/*.h)
include ../Makefile.inc
+++ /dev/null
-#include <pass.h>
-
-#include <magic/support/Backports.h>
-#include <magic/support/EDIType.h>
-#include <magic/support/SmartType.h>
-
-using namespace llvm;
-
-namespace llvm {
-
-//===----------------------------------------------------------------------===//
-// Public static methods
-//===----------------------------------------------------------------------===//
-
-/// Find the debug info descriptor corresponding to this global variable.
-Value *Backports::findDbgGlobalDeclare(GlobalVariable *V) {
- return PassUtil::findDbgGlobalDeclare(V);
-}
-
-/// Find the debug info descriptor corresponding to this function.
-Value *Backports::findDbgSubprogramDeclare(Function *V) {
- return PassUtil::findDbgSubprogramDeclare(V);
-}
-
-/// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
-/// It looks through pointer casts too.
-const DbgDeclareInst *Backports::findDbgDeclare(const Value *V) {
- V = V->stripPointerCasts();
-
- if (!isa<Instruction>(V) && !isa<Argument>(V))
- return 0;
-
- const Function *F = NULL;
- if (const Instruction *I = dyn_cast<Instruction>(V))
- F = I->getParent()->getParent();
- else if (const Argument *A = dyn_cast<Argument>(V))
- F = A->getParent();
-
- for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
- for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end();
- BI != BE; ++BI)
- if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
- if (DDI->getAddress() == V)
- return DDI;
-
- return 0;
-}
-
-/// FindAllocaDbgDeclare - Finds the llvm.dbg.declare intrinsic describing the
-/// alloca 'V', if any.
-DbgDeclareInst *Backports::FindAllocaDbgDeclare(Value *V) {
-#if LLVM_VERSION >= 33
- if (MDNode *DebugNode = MDNode::getIfExists(V->getContext(), V))
- for (Value::use_iterator UI = DebugNode->use_begin(),
- E = DebugNode->use_end(); UI != E; ++UI)
- if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(*UI))
- return DDI;
-
- return 0;
-#else
-
-///
-/// There is an unfixed bug (http://llvm.org/bugs/show_bug.cgi?id=10887)
-/// that drops debug information references for local variables at linking time.
-/// This is way the method FindAllocaDbgDeclare() will always return NULL and
-/// we need to resort to some ugly workaround.
-///
- AllocaInst *AI = dyn_cast<AllocaInst>(V);
- if(!AI) {
- return NULL;
- }
- BasicBlock *varParent = AI->getParent();
- Function *varFunc = varParent->getParent();
- if(!AI->hasName() || !AI->getName().compare("retval")) {
- return NULL;
- }
- StringRef varName = AI->getName();
- bool isInlinedVar = false;
- bool isScopedVar = false;
- DIType aDIType, aAddrDIType, tmpDIType;
- DbgDeclareInst *DDI = NULL, *addrDDI = NULL;
- SmallVector< StringRef, 8 > vector;
- varName.split(vector, ".");
- if(vector.size() >= 2 && vector[1][0] == 'i') {
- isInlinedVar = true;
- varName = vector[0];
- }
- if(!isInlinedVar) {
- //for non-inlined variables we have to look in the first bb first.
- for(BasicBlock::iterator i=varParent->begin(), e=varParent->end();i!=e;i++) {
- if(DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(i)) {
- MDNode *node = DI->getVariable();
- assert(node);
- DIVariable DIV(node);
- if(!DIV.getName().compare(varName)) {
- aDIType = DIV.getType();
- DDI = DI;
- break;
- }
- StringRef addrVarName(DIV.getName().str() + "_addr");
- if(!addrVarName.compare(varName)) {
- aAddrDIType = DIV.getType();
- addrDDI = DI;
- break;
- }
- }
- }
- if(!DDI && !addrDDI) {
- //not found? probably a scoped variable, look anywhere else.
- isScopedVar = true;
- }
- }
- if(isInlinedVar || isScopedVar) {
- //for inlined/scoped variables we have to look everywhere in the function and name clashing could also occur.
- bool isDuplicate = false;
- for (inst_iterator it = inst_begin(varFunc), et = inst_end(varFunc); it != et; ++it) {
- Instruction *inst = &(*it);
- if(DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(inst)) {
- MDNode *node = DI->getVariable();
- assert(node);
- DIVariable DIV(node);
- StringRef addrVarName(DIV.getName().str() + "_addr");
- if(!DIV.getName().compare(varName) || !addrVarName.compare(varName)) {
- tmpDIType = DIV.getType();
- EDIType tmpEDIType(tmpDIType);
- if(!SmartType::isTypeConsistent(AI->getAllocatedType(), &tmpEDIType)) {
- continue;
- }
- bool skipDIType = false;
- if(DDI) {
- EDIType aEDIType(aDIType);
- skipDIType = true;
- if(!aEDIType.equals(&tmpEDIType)) {
- isDuplicate = true;
- }
- }
- if(addrDDI) {
- EDIType aAddrEDIType(aAddrDIType);
- skipDIType = true;
- if(!aAddrEDIType.equals(&tmpEDIType)) {
- isDuplicate = true;
- }
- }
- if(!skipDIType && !DIV.getName().compare(varName)) {
- aDIType = tmpDIType;
- DDI = DI;
- continue;
- }
- if(!skipDIType && !addrVarName.compare(varName)) {
- aAddrDIType = tmpDIType;
- addrDDI = DI;
- continue;
- }
- }
- }
- }
- if(isDuplicate) {
- //name clashing problem with inline/scoped variables, pretend nothing was found
- DDI = NULL;
- addrDDI = NULL;
- }
- }
- if(!DDI && !addrDDI) {
- return (DbgDeclareInst*)-1;
- }
- assert((DDI && !addrDDI) || (!DDI && addrDDI));
- DDI = DDI ? DDI : addrDDI;
- return DDI;
-#endif
-}
-
-}
}
return subType;
}
- DIArray aDIArray = getTypeArray();
- unsigned numContainedTypes = aDIArray.getNumElements();
- assert(i < numContainedTypes);
- EDIType tmpType((const DIType) aDIArray.getElement(i), norm);
- subType = tmpType;
+ if (isFunctionTy()) {
+ DITypeArray DTA = ((const DISubroutineType)aDIType).getTypeArray();
+ subType = PassUtil::getDITypeFromRef(DTA.getElement(i));
+ } else {
+ DIArray aDIArray = getTypeArray();
+ unsigned numContainedTypes = aDIArray.getNumElements();
+ assert(i < numContainedTypes);
+ EDIType tmpType((const DIType) aDIArray.getElement(i), norm);
+ subType = tmpType;
+ }
return subType;
}
if(isDerivedType() || isArrayOrVectorTy) {
return 1;
}
- DIArray aDIArray = getTypeArray();
- unsigned numContainedTypes = aDIArray.getNumElements();
- return numContainedTypes;
+ return getTypeArrayNum();
}
const DIDerivedType& EDIType::getMember(unsigned i) const {
return false;
}
+unsigned int EDIType::getTypeArrayNum() const {
+ EDIType_assert(isCompositeType());
+ /* This function is used from isOpaqueTy(), so do not use isFunctionTy() here. */
+ if (getTag() == dwarf::DW_TAG_subroutine_type) {
+ DITypeArray DTA = ((const DISubroutineType)aDIType).getTypeArray();
+ return DTA.getNumElements();
+ } else {
+ return getTypeArray().getNumElements();
+ }
+}
+
DIArray EDIType::getTypeArray() const {
static std::set<std::string> nonOpaqueEmptyTypes;
static std::set<std::string>::iterator nonOpaqueEmptyTypesIt;
EDIType_assert(isCompositeType());
- DIArray aDIArray = ((const DICompositeType)aDIType).getTypeArray();
+ EDIType_assert(getTag() != dwarf::DW_TAG_subroutine_type); /* as above, no isFunctionTy() */
+ DIArray aDIArray = ((const DICompositeType)aDIType).getElements();
if(aDIArray.getNumElements() == 0 && checkOpaqueTypes && myNames.size() > 0) {
const EDIType *aType = NULL;
std::string name;
}
}
if(aType) {
- aDIArray = ((const DICompositeType *)aType->getDIType())->getTypeArray();
+ aDIArray = ((const DICompositeType *)aType->getDIType())->getElements();
nonOpaqueEmptyTypesIt = nonOpaqueEmptyTypes.find(name);
if(nonOpaqueEmptyTypesIt == nonOpaqueEmptyTypes.end()) {
EDITypeLog("Found a non-opaque composite type with 0 members! Name is: " << name);
std::string EDIType::lookupTypedefName(std::string &typedefName) {
static std::string noName;
- for (DebugInfoFinder::iterator I = DIFinder.type_begin(),
- E = DIFinder.type_end(); I != E; ++I) {
- DIType aDIType(*I);
+ for (const DIType aDITypeIt : DIFinder.types()) {
+ DIType aDIType(aDITypeIt);
if(aDIType.getTag() == dwarf::DW_TAG_typedef && aDIType.getName().compare(typedefName)) {
while(aDIType.getTag() == dwarf::DW_TAG_typedef) {
aDIType = PassUtil::getDITypeDerivedFrom((const DIDerivedType)aDIType);
const EDIType* EDIType::getStructEDITypeByName(std::string &typeName) {
static EDIType aEDIType;
assert(module);
- for (DebugInfoFinder::iterator I = DIFinder.type_begin(),
- E = DIFinder.type_end(); I != E; ++I) {
- const DIType aDIType(*I);
+ for (const DIType aDIType : DIFinder.types()) {
//skip zero-element stuct types, necessary to avoid infinite recursion during opaque type lookup
//xxx opaque type lookup should not be necessary but is there a bug in the frontend that leaves certain concrete types unnecessarily opaque?
const EDIType tmpEDIType(aDIType, NORMALIZE, DO_NOT_CHECK_OPAQUE_TYPES);
StringRef MagicUtil::getGVSourceName(Module &M, GlobalVariable *GV, DIGlobalVariable **DIGVP, const std::string &baseDir) {
static DIGlobalVariable Var;
- Value *DIGV = Backports::findDbgGlobalDeclare(GV);
+ MDNode *DIGV = PassUtil::findDbgGlobalDeclare(GV);
if(DIGV) {
- Var = DIGlobalVariable(cast<MDNode>(DIGV));
+ Var = DIGlobalVariable(DIGV);
if(DIGVP) *DIGVP = &Var;
if(GV->getLinkage() == GlobalValue::InternalLinkage){
/* static variable */
Module::GlobalListType &globalList = M.getGlobalList();
for (Module::global_iterator it = globalList.begin(); it != globalList.end(); ++it) {
GlobalVariable *OtherGV = &(*it);
- Value *OtherDIGV = Backports::findDbgGlobalDeclare(OtherGV);
+ MDNode *OtherDIGV = PassUtil::findDbgGlobalDeclare(OtherGV);
if(OtherDIGV) {
- DIGlobalVariable OtherVar(cast<MDNode>(OtherDIGV));
+ DIGlobalVariable OtherVar(OtherDIGV);
DIScope otherScope = OtherVar.getContext();
if(otherScope.isLexicalBlock()){
StringRef MagicUtil::getLVSourceName(Module &M, AllocaInst *V, DIVariable **DIVP) {
static DIVariable Var;
- const DbgDeclareInst *DDI = Backports::FindAllocaDbgDeclare(V);
+ const DbgDeclareInst *DDI = FindAllocaDbgDeclare(V);
if(DDI && DDI != (const DbgDeclareInst *) -1){
Var = DIVariable(cast<MDNode>(DDI->getVariable()));
if(DIVP) *DIVP = &Var;
StringRef MagicUtil::getFunctionSourceName(Module &M, Function *F, DISubprogram **DISP, const std::string &baseDir) {
static DISubprogram Func;
- Value *DIF = Backports::findDbgSubprogramDeclare(F);
+ MDNode *DIF = PassUtil::findDbgSubprogramDeclare(F);
if(DIF) {
- Func = DISubprogram(cast<MDNode>(DIF));
+ Func = DISubprogram(DIF);
if(DISP) *DISP = &Func;
if(F->getLinkage() == GlobalValue::InternalLinkage){
std::stringstream stm;
std::vector<const User*> sourceUsers;
sourceUsers.push_back(GV);
if(includeMembers && isa<GlobalVariable>(GV)) {
- for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end();
- UI != E; ++UI) {
- const User *U = *UI;
+ for (const Use &UI : GV->uses()) {
+ const User *U = UI.getUser();
const ConstantExpr *constantExpr = dyn_cast<ConstantExpr>(U);
if(isa<GetElementPtrInst>(U)) {
sourceUsers.push_back(U);
}
for(unsigned i=0;i<sourceUsers.size();i++) {
- for (Value::const_use_iterator UI = sourceUsers[i]->use_begin(), E = sourceUsers[i]->use_end();
- UI != E; ++UI) {
- const User *U = *UI;
+ for (const Use &UI : sourceUsers[i]->uses()) {
+ const User *U = UI.getUser();
if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
if (SI->getOperand(0) == sourceUsers[i] || SI->isVolatile())
return true; // Storing addr of sourceUsers[i].
} else if (isa<InvokeInst>(U) || isa<CallInst>(U)) {
// Make sure we are calling the function, not passing the address.
ImmutableCallSite CS(cast<Instruction>(U));
- if (!CS.isCallee(UI))
+ if (!CS.isCallee(&UI))
return true;
} else if (const LoadInst *LI = dyn_cast<LoadInst>(U)) {
if (LI->isVolatile())
GV->removeDeadConstantUsers();
std::set<int> set;
- for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end();
+ for (Value::const_user_iterator UI = GV->user_begin(), E = GV->user_end();
UI != E; ++UI) {
const User *U = *UI;
if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
std::vector<User*> sourceUsers;
sourceUsers.push_back(GV);
- for (Value::use_iterator UI = GV->use_begin(), E = GV->use_end();
+ for (Value::user_iterator UI = GV->user_begin(), E = GV->user_end();
UI != E; ++UI) {
User *U = *UI;
ConstantExpr *constantExpr = dyn_cast<ConstantExpr>(U);
Value *stringOwner = NULL;
for(unsigned i=0;i<sourceUsers.size();i++) {
- for (Value::use_iterator UI = sourceUsers[i]->use_begin(), E = sourceUsers[i]->use_end();
+ for (Value::user_iterator UI = sourceUsers[i]->user_begin(), E = sourceUsers[i]->user_end();
UI != E; ++UI) {
User *U = *UI;
Value *V = U;
+#include <magic_common.h>
#include <magic/support/SmartType.h>
#include <limits.h>
if(GV->getName().startswith(".str")) {
return NULL;
}
- Value *DIGV = Backports::findDbgGlobalDeclare(GV);
+ MDNode *DIGV = PassUtil::findDbgGlobalDeclare(GV);
if (!DIGV) {
return NULL;
}
- DIGlobalVariable Var(cast<MDNode>(DIGV));
- DIType aDIType = Var.getType();
+ DIGlobalVariable Var(DIGV);
+ DIType aDIType = PassUtil::getDITypeFromRef(Var.getType());
const SmartType* retSmartType = new SmartType(GV->getType()->getElementType(), &aDIType);
if(DIG) {
*DIG = Var;
}
const SmartType* SmartType::getSmartTypeFromLV(Module &M, AllocaInst *AI, DIVariable *DIV) {
- const DbgDeclareInst *DDI = Backports::FindAllocaDbgDeclare(AI);
+ const DbgDeclareInst *DDI = FindAllocaDbgDeclare(AI);
if (!DDI) {
return NULL;
}
return (const SmartType*)-1;
}
DIVariable Var(cast<MDNode>(DDI->getVariable()));
- DIType aDIType = Var.getType();
+ DIType aDIType = PassUtil::getDITypeFromRef(Var.getType());
if(DIV) {
*DIV = Var;
}
}
const SmartType* SmartType::getSmartTypeFromFunction(Module &M, Function *F, DISubprogram *DIS) {
- Value *DIF = Backports::findDbgSubprogramDeclare(F);
+ MDNode *DIF = PassUtil::findDbgSubprogramDeclare(F);
if (!DIF) {
return NULL;
}
- DISubprogram Sub(cast<MDNode>(DIF));
+ DISubprogram Sub(DIF);
DIType aDIType = Sub.getType();
const SmartType* retSmartType = new SmartType(F->getType()->getElementType(), &aDIType);
if(DIS) {
return sectionified;
}
-bool SectionifyPass::sectionifyFromRegex(GlobalValue *value, Regex *regex, std::string §ion)
+bool SectionifyPass::sectionifyFromRegex(GlobalObject *value, Regex *regex, std::string §ion)
{
bool returnValue = false;
DEBUG(errs() << "Sectionified " << valueStrPrefix << (isa<Function>(value) ? "Function " : "GlobalVariable ") << value->getName() << " with section " << trgSection << "\n");
value->setSection(trgSection);
if (value->hasCommonLinkage()) {
- value->setLinkage(GlobalValue::WeakAnyLinkage);
+ value->setLinkage(GlobalObject::WeakAnyLinkage);
}
returnValue = true;
}
return returnValue;
}
-bool SectionifyPass::sectionify(GlobalValue *value, std::vector<Regex*> ®exList, std::map<Regex*, std::string> ®exMap)
+bool SectionifyPass::sectionify(GlobalObject *value, std::vector<Regex*> ®exList, std::map<Regex*, std::string> ®exMap)
{
std::map<Regex*, std::string>::iterator regexMapIt;
for (std::vector<Regex*>::iterator it = regexList.begin(); it != regexList.end(); ++it) {