Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi 9fc389fd58 DLAHelpers: fix use-after-free with short-circuit
NextEdgeToVisit is not safe to use if StartNew is true.
Using short circuit the code is now safe.
2021-05-18 11:46:01 +02:00
Alessandro Di Federico b150274a1f Import overview document 2021-05-14 13:45:00 +02:00
Pietro Fezzardi 461b1cc715 DLATypeSystem: simplify ownership, lookup, removal
Before this commit DLATypeSystem used a
std::set<std::unique_ptr<LayoutTypeSystemNode> to hold nodes, allowing
heterogenous lookup with bare pointers, fast removal being a set,
and providing address stability without requiring an ordering between
LayoutTypeSystemNodes.

The same requirements is now obtained more cleanly using with a
BumpPtrAllocator for nodes, and a set of naked pointers to them to
enable fast lookup and removal.
2021-05-14 11:23:40 +02:00
Pietro Fezzardi 981274d0b3 LayoutTypeSystem: drop unused overload mergeNodes 2021-05-14 11:23:40 +02:00
Pietro Fezzardi 2b73e29249 Decouple LayoutTypeSystemNode from LLVM IR 2021-05-14 11:23:40 +02:00
Pietro Fezzardi 7be0e6ab23 Drop redundant functions dumpToString
They have been substituted with `print` methods, that are more general.
The `dumpToString` is emitted automatically with a template in a revng
header, for those classes that already have the `print` method anyway.
2021-05-14 11:23:40 +02:00
Alvise de Faveri 6fbf5724d1 Add Value Manipulation Analysis 2021-05-14 11:18:14 +02:00
Alessandro Di Federico 5a002a6fc9 Merge branch 'feature/various-bugfixes' 2021-05-12 18:59:56 +02:00
Alessandro Di Federico 0af0fea277 Handle R_386_32 relocations 2021-05-12 18:42:17 +02:00
Alessandro Di Federico 5878fee3e2 Make PCH::addCaseToDispatcher more efficient
Checking if a `SwitchInst` has a certain case triggers a linear search.
When we have *a lot* of jump targets this is an issue.

This commit assumes that when we add a case to a dispatcher, that case
is not already there.
2021-05-12 18:42:13 +02:00
Alessandro Di Federico ec0a1c7d3e Fix dispatcher.external
`dispatcher.external` used to jump to itself due to a misuse of
`replaceAllUsesWith`.
2021-05-12 18:42:08 +02:00
Alessandro Di Federico 10eb8e498a AVI: handle Undef
Also, be more verbose on an unexpected instruction.
2021-05-12 18:31:23 +02:00
Alessandro Di Federico 9be97248ce Reorganize VariableManager
This commit slightly improves VariableManager's API and, most
importantly, undef-initializes all TCG variables in order to avoid
creation of complex PHIs.
2021-05-08 19:27:57 +02:00
Alessandro Di Federico cfddcceb3e IRHelpers: non-const getModule(...) 2021-05-08 19:27:57 +02:00
Alessandro Di Federico 82260c2693 Make dumping assembly and PTC optional
Output files can become *very* large.

This commit disables by default dumping disassembled instructions and
PTC code into the IR.
2021-05-08 19:27:57 +02:00
Alessandro Di Federico 91991bb694 Handle PHIs in lifted code
In large binaries PHI nodes show up. As a consequence, calls to `newpc`
are no longer the first instruction.

This commit uses the `getFirstNonPHI` method to fix this issue.
2021-05-08 19:19:41 +02:00
Alessandro Di Federico c04a30e703 Model: fake functions have no blocks 2021-05-08 11:39:10 +02:00
Alessandro Di Federico 1ac2884f2e Handle blocks ending with unreachable
Sometimes basic blocks end with an
2021-05-08 11:39:10 +02:00
Alessandro Di Federico 871931b9cd Test TupleTreeDiff on Model
`TupleTreeDiff` was not being tested.

This commit implements several `operator==` that are required to
successfully instantiate `TupleTreeDiff`.
2021-05-06 15:42:16 +02:00
Alessandro Di Federico e62f888381 Drop KeyTraits
This commit drops the KeyTraits in favor of a std::any-like solution.
Basically, we type erase any key the user wants to employ, just exposing
a virtual version of the destructor, a comparison operator and a clone
primitive.
2021-05-06 15:42:00 +02:00
Alessandro Di Federico 9fb066a87f Use TupleTree<model::Binary> 2021-05-06 10:37:56 +02:00
Alessandro Di Federico bf433d96f8 Drop rc_run
Recent updates in recursive coroutines handling no longer requires the
`rc_run` macro.
2021-05-06 10:37:56 +02:00
Pietro Fezzardi e34426c03e Decompiler: handle PHINode with StructType 2021-05-06 10:37:56 +02:00
Pietro Fezzardi b58693b8e8 RecursiveCoroutine: enable direct continuation
Before this commit, the execution logic of RecursiveCoroutine used an
underlying std::stack allocated on the heap to hold all the
coroutine_handles. It also manually managed passing return values from
callees to callers.

This commit drops this unnecessary auxiliary stack.
When a RecursiveCoroutine co_awaits another one, the handle of the
awaiter is injected into the awaitee, so that when the awaitee is done
it can directly execute the remaining part of the awaiter as a
continuation.
2021-05-05 17:48:04 +02:00
Alessandro Di Federico bca502aeaa Merge branch 'feature/extend-model' 2021-05-05 17:13:16 +02:00
Alessandro Di Federico 7e637beef3 Import static TupleTree validation routines 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 9650369fa7 Import TupleTree and TupleTreeReference 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 0d77258109 Introduce HasKeyObjectTraits concept 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 508bc4eb00 Minor changes 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 6fd8a87572 TupleTree, visit: rename and make more usable 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 51682eb024 model::FunctionEdge: carve out CallEdge 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 582dee6fcc TupleTree: support UpcastablePointer 2021-05-05 17:10:12 +02:00
Alessandro Di Federico 702f4230ac Import UpcastablePointer 2021-05-05 17:10:12 +02:00
Alessandro Di Federico a6468d8d22 Minor changes 2021-05-05 17:10:12 +02:00
Pietro Fezzardi 50681284c0 Conceptify revng
Use concepts across revng wherever possible, to keep the code concise
and easier to understand.
2021-05-05 17:10:12 +02:00
Alessandro Di Federico dde698e201 Merge branch 'feature/inline-helpers' 2021-05-03 18:32:06 +02:00
Alessandro Di Federico 2c7fa21065 Enable -inline-helpers 2021-04-30 14:52:25 +02:00
Alessandro Di Federico 0c671ea7ae Introduce RemoveExceptionalCalls
RemoveExceptionalCalls is a simple pass whose goal is to drop all the
calls to functions marked as `Exceptional` and replace them with an
`UnrechableInst`.

This is mainly useful in the decompilation pipeline.
2021-04-30 14:52:25 +02:00
Alessandro Di Federico ce87c30490 Introduce InlineHelpers
InlineHelpers is a simple pass that recursively inlines all the
functions belonging to the section `revng_inline` in isolated functions.
2021-04-30 14:52:25 +02:00
Pietro Fezzardi b6327b0526 PromoteCSVs: fix CSV list initialization 2021-04-30 14:52:25 +02:00
Pietro Fezzardi 223d022968 replaceFunction: preserve metadata 2021-04-30 14:52:25 +02:00
Pietro Fezzardi 49a493ebbb DLA: handle extractvalue from struct_initalizers 2021-04-29 15:16:08 +02:00
Pietro Fezzardi 80b1a9e7fa Add RemoveLLVMDbgIntrinsicsPass
This pass removes all llvm debug intrinsics from the IR.
It is enabled by default in all decompilation pipelines.
2021-04-29 03:06:58 +02:00
Pietro Fezzardi 0cd27eed3f Drop loads from cpu_loop_exiting 2021-04-29 03:04:39 +02:00
Pietro Fezzardi 5aaff6a524 AddSCEVBarrierPass: handle barriers on struct ptrs 2021-04-28 18:14:41 +02:00
Pietro Fezzardi 4202117d84 Merge branch 'next-develop' into develop 2021-04-27 22:51:15 +02:00
Pietro Fezzardi 3be9d0a9a1 Fix missing parenthesis around ConditionalOperator 2021-04-27 21:19:06 +02:00
Pietro Fezzardi 572e04751f CDecompilerAction: fix parens in negateExpr 2021-04-27 21:19:06 +02:00
Pietro Fezzardi cdb8f84f48 DLA: Handle StructInitializers 2021-04-27 21:19:06 +02:00
Pietro Fezzardi 39eb322820 FilterForDecompilation: mark Functions optnone
Before this commit we dropped the body altogether. This was bad because
dropping the body of a Function also clears metadata, preventing the
propagation of FunctionTags from revng.

Now all the functions that are not isolated are simply marked optnone
noinline, so that all the optimizations we do for decompilation are only
restricted to isolated functions.
2021-04-27 21:19:06 +02:00