Commit Graph

195 Commits

Author SHA1 Message Date
Alessandro Di Federico 7476eb5cbf MonotoneFramework: allow successors in final BBs
This will be necessary to correctly handle infinite loops.
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 b7b82a55a9 Marker functions: add the function isolation ones 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 52f847a4df IRHelpers: introduce getName(Function *) 2019-03-06 10:31:23 +01:00
Alessandro Di Federico 103df1e46c Backward BFSVisitor: include starting instruction
The `BFSVisitorBase` can go forward and backward starting from a certain
instruction. When going backward, it used to skip the starting
instruction.

For simmetry purposes, this commit changes that.
2019-03-06 10:31:22 +01:00
Alessandro Di Federico 75914742d7 Use BlockType by name in metadata
We used to save the type of a block in the `revng.block.type` metadata
as a number. This commit serializes it as a string.

In order to do this, the `BlockType` enum has been promoted to a
namespace with the usual `getName` and `fromName` functions.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi baa68faaf9 Fix linking erros with librevngSupport.so
`extern` declarations of template specializations for Logger<true> and
Logger<false> caused weak symbols to be emitted in librevngSupport.so
and into its users.
Dynamic loading then failed because both symbols were weak.
This commit removes the `extern` declarations so that dynamic loading
succeeds.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 33a8aeb64c MonotoneFramework: drop greaterThan from Lattices
All the definitions of `greaterThan` were `!lowerThanOrEqual`, and all
the uses were implicitly assuming this semantic.
However, this was confusing because in a Lattice the ordering is not
total, hence `!lowerThanOrEqual` is not equivalent to `greaterThan`.

This commit drops the `greaterThan` method altogether to avoid
confusion.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi db2e4b5bdb Improve interface types for MonotoneSet 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 773b33e5f5 Add InterruptCreator in MonotoneFramework
This commit introduces the helper templated struct InterruptCreator,
that is used to provide defaults for the methods
MonotoneFramework::createSummaryInterrupt() and
MonotoneFramework::createNoReturnInterrupt() whenever the Interrupt
template parameter for Monotoneframework is of type
DefaultInterrupt<LatticeElement>.
This frees the implementor of a new MonotoneFramework from the need
to implement those methods in the most common cases.

Whenever Interrupt is DefaultInterrupt<LatticeElement>,
MonotoneFramework::createSummaryInterrupt() aborts, since a summary
should never be generated for those kind of analyses.
Instead, MonotoneFramework::createNoReturnInterrupt() generates a
default Interrupt, since it will never be used.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 8c49f47f26 Use DefaultInterrupt<LatticeElement> as default
In most cases, a user of MonotoneFramework does not need a
interprocedural analysis, nor an analysis whose results on
terminal labels have to be aggregated in a FinalResults.
DefaultInterrupt<LatticeElement> is designed exactly for those
cases, and is hence used as default template parameter for
MonotoneFramework.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi d16e02a4c4 Add DefaultInterrupt template class
This class provides the simplest possible implementation for an Interrupt
for a Monotone Framework.

In particular this interrupt is suitable for MonotoneFrameworks that are NOT
interprocedural, and that DO NOT need to combine all the results on the
terminal labels at the end of the analysis in a single FinalResult.

With these assumption, the resulting Interrupt is pretty simple and it just
forwards the results of the transfer function.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 186b2d9a07 Rename isReturn method to isPartOfFinalResults 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 08d0722bef MonotoneFramework: remove public typedef LabelRange 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4996a06517 MonotoneFramework: remove method extremalLabels
This method was unused.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi a0cd9664ee Add IntersectionMonotoneSet and UnionMonotoneSet
The MonotoneFrameworkSet class had two sets of methods, one for handling
set operations on it, the other handling lattice ordering.
It also silently assumed that the lattice combine operation was the set
union, which is not true in general.

This commit decouples the set operations from the lattice operations.
This allows to provide two separate implementations of
IntersectionMonotoneSet (for which the compbine operation is the set
intersection) and UnionMonotoneSet (for which the combine operation is
the set union).
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 10d3cfe4b6 Add writeToLog specialization for llvm::StringRef 2019-03-06 09:04:58 +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 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
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 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 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 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 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 dee2cf0d04 Reimplement the reaching definition analyses
This commit reimplements the (conditional) reaching definitions passes
as an instance of a monotone framework.

The `ConditionNumberingPass` has also been reworked in the way it
exposes its results, but it's otherwise unchanged.

A proper unit testing framework is also available to ensure everything
works as supposed to.
2018-10-16 17:39:22 +02:00
Alessandro Di Federico b6ee8480da Extend MonotoneFrameworkSet
This commit simply adds a couple of handy methods to
`MonotoneFrameworkSet` such as `begin`, `end`, `erase`, `erase_if`,
`contains` and `size`.
2018-10-16 16:55:12 +02:00
Alessandro Di Federico f305541d5e Introduce MonotoneFramework::handleEdge
In a `MonotoneFramework` it is sometimes necessary to change the
information propagated on a branch w.r.t. another branch.

This commit introduces the `handleEdge` function that allows
`MonotoneFramework` implementors to modify the `LatticeElement` produced
by `transfer`.
2018-10-16 16:52:24 +02:00
Alessandro Di Federico 873dd13dd5 Introduce dumpModule
`dumpModule` is a debug function that can be called from GDB to dump a
`Module *` to a chosen path.
2018-10-16 16:51:52 +02:00
Alessandro Di Federico e80b05a48e Move MonotoneFramework.h to libSupport
`MonotoneFramework.h` has been moved into `include/revng/Support` so
that it can be employed by components outside `libStackAnalysis`.
2018-10-16 16:25:29 +02:00
Alessandro Di Federico cc02713f6d Abandon argparse in favor of LLVM's CommandLine
This commit dismisses the `argparse` library (the only non-runtime C
component of rev.ng) in favor of LLVM's CommandLine library, which
offers several benefits. Among others, now command line arguments can be
easily specified as a global variable, decentralizing their management
and avoiding the long list of arguments in the constructor of singleton
objects such as `CodeGenerator`.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico 43cf36bfce Introduce revng_log and abandon DBG(...)
This commit introduces `revng_log`, a macro analagous to `revng_assert`,
which basically allows to have the benefit of the `Logger` class without
having to compute the expression to log if the logger is disabled.

This commit also completely dismisses the `DBG` macro, converting all
the old code to `Logger` + `revng_log`.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico cf8d6d530e Whitespaces and other minor fixes 2018-10-03 23:11:12 +02:00
Alessandro Di Federico 076aeac7f3 Move and rename all files
This commit moves around most files. The new directory structure is as
follows:

* `lib/$LIBRARY/`: contains a library, i.e., a set of `.cpp` files used
  by multiple libraries/tools.
* `include/revng/$LIBRARY/`: contains the public headers associated to
  the library in `lib/$LIBRARY/`.
* `tools/$TOOL/`: directory where all the `.cpp` files (and private
  headers) for a tool reside. Currently we have two tools: `revamb` and
  `revamb-dump`.

On top of this, all file names are now in camel case.
2018-10-03 23:11:12 +02:00