Commit Graph

233 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 1e5fd5cc25 BinaryFile::readRawValue: prevent invalid reads
It might happend that, while parsing an input binary, we are request to
read at a valid address, but a for a size leading outside of a valid
page.

This commit, copies as much data as possible from the valid page into a
temporary buffer of the appropriate size, and then performs the read on
that temporary buffer.
2020-05-14 22:22:31 +02:00
Alessandro Di Federico 429567b885 Handle binaries without ELF program headers
Not all binaries have ELF program headers, e.g., Mach-O binaries.
2020-05-14 22:22:31 +02:00
Alessandro Di Federico 20d346aaf7 Fix handling of Mach-O LC_UNIXTHREAD 2020-05-14 22:22:31 +02:00
Alessandro Di Federico 9cfb96c18c Run InstCombine on generated code
We now run InstCombine on the generated code in order to simplify
further analyses. In particular this is useful to handle code such as
the following:

    %pc = load @pc
    %is_thumb = and %pc, 1
    %address = and %pc, ~1
    %pc2 = or %is_thumb, %pc

After InstCombine `%pc` and `%pc2` are collapsed.
2020-05-14 11:59:05 +02:00
Pietro Fezzardi 1c02dfd2a5 CSAA: strip bitcasts on pointers to env 2020-05-14 11:59:02 +02:00
Alessandro Di Federico dc48188f37 Introduce MetaAddress
`MetaAddress` replaces all the `uint64_t` used to represent a virtual
address. Its main features are:

* It has a non-zero representation of invalid addresses.
* It supports tags to represent code that has different interpretations but
  resides at the same address in memory (namely ARM vs Thumb).
* Arithmetic operations cannot overflow.
* It supports epochs, a way we intend to employ to handle self-modifying code
  (i.e., different code at the same address at different times).
* It supports "address spaces", which enable handling architectures with
  multiple address spaces.
* It fits in two 64-bit registers.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 58a070349b Fixes in handling DWARF information 2020-05-14 11:58:18 +02:00
Alessandro Di Federico 35171a789d Sort translated basic blocks in reverse post-order
After translation, `revng-lift` now sorts all the basic blocks in
reverse post-order to ease manual reading of the generated modules.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 20c367b88f Add ArchitectureName to revng.input.architecture 2020-05-14 11:58:18 +02:00
Alessandro Di Federico da9e6094d3 Introduce Label::hasValue 2020-05-14 11:58:18 +02:00
Alessandro Di Federico cb803dce70 BinaryFile::parseELF: fix labels creation
The loop creating the labes in `BinaryFile::parseELF` was badly indent
and resulted in the creation of labels only if the `.dynamic` section
was available.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 72fc95bda9 Purge OriginalInstructionAddresses when deleting
`JumpTargetManager::purgeTranslation` deletes some basic blocks that
need to re-translated, however references to some instructions remained
in `OriginalInstructionAddresses`.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 8deab9c7ea Whitespace and other minor changes
* Drop unused argument names from function prototypes
* Make `static` some methods
* Disable some copy constructors
* Fix casing of Doxygen `\file` directives
* Add some casts to make the compiler happy
* Initialize `hasRelocationAddend` for AArch64
* Use references in range-for where possible
* Drop default for `switch` statements covering all the entries of an `enum`
* Make some global variables `static`
* Drop dead functions
2020-05-14 11:58:18 +02:00
Alessandro Di Federico c1a768ff21 Drop InstructionTranslator::ForceNewPC
It was a leftover for a problem (marking post-helper addresses as jump
targets) that we appear to have solved in another way.
2020-03-02 12:38:01 +01:00
Pietro Fezzardi 5d0f5fef71 Drop TransformIterator
LLVM already implements an analogous `mapped_iterator` type in
`STLExtras.h` header.  `llvm::mapped_iterator` has been used to
substitute `TransformIterator` in the project so that we don't need to
reinvent the wheel.
2020-02-27 12:28:28 +01:00
Andrea Gussoni 2896664cab JTM::readFromPointer: handle ConstantNullPointer 2020-02-27 11:57:34 +01:00
Pietro Fezzardi ae948500eb Move LLVM header where it's really needed
Before this commit, the header `revng/Support/DebugHelper.h` could only
be included after explicitly including
`llvm/IR/AssemblyAnnotationWriter.h`, since `DebugHelper.h` used the
LLVM class `AssemblyAnnotationWriter`, that is not defined in
`DebugHelper.h`.

This commit includes `llvm/IR/AssemblyAnnotationWriter.h` directly into
`revng/Support/DebugHelper.h`, which can now be included alone without
compilation errors.
2020-02-27 10:47:07 +01:00
Alessandro Di Federico b6658df052 Fix various warnings 2019-11-24 22:52:23 +01:00
Alessandro Di Federico 229a93367c Switch to C++20 2019-11-24 22:47:06 +01:00
Alessandro Di Federico 7b2744f0ab Register ModuleAnalysisManager in new PassManager 2019-11-21 23:35:42 +01:00
Alessandro Di Federico ae8da14d46 Adopt FunctionCallee
`getOrInsertFunction` in LLVM 9 now returns `FunctionCallee`.
2019-11-21 20:52:55 +01:00
Alessandro Di Federico 0eb1bb583f Remove TerminatorInst
LLVM 9 drops the `TerminatorInst` class. This commit replaces it with
`Instruction` where possible and asserts
`Instruction::isTerminator()`. It also switches from
`TerminatorInst::successors` to `successors(TerminatorInst *)`.
2019-11-21 20:50:55 +01:00
Alessandro Di Federico 8d664c1588 Fix RPATHs
This commit replicates the structure of the install directory into the
build directory in order to simplify the management of RPATHs.

This commit also drop `QEMU_INSTALL_PATH`.
2019-09-04 11:52:07 +02:00