3016 Commits

Author SHA1 Message Date
Andrea Gussoni c88ccdff43 Fix include guards
Fixed some include guards in the header files of the imported libraries,
which where missing or not conform to the convention.
2019-01-28 18:54:10 +01:00
Andrea Gussoni e5187a61d9 Use new DominatorTree update features
Instead of rebuilding the dominator and postdominator at each iteration
of the inflate procedure, use the utilities introduced in LLVM 7.0 to
keep the data structures updated after each change to the RegionCFG.
2019-01-28 15:13:25 +01:00
Pietro Fezzardi 20a336344e Add state variable info to dummy BasicBlockNodes 2019-01-25 18:36:37 +01:00
Andrea Gussoni c70b6f1097 Implemented de-optimization on RegionCFGTree
Now, during the simplification of short-circuits the so called
`de-optimization` is also applied to the corresponding `RegionCFGTree`.

This allows us to avoid loss of information during the iterative
refinement phase, which basically divides for ever the existencies of
two nodes that have been cloned starting from a single original one.
2019-01-25 13:45:03 +01:00
Andrea Gussoni 05d736cbb1 AST serialization is now performed on file
We now perform the AST serialization directly on file, without using
stderr. In this way we can follow the evolution of simplifications and
changes to the AST tree.
2019-01-25 13:35:20 +01:00
Andrea Gussoni 7de353785e Implemented conditional node list for IfNode
After short-circuit simplification, we can have that a conditional node
corresponds to more than one `BasicBlockNode`.

This change reflects this fact, and takes care of merging blocks during
short-circuit simplification, and of representing this change in the
serialization.
2019-01-25 13:32:29 +01:00
Andrea Gussoni d591ae13e6 Improved serialization of graphs during inflate
Improved the `dumpOnDotFile` function to take as a parameter also a
sub-folder name.

Modified the `inflate` function to dump on file the graphs after each
modification.
2019-01-25 13:32:28 +01:00
Pietro Fezzardi f5fcc4aa24 Completely redesign ownership model for RegionCFG 2019-01-25 13:13:35 +01:00
Pietro Fezzardi 6ef68f2ca2 Remove unused headers 2019-01-23 17:03:17 +01:00
Andrea Gussoni 578772ddb4 Fix isDummy for ASTNode
Now the `isDummy` method is invoked on the underlying `CFGNode` only
when we actually have a corresponding node.
2019-01-22 19:16:48 +01:00
Andrea Gussoni 9876e514d5 Improved isEqual operator with deep comparison
Now the `isEqual` operator does what we call a `deep` comparison,
meaning for every type of `ASTNode` it recursively check if the
structures of the AST tree originating in that node can be considered
equivalent (e.g., two sequence nodes are considered equal if every node
they contain is in turn equal).

This operator gives more space to the short-circuit simplification,
which relies heavily on the `isEqual` operator.
2019-01-22 19:16:48 +01:00
Andrea Gussoni 05a5d80151 Short-circuit simplification concept
First concept of short-circuit simplification.
The `isEqual` operator between ASTNodes is very limited (it does only
check if two nodes originate from the same `BasicBlock` in the original
IR.
2019-01-22 19:16:48 +01:00
Andrea Gussoni a540a08c38 Added RemovePCStores pass
Added a new pass that simply purge all the functions in a module from
the useless basic blocks that simply do the `pc` serialization.

Without this until we have available the optimization/comb iterative
refinement, we would not be able to test the short-circuit
simplification.
2019-01-21 18:28:48 +01:00
Alessandro Di Federico a2b30ceb42 Update FunctionIsolation to use the new FBDP
This commit updates the function isolation transformation to handle the
metadata as provided by the new `FunctionBoundariesDetectionPass`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 2e241acae3 Introduce SA-based ABIDetection and FBD passes
This commit drops the old FunctionBoundariesDetectionPass and introduces
a new one based on the results provided by the StackAnalysis. A very
similar pass, the ABIDetectionPass, is now available to offer the
results of the ABI analysis too.

These two new passes are a thin shim depending on the appropriate
version of the StackAnalysis (with or withour ABI anlysis) and simply
call `serializeMetadata`, which decorates the LLVM IR with the requested
information.

In addition to drop the old analysis, this commit also isolates the
function boundaries detection pass from `revamb` making it available as
a library only.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 7a045d0c0d Drop revamb-dump in favor of plain passes
This commit does the following:

* It drops `revamb-dump` and transforms all the passes it featured in
  passes that can be used directly from `opt`.
* It rename `revamb` to `revng-lift`.
* It introduces a script called `revng` which acts as a driver for the
  whole rev.ng project. It replaces `translate`, `revcc`,
  `csv-to-ld-options` and `revamb-dump`, since it offers an `opt`
  subcommand which allows to easily invoke all the analysis passes.
* It makes the project a CMake package that can be easily used
  externally.
* It allows to easily create libraries of analysis to use through
  `revng-opt`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 25bf160910 Improve detection of stack alignment in SA 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 05b1833ee6 Add ExternalJumpsHandlerBlock to BlockType 2019-01-18 15:18:47 +01:00
Alessandro Di Federico ef708e9912 Let --debug-log work without main involvement 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 9985ff5fb6 Drop const in FunctionsSummary-related code 2019-01-18 15:18:47 +01:00
Alessandro Di Federico e9b4b8edf1 Use stack analysis in RDA
This commit lets the reaching definitions analysis employ results from
the stack analysis to propagate definitions across functions
calls. Specifically, the stack analysis provides a list of registers
that might be clobbered by the callee: definitions concerning those are
not propagated, all the others are propagated.

This change is key to detect jump tables whose address has been
materialized *before* a function call. A test for such situation has
been introduced.

To make this work, the RDA now works over the CFG provided by the
function identification analysis.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 98c99e9406 Make StackAnalysis::getClobbered const 2019-01-18 15:18:47 +01:00
Alessandro Di Federico bd09716534 FCI: provide a custom CFG
The `FunctionCallIdentification` analysis now provides a custom view on
the CFG where 1) dispatcher-related basic blocks are absent, 2) nodes
performing functions calls have an edge to their return address and 3)
nodes ending with a return instruction have no successor.

This CFG is now employed by the reaching definitions analysis and OSRA.

Additionally, the implementation of the `visitSuccessors` and
`visitPredecessors` method has been reviewed. It now consists in a class
that needs to be inherited and for which two methods should be
implemented, one to perform the visit of a block and another one to
enumerate the successors.

In addition, all the users of `visitSuccessors`/`visitPredecessors` have
been updated, a simple set of tests has been introduced and
`GeneratedCodeBasicInfo::visitPredecessors` has been dropped.
2019-01-18 15:18:46 +01:00
Andrea Gussoni 659441eb85 Introduced useless dummy simplification
Added a post processing phase on the ASTTree which is in charge of
removing useless dummy nodes
2019-01-17 17:19:08 +01:00
Andrea Gussoni b08da2c045 Serializing CFGs to file 2019-01-17 17:05:10 +01:00
Pietro Fezzardi da299f3095 EnforceCFGCombingPass: inject dummy nodes in CFG 2019-01-16 12:53:08 +01:00
Pietro Fezzardi dc430e446b RegionCFGTree.h: add missing #include<set> 2019-01-15 16:57:15 +01:00
Pietro Fezzardi 5805679ead RestructureCFGPass: fix use of include directory 2019-01-15 16:57:15 +01:00
Pietro Fezzardi 4e941de03a LivenessAnalysis: fix successor_size method 2019-01-15 12:54:19 +01:00
Pietro Fezzardi 68425a71ca Use consistent naming in include guards in headers 2019-01-15 11:19:59 +01:00
Pietro Fezzardi a478de61e5 Create a separate include directory 2019-01-15 11:19:59 +01:00
Alessandro Di Federico 7ead8d68cc Collect simple literals (return addresses) as JTs
This commit fixes a problem that led to use SET to discover very very
simple jump targets: the return addresses of functions call.

Since in this situation, for each call, we needed to run SET, this
commit leads to a *huge* improvements in terms of translation
performance.

This commit also enforces renaming of the translated basic blocks after
they get split and update the ground truth for several analysis tests.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico 9ce805415b Improve Reaching Definitions Analysis
The Reaching Definitions Analysis used to ignore all the memory access
that were not relative to a CSV or an `alloca`. In certain situations,
in particular in x86 which makes heavy use of the stack, this led to
miss certain links that were vital for a correct identification of
certain jump targets.

As an example consider the following example:

    cmp    DWORD PTR [rbx+0x8],0x5
    ja     4bc5c8 <uw_update_context_1+0x148>
    mov    eax,DWORD PTR [rbx+0x8]
    movsxd rax,DWORD PTR [r12+rax*4]
    add    rax,r12
    jmp    rax

The constaint on `rbx+0x8` is not propagated to the use after the jump,
due to a missing link.

This commit fixes this by tracking all the memory accesses within the
expressive power of the `MemoryAccess` class, in particular those
expressed as register plus offset.

Additionally, this commit also makes RDA consider as reaching
definitions for a `load` only those definitions that match exactly the
load address, while previously we were considering all the `mayAlias`
definitions. This situation, in combination with the previous change,
led to have paths with multiple reaching definitions, which was
problematic for the path sensitive merge.

Finally, we consider a definition to be clobbered only if there's an
exact store to the esame address, instead of a store on an aliasing
address.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico ef2d16db15 Install headers and libraries 2018-12-15 08:34:36 +01:00
Alessandro Di Federico ac5dea43b4 Reduce exceptions thrown (e.g., due to tail calls)
In function isolation, every time we met a jump to an unexpected basic
block (i.e., a basic block that is not part of the current function), we
used to throw an exception. However this is unnecessary since oftentimes
it is sufficient to call the `function_dispatcher` or even perform a
regular function call.

The most obvious example is the case of a direct tail call. In this
situation performing a function call to the corresponding isolated
function is the most appopriate thing to do.
2018-12-15 08:34:36 +01:00
Alessandro Di Federico d4b8fe847d GCBI: use getBlockType in isTranslated 2018-12-13 18:03:11 +01:00
Alessandro Di Federico a43fad370f GCBI: introduce the EntryPoint BlockType
`getType` didn't have a `BlockType` to represent the entry basic block
of the `root` function. Therefore, such basic block was erroneously
identified as a translated basic block.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 4f64816ac3 GCBI::getFunctionCall: skip markers
`GCBI::getFunctionCall` used to stop to the first marker function call,
instead of going through all of them looking for `function_call`.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 0c9945c2d0 Introduce QuickMetadata::get() 2018-12-13 18:03:11 +01:00
Alessandro Di Federico bba5bdf4fb Use std::iterator_traits in IteratorWrapper
Using `std::iterator_traits` allows `IteratorWrapper` to be employed on
pointers too.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 371c38d6b8 Add nodce to the list of marker functions 2018-12-13 18:03:11 +01:00
Alessandro Di Federico 5cc504e117 Whitespace and other minor changes 2018-12-13 18:03:11 +01:00
Alessandro Di Federico e21eed118c Tag function_call targeting external symbols
This commit uses SET, information about canonical values and labels to
detect if an indirect function call is targeting an external symbol.

The strings used for the name of external symbols are uniqued global
variables. This commit also uses this approach for the disassembly of
original instructions, which used to be metadata.
2018-11-15 16:03:09 +01:00
Alessandro Di Federico abb47bb964 Minor changes 2018-11-15 08:48:26 +01:00
Alessandro Di Federico cc4dfbce4c Introduce labels, relocation and canonical values
So far we've been tracking only base-relative relocations in an ad-hoc
fashion. This commit introduces a data structure that can describe the
most common relocations, including those for `.got`, `.got.plt`,
base-relative and `R_*_COPY`.

A label describes a range of the binary. A label can be generated from a
symbol (basically assigning a name to range of the binary) or from a
relocation, describing the content of a certain range.

This commit generates labels from symbols and relocations, including
MIPS implicit relocations.

This commit also introduces canonical values.

A register can have a canonical value, i.e., a value that register will
assume when the analyzed module is being run. This is typically useful
for the value of the global pointer, which is different from one module
to another but, within a module, is stable.

This commit registers the canonical value of `gp` (in MIPS), if
available.
2018-11-15 08:48:26 +01:00
Alessandro Di Federico 6748032643 Extend FCI interface to identify function calls 2018-11-14 14:41:25 +01:00
Alessandro Di Federico 9606c8df35 QMD: add 64 bits ints 2018-11-14 09:34:49 +01:00
Alessandro Di Federico 09b9fbba39 Drop trailing semi-colon in messageless assertions 2018-11-14 09:34:49 +01:00
Pietro Fezzardi b9273210d0 Update to LLVM 7
Updating to LLVM 7 mainly involved the following steps:

* Upgrade APIs for folding ConstantExpr.
* Upgrade APIs for GraphTraits.
* Upgrade APIs for DominatorTreeBase.
* Upgrade APIs for BinaryFormat to parse ELFs.
* Fix the LLVM Linker to properly link the QEMU helpers.
* Disable the new optnone attribute even with optimization -O0. This is
  necessary to allow SROA to do its job properly.
* Upgrade APIs to delete Instructions.
* Properly cleaning up orphaned metadata still referring to Instructions
  that have been destroyed. Recent versions of LLVM are more strict in
  this respect, and will assert when compiled in debug.
* Avoid using LLVM `getGlobalContext` which has been removed from newer
  versions of LLVM.
* Upgrade tests to use the new APIs.
* Upgrade APIs for instruction iterators and reverse iterators.
2018-11-13 18:11:05 +01:00
Alessandro Di Federico b34a421ec4 getResetColors: return nullptr when appropriate
A method in RDA was returning nullptr when a basic block *had* a color
and a dangling reference when it did not.
2018-10-24 17:21:57 +02:00