Commit Graph

3168 Commits

Author SHA1 Message Date
Alessandro Di Federico 04633a21ca Tag call sites with CallToLifted 2021-12-17 18:49:26 +01:00
Alessandro Di Federico 09914e56cf model::Type::dump: upcast 2021-12-17 18:48:52 +01:00
Alessandro Di Federico ca899c96f5 Debug output: pad before ] 2021-12-17 18:48:44 +01:00
Alessandro Di Federico 9a60a5fd82 Expand IRHelpers
* New `getCallTo` overloads accepting `Function *`
* `setInsertPointToFirstNonAlloca`
* Various additional helpers for Load/StoreInst
* `changeFunctionType`
2021-12-17 18:48:36 +01:00
Alessandro Di Federico 6fcf1673c9 Adopt eraseFromParent 2021-12-17 14:01:28 +01:00
Alessandro Di Federico f38cc9ea06 Drop AdjustStackPointer 2021-12-17 14:01:22 +01:00
Alessandro Di Federico cdc05640b8 DLA: handle the extra argument for stack arguments 2021-12-17 14:01:05 +01:00
Alessandro Di Federico 24f5515842 Import passes of the new stack promotion pipeline 2021-12-17 14:01:00 +01:00
Alessandro Di Federico 58f114f19f Introduce libSupport 2021-12-17 14:00:05 +01:00
Alessandro Di Federico d733640143 Ensure functions begin with allocas only
Mixin `alloca`s with other instructions is malpractice.
2021-12-17 13:50:46 +01:00
Alessandro Di Federico f51808be24 Review PromoteStackPointerPass
* Adjust stack pointer upon returning from call.
  In architecture where the return address is pushed on the stack, on
  the caller side, we see the the push but not the pop. This means that,
  once the stack pointer is no longer global, we need to take this into
  account.
  This commit fixes this increase the stack pointer of
  `FinalStackOffset` right after a function call.
* Drop the size argument from the `revng_init_local_sp` function.  We
  will have a `revng_stack_frame` function to represent the actual stack
  frame pointing to its beginning.
2021-12-17 13:50:46 +01:00
Alessandro Di Federico 01e4fb7f88 Minor changes to PromoteStackPointerPass 2021-12-17 13:50:46 +01:00
Alessandro Di Federico 8a337a4525 DLA: ignore loops with trip count 0 2021-12-17 13:50:46 +01:00
Alessandro Di Federico 54e9a96a03 PromoteStackPointer: do not force stack alignment 2021-12-17 13:50:46 +01:00
Pietro Fezzardi 39ec9a32ee DLAMakeLayouts: drop too strict assertion
This assertion was conceived to check that DLADeduplicateUnionFields was
doing its job, ensuring that we never created a union with only one
field.

However, the assertion is too strict, and there are situation that union
deduplication cannot handle and that still generate a union with one
single field. Here's an example

    Node A, with Interfering Children
       Instance Edge -> Node B
       Offset 12 Edge -> Node C

    Node C
       Offset 12 Edge -> Node D

    Node C: uint32_t

    Node D: uint32_t

Hence we need to remove the assertion.
2021-12-17 11:02:14 +01:00
Alessandro Di Federico 1dbe474873 Whitespace fixes 2021-12-16 11:56:06 +01:00
Antonio Frighetto 10f45c593a Move StackAnalysis to EarlyFunctionAnalysis 2021-12-15 18:03:30 +01:00
Antonio Frighetto ffd5ac7f57 Drop old StackAnalysis 2021-12-15 18:03:30 +01:00
Antonio Frighetto 10704a8981 EFA: build prototype and finalize model 2021-12-15 18:03:30 +01:00
Antonio Frighetto 92591d42c3 EFA: propagate interprocedural results 2021-12-15 18:03:30 +01:00
Antonio Frighetto 35311dcf14 Integrate EarlyFunctionAnalysis with ABIAnalyses
Integrate results of ABIAnalyses in EarlyFunctionAnalysis
and refine such results by suppressing stack pointer
and callee-saved registers from the analyses.
2021-12-15 18:03:30 +01:00
Qian Matteo Chen 886e58553b Introduce new ABIAnalyses
Architecture-agnostic and ABI-independent data-flow analyses that
traverse the recovered functions in order to detect arguments and
return values registers.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 74a35bca10 Introduce new EarlyFunctionAnalysis
An architecture-agnostic analysis that attempts to detect
boundaries of functions, recover the control-flow graph as
well as function prototypes (arguments and return values)
of the original program. The analysis determines whether
the function jumps to its return address (namely, it is a
regular function), it tracks the evolution of the stack
by determining its height (in order to say if the stack is
left in a correct position upon stackframe destruction),
and it identifies callee-saved registers.
2021-12-15 18:03:30 +01:00
Antonio Frighetto a574f3c8e3 Introduce AAWriterPass
A simple pass that adds aliasing scope information as
comments to the IR before load and store accesses.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 14f0e9ed09 Introduce IndirectBranchInfoPrinterPass
A simple pass that serializes the results of the StackAnalysis on disk.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 4ed08d1e94 Introduce SegregateDirectStackAccessesPass
A pass which segregates direct stack accesses from all other
memory accesses through appropriate alias information metadata.
By doing so, we provide a way to say that stack accesses reasonably
do not interfere with any other memory access. This pass also tries
to canonicalize `inttoptr` + `add` instructions into `getelementptr`s
so as to avoid the use of `inttoptr`, which would otherwise inhibit
compiler optimizations.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 215dab9dd2 Introduce CSVAliasAnalysisPass
A pass that decorates memory accesses with
information about CSV aliasing.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 9a59cee319 Introduce PromoteGlobalToLocalPass
A simple pass that promotes the CSVs to local variables.
2021-12-15 18:03:30 +01:00
Antonio Frighetto e9439a15e5 Introduce RemoveHelperCallsPass
A simple pass that removes the calls to the helpers and replaces them
with stores of an opaque value onto the CSVs clobbered by the helper.
2021-12-15 18:03:30 +01:00
Antonio Frighetto ba49937a69 Introduce RemoveNewPCCallsPass
A simple pass that removes the calls to `newpc` marker.
2021-12-15 18:03:30 +01:00
Antonio Frighetto cbd81e57d9 Improve MFP 2021-12-15 18:03:30 +01:00
Antonio Frighetto 976398aeb6 ProgramCounterHandler: emit branches separately
When generating a conditional branch with fallthrough and `anyPC`
basic block, make sure branches are emitted in distinct blocks.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 47fa41d784 ProgramCounterHandler: add dissectJumpablePC
The new method `dissectJumpablePC` provides information about the
PC CSVs and allows not to make architecture-specific assumptions.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 8328575839 IRHelpers: refactor getPC
Dead code removal and various fixes while refactoring `getPC`.
2021-12-15 18:03:30 +01:00
Antonio Frighetto b5f87748eb PromoteCSVs: no wrapper for Marker and Exceptional 2021-12-15 18:03:30 +01:00
Antonio Frighetto 34580789eb BinaryFile: add architecture-dependent fields
Add return address register and minimal final stack offset in Arch.
2021-12-15 18:03:30 +01:00
Antonio Frighetto 20211fc3f6 DwarfImporter: exclude empty names 2021-12-15 18:03:30 +01:00
Antonio Frighetto f1ac5e4075 Model: handle NoReturn functions in CallEdge 2021-12-15 18:03:30 +01:00
Antonio Frighetto 034618d228 FunctionIsolation: fix object passed by copy 2021-12-15 18:03:30 +01:00
Alessandro Di Federico 4401871489 FunctionIsolation: handle NoReturn attribute 2021-12-15 18:03:30 +01:00
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
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
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