Commit Graph

465 Commits

Author SHA1 Message Date
Alessandro Di Federico 885d705938 FunctionIsolation: handle nullptr and undefs 2020-05-14 21:59:04 +02:00
Alessandro Di Federico 2531cc3c60 The link register has to be an ABI register
This is to prevent the PC (or similar CSVs) from being considerate as a
link register.
2020-05-14 11:59:05 +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 e336a33545 Move GCBI::getPC to IRHepers.h 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 a52fb24e02 Various improvements to StackAnalysis
* Ignore casts in `BasicBlockState::get`
* Fix some types
* Do not move `Element::bottom()`
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 78dafb04da IFI::cloneInstruction: handle ConstantAggregate 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
Alain Carlucci 469ef9cae8 Rename emit to flush in Debug.h
The `emit` keyword is used in Qt and, if the method is called `emit`,
rev.ng headers cannot be included in a Qt project.
2020-02-27 12:12:25 +01:00
Alessandro Di Federico b6658df052 Fix various warnings 2019-11-24 22:52:23 +01:00
Alessandro Di Federico cd41d055f4 DIBuilder::createFunction now takes SPFlags 2019-11-21 23:34:25 +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 25ede62813 Link librevngSupport to libLLVMSupport 2019-09-04 11:52:07 +02: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
Alessandro Di Federico e445201b94 Restore getBasicBlockPC and fix FunctionIsolation
This commit restores the old implementation of `getBasicBlockPC` (which
was changed in an incompatible and wrong way) and fixes the bug the
original change tried to fix: in function isolation, jumping from a
function to a basic block that doesn't start with `newpc` now leads to a
basic block containing an `unreachable`.
2019-05-28 17:03:30 +02:00
Alessandro Di Federico 9eb3cfd06a FunctionIsolation: update PHINodes
This commit improves the function isolation pass to fix references to
predecessor basic blocks in phi nodes.

The commit also improves handling of instruction operands to ensure no
unmapped Values are used.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 8d009296ef FCI: ignore non-translated basic blocks 2019-05-27 19:36:12 +02:00
Andrea Gussoni 9f97826806 raise_exception_helper calls exception_warning
The call to `exception_warning` in `support.c` is now performed
directly by the `raise_exception_helper` function defined in
`support.c`, so that we can avoid calling two different functions in the
translated and isolated module.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 53df3086ce FunctionIsolation: do not remove anypc and friends 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 357d88377d EnforceABI: Killer branches are noreturn 2019-05-27 19:36:12 +02:00
Alessandro Di Federico c232e20be8 s/func.entry/revng.func.entry/ leftover 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 7815c551db Support for file names in Logger
`Logger` can now print the file name from which it was called
(`--debug-location-max-length`).
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 5009074e9e Introduce AdvancedValueInfo for JT discovery
* Introduce `ShrinkInstructionOperandsPass`: a transformation shrinking
  operands and the results of instructions if they are
  zero/sign-extended immediately before and after the instruction.
* Introduce `ConstantRangeSet`: similar to `ConstantRange` but allows
  disjoint ranges.
* Introduce `MaterializedValue`: a class that can represent a constant
  value or a symbol plus offset pair.
* Introduce `DropHelperCallsPass`: a transformation removing calls to
  helpers and replacing them with a function call reading the CSVs that
  the helper reads and writing the CSVs that the helper writes
  (according to CSAA).
* Introduce `DropRangeMetadataPass`: a transformation dropping the
  `range` metadata, which, in certain situations, lowers the quality of
  the results provided by `LazyValueInfo`.
* Introduce `AdvancedValueInfo`: an analysis exploiting results of
  `LazyValueInfo` but collecting them as `ConstantRangeSet` with a
  monotone framework. It produces `MaterializedValue`.
* Anticipate linking of helpers: `AVI` requires `CSAA`, which requires
  helper functions to be linked in.
* Drop `--no-link`.
* Force x86-64 `DataLayout`.
* Reorganize harvesting to either collect simple literals or go with
  (incremental) `AVI`.
* Drop `SET`, `OSRA`, the reaching definition analysis, the
  `SimplifyComparisonsPass` and all the sumjump-related code: e now
  clone `root`, optimize it and analyze it with `AVI`.
* Temporarily drop the `NoReturnAnalysis`.
* Link `libLLVMInstCombine`, `libLLVMCodeGen` and `libLLVMPasses`.
* Introduce tests for `AdvancedValueInfo`,
  `ShrinkInstructionOperandsPass` and `ConstantRangeSet`.
* Fix test results.
* Add `llvm.bswap.i64` and `@pc` to the LLVM template module for unit
  tests.
2019-05-22 21:30:29 +02:00
Alessandro Di Federico c8998cdece StackAnalysis: election of return SP value
Any stack pointer value greater than or equal to the original one used
to be OK for stack analysis to recognize an instruction as a
return. This commit changes this policy by collecting the value of the
stack pointer on all the return points and, at the end, elect a final
stack pointer value. All non-compliant returns are marked a
`BranchType::BrokenReturn`. The function is now considered fake only if
all the return instructions agree on a specific value of the stack
pointer, and it's lower than the original one.

* Drop `BranchType::IndirectTail`.
* `s/BranchType::FunctionSummary/BranchType::RegularFunction/`.
2019-05-22 21:30:29 +02:00
Alessandro Di Federico a9de053243 Introduce GraphAlgorithms
A series of algorithms working on `llvm::GraphTraits`.

* `nodesBetween` computes the set of nodes on all the paths from a node
  A to B.
* Factor out code to iterate over infinite loops into
  `exitless_scc_range`.
* Introduce unit tests.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico b7ce437469 EnforceABI: completely ignore the stack pointer 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 09cf8ecfbc StackAnalysis: fix bug involving EmptyCallSummary 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 0e9d453be3 ZipMapIterator changes
* Introduce `KeyContainer::compare` and drop the `getKey` method.
* Let users of ZipMapIterator specify a trait class instead of using the
  default one.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico 6ae3b6f22f Whitespace and other minor changes
* `GeneratedCodeBasicInfo::getCSVUsedByHelperCall` and
  `GeneratedCodeBasicInfo::extractCSVs`: make the call argument an
  `Instruction`.
* Introduce `blockByName`
* Introduce `getUniqueUser`.
* Fix linking issues.
2019-05-14 16:27:13 +02:00
Andrea Gussoni 616c162523 DotGraph and DotNode
This commit implements a simple wrapper class able to parse a GraphViz
file in an object implementing the LLVM `GraphTraits`.
2019-04-22 05:40:27 +02:00
Alessandro Di Federico d50fbe969a Update documentation and add revng. to metadata 2019-04-11 19:51:32 +02:00
Alessandro Di Federico d77ad08917 Drop leftover references to revamb 2019-04-11 17:44:39 +02:00
Pietro Fezzardi 76135b76fb Add RemoveDbgMetadata FunctionPass 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 28ceefcac3 SA: unify management of CSV indices 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 489e4b1d87 ABI analysis: ignore non-CSV used by helpers 2019-03-08 15:00:59 +01:00
Alessandro Di Federico c2d39fb702 SA: reorganize the way functions are registered 2019-03-08 15:00:59 +01:00
Alessandro Di Federico baef567365 ABI: ECSR are not "No" for function calls
Register marked as explicitly callee saved in a function used to be
marked as No both for the current function and all of its function
calls. However, the latter action is not accurate.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 9b070d8856 SA: use deque were appropriate
In certain locations we were using a `std::vector`, taking a reference
to it, adding elements and ending up in a reference invalidation issue.

This commit replaces those `std::vectors` with `std::deque` which do not
present this issue.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 05d16b6470 ResultsPool::dump: consider call sites too 2019-03-08 15:00:59 +01:00
Alessandro Di Federico fcb5315b7d Bug: FunctionABI::copy ignored a field 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 9925243398 Handle infinite loops in ABI analysis
The ABI analysis used to ignore actions happening in CFG-level infinite
loops due to the fact that they had no exists. This commits detects
infinite loops and marks certain nodes as exits.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 467d916aac Ignore pc and sp in ABI analysis
They are not really part of the ABI.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico e73def0c31 Register additional metadata in isolated functions
This commit reorganizes a bit the function isolation pass and, in
particular, copies over the `func.call` and `member.type` metadata.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 5dc8056b8c Introduce enforce-abi pass
This commit introduces the `enforce-abi` pass, which consumes the
information provided by the ABI analysis and enforces them in the
isolated functions adding actual arguments.

This commit also rewrites the logic of `ResultsPool::finalize` and
changes the semantic of `Yes` statements on arguments to `YesOrDead`.
2019-03-08 15:00:59 +01:00
Alessandro Di Federico 2bd8c468bc Introduce empty-newpc pass
`empty-newpc` is a simple pass suppose to provide an empty body for
the `newpc` function, allowing further optimization pass to take out
all its calls.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico 0fa2d79fe4 Introduce ZipMapIterator
`ZipMapIterator` allows you to iterate in parallel over two
`std::map`-like containers.

In the ABI analysis, this allows us to be much more efficient. In
practice, if we have two maps with M and N elements, we pass from
performing N*log(N) + M*log(M) queries to the size of the union of the
set of keys of the two maps.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico 4d08f9793a ABI analysis: ignore non-ABI registers
Considering non-GPRs slows down the analysis and deteriorates the
results.
2019-03-06 10:31:23 +01:00
Alessandro Di Federico b232678477 GCBI: collect and expose ABI registers 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 3a127dc7b3 ABIIR: add GraphTratis<Inverse<>> and iterators 2019-03-06 10:31:23 +01:00