Commit Graph

156 Commits

Author SHA1 Message Date
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
Alessandro Di Federico ae500fa314 Assert ELFs are executables or .so 2020-11-12 16:39:28 +01:00
Alessandro Di Federico 5e7d288530 Introduce PruneRetSuccessors pass
This commit introduces the PruneRetSuccessors pass, whose role is to
identify all the indirect jumps whose devirtualized destinations
correspond to return addresses. In fact, they are most likely to be
return instructions and devirtualizing them is always detrimental.
2020-11-12 15:28:31 +01:00
Alessandro Di Federico 4b3562edce Handle failure of ptc_mmap 2020-11-12 14:55:57 +01:00
Pietro Fezzardi fc537a2fc7 Add missing MIT license headers 2020-11-12 14:55:57 +01:00
Alain Carlucci 42e8f8db02 revng-lift: Enable LLVM stack trace on kill signal
This commit enables LLVM stack trace mechanism when a kill signal is
raised.
2020-11-12 14:55:57 +01:00
Alessandro Di Federico cf5fca85a1 Whitespace changes 2020-11-12 14:55:56 +01:00
Alessandro Di Federico acb896e934 PE/COFF: consider ImageBase as code 2020-11-06 22:14:44 +01:00
Alessandro Di Federico 0e4c4aad59 Make --use-debug-symbols the default 2020-10-21 10:34:34 +02:00
Pietro Fezzardi 05e34ef6f9 Add functions to get installed resource files 2020-10-05 14:09:53 +02:00
Pietro Fezzardi 838ab5b247 CSAA: switch taint sets to SetVector
This makes iteration order deterministic, making bugs due to ordering
easier to reproduce.
2020-10-05 14:09:31 +02:00
Pietro Fezzardi 9fca2ba1e0 CSAA: fix handling of recursion again 2020-10-05 14:09:17 +02:00
Alessandro Di Federico b4c78ad047 libtinycode is now bitcode 2020-10-01 18:17:53 +02:00
Pietro Fezzardi b8e2f85ddd CSAA: fix handling of recursion 2020-10-01 18:17:53 +02:00
Alessandro Di Federico 89651cbde8 revng-lift: fix new module's data layout
We used to hard code a data layout. We now copy it over from the helpers
module.
2020-10-01 17:41:55 +02:00
Pietro Fezzardi 2fc342d2e4 Add a global public Logger: VerifyLog
Rationale: it is a widespread practice, both in revng and in projects
that depend on it, to write verification functions that check specific
properties hold after different transformations on various data
structures.
Often, these verification function are very useful for debugging and
during development, but they can be very costly and we don't want to
always execute them at runtime.

This patch adds a global public Logger, called VerifyLog, that can be
enabled with the --debug-log=verify command line argument.
This Logger is intended to be used in revng and in projects that depend
on it, as a guard for costly calls to verification functions that do not
need to be performed on a typical execution, but only when debugging.

For now the only user is JumpTargetManager, but other uses are already
envisioned.
2020-06-14 23:34:14 +02:00
Pietro Fezzardi 49b3c4b2c9 Upgrade to LLVM 10 2020-06-13 10:36:08 +02:00
Pietro Fezzardi 66873d9c26 Fix legacy::FunctionPassManager initialization and finalization.
This commit adds calls to
`legacy::FunctionPassManager::doInitialization()` and
`legacy::FunctionPassManager::doFinalization()` before and after calls
to `legacy::FunctionPassManager::run()`.

`legacy::FunctionPassManager`s must be explicitly initialized before
running and finalized after running.
Given that we used these managers only in two places and their are the
only ones that need explicit initialization and finalization, we forgot
to do it.

This caused problems with recent versions of llvm.
In particular, when compiled with aggressive optimizations (at least
`-O2`), missed initialization resulted in null pointers being
dereferenced, causing crashes.
The crashes were caused by the compiler optimizing away `nullptr` checks
on values returned from `getPSI`.
2020-06-06 02:25:45 +02:00
Alessandro Di Federico 2e0266ed05 mv {JumpTargetManager,BinaryFile}::nameForAddress 2020-06-02 21:14:56 +02:00
Alessandro Di Federico 3f79683c18 Drop CFG suffix from CFGForm::Values 2020-06-02 21:14:55 +02:00
Alessandro Di Federico 23f1a7b342 Reduce blocks analyzed by AVI
AVI and InstCombine are the bottleneck of the lifting process.
This commit introduces a whitelist of jump targets that are considered
by AVI during harvesting.
The whitelist is initialized by the jump targets that are new with
respect to the last run of AVI. Then, it's expanded with all the jump
targets that can reach the initial set of jump targets through direct
jumps.
2020-06-02 21:14:50 +02:00
Alessandro Di Federico b27beecc0f Preliminary harvesting: s/InstCombine/ConstProp/ 2020-06-02 10:57:02 +02:00
Alessandro Di Federico c202b989af AVI: drop one InstCombinePass
Preparing for AVI we used to run InstCombine twice in the
pipeline. Apparently, this was not acutally necessary.
2020-06-02 10:57:02 +02:00
Alessandro Di Federico 1f7b23bb5a Introduce harvesting statistics 2020-06-02 10:57:02 +02:00
Alessandro Di Federico 773e386f22 Prevent SIGSEGV in translation with guard pages
When translation of code overflows into an unmapped page, we can get a
SIGSEGV. To avoid this, for each set of contiguous pages, we add "guard
page" containing an architecture-specific pattern that ensure basic
block termination.
2020-06-02 10:57:02 +02:00
Alessandro Di Federico d10178483d Introduce the new MetaAddress
Unlike the previous iteration of `MetaAddress`, which tried to stuff all
the parts of `MetaAddress` within the existing `PC` CSV, this
implementation adds a set of new CSVs (or marks some existing ones as) to
represent the four portions of the current PC's `MetaAddress`.

* Introduce `ProgramCounterHandler`: a class responsible to maintain the
  PC-related CSVs. This class is also used to manipulate the new
  dispatcher.
* `AdvancedValueInfo`: update for new MetaAddress.
* External jump handler: do not clobber registers.
  When introducing support for dynamic binaries, we didn't realize that
  in x86-64 we were clobbering `r11`. To avoid this, we have to jump to
  an address stored in memory. However, due to the new `MetaAddress`,
  obtaining a *jumpable* address from the PC-related CSVs might require
  some computations (and it does in ARM). Therefore, we introduce a new
  global variable, `jumpablepc`, whose only role is to contain the
  jumpable version of the program counter and then be the target of the
  memory-indirect jump instruction.
* Labels care only about absolute addresses.
* CSAA: mark call site, even if no accesses.
2020-06-02 10:57:02 +02:00
Alessandro Di Federico 10435feb59 Whitespace and other minor changes 2020-05-14 22:55:18 +02:00
Alessandro Di Federico 89258b832d Add ARM's PCMContextIndex
`PCMContextIndex` is the index of the PC register within the `mcontex_t`
`struct`.
2020-05-14 22:55:18 +02:00