Commit Graph

6113 Commits

Author SHA1 Message Date
Alessandro Di Federico 09e483f96b BinaryImporter: create a Function for EntryPoint 2024-08-16 13:01:59 +02:00
Alessandro Di Federico cba1d6fa51 PDBImporter: fix .pdb path lookup 2024-08-16 13:01:57 +02:00
Pietro Fezzardi 0a082c3f32 Merge branch 'feature/cycle-equivalence' 2024-08-12 12:43:23 +02:00
Andrea Gussoni eeca8f781c GenericGraph: introduce Undirected
Introduce the `Undirected` GraphTraits, which treats a `MutableEdgeNode`
`GenericGraph` as an undirected graph.

The trait uses the newly introduced `UndirectedChildIterator`, which is
a special custom iterator to get successors and predecessors
concatenated together.

Add some unit tests for `UndirectedChildIterator`.
2024-08-12 12:32:45 +02:00
Andrea Gussoni c32a4776ab GenericGraph: edge traits for llvm::Inverse 2024-08-12 12:32:45 +02:00
Andrea Gussoni 5f7a67c8af CycleEquivalence: implement analysis
We introduce the `CycleEquivalence` analysis.

This is an analysis which implements the _Cycle Equivalence_ computation
algorithm, and provides as result the _cycle equivalence classes_
Specifically, we introduce:
- The `CycleEquivalenceClass`, which is the unitary element computed by
  the analysis.
- The `CycleEquivalenceAnalysis`, which contains the algorithm to
  compute the cycle equivalence.
- The `CycleEquivalencePass`, a `FunctionPass` that can be used to
  perform the analysis on a `llvm::Function`.

The algorithm is composed by various stages:
- We construct a new `GenericGraph` object, replicating the input CFG,
  with the addition of the `exit`->`entry` edge.
- Taking advantage of `llvm::GraphTraits<Undirected<>>`, we can now
  implement the algorithm working on an undirected version of the input.
- We perform the `CycleEquivalence` computation, returning a
  `llvm::SmallVector` of `CycleEquivalenceClass` objects.

In addition to using the `llvm::GraphTraits<Undirected<>>` traits to
walk on the equivalent undirected graph, we also need to:
- Perform a preliminary DFS, in order to:
  - Assign the DFS number to each node in the graph.
  - Compute the spanning tree, and use this information to distinguish
    tree edges and back edges when running the algorithm.

The internal graph used by the analysis also normalizes the graph in
order to have a sinle exit node (called sink), which is a requirement
for the `CycleEquivalence` algorithm.

We also implement the `llvm::DOTGraphTraits` for the
`CycleEquivalenceAnalysis<llvm::Function *>` specialization. In this
way, we can have a graphical representation of the undirected graph used
internally in the `CycleEquivalenceAnalysis` core implementation.

We add some `FileCheck` tests on some well-known graph topologies.
2024-08-12 12:30:54 +02:00
Alessandro Di Federico 9cca30976d docs/*.rst: add warning 2024-08-07 16:08:00 +02:00
Alessandro Di Federico 99149c1b36 Drop revng lift 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 024c9abda2 Step: fix use-after-free 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 744184c90c Do not use CallBase::getCalledFunction
Use our wrapper, which does not return nullptr if the `FunctionType`s do
not match.
2024-08-07 16:07:59 +02:00
Alessandro Di Federico c92c109424 revng artifact: error out if step has no artifact 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 05b6989274 FunctionPass: add tracing 2024-08-07 16:07:59 +02:00
Alessandro Di Federico ae7e7a0bc7 IsolateFunctions: add tracing 2024-08-07 16:07:59 +02:00
Alessandro Di Federico ee2d2e25c6 InlineHelpers: add tracing 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 80237078e4 setMetaAddressMetadata: use MDString 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 09bc315448 Pipeline: improve invalidation logging 2024-08-07 16:07:59 +02:00
Alessandro Di Federico 0cb3eedd37 Do not use CallBase::getCalledFunction
Use our wrapper, which does not return nullptr if the `FunctionType`s do
not match.
2024-08-07 15:40:56 +02:00
Alessandro Di Federico 9408f4f465 ImportLLVMToMLIRPipe: adopt getMetaAddressMetadata 2024-08-07 15:40:56 +02:00
Ivan Krysak 336fac0a67 ABI: do not assert when offset is not aligned
Abort the conversion instead.
2024-08-06 10:26:34 +02:00
Alessandro Di Federico d3b945c6c2 PECOFFImporter: use Generic Segment::StartAddress 2024-08-05 18:00:27 +02:00
Alessandro Di Federico fa6249edc0 Isolate: add FunctionTag to declared functions 2024-08-05 17:42:04 +02:00
Alessandro Di Federico 15d72e580d MetaAddress::address*: simply ignore Type 2024-08-05 17:41:41 +02:00
Alessandro Di Federico 7b00473859 PDBImporter: rework .pdb search 2024-08-05 17:41:34 +02:00
Alessandro Di Federico d50e7e9451 revng artifact: anticipate artifact name check 2024-07-25 17:44:03 +02:00
Alessandro Di Federico b096da3b4b revng-c-pipelines.yml: add early-type-shrinking 2024-07-10 17:24:56 +02:00
Alessandro Di Federico ce305b41dc Merge branch 'feature/type-shrink-shr' 2024-07-10 17:24:15 +02:00
Alessandro Di Federico f87ba8a0d3 Introduce TypeShrinking tests 2024-07-10 16:19:27 +02:00
Alessandro Di Federico effc91689c Introduce early-type-shrinking 2024-07-10 16:19:27 +02:00
Alessandro Di Federico 06023b4555 BitLivenessWrapperPass::dump 2024-07-10 16:19:26 +02:00
Alessandro Di Federico f83f40078c Invalidation tests: relax
At this stage, certain artifacts are invalidated by any change, even an
empty one.
2024-07-10 16:19:26 +02:00
Alessandro Di Federico 7ddae47040 Minor changes 2024-07-10 15:34:19 +02:00
Alessandro Di Federico 5f312e8998 Merge branch 'feature/fix-revng-artifact-targets' 2024-07-09 14:35:23 +02:00
Alessandro Di Federico 3f60b74a28 fetch-debuginfo: soft fail if no network 2024-07-09 12:02:31 +02:00
Alessandro Di Federico df8f4db512 MachOImporter: set DefaultABI 2024-07-09 08:58:51 +02:00
Alessandro Di Federico 901a78a66f Lift: fix usage of empty instead of isEmpty 2024-07-09 08:58:51 +02:00
Alessandro Di Federico 6f47a8af5a MaterializedValue: ignore alloca 2024-07-09 08:58:51 +02:00
Alessandro Di Federico 3c839cb821 Pipe::mutableContainers: use running containers 2024-07-09 08:58:51 +02:00
Alessandro Di Federico 966caa4137 revng artifact: fix handling of target arguments
This commit adds to `revng artifact` help the part of the command line
accepting a list of targets.
Also, it fixes the parsing of targets.
2024-07-09 08:58:51 +02:00
Alessandro Di Federico 1981f5a433 Minor changes 2024-07-09 08:58:51 +02:00
Pietro Fezzardi dc8d57e520 Merge branch 'feature/re-enable-tests' 2024-07-05 09:50:37 +02:00
Pietro Fezzardi e1b5541462 DLA: depotentiate SimplifyInstanceAtOffset0
The DLAStep SimplifyInstanceAtOffset0 now only triggers if the parent
node has the child-at-offset-0 node as its only successor, or when the
child-at-offset-0 doesn't have other predecessors.

Doing this guarantees that it's impossible for another predecessor of
the child-at-offset-0 to start seeing memory accesses that were
initially relative to the parent.

This condition is slightly more restrictive than the previous one, but
it takes into consideration some far reaching consequences.
If SimplifyInstanceAtOffset0 aggressively like we did before, DLA can
end up inferring types in some memory locations, like executable
segments, for which there aren't clues in the binary.
This isn't bad per se, but if DLA does that, the newly recovered type is
identified as non-executable data, causing misdecompilation because
rev.ng doesn't decompile memory regions that it understands as non
executable.

This commit, making SimplifyInstanceAtOffset0 less aggressive, makes it
play better with the rest of the assumptions of the decompilation
pipeline.

It also relaxes a decompilation test that was previously working by
chance and that was effectively beyond the current expressive power of
reasoning for DLA at the moment.
2024-07-05 00:43:45 +02:00
Pietro Fezzardi 8311efb21c DLA: re-enable DeduplicateFields after fixing it 2024-07-05 00:43:35 +02:00
Pietro Fezzardi 99d4c0283a DLA: fix DeduplicateField traversal and comparison
Before this commit the breadth-first traversal was more convoluted and
it used a broken criterion for bailing out, resulting sometimes in
considering a pointer edge as if it was an instance edge.
This in turn caused bugs to the point of the DLA Graph failing
verification.

This commit rewrites and simplifies the main traversal and comparisons
in DeduplicateField to make them robust against these bugs.
2024-07-05 00:43:35 +02:00
Pietro Fezzardi 19d43cde1d Partially re-enable end-to-end tests
End-to-end tests were disabled due to a bug in ModelToHeader that caused
the decompiled C header with the types not to be recompilable in some
cases.

However, the commit that disabled the tests was too aggressive, because
the only part that needed to be disabled was the part of the tests that
actually recompiled the C code.

This commit re-enables the end-to-end tests except for the recompilation
part, that will be re-enabled after the bug in ModelToHeader is fixed.
2024-07-04 02:56:31 +02:00
Alessandro Di Federico 71b7fae69d revng --version: emit component hashes 2024-06-30 19:36:48 +02:00
Ivan Krysak 22b9a4db74 Restore an accidentally deleted test 2024-06-30 19:36:48 +02:00
Pietro Fezzardi 4562232281 Merge branch 'feature/demo-recon' 2024-06-27 17:34:19 -04:00
Pietro Fezzardi 70b75e9ac3 Merge branch 'feature/demo-recon' 2024-06-27 17:32:22 -04:00
Pietro Fezzardi 521baf38e8 PTML: honor GeneratePlainC 2024-06-27 17:30:56 -04:00
Pietro Fezzardi dfe3f4cb47 Rename revng C headers for decompiled code
Strip away the 'revng-' prefix from the filename.
2024-06-27 17:26:18 -04:00