Commit Graph

3168 Commits

Author SHA1 Message Date
Pietro Fezzardi bb1f2d629e CDecompilerPass: cleanup clang::tooling invocation 2021-03-03 19:02:33 +01:00
Pietro Fezzardi 9846e9f3bf Use MainCategory instead of RevNgCategory 2021-03-03 14:57:26 +01:00
Pietro Fezzardi e95c21db25 Use Model to detect isolated functions 2021-02-23 10:39:05 +01:00
Alessandro Di Federico 27b58695a1 Let FunctionIsolation and EnforceABI use the Model 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 0f7de0c2e0 Call to noreturn functions are not killer
We used to mark call to noreturn functions as killers, but this is not
correct.

Note that this is a temporary solution, we need to explicitly handle
such situations.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 137c8b9752 StackAnalysis: factor out successors enumeration 2021-02-19 09:39:49 +01:00
Alessandro Di Federico d0a78a41bf Drop direct branches to the dispatcher
Generated code now either jumps to `anypc` or `unexpectedpc`. The latter
one is to be considered a safety measure and will be populated with an
unreachable instruction on the decompilation pipeline.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico b5065e1e8d StackAnalysis: expose FakeReturns 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 151e711cde Review PCH::getUniqueJumpTarget
This commit makes `PCH::getUniqueJumpTarget` more robust:

1. We bail out only if we find a non-constant write to a field of
   `MetaAddress` for which we already have a value. Before, any
   non-constant write would lead to bailing out.
2. In case we meet an helper, we now bail out only if we didn't saw any
   write to a portion of the `MetaAddress`.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico f2c83d2f67 Introduce PlainMetaAddress
This commit extracts a plain `struct` from the `MetaAddress` class. This
enables us to use `MetaAddress` from C and therefore, runtime.

The definition of such `struct`, `PlainMetaAddress`, is in
`PlainMetaAddress.h`, which is included by `early-linked.c`.

A function to print the content of a `PlainMetaAddress` has also been
introduced.

Also, anticipating the linkage of `early-linked.c` triggered a
superflous assertion in `CPUStateAccessAnalysis`. This commit removes
it.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico df11232fe1 Improve GCBI
* Introduce GCBI::buildDispatcher
* Introduce GCBI::getJumpTarget{,Block} and GCBI::getBlocksGeneratedByPC
  to easily map `BasicBlock *` to jump targets and viceversa.
* PCH::buildDispatcher now returns a list of the newly created basic
  blocks.
* Other minor changes
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 93b7420c8a Implement model::Function::dumpCFG 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 82605514c4 model: prepare for ABI information
This commit also drops some dead code and fixes Model tests accordingly.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 6cfcd087b7 Introduce ProgramCounterHandler::loadPC 2021-02-18 19:13:06 +01:00
Pietro Fezzardi 448d7366ac Small lib to detect isolated functions using Model 2021-02-18 11:59:05 +01:00
Pietro Fezzardi cc65e946cb RestructureCFG: fix exit dispatcher to backedges 2021-02-18 11:59:05 +01:00
Pietro Fezzardi b23cf45fd9 RestructureCFG: refactor entry and exit dispatcher 2021-02-18 11:59:05 +01:00
Pietro Fezzardi 444663ed94 RestructureCFG: refactor logging of MetaRegions 2021-02-18 11:59:04 +01:00
Pietro Fezzardi 1616b9d0ab Fix checkMetaRegionConsistency
This function was intended to check that backedges are entirely enclosed
inside metaregions, i.e. that we cannot have a backedge jumping from a
metaregion to an outer or an inner one.

Before this commit, the assertion was tautological.
2021-02-18 11:59:04 +01:00
Pietro Fezzardi 9a4bb33bfe RegionCFG: refactor simplifySCSAbnormalRetreating 2021-02-18 11:59:03 +01:00
Pietro Fezzardi 2998494d18 RegionCFG: use meaningful names for dummy nodes
This helps debugging.
2021-02-18 11:59:03 +01:00
Alessandro Di Federico 685dbfd3f7 Whitespace and other minor changes 2021-02-18 08:48:39 +01:00
Pietro Fezzardi 10b90d6e15 SerializeModelPass: static method to write Model 2021-02-17 11:37:00 +01:00
Pietro Fezzardi 645484f699 LoadModelPass: add static function to read Model 2021-02-17 11:37:00 +01:00
Pietro Fezzardi eda6e60330 decompileFunction: run only on isolated functions 2021-02-11 16:25:42 +01:00
Pietro Fezzardi 148119c528 PromoteStackPointer: make local sp aligned 2021-02-09 15:07:04 +01:00
Pietro Fezzardi 2820fc395c Fix emission of (?:) with ptr type and int args 2021-02-04 18:09:53 +01:00
Pietro Fezzardi f722224a09 Emit return statements returning a ConstantStruct 2021-02-04 16:01:26 +01:00
Pietro Fezzardi b98228eed0 Fix generation of bool typedef in C 2021-02-04 14:33:41 +01:00
Pietro Fezzardi ec86afdc5a decompileFunction: run doFinalization at end 2021-02-03 16:20:44 +01:00
Pietro Fezzardi 5b57a206d0 ASTBuildAnalysis: handle pointer operands from DLA
When DLA is activated, a larger variety of combinations between integers
and pointers operands need to be handled when emitting C code from LLVM
Instructions.
This commit removes some assertions that do not hold anymore about some
operands not being pointers, handles a set of new cases with strange
mixtures of pointer and integer operands, and introduces a fail path for
cases that are not handled when emitting code based on DLA results.
2021-02-03 12:37:24 +01:00
Pietro Fezzardi 6ad6d5294d Fix getPointedLayouts for struct types
Before this commit, we assumed that given a Value V, if only a single
entry was found for in ValueLayouts, it meant that is was a scalar type.

This assumption was wrong, because it could be a struct type for which
we didn't have information about memory access for all fields but one.
This caused some struct type to be wrongly identified as scalar types.

This commit fixes the issue.
2021-02-03 12:13:14 +01:00
Pietro Fezzardi 4b50946d60 DLACreateIntraProcedualTypes: create less pointers
Before this commit, the creation of layouts in the DLA was very
aggressive, treating almost every instruction as if it could be an
address (hence creating a layout for it).

This commit adds assertions and narrows down the number of cases where
an instruction is actually considered an address.
Specifically, the following kinds of instructions are not considered
addresses anymore:
  - Mul
  - SDiv
  - UDiv
  - SRem
  - URem
  - AShr
  - LShr
  - Shl
  - And
  - Xor
  - Or
2021-02-03 12:07:28 +01:00
Pietro Fezzardi 7a1b11a83d DecompilationHelpers: improve int->ptr casts
Before this commit, we assumed integer-to-pointer casts were only
widening, never narrowing.
Turns out this is not true. For instance, narrowing casts happen when
decompiling s390x code.

With this commit, the decompiler can handle that case gracefully.
2021-02-03 12:03:29 +01:00
Pietro Fezzardi dc84daf7e8 DLATypeSystem: add assertion on mergeNodes
The mergeNodes API is not guaranteed to work properly if the 2 merged
nodes are the same.
This commit adds an assertion to rule this situation out.
2021-02-03 12:00:04 +01:00
Pietro Fezzardi 42b9fb97e7 Drop static storage specifier for globals 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 4cf69e8edd ASTBuildAnalysis: fix emission of comparison ops 2021-02-02 11:23:53 +01:00
Pietro Fezzardi c02db52709 IRASTTypeTranslation: fix bug in getPointedLayouts 2021-02-02 11:23:53 +01:00
Pietro Fezzardi ad70251a7f SCEVBaseAddressExplorer: fix exploration of Values
A logical bug prevented to properly identify some leaf Values in SCEVs
as base addresses, restricting such Value leaves to only be CallInst to
isolated Functions.
This commit fixes this bug and enables to identify base addresses that
are not CallInst.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi b33e9385fe ASTBuildAnalysis: add draft of member accesses
This commit is just a skeleton. In order to actually build those member
accesses, we still need to compute the proper nested dla::Layouts for
which we want to emit those member accesses.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 6c0cc326a4 Fix comment 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 4767fa63c3 Fixed emission for local_sp and scev_barrier
This commit fixes a bug due to interacting behaviors between
MarkForSerialization, AddSCEVBarrierPass, and the emission in C of calls
to revng_init_local_sp.

These interacting behaviors caused the following quirks:
- At the beginning of Functions that contained a call to
  `revng_init_local_sp()`, that call was actually emitted twice.
  The first time was due to the actual call to `revng_init_local_sp()`,
  while the second was due to the first call being wrapped from a call
  to `revng_scev_barrier_*`.
  Now we properly emit only one call.
- The original call to `revng_init_local_sp()` was supposed to generate
  a local variable, to be used in various places across the function.
  However, due to the fact that the call was not properly labeled by
  MarkForSerialization, there was no local variable, causing calls to
  `revng_init_local_sp()` to be scattered around the body of the
  functions, follwed by various arithmetic operations.
  This behavior has been fixed as well, and we now emit the local
  variable correctly.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi ba0e57e956 DeclCreator: unify type mapping 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 2485cd2c8b DLAHelpers: relax assumptions on ExtractValueInst
Before this commit, the DLA code made very strong assumptions about
Functions that returned struct types.
In particular, calls to such Functions were expected to have at most a
number of uses equal to the number of fields of the returned struct.
Moreover, such uses were only expected to be ExtractValueInst.

Now, we still assume that such uses are ExtractValueInst, but we don't
make any strong assumption on their number anymore.

This makes the DLA code less reliant on specific form of LLVM IR, so we
can also drop -gvn-hoist from the decompilation test pipeline.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 56fe5c95c3 New Typeable type
This type represents all llvm constructs to which we may want to
associate a type.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 821b430f40 Collapse FunctionDecls map into GlobalDecls map 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 6de169e138 MarkForSerialization: new LatticeElement
This commit introduces a new LatticeElement for the
MarkAnalysis::Analysis MonotoneFramework.

Before this it used a IntersectionMonotoneSet.
This commit extends the set transforming it into a map, that holds the
set of Instructions with side-effects that taint each pending
instruction.

This is not used yet. The behavior is identical to the old one.
It will be used in future commits to prevent serialization when
possible, to increase the quality of emitted C code, thanks to the fact
that serializing less instructions means less local variables in C.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 3f1ee6ea64 Stub of DLA integration in Clang AST emission 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 3b3dbc3a8b Add end-to-end tests for AddSCEVBarrierPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 7987eccecd ASTBuildAnalysis: handle nested InsertValueInst 2021-02-02 11:23:53 +01:00