Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Debug utils (#369)" #391

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions bin/Decompile/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <llvm/ADT/Statistic.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/PrintPasses.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/MemoryBuffer.h>
#include <remill/Arch/Arch.h>
#include <remill/BC/Error.h>
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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'"
Expand Down Expand Up @@ -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<uint64_t, std::string> names;
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 1 addition & 6 deletions include/anvill/Lifters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -294,10 +293,6 @@ class LifterOptions {

bool should_inline_basic_blocks : 1;

// enable pass manager debug printout
bool debug_pm;


private:
LifterOptions(void) = delete;

Expand Down
59 changes: 13 additions & 46 deletions lib/Lifters/CodeLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Pass.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/Passes/StandardInstrumentations.h>
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Scalar/DCE.h>
#include <llvm/Transforms/Scalar/DeadStoreElimination.h>
#include <llvm/Transforms/Scalar/Reassociate.h>
#include <llvm/Transforms/Scalar/SROA.h>
#include <llvm/Transforms/Scalar/SimplifyCFG.h>
#include <llvm/Transforms/Utils.h>
#include <llvm/Transforms/Utils/Cloning.h>
#include <llvm/Transforms/Utils/Mem2Reg.h>
#include <remill/Arch/Arch.h>
#include <remill/Arch/Context.h>
#include <remill/Arch/Instruction.h>
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Lifters/CodeLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,4 +87,4 @@ class CodeLifter {
CodeLifter(CodeLifter &&) = default;
};

} // namespace anvill
} // namespace anvill
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

Expand Down
Loading