Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi a65407f089 MakeModelGEP: handle array traversal with 0 offset 2022-03-07 17:25:05 +01:00
Pietro Fezzardi 198ecd08d9 Update to new revng API for getCallSitePrototype
This commit updates the calls to getCallSitePrototype according to the
new API introduced in revng in commit 0659e6b6a3
2022-03-02 18:04:36 +01:00
Alessandro Di Federico d5843e807f Merge branch 'feature/various-improvements' 2022-03-02 16:11:32 +01:00
Alvise de Faveri 9e326682bc Check-conventions: handle dirs with 0 python files 2022-03-02 15:40:27 +01:00
Pietro Fezzardi 269d729554 FilteredGraphs: add filter() method
The method allows to access the filter function and is useful for
templating.
2022-03-02 15:40:27 +01:00
Alvise de Faveri 0659e6b6a3 Model: Improve getCallSitePrototype() helper
1. Hoist the logic to retrieve a model CallEdge from an llvm::CallInst
   out of `getCallSitePrototype()`, in a separate `getCallEdge()`
   function.
2. Modify `getCallSitePrototype()` so that the parent function's type is
   optional.
2022-03-02 15:40:27 +01:00
Alvise de Faveri ea53846fa0 Add Qualifier::createPointer(Architecture) 2022-03-02 15:40:27 +01:00
Alvise de Faveri 62b5ec38cd Add CallEdge::isDirect() 2022-03-02 15:40:27 +01:00
Antonio Frighetto e798131082 O2Pipe: fix pipe name 2022-03-02 15:40:27 +01:00
Massimo Fioravanti b982b69c5d revng-model-inject: support model-less modules
Inject is meant to inject a model into an `llvm::Module`, but it fails
when operating on a Module that had no model metadata.

This commit fixes the bug.
2022-03-02 15:40:27 +01:00
Alessandro Di Federico 9608b337c6 Python formatting: switch to black 22 2022-03-02 15:40:27 +01:00
Alvise de Faveri 4e5026c368 Add ReadNone attribute to revng intrinsics
In order to enable the optimizer to strip dead calls, ModelGEP,
 SerializationMarker and AddressOf functions are marked as
 `ReadNone` instead of `InaccessibleMemOnly`.
2022-03-02 11:46:42 +01:00
Alvise de Faveri b2b1aa8a58 ModelToHeader: define NULL in model.h 2022-03-02 11:46:30 +01:00
Alvise de Faveri ebd684fabf Add 128-bit numbers to primitive types 2022-03-02 11:46:19 +01:00
Pietro Fezzardi cb51965f6e DLAComputeNonInterferingComponents: fix moveEdges
This DLAStep was moving edges improperly before this commit.
In particular, edges were detected solely looking at source and target
edge, not looking at the edge itself. This was leading to wrong results
whenever a node N1 had many outgoing edges to a child node N2, at
different offsets, where all the edges were moved instead of just the
correct ones.

In order to fix this, this commit:
- reworks the logic of `moveEdges`, switching to iterator-based logic
- reworks the struct OrderedChild used internally by
  DLAComputeNonInterferingComponents, so that it is also iterator-based
- re-uses common code for field size computation
2022-03-01 12:52:58 +01:00
Pietro Fezzardi 3a94aab82a DLA: extract field size computation logic
This commit moves the logic for the computation of field sizes to a
separate .cpp file.
At the moment this is only used by DLAComputeUpperMemberAccess, but in
the future it will also be re-used DLAComputeNonInterferingComponents,
which at the moment employs very similar code.
2022-03-01 12:52:58 +01:00
Pietro Fezzardi 60f9141a07 DLA: move DLAHelpers.{cpp,h} to Middleend 2022-03-01 12:18:23 +01:00
Pietro Fezzardi 050af6e5c6 Move getLoadStoreSizeFromPtrOpUse to DLA frontend
This helper was only used once in DLACreateIntraProceduralTypes.cpp.
This commit moves it there, paving the way for better isolation of
helpers.
2022-03-01 12:18:22 +01:00
Pietro Fezzardi b0d3ab2b84 DLACollapseSingleChild: relax assertion on node collapse 2022-03-01 11:38:04 +01:00
Pietro Fezzardi e2a82f8dfc Drop useless include DLAHelpers.h 2022-03-01 11:38:04 +01:00
Pietro Fezzardi 59ed4b56f7 Merge feature/dla-fixes into develop 2022-02-28 18:16:57 +01:00
Pietro Fezzardi 7132ffa3e3 DLA: improve handling of stack arguments
Before this commit the case where the DLA recovered narrower sizes for
stack arguments than what expected on the Model was not handled
properly.

Now the scenario is handled explicitly, in two ways
- if the DLA recovers a stack argument with struct type, the fields are
  copied to the model in the type representing the stack argument;
- if the DLA recovers a stack argument with a type T that is non-struct,
  then the type in the model representing that stack argument is a
  struct with a single field at offset 0 and type T.
2022-02-28 18:12:27 +01:00
Pietro Fezzardi 1f39ed42e6 Fix update of stack sizes on Model by DLA
Before this commit, if the DLA was detecting stack sizes that were
smaller than expected by the Model, the size of struct recovered by the
DLA was edited in-place, enlarging it an possibly leading to a
malformed Model.

This commit fixes the problem:
- the size of the stack struct recovered by DLA is not changed
- the fields of the stack struct recovered by DLA are copied inside
  inside the Model in the struct representing the stack
2022-02-28 18:12:06 +01:00
Pietro Fezzardi b6520330fb DLADeduplicateUnionFields: fix use-after-poison
This commit fixes a use-after-poison bug.

DLADeduplicateUnionFields::runOnTypeSystem iterates over the DLA graph
while mutating it.
Due to iterations on copies of the edges, there were some edges to dead
nodes that were still hanging around and could be accessed.

This commit fixes the problem by not saving copies of the edges, but
saving LayoutTypeSystemNode * and iterating lazily on the edges starting
from the node itself every time.
In this way, if the graph is mutated, we never have outdated edges
pointing to dead nodes, and we don't have use-after-poison.
2022-02-28 18:11:49 +01:00
Pietro Fezzardi 94d875b559 Improve dla::LayoutTypeSystem::moveEdges
Before this commit, this method could not move Inheritance edges to
offsets different than 0.
This commit enables this action. Inheritance edges that are moved to
offset different than 0 become Instance edges.
2022-02-28 18:11:31 +01:00
Pietro Fezzardi 9c5e1750c7 DLATypeSystem: use lower_bound and upper_bound
This commit changes a bunch of methods of LayoutTypeSystem that were
dealing with edge removal and editing.
The previous version was using linear search with std::find_if on the
neighbours.
This commit switches to using std::set::lower_bound and
std::set::upper_bound, exploiting the fact that edges are ordered based
on the address of the target node.
This makes the code more concise and more efficient.
2022-02-28 18:11:13 +01:00
Pietro Fezzardi a58d960440 DLA: avoid late insertion of Inheritance edges
Inheritance edges have a specific semantic that must derive directly
from the binary, and are often treated specially by DLA steps.
For this reason is not correct to inject them late in the pipeline.
2022-02-28 18:10:57 +01:00
Pietro Fezzardi bd99db4711 DLADeduplicateUnionFields: fix use-after-free
This DLA Step works iterating in post-order on a graph while mutating
it. The post-order traversal is done with llvm::post_order, which holds
an iterator to the next children to visit.
Before this commit, the mutation of the graph could invalidate this
iterator.
This commit fixes the iteration logic, by computing the post-order ahead
of time, without holding around iterators that could be invalidated.
This is possible thanks to the fact that the mutation applied by the
DLADeduplicateUnionFields step on the graph do not change the post-order
visit, so the order computed beforehand remains valid throughout all the
computation despite the mutations that could take place.
2022-02-28 18:10:20 +01:00
Pietro Fezzardi 64d30a4790 DLATypeSystemBuilder: isolate assertion methods
The assertGetLayoutTypePreConditions methods didn't really need to be
exposed as methods in a header. This commit moves them to static
standalone functions in the only place they're used.
2022-02-28 18:06:44 +01:00
Pietro Fezzardi 078c56bbb1 DLAComputeUpperMemberAccess: improve debug logging 2022-02-28 18:06:28 +01:00
Pietro Fezzardi 41a62366fc DLATypeSystem: color edges when printing to .dot 2022-02-28 18:06:10 +01:00
Pietro Fezzardi cd240e1bdb lib/Support link with revngModel 2022-02-28 18:04:43 +01:00
Pietro Fezzardi 5cdc63cda6 Apply new revng coding conventions 2022-02-28 18:02:25 +01:00
Pietro Fezzardi 65e6193edf MakeModelGEPPass.cpp: improve const-correctness 2022-02-25 10:32:22 +01:00
Pietro Fezzardi a767a0556c MakeModelGEP: RestOff might be wider
This is a temporary fix for an heisenbug, very much like commit
99ceac865b790d08de46d21a8ba89f3649d3a097
2022-02-25 10:32:22 +01:00
Alessandro Di Federico 24e6873d20 Merge branch 'feature/describe-function-type' 2022-02-25 08:21:49 +01:00
Alessandro Di Federico 984aea88ae Minor changes 2022-02-25 00:32:46 +01:00
Ivan Krysak bc0e6d1392 ABI: preliminary FinalStackOffset computation 2022-02-25 00:32:24 +01:00
Ivan Krysak 868970c5e7 ABI: specify stack alignment 2022-02-25 00:32:01 +01:00
Ivan Krysak fca0df8dd2 ABI: specify who's responsible for stack cleanup 2022-02-25 00:31:37 +01:00
Ivan Krysak 2c35fc87d5 Conversion to RawFunctionType cannot fail 2022-02-25 00:31:14 +01:00
Ivan Krysak 11989b316b Ensure model is untouched RawToCABI
It's now guaranteed to leave the model unmodified if the converstion
from `RawFunctionType` to `CABIFunctionType` fails.
2022-02-25 00:30:51 +01:00
Ivan Krysak d811321538 InvokeIsolatedFunctions: adopt Layout 2022-02-25 00:30:38 +01:00
Ivan Krysak f30ed88eb5 EnforceABI: adopt FunctionType::Layout 2022-02-25 00:30:27 +01:00
Ivan Krysak b14fee7515 Implement abi::FunctionType::layout()
The `Layout` data structure works as a common view over
`RawFunctionType` and `CABIFunctionType`.
2022-02-25 00:30:14 +01:00
Ivan Krysak 541643afc3 Move function type conversion to librevngABI 2022-02-24 23:56:30 +01:00
Alessandro Di Federico d193c6435e Merge branch 'feature/python-model' 2022-02-24 14:18:43 +01:00
Alessandro Di Federico 3f52078950 Use BYPRODUCTS after POST_BUILD copy 2022-02-24 14:18:17 +01:00
Alessandro Di Federico 838a9cab7d Update test files for new model schema
The YAML tags all now have the `Type` suffix.
2022-02-24 12:08:14 +01:00
Alessandro Di Federico e7ae70e9a4 Record grandiso as a dependency 2022-02-23 18:03:45 +01:00