Commit Graph

2939 Commits

Author SHA1 Message Date
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
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 b5065e1e8d StackAnalysis: expose FakeReturns 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 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
Alessandro Di Federico a96c6d4931 get{Name,Value}FromYAMLScalar: support quotes 2021-02-18 18:44:42 +01:00
Alessandro Di Federico 60ae42aa46 Introduce GCBI::arch() 2021-02-18 18:44:42 +01:00
Pietro Fezzardi 448d7366ac Small lib to detect isolated functions using Model 2021-02-18 11:59:05 +01:00
Pietro Fezzardi 444663ed94 RestructureCFG: refactor logging of MetaRegions 2021-02-18 11:59:04 +01:00
Pietro Fezzardi 2998494d18 RegionCFG: use meaningful names for dummy nodes
This helps debugging.
2021-02-18 11:59:03 +01:00
Alessandro Di Federico 685dbfd3f7 Whitespace and other minor changes 2021-02-18 08:48:39 +01:00
Alvise de Faveri 495e725d14 ADT: Enclose RPOExt in the llvm namespace 2021-02-17 16:50:32 +01:00
Alessandro Di Federico 49287e9de7 Improve Model and TupleTree
This commit:

* Drops `KeyTraits::toString`: if needed, use `getNameFromYAMLScalar`.
* Makes many methods in TupleTree.h return `nullptr` or `std::optional`
  in order to gracefully handle failures.
* Provides `KeyTraits` specializations for integral types and tuple-like
  composed by types providing `KeyTraits`.
* Introduces `CompositeScalar`, which enables tuple-like objects to be
  YAML-serializable scalars by joining the YAML-serialization of its
  members through a customziable character.
* Implements `PathMatcher`, a very simple "regular expression" mechanism
  for paths on tuple trees.
* Introduce testing for the Model.
2021-02-17 11:48:46 +01:00
Alessandro Di Federico 071cce12f6 KeyTraits::toInts: handle invalid MetaAddress 2021-02-17 11:46:46 +01:00
Alessandro Di Federico e382f40119 get*FromYAML* handle scalars and enumeration 2021-02-17 11:45:28 +01:00
Alessandro Di Federico 7f86530e74 MetaAddress::verify: handle invalid types 2021-02-17 11:44:23 +01:00
Pietro Fezzardi 10b90d6e15 SerializeModelPass: static method to write Model 2021-02-17 11:37:00 +01:00
Pietro Fezzardi 645484f699 LoadModelPass: add static function to read Model 2021-02-17 11:37:00 +01:00
Pietro Fezzardi 8ffcd49dd2 RecursiveCoroutine: fix reference arguments
Before this commit, recursive coroutines did not work properly if they
had out arguments with reference type.
The reason is that `rc_run` was inferring the type of its arguments from
the arguments themselves, not from the prototype of the recursive
coroutine.

Hence, code snippets like the following did not work properly, because
`rc_run` was taking x by value, not by reference.

```
RecursiveCoroutine<void> accumulate_on_i(int &i) {
  // ...
}

int f() {
  int x = 0;
  rc_run(accumulate_on_i, x);
  return x;
}
```

This commit fixes the problem. Now the arguments of `rc_run` are
properly forwarded to the recursive coroutine.
2021-02-17 11:37:00 +01:00
Alain Carlucci 8e275ed957 ADT: Add SerializableGraph 2021-02-09 22:44:01 +01:00
Alain Carlucci f3d755e0ff TupleTree*.h: add missing include 2021-02-08 12:25:34 +01:00
Alain Carlucci 557ee758e6 MetaAddress: enable quoting on YAML serialization
Enable quotes around MetaAddress during serialization, since ':' is a
valid YAML separator, which causes wrong deserialization when a vector
of MetaAddress is serialized as a list
2021-02-08 12:25:12 +01:00
Pietro Fezzardi f01fe2ec7a MarkForSerialization: fix needsVarDecl 2021-02-05 15:45:11 +01:00
Pietro Fezzardi 904aab0f6f LayoutTypePtr: drop friend struct std::less
This was necessary before defaulting operator<=>, now it's not necessary
anymore.
2021-02-03 12:02:25 +01:00
Pietro Fezzardi 3f1ee6ea64 Stub of DLA integration in Clang AST emission 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 088015e11c Forward SCEV and DLA results to decompilation 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 9d1d6afe6e MarkForSerialization: extract into its own Pass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 2ff7044bb9 Decompiler: forward-declare types coming from DLA
This commits enable the emission of rich types associated with function
signatures. This types are forward-declared in the decompiled C code
before the definition of each decompiled function that uses them.

The types we emit for now are the types that the DLA is able to compute
(if any) for the return values and the arguments of the function.

Such types are not yet used in the body of the function, nor in the
function declaration. These are the next steps to come.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 476064d855 [DLA] kill structural deduplication of Layouts
Before this commit, the MakeLayout step of the DLA used to deduplicate
structurally equal Layouts. This has turned out to be wrong when going
forward with the emission of types in C.
Being able to tell apart two different types that are structurally equal
is important for the emission of C types. Throwing this information away
with deduplication is bad. This commit disables such deduplication.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi e0f9401ff8 ADT: add HeterogeneousPtrCompare template class
This is a utility class useful to make std::set<std::unique_ptr<T>>
searchable with raw pointers, by using
std::set<std::unique_ptr<T>, HeterogeneousPtrCompare<T>> instead.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi d6c8214d52 Decompiler: improve handling of command line flags
Handling of command line options that specify paths for output files
have been improved in the following ways:
- If the CDecompilerPass is not default-constructed, it already has a
  reference to the stream where outputs must be written. In this case,
  it is wrong to use a command line option to specify the output
  directory. If this happens the program is now able to detect it and to
  terminate with an error.
- If some of the specified paths is not found or has the wrong
  permission, the program fails early.
- On program failure because of one of the above safety checks, the
  program terminates with an informative error message.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi 1e825a8201 Create IRASTTypeTranslator class
This class handles the creation of type declarations in clang's AST, and
holds the relationships between llvm Types and Values with those clang's
type declarations.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi cbbbdf660f [DLA] propagate DLA results to CDecompilerPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 44564c2ba7 [DLA] export layouts to DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi c553965b62 CDecompilerPass: addUsedIfAvailable<DLAPass>() 2021-02-02 11:23:53 +01:00
Pietro Fezzardi dda2b5aaa0 [DLA] Add skeleton for DLAPass 2021-02-02 11:23:53 +01:00
Pietro Fezzardi 7ff39039a8 Add Liveness Analysis 2021-02-02 11:23:53 +01:00
Pietro Fezzardi a96f98821c [DLA] Add AdjustStackPointerPass FunctionPass
Add a pass that computes the lowest negative offset that is summed in
each isolated function to the local stack pointer returned by a call to
revng_init_local_sp (previously added by PromoteStackPointerPass).
After the computation, all the accesses relative to the stack pointer
are recomputed as if the stack pointer was lowered by the computed
amount.

This is useful to enable the DLA to easily recover layouts that are
placed at negative offsets from the stack pointer.
The reason is that the DLA in its current form does not handle negative
offsets, but at the same time negative offsets are important to recover
the layout of the local variables on the stack.

This pass implicitly depends on running PromoteStackPointerPass.
If PromoteStackPointerPass did not run before the execution of
AdjustStackPointerPass, the latter doesn't do anything.

For demonstration purposes, AdjustStackPointerPass has been implemented
both with LLVM's legacy PassManager and the new PassManager.
2021-02-02 11:23:53 +01:00
Pietro Fezzardi a31bdbd602 [DLA] Add PromoteStackPointerPass 2021-02-02 11:23:53 +01:00
Alessandro Di Federico 433d8a9ddc Update GenericGraph<DataFlowNode>
This commit updates the `DataFlowNode` data structure used in
`TypeShrinking` to be compatible with the newer version `GenericGraph`
provided by revng.

The change basically encompasses inverting the inheritance and dropping
CRTP.
2021-02-01 18:21:38 +01:00