400 Commits

Author SHA1 Message Date
Alessandro Di Federico 1dbe474873 Whitespace fixes 2021-12-16 11:56:06 +01:00
Antonio Frighetto 10f45c593a Move StackAnalysis to EarlyFunctionAnalysis 2021-12-15 18:03:30 +01:00
Antonio Frighetto 215dab9dd2 Introduce CSVAliasAnalysisPass
A pass that decorates memory accesses with
information about CSV aliasing.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 4504b3d770 JumpTargetManager: move getOption in IRHelpers 2021-12-15 18:03:30 +01:00
Antonio Frighetto 34580789eb BinaryFile: add architecture-dependent fields
Add return address register and minimal final stack offset in Arch.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 31620e4efd CodeGenerator: record static functions as well 2021-12-15 18:03:30 +01:00
Antonio Frighetto adcda3532b AVI: fix error in detection of stores to PC 2021-11-18 15:30:07 +01:00
Alessandro Di Federico 89532890ed Introduce support for importing DWARF information 2021-10-21 15:01:20 +02:00
Alessandro Di Federico 3a3eea0cf5 Introduce support for dynamic functions 2021-10-21 15:01:19 +02:00
Alessandro Di Federico a023bfa7f5 Introduce ABI handling 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 18cfbdbfe0 Whitespace and other minor changes 2021-10-18 12:39:21 +02:00
Pietro Fezzardi 67eaaab045 JumpTargetManager: enable InstCombine(true)
This fixes the latest failing tests after upgrading to llvm-12.
2021-06-14 23:04:02 +02:00
Pietro Fezzardi b96fbd091d Fix check-conventions with clang-format-12 2021-06-14 23:04:02 +02:00
Pietro Fezzardi 6f7de910a6 Enable warning -Wunused-local-typedefs 2021-06-14 23:04:02 +02:00
Pietro Fezzardi 544b553e5c JumpTargetManger: swap constprop with instsimplify
Constant propagation has been dropped from llvm
2021-06-14 23:04:02 +02:00
Pietro Fezzardi 12364e6d63 Update BinaryFile to new llvm::object APIs
This is required to compile against llvm-12
2021-06-14 23:04:02 +02:00
Pietro Fezzardi d3d4e1ea5e JumpTargetManager.cpp: include missing header
Before the addition of this include, the file failed to compile with
llvm-12.
2021-06-14 23:04:02 +02:00
Filippo Cremonese 478baf1f43 Fix use-after-free in InstructionTranslator 2021-06-09 18:42:56 +02:00
Antonio Frighetto 67b6bc491b BinaryFile: always relocate addresses
Always relocating addresses allows to include symbols on
dynamically linked position independent objects as well.
2021-06-09 18:15:16 +02:00
Ivan Krysak bc8c8f82d2 Prevent separation of 'main' headers into group 0
The prevention mechanism uses a dummy suffix:
'_THIS_SEQUENCE_IS_NEVER_GOING_TO_HAPPEN'.
2021-06-09 18:05:20 +02:00
Alessandro Di Federico 0af0fea277 Handle R_386_32 relocations 2021-05-12 18:42:17 +02:00
Alessandro Di Federico ec0a1c7d3e Fix dispatcher.external
`dispatcher.external` used to jump to itself due to a misuse of
`replaceAllUsesWith`.
2021-05-12 18:42:08 +02:00
Alessandro Di Federico 9be97248ce Reorganize VariableManager
This commit slightly improves VariableManager's API and, most
importantly, undef-initializes all TCG variables in order to avoid
creation of complex PHIs.
2021-05-08 19:27:57 +02:00
Alessandro Di Federico 82260c2693 Make dumping assembly and PTC optional
Output files can become *very* large.

This commit disables by default dumping disassembled instructions and
PTC code into the IR.
2021-05-08 19:27:57 +02:00
Alessandro Di Federico 91991bb694 Handle PHIs in lifted code
In large binaries PHI nodes show up. As a consequence, calls to `newpc`
are no longer the first instruction.

This commit uses the `getFirstNonPHI` method to fix this issue.
2021-05-08 19:19:41 +02:00
Pietro Fezzardi 223d022968 replaceFunction: preserve metadata 2021-04-30 14:52:25 +02:00
Alessandro Di Federico 2e9c2ee275 Introduce FunctionTags
FunctionTags goal is to solve the long-standing problem of identifying
what type of function are we dealing with. Is it a lifted function? An
helper?

Now we have a sane way to determine this using Metadata and a proper
API.
2021-04-22 18:07:24 +02:00
Alessandro Di Federico 2ea5723a53 s/getCalledValue/getCalledOperand/g 2021-04-22 18:06:27 +02:00
Alessandro Di Federico aeb81c4218 Don't implicitly use StringRef as std::string 2021-04-22 18:06:27 +02:00
Alessandro Di Federico d6df9b682f Use MaybeAlign 2021-04-22 18:06:27 +02:00
Alessandro Di Federico bd3e048647 CPUStateAccessFixer: do not call delete directly 2021-04-22 18:06:27 +02:00
Alessandro Di Federico e92cbd91a1 LoadInst::LoadInst: pass pointee type 2021-04-22 18:06:27 +02:00
Alessandro Di Federico 93ef716311 Module::getFunction returns Function * 2021-04-22 18:06:27 +02:00
Alessandro Di Federico fee270b64e Minor changes 2021-04-22 18:06:27 +02:00
Alessandro Di Federico 3ce9acf198 AVI: ignore function calls
This commit further reduces the time spent in AVI by considering all the
function calls as indirect. In fact, we currently don't handle indirect
jumps whose target is affected by computation happening before a
function call.
2021-04-22 18:05:39 +02:00
Alessandro Di Federico 33fbcd7ac2 AVI: stop backward exploration at dispatcher
This commit greatly improves the performance by ensuring that, when
computing the set of nodes we want to consider for AVI, we do not
traverse the dispatcher.

Doing so, means including *a lot* of irrelevant nodes and wasting a lot
of computation, since the CFG usually is not influenced by stuff
happening before an indirect jump.

In at least a situation the speedup is in the order of 20x, however this
depends on the size of the binary, since traversing the dispatcher means
including all the binary in the computations (as opposed to just the set
of blocks involved in the dataflow to compute a certain expression).
2021-04-22 18:05:39 +02:00
Alessandro Di Federico 0e21755eb0 Handle more count-leading-zeros helpers 2021-04-22 18:03:53 +02:00
Alessandro Di Federico 02f3bb4f88 QEMU helpers no longer have optnone
QEMU helpers are compiled with -O0. This led the functions in the QEMU
helper module to have the `optnone` attribute, preventing any
optimization.

This has now been fixed on the QEMU side with the following flags:

    clang -Xclang -disable-O0-optnone
2021-04-22 18:03:53 +02:00
Alessandro Di Federico 081809ec38 Adopt EliminateUnreachableBlocks 2021-04-22 14:45:52 +02:00
Alessandro Di Federico b25c43705c SerializeModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico ae0a92d7e1 SymbolType::fromELF: do not abort 2021-03-16 11:36:32 +01:00
Alessandro Di Federico 2c3df7068e revng-lift: keep harvesting upon new CFG edges
We used to stop the harvesting process when the harvesting process was
no longer able to identify new jump targets, even if new CFG edges have
been identified.

This approach prevented to discover additional parts of the CFG thanks
to the increased accuracy gained by a more accurate CFG. This effect is
particularly visible when we have jump tables that can be reached only
through other jump tables.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8b5a462187 AVI: use TypeShrinking
This enables us to handle situations where the comparison against the
switch value is performed on the lower 32 bits, but the address
computations uses the full 64 bits.

    cmp    edi,0x23
    ja     ...
    movsxd rdx,DWORD PTR [rcx+rdi*4]

Note that this does not solve all these situations yet.

This commit also introduces a reference output for the new
switch-jump-table-32-bit-comparison test case.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico 68e5c6c6ea AVI: drop PC initialization from cloned root
AVI used to work on a cloned root that was initializing the pc to the
program entry point. Under certain conditions, this led to DCE almost
all of the code.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico 27b58695a1 Let FunctionIsolation and EnforceABI use the Model 2021-02-19 09:39:49 +01:00
Alessandro Di Federico d0a78a41bf Drop direct branches to the dispatcher
Generated code now either jumps to `anypc` or `unexpectedpc`. The latter
one is to be considered a safety measure and will be populated with an
unreachable instruction on the decompilation pipeline.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico f2c83d2f67 Introduce PlainMetaAddress
This commit extracts a plain `struct` from the `MetaAddress` class. This
enables us to use `MetaAddress` from C and therefore, runtime.

The definition of such `struct`, `PlainMetaAddress`, is in
`PlainMetaAddress.h`, which is included by `early-linked.c`.

A function to print the content of a `PlainMetaAddress` has also been
introduced.

Also, anticipating the linkage of `early-linked.c` triggered a
superflous assertion in `CPUStateAccessAnalysis`. This commit removes
it.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico df11232fe1 Improve GCBI
* Introduce GCBI::buildDispatcher
* Introduce GCBI::getJumpTarget{,Block} and GCBI::getBlocksGeneratedByPC
  to easily map `BasicBlock *` to jump targets and viceversa.
* PCH::buildDispatcher now returns a list of the newly created basic
  blocks.
* Other minor changes
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 6cfcd087b7 Introduce ProgramCounterHandler::loadPC 2021-02-18 19:13:06 +01:00
Pietro Fezzardi 85971bcc06 revng-lift: write empty Model in lifted Modules 2021-02-17 11:37:01 +01:00