Commit Graph

3168 Commits

Author SHA1 Message Date
Pietro Fezzardi 8fa8ca2d03 Rework getWriteableModel to return a TupleTree
The previous design returned a model::Binary &, which did not allow
users writing the model to properly initialize cross references between
different parts of the model.
2021-07-15 13:30:25 +02:00
Alessandro Di Federico 6d10581163 Whitespace and other minor changes 2021-07-15 13:30:25 +02:00
Alvise de Faveri 4eb50d0bb5 Add Unit Test for DLACollapseSingleChild 2021-06-30 17:50:12 +02:00
Alvise de Faveri c1e4b940d0 Add CollapseSingleChild step to DLA 2021-06-30 17:50:12 +02:00
Alvise de Faveri 47db3fdb11 Promote AccessSizes to full-fledged TS nodes
While doing thie, also drop `printAccessNode()` from DLA DebugPrinter.

The information about which LLVM instruction originated a given access
node is already available in the csv generated by the `dla-accesses-log`
logger.
2021-06-25 18:07:17 +02:00
Pietro Fezzardi d09c7c6ab3 Handle inheritance in with interfering children
Until now, in makeLayout, inheritance edges were ignored when the
children were interfering.
Now the inheritance edges are treated as if they were instance edges at
offset 0.
2021-06-24 17:24:59 +02:00
Pietro Fezzardi 18bff2dba1 DLAMakeLayouts.cpp: drop unused variable 2021-06-24 17:24:59 +02:00
Pietro Fezzardi 6a2e130ec6 Move openFunctionFile to new Utils library 2021-06-21 14:15:30 +02:00
Alvise de Faveri bfdef657f2 Move DLA files to separate folder 2021-06-18 18:24:04 +02:00
Alvise de Faveri 105edb69a3 DLA: Decouple DLATypeSystem from LLVM Values
- Remove `CreateInterProceduralTypes` and `CreateIntraProceduralTypes`
  from the StepManager and put them in a separate
  `DLATypeSystemLLVMBuilder` object that is in charge of initializing
  the DLATypeSystem graph.
- Remove `MakeLayouts` from the StepManager and split into two free
  functions: `makeLayouts` and `makeLayoutMap()`
- Remove all LLVM-related stuff (Module, LayoutTypePtrs and mappings
  between these and DLATypeSystemNodes) from DLATypeSystem
- Add an IntEqClasses member to DLATypeSystem, to use to map between
  LayoutTypePtrs and Layouts
- Add a TSDebugPrinter object inside the DLATypeSystem, which by default
  prints only IDs
- Define an LLVMTSDebugPrinter inside DLATypeSystemBuilder which
  overrides the default printer's behavior, printing LLVM-related info.
- Add the possibility to dump into a .csv file the bindings between
  Nodes in the TypeSystem and `llvm::Value`s
2021-06-18 18:12:14 +02:00
Pietro Fezzardi f0a6184ac0 Propagate DebugLoc on CallInst and InvokeInst
With llvm-12 thera are more stringent requirement on the propagation of
DebugLoc on CallInst and InvokeInst.
Various CallInst and InvokeInst created during lifting did not fulfill
these requirements, causing the Module to not verify() with llvm-12.

This commit fixes the problem, properly propagating the debug locations.
2021-06-14 23:04:02 +02:00
Pietro Fezzardi 370dfdaf13 Update InlineFunction API to LLVM-12 2021-06-14 23:04:02 +02:00
Antonio Frighetto 1e68b6e665 EnforceABI: drop handleRoot
Unmaintained code has been removed.
2021-06-09 18:39:43 +02:00
Matteo Giordano 04c5b5c5c3 MetaAddress.cpp: fix on fields processing order
Adjusted methods `MetaAddress::toConstant()` and
`MetaAddress::fromConstant()` in processing the order of MetaAddress
field.
2021-06-09 18:14:16 +02:00
Ivan Krysak bc8c8f82d2 Prevent separation of 'main' headers into group 0
The prevention mechanism uses a dummy suffix:
'_THIS_SEQUENCE_IS_NEVER_GOING_TO_HAPPEN'.
2021-06-09 18:05:20 +02:00
Pietro Fezzardi dfd81a017d Use std::has_single_bit and std::bit_ceil 2021-06-09 14:37:37 +02:00
Pietro Fezzardi 260df31adc ASTBuildAnalysis.cpp: fix emission of ternary 2021-05-31 12:23:32 +02:00
Pietro Fezzardi 65907f892f decompileFunction: add pass required by llvm-12 2021-05-28 17:45:59 +02:00
Pietro Fezzardi 2fea7e3076 TypeFlowGraphWriter: update to llvm-12 API 2021-05-27 17:14:25 +02:00
Pietro Fezzardi 36e42855a5 PromoteStackPointer.cpp: fix deprecated include
This caused compilation error with llvm-12.
2021-05-27 17:14:25 +02:00
Pietro Fezzardi 9d3216970a IRASTTypeTranslation: handle new llvm-12 types 2021-05-27 17:14:25 +02:00
Pietro Fezzardi 80f1e2fd6d Explictly convert llvm::StringRef to std::string
Implicit conversion is not available anymore in llvm-12.
2021-05-27 17:14:25 +02:00
Pietro Fezzardi a5b42ea913 DLATypeSystem.cpp: update scc_iterator API 2021-05-27 17:14:25 +02:00
Pietro Fezzardi a63d1768ee DLACreateIntraProceduralTypes: add missing include 2021-05-27 17:14:25 +02:00
Pietro Fezzardi 8494034931 ASTBuildAnalysis.cpp: explicitly handle new kinds 2021-05-27 17:14:25 +02:00
Pietro Fezzardi 73ee5e8c34 Update to clang-12 API for AST creation 2021-05-27 17:14:25 +02:00
Pietro Fezzardi 798ea21963 Replace constprop with instsimplify
Constant Propagation has been dropped by llvm-12
2021-05-27 16:07:49 +02:00
Pietro Fezzardi 3436ed4125 DLATypeSystem.h: add missing include
This was causing compilation error with llvm-12
2021-05-27 15:04:03 +02:00
Alvise de Faveri e8dfaa3a86 DLA: Fix missing AccessLayout field in structs
The BaseLayout should be the fist field of each StructLayout, but it
is never really added.
2021-05-21 18:50:58 +02:00
Pietro Fezzardi 13170f0a2a DLARemoveTransitiveInheritanceEdges: fix UAF
Accessing NextChildPos is not safe if Pushed is true.
This commit switches the conditions so that NextChildPos is never
accessed unsafely thanks to short-circuiting.
This fixes a use-after-free bug, that was activate when calling tryPush
triggered realloc on the Stack.
2021-05-19 10:31:07 +02:00
Pietro Fezzardi 7b59291576 Add custom destructor for dla::LayoutTypeSystem
This prevents from leaking nodes when destroying the LayoutTypeSystem
itself.
2021-05-19 10:31:07 +02:00
Pietro Fezzardi e4c857185f LayoutTypeSystem: fix memory leak
Not calling the destructor of LayoutTypeSystemNode before their
deallocation was leaking pairs of Successors and Predecessors.

This commit fixes it by explicitly destructing LayoutTypeSystemNodes.
2021-05-19 10:31:07 +02:00
Pietro Fezzardi 7d4a1ba467 DLATypeSystem: fix use-after-poison false positive
This commit fixes a use-after-poison false-positive report from ASAN.

This was due to misuse of SpecificBumpPtrAllocator together with
__asan_poison_memory_region.
The region was poisoned but not deallocated, which caused a the false
positive when trying to destroy and deallocate it in the destructor of
LayoutTypeSystem.

This was fixed by switching to plain BumpPtrAllocator, and properly
calling the Deallocate method, which wraps its own battle-tested ASAN
logic.
2021-05-18 12:15:53 +02:00
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
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 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 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 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 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 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
Alessandro Di Federico 9650369fa7 Import TupleTree and TupleTreeReference 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 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