Skip to content

Commit

Permalink
bump remill and fix initial state pc (#407)
Browse files Browse the repository at this point in the history
* bump remill and fix initial state pc

* bump remill

* don't install python3 bindings in CI

* dont set body twice if struct named twice

* completely remove python

* try to be robust to overlapping vars

---------

Co-authored-by: William Tan <[email protected]>
  • Loading branch information
2over12 and Ninja3047 authored Feb 28, 2024
1 parent 70209a8 commit 30969fb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ jobs:
-Dsleigh_DIR:PATH=${{ steps.remill_installer.outputs.PATH }}/usr/local/lib/cmake/sleigh \
-DANVILL_ENABLE_TESTS=true \
-DANVILL_ENABLE_INSTALL=true \
-DANVILL_INSTALL_PYTHON3_LIBS=false \
-G Ninja \
${{ steps.build_paths.outputs.SOURCE }}/anvill
Expand Down
4 changes: 0 additions & 4 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ target_link_libraries(anvill

add_dependencies(anvill check_git_anvill)

if(ANVILL_ENABLE_PYTHON3_LIBS)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../python" python)
endif()

# if(ANVILL_ENABLE_TESTS)
# add_subdirectory("tests")
# endif()
Expand Down
14 changes: 9 additions & 5 deletions lib/Lifters/BasicBlockLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool BasicBlockLifter::DoInterProceduralControlFlow(
auto func = block->getParent();
auto should_return = func->getArg(kShouldReturnArgNum);
builder.CreateStore(llvm::Constant::getAllOnesValue(
llvm::IntegerType::getInt1Ty(llvm_context)),
llvm::IntegerType::getInt1Ty(llvm_context)),
should_return);
}
}
Expand Down Expand Up @@ -417,7 +417,8 @@ llvm::MDNode *BasicBlockLifter::GetBasicBlockUidAnnotation(Uid uid) const {

llvm::Function *BasicBlockLifter::DeclareBasicBlockFunction() {
std::string name_ = "func" + std::to_string(decl.address) + "basic_block" +
std::to_string(this->block_def.addr) + "_" + std::to_string(this->block_def.uid.value);
std::to_string(this->block_def.addr) + "_" +
std::to_string(this->block_def.uid.value);
auto &context = this->semantics_module->getContext();
llvm::FunctionType *lifted_func_type =
llvm::dyn_cast<llvm::FunctionType>(remill::RecontextualizeType(
Expand Down Expand Up @@ -597,7 +598,8 @@ BasicBlockFunction BasicBlockLifter::CreateBasicBlockFunction() {
auto pc_ptr = pc_reg->AddressOf(this->state_ptr, ir);
auto pc_val = this->options.program_counter_init_procedure(
ir, this->address_type, this->block_def.addr);
ir.CreateStore(pc_val, pc_ptr);

ir.CreateStore(ir.CreateZExtOrTrunc(pc_val, pc_reg_type), pc_ptr);

std::array<llvm::Value *, kNumLiftedBasicBlockArgs> args = {
this->state_ptr, pc_val, mem_res, next_pc, should_return};
Expand Down Expand Up @@ -648,7 +650,8 @@ void BasicBlockLifter::TerminateBasicBlockFunction(
llvm::IRBuilder<> calling_bb_builder(calling_bb);
auto edge_bb = this->decl.cfg.find(edge_uid);
CHECK(edge_bb != this->decl.cfg.end());
auto &child_lifter = this->flifter.GetOrCreateBasicBlockLifter(edge_bb->second.uid);
auto &child_lifter =
this->flifter.GetOrCreateBasicBlockLifter(edge_bb->second.uid);
auto retval = child_lifter.ControlFlowCallBasicBlockFunction(
caller, calling_bb_builder, this->state_ptr, bbfunc.stack, next_mem);
if (this->flifter.curr_decl->type->getReturnType()->isVoidTy()) {
Expand All @@ -658,7 +661,8 @@ void BasicBlockLifter::TerminateBasicBlockFunction(
}

auto succ_const = llvm::ConstantInt::get(
llvm::cast<llvm::IntegerType>(this->address_type), edge_bb->second.addr);
llvm::cast<llvm::IntegerType>(this->address_type),
edge_bb->second.addr);
sw->addCase(succ_const, calling_bb);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Passes/ReplaceStackReferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,12 @@ class StackModel {
GetParamDeclSize(var) - 1);
}

LOG(FATAL) << "Inserting variable that overlaps with current frame "
LOG(ERROR) << "Inserting variable that overlaps with current frame "
<< var.ordered_locs[0].mem_offset
<< " with size: " << GetParamDeclSize(var) << " Overlaps with "
<< oparam->decl.decl.ordered_locs[0].mem_offset
<< " with size " << GetParamDeclSize(oparam->decl.decl);
return;
}

this->frame.insert({var.ordered_locs[0].mem_offset, {index, var}});
Expand Down
4 changes: 3 additions & 1 deletion lib/Protobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,9 @@ Result<std::monostate, std::string> ProtobufTranslator::DecodeTypeMap(

std::string name = names.at(k);
auto res = getOrCreateNamedStruct(this->context, name);
res->setBody(sty->elements());
if (res->isOpaque()) {
res->setBody(sty->elements());
}
}
type_names[k] = names.at(k);
} else {
Expand Down
2 changes: 1 addition & 1 deletion libraries/lifting-tools-ci

0 comments on commit 30969fb

Please sign in to comment.