Commit Graph

1006 Commits

Author SHA1 Message Date
Alessandro Di Federico b190dc07da Introduce constructors
Isolated functions return structs. These structs used to be constructed
using `IRBuilder::CreateAggregateRet`, which is implemented using
`insertvalue` instructions. However, this approach led to ugly
decompiled code.

This commit introduces "constructor" functions that can be easily
pattern matched down the pipeline.
2021-03-23 12:54:05 +01:00
Alessandro Di Federico 73853ab679 Introduce --invoke-isolated-functions
This commit ensures that FunctionIsolation and EnforceABI do only
thing. This means that they no longer modify `root`.

Instead, we have a new pass, `invoke-isolated-functions` that needs to
be run after them and replaces the entry point of the functions with
invokes to the isolated functions, possibly with the appropriate
arguments.
2021-03-23 12:49:11 +01:00
Alessandro Di Federico b0f9f69908 Adopt EliminateUnreachableBlocks 2021-03-23 12:48:47 +01:00
Alessandro Di Federico 1d43949c7b scripts/revng: handle same library multiple times
The `revng` script looks in several paths for analysis
libraries. However, before this commit, in case multiple versions of the
same library were available, you'd get unpredictable results.

This commit ensures that each library is considered at most once, in the
right order.
2021-03-23 12:47:00 +01:00
Alessandro Di Federico bd41eab558 Drop setNoInline from invokes
This is no longer necessary, since we now use invoke instructions
properly and it's no longer possible to demote them to calls.
2021-03-23 12:45:13 +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
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 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
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
Alessandro Di Federico c1c2a3ef90 Merge branch 'feature/model' 2021-02-23 10:41:30 +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
Alessandro Di Federico 93b7420c8a Implement model::Function::dumpCFG 2021-02-19 09:39:49 +01:00
Alessandro Di Federico 82605514c4 model: prepare for ABI information
This commit also drops some dead code and fixes Model tests accordingly.
2021-02-19 09:39:49 +01:00
Alessandro Di Federico 6cfcd087b7 Introduce ProgramCounterHandler::loadPC 2021-02-18 19:13:06 +01:00
Alessandro Di Federico 8952ca3cc1 IRHelpers.h: introduce createFunctionType 2021-02-18 18:46:49 +01:00
Alessandro Di Federico 575a0d6a6d IRHelpers.h: introduce isHelper 2021-02-18 18:46:49 +01:00
Alessandro Di Federico 0ebb32f25e GCBI: make certain methods static 2021-02-18 18:46:49 +01:00
Alessandro Di Federico ee9f2192f3 KOC::batch_insert: return newly created object 2021-02-18 18:46:49 +01:00
Alessandro Di Federico 2d22b31d00 revng-all-binaries: depend on early-linked-module-* 2021-02-18 18:46:49 +01:00
Alessandro Di Federico a314fd61ef Import revng-dump-model 2021-02-18 18:46:49 +01:00
Alessandro Di Federico e9ca81247d Improve get*FromYAML*
This commit fixes the following issues:

1. It introduces `getNameFromYAMLEnumScalar` which returns a
   `llvm::StringRef` instead of a `std::string`.
2. Lets users decide what to do when `getValueFromYAMLScalar` does not
   get any match (abort by defaul, or return an "Invalid" value).
2021-02-18 18:44:42 +01:00