From 92c4482fe577507cbb39340bbe41c6600a52dde3 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Thu, 21 Sep 2023 15:11:15 +1000 Subject: [PATCH] Revert "Debug utils (#369)" This reverts commit 465ecdc4e3b0c28149b90a1efeb3d38857f8bcd5. --- bin/Decompile/Main.cpp | 23 +++------------ include/anvill/Lifters.h | 7 +---- lib/Lifters/CodeLifter.cpp | 59 +++++++++----------------------------- lib/Lifters/CodeLifter.h | 3 +- scripts/build.sh | 2 +- 5 files changed, 21 insertions(+), 73 deletions(-) diff --git a/bin/Decompile/Main.cpp b/bin/Decompile/Main.cpp index e79ceba68..b74245233 100644 --- a/bin/Decompile/Main.cpp +++ b/bin/Decompile/Main.cpp @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include #include #include @@ -47,10 +45,6 @@ DEFINE_bool(add_breakpoints, false, DEFINE_bool(add_names, false, "Try to apply symbol names to lifted entities."); DEFINE_bool(disable_opt, false, "Dont apply optimization passes"); DEFINE_bool(llvm_debug, false, "Enable LLVM debug flag"); -DEFINE_bool(llvm_print_changed_diff, false, - "Print IR diff. NOTE: LLVM must be compiled as Debug"); -DEFINE_bool(llvm_print_changed_color_diff, false, - "Print IR colored diff. NOTE: LLVM must be compiled as Debug"); DEFINE_bool(inline_basic_blocks, false, "Enables inlining of basic blocks for high level output"); @@ -95,16 +89,6 @@ int main(int argc, char *argv[]) { google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); - if (FLAGS_llvm_debug) { - llvm::DebugFlag = true; - } - - if (FLAGS_llvm_print_changed_diff) { - llvm::PrintChanged = llvm::ChangePrinter::DiffVerbose; - } else if (FLAGS_llvm_print_changed_color_diff) { - llvm::PrintChanged = llvm::ChangePrinter::ColourDiffVerbose; - } - if (FLAGS_spec.empty()) { std::cerr << "Please specify a path to a Protobuf specification file in '--spec'" @@ -192,9 +176,6 @@ int main(int argc, char *argv[]) { options.stack_frame_recovery_options.stack_offset_metadata_name = "stack_offset"; - options.debug_pm = FLAGS_llvm_debug || FLAGS_llvm_print_changed_diff || - FLAGS_llvm_print_changed_color_diff; - anvill::EntityLifter lifter(options); std::unordered_map names; @@ -264,6 +245,10 @@ int main(int argc, char *argv[]) { llvm::EnableStatistics(); } + if (FLAGS_llvm_debug) { + llvm::DebugFlag = true; + } + if (!FLAGS_disable_opt) { anvill::OptimizeModule(lifter, module, spec.GetBlockContexts(), spec); } diff --git a/include/anvill/Lifters.h b/include/anvill/Lifters.h index 67b2408fe..6107def57 100644 --- a/include/anvill/Lifters.h +++ b/include/anvill/Lifters.h @@ -219,8 +219,7 @@ class LifterOptions { //TODO(ian): This should be initialized by an OS + arch pair stack_pointer_is_signed(false), should_remove_anvill_pc(true), - should_inline_basic_blocks(false), - debug_pm(false) { + should_inline_basic_blocks(false) { CheckModuleContextMatchesArch(); } @@ -294,10 +293,6 @@ class LifterOptions { bool should_inline_basic_blocks : 1; - // enable pass manager debug printout - bool debug_pm; - - private: LifterOptions(void) = delete; diff --git a/lib/Lifters/CodeLifter.cpp b/lib/Lifters/CodeLifter.cpp index 6454142bb..2b8e921d8 100644 --- a/lib/Lifters/CodeLifter.cpp +++ b/lib/Lifters/CodeLifter.cpp @@ -6,20 +6,13 @@ #include #include #include +#include #include #include -#include -#include #include #include -#include -#include -#include -#include -#include #include #include -#include #include #include #include @@ -306,44 +299,18 @@ void CodeLifter::RecursivelyInlineFunctionCallees(llvm::Function *inf) { DCHECK(!llvm::verifyFunction(*inf, &llvm::errs())); - llvm::ModuleAnalysisManager mam; - llvm::FunctionAnalysisManager fam; - llvm::LoopAnalysisManager lam; - llvm::CGSCCAnalysisManager cam; - - llvm::ModulePassManager mpm; - llvm::FunctionPassManager fpm; - - llvm::PassInstrumentationCallbacks pic; - llvm::StandardInstrumentations si(inf->getContext(), - /*DebugLogging=*/options.debug_pm, - /*VerifyEach=*/options.debug_pm); - si.registerCallbacks(pic, &fam); - - llvm::PassBuilder pb(nullptr, llvm::PipelineTuningOptions(), std::nullopt, - &pic); - pb.registerModuleAnalyses(mam); - pb.registerFunctionAnalyses(fam); - pb.registerLoopAnalyses(lam); - pb.registerCGSCCAnalyses(cam); - pb.crossRegisterProxies(lam, fam, cam, mam); - - fpm.addPass(llvm::SimplifyCFGPass()); - fpm.addPass(llvm::PromotePass()); - fpm.addPass(llvm::ReassociatePass()); - fpm.addPass(llvm::DSEPass()); - fpm.addPass(llvm::DCEPass()); - fpm.addPass(llvm::SROAPass(llvm::SROAOptions::ModifyCFG)); - fpm.addPass(llvm::DCEPass()); - fpm.addPass(llvm::InstCombinePass()); - - mpm.addPass(llvm::createModuleToFunctionPassAdaptor(std::move(fpm))); - mpm.run(*inf->getParent(), mam); - - mam.clear(); - fam.clear(); - lam.clear(); - cam.clear(); + llvm::legacy::FunctionPassManager fpm(inf->getParent()); + fpm.add(llvm::createCFGSimplificationPass()); + fpm.add(llvm::createPromoteMemoryToRegisterPass()); + fpm.add(llvm::createReassociatePass()); + fpm.add(llvm::createDeadStoreEliminationPass()); + fpm.add(llvm::createDeadCodeEliminationPass()); + fpm.add(llvm::createSROAPass()); + fpm.add(llvm::createDeadCodeEliminationPass()); + fpm.add(llvm::createInstructionCombiningPass()); + fpm.doInitialization(); + fpm.run(*inf); + fpm.doFinalization(); ClearVariableNames(inf); } diff --git a/lib/Lifters/CodeLifter.h b/lib/Lifters/CodeLifter.h index cc7f10438..195815eeb 100644 --- a/lib/Lifters/CodeLifter.h +++ b/lib/Lifters/CodeLifter.h @@ -29,6 +29,7 @@ class CodeLifter { remill::OperandLifter::OpLifterPtr op_lifter; + // Are we lifting SPARC code? This affects whether or not we need to do // double checking on function return addresses; const bool is_sparc; @@ -86,4 +87,4 @@ class CodeLifter { CodeLifter(CodeLifter &&) = default; }; -} // namespace anvill +} // namespace anvill \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index 03b44a2bd..56c8862e4 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -364,7 +364,7 @@ function Help echo " --build-dir Change the default (${BUILD_DIR}) build directory." echo " --debug Build with Debug symbols." echo " --extra-cmake-args Extra CMake arguments to build with." - echo " --install Just install Anvill, do not package it." + echo " --install Just install Rellic, do not package it." echo " -h --help Print help." }