Commit Graph

1642 Commits

Author SHA1 Message Date
Alessandro Di Federico 0cf1d2b44a Associate to noreturn BBs a noreturn metadata 2016-12-03 08:46:12 +01:00
Alessandro Di Federico 5ca3200114 Update command line description of revamb 2016-12-03 08:46:12 +01:00
Alessandro Di Federico 786c809e6f Associate each BB with the functions it belongs to
Create a MDNode for each identified function and associate to the
terminator instruction of each basic block a list containing a reference
to the MDNodes identifying the functions it belongs to.
2016-12-03 08:46:12 +01:00
Alessandro Di Federico bc6a732ad7 Don't compute function boundaries by default 2016-12-03 08:46:12 +01:00
Alessandro Di Federico 4f60a23d9a JTM::readRawValue: fix endianess bug
`JumpTargetManager::readRawValue` used to take into account the
endianess information from `DataLayout`, i.e., the output endianess,
while the input endianess should be take into account.

The commit also checks that during final basic block finalization we
have no empty basic blocks.
2016-12-03 08:46:12 +01:00
Alessandro Di Federico 83ea2caacd Isolate ELF code and remove architecture parameter
This commit removes all the ELF-specific code from the `CodeGenerator`
class by creating a new class, `BinaryFile` which contains all the
information about the program that might be needed in an image format
independent way. However, `BinaryFile` has some fields which are
specific to ELF, we might want to address this when additional file
formats are supported.

A key benefit of isolating this code is that we can anticipate the
parsing of the input file, so that we have its architecture available
earlier than when `CodeGenerator` is instantiated, therefore we can drop
the `--architecture` parameter.
2016-12-03 08:46:12 +01:00
Alessandro Di Federico 4460770b07 Handle binaries without syscalls correctly 2016-12-03 08:46:12 +01:00
Alessandro Di Federico c50dcc5c5d Use symbols to produce meaningful names
This commit introduces the usage of symbols, if they are available. We
employ them to produce meaningful names for basic block names.

* Collect the symbols from `.symtab`/`.dynsym`
* Box the `Segments` into a new data structure (`BinaryInfo`) which also
  handles symbols.
* `JumpTargetManager::nameForAddress`: produce a meaningful name using
  symbols, if possible.
* Spread some `const`-ness
2016-09-28 00:03:13 +02:00
Alessandro Di Federico d48715494d Improve installation
* Use "$ORIGIN/../lib/" as RPATH when linking the installed binary
* Install also support material such as "support.c"
* Import the `translate` script for easy end-to-end translation
2016-09-22 22:44:16 +02:00
Alessandro Di Federico 59c871afc5 Make revamb portable
Add different search paths for QEMU components, in paritcular relative
to the program's path.
Also, install the revamb.
2016-09-22 18:45:59 +02:00
Alessandro Di Federico ccd5795d37 Remove wrong assertion related to forced BVs 2016-09-21 21:39:00 +02:00
Alessandro Di Federico 95cf77d3b3 Downgrade from C++14 to C++11 2016-09-21 04:50:17 +02:00
Alessandro Di Federico d01ee1f437 Copyright notices, license and credits 2016-09-21 01:45:26 +02:00
Alessandro Di Federico 53b1dfbb5d Improve autodetection of QEMU's location 2016-09-21 01:45:26 +02:00
Alessandro Di Federico b98c163c3e Implement the path function in support.c
The `path` function allows support.c to decide how to modify the path
opened by the translated program.
2016-09-21 01:45:26 +02:00
Alessandro Di Federico f0c12bfac4 Fixes to the testing infrastructure
* Disable PIE if enabled by default
* Link librt.so to compiled binaries (sometimes the QEMU runtime needs
  it)
* Replace `strtonum` with `int` in `awk` script
* Specify the compiler, not the triple
2016-09-21 01:45:26 +02:00
Alessandro Di Federico c7990ae60c Autodetect the compiler to use
Check in PATH if there's a compiler compatible with the supported ones
(i.e., using uclibc or musl) and use that triple.
2016-09-21 01:45:19 +02:00
Alessandro Di Federico 29879c8de2 Remove some dead code 2016-09-17 15:33:57 +02:00
Alessandro Di Federico adb45173ef Preserve user's CMAKE_CXX_FLAGS 2016-09-17 15:33:57 +02:00
Alessandro Di Federico 5af920a69d Enforce 80 columns 2016-09-17 15:33:57 +02:00
Alessandro Di Federico 4acae6beed Limit propagation of reaching definitions
This commit handles two cases related to function calls where we want to
limit the propagation of reaching definitions. In the first case down
through function calls, in the second case back up through return
instructions.

For the call instructions, we choose to stop the propagation of reaching
definitions to the callee, since we assume each function should check
its arguments if they affect the control-flow. In particular, this
allows a larger coverage of the function body in case, being able to
enumerate all the calls, we consider dead code those parts that, in the
current program would nevere be executed. Right now we do it in all
cases, it would be more appropriate to do this only if the address of
the function is taken. Also, we should expand this also for tail calls.

For what concerns return instructions, a function called from a lot of
different locations in the code receives a huge number of reaching
definitions. If its close to a no-op, it will also propagate most of
them through the return path. This is an hack to limit how such
definitions spread around the code.

A proper solution, requires to detect the calling convention and allow
to propagate along return paths only return values.
2016-09-17 15:33:57 +02:00
Alessandro Di Federico cc87ad607d Introduce NoreturnAnalysis
This commit introduces the `noreturn` analysis, whose aim is to detect
all the basic blocks the are doomed to lead to a `noreturn` syscall such
as `execve` or `exit`.

* Implement `NoreturnAnalysis`.
* Include and initialize in the `Architecture` data structure all the
  necessary information to detect `noreturn` syscalls. Specifically, the
  name of the QEMU helper for syscalls, the name of the register holding
  the syscall number and the syscall numbers representing `noreturn`
  syscalls.
* `ReachingDefinitionsPass`: make reaching definitions available both in
  reaching definitions mode and reached loads mode. This part needs
  further cleanup. We also might be willing to implement this with a
  `Boost.Bimap`.
* Use `SET` to collect information useful for the
  `NoreturnAnalysis`. Also restructure how the `OperationsStack` works
  to be more streamlined and keep track of multiple information about
  the instruction currently being tracked.
2016-09-17 15:33:57 +02:00
Alessandro Di Federico 37de0a0002 Introduce FunctionBoundariesDetectionPass
`FunctionBoundariesDetectionPass` implements our function detection
system.
2016-09-17 15:33:57 +02:00
Alessandro Di Federico 8dfda3d55a Keep track of memory ranges read by SET 2016-09-17 15:33:56 +02:00
Alessandro Di Federico f168621aa7 If OSRA provides no useful information, use SET 2016-09-17 15:33:56 +02:00
Alessandro Di Federico e9834e25b9 Exploit the power of unsigned comparisons
An unsigned comparison such as `x - 3 < 5` carries two information: the
first is the obvious one (`x < 8`), but the other one is even more
interesting. In fact any unsigned comparison implies that the LHS is not
negative, therefore we also can state that `x >= 3`. This commit
implements the usage of this information.
2016-09-17 15:33:56 +02:00
Alessandro Di Federico 621095c31a Create OSRs also for trunc and zext instructions 2016-09-17 15:33:56 +02:00
Alessandro Di Federico bdc0c221bd Consider AllocaInst in RDA 2016-09-17 15:33:56 +02:00
Alessandro Di Federico f51c0c2771 Ignore undef values in SET 2016-09-17 15:33:56 +02:00
Alessandro Di Federico 65190dc20e OSRA: bugfixes about constant bounded values
* When creating a new `BoundedValue`, check if the value associated to
  it is a `ConstantInt` and if so, initialize the boundaries and the the
  signedness as appropriate.
* Add various checks for the presence of the signedness information
  before using functions that might require it.
2016-09-17 15:33:56 +02:00
Alessandro Di Federico 51d73d6b18 Register analysis passes as such 2016-09-17 15:33:56 +02:00
Alessandro Di Federico 46fe86225b Free memory after analyses
* Clear all the data that's not part of the analysis results at the end
  of the `runOnFunction` method
* Clear all the data that's part of the analysis results when the
  `PassManager` tells us so (`Pass::releaseMemory`)
* Do not use the `clear()` method, since it doesn't release memory
* Add some debugging information
2016-09-17 15:33:56 +02:00
Alessandro Di Federico 7e8ac596b5 Minimize pathSensitiveMerge usage
Record amount of reaching definitions for each load, even in
`ReachedLoads` mode, so that we can run the `pathSensitiveMerge` only
when we're sure we've collected all of them.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 785e74dafe CRDP: use an hash table of SmallVectors for RD
In `ConditionalReachingDefinitionsPass` switch from a `std::vector` of
pairs to an `std::unordered_map` of `llvm::SmallVector`. This is a
non-negligible impact on performances.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico bd9face7fe Add braces around std::array initializers
This commit fixes a bug preventing clang from correctly compiling the
code.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 5671806fe0 Anticipate specializations in Reachingdefinitions
This commit fixes a bug preventing clang from compiling the code
correctly.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 168bac9079 Merge of BV: handle the [0,1] | [2,3] case 2016-09-17 15:33:55 +02:00
Alessandro Di Federico c1742184e7 OSRA: subscription for the update of load reachers
An instruction can now subscribe for the change of the list of reachers
of a certain load. This is particularly useful in the case of `ICmp`
instructions, which might hold constraints about the reachers of a
certain load without actually being a its user.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 65baa9fec0 Let SET always try to register the jump target
This patch removes the `JumpTargetManager::isInterestingPC` function
which used to prevent to register a jump target if it already
was. However this also prevents from marking that jump target as seen by
SET.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico e177c5f2ff Expose the JumpTarget class to JTM users
This patch introduces in `JumpTargetManager` a pair of `begin` and `end`
methods which allow to iterate over all the registered jump targets, and
obtain the reason that lead to register them (through the `JumpTarget`
class).
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 1254f400c3 Introduce OnceQueue
`OnceQueue` is a queue which not only keeps track of what's already in
the queue and prevents it from being re-inserted, but also keeps track
of what has ever been in the queue, and prevents it from returning to
the queue.

`OnceQueue` is implemented by adding a new template parameter to what
was once `UniquedQueue`.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 7859f9de78 Keep track of how jump targets have been met
This commit registers for each jump target how we met it, as a flag. It
also keeps track of which pointers in global data have been involved in
materialization performed by SET: those who are not are of special
interest for us, since they are likely function pointers, and are
therefore marked with a specific flag.
2016-09-17 15:33:55 +02:00
Alessandro Di Federico 4ae7cdadaa Dismiss JumpTargetManager::registerBlock 2016-09-17 15:33:54 +02:00
Alessandro Di Federico 27b4e46525 Draft tracking of reasons for registering JTs 2016-09-17 15:33:54 +02:00
Alessandro Di Federico 1d87dced75 Drop the concept of "reliable" jump target 2016-09-17 15:33:54 +02:00
Alessandro Di Federico 6c5c0ad8f7 Add support for using section information 2016-09-17 15:33:54 +02:00
Alessandro Di Federico 9487f0e400 Assign labels to tests 2016-09-17 15:33:54 +02:00
Alessandro Di Federico dd7e05d6c1 exitTBCleanup: don't delete with pending uses 2016-09-17 15:33:54 +02:00
Alessandro Di Federico f4d71cf926 OSRA: improve handling of multi-defined loads
Before this commit, loads with multiple definitions were handled by
simply checking if all the definitions agreed. Now we also implement
some logic to put constraints on the new OSR, in case they don't agree.

To do this we implement a path-sensitive algorithm to collect
constraints about the reaching definitions.

This commit also introduce a set of methods to, if possible, apply an
OSR to a BoundedValue, e.g. [1 + 1 * x] will produce a new BoundedValue
whose bounds are shifted of 1 unit.
2016-09-17 15:33:54 +02:00
Alessandro Di Federico 37f54ffc8d Handle some undef cases building ConstantExprs
Some undefined behaviors, which result in `undef` values, are now
handled in `OSR::solveEquation`.
2016-09-17 15:33:54 +02:00