Commit Graph

465 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 60fdcbc66a Whitespace changes 2020-10-01 17:40:17 +02:00
Alain Carlucci 3cafe56223 MetaAddress::fromString: fix error handling
StringRef::getAsInteger() returns true on error; false on success. This
commit fixes the off-by-not.
2020-09-14 17:19:14 +02:00
Alessandro Di Federico cbe36d5267 FunctionIsolation: enable/disable safety checks 2020-09-04 23:53:00 +02:00
Alessandro Di Federico ae3c800109 Implement MetaAddress::{from,to}String 2020-09-02 18:21:07 +02:00
Antonio Frighetto 76a6403ebd FunctionIsolation: drop ExceptionFlag
ExceptionFlag has been superseded by proper use of stack unwinding.
Our custom personality routine has been replaced with the GNU GCC
personality one.
2020-08-03 22:11:06 +02:00
Alain Carlucci be9bc6ce0a MetaAddress: remove header dependency from IRBuilder 2020-06-25 14:28:07 +02:00
Alessandro Di Federico 314cae3a1e Abandon removeUnreachableBlocks
`llvm::removeUnreachableBlocks` doesn't just drop dead basic blocks,
it also turns certain `SwitchInst` into `BranchInst`, which leads to
hard-to-debug issues in parts of the code where we don't assume
unexpected changes such as this.
2020-06-23 15:01:52 +02:00
Alessandro Di Federico d8cbc86b1c Isolate: handle IndirectBranchDispatcherHelper
Function isolation used to mishandle blocks of type
`BlockType::IndirectBranchDispatcherHelperBlock`. This led to have
empty basic blocks instead of the dispatcher for handling indirect
branches.
2020-06-23 14:55:13 +02:00
Pietro Fezzardi 2fc342d2e4 Add a global public Logger: VerifyLog
Rationale: it is a widespread practice, both in revng and in projects
that depend on it, to write verification functions that check specific
properties hold after different transformations on various data
structures.
Often, these verification function are very useful for debugging and
during development, but they can be very costly and we don't want to
always execute them at runtime.

This patch adds a global public Logger, called VerifyLog, that can be
enabled with the --debug-log=verify command line argument.
This Logger is intended to be used in revng and in projects that depend
on it, as a guard for costly calls to verification functions that do not
need to be performed on a typical execution, but only when debugging.

For now the only user is JumpTargetManager, but other uses are already
envisioned.
2020-06-14 23:34:14 +02:00
Pietro Fezzardi 0eb179baf8 GCBI: relax assumptions on AnyPC and UnexpectedPC
This commit makes possible to execute the GeneratedCodeBasicInfo (GCBI)
Pass even on LLVM IR where the AnyPC and UnexpectedPC BasicBlocks are
not present.
This makes the GCBI pass more flexible, enabling more other passes to
depend on it and to use it to retrieve informations on the generated
code without architecture-dependent hacks.

As an example, one can now use GCBI to retrieve the CSV representing the
Stack Pointer Register or the Program Counter Register without relying
on the register names (which are architecture-specific), even if some
optimization pass along the decompilation pipeline has removed AnyPC or
UnexpectedPC.

Notice that the contracts of GCBI's methods has not been changed.
Calling anyPC() or unexpectedPC() still asserts that those are not
nullptr.
The contract has just been moved from the execution stage of the pass
(basically runOnModule), to the APIs used to query the results.
2020-06-14 23:33:02 +02:00
Pietro Fezzardi d39c124344 DotGraphObject: support Dom and PostDom Trees 2020-06-13 10:36:08 +02:00
Pietro Fezzardi 45516f89b8 Add Inverse GraphTraits for DotNode and DotGraph 2020-06-13 10:36:08 +02:00
Pietro Fezzardi 2bf702b74b DotGraph: add EdgeRef and ChildEdgeIteratorType
Add EdgeRef and ChildEdgeIteratorType to GraphTraits<DotNode *> and to
GraphTraits<const DotNode *>.

This allows iterating on edges of DotGraphs, which will be useful for
some testing on edge properties.
2020-06-10 00:23:54 +02:00
Alessandro Di Federico d10178483d Introduce the new MetaAddress
Unlike the previous iteration of `MetaAddress`, which tried to stuff all
the parts of `MetaAddress` within the existing `PC` CSV, this
implementation adds a set of new CSVs (or marks some existing ones as) to
represent the four portions of the current PC's `MetaAddress`.

* Introduce `ProgramCounterHandler`: a class responsible to maintain the
  PC-related CSVs. This class is also used to manipulate the new
  dispatcher.
* `AdvancedValueInfo`: update for new MetaAddress.
* External jump handler: do not clobber registers.
  When introducing support for dynamic binaries, we didn't realize that
  in x86-64 we were clobbering `r11`. To avoid this, we have to jump to
  an address stored in memory. However, due to the new `MetaAddress`,
  obtaining a *jumpable* address from the PC-related CSVs might require
  some computations (and it does in ARM). Therefore, we introduce a new
  global variable, `jumpablepc`, whose only role is to contain the
  jumpable version of the program counter and then be the target of the
  memory-indirect jump instruction.
* Labels care only about absolute addresses.
* CSAA: mark call site, even if no accesses.
2020-06-02 10:57:02 +02:00
Alessandro Di Federico b5d719efb5 Indent multiline log entries 2020-05-14 22:03:37 +02:00
Alessandro Di Federico 2e8e594304 StackAnalysis: handle UndefValue 2020-05-14 21:59:04 +02:00