Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi abee369841 Handle calls whose callee is not an llvm::Function 2021-12-14 16:57:41 +01:00
Pietro Fezzardi 375eb70dc8 SCEVBaseAddressExplorer: ignore non-const strides 2021-12-14 16:56:51 +01:00
Pietro Fezzardi 0908c7d12f AdjustStackPointerPass: bail out on sub from SP0
If someone subtracts something from the stack pointer the result cannot
be a pointer, so we have to ignore the result when trying to adjust the
stack pointer.
2021-12-14 16:55:29 +01:00
Pietro Fezzardi 3a28bb0611 DLAMakeModelTypes: use isValid for TTR 2021-12-01 17:40:01 +01:00
Pietro Fezzardi 373abf9ba8 Merge feature/dla-pointer-edges into develop 2021-11-19 12:23:42 +01:00
Alvise de Faveri 2f4b716e6b Add Model::toString() and writeToFile()
These functions can be used in conjunction to dump the Model on a
file during a gdb session, for example:

```
(gdb)  p  writeToFile(Model->toString(), "/tmp/model.yaml")
```
2021-11-19 10:17:09 +01:00
Alvise de Faveri 267410ac43 Add Attribute::WillReturn to ReadOnly funcs
Without this attribute, newer versions of llvm are not able to
remove calls to `ReadOnly` functions whose return value is unused.

This is instead the expected behavior for the functions that are
generated by `revng` with the `ReadOnly` attribute.
2021-11-19 10:17:02 +01:00
Alessandro Di Federico d3cee7611d revng-dump-model: consider generic MetaAddress too 2021-11-19 10:12:23 +01:00
Alessandro Di Federico 54573608fe revng-dump-model: consume all the input 2021-11-19 10:12:23 +01:00
Alessandro Di Federico e1dadae08d revng-dump-model: ignore YAML tags 2021-11-19 10:12:23 +01:00
Antonio Frighetto adcda3532b AVI: fix error in detection of stores to PC 2021-11-18 15:30:07 +01:00
Alvise de Faveri bda519b3e2 Add AddPrimitiveTypesPass to Decompiler
This pass is in charge of creating all the primitive types for any
of the typical sizes used for numbers.
2021-11-18 11:13:36 +01:00
Alvise de Faveri 89091510d5 DLA: Handle functions with same prototype in FE
Since in the model a FunctionPrototype can be shared among different
functions or indirect calls, we should take into account this fact when
initializing the DLA.

In particular, if the aforementioned case happens, we want to add
equality edges between the return value(s) and the arguments of all the
functions that have the same prototype. These will then be merged by
later steps in the middle-end, and the resulting information will be
shared among all the merged nodes.
2021-11-16 17:00:53 +01:00
Alvise de Faveri 5b8529edd5 DLA: Generate Model Types
Add `MakeModelTypes` and `UpdateFuncPrototypes` to the DLA backend:
* `MakeModelTypes` adds to the model all the types recovered by the DLA
* `UpdateFuncPrototypes` updates function prototypes in the model that
have generic return values or arguments to use the types recovered by
the DLA
2021-11-16 17:00:53 +01:00
Alvise de Faveri 4c8215fc47 DLA: Add pointers
* Changes to the `LayoutTypeSystem` graph

Pointers are identified in the TypeSystem graph as leaf nodes which
have a new type of edge (PointerEdge) that connects them to another
node of the graph. The destination of the edge represents the layout of
the pointed type.

* Changes to the Front-end

Pointer edges, and their destination nodes, are created by the DLA
front-end (`DLACreateIntraProceduralTypes`) whenever an access node has
a size that is compatible with the size of a pointer in the current
Architecture.
Successors might then be added to the newly generated node, if any,
by looking up the llvm::Value it is attached to.

* Changes to the Middle-end

Most of the DLA passes should ignore Pointer Edges, so they are modified
accordingly. Most notably, nodes that represent pointed layouts should
never be merged/pruned-off.

* Changes to the Back-end

The `TypeDeclCreationAction` of the decompiler and the `DLAMakeLayouts`
step of the DLA back-end are modified to take into account the new
information about pointers.

⚠️ There is a known issue with this version of the decompiler,
namely the fact that type loops are not detected and can cause the
emitter to enter an infinite loop.
2021-11-16 17:00:34 +01:00
Alvise de Faveri 92712396ee DLA: Fix multi-edge children in DedupUnionFields
When deduplicating unions, for each union we compare each successor
with all other successors. However, the same successor node might be
reachable by more than one edge from the parent.

This can cause problems when a node gets merged while the comparison is
still ongoing. In particular, since the comparison is done using a copy
of the successor list, to avoid iterator invalidation, the links in
the worklist are not updated when a node gets merged, causing links to
the merged node to have an invalid destination.

The fix here is to keep a list of **nodes** to visit, and a list of
**edges** that have already been visited, so that, if a node is merged
through one of its links, we are not visiting other links connected to
the same node after the merge.
2021-11-16 17:00:34 +01:00
Pietro Fezzardi ac2e5db6e2 Merge branch 'feature/ast-improvements' into develop 2021-11-15 12:40:45 +01:00
Andrea Gussoni 81782fe633 generateAst: new tile for matching inlined if
We introduce a new tile, for matching if node with a single and inlined
then/else. In these case, the not inlined successor should be connected
with the tile node.
2021-11-15 12:39:17 +01:00
Andrea Gussoni 6d306ee473 generateAst: improve switch postdominator identify
We now identify the postdominator of a switchnode if one of the cases is
the successor of all the other cases nodes.
2021-11-15 12:39:17 +01:00
Andrea Gussoni 46cb2be99c generateAst: Add parent switch in SwitchBreak 2021-11-15 12:39:17 +01:00
Andrea Gussoni ce902e36b6 generateAst: generalize the switch fallthrough 2021-11-15 12:01:00 +01:00
Andrea Gussoni 6dcffcce67 generateAst: Handle switch postdominator
Handle switch nodes with all but one case edges inlined, by electing the
not inlined edge as the path conducting to the postdominator, and
avoiding parts of the graph disconnecting during the tiling procedure.
2021-11-15 11:57:36 +01:00
Pietro Fezzardi 067f2fffe1 Add ModelToHeader 2021-11-15 11:47:17 +01:00
Pietro Fezzardi 432cf351d7 AddSCEVBarrierPass.h: declare function extern 2021-11-12 18:36:19 +01:00
Pietro Fezzardi 86734aef6b Fix revng coding conventions 2021-11-09 15:28:04 +01:00
Alessandro Di Federico 9b61ad1772 scripts/revng: fix typo in ASan handling 2021-11-08 16:18:27 +01:00
Ivan Krysak 52f7432f1b Add model::Architecture::getPointerSize() 2021-11-08 16:17:47 +01:00
Pietro Fezzardi 15cc5d2a42 libRestructureCFGPass: link revngModel 2021-11-04 10:00:11 +01:00
Alvise de Faveri 2e19fade43 Fix memory leak in TupleTreeKeyWrapper::clone
ConcreteTupleTreeKeyWrapper::clone() should cleanup the Target object
befor cloning, otherwise the destructor of the inner Pointer object
is never called.
2021-10-27 08:42:53 +02:00
Pietro Fezzardi 1e5750f26d Setup infrastructure for FileCheck tests 2021-10-21 17:08:46 +02:00
Pietro Fezzardi d042299ff1 Update comment in tests cmake file 2021-10-21 17:08:46 +02:00
Pietro Fezzardi c2e27869af Merge feature/dynamic-functions into next-develop 2021-10-21 17:04:14 +02:00
Alessandro Di Federico 0b7787967d Merge branch 'feature/dynamic-functions' 2021-10-21 15:55:44 +02:00
Alessandro Di Federico 93b93a3908 scripts/revng: fix computation of libs dependencies 2021-10-21 15:02:01 +02:00
Pietro Fezzardi c050dcb621 Handle missing model in SerializeModelPass
Before this commit, SerializeModelPass and SerializeModelWrapperPass had
hard dependencies on the passes that load the model from LLVM-IR.

This commit makes this dependency optional. When the passes for model
serialization are executed, if they see that nobody requested to load
the model, they will not try to serialize it.

This prevents them from crashing when running in pipelines that only
contain passes that ignore the model.

This is particularly beneficial because `revng opt` automatically adds
`-serialize-model` at the end of each pipeline and, before this commit,
this meant that `revng opt` could not be used for unit-testing simple
llvm passes that do not use the model.

With this commit, `revng opt` can be used for unit-tests, even on LLVM IR
with missing model.
2021-10-21 15:02:01 +02:00
Andrea Gussoni cd9e4b5df1 check-revng-conventions: improve c files exclusion 2021-10-21 15:02:01 +02:00
Alessandro Di Federico 0a6c52a590 Update docs/GeneratedIRReference.rst
* Drop outdated portion describing ABI/CFG metadata that are now stored
  in the model.
* Introduce MetaAddress concept.
* Describe the four-parts program counter CSVs.
* Update description of the dispatcher.
* Update description of `function_call` and `newpc`.
2021-10-21 15:02:00 +02:00
Alessandro Di Federico 83f420abda Introduce dump method for model structs 2021-10-21 15:02:00 +02:00
Alessandro Di Federico eb2c3df925 Tag with MetaAddress functions and call sites 2021-10-21 15:02:00 +02:00
Alessandro Di Federico 8546a0c786 CallEdge: only indirect calls have a prototype 2021-10-21 15:01:59 +02:00
Alessandro Di Federico 89532890ed Introduce support for importing DWARF information 2021-10-21 15:01:20 +02:00
Alessandro Di Federico 3a3eea0cf5 Introduce support for dynamic functions 2021-10-21 15:01:19 +02:00
Alessandro Di Federico a023bfa7f5 Introduce ABI handling 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 0dfc81da41 Minor model improvements
* Introduce some documentation for the model.
* Improve the way enums are serialized/deserialized.
* Mark certain fields of model data structures as optional.
* introduces some error messages during model validation.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 5b50a3320f Introduce error messages during model validation 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 34ae75c800 model: handle 80 bits floats (12 bytes) 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 06043b92c6 PromoteCSV: do not promote the stack pointer 2021-10-18 20:44:58 +02:00
Alessandro Di Federico d5bfb872d6 Introduce SortedVector::isSorted
This is a debug method.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 2fec214959 Fix QualifiedType::isScalar 2021-10-18 20:44:58 +02:00
Alessandro Di Federico fe2e9427c1 scripts/revng: use gdb -q 2021-10-18 20:44:58 +02:00