From 056be957a0fc3ab4420cab85d807b4f0dca9f83e Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Tue, 31 May 2022 21:17:45 +1000 Subject: [PATCH] More fixes --- include/remill/BC/Compat/PointerType.h | 2 +- lib/Arch/Arch.cpp | 9 ++------- lib/BC/Util.cpp | 4 ++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/remill/BC/Compat/PointerType.h b/include/remill/BC/Compat/PointerType.h index f992edf0..35ac465d 100644 --- a/include/remill/BC/Compat/PointerType.h +++ b/include/remill/BC/Compat/PointerType.h @@ -21,7 +21,7 @@ namespace remill { // TODO(alex): Just remove this function entirely inline static llvm::Type *PointerElementType(llvm::PointerType *type) { - assert(type->isOpaque()); + // assert(type->isOpaque()); return nullptr; } diff --git a/lib/Arch/Arch.cpp b/lib/Arch/Arch.cpp index 09b7b8eb..c75be0e8 100644 --- a/lib/Arch/Arch.cpp +++ b/lib/Arch/Arch.cpp @@ -496,11 +496,7 @@ FinishAddressOf(llvm::IRBuilder<> &ir, const llvm::DataLayout &dl, // Best case: we've found a value field in the structure that // is located at the correct byte offset. if (gep_offset == reg->offset) { - if (gep->getType()->isPointerTy()) { - return gep; - - } else if (auto const_gep = llvm::dyn_cast(gep); - const_gep) { + if (auto const_gep = llvm::dyn_cast(gep); const_gep) { return llvm::ConstantExpr::getBitCast(const_gep, goal_ptr_type); } else { @@ -574,8 +570,7 @@ llvm::Value *Register::AddressOf(llvm::Value *state_ptr, return AddressOf(state_ptr, ir); } -llvm::Value * -Register::AddressOf(llvm::Value *state_ptr, +llvm::Value *Register::AddressOf(llvm::Value *state_ptr, llvm::IRBuilder<> &ir) const { auto &context = type->getContext(); CHECK_EQ(&context, &(state_ptr->getContext())); diff --git a/lib/BC/Util.cpp b/lib/BC/Util.cpp index 8f17bb85..a2662a70 100644 --- a/lib/BC/Util.cpp +++ b/lib/BC/Util.cpp @@ -1464,6 +1464,9 @@ llvm::GlobalVariable *DeclareVarInModule(llvm::GlobalVariable *var, return llvm::dyn_cast(moved_var); } + // NOTE(alex): This looks difficult to reproduce without querying `PointerElementType`. + // It appears to be transferring global variables from one LLVM module to another. The + // variables are pointer types. auto &dest_context = dest_module->getContext(); const auto type = ::remill::RecontextualizeType( PointerElementType(var->getType()), dest_context); @@ -2433,6 +2436,7 @@ llvm::Value *BuildPointerToOffset(llvm::IRBuilder<> &ir, llvm::Value *ptr, } } + // NOTE(alex): Same here const auto dest_elem_type = PointerElementType(dest_elem_ptr_type); const auto ptr_elem_type = PointerElementType(ptr_type); const auto ptr_elem_size = dl.getTypeAllocSize(ptr_elem_type);