Commit Graph

860 Commits

Author SHA1 Message Date
Alessandro Di Federico add47a861a EnforceABI: use read-only model 2022-08-05 14:39:29 +02:00
Alessandro Di Federico c2651f7218 importBinary: fail if no architecture is specified 2022-08-04 17:27:06 +02:00
Alessandro Di Federico 01ed4fb687 PCH: handle a dispatcher with 0 elements 2022-08-03 18:36:52 +02:00
Alessandro Di Federico 5f49437393 CodeGenerator: invoke peek post newpc creation 2022-08-03 18:35:57 +02:00
Djordje Todorovic 1243d1061c Introduce revng model hard-purge
In addition, introduce a new model Pass:

  revng model opt -prune-unsused-types
2022-07-28 15:02:55 +02:00
Djordje Todorovic 46bc14bc73 Model: Add an opt for user defined paths of PDB 2022-07-28 14:52:50 +02:00
Djordje Todorovic a36e22729f Model: Add PDB support 2022-07-28 14:52:50 +02:00
Djordje Todorovic 9efb9cb55f Model: Add parsing of delay dyn syms to PECOFF
This parses dedicated symbols similar to ELF's lazy linking.
2022-07-28 14:52:02 +02:00
Djordje Todorovic b3cd1316f0 ELFImporter: Fix the documentation comment 2022-07-28 14:52:02 +02:00
Djordje Todorovic 098f864d8d Model: Add parsing of dyn syms to PECOFFImporter
This parses symbols similar to ELF's .dynsym.
2022-07-28 14:52:02 +02:00
Djordje Todorovic b79158bafc Model: Add parseSymbols() to PECOFFImporter
This parses symbols similar to ELF's .symtab.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 9d18d84f68 ELFImporter: Improve the parseSymbols()
This is an NFC.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 5a72d968e5 Model: Add a method for parsing pe sections hdrs
This is an NFC.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 8cbdcf278d Model: Import PE when file size is > than virtual
Without this patch, the import part would fail with an assertion
even for a simple case since it doesn't expect that file size
could be larger than virtual.

From the microsoft documentation:
```
Because the SizeOfRawData field is rounded but the VirtualSize field
is not, it is possible for SizeOfRawData to be greater than
VirtualSize as well. When a section contains only uninitialized data,
this field should be zero.
```
We rather choose not to percolate this into the Model.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 6d390af909 Model: Factor target-dep code out of ELFImporter 2022-07-28 14:51:40 +02:00
Giacomo Vercesi 09009836a1 PipelineC: expose globals verification 2022-07-28 08:47:46 +02:00
Giacomo Vercesi 3e9058393e Rework YieldAssemblyHTML to output PTML 2022-07-28 08:47:34 +02:00
Giacomo Vercesi efc2d36a14 Introduce ptml namespace
The `ptml` namespace contains utilities for easier PTML manipulation.
These include:

* A few constants (e.g. standard attributes) available in
  `revng/PTML/Constants.h`
* The `Tag` class to easily construct html/xml tags with attributes
  without having to use format strings.
* The `PTMLIndentedOstream`, a llvm::raw_ostream wrapper that
  automatically adds tagged indentation to the output
2022-07-28 08:47:17 +02:00
Alessandro Di Federico d42fb9bb13 Segment::verify(): relocations can be out segment
We used to check that the target address of a relocation needs to be
within the `model::Segment` it's referring to.
However this is not correct.
2022-07-27 18:57:21 +02:00
Massimo Fioravanti da30cf9e99 Pipeline: add read-only containers 2022-07-25 16:24:27 +02:00
Davide Depau e9cfac1727 Add InitRevng signal handlers to PipelineC API 2022-07-22 21:04:03 +02:00
Davide Depau 363fa21fe0 Introduce PipelineC API shutdown method 2022-07-22 21:04:03 +02:00
Davide Depau 0d55cd4c51 Do not explicitly print stack trace on abort
Let the signal handler take care of that
2022-07-22 21:04:03 +02:00
Antonio Frighetto 4bc21328d8 Model: reserve type prefixes 2022-07-22 16:10:51 +02:00
Antonio Frighetto 5500fadb0e MachOImporter: add segment name 2022-07-22 16:10:51 +02:00
Antonio Frighetto 186d907be3 Model: extend model::Segment
`Segment` now includes a `Type` of struct kind. This is intended to
emit the segment as a struct later in decompilation. The implementation
of name has also been added.
2022-07-22 16:10:51 +02:00
Giacomo Vercesi 80afd71721 Add singleTargetFilename to pipelines
A step's artifacts now include singleTargetFilename, which gives a
suggested filename to use when a single element is extracted from the
underlying container.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 2df691535d Pipeline: Make recalculateAllPossibleTargets
`recalculateAllPossibleTarget` is now a private member of
PipelineManager This was done since all calls that can trigger a change
in the target list have been isolated and the call is done implicitly.
This removes rp_manager_recompute_all_available_targets from PipelineC,
since it was added as a stopgap until the above was implemented.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 487af0f4b0 Do not pass file paths to revng from PipelineC
Allow deserializing containers from a byte string rather than pointing
to a file, this allows revng to have an opaque workdir.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 05dc27715d Improve pipeline saving capabilities
This commit introduces some changes to how the revng pipeline handles
serializing to disk. Specificaly:

* Pipeline globals (specifically model.yml) are better handled if they
  are in a subdirectory. They are now saved in the "context"
  subdirectory.
* In python:revng.api the pipeline is serialized whenever there is a
  non-reproducible change to the state (e.g. binary upload or model
  change).
  In the case of analyses this is done conservatively by checking that
  the diff produced is not empty.
* The logic for computing a step's subdirectory has been moved to the
  pipeline runner, consequently if a step is asked to serialize it
  will not create any subdirectories.
* Functionality for saving a single step/context has been exposed in
  Pipeline C.
* Finally, all path concatenations are now handled by
  llvm::sys::path::append, for extra os-agnosticism.
2022-06-29 14:50:58 +02:00
Giacomo Vercesi 6d159f2ef2 Kind::serialize: emit :kind if no components
This commit fixes an issue where if a target had no components the
serialized name would have been an empty string instead of ":kind".
2022-06-29 14:50:58 +02:00
Massimo Fioravanti 8c7434f79e pipes::FileContainer: drop temporary file on crash 2022-06-22 18:10:48 +02:00
Alessandro Di Federico 6d3a35cf22 EFA: ignore dynamic functions, if static too 2022-06-21 14:17:57 +02:00
Alessandro Di Federico f4684e244d Switch to new testsuite 2022-06-20 19:04:18 +02:00
Massimo Fioravanti 55fb87b268 PipelineC: introduce dead kinds
We need to prevent stub kinds used just to represent dead elements to be
displayed in the GUI and CL.
We do so by introducing a DeadKind which expands their targets to the
empty list.
2022-06-20 19:03:17 +02:00
Ivan Krysak 71115c8062 Implement SVG control flow exporter 2022-06-15 16:04:44 +03:00
Ivan Krysak eb129428a9 Import edge routing from caliban
(the following is the original commit message)

The last step is pretty simple. All that's left to do is to take the
ordered edge container and to `append` their points to their `Path`
2022-06-15 16:04:44 +03:00
Ivan Krysak 5ff8a00b2e Import edge ordering from caliban
(the following is the original commit message)

Now that the problematic edges are dealt with, all the normal edges
need to also get routed, but first, it's a good idea to order them.
As such, the DAG is consumed to produce the list of all the edges in
the optimal order for them to get routed.
2022-06-15 16:04:44 +03:00
Ivan Krysak 479d0287c7 Import corner routing from caliban
(the following is the original commit message)

Now that every single node has gotten its exact position, the only
thing left to do is to route all the edges between them. First of
all, the special edges (like corners) need to be handled.
2022-06-15 16:04:44 +03:00
Ivan Krysak b69121bc0a Import vertical coordinate position from caliban
(the following is the original commit message)

Now, that it's precisely known how much space is needed between each
pair of the layers, it's possible to set the vertical coordinates for
each of the nodes based on the layer heights (the height of the
longest node within said layer) and the number of horizontal lanes
required after it.
2022-06-15 16:04:44 +03:00
Ivan Krysak acf5858099 Import edge lane selection from caliban
(the following is the original commit message)

Now that the nodes are placed into the grid (at least horizontally),
it's possible to focus on the edges. Since, the information about
the number of edges going from/to each of the layers is known, it's
possible to determine the number of horizontal space needed to placed
those.

In this part of the layouter, the focus is on three different laning
points:
- horizontal lanes between layers.
- entry lanes for each of the nodes.
- exit lanes for each of the nodes.

Indexation is done independently for each of the lane types.
2022-06-15 16:04:44 +03:00
Ivan Krysak 057ac648c3 Import horizontal coordinate position from caliban
(the following is the original commit message)

Since the predetermined order of the nodes for each layer was already
predetermined, what's left is to put their coordinates based on the
size of the nodes and the predefined margins between them.

Except the resulting layouts are extremely left-heavy. As such, it's
important to use the coordinate selection part to push as many nodes
to the right as possible to balance the graph out at least somewhat.
2022-06-15 16:04:44 +03:00
Ivan Krysak 98b098cbce Import graph layout finalization from caliban
(the following is the original commit message)

Since from this point on, no breaking changes will be done to the graph
It's possible to finalize the layout. Meaning that from this point
onwards the logical positions of the nodes remain unchanged.

Having this guarantee we can proceed to calculating their real
positions, starting from the horizontal coordinates.
2022-06-15 16:04:44 +03:00
Ivan Krysak eee95028d0 Import linear segment selection from caliban
(the following is the original commit message)

Now that the layer permutation is finalized, it's possible to select
a couple of node-groups that only depend on a single predecessor and
consider them a single linear segment. This allows to "draw" straight
vertical lines accross the layout for nodes that could benefit from
that.

Such linear segments are also paramount for good looking long edges
(both forwards and backwards facing).

\note: this part of the layouter could still use more work.
If you're looking to rework it, this is the spot.
2022-06-15 16:04:44 +03:00
Ivan Krysak 054f9a2b25 Import topological ordering from caliban
(the following is the original commit message)

To optimize the algorithms coming from now, having a topological
of the nodes of the graph is benefitial. And, considering, no new
nodes will be added to the graph from this point on, we can only
compute it once.

To optimize the ordering even further, augmented graph is used.
On top of the original (and earlier added artifical) edges, the graph
used for obtaining the ordering get a few extra edges added.

`llvm::ReversePostOrderTraversal` is used to convert the graph to the
ordered node list.
2022-06-15 16:04:44 +03:00
Ivan Krysak 678e203164 Import permutation selection from caliban
(the following is the original commit message)

To ensure the optimal layout is choosen, it's important to try out
and compare a few different permutations.

First of all, layers are optimized. Those layers, that only contain
irrelevant artificial nodes are removed and all the others are shifted
in order to maintain simple layer indexing.

Then, using a simple hill climbing the permutation with the lowest
number of edge crossings is selected. After which a technique based
on computing barycenters for nodes and layers is used as a fallback
to ensure even the least optimal layout is still usable.

On top of all that, simple clustering based on the classification
obtained while preparing the graph is used to keep original nodes
somewhat separate from the artificial ones.
2022-06-15 16:04:44 +03:00
Ivan Krysak c45f4d5e73 Import graph preparation from caliban
(the following is the original commit message)

Preparation includes:
- ensuring there are no loops.
- ensuring there are no edges spanning more than a single layer.
- ensuring there are no backwards facing edges that were not split
  into a bunch of parts to simplify laying them out.
- ensuring there are no self loops (they are treated similarly to
  backwards facing edges, which they theoretically are).

Subproducts include:
- `Classifier` allowing to cheaply determine whether a given node is
  adjacent to an artificial edge.
- `Ranks` container allowing to easily determine the layer each of the
  nodes belongs to.
2022-06-15 16:04:44 +03:00
Ivan Krysak 7e538776d4 Outline sugiyama style layouter interface 2022-06-15 16:04:44 +03:00
Ivan Krysak 7591788620 Implement node size calculation 2022-06-15 16:04:44 +03:00
Ivan Krysak 840a34c0a4 Implement CFG extraction 2022-06-15 16:04:44 +03:00