Commit Graph

6113 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 4b3562edce Handle failure of ptc_mmap 2020-11-12 14:55:57 +01:00
Pietro Fezzardi fc537a2fc7 Add missing MIT license headers 2020-11-12 14:55:57 +01:00
Alain Carlucci 42e8f8db02 revng-lift: Enable LLVM stack trace on kill signal
This commit enables LLVM stack trace mechanism when a kill signal is
raised.
2020-11-12 14:55:57 +01:00
Alessandro Di Federico 864bcdc471 scripts/revng: add --lldb 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 c7e0361acf scripts/revng: handle empty ASAN_OPTIONS 2020-11-12 14:55:57 +01:00
Alessandro Di Federico cf5fca85a1 Whitespace changes 2020-11-12 14:55:56 +01:00
Alessandro Di Federico 0b15c965ce scripts/revng: use subprocess.Popen directly
We used to use `subprocess.run`, but it's not supported in Pytnon 3.2
(Debian 7).
2020-11-10 10:04:31 +01:00
Alessandro Di Federico 37fde04594 Move licensing details to LICENSE.md 2020-11-09 10:03:33 +01:00
Alessandro Di Federico 6e68453d9c Assign copyright to rev.ng Srls 2020-11-09 08:52:51 +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 acb896e934 PE/COFF: consider ImageBase as code 2020-11-06 22:14:44 +01:00
Pietro Fezzardi 5de14227cf Improve generation of valid C identifiers
This commit does not implement real mangling yet, but it should at least
get most low-hanging fruits, to prevent generation of invalid C
identifiers.
2020-11-06 15:08:42 +01:00
Andrea Gussoni 6c8eb2fd53 ASTTree: remove Successor in sequence creation
When the `Successor` field is consumed to create the `Sequence` nodes,
we blank the field so that we do not have redundant information in our
graph representation.
2020-11-06 15:08:00 +01:00
Andrea Gussoni 1bade3fd88 ASTTree: delete sequence nodes in simplification
When performing `atomicSequenceSimplification`, actually remove the
nodes from the ASTTree.
2020-11-06 15:08:00 +01:00
Andrea Gussoni 5afaa7a90b ASTTree: AST debug printing is now iterative
Change the AST debug printing from a recursive descent on the AST nodes
in the graph, to an iterative printing of respectively nodes and their
outgoing edges.

Also, we now print the edge going to the `Successor` field, if present.
2020-11-06 15:08:00 +01:00
Andrea Gussoni f3f11533b8 ASTTree: Reorganize AST dot printing
Reorganize the AST dot printing in order to use LLVM facilities for
files handling. In addition, clean up the code, and add a function
(useful in debug) in order to dump the dot of and AST from GDB (accepts
a `char *` instead of a `std::string`.
2020-11-06 15:08:00 +01:00
Andrea Gussoni f3df7e2ab1 Fix inclusion order 2020-11-06 15:08:00 +01:00
Andrea Gussoni e6e5c73f62 ASTTree: Remove old version of dumpASTOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni df0985f1fc RegionCFG: dumpOnFile to dumpASTOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni eb1ddab86c RegionCFG: dumpDotOnFile to dumpCFGOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni 7362e7beeb RegionCFG: Reorganize graph debug
Now, when the `debug-log=restructure` flag is active, debug graphs are
organized in a more rational way.

First of all, all the graphs are now put in a single directory, and are
divided first by function name and then by type.

Also, as in the case of the tiling debug graphs, their name is more
consistent with the rest of the codebase.
2020-11-06 15:08:00 +01:00
Pietro Fezzardi e0c5bba880 Drop UnitTestHelpers.h, now shipped by revng 2020-11-06 15:08:00 +01:00
Pietro Fezzardi 217a18edb1 Update copyright notice 2020-11-06 15:07:45 +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 124d5e88b1 Merge branch 'function-isolation-use-func-call' 2020-11-06 10:58:18 +01:00
Pietro Fezzardi 04acd0f6e5 Remove check-conventions.sh: shipped by revng now 2020-11-06 10:17:23 +01:00
Pietro Fezzardi 890d60833b Drop old obsolete RemovePCStoresPass 2020-11-04 09:42:13 +01:00
Pietro Fezzardi 8bfbb153ca libDecompiler: new public API decompileFunction 2020-11-04 09:32:36 +01:00
Pietro Fezzardi b5bea3c30b Add new decompilation pipeline to tests 2020-11-04 09:32:36 +01:00
Pietro Fezzardi f127764e0b CDecompilerBeautify: fix beautification of IfNodes
This commit fixes two interacting problems in the beautification of if
statements.

First, in `simplifyShortCircuit`, there were two assertion on null
pointers that were too strict. These assertions didn't take into
consideration that one among the "then" and the "else" branch of an
`IfNode` could be simplified away _during_ the beautification itself.

Second, a previous commit had moved the execution `flipEmptyThen` after
the two beautification of short-circuit, leading to assertions failed
in `simplifyTrivialShortCircuit`.
This was caused by the fact that `simplifyTrivialShortCircuit` only
never expected `IfNode`s with empty "then".
This was fixed by running `flipEmptyThen` also before
`simplifyTrivialShortCircuit`.
2020-11-04 09:32:36 +01:00
Pietro Fezzardi 90ff17f107 Fix handling of switch default in GHAST 2020-11-04 09:32:36 +01:00
Andrea Gussoni 6a8a1b613d Combing: fix conditional node edge inlining
Before marking any outgoing edge as inlined, check that the exit nodes
reachable from each successor of the conditional node are two disjoint
sets.
2020-11-04 09:32:36 +01:00
Pietro Fezzardi 508719ad97 HACK: remove assertion on NDuplicates
This commit is a hack, that removes an assertion on NDuplicates.
For now we can remove this check, because we declare all the local
variables at the beginning of the function body.
Whenever we start emitting the declarations of local variables
as-late-as-possible, we'll need to take care of this.
2020-11-03 13:50:20 +01:00
Pietro Fezzardi 87611643ad Fix names of struct types declarations
Before this commit, we assigned names to struct types without looking at
the function names of which they were return types.
Now we do, so that the name of the generated type for the function `f`
is `f_ret_type`.

This also fixes errors when reparsing the generated C code, where the
names of the struct types did not match.
2020-11-03 12:53:11 +01:00
Andrea Gussoni 371dc7ea97 Remove exceptions before decompilation in pipeline
We now craft a new decompilation pipeline. We remove the exceptions
introduced as fallbacks to preserve the semantics, and we perform passes
of `dce` and `simplifycfg` to remove all the superfluos basic block
remaining after this change. To do this, we need an additional pass that
removes also the calls to the `llvm.assume` intrinsic, and another pass
of `dce` to remove all the dead uses.

In addition, we also remove dead stores to the `cpu_loop_exiting` global
variable in order to improve the decompiled code.

As a byproduct of this, we remove also the dependency from the
`-remove-pc-stores` pass, since its jobs is included by the changes
mentioned above.
2020-11-02 18:33:57 +01:00
Pietro Fezzardi 2e7b6d171f CDecompilerAction: use logical not in if stmts
This commit fixes some warnings due to the wrong emission of bitwise not
instead of logical not in condition of if statements.
2020-11-02 18:33:57 +01:00
Pietro Fezzardi ecd9ac991f CDecompilerAction: fix print of conditional blocks
This commit fixes an issue that caused to emit duplicated statements
for BasicBlocks that terminated with a conditional branch.
This was caused by a redundant call to `buildStmtsForBasicBlocks()`
inside `createCondExpr`, that has now been removed.
2020-11-02 18:33:57 +01:00
Pietro Fezzardi 2bdff9bbaf MarkForSerialization: fix ExtractValueInst
With this commit `ExtractValueInst`s are handled so that they don't have
side effects.
This significantly improves the quality of the decompiled output,
preventing the forced serialization of all the extraction of struct
fields after calls to function that return structs, except for when it's
really needed.
2020-11-02 12:52:58 +01:00
Pietro Fezzardi 37f43f7e83 Use Value names for C declarations if possible
With this commit, the declarations of local variables and function
parameters now use the name of the associated `llvm::Value` if present,
instead of always using the prefix "param_" or "var_".
2020-11-02 12:32:22 +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
Pietro Fezzardi 99a6a18f26 createAST(): fix size of stack-allocated arrays
This commit fixes a wrong computation that caused stack-allocated arrays
to use the wrong size in bits instead of the correct size in bytes.
2020-11-02 10:43:06 +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