Commit Graph

233 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 3d9f10307d Force Mach-O entry point to be code 2021-01-24 18:37:35 +01:00
Alessandro Di Federico 4d1f681a44 Add RelocationTypes R_X86_64_{64,32} 2021-01-06 17:40:56 +01:00
Alessandro Di Federico 8549844d36 Set BaseAddress to 0x400000 by default 2021-01-06 17:40:56 +01:00
Alessandro Di Federico d3247870f0 Reorganize ProgramCounterHandler construction 2020-12-31 14:37:53 +01:00
Alessandro Di Federico a153dc3f7a ProgramCounterHandler.cpp: drop unnecessary llvm:: 2020-12-31 14:17:30 +01:00
Alessandro Di Federico 4c4e427a4a Make ProgramCounterHandler implementations private 2020-12-31 14:17:30 +01:00
Antonio Frighetto 02b3a24463 Jump to dispatcher when location is invalid
Replace a call to `abort` with a branch to `dispatcher` when the
callee is unknown or invalid (namely, it is always treated as an
indirect call).
2020-12-31 14:17:30 +01:00
Alessandro Di Federico 3c58c7441b Whitespace changes 2020-12-29 16:14:49 +01:00
Antonio Frighetto e6f0b26455 CodeGen: remove variadic args in calls to newpc
After the discovery of new code to be translated, the calls to `newpc`
can be stripped of their variadic arguments (reference to local vars)
in order to let SROA perform more optimization.
2020-12-29 15:25:42 +01:00
Alessandro Di Federico c6d0ce9dec Don't use RPOT for DisjointRanges
Sorting the BasicBlocks on which DisjointRanges works is detrimental for
performance.  Using a random order takes less time. This is due to the
fact that the number of BasicBlocks to analyze is significantly smaller
than the whole list of BasicBlocks.
2020-11-23 14:52:46 +01:00
Alessandro Di Federico cbe4967aad SymbolTableList::size() is expensive
This simple commit reduces the number of times we query the size of the
`BasicBlock` list of a `Function` during the final reodering of blocks
before emission.

This change introduces a 25% speedup when lifting `/bin/bash`.
2020-11-23 10:20:43 +01:00
Alessandro Di Federico c313fdbcb0 CSAA: verify module only if --debug-log=verify
This commit brings a 6% speedup in lifting `/bin/bash`.
2020-11-23 10:20:43 +01:00
Alessandro Di Federico 0ccc32af08 Performance: destroy AVI PassManager ASAP
It is important to let the pass manager go out of scope ASAP:
LazyValueInfo registers a lot of callbacks to get notified when a Value
is destroyed, slowing down OptimizedFunction->eraseFromParent
enormously.

This commit introduces a speedup of approximately 25% when lifting
`/bin/bash`.
2020-11-22 15:14:44 +01:00
Pietro Fezzardi 9869f057b9 Use #pragma once for header include guards 2020-11-13 14:12:18 +01:00
Pietro Fezzardi cd9bc34d9d Enforce new include conventions 2020-11-13 10:00:24 +01:00
Alessandro Di Federico bcd1554546 Do not add to CodePointers invalid addresses 2020-11-12 20:36:02 +01:00
Alessandro Di Federico 2fee00f01e Ignore undefined symbols 2020-11-12 20:35:58 +01:00