Commit Graph

1642 Commits

Author SHA1 Message Date
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 57693f3653 NRA: compute PredecessorsMap internally 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 cb2bd9a3ce IRHelpers: introduce getCallToHelper 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 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 4076fbc8cd revng script: use -load and debugging options
Due to `opt` loading multiple times the same library, we had to switch
to `LD_PRELOAD`. However, this is suboptimal. This commit goes back to
use the `-load` flag but excludes the libraries that are dependencies of
other libraries. This requires parsing the ELF but it's a more neat
solution.

In addition, several shortcuts for popular debugging tools (namely,
`gdb`, `valgrind`, `callgrind`, `heaptrack` and `perf`) have been added
to the root command.
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
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 3d71147cbc FunctionIsolation: fix fake returns bug
The `cloneInstruction` did not stop when a fake return instruction is
met.
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 2d521285bb Handle helper functions in StackAnalysis
In the stack analysis, we used to consider helper functions as indirect
calls. However, the `CPUStateAccessAnalysis` provides us accurate
information about what an helper function does.

This commit transforms calls to helper functions in a series of ABI IR
instructions reading all the input registers of the helper functions and
a series of instructions writing the output registers.

Note that, while this is a serious improvement over considering them
indirect function calls, it's still suboptimal since
`CPUStateAccessAnalysis` doesn't provide us information as fine-grained
as the ABI analysis.
2019-03-06 10:31:19 +01:00
Alessandro Di Federico a61c744bd8 CSAA: fix bug leading to ignore stores 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 17b1eb19a9 Introduce revng.csv for listing CSVs
Previously, to enumerate all the CSVs we had to go through the
`GlobalVariable` of a `Module` and see if the were being used in
rev.ng-generated code.

Now we have a named metadata for that: `revng.csv`.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 82412a5a05 CSAA: use GlobalVariable *, not names
The CPUStateAccessAnalysis used to record its results in terms of the
names of GlobalVariable, however, metadata can be constants, and,
specifically, `GlobalVariable`.

This commit serializes the results as references to the `GlobalVariable`
object instead of using their names.
2019-03-06 09:04:58 +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
Alessandro Di Federico ed43c2b84a func.entry: add an address field 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 45172f52d9 LazySmallBitVector: introduce operator<
`LazySmallBitVector` was lacking a comparison operator, which prevented
it from being used as the key of a `std::map`.

This commit implements such operator, along with the `reserve` method.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 7db7309987 SA: Trunc is not identity
In the intraprocedural analysis of the stack analysis we implemented the
transfer function of the `Trunc` instruction as the identity function
(just as `PtrToInt` or `ZExt`). However this is not safe since `Trunc`
loses information. This lead to incorrect results in the ABI analysis.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi e999665ff2 Remove unreachable blocks from isolated functions 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4fc4531403 Use nullptr instead of NULL for pointer constant 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 50dd2b7b11 Remove buildEmptyExecutableSegmentList method
ExternalJumpsHandler::buildEmptyExecutableSegmentLIst() was used to
initialize an empty lists of segments for targets that did not
support dynamic libraries.
However, having an empty segment list triggered assertions in the
handling of jumps to invalid jump targets providing misleading error
messages on the segments_count that were hiding the real cause of the
error (unknown pc, invalid jump target).
This commit properly initializes the segment list to avoid the
misleading assertion messages
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
Pietro Fezzardi f4603dc10c Add operator[] and at() members to SmallMap 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4122f76a27 Avoid useless constructor 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 6f77c27e9f CRDP: avoid useless std::move 2019-03-06 09:04:58 +01:00
Pietro Fezzardi ba433e60a0 Fix check on static in check-conventions.sh
Now the `static` keyword in headers is considered an error only if it's
followed by a whitespace.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico e6928e34c1 Minor changes 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 72c34efc57 revng_add_analyses_library: add EXPORT_NAME 2019-02-22 11:36:36 +01:00
Alessandro Di Federico a75c75c305 Make install_pattern available in CMake package 2019-02-22 11:33:28 +01:00
Alessandro Di Federico 94a99fe57c Force linking of all the original libraries
Certain libraries linked to the input executable sometimes are not
required by the executable or other dynamic libraries. Therefore, the
`ld -l` switch ignores them.

This commit forces linking of all the required libraries, no matter
what, by wrapping the list of dynamic libraries in `-Wl,--no-as-needed`
and `-Wl,--as-needed`.
2019-02-19 18:23:29 +01:00