diff --git a/clambcc/clambc-compiler.py b/clambcc/clambc-compiler.py index c11a6fa567..0dd31bb321 100755 --- a/clambcc/clambc-compiler.py +++ b/clambcc/clambc-compiler.py @@ -540,7 +540,6 @@ def createInputSourceFile(clangLLVM: ClangLLVM, name: str, args: list, options: OPTIMIZE_OPTIONS.append("-opaque-pointers=0") OPTIMIZE_PASSES = ["function(mem2reg)" - , 'clambc-remove-undefs' , 'verify' , 'clambc-preserve-abis' , 'verify' diff --git a/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.cpp b/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.cpp index f7f524edf5..385b32d658 100644 --- a/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.cpp +++ b/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.cpp @@ -39,8 +39,6 @@ using namespace llvm; AnalysisKey ClamBCAnalyzer::Key; -//extern cl::opt WriteDI; - static unsigned getSpecialIndex(StringRef Name) { // Ensure main/entrypoint is sorted before any other function @@ -69,16 +67,10 @@ static bool compare_lt_functions(Function *A, Function *B) return NA.compare(NB) < 0; } -#if 0 -bool ClamBCAnalysis::runOnModule(Module &M) -#else void ClamBCAnalysis::run(Module & m) -#endif { pMod = &m; - DEBUGERR << "ClamBCAnalysis::run::" << __LINE__ << ">\n"; - // Determine bytecode kind, default is 0 (generic). kind = 0; GlobalVariable *GVKind = pMod->getGlobalVariable("__clambc_kind"); @@ -99,9 +91,7 @@ void ClamBCAnalysis::run(Module & m) if (!getConstantStringInfo(C, c)) { ClamBCStop("Failed to extract copyright string\n", pMod); } - // copyright = strdup(c.c_str()); copyright = c.str(); - // G->setLinkage(GlobalValue::InternalLinkage); // Do not set the linkage type to internal because the optimizer will remove it. } @@ -124,18 +114,13 @@ void ClamBCAnalysis::run(Module & m) } std::vector types; - // cid=1; fid = 1; for (Module::global_iterator I = pMod->global_begin(); I != pMod->global_end(); ++I) { GlobalVariable *gv = llvm::cast(I); -//DEBUG_VALUE(gv); std::set insts; std::set globs; std::set ces; getDependentValues(gv, insts, globs, ces); -//DEBUG_NONPOINTER(insts.size()); -//DEBUG_NONPOINTER(globs.size()); -//DEBUG_NONPOINTER(ces.size()); /*It is necessary to add these twice, because there is a condition we * can't use global idx 0 or 1 in the interpreter, since the size will @@ -157,12 +142,8 @@ void ClamBCAnalysis::run(Module & m) errs() << "UNSUPPORTED: " << *CE << "\n"; ClamBCStop("Unsupported constant expression", pMod); } - //DEBUG_VALUE(CE); - //DEBUG_NONPOINTER(CE->getNumOperands()); ConstantInt *C0 = dyn_cast(CE->getOperand(1)); ConstantInt *C1 = dyn_cast(CE->getOperand(2)); - //DEBUG_NONPOINTER(C0); - //DEBUG_NONPOINTER(C1); uint64_t v = C1->getValue().getZExtValue(); if (!C0->isZero()) { errs() << "UNSUPPORTED: " << *CE << "\n"; @@ -177,29 +158,7 @@ void ClamBCAnalysis::run(Module & m) indices.push_back(CE->getOperand(i)); } Type *IP8Ty = PointerType::getUnqual(Type::getInt8Ty(CE->getContext())); - -#if 0 - Type *type = CE->getOperand(0)->getType(); - if (llvm::isa(type)) { -#if 0 - type = llvm::cast(type)->getElementType(); -#else - if (llvm::isa(CE)){ - GEPOperator * pgep = llvm::cast(CE); - type = pgep->getPointerOperandType(); - } else if (llvm::isa(CE)){ - BitCastOperator - } else { - llvm::errs() << "<" << __LINE__ << ">" << "https://llvm.org/docs/OpaquePointers.html" << "\n"; - llvm::errs() << "<" << __LINE__ << ">" << *CE << "\n"; - assert (0 && "FIGURE OUT WHAT TO DO HERE"); - } -#endif - - } -#else Type * type = getResultType(CE); -#endif uint64_t idx = dataLayout.getIndexedOffsetInType(type, indices); @@ -226,10 +185,6 @@ void ClamBCAnalysis::run(Module & m) // Collect types of all globals. const Type *Ty = I->getType(); Ty = I->getValueType(); - //DEBUGERR << "FIGURE OUT IF THIS IS RIGHT" << "\n"; - - //DEBUG_VALUE(Ty); - //DEBUG_VALUE(I->getValueType()); if (!typeIDs.count(Ty)) { extraTypes.push_back(Ty); typeIDs[Ty] = tid++; @@ -243,7 +198,6 @@ void ClamBCAnalysis::run(Module & m) Function *F = &*I; ++I; functions.push_back(F); -// F->removeFromParent(); } for (size_t i = 0; i < functions.size(); i++){ @@ -297,9 +251,6 @@ void ClamBCAnalysis::run(Module & m) } continue; } - //DEBUGERR << "THIS IS THE PLACE TO LOOK" << "\n"; - //DEBUG_NONPOINTER(F.getName()); - //DEBUG_VALUE(&F); functionIDs[&F] = fid++; for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { const Type *Ty = I->getType(); @@ -310,9 +261,7 @@ void ClamBCAnalysis::run(Module & m) typeIDs[Ty] = tid++; } - //DEBUG_VALUE(&F); for (inst_iterator II = inst_begin(F), IE = inst_end(F); II != IE; ++II) { - //DEBUG_VALUE(II); const Type *Ty; // Skip debug intrinsics, so we don't add llvm.dbg.* types if (isa(&*II)) { @@ -330,8 +279,6 @@ void ClamBCAnalysis::run(Module & m) // Collect types of all instructions. if (const AllocaInst *AI = dyn_cast(&*II)) { Ty = AI->getAllocatedType(); - //DEBUG_VALUE(AI); - //DEBUG_VALUE(Ty); } else { Ty = II->getType(); } @@ -345,31 +292,25 @@ void ClamBCAnalysis::run(Module & m) } } - //DEBUG_VALUE(Ty); for (size_t i = 0; i < II->getNumOperands(); i++){ Value * operand = II->getOperand(i); if (llvm::isa(operand)){ continue; } Type * pt = operand->getType(); - //DEBUG_VALUE(pt); if (0 == typeIDs.count(pt)){ - //DEBUG_VALUE(pt); types.push_back(pt); extraTypes.push_back(pt); typeIDs[pt] = tid++; } } - if (typeIDs.count(Ty)) { continue; } types.push_back(Ty); extraTypes.push_back(Ty); typeIDs[Ty] = tid++; - - } } @@ -406,9 +347,6 @@ void ClamBCAnalysis::run(Module & m) } printGlobals(startTID); - -// DEBUGERR << "ClamBCAnalysis::run::" << __LINE__ << ">\n"; - //return false; } void ClamBCAnalysis::printGlobals(uint16_t stid) @@ -416,7 +354,6 @@ void ClamBCAnalysis::printGlobals(uint16_t stid) llvm::Module &M = *pMod; // Describe types maxApi = 0; - // std::vector apis; for (Module::iterator I = pMod->begin(), E = pMod->end(); I != E; ++I) { llvm::Function *pFunc = llvm::cast(I); // Skip dead declarations @@ -478,13 +415,9 @@ void ClamBCAnalysis::printGlobals(uint16_t stid) specialGlobals.insert(GV); } - //DEBUGERR << "PRINTING ALL GLOBALS IN ANALYZER" << "\n"; - - // std::vector globalInits; globalInits.push_back(0); // ConstantPointerNul placeholder for (Module::global_iterator I = pMod->global_begin(), E = pMod->global_end(); I != E; ++I) { GlobalVariable *pgv = llvm::cast(I); - //DEBUG_VALUE(pgv); if (specialGlobals.count(pgv)) { continue; } @@ -511,15 +444,15 @@ void ClamBCAnalysis::printGlobals(uint16_t stid) &M); } Constant *C = pgv->getInitializer(); - if (C->use_empty()) + if (C->use_empty()) { continue; + } globalInits.push_back(C); globals[pgv] = i++; if (i >= 32768) { ClamBCStop("Attempted to use more than 32k global variables!", &M); } } - DEBUGERR << "DONE PRINTING ALL GLOBALS IN ANALYZER" << "\n"; if (anyDbgIds) { mds.resize(dbgMap.size()); @@ -664,22 +597,6 @@ void ClamBCAnalysis::populateAPIMap() apiMap["bzip2_done"] = id++; } -#if 0 -void ClamBCAnalysis::getAnalysisUsage(AnalysisUsage &AU) const -{ - // Preserve the CFG, we only eliminate PHIs, and introduce some - // loads/stores. - AU.setPreservesAll(); -} -#endif -#if 0 -char ClamBCAnalysis::ID = 0; -static RegisterPass X("clambc-analyzer", - "ClamAV bytecode register allocator"); - -const PassInfo *const ClamBCAnalysisID = &X; -#else - // This part is the new way of registering your pass extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { @@ -696,5 +613,3 @@ llvmGetPassPluginInfo() { } -#endif - diff --git a/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.h b/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.h index 934281309b..b83b39f417 100644 --- a/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.h +++ b/libclambcc/ClamBCAnalyzer/ClamBCAnalyzer.h @@ -135,13 +135,8 @@ class ClamBCAnalysis } ~ClamBCAnalysis() {} - //virtual bool runOnModule(llvm::Module &m) override; virtual void run(llvm::Module & m); -#if 0 - virtual void getAnalysisUsage(llvm::AnalysisUsage &au) const override; -#endif - virtual uint32_t getTypeID(const llvm::Type *const t) { TypeMapTy::iterator I = typeIDs.find(t); @@ -149,20 +144,6 @@ class ClamBCAnalysis DEBUG_NONPOINTER("BAD VALUE"); DEBUG_VALUE(t); } -#if 0 - static int first = 1; - if (first) { - for (auto i = typeIDs.begin(), e = typeIDs.end(); i != e; i++) - { - DEBUGERR << *(i->first) << "::" << i->second << "\n"; - } - first = 0; - } -#endif - - - - assert((I != typeIDs.end()) && "Type ID requested for unknown type"); return I->second; @@ -284,7 +265,7 @@ class ClamBCAnalysis } }; -class ClamBCAnalyzer : public llvm::AnalysisInfoMixin //llvm::ModulePass +class ClamBCAnalyzer : public llvm::AnalysisInfoMixin { protected: ClamBCAnalysis clamBCAnalysis; diff --git a/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp b/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp index 9718970809..c75fc74479 100644 --- a/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp +++ b/libclambcc/ClamBCRemoveUndefs/ClamBCRemoveUndefs.cpp @@ -238,7 +238,8 @@ struct ClamBCRemoveUndefs : public PassInfoMixin PreservedAnalyses run(Module & m, ModuleAnalysisManager & MAM) #endif { - DEBUGERR << "This was causing issues in testing, so removed. Still need to verify that we no longer need it" << "\n"; return PreservedAnalyses::all(); + /*This no longer appears to be needed. Will keep it during the -rc phase and then remove.*/ + return PreservedAnalyses::all(); pMod = &m;