Commit Graph

1429 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 047ae0d4d8 Apply clang-format globally
This commit applies our `clang-format` rules globally. From now on, all
commits should respect our configuration file.

Pretty large change.
2018-09-21 20:08:45 +02:00
Alessandro Di Federico fba681bbcc s/X --> 0/X-- > 0/ 2018-09-21 20:08:23 +02:00
Alessandro Di Federico 960286f419 Reorder Boost includes
Include directives are groups by library, the groups should be sorted
from the most general (i.e., the STL) to the most specific (the local
includes).

This commit ensures that Boost includes are before LLVM includes.
2018-09-21 20:08:23 +02:00
Alessandro Di Federico 38a67f2ad5 Enforce new convention for switch's breaks 2018-09-21 20:08:23 +02:00
Alessandro Di Federico d57b8b3ab4 Various minor whitespace/case changes 2018-09-21 20:08:23 +02:00
Alessandro Di Federico 57fae6ebb1 Functions in header files should be inline only 2018-09-21 20:05:18 +02:00
Alessandro Di Federico 384c317ef1 Introduce using to increase readibility
This commit introduces `using` statements and `constexpr` functions to
increase readibility of various types.
2018-09-21 20:05:18 +02:00
Alessandro Di Federico 34d216eb0a Create temporary variables to increase readibility 2018-09-21 20:05:18 +02:00
Alessandro Di Federico a566130825 Outline lambdas 2018-09-21 20:05:18 +02:00
Alessandro Di Federico 31e5d1c96f Add braces around else
Sometimes the true-branch of an `if` statement was using braces but the
false-branch was not. This commit fixes this.
2018-09-21 20:05:18 +02:00
Alessandro Di Federico 037fca46ae Check 80 columns limit
This commit introduces an additional check in `check-conventions.sh` to
detect lines in source files exceeding 80 columns.
2018-09-21 20:04:25 +02:00
Alessandro Di Federico 6cfabd96f8 Prevent committing WIP code
This commit introduces a check in `check-conventions.sh` to prevent
committing code denoted by a `// WIP` comment, that are supposed to be
used to remind the developer something has to be changed before
submitting a pull request.
2018-09-21 20:03:21 +02:00
Alessandro Di Federico 5513ae606c Force the text segment at 0x20000 on ARM
For a long time we had an issue on ARM: the linker would use as the
first page 0x10000. However, on many distros, that matches the first
page that can be mapped (see `/proc/sys/vm/mmap_min_addr`). Therefore,
this shouldn't be a problem, except the fact that the translated program
also needs the preceeding page for the (outer) ELF header.

We used to suggest users to run:

    echo 4096 | sudo tee /proc/sys/vm/mmap_min_addr

Now in our tests, we force the text segment page to be at 0x20000,
therefore, this will no longer be necessary.
2018-09-21 17:27:22 +02:00
Andrea Gussoni 500d77f43e Register and add among JT reasons FunctionSymbol
The symbol handling has been extended to register whether a symbol
represents a function or not. This information is then used to register,
during the global data harvesting phase, all the function symbols and
explicitly mark them through the "FunctionSymbol" `JTReason`.

We use this information during the CFEP harvesting phase to integrate
the information produced by the function boundaries detection with
potential unidentified CFEPs.

This option can be enabled with the `--use-debug-symbols`, which
supersedes `--use-sections`.
2018-09-20 17:52:10 +02:00
Pietro Fezzardi 6e642ea6f9 Add support for pyelftools >= 0.25
From version 0.25 pyelftools changed the API for ENUM_P_TYPE.
This commit wraps the import in a try-except block to handle older and
newer versions gracefully.
2018-09-20 15:23:31 +02:00
Alessandro Di Federico 1aa65aa211 Fix trivial bug in test_stackanalysis 2018-09-19 19:59:10 +02:00
Pietro Fezzardi cce1a9684c Fixes to suppress GCC 8 warnings 2018-09-18 16:29:04 +02:00
Pietro Fezzardi 626c30b905 Revert workaround for NDEBUG-related linkage issue
This problem has been fixed backporting the proper patches on LLVM.
2018-09-18 16:28:07 +02:00
Alessandro Di Federico ce6f062547 Merge branch 'feature/arguments-detection' 2018-09-18 16:03:16 +02:00
Alessandro Di Federico 7fe00c08dd Rewrite the stack and introduce the ABI analyses
This is a very large commit importing the reviewed (and heavily
simplified) stack analysis and the new ABI analysis, which provides
information on the calling convention of each function and so on.

For an overview of the new analyses please consult OVERVIEW.md.
2018-09-18 15:58:20 +02:00
Alessandro Di Federico 4557c91457 FilePortion: force members initialization
This commit fixes a bug triggered by the fact that the constructor of
the `FilePortion` class was not initializing fields featuring a "native"
type (which are therefore not automatically zero-initialized).

In particular, this bug was triggered when dealing with a dynamic binary
lacking the sections for dynamic relocations.
2018-09-17 19:20:36 +02:00
Alessandro Di Federico e82635ee0b Introduce function_call-related helpers 2018-09-17 19:20:17 +02:00
Alessandro Di Federico 8eb532d73c Introduce StreamWrapper
`StreamWrapper` is a class that wraps a stream of any type. It has a
`flush` method, that, when called with a `std::stringstream` copies all
of its content in the wrapped stream.

The main reason for having `StreamWrapper` is being able to have a
`dumpInternal` method in a `.cpp` file while preserving a
stream-agnostic `dump` method in the header.
2018-09-17 19:20:17 +02:00
Alessandro Di Federico e6bc62f760 Twine: use them only as const Twine & arguments
`Twine`s are very cool but very subtle objects. You basically have to
use them as `const Twine &` arguments only. In fact, a Twine keeps a
reference to objects whose lifetime corresponds to the current
statament. Therefore, a `Twine` can easily end up holding a reference to
invalid objects.

This commit fixes a bug in function isolation (which would show up only
if optimizations are enabled) due to a misusage of
`Twine`. Additionally, it reduces its usage to safe places in
`statistics.h`. Finally, we added an assertion in `check-conventions.sh`
to ensure that no variables of type `Twine` are ever declared.
2018-09-17 19:20:17 +02:00
Alessandro Di Federico 25278f2e03 revamb-dump: -T option for dumping statistics
revamb-dump was missing the `-T` option.
2018-09-17 19:20:17 +02:00
Alessandro Di Federico 770d61b00f Drop assertion on QueueImpl 2018-09-17 19:20:17 +02:00
Alessandro Di Federico 0121ddfde4 Minor whitespace and formatting changes 2018-09-17 19:20:17 +02:00
Alessandro Di Federico c9c884d809 Introduce SmallMap::erase 2018-08-31 09:00:33 +02:00
Alessandro Di Federico fb7ad64070 CMake: one argument per line
This commit simply reduces the length of lines in CMake by splitting the
statements over multiple lines. This is particularly useful when listing
the translation units composing a program/library. In fact, it makes
merge much easier.
2018-08-31 09:00:33 +02:00
Alessandro Di Federico ee2ab2978e Reorganize enums in namespaces with functions
`enum`s throw their entries into the parent scope. `enum class` can work
around this issue, however, `enum class` cannot have methods. Since we
often need to have `getName` and `fromName` functions for the enums, we
now create a namespace for each enum that contain a number of helper
functions.
2018-08-31 09:00:33 +02:00
Alessandro Di Federico 82ab7869d9 Doxygen: parse files from git ls-files
Doxygen doc used to look for source files in the source root directory
only. We now use `git ls-files` to figure out which files need to be
part of the documentation.
2018-08-31 09:00:33 +02:00
Alessandro Di Federico 2c7e0ee50b Drop some leftover "Lol" variables 2018-08-31 09:00:33 +02:00
Alessandro Di Federico 6b39f031e1 Generate as much debug info as possible in tests 2018-08-31 08:42:31 +02:00
Alessandro Di Federico 51009347a2 Introduce CounterMap for collecting statistics
The `CounterMap` class allows to increment a counter associated to an
arbitrary key. This is useful for printing out statistics, e.g., per
`Function` or `BasicBlock`.
2018-08-31 08:42:31 +02:00