Commit Graph

6113 Commits

Author SHA1 Message Date
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
Alessandro Di Federico 198ccd83b7 OSRA: handle the bswap intrinsic 2018-08-31 08:42:31 +02:00
Alessandro Di Federico 149da95610 OSRA: ignore constants wider than 64 bits 2018-08-20 16:08:07 +02:00
Alessandro Di Federico f6753e7287 Make getModule(nullptr) return nullptr 2018-08-20 16:08:07 +02:00
Alessandro Di Federico a114f60299 New JTReason: ReturnAddress 2018-08-20 16:08:07 +02:00
Alessandro Di Federico d31af260c1 revamb-dump: stop Callgrind while loading LLVM IR 2018-08-20 16:08:07 +02:00
Niccolò Izzo 92253e23b2 Fixed typos in revamb documentation 2018-08-18 17:14:02 +02:00
Alessandro Di Federico 9a85cc3a04 Introduce check-conventions.sh, .clang-format
`.clang-format` is the configuration file for the `clang-format` tool,
which can help us to enforce a consistent coding style.

`check-conventions.sh` is a a simple bash script that checks (using
mostly `git grep`) if, after running `clang-format`, there are some
undesired situations such as lines ending with "(" or "<".

This script should produce no output before a merge request is
merged. However, currently this is not the case, therefore the script
should be used mostly for new code (in particular, files) only.
2018-08-18 17:09:23 +02:00
Alessandro Di Federico a0f4e0bb41 Introduce new assertion framework
A set of assertion-related functions has been introduced:

* `revng_abort(message)`: aborts, in release builds too.
* `revng_check(what, message)`: asserts `what`, in release builds
  too. Also emits a `__builtin_assume`, that can lead to additional
  optimizations in clang.
* `revng_unreahcable(message)`: identical to `revng_abort`, but in
  release builds emits `__built_unreachable`.
* `revng_assert(what, message)`: asserts in debug builds, otherwise
  emits `sizeof(what)` (to suppress unused variable warnings) and
  `__builtin_assume`.

The adoption of these function has the following benefits:

* Nice stack traces.
* The developer can choose to enforce an `assert` (or an `unreachable`)
  at release-time too by using `check`/`abort`.
* Most warnings about unused variables in release mode should be gone.
* When using clang, the `assert`s become `assume`s, which might enable
  additional optimizations (with no run-time costs).
* The `assert(Condition && "Reason")` trick is no longer needed, we now
  have a proper argument.
2018-08-18 16:25:40 +02:00
Alessandro Di Federico aa0d846bfc Merge branch 'feature/pie' 2018-08-18 11:46:30 +02:00
Alessandro Di Federico f2e1ea68f1 OSRA: improve handling of equality comparisons
Equality comparisons used to be ignored more often than required due to
the fact that they give no hint on the signedness of the tracked value.

This commits removes some assertions and improves the handling of OSRs
without a known signedness. In particular, now, inequalities can be
solved even in absence of signedness information, as long as the result
that you would get with a signed OSR and an unsigned OSR matches (i.e.,
the signedness doesn't matter).
2018-08-18 10:50:05 +02:00
Alessandro Di Federico 88e2a6eff1 OSRA: improve handling of unsigned comparisons
We used to have a special handling of unsigned comparisons, since we
assumed that each side of the comparison had to be greater than or equal
to zero. This commit further widens the cases in which this is
useful. Specifically, if both the comparison we're dealing with and the
greater-than-or-equal-to-zero comparison don't have an upper bound, we
flip one of the two in a way that ensure that they represent a closed
interval. Then, if the flipped comparison is the former, we reflip the
final result.
2018-08-17 21:55:48 +02:00
Alessandro Di Federico 8773186ef1 OSRA: handle identical-but-negated conditions
If a conditional branch propagates a constraint on a value that is
exactly the opposite with respect to its current constraint, we simply
ignore it, since simply flipping the condition (and the destination
basic blocks) would do the same.

In future, we should propagate a contradiction on the appropriate
branch.
2018-08-17 21:55:48 +02:00
Alessandro Di Federico 85a000089f merge-dynamic.py: generate .hash section
We used to ignore the `.gnu.hash` section, however it turns out to be
fundamental in case the ELF we're working on *defines* one or more
symbols. This has not been a problem so far since we usually work with
the main executable only, which, usually, doesn't define any dynamic
symbol. However, for example, `ls` "defines" a `getoptind` symbol (more
accurately, it clones it from libc).

To handle this situation, we replace the `.gnu.hash` with a minimal
`.hash` section. Basically, the `.hash` section should contain an hash
table. However, currently, we just create an hash table with a single
entry, which immediately triggers scanning the chain of entries
colliding in the (only) entry.
2018-08-17 21:55:48 +02:00
Alessandro Di Federico b4b0b7bce9 FCI: API for fallthrough BasicBlocks
The `FunctionCallIdentification` pass now has an API to get the
fallthrough basic block of a function call basic block and to check
whether a certain basic block/address is the fallthrough of a function
call.
2018-08-17 21:55:48 +02:00
Alessandro Di Federico 2d23bb525b Introduce dump for OSR and BoundedValue
This commit introduces a `dump` method for `OSR` and `BoundedValue` for
easier debugging within gdb. It also introduces `debug_function`, a
definition that wraps attributes to ensure the function is emitted even
if unused and emitted as a standalone function that can be called from
gdb.
2018-08-17 21:55:48 +02:00
Alessandro Di Federico c4965a811b OSRA: fix iteration over BV with no upper bound
`BoundsIterator` had an issue in case there was the need to iterat over
bounds reaching the upper bound of an integer: the increment would
generate an overflow that would go undetected and, therefore, lead to an
infinite loop.
2018-08-17 21:55:48 +02:00