Commit Graph

181 Commits

Author SHA1 Message Date
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
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
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
Massimo Fioravanti 8ba9930638 Invert inheritance of GenericGraph nodes
GenericGraphs no longer require CRTP.
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 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 54ea92cfec Introduce GCBI::programCounterHandler 2020-12-31 14:37:53 +01:00
Alessandro Di Federico d3247870f0 Reorganize ProgramCounterHandler construction 2020-12-31 14:37:53 +01:00
Antonio Frighetto 02b3a24463 Jump to dispatcher when location is invalid
Replace a call to `abort` with a branch to `dispatcher` when the
callee is unknown or invalid (namely, it is always treated as an
indirect call).
2020-12-31 14:17:30 +01:00
Pietro Fezzardi 7ff24ac761 GCBI: remove assertion on Dispatcher != nullptr
This assertion was executed in the `runOnModule` method of the GCBI
pass, but it is too strict.

Asserting that Dispatcher != nullptr during the execution of the pass
prevents the pass from successfully running on a Module without a
Dispatcher.
This is unfortunate, because some passes that depend on GCBI in revng-c
actually do that. They do so because they are not really interested in
the Dispatcher at all. They only use GCBI to access information on the
Stack Pointer.

In fact, the check for Dispatcher being != from nullptr is already
performed also in the `dispatcher()` method which is the sane thing to
do. This commit removes the assertion from the `runOnModule` method and
leaves it in the `dispatcher` method.
This allows to run the pass successfully even on a Module without the
Dispatcher, while not changing the contract of this pass (i.e. that when
you call the `dispatcher` method you get a nonnull pointer).
2020-12-29 14:51:38 +01:00
Pietro Fezzardi 9869f057b9 Use #pragma once for header include guards 2020-11-13 14:12:18 +01:00
Pietro Fezzardi cd9bc34d9d Enforce new include conventions 2020-11-13 10:00:24 +01:00
Alessandro Di Federico 14cf2a399d Make assertion messages prettier 2020-11-12 16:39:03 +01:00
Alessandro Di Federico 5e7d288530 Introduce PruneRetSuccessors pass
This commit introduces the PruneRetSuccessors pass, whose role is to
identify all the indirect jumps whose devirtualized destinations
correspond to return addresses. In fact, they are most likely to be
return instructions and devirtualizing them is always detrimental.
2020-11-12 15:28:31 +01:00
Alessandro Di Federico d609c2e74d ABI Analysis: more verbose logging 2020-11-12 15:15:27 +01:00
Alessandro Di Federico 5f25194ec8 IncoherentCallsAnalysis: introduce Logger 2020-11-12 14:56:05 +01:00
Antonio Frighetto cd4a8dcf79 StackAnalysis: remove cleanup in mergeASState
After combining two AS objects, removing an ASOContent in the cleanup
phase may lead to a mismatch in the CSVs promoted to function argument,
with some registers actually being used. In most cases, this results in
promoting only one or few alive registers as function argument.
2020-11-12 14:56:03 +01:00
Pietro Fezzardi fc537a2fc7 Add missing MIT license headers 2020-11-12 14:55:57 +01:00
Alessandro Di Federico 29080a2f29 StackAnalysis: resetCacheMustHit on right entry
We used to accidentaly call `resetCacheMustHit` on the just popped
element of the set, resulting in an out-of-bounds access within the
container.

This bug has been spotted thanks to AddressSanitizer.
2020-11-12 14:55:57 +01:00
Alessandro Di Federico cf5fca85a1 Whitespace changes 2020-11-12 14:55:56 +01:00
Andrea Gussoni 9c910604fd EnforceABI: add opaque store to PC after call
Add an additional opaque store the the `pc` after each function call in
the enforced functions. In this way, when the `pc` will be promoted to
an alloca, we won't have an inconsistent state of the IR (the callee
cannot propagate the correct value of pc, the safety check introduced by
the function isolation will always be false, and llvm will place a
`llvm.assume` which will in turn make the rest of the code dead and
purged by an additional `-simplifycfg`).
2020-11-08 20:52:03 +01:00
Alessandro Di Federico 10d3561212 StackAnalysis: disable expensive assertions 2020-11-06 10:59:00 +01:00
Alessandro Di Federico d0a61e7947 Add logger to dump CFEPs 2020-11-06 10:59:00 +01:00
Alessandro Di Federico 6bfae0409b FunctionIsolation: drop isolate-no-safety-checks
This commit drops the `--isolate-no-safety-checks` flags since we
adopted a new approach later on in the decompilation pipeline, i.e.,
dropping calls to `raise_exception_helper` and running dead code
elimination.
2020-11-02 11:21:32 +01:00
Alessandro Di Federico ccb0b183a5 FunctionIsolation: member.type, not function_call
FunctionIsolation used to base its work on calls to the marker function
`function_call`, as opposed to information provided by the StackAnalysis
(i.e., `revng.member.type` along with `func.call`).

This also affected EnforceABI, which took care of finishing the work
left over by FunctionIsolation. This was hackish and inelegant.

This commit makes FunctionIsolation work exclusively employing
information from StackAnalysis and purges away code that is no longer
necessary from EnforceABI.
2020-11-02 11:21:07 +01:00
Alessandro Di Federico 7f90bc4fe0 StackAnalysis: callee saved must pass by the stack
We used to detect callee-saved registers only by checking if their final
value was identical to the initial one. However, the need for a more
precise heuristic emerged: we now also check if at least on of the stack
slots contains that same value.
2020-11-02 09:05:12 +01:00
Alessandro Di Federico dd774af288 ABIAnalysis: merge DefaultMap::Default last
This commit fixes a subtle bug that was preventing us from correctly
considering the effects of function calls during ABI analysis.

Specifically, when merging information from the call site to the caller,
in case the caller did not provide any information about a certain
slots, we used the `DefaultMap::Default` field, which is the correct
thing to do, except for the fact that, in two methods, the `Default`
field was being updated to early.

This basically had the effect of not considering arguments of function
calls as used, e.g., in URAOF.
2020-11-02 09:05:12 +01:00
Alessandro Di Federico dd29699aed FunctionsSummary: print the callee too 2020-11-02 09:05:12 +01:00
Alessandro Di Federico 51b29afc30 Make ABIAnalysis mandatory 2020-11-02 09:05:12 +01:00
Andrea Gussoni 02a4970fa6 EnforceABI: outline function_dispatcher on flag
When the `--enforce-no-safety-checks` flag is passed during the
enforcing, we avoid emitting the inlined `function_dispatcher` and we
emit instead a call to an `indirect_handle` disposable call created on
the fly to respect the ABI information on the callsite.
2020-10-30 14:17:57 +01:00
Alessandro Di Federico bf2ac34b38 FunctionSymbol blocks are tier-1 CFEPs 2020-10-30 09:10:00 +01:00
Alessandro Di Federico 5791429f91 ABIIR: prune on finalization
Under certain conditions, we ended up having code in the ABI IR which
was not reachable. This was due to the fact that a certain instruction
was initially detected as an indirect call, triggering inclusion in the
function of the fallthrough code, and then as a return, which has no
successors within the function.

This commit simply prunes the ABI IR in the finalization method.
2020-10-24 17:40:54 +02:00
Alessandro Di Federico 0e4c4aad59 Make --use-debug-symbols the default 2020-10-21 10:34:34 +02:00
Pietro Fezzardi 05e34ef6f9 Add functions to get installed resource files 2020-10-05 14:09:53 +02:00
Antonio Frighetto 11e9203de9 StackAnalysis: storing Type in copy() method
`FunctionType::Values Type` was not copied when returning an `IFS`
object. This issue was addressed by adding `Type` to `Result` as well.
2020-10-01 18:17:53 +02:00
Pietro Fezzardi a94371cca2 EnforceABI: promote CSV in ConstantExprs casts
EnforceABI promotes global variables representing parts of the CPU
states to arguments and return values of isolated functions.

This commit enables the promotion of CSV that are used in isolated
functions only indirectly, through `ConstantExpr`s casts.
2020-10-01 18:17:53 +02:00