Commit Graph

6113 Commits

Author SHA1 Message Date
Andrea Gussoni f4f877c569 Change SetNode interface 2019-04-15 10:05:17 +02:00
Andrea Gussoni 1c66c145cb RegionCFG::initialize method now template
The `RegionCFG::initialize` method is now a template method, which
accepts as input any kind of object which exposes the `GraphTraits`.

In this way we can build a `RegionCFG` object not only starting from
LLVM IR, which can be very useful for testing purpose.

Since we also removed the information about the original
`llvm::BasicBlock` inside the `BasicBlockNode`, we need to keep this
link to later feed this information to the GHAST in an external data
structure (potentially a `std::map`).
2019-04-15 10:04:40 +02:00
Andrea Gussoni afbb3531f5 Name of the BasicBlockNode is now a StringRef
The `Name` field of the `BasicBlockNode` class is now of
`llvm::StringRef` type instead of a simple `std::string`.
2019-04-15 10:03:08 +02:00
Andrea Gussoni 2c3056527d Remove any pointer to BasicBlock inside BBNode
The `BasicBlockNode` does not contain anymore any pointer to the
`llvm::BasicBlock` object that generated the `BasicBlockNode`.

This change is necessary for decoupling completely the `BasicBlockNode`
and `RegionCFG` classes from the LLVM IR, so that we can build up a
`RegionCFG` from any object which implements the `GraphTraits`.

The `RegionCFG` does not contain anymore a map between
`llvm::BasicBlock` and `BasicBlockNode`.
2019-04-15 10:03:08 +02:00
Andrea Gussoni e9f2b4239a Remove backedges refresh 2019-04-14 20:16:51 +02:00
Alessandro Di Federico 2f2b1f6ffe revng script: wrap executables 2019-04-12 19:17:23 +02:00
Pietro Fezzardi 743b2e522c Fix switches with empty cases 2019-04-12 18:25:15 +02:00
Andrea Gussoni e8b59c2ff0 Update Backedges instead of refreshing it
Once we compute the set of backedges, they should be fixed and should
not change during the restructuring phase, otherwise we may end-up
inserting loops including outlined node if the information about the
backedges changes completely during the analysis (edge that were
backedges and for which a corresponding SCS was computed become forward
edges, and viceversa, and this behaviors break our assumptions that
outlined node do not take part in loops ever).

This means that we need to keep updated the set of backedges computed at
the beginning instead of recomputing it at each restructuring iteration.

We need to take particular care in updating the information in presence
of the default `SetNode` inserted in case of an entry dispatcher.

The actual implementation is pretty naive, and the update of the
`Backedges` `std::set` is for sure not optimal, we should consider using
a `std::multimap` for it.

We should also consider updating the reverse postorder instead of
recomputing it, but at it seems that recomputing it may cause
sub-optimal restructuring, but no errors should be triggered.
2019-04-12 15:01:49 +02:00
Alessandro Di Federico d75e5f3b6a Improve detection of external function calls
This commit enlarges the set of external function calls we
detect. Basically, instead of assuming that the instruction jumping to
the external function is the call, we now also consider instructions in
previous basic blocks, as long as there's only one possible path
backward.
2019-04-11 19:51:32 +02:00
Alessandro Di Federico d50fbe969a Update documentation and add revng. to metadata 2019-04-11 19:51:32 +02:00
Alessandro Di Federico 2a5081328c NRA: do not iterate while deleting calls 2019-04-11 18:16:53 +02:00
Alessandro Di Federico 9f4711b770 Improve revng help and ASAN support
This commit improves the output of `--help` and reduces the output of
`--version`.  This commit, when calling `opt`, injects a `LD_PRELOAD`
for `libasan.so` in case a `librevng*.so` library uses it.
2019-04-11 18:16:53 +02:00
Pietro Fezzardi b3da9f0429 Fix wrong assertion on binary ExprNode expressions 2019-04-11 18:14:23 +02:00
Andrea Gussoni 16c3d87a3b Fix check nodes with only then or else branch
Match correctly `IfCheckNodes` which have only the `then` or `else`
branch, that may appear due to conditional nodes blacklisting (the not
identified branch becomes the fallthrough branch).
2019-04-11 17:45:10 +02:00
Alessandro Di Federico d77ad08917 Drop leftover references to revamb 2019-04-11 17:44:39 +02:00
Andrea Gussoni d7e62c8777 New SCS merge step for abnormal retreating.
New SCS merge step for situations in which we have an abnormal edge
exiting from an SCS.

This criterion, during the preprocessing of the metaregions, if an SCS
with an abnormal retreating edge is found (an abnormal retreating is a
retreating edge which target is outside the scope of the current SCS
under analysis), merges the metaregion under analysis with the one which
has been created starting from the backedge.

This preprocessing phase is made in a fixed point fashion.
2019-04-11 16:44:59 +02:00
Andrea Gussoni ad31920b63 Fix for default SetNode membership.
When creating the collapsed node, remember to add in the substitution
phase of the old nodes of the regions (relative to the outer regions),
also any nodes added as default `SetNode`s for any entry dispatcher
inserted.
2019-04-11 16:35:10 +02:00
Andrea Gussoni 0afaa0412c Create new break/continue for each edge
Create a new `break` node for each outgoing edge from the SCS, and a new
`continue` node for each retreating edge.
2019-04-11 16:32:56 +02:00
Andrea Gussoni c3654b5ef7 Additional asserts to verify restructuring
Add an assert which verify that all the targets of the retreating edges
fall inside the SCS under analysis.

Add other asserts to verify that the graphs passed to the comb pass are
acyclic after restructuring.
2019-04-11 16:29:46 +02:00
Andrea Gussoni b1cf76ef4b removeNotReachables removes from MetaRegion
The `removeNotReachables` method now can take care of removing any
reference of the removed nodes from any `MetaRegion` which contains any
reference to it.
2019-04-09 20:12:41 +02:00
Andrea Gussoni 17d6256de7 Add isDAG method for RegionCFG
Added a new method which can be used to check that the `RegionCFG` under
analysis does not contain any cycle.
2019-04-09 20:11:04 +02:00
Andrea Gussoni 5aee9c2711 Fix iterator usage and map access
Now avoiding `predecessors()` iterator invalidation and enforcing
bounds check when using `ClonedMap` during first iteration outlining.

Also avoiding usage of `FirstCandidate` once the real head of a
`RegionCFG` has been elected (only `Head` ptr should be used).
2019-04-09 20:09:12 +02:00
Andrea Gussoni 34913cad29 Fix predecessor iterator invalidation. 2019-04-09 11:55:00 +02:00
Andrea Gussoni 486ddeb4b6 Fix first iteration outling edges movement
In case of `check` nodes some edges could not be attached to the head
dispatcher, if necessary.
2019-04-09 11:38:44 +02:00
Pietro Fezzardi 3f01eed105 Fix setTrue, setFalse, and removePredecessor 2019-04-09 11:27:48 +02:00
Andrea Gussoni eddd6e1924 Change a use of addEdge with moveEdgeTarget 2019-04-09 10:49:10 +02:00
Andrea Gussoni f061095caa Fix first iteration outling
Fix an incorrect iteration over the predecessors of outlined nodes,
which caused iteration invalidation since we are modifying edges in the
meanwhile.
2019-04-09 10:33:57 +02:00
Andrea Gussoni 3ee8eb964b Fix addEdge usage in favor of moveEdgeTarget
Changed an incorrect use of the `addEdge` method in favor of
`moveEdgeTarget` when inserting the `set` nodes.
2019-04-09 09:41:00 +02:00
Pietro Fezzardi 0648b41585 Fix wrong removal of edges 2019-04-08 19:06:27 +02:00
Andrea Gussoni 05fb7a6ccc Fix the conditional nodes blacklisting
We add an additional check for the conditional nodes blacklisting,
meaning that we need to verify that we dominates at least 1 of the
reachable sets for each branch departing from the conditional node.
2019-04-08 09:58:09 +02:00
Pietro Fezzardi ed3d1b1ab8 Properly print bool variables from stdbool.h 2019-04-05 18:52:13 +02:00
Alessandro Di Federico dda91e8c90 ClassSentinel prevent test failures
`ClassSentinel` makes use of an undefined behavior to check if an object
has been destroyed. Disable this check in case of presence of address
sanitizer or even regular optimizations.
2019-04-04 22:58:21 +02:00
Alain Carlucci 51a58a5513 Add support for PE32+ (x86-64) 2019-04-04 22:55:45 +02:00
Pietro Fezzardi 28a9804143 Print int types from inttypes.h 2019-04-04 17:30:48 +02:00
Pietro Fezzardi 3f7965cf7f Fix emission of global struct types 2019-04-02 16:19:27 +02:00
Pietro Fezzardi 490b5eaef8 Apply clang format 2019-04-02 15:30:17 +02:00
Pietro Fezzardi 9e4c5f0ece Add support for functions returning structs 2019-04-02 11:57:07 +02:00
Pietro Fezzardi 6e710dede1 Remove unused variable 2019-03-29 11:17:21 +01:00
Pietro Fezzardi 8329b822e0 Run PHIASAPAssignmentInfo only on isolated funcs 2019-03-29 11:08:13 +01:00
Pietro Fezzardi a231d013d0 improve lazy serialization of branch conditions 2019-03-29 11:08:13 +01:00
Pietro Fezzardi 9dc97a360e ASTBuildAnalysis: skip over Stores of undef values 2019-03-29 11:08:13 +01:00
Pietro Fezzardi b514cc9399 Add virtual destructors for ExprNode 2019-03-28 11:20:25 +01:00
Pietro Fezzardi e6e2f52aa2 Add virtual destructors to ASTNodes 2019-03-28 11:11:57 +01:00
Pietro Fezzardi 25d9a8f3d5 Handle Set/Check nodes for loop state variables 2019-03-26 13:51:06 +01:00
Pietro Fezzardi d50f9d0036 Improve prototypes of ASTNode members 2019-03-25 16:08:41 +01:00
Andrea Gussoni 9dc26b6d05 Create SwitchCheckNode
We now match the `IfCheckNode` trees created by the dispatchers
insertion as an unique switch.

To this we introduced a new `SwitchCheckNode` AST type, which cannot
inherith from the `SwitchNode` since the underlying container for the
`case`s is different (the index is saved as an `unsigned`, while instead
in the `SwitchNode` we use a `ConstantInt *`.
2019-03-21 14:25:48 +01:00
Pietro Fezzardi a5175908dc Fix emission of statements after decompiler rework 2019-03-21 11:59:06 +01:00
Pietro Fezzardi fd66e59e25 Fix emission of switches 2019-03-21 10:46:40 +01:00
Pietro Fezzardi 8993ae644d Fix flattening of ExprNode 2019-03-21 10:46:25 +01:00
Pietro Fezzardi 65e1d9e35b Emit switch 2019-03-20 19:37:29 +01:00