Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi 7e553762b9 CDecompilerBeautify: omit more continue statements 2021-03-29 17:18:39 +02:00
Alessandro Di Federico 690e5fd9bd Update LoadModelPass usage 2021-03-16 12:01:15 +01:00
Alessandro Di Federico 45ee99d5de Merge branch 'feature/model-new-pass-manager' 2021-03-16 11:57:44 +01:00
Alessandro Di Federico 9171452342 Test instantiation of passes in new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico b25c43705c SerializeModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico c2d6631216 LoadModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico ae0a92d7e1 SymbolType::fromELF: do not abort 2021-03-16 11:36:32 +01:00
Alessandro Di Federico 1e6230b46c scripts/revng: drop print_help 2021-03-16 11:36:32 +01:00
Alessandro Di Federico 830ef23fe8 Whitespace changes 2021-03-16 11:36:32 +01:00
Alessandro Di Federico 58d0509909 scripts/revng: re-engineer option parsing
We now employ `argparse` subparsers.

This commit also fixes a bug involving global options with an argument
(such as `--prefix`) that led the argument to be interpreted as the
subcommand.
2021-03-10 12:29:25 +01:00
Pietro Fezzardi db33f74650 Tests: workaround a bug of revng arg --prefix
The --prefix option of revng has a bug that causes it to skip over the
whole command line, ignoring all the other arguments, and always
printing the help returning with success.
This means that we cannot properly detect failing tests.

Luckyly, if we use the syntax `--prefix=actualprefix` instead of
`--prefix actualprefix` the bug does not show up and we can properly run
our tests.
2021-03-09 12:36:02 +01:00
Alessandro Di Federico ae368f9302 ReversePostOrderTraversal has been moved to revng 2021-03-08 11:11:47 +01:00
Alessandro Di Federico 8cee47f8a7 Merge branch 'feature/improve-cfg-identification' 2021-03-08 10:45:30 +01:00
Alessandro Di Federico e51145ec99 script/revng: introduce --prefix
`--prefix` enables projects using revng to easily and correctly employ
libraries available in build directories organized in a install
tree-like fashion.
2021-03-08 10:37:32 +01:00
Alessandro Di Federico 1217296328 TypeShrinking has been moved to revng 2021-03-08 10:26:44 +01:00
Alessandro Di Federico 0f72a220b1 Exploit revng --prefix
Thanks to the new `revng --prefix` feature, it is no longer necessary
specify `-load` arguments to `opt` by hand.
2021-03-08 10:25:53 +01:00
Alessandro Di Federico 2c3df7068e revng-lift: keep harvesting upon new CFG edges
We used to stop the harvesting process when the harvesting process was
no longer able to identify new jump targets, even if new CFG edges have
been identified.

This approach prevented to discover additional parts of the CFG thanks
to the increased accuracy gained by a more accurate CFG. This effect is
particularly visible when we have jump tables that can be reached only
through other jump tables.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8b5a462187 AVI: use TypeShrinking
This enables us to handle situations where the comparison against the
switch value is performed on the lower 32 bits, but the address
computations uses the full 64 bits.

    cmp    edi,0x23
    ja     ...
    movsxd rdx,DWORD PTR [rcx+rdi*4]

Note that this does not solve all these situations yet.

This commit also introduces a reference output for the new
switch-jump-table-32-bit-comparison test case.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico 68e5c6c6ea AVI: drop PC initialization from cloned root
AVI used to work on a cloned root that was initializing the pc to the
program entry point. Under certain conditions, this led to DCE almost
all of the code.
2021-03-08 10:15:50 +01:00
Alessandro Di Federico d73f93f936 TypeShrinking: inject zext close to users 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 035b75d540 TypeShrinking: do not expose dependency on MFP.h 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 23470dc911 Convert TypeShrinking to new pass manager 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8f05cbf1ee Convert BitLiveness to the new pass manager 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8a5cc6a020 Import TypeShrinking 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 4780457c53 Drop StackAnalysis<false> and FBDP
This commit drops support for running StackAnalysis without ABI
analysis. This has been broken for quite some time and a source of slow
downs in (badly) crafted optimization pipelines.
2021-03-06 17:35:30 +01:00
Alessandro Di Federico 1db6e5db5b MetaAddress: handle invalid values in operator+= 2021-03-06 16:59:38 +01:00
Alessandro Di Federico 1033c15b78 ABIDetectionPass and FBDP: depend on GCBI
This commit fixes a subtle bug due to `ABIDetectionPass` and
`FunctionBoundariesDetectionPass` using methods from
`GeneratedCodeBasicInfo` (through `StackAnalysis::serializeMetadata`)
without explicitly depending on it.
2021-03-06 16:57:45 +01:00
Alessandro Di Federico 47e34bf897 Make MutableSet copiable
We were using a `std::map<const key_t, value_t>` as internal storage,
which was not copiable. This commit drops the `const`.
2021-03-06 16:56:25 +01:00
Alessandro Di Federico 86d931dc1f Update FromIRToExecutable.rst 2021-03-06 16:56:09 +01:00
Alessandro Di Federico 9cfc4e289d Update README.md
Point to orchestra and update minimal usage instructions.
2021-03-06 16:55:40 +01:00
Pietro Fezzardi b092c4f505 Add ThreadSafeClangTooling library
This library provides a thin locking wrapper around clang::tooling
invocations.
It should be used instead of performing direct clang::tooling
invocations by all programs that use revng-c and may run more than one
ClangTool concurrently.

This is necessary because clang::tooling internally uses llvm's cl::opt
for parsing command line options.
cl::opt uses a global variable for the parser under the hood so parsing
two command lines concurrently is not safe.
Similarly, cl::opt typically uses global variables to hold options, so
it is not safe to execute a ClangTool concurrently to another tool
that is parsing a new set of options, because there might be race
conditions between threads reading and writing the same options at the
same time.

The new library introduces a thin locking layer so that the end-user
does not need to know or worry about these details.
2021-03-05 16:12:41 +01:00
Pietro Fezzardi 2277bc898a Drop unused DecompilerResourceFinder
Now the decompiler does not need to find resources on disk anymore.
2021-03-05 16:12:41 +01:00
Pietro Fezzardi 81413c4b64 IRASTTypeTranslation: enable floats and bitfields 2021-03-05 16:10:00 +01:00
Pietro Fezzardi 475dc4462c Fix createTypeFromLayout for structs and unions 2021-03-05 16:10:00 +01:00
Pietro Fezzardi bb1f2d629e CDecompilerPass: cleanup clang::tooling invocation 2021-03-03 19:02:33 +01:00
Pietro Fezzardi 9846e9f3bf Use MainCategory instead of RevNgCategory 2021-03-03 14:57:26 +01:00
Andrea Gussoni ecd20d21a1 Remove dummies from the AST during simplification
Actually remove dummy nodes that are purged during the `purgeDummies`
normalization phase (which is in charge of removing dummy nodes that are
not superfluos for our AST representation).

These dummies where laying around untouched, and caused errors when
iterating over all the AST while collecting the weight after the
combing.
2021-03-03 12:35:35 +01:00
Alessandro Di Federico 6347ef5ba5 scripts/revng: --verbose reports all commands
Previously, we were reporting only those going though `wrap`.
2021-02-24 13:05:57 +01:00
Pietro Fezzardi a23a89fd61 DecompileFunction: improve test efficiency
Now we don't iterate over all the Functions in a Module, but we use the
Model to detect the first isolated function.
2021-02-23 11:09:36 +01:00
Alessandro Di Federico c1c2a3ef90 Merge branch 'feature/model' 2021-02-23 10:41:30 +01:00
Pietro Fezzardi e95c21db25 Use Model to detect isolated functions 2021-02-23 10:39:05 +01:00
Alessandro Di Federico 27b58695a1 Let FunctionIsolation and EnforceABI use the Model 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 0f7de0c2e0 Call to noreturn functions are not killer
We used to mark call to noreturn functions as killers, but this is not
correct.

Note that this is a temporary solution, we need to explicitly handle
such situations.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 137c8b9752 StackAnalysis: factor out successors enumeration 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 3f0e715b98 Decrease verbosity of tests 2021-02-19 09:39:49 +01:00
Alessandro Di Federico d0a78a41bf Drop direct branches to the dispatcher
Generated code now either jumps to `anypc` or `unexpectedpc`. The latter
one is to be considered a safety measure and will be populated with an
unreachable instruction on the decompilation pipeline.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico b5065e1e8d StackAnalysis: expose FakeReturns 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 151e711cde Review PCH::getUniqueJumpTarget
This commit makes `PCH::getUniqueJumpTarget` more robust:

1. We bail out only if we find a non-constant write to a field of
   `MetaAddress` for which we already have a value. Before, any
   non-constant write would lead to bailing out.
2. In case we meet an helper, we now bail out only if we didn't saw any
   write to a portion of the `MetaAddress`.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico f2c83d2f67 Introduce PlainMetaAddress
This commit extracts a plain `struct` from the `MetaAddress` class. This
enables us to use `MetaAddress` from C and therefore, runtime.

The definition of such `struct`, `PlainMetaAddress`, is in
`PlainMetaAddress.h`, which is included by `early-linked.c`.

A function to print the content of a `PlainMetaAddress` has also been
introduced.

Also, anticipating the linkage of `early-linked.c` triggered a
superflous assertion in `CPUStateAccessAnalysis`. This commit removes
it.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico df11232fe1 Improve GCBI
* Introduce GCBI::buildDispatcher
* Introduce GCBI::getJumpTarget{,Block} and GCBI::getBlocksGeneratedByPC
  to easily map `BasicBlock *` to jump targets and viceversa.
* PCH::buildDispatcher now returns a list of the newly created basic
  blocks.
* Other minor changes
2021-02-19 09:39:49 +01:00