Commit Graph

941 Commits

Author SHA1 Message Date
Alessandro Di Federico e0c4cd843e tmp 2021-02-08 18:42:42 +01:00
Alain Carlucci 0261181cd1 ADT: Add SerializableGraph 2021-02-08 12:27:26 +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
Alain Carlucci f1808c9db6 TupleTree: extend FOR_EACH up to 16 arguments
This commit extends the support for the FOR_EACH macro used in
INTROSPECTION_NS to allow serialization of structs with more than
5 entries. Now it supports up to 16 entries.
2021-02-01 11:03:53 +01:00
Alessandro Di Federico 4982ba6922 KeyedObjectContainers: ensure serializability
This commit fixes a couple of bugs preventing SortedVector and
MutableSet from being serialized.
Also, it introduces minimal testing for serialization.
2021-01-28 17:45:14 +01:00
Alessandro Di Federico 0e3bf6c340 Merge branch 'feature/gcbi-new-pm' 2021-01-28 17:13:16 +01:00
Antonio Frighetto 99274f1a41 GCBI: create wrappers to support old and new PM
The GeneratedCodeBasicInfo class has been disentangled in order to
create wrappers to support both the legacy and the new pass manager.
2021-01-28 17:03:31 +01:00
Antonio Frighetto eacc0b76b2 Refactor GCBI
Changes include:
- `getFunctionCall` has been moved in IRHelpers.h
- `getFallthrough` and `getFunctionCallCallee`
  have been simplified and added in IRHelpers.h (their old versions
  have been removed respectively from FCI.h and revng.h)
- `FCI::getCall` and `FCI::isCall` have been removed
  due to redundancy with `getFunctionCall`.
2021-01-28 17:03:30 +01:00
Antonio Frighetto 2283e0a4e7 Move isMarker-related helpers in IRHelpers.h 2021-01-28 17:02:17 +01:00
Antonio Frighetto 29ee916559 FCI: drop findPostDominatedCall and cfg
Unmaintained code has been removed.
2021-01-28 16:03:02 +01:00
Alessandro Di Federico dcb7f3f9f3 Merge branch 'feature/import-preliminary-model' 2021-01-27 20:09:11 +01:00
Massimo Fioravanti 8ba9930638 Invert inheritance of GenericGraph nodes
GenericGraphs no longer require CRTP.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 256ba44158 Make revng-all-binaries depend on support-*.ll 2021-01-27 19:46:53 +01:00
Alessandro Di Federico b544e214b8 ProgramCounterHandler: CSVs are internal
This commit fixes a bug that lead to be unable to instantiate from a
`Module` `ProgramCounterHandler`. The reason for this was that
`ProgramCounterHandler` was using `Module::getGlobalVariable` which, by
default, ignores variables with internal linkage.
2021-01-27 19:46:53 +01:00
Alessandro Di Federico a655507a0c Use relative paths during builds 2021-01-27 19:46:53 +01:00
Alessandro Di Federico 38031f2f8a Import preliminary model
This commit imports:

* support for (de-)serializing tuple-like objects in YAML
* the Model data structure
* the {Load,Serialize}ModelPass
2021-01-27 19:46:53 +01:00
Alessandro Di Federico 28cb935d39 ZipMapIterator: handle dishomogeneous containers
ZipMapIterator can now handle containers of different type, as long as
their keys are comparable.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico 8aab914037 Import MutableSet and SortedVector
These data structures are substitutes for a `std::map<Key, Value>` where
`Key` is embedded in `Value`. Their main goal is to be serializable in a
YAML sequence while preserving the order enforced by the key.

`MutableSet` is implemented using a map.
`SortedVector` is implemented using a sorted vector.
2021-01-27 19:46:52 +01:00
Alessandro Di Federico e72bcf796f Simplify MetaAddress::operator== 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 7a560adbfa MetaAddress: drop std::less specialization 2021-01-26 18:42:10 +01:00
Alessandro Di Federico 6359edebb7 GenericGraph: Node::has{Successors,Predecessors} 2021-01-26 17:44:21 +01:00
Alvise de Faveri 9eb9e9b1a1 ADT: fix neighbor constness for GenericGraph
Problem:
1. `ForwardNode::getConstNeighbor` returns a reference to a non-`const`
    object, but the referenced pointer is `const`
2. `FowardNode::toNeighborRange` checks if the type of the argument is
const, but since `Successors` is not declared const the resulting
`toNeighborRange(Successors)` is never executed in the const version

Solution:
1. Make `getConstNeighbor()` return a reference to a `const` pointer
2. Explicitly declare a separate `toNeighborRange()` function which
returns a `const_child_iterator` and remove the template parameter
2021-01-26 17:41:58 +01:00
Alessandro Di Federico 3d9f10307d Force Mach-O entry point to be code 2021-01-24 18:37:35 +01:00
Filippo Cremonese c5680b2120 Refactor revng-merge-dynamic
Notable changes:

- Split in multiple files the existing revng-merge-dynamic script
- Add the option to merge additional LOAD segments in the resulting
  binary
- Align the new .dynstr to a 4 byte boundary
- Ensure the last verneed entry is marked as such (vn_next == 0)
- Ensure LOAD PHDRs are listed in ascending order,
  as mandated by ELF spec
2021-01-23 00:41:52 +01:00
Alessandro Di Federico 09f4477ac7 Merge branch 'feature/various-fixes' 2021-01-06 17:46:47 +01:00
Alessandro Di Federico 4d1f681a44 Add RelocationTypes R_X86_64_{64,32} 2021-01-06 17:40:56 +01:00
Alessandro Di Federico 8549844d36 Set BaseAddress to 0x400000 by default 2021-01-06 17:40:56 +01:00
Alessandro Di Federico 28432e30c1 Disable HARD_FLAGS_* when invoking linker
This commit is necessary in order to avoid using the compiler wrapper
provided by orchestra when developing.
2021-01-06 14:40:27 +01:00
Alessandro Di Federico 54ea92cfec Introduce GCBI::programCounterHandler 2020-12-31 14:37:53 +01:00
Alessandro Di Federico d3247870f0 Reorganize ProgramCounterHandler construction 2020-12-31 14:37:53 +01:00
Alessandro Di Federico a153dc3f7a ProgramCounterHandler.cpp: drop unnecessary llvm:: 2020-12-31 14:17:30 +01:00
Alessandro Di Federico 4c4e427a4a Make ProgramCounterHandler implementations private 2020-12-31 14:17:30 +01:00
Antonio Frighetto 02b3a24463 Jump to dispatcher when location is invalid
Replace a call to `abort` with a branch to `dispatcher` when the
callee is unknown or invalid (namely, it is always treated as an
indirect call).
2020-12-31 14:17:30 +01:00
Pietro Fezzardi e1b283b0b6 Add RecursiveCoroutine headers and tests
RecursiveCoroutines are a facility intended to be used as-drop in
replacement of recursive functions.

They provide the following features.
- They can be written almost as regular recursive functions,
  with 4 caveats.
  1. A recursive coroutine that returns a type `T`, needs to be declared
     to return a `RecursiveCoroutine<T>`.
  2. Inside the body of a recursive coroutine, when recursively calling
     another recursive coroutine, the recursive call needs to be
     prepended by the new keyword `rc_recur`.
  3. Inside the body of a recursive coroutine, the `return` statement
     needs to be substituted with `rc_return`.
  4. When launching a recursive coroutine `A` from a function that is
     not a recursive coroutine, `A` needs to be called with the provided
     dedicated template wrapper `rc_run`.
     The syntax is the following `rc_run(A, arg0, arg1, ...)`.
     This is necessary to enable swapping off recursive coroutine and
     fall back to regular recursion for debug.
     See below for how to do it.
- Unlike regular recursive functions, they don't use the system stack
  for recursion. They use a custom heap-allocated stack to manage
  recursion. This makes them more robust for implementing recursive
  functions that manipulate user-defined input, because they are much
  less likely to trigger stack overflow.
- They can be turned off compiling with
  `-DDISABLE_RECURSIVE_COROUTINES`, falling back to regular recursion,
  for debug purposes.
- They support both direct and indirect recursion, i.e. a recursive
  coroutine A can recursively call itself, or it can recursively call
  another recursive coroutine B, which in turns recursively calls A.
2020-12-29 16:15:31 +01:00
Alessandro Di Federico 6652eb660d Merge 'check-conventions-generate-style-file' 2020-12-29 16:15:09 +01:00
Alessandro Di Federico 3c58c7441b Whitespace changes 2020-12-29 16:14:49 +01:00
Pietro Fezzardi 9a3b514a80 CMakeLists.txt: generate and install .clang-format
This is intended to be used by all projects that adopt rev.ng coding
conventions for C++. Each project can create a symbolic link to the
installed .clang-format file, so that IDEs and other dev tools can pick
it up easily while keeping it up-to-date when updating revng.
2020-12-29 16:14:49 +01:00
Pietro Fezzardi 670801fad7 Tidy-up cmake commands for check-revng-conventions
This is a preliminary step before adding cmake commands to generate and
install a .clang-format file for easier use from other projects.
2020-12-29 16:14:49 +01:00
Pietro Fezzardi d37aed928e Run check-revng-conventions from outside git dirs
This enables running the check-revng-conventions script as part of the
build and install process, to generate the .clang-format file for
installation and use from other projects.
2020-12-29 16:14:45 +01:00
Pietro Fezzardi 86fcff5db4 check-revng-conventions: improve help 2020-12-29 15:43:34 +01:00
Pietro Fezzardi 13a893e91f check-revng-conventions prints errors on more opts
Options with only a single leading dash were previously recognized as
filenames.
Now they are recognized as options.
2020-12-29 15:43:34 +01:00
Pietro Fezzardi 01118920b0 Add check-revng-conventions option to print config
This option is enabled with --print-clang-format-config.
This is useful to work around the fact that clang-format configuration
is hard-coded in a file.
Using this option is easier to generate a .clang-format file that can be
dropped in single projects to be picked up by IDE.
2020-12-29 15:43:34 +01:00
Pietro Fezzardi 4b4e791afe Add missing option to check-revng-conventions help 2020-12-29 15:43:34 +01:00
Pietro Fezzardi cb2c3c610f Add --help flag to check-revng-conventions 2020-12-29 15:43:32 +01:00
Antonio Frighetto e6f0b26455 CodeGen: remove variadic args in calls to newpc
After the discovery of new code to be translated, the calls to `newpc`
can be stripped of their variadic arguments (reference to local vars)
in order to let SROA perform more optimization.
2020-12-29 15:25:42 +01:00
Antonio Frighetto 59b8c6ca4d Exception helper: add attribute noreturn
`raise_exception_helper` must not return to its caller. Should
`_Unwind_RaiseException` return, something will have gone wrong
with the personality routine; yet this should never happen.
This way we might also save a few bytes and hint the compiler to
avoid storing the callee-saved regs / allocating a new frame.
2020-12-29 14:53:09 +01:00
Pietro Fezzardi 7ff24ac761 GCBI: remove assertion on Dispatcher != nullptr
This assertion was executed in the `runOnModule` method of the GCBI
pass, but it is too strict.

Asserting that Dispatcher != nullptr during the execution of the pass
prevents the pass from successfully running on a Module without a
Dispatcher.
This is unfortunate, because some passes that depend on GCBI in revng-c
actually do that. They do so because they are not really interested in
the Dispatcher at all. They only use GCBI to access information on the
Stack Pointer.

In fact, the check for Dispatcher being != from nullptr is already
performed also in the `dispatcher()` method which is the sane thing to
do. This commit removes the assertion from the `runOnModule` method and
leaves it in the `dispatcher` method.
This allows to run the pass successfully even on a Module without the
Dispatcher, while not changing the contract of this pass (i.e. that when
you call the `dispatcher` method you get a nonnull pointer).
2020-12-29 14:51:38 +01:00
Alessandro Di Federico b420128e9f Merge 'feature/lifting-performance-improvements' 2020-11-23 14:53:36 +01:00
Alessandro Di Federico c6d0ce9dec Don't use RPOT for DisjointRanges
Sorting the BasicBlocks on which DisjointRanges works is detrimental for
performance.  Using a random order takes less time. This is due to the
fact that the number of BasicBlocks to analyze is significantly smaller
than the whole list of BasicBlocks.
2020-11-23 14:52:46 +01:00