Commit Graph

1642 Commits

Author SHA1 Message Date
Alessandro Di Federico 00b9ade51f Handle libraries not ending with .so
Sometimes dynamic libraries linked to executables do not end in
`.so`. Previously, we assumed that a version of the library ending in
`.so` was available on the system. However, this is not always the
case. In particular, Ubuntu 16.04 links `ls` to `libselinux.so.1` but no
`libselinux.so` file is available. This can lead to a linking failure.

This commit, correctly handles libraries whose name doesn't end in `.so`
by using the `-l:` linker option (e.g., `-l:libselinux.so.1`).
2019-02-19 17:57:28 +01:00
Alessandro Di Federico 35ff5a4ce4 Add lib/revng/analyses to RPATH
When installing programs we used to add to `RPATH` the `../lib`
directory. However, this is not enough, since the analysis libraries
reside in `../lib/revng/analyses`. This commit fixes the issue.
2019-02-18 07:50:34 +01:00
Alessandro Di Federico 543ab2253d revng-merge-dynamic: improve is_rela detection 2019-02-12 18:40:30 +01:00
Alessandro Di Federico 4b9123fce8 Induction variable name used in range 2019-02-12 18:40:30 +01:00
Alessandro Di Federico 2b99f8e811 Use LD_PRELOAD instead of opt -load
In `opt -load`, the order in which the libraries are provided
matters. Using `LD_PRELOAD` circumvents this issue.
2019-02-12 18:40:30 +01:00
Alessandro Di Federico 6ae0610e2d Force Python versions
This commit switches all scripts to Python 3, except for
`revng-merge-dynamic` which requires Python 2 due to a limitation of
pyelftools.
2019-02-12 18:40:24 +01:00
Alessandro Di Federico 53db84f7d6 s/revamb/revng/g 2019-02-11 16:09:23 +01:00
Alessandro Di Federico 2382c5e638 Merge branch 'feature/employ-stackanalysis' 2019-01-18 15:38:20 +01:00
Pietro Fezzardi e594de5b3e Remove unused data members from VariableManager 2019-01-18 15:18:47 +01:00
Andrea Gussoni 5069ed44c6 Change linkage of isolated functions
Change the linkage of functions created during isolation to
`InternalLinkage`, to give more space to optimizations.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico ee1c8cae15 Add opt options to moderate runtime
Pass to the Global Value Numbering pass the `enable-pre=false` and
`enable-load-pre=false` since they have been identified as a major
source of slowdown with very large binaries.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 524862679a Enable PIC project-wide 2019-01-18 15:18:47 +01:00
Alessandro Di Federico a2b30ceb42 Update FunctionIsolation to use the new FBDP
This commit updates the function isolation transformation to handle the
metadata as provided by the new `FunctionBoundariesDetectionPass`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 2e241acae3 Introduce SA-based ABIDetection and FBD passes
This commit drops the old FunctionBoundariesDetectionPass and introduces
a new one based on the results provided by the StackAnalysis. A very
similar pass, the ABIDetectionPass, is now available to offer the
results of the ABI analysis too.

These two new passes are a thin shim depending on the appropriate
version of the StackAnalysis (with or withour ABI anlysis) and simply
call `serializeMetadata`, which decorates the LLVM IR with the requested
information.

In addition to drop the old analysis, this commit also isolates the
function boundaries detection pass from `revamb` making it available as
a library only.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 7a045d0c0d Drop revamb-dump in favor of plain passes
This commit does the following:

* It drops `revamb-dump` and transforms all the passes it featured in
  passes that can be used directly from `opt`.
* It rename `revamb` to `revng-lift`.
* It introduces a script called `revng` which acts as a driver for the
  whole rev.ng project. It replaces `translate`, `revcc`,
  `csv-to-ld-options` and `revamb-dump`, since it offers an `opt`
  subcommand which allows to easily invoke all the analysis passes.
* It makes the project a CMake package that can be easily used
  externally.
* It allows to easily create libraries of analysis to use through
  `revng-opt`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 14476a354c Fix function isolation test dependencies 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 25bf160910 Improve detection of stack alignment in SA 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 9ad7a7dbab Minor fixes to StackAnalysis' logging 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 05b1833ee6 Add ExternalJumpsHandlerBlock to BlockType 2019-01-18 15:18:47 +01:00
Alessandro Di Federico ef708e9912 Let --debug-log work without main involvement 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 9985ff5fb6 Drop const in FunctionsSummary-related code 2019-01-18 15:18:47 +01:00
Alessandro Di Federico e9b4b8edf1 Use stack analysis in RDA
This commit lets the reaching definitions analysis employ results from
the stack analysis to propagate definitions across functions
calls. Specifically, the stack analysis provides a list of registers
that might be clobbered by the callee: definitions concerning those are
not propagated, all the others are propagated.

This change is key to detect jump tables whose address has been
materialized *before* a function call. A test for such situation has
been introduced.

To make this work, the RDA now works over the CFG provided by the
function identification analysis.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 98c99e9406 Make StackAnalysis::getClobbered const 2019-01-18 15:18:47 +01:00
Alessandro Di Federico bd09716534 FCI: provide a custom CFG
The `FunctionCallIdentification` analysis now provides a custom view on
the CFG where 1) dispatcher-related basic blocks are absent, 2) nodes
performing functions calls have an edge to their return address and 3)
nodes ending with a return instruction have no successor.

This CFG is now employed by the reaching definitions analysis and OSRA.

Additionally, the implementation of the `visitSuccessors` and
`visitPredecessors` method has been reviewed. It now consists in a class
that needs to be inherited and for which two methods should be
implemented, one to perform the visit of a block and another one to
enumerate the successors.

In addition, all the users of `visitSuccessors`/`visitPredecessors` have
been updated, a simple set of tests has been introduced and
`GeneratedCodeBasicInfo::visitPredecessors` has been dropped.
2019-01-18 15:18:46 +01:00
Alessandro Di Federico 9cbcef37d5 Disallow #if [01]
Sometimes code is commented using preprocessor directives. This is fine
for temporary testing stuffs, but it should never end up in a commit.
2019-01-18 08:38:46 +01:00
Alessandro Di Federico 034621e2ec monotone-framework.py: restore Python 3 compat
Due to a minor error, `monotone-framework.py` loss its Python 3
compatibility. This commit fixes the situation.
2019-01-09 22:31:26 +01:00
Alessandro Di Federico 1fb8b1a6ec Merge branch 'feature/improve-performance' 2018-12-17 08:51:45 +01:00
Alessandro Di Federico 7ead8d68cc Collect simple literals (return addresses) as JTs
This commit fixes a problem that led to use SET to discover very very
simple jump targets: the return addresses of functions call.

Since in this situation, for each call, we needed to run SET, this
commit leads to a *huge* improvements in terms of translation
performance.

This commit also enforces renaming of the translated basic blocks after
they get split and update the ground truth for several analysis tests.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico 9ce805415b Improve Reaching Definitions Analysis
The Reaching Definitions Analysis used to ignore all the memory access
that were not relative to a CSV or an `alloca`. In certain situations,
in particular in x86 which makes heavy use of the stack, this led to
miss certain links that were vital for a correct identification of
certain jump targets.

As an example consider the following example:

    cmp    DWORD PTR [rbx+0x8],0x5
    ja     4bc5c8 <uw_update_context_1+0x148>
    mov    eax,DWORD PTR [rbx+0x8]
    movsxd rax,DWORD PTR [r12+rax*4]
    add    rax,r12
    jmp    rax

The constaint on `rbx+0x8` is not propagated to the use after the jump,
due to a missing link.

This commit fixes this by tracking all the memory accesses within the
expressive power of the `MemoryAccess` class, in particular those
expressed as register plus offset.

Additionally, this commit also makes RDA consider as reaching
definitions for a `load` only those definitions that match exactly the
load address, while previously we were considering all the `mayAlias`
definitions. This situation, in combination with the previous change,
led to have paths with multiple reaching definitions, which was
problematic for the path sensitive merge.

Finally, we consider a definition to be clobbered only if there's an
exact store to the esame address, instead of a store on an aliasing
address.
2018-12-17 08:15:45 +01:00
Pietro Fezzardi dbb25bef2c Apply information about CSV aliasing
This commit introduces alias information to state that memory accesses
relative to CSVs do not alias memory accesses of the original program.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico ef2d16db15 Install headers and libraries 2018-12-15 08:34:36 +01:00
Alessandro Di Federico 8877946be3 Handle codeless programs
Programs without code (e.g., no executable segment) led to miss the
`env` variable, making the `CpuLoopExitPass` fail. This commit, fixes
the problem by simply populating the `cpu_loop_exit` function with a
`ret`.
2018-12-15 08:34:36 +01:00
Alessandro Di Federico ac5dea43b4 Reduce exceptions thrown (e.g., due to tail calls)
In function isolation, every time we met a jump to an unexpected basic
block (i.e., a basic block that is not part of the current function), we
used to throw an exception. However this is unnecessary since oftentimes
it is sufficient to call the `function_dispatcher` or even perform a
regular function call.

The most obvious example is the case of a direct tail call. In this
situation performing a function call to the corresponding isolated
function is the most appopriate thing to do.
2018-12-15 08:34:36 +01:00
Alessandro Di Federico 2003b5c79f Being a callee is more important than being read
We used to black list memory portions target of memory read, so that
they couldn't become function entry points. However, this led to false
positives, in particular with functions that are explicitly called.

This commit ensures that we black list those addresses only if they are
not targets of function calls.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico c5657f8116 Optimize support.c
We now optimize `support.c`. We didn't do that since we were optimizing
everything after linking anyway, however, without `-O2`, functions in
`support.c` were getting an `optnone` attribute which inhibited any
optimization. In particular `newpc` and analogous functions were not
inlined. Resolving this issue led to a gigantic improvement in terms of
performance of the output program.
2018-12-13 18:03:11 +01:00
Andrea Gussoni af6f963d77 Improve exception handling
When optimizing a module to which function isolation has been applied the
`prune-eh` pass lead to several issues, specifically:

* `support.c` is now compiled with support for exceptions, to prevent
  `raise_exception_helper` from being marked `nounwind` during the
  link phase.
* Added a fake `ret` at the end of the `catchblock` to avoid promotion
  of `invoke`s to regular `call`s.
* Marked the `invoke` instructions as `noinline`.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 0010b6c704 Import revcc
`revcc` is a simple script that forwards its arguments to a specified
compiler, except in the case in which the compiler is asked to link the
final program. In such case, the compiler is invoked as appropriate, but
the resulting binary is then translated using rev.ng and replaced by the
translated version.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico a292542d06 Fix include paths order
We used to include `.` and `include/`, but the former is no longer
necessary and the latter has to have the highest priority to avoid that
installed headers take higher precedence, leading to a build employing
outdated headers.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 9d13ce343d OSRA: handle computations on constants
This commit fixes an issue in OSRA with computations on constants. If a
constant was added to another constant, a new constant bounded value
would be created. However, such bounded value wouldn't get propagated
further. This commit fixes the problem by creating an OSRA relative to
the original constant plus an offset.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico cb425c6a7a FCI: use previously detected fallthrough addresses
When going through basic blocks, FCI ignores basic blocks that have
already been identified as function calls. However, this lead to exclude
their fallthrough addresses from the list of fallthrough addresses.

This commit fixes this situation.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico d4b8fe847d GCBI: use getBlockType in isTranslated 2018-12-13 18:03:11 +01:00
Alessandro Di Federico a43fad370f GCBI: introduce the EntryPoint BlockType
`getType` didn't have a `BlockType` to represent the entry basic block
of the `root` function. Therefore, such basic block was erroneously
identified as a translated basic block.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 4f64816ac3 GCBI::getFunctionCall: skip markers
`GCBI::getFunctionCall` used to stop to the first marker function call,
instead of going through all of them looking for `function_call`.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico ecfb842073 Force FCI during basic block harvesting
This commit forces the function call identification analysis during
harvesting of new basic blocks. Additionally, the appropriate jump
target reasons are associated to the involved basic blocks.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 0c9945c2d0 Introduce QuickMetadata::get() 2018-12-13 18:03:11 +01:00
Alessandro Di Federico bba5bdf4fb Use std::iterator_traits in IteratorWrapper
Using `std::iterator_traits` allows `IteratorWrapper` to be employed on
pointers too.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 371c38d6b8 Add nodce to the list of marker functions 2018-12-13 18:03:11 +01:00
Alessandro Di Federico 2669d78206 Add some dump methods 2018-12-13 18:03:11 +01:00
Alessandro Di Federico 787b45630d Fix assertion messages
Assertion used to erroneously print part of the message on `stdout`.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 4c446a38fe Check for include guards starting with _ 2018-12-13 18:03:11 +01:00