Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi c40b3c5386 [DLA] Add LayoutTypeSystem::createArtificialLayout
This method allows to create artificial layouts that are not directly
associated to `llvm::Value`s.
Because of this missing association with `Value`s, the artificial
layouts are not retrievable by using the public `getOrCreateLayoutType`
and `getLayoutType` methods of `LayoutTypeSystem`, but they will be
accessible only by walking the graph.

The capability to add layouts that are not associated to `llvm::Value`s
is necessary for the future implementation of the DLA Step:
`ComputeNonInterferingComponents`.
The step will add artificial layouts to represent non-intefering
components.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 46a504b9ea [DLA] Drop useless method from LayoutTypeSystem 2021-02-02 11:23:53 +01:00
Pietro Fezzardi b980c8bcfc [DLA] Use defaulted operator <=> whenever possible 2021-02-02 11:23:53 +01:00
Pietro Fezzardi cdca33a99f [DLA] Guard costly verify calls with VerifyLog 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 6119e54e1b [DLA] Add MakeLayouts DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 8d02bec310 [DLA] Add ComputeUpperMemberAccess DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi e259397b4e [DLA] Add PruneLayoutNodesWithoutLayout DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 8fdfe8e169 [DLA] Add MakeInheritanceTree DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi fc7296a302 [DLA] Add RemoveTransitiveInheritanceEdges DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 22ebf9cf52 [DLA] Add CollapseIdentityAndInheritanceCC DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 94ca753808 [DLA] Add CreateIntraProceduralTypes DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi cdee2fb194 [DLA] Add CreateInterProceduralTypes DLAStep 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 36c89c3118 [DLA] Add pipeline of steps to DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi dda2b5aaa0 [DLA] Add skeleton for DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi fc48930e5e [DLA] Add data structures for dla::TypeSystem 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 52b617a6dd [DLA] Add dla::Step and dla::StepManager
These are the elementary steps of the DataLayoutAnalysis (that is still
to be defined), along with a manager to handle them, their dependencies,
their executions and their invalidations.

In principle, this design could have been implemented inheriting from
`llvm::Pass` and `llvm::legacy::PassManager` (or `llvm::PassInfoMixin`
and `llvm::PMDataManager` for the new step manager).
However, LLVM's passes and managers provide far more complex features
than we need for now, so I decided to keep it simple and roll our own
for now.
We could potentially switch to LLVM stuff later if we need their power.

Some examples of features we don't need for now are:
- capability to pass results from a pass to another that depends on it
- capability to dynamically compute pass dependencies
- capability to dynamically invalidate passes
If some of these become necessary in future, it's a sign that it might
be time to switch to an LLVM-based design

The design is structured as follows.

1) Adding `Step`s to the `StepManager`

The `StepManager` owns the `Step`s, that can be added via the `addStep`
method.
Whenever a new `Step` is added, four properties are checked:
- that all its dependencies have already been added before it;
- that non of its dependencies have been invalidated by the insertion of
  another step that invalidate them.
- that it does not depend on itself
- that it does not invalidate itself
If any of these conditions fail, the `Step` is not added successfully.

Whenever a new `Step` A is added and it invalidates any `Step` B, the
last instance of B added to the `StepManager` before A (if present) is
marked as invalidated.
If one wants to add a new `Step` C that depends on B, it will be
necessary to explicitly add a new instance of A (say A*) before adding
C.
Otherwise, there will be no guarantee that an instance of A executes
before C without being invalidated.

These conditions on invalidations are restrictive but the allow to
specify the dependencies and invalidations that we need for now.
If it turns out we need more complex dependencies and invalidations we
should explore implementing the LLVM-based design.

2) Executing the added `Step`s

After adding the `Step`s to the `StepManger`, they can be executed all
together with the `dla::StepManger::run()` method.

This method runs all the steps in the order they were added by the user
with calls to `addStep`.
The fact that `addStep` strictly ensures that dependencies and
invalidations are respected, guarantees that the execution always works
in the order of `Step`s specified by the user.
It also means that there is no need to check and propagate invalidations
across dependencies between the execution of the `Step`s, because there
is the guarantee that if a `Step` A invalidates `Step` B, another
instance of B will be executed later if some `Step` C needs it, or if
the user has added it explicitly.

When the `dla::StepManager::run()` method returns, all the `Step`s that
were successfully added to the manager have finished running.

3) Implementing a `Step`

Each `Step` has a virtual `runOnTypeSystem` method, that executes the
`Step` and returns true if some change was made, false otherwise.
`TypeSystem` for now is just a forward declaration and all the
implementations of `runOnTypeSystem` simply return true.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 7ff39039a8 Add Liveness Analysis 2021-02-02 11:23:53 +01:00
Pietro Fezzardi a96f98821c [DLA] Add AdjustStackPointerPass FunctionPass
Add a pass that computes the lowest negative offset that is summed in
each isolated function to the local stack pointer returned by a call to
revng_init_local_sp (previously added by PromoteStackPointerPass).
After the computation, all the accesses relative to the stack pointer
are recomputed as if the stack pointer was lowered by the computed
amount.

This is useful to enable the DLA to easily recover layouts that are
placed at negative offsets from the stack pointer.
The reason is that the DLA in its current form does not handle negative
offsets, but at the same time negative offsets are important to recover
the layout of the local variables on the stack.

This pass implicitly depends on running PromoteStackPointerPass.
If PromoteStackPointerPass did not run before the execution of
AdjustStackPointerPass, the latter doesn't do anything.

For demonstration purposes, AdjustStackPointerPass has been implemented
both with LLVM's legacy PassManager and the new PassManager.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi a31bdbd602 [DLA] Add PromoteStackPointerPass 2021-02-02 11:23:53 +01:00
Alessandro Di Federico 81da6947d2 Run unit tests from bin/ directory 2021-02-02 09:23:33 +01:00
Alessandro Di Federico 3277d17435 s/decompileFunctionPipeline/decompile_function/ 2021-02-02 09:22:33 +01:00
Alessandro Di Federico 06e8320849 Unit test configuration: remove debugging output 2021-02-01 18:45:39 +01:00
Alessandro Di Federico e31fc91e04 s/decompileFunction.cpp/DecompileFunction.cpp/ 2021-02-01 18:45:33 +01:00
Alessandro Di Federico 433d8a9ddc Update GenericGraph<DataFlowNode>
This commit updates the `DataFlowNode` data structure used in
`TypeShrinking` to be compatible with the newer version `GenericGraph`
provided by revng.

The change basically encompasses inverting the inheritance and dropping
CRTP.
2021-02-01 18:21:38 +01:00
Alain Carlucci f1808c9db6 TupleTree: extend FOR_EACH up to 16 arguments
This commit extends the support for the FOR_EACH macro used in
INTROSPECTION_NS to allow serialization of structs with more than
5 entries. Now it supports up to 16 entries.
2021-02-01 11:03:53 +01:00
Alessandro Di Federico 4982ba6922 KeyedObjectContainers: ensure serializability
This commit fixes a couple of bugs preventing SortedVector and
MutableSet from being serialized.
Also, it introduces minimal testing for serialization.
2021-01-28 17:45:14 +01:00
Alessandro Di Federico 0e3bf6c340 Merge branch 'feature/gcbi-new-pm' 2021-01-28 17:13:16 +01:00
Antonio Frighetto 99274f1a41 GCBI: create wrappers to support old and new PM
The GeneratedCodeBasicInfo class has been disentangled in order to
create wrappers to support both the legacy and the new pass manager.
2021-01-28 17:03:31 +01:00
Antonio Frighetto eacc0b76b2 Refactor GCBI
Changes include:
- `getFunctionCall` has been moved in IRHelpers.h
- `getFallthrough` and `getFunctionCallCallee`
  have been simplified and added in IRHelpers.h (their old versions
  have been removed respectively from FCI.h and revng.h)
- `FCI::getCall` and `FCI::isCall` have been removed
  due to redundancy with `getFunctionCall`.
2021-01-28 17:03:30 +01:00
Antonio Frighetto 2283e0a4e7 Move isMarker-related helpers in IRHelpers.h 2021-01-28 17:02:17 +01:00
Antonio Frighetto 29ee916559 FCI: drop findPostDominatedCall and cfg
Unmaintained code has been removed.
2021-01-28 16:03:02 +01:00
Alessandro Di Federico dcb7f3f9f3 Merge branch 'feature/import-preliminary-model' 2021-01-27 20:09:11 +01:00
Massimo Fioravanti 8ba9930638 Invert inheritance of GenericGraph nodes
GenericGraphs no longer require CRTP.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 256ba44158 Make revng-all-binaries depend on support-*.ll 2021-01-27 19:46:53 +01:00
Alessandro Di Federico b544e214b8 ProgramCounterHandler: CSVs are internal
This commit fixes a bug that lead to be unable to instantiate from a
`Module` `ProgramCounterHandler`. The reason for this was that
`ProgramCounterHandler` was using `Module::getGlobalVariable` which, by
default, ignores variables with internal linkage.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico a655507a0c Use relative paths during builds 2021-01-27 19:46:53 +01:00
Alessandro Di Federico 38031f2f8a Import preliminary model
This commit imports:

* support for (de-)serializing tuple-like objects in YAML
* the Model data structure
* the {Load,Serialize}ModelPass
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 28cb935d39 ZipMapIterator: handle dishomogeneous containers
ZipMapIterator can now handle containers of different type, as long as
their keys are comparable.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico 8aab914037 Import MutableSet and SortedVector
These data structures are substitutes for a `std::map<Key, Value>` where
`Key` is embedded in `Value`. Their main goal is to be serializable in a
YAML sequence while preserving the order enforced by the key.

`MutableSet` is implemented using a map.
`SortedVector` is implemented using a sorted vector.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico e72bcf796f Simplify MetaAddress::operator== 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 7a560adbfa MetaAddress: drop std::less specialization 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 6359edebb7 GenericGraph: Node::has{Successors,Predecessors} 2021-01-26 17:44:21 +01:00
Alvise de Faveri 9eb9e9b1a1 ADT: fix neighbor constness for GenericGraph
Problem:
1. `ForwardNode::getConstNeighbor` returns a reference to a non-`const`
    object, but the referenced pointer is `const`
2. `FowardNode::toNeighborRange` checks if the type of the argument is
const, but since `Successors` is not declared const the resulting
`toNeighborRange(Successors)` is never executed in the const version

Solution:
1. Make `getConstNeighbor()` return a reference to a `const` pointer
2. Explicitly declare a separate `toNeighborRange()` function which
returns a `const_child_iterator` and remove the template parameter
2021-01-26 17:41:58 +01:00
Alessandro Di Federico 3d9f10307d Force Mach-O entry point to be code 2021-01-24 18:37:35 +01:00
Filippo Cremonese c5680b2120 Refactor revng-merge-dynamic
Notable changes:

- Split in multiple files the existing revng-merge-dynamic script
- Add the option to merge additional LOAD segments in the resulting
  binary
- Align the new .dynstr to a 4 byte boundary
- Ensure the last verneed entry is marked as such (vn_next == 0)
- Ensure LOAD PHDRs are listed in ascending order,
  as mandated by ELF spec
2021-01-23 00:41:52 +01:00
Pietro Fezzardi d91ca93b5b MakeEnvNull: fix env substitution
Before this commit, `MakeEnvNullPass` was substituting uses of `env`
with uses of `nullptr`.
This operation was introducing undefined behavior, and subsequent
optimizations were allowed to mark BasicBlocks where it occured as
unreachable, eventually leading to their wrong removal.

This commit fixes the substitution, properly replacing loads from `env`
with `nullptr`.
This should never cause undefined behavior anymore, because the results
from load from `env` is never referenced in isolated functions.
2021-01-22 17:23:55 +01:00
Alessandro Di Federico 09f4477ac7 Merge branch 'feature/various-fixes' 2021-01-06 17:46:47 +01:00
Alessandro Di Federico 4d1f681a44 Add RelocationTypes R_X86_64_{64,32} 2021-01-06 17:40:56 +01:00
Alessandro Di Federico 8549844d36 Set BaseAddress to 0x400000 by default 2021-01-06 17:40:56 +01:00
Alessandro Di Federico 28432e30c1 Disable HARD_FLAGS_* when invoking linker
This commit is necessary in order to avoid using the compiler wrapper
provided by orchestra when developing.
2021-01-06 14:40:27 +01:00