Commit Graph

3168 Commits

Author SHA1 Message Date
Alessandro Di Federico 1cd17a13e8 readFromPointer: use bool IsLittleEndian 2022-03-08 12:25:47 +01:00
Alessandro Di Federico 0589697dca CMake: sort headers for tuple_tree_generator 2022-03-08 12:25:35 +01:00
Alessandro Di Federico 7c515ff997 Use std::string for MaterializedValue::SymbolName 2022-03-08 12:25:35 +01:00
Alessandro Di Federico c1ed018786 Fix a revng_assert meant to be a revng_abort 2022-03-08 12:25:22 +01:00
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
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
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
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 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
Ivan Krysak bc0e6d1392 ABI: preliminary FinalStackOffset computation 2022-02-25 00:32:24 +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
Filippo Cremonese 09a995ba51 python-model: generate from jsonschema 2022-02-23 18:03:35 +01:00
Pietro Fezzardi 06dc78382b MakeModelGEPPass: fix AddressOf parameters
Before this commit, the type parameter of AddressOf calls was
erroneously set to the same type of the associated ModelGEP.
This commit fixes the problem, setting the type parameter of AddressOf
calls to the pointee type.
2022-02-15 11:44:04 +01:00
Alessandro Di Federico b7f5884f8c DynamicFunction::name: no OriginalName direct use 2022-02-14 17:54:32 +01:00
Ivan Krysak 242b885a78 Remove obsolete ABI utilities 2022-02-14 13:35:37 +01:00
Ivan Krysak 371f5c4555 Implement ABI-based register state deductions
This will help EarlyFunctionAnalysis in providing more accurate results,
in case assumptions about the ABI can be made.
2022-02-14 13:35:37 +01:00
Ivan Krysak 9771ae29d6 Move RegisterState to ABI 2022-02-14 13:35:37 +01:00
Ivan Krysak cafe44097b ABI: introduce default function type generation 2022-02-14 13:35:37 +01:00
Ivan Krysak 8d876b0def ABI: introduce bulk function conversion 2022-02-14 13:35:37 +01:00
Ivan Krysak e20e65ca9a Require a description when registering a pass 2022-02-14 13:35:36 +01:00
Ivan Krysak 7369e49eba Implement "best effort" function type convertion 2022-02-14 13:35:36 +01:00
Ivan Krysak 68129c9221 Add model::Binary::DefaultABI field 2022-02-14 13:35:36 +01:00
Ivan Krysak bac670a38a monotone_framework_lattice: move generation notice
It made it look like the template was autogenerated.
2022-02-14 10:57:20 +01:00