Commit Graph

6113 Commits

Author SHA1 Message Date
Alessandro Di Federico 7fab462593 Don't fail if section headers are corrupt 2018-11-14 09:34:49 +01:00
Alessandro Di Federico 09b9fbba39 Drop trailing semi-colon in messageless assertions 2018-11-14 09:34:49 +01:00
Alessandro Di Federico bc0de2c88f Fix tests due to changes in QEMU
In QEMU we should suppress the emission of the debug_insn
pseudo-instruction (which delimits the tiny code instructions
corresponding to an original input instruction) in case of a delay slot.

However, this was not happening due to a wrong `#ifdef`. Since this has
now been fixed in QEMU, this commit updates the results of the tests
accordingly.
2018-11-14 09:34:49 +01:00
Alessandro Di Federico 37fb3d6e56 Introduce support for little endian MIPS 2018-11-14 09:34:49 +01:00
Alessandro Di Federico 509625cb30 Do not clobber helper functions' debug info
`DebugAnnotationWriter` creates debug information for each instruction
in the generated LLVM IR module. Before this commit, it used to clobber
any debug information in any function, which lead to wrong debug
information on helper functions.

This commit ensures that debug information of helper functions are
untouched, so that they can be used while debugging.
2018-11-14 09:34:49 +01:00
Pietro Fezzardi b9273210d0 Update to LLVM 7
Updating to LLVM 7 mainly involved the following steps:

* Upgrade APIs for folding ConstantExpr.
* Upgrade APIs for GraphTraits.
* Upgrade APIs for DominatorTreeBase.
* Upgrade APIs for BinaryFormat to parse ELFs.
* Fix the LLVM Linker to properly link the QEMU helpers.
* Disable the new optnone attribute even with optimization -O0. This is
  necessary to allow SROA to do its job properly.
* Upgrade APIs to delete Instructions.
* Properly cleaning up orphaned metadata still referring to Instructions
  that have been destroyed. Recent versions of LLVM are more strict in
  this respect, and will assert when compiled in debug.
* Avoid using LLVM `getGlobalContext` which has been removed from newer
  versions of LLVM.
* Upgrade tests to use the new APIs.
* Upgrade APIs for instruction iterators and reverse iterators.
2018-11-13 18:11:05 +01:00
Alessandro Di Federico b34a421ec4 getResetColors: return nullptr when appropriate
A method in RDA was returning nullptr when a basic block *had* a color
and a dangling reference when it did not.
2018-10-24 17:21:57 +02:00
Alessandro Di Federico 4c66e41352 Merge branch 'feature/rda-rewrite' 2018-10-16 17:43:44 +02:00
Alessandro Di Federico dee2cf0d04 Reimplement the reaching definition analyses
This commit reimplements the (conditional) reaching definitions passes
as an instance of a monotone framework.

The `ConditionNumberingPass` has also been reworked in the way it
exposes its results, but it's otherwise unchanged.

A proper unit testing framework is also available to ensure everything
works as supposed to.
2018-10-16 17:39:22 +02:00
Alessandro Di Federico 4538d520a6 SET: fix use after free in assertion
An `assert` used to check the type of a deleted object. This commit
delays the deletion of such object.
2018-10-16 16:59:08 +02:00
Alessandro Di Federico 1c5bb1a84c Whitespace and other minor changes 2018-10-16 16:58:57 +02:00
Alessandro Di Federico 5872dc1ffc Handle top in BoundedValue::setSignedness
In case of a top `BoundedValue` which appears to be used with an
inconsistent signedness, simply change the signedness and keep it to
top.
2018-10-16 16:57:53 +02:00
Alessandro Di Federico 826accaa0a OSRA: fix "It's already on the stack" message
This message used to be emitted unconditionally. It is now emitted only
as appropriate.
2018-10-16 16:57:07 +02:00
Alessandro Di Federico f4c5942d62 Introduce the registerjt logger
This commit introduces a new logger that prints out the name and reason
for each newly registered basic block.
2018-10-16 16:55:57 +02:00
Alessandro Di Federico b6ee8480da Extend MonotoneFrameworkSet
This commit simply adds a couple of handy methods to
`MonotoneFrameworkSet` such as `begin`, `end`, `erase`, `erase_if`,
`contains` and `size`.
2018-10-16 16:55:12 +02:00
Alessandro Di Federico f305541d5e Introduce MonotoneFramework::handleEdge
In a `MonotoneFramework` it is sometimes necessary to change the
information propagated on a branch w.r.t. another branch.

This commit introduces the `handleEdge` function that allows
`MonotoneFramework` implementors to modify the `LatticeElement` produced
by `transfer`.
2018-10-16 16:52:24 +02:00
Alessandro Di Federico 873dd13dd5 Introduce dumpModule
`dumpModule` is a debug function that can be called from GDB to dump a
`Module *` to a chosen path.
2018-10-16 16:51:52 +02:00
Alessandro Di Federico a704926ddc Ensure blocks are always reachable in root
Through `JumpTargetManager::setCFGForm` the `root` function CFG can be
changed so that the `dispatcher` is minimized, i.e., it jumps only to
those basic blocks that would be otherwise unreachable. This allows us
to perform more accurate and simpler analyses.

To bring the function in this state we used to check if there was at
least a non-dispatcher predecessor, however this did not work with loops
reachable only from the dispatcher, since they had a predecessor, but
that didn't mean it was reachable from the entry.

This commit fixes the problem by navigating the CFG in reverse-post
order, registering all the reachable blocks and then restoring the edge
from the dispatcher to those that are not reachable.

Additionally:

* Basic blocks with no predecessors are now purged before
  `JumpTargetManager::harvest`.
* The `CFGForm` enum is now a namespace.
2018-10-16 16:26:35 +02:00
Alessandro Di Federico e80b05a48e Move MonotoneFramework.h to libSupport
`MonotoneFramework.h` has been moved into `include/revng/Support` so
that it can be employed by components outside `libStackAnalysis`.
2018-10-16 16:25:29 +02:00
Alessandro Di Federico 944dcbc747 Merge branch 'feature/new-names-assert-logging-options' 2018-10-03 23:11:20 +02:00
Alessandro Di Federico 81c003d997 Use MDBuilder to create alias.scope
This commit also fixes a bug due to some problem in how we were building
the self-referencing metadata associated to `alias.scope`.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico 9dcefc8151 Add argument to InlineAsm function
`InlineAsm` instructions resemble function calls. You also have to
provide the prototype of the called function. Before this commit, we
were employing `void(void)`, which was wrong since we were passing in a
CSV.

In this commit we add a pointer argument to this prototype, which
prevents an assertion in LLVM from being triggered.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico 8348766b4e Make stack analysis' output more deterministic
In stack analysis' output, the list of basic blocks composing a function
was not sorted. This lead a test to fail due to the presence of the
`--order` flag when comparing the output.

This commit ensures that this list is ordered, by basic block name.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico 648e4e5945 Fix assertion in function isolation
Update an assertion trying to enforce the fact that `alloca`s copied
from `root` where in the original entry block, while they should be in
the `dummy` entry block.

Additionally, an improvement has been introduced which ensures only one
`alloca` is copied per-function, while, before, we were creating a new
`alloca` for each use in that function.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico cc02713f6d Abandon argparse in favor of LLVM's CommandLine
This commit dismisses the `argparse` library (the only non-runtime C
component of rev.ng) in favor of LLVM's CommandLine library, which
offers several benefits. Among others, now command line arguments can be
easily specified as a global variable, decentralizing their management
and avoiding the long list of arguments in the constructor of singleton
objects such as `CodeGenerator`.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico 43cf36bfce Introduce revng_log and abandon DBG(...)
This commit introduces `revng_log`, a macro analagous to `revng_assert`,
which basically allows to have the benefit of the `Logger` class without
having to compute the expression to log if the logger is disabled.

This commit also completely dismisses the `DBG` macro, converting all
the old code to `Logger` + `revng_log`.
2018-10-03 23:11:13 +02:00
Alessandro Di Federico cf8d6d530e Whitespaces and other minor fixes 2018-10-03 23:11:12 +02:00
Alessandro Di Federico d3f042479a Declare arch_prctl prototype in support.c
In `support.c`, we employ `arch_prctl` to set the value of segment
registers. However glibc, despite providing that function, doesn't
provide its prototype in any header file. This commit declares it,
according to the declaration provided in the man page.
2018-10-03 23:11:12 +02:00
Alessandro Di Federico cfba8372cf Remove extra --debug-symbols in tests invocation 2018-10-03 23:11:12 +02:00
Alessandro Di Federico 076aeac7f3 Move and rename all files
This commit moves around most files. The new directory structure is as
follows:

* `lib/$LIBRARY/`: contains a library, i.e., a set of `.cpp` files used
  by multiple libraries/tools.
* `include/revng/$LIBRARY/`: contains the public headers associated to
  the library in `lib/$LIBRARY/`.
* `tools/$TOOL/`: directory where all the `.cpp` files (and private
  headers) for a tool reside. Currently we have two tools: `revamb` and
  `revamb-dump`.

On top of this, all file names are now in camel case.
2018-10-03 23:11:12 +02:00
Alessandro Di Federico f061c6bad2 Make valgrind an optional dependency
This commit checks if valgrind headers are available and, if so, defines
a macro. In this way, if the heders are not available,
`valgrindhelper.h` can be aware of this fact and become a no-op.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico 216af772f1 Update the set of enabled warnings
Many of the previous commits are aimed at suppressing several compiler
warnings. This commit updates the set of warning we want to have.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico 386492e8fe Fix definition of ID for templated passes
`FunctionPass` has a static field `ID`. In templated passes, this needs
to be declared in the header file and defined in a `.cpp` file.

This does this, the right way.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico fea049ad95 Drop some unused variables 2018-09-29 16:50:36 +02:00
Alessandro Di Federico 469b0c6543 Add noexcept to dlclose prototype
This commit suppresses a warning due to the fact that an instance of
`std::integral_context` embedding `dlclose` was missing the `noexcept`
specifier in the type, due to a `decltype` limitation.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico 15178146ee Make message optional for revng_ assertions
This commit introduces a trick for having optional arguments in
macros. This enables the `revng_abort` and `revng_unreachable` macros to
have 0 or 1 argument, and the `revng_assert` and `revng_check` macros to
have 1 or 2 arguments.

Note that, by employing a macro trick (instead of C++ default
arguments), we keep the header compatible with C files.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico 45d58cbaca Force __builtin_assume argument to bool
The macro invoking ``__builtin_assume` was using the expression passed
by the user to the builtin directly. This commit introduces an explicit
cast to `bool`, which is sometimes required.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico 1515e2cd21 clang-format: don't split _Pragma argument
`clang-format` tends to make fit as much content as possible within a
line, even splitting string literals. However, this is not legal for
`_Pragma` expressions.

This commit disables `clang-format` in the portion of code using
`_Pragma`.
2018-09-29 16:50:36 +02:00
Alessandro Di Federico b1026bcbe6 Introduce a missing override 2018-09-29 16:50:36 +02:00
Alessandro Di Federico 9230bc3dc4 Ban assert(false) and non-revng_ assertions
This commit enforces, through `scripts/check-conventions.sh`, the
absence of `assert(false)` and direct calls to `assert`, `abort` and
`llvm_unreachable`.
2018-09-29 16:50:32 +02:00
Alessandro Di Federico 6bb7f4e8f1 Declare prototype of non-static functions
Certain non-`static` functions were missing prototype declarations,
triggering a compiler warning.

This was due to a missing header or due to a bug in boost.

This commit resolves this situation.
2018-09-29 13:05:16 +02:00
Alessandro Di Federico e74ee1431d Enforce struct/class usage coherency 2018-09-29 13:05:16 +02:00
Alessandro Di Federico fe249edbd7 Make some functions static 2018-09-29 13:05:16 +02:00
Alessandro Di Federico 0ff8f1c1ac Add virtual destructors as needed 2018-09-29 13:05:16 +02:00
Alessandro Di Federico 2615fba98d Remove some unreachable break statements 2018-09-29 13:05:16 +02:00
Alessandro Di Federico 622d6bacbb Remove some unused function arguments 2018-09-29 13:05:16 +02:00
Alessandro Di Federico 5a3e203e4b Switch to C++14
We'd switch to C++17, but we currently aim at supporting building revamb
with Ubuntu 16.04, whose default version of GCC doesn't support C++17.
2018-09-29 13:05:16 +02:00
Alessandro Di Federico f819962527 Switch to new assertion system globally
This commit enforces on the whole project the usage of our own assertion
system. This means all calls to `abort`, `assert` and `llvm_unreachable`
have been replaced with calls to `revng_abort`, `revng_assert` and
`revng_unreachable`, respectively.

The error messages, usually expressed as `assert(Condition &&
"Message")` have now been replaced using the second (optional) argument
of `revng_assert`.

Additionally, all the `assert(false)` statements have been replaced with
calls to `revng_abort`. Apart from readibility, this ensures the
compilers is aware of the fact that call will never return.

This change will enable us to drop many statements whose sole purpose
was marking a variable employed in an assertion as used in release
mode. In fact, with the new assertion system this is no longer
necessary.
2018-09-29 13:05:16 +02:00
Alessandro Di Federico e053b215d8 Drop _ prefix in include guards
We used to have a `_` prefix for include guards macros, however,
according to the standard, macros starting with an underscore are
reserved. This commit drops them all.
2018-09-26 08:59:59 +02:00
Alessandro Di Federico 8d0a16ca0c Merge branch 'feature/clang-format' 2018-09-21 20:25:16 +02:00