Commit Graph

20 Commits

Author SHA1 Message Date
Alessandro Di Federico b190dc07da Introduce constructors
Isolated functions return structs. These structs used to be constructed
using `IRBuilder::CreateAggregateRet`, which is implemented using
`insertvalue` instructions. However, this approach led to ugly
decompiled code.

This commit introduces "constructor" functions that can be easily
pattern matched down the pipeline.
2021-03-23 12:54:05 +01:00
Alessandro Di Federico 73853ab679 Introduce --invoke-isolated-functions
This commit ensures that FunctionIsolation and EnforceABI do only
thing. This means that they no longer modify `root`.

Instead, we have a new pass, `invoke-isolated-functions` that needs to
be run after them and replaces the entry point of the functions with
invokes to the isolated functions, possibly with the appropriate
arguments.
2021-03-23 12:49:11 +01:00
Alessandro Di Federico bd41eab558 Drop setNoInline from invokes
This is no longer necessary, since we now use invoke instructions
properly and it's no longer possible to demote them to calls.
2021-03-23 12:45:13 +01:00
Alessandro Di Federico c2d6631216 LoadModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico 27b58695a1 Let FunctionIsolation and EnforceABI use the Model 2021-02-19 09:39:49 +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
Pietro Fezzardi cd9bc34d9d Enforce new include conventions 2020-11-13 10:00:24 +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 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
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
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
Alessandro Di Federico dc48188f37 Introduce MetaAddress
`MetaAddress` replaces all the `uint64_t` used to represent a virtual
address. Its main features are:

* It has a non-zero representation of invalid addresses.
* It supports tags to represent code that has different interpretations but
  resides at the same address in memory (namely ARM vs Thumb).
* Arithmetic operations cannot overflow.
* It supports epochs, a way we intend to employ to handle self-modifying code
  (i.e., different code at the same address at different times).
* It supports "address spaces", which enable handling architectures with
  multiple address spaces.
* It fits in two 64-bit registers.
2020-05-14 11:58:18 +02:00
Alessandro Di Federico 0eb1bb583f Remove TerminatorInst
LLVM 9 drops the `TerminatorInst` class. This commit replaces it with
`Instruction` where possible and asserts
`Instruction::isTerminator()`. It also switches from
`TerminatorInst::successors` to `successors(TerminatorInst *)`.
2019-11-21 20:50:55 +01:00
Alessandro Di Federico 357d88377d EnforceABI: Killer branches are noreturn 2019-05-27 19:36:12 +02:00
Alessandro Di Federico c232e20be8 s/func.entry/revng.func.entry/ leftover 2019-05-27 19:36:12 +02:00
Alessandro Di Federico b7ce437469 EnforceABI: completely ignore the stack pointer 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 6ae3b6f22f Whitespace and other minor changes
* `GeneratedCodeBasicInfo::getCSVUsedByHelperCall` and
  `GeneratedCodeBasicInfo::extractCSVs`: make the call argument an
  `Instruction`.
* Introduce `blockByName`
* Introduce `getUniqueUser`.
* Fix linking issues.
2019-05-14 16:27:13 +02:00
Alessandro Di Federico d50fbe969a Update documentation and add revng. to metadata 2019-04-11 19:51:32 +02:00
Alessandro Di Federico 5dc8056b8c Introduce enforce-abi pass
This commit introduces the `enforce-abi` pass, which consumes the
information provided by the ABI analysis and enforces them in the
isolated functions adding actual arguments.

This commit also rewrites the logic of `ResultsPool::finalize` and
changes the semantic of `Yes` statements on arguments to `YesOrDead`.
2019-03-08 15:00:59 +01:00