Commit Graph

1642 Commits

Author SHA1 Message Date
Alessandro Di Federico 1c6f8ee0f0 Fix disassembly printing too many instructions
This commit fixes a bug that lead to print 4096 disassembly instructions
at a time instead of one. This restore `--debug-log ptc` into a useful
state.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 53df3086ce FunctionIsolation: do not remove anypc and friends 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 357d88377d EnforceABI: Killer branches are noreturn 2019-05-27 19:36:12 +02:00
Alessandro Di Federico c232e20be8 s/func.entry/revng.func.entry/ leftover 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 7815c551db Support for file names in Logger
`Logger` can now print the file name from which it was called
(`--debug-location-max-length`).
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 706b1d8e71 revng script: use sh instead of env
`env` sometimes is not a real executable but a shebang script spawning
/usr/bin/coreutils, which makes gdb unhappy.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 061906af3e Suppress GCC 9.1 warnings due to false positives 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 5eee55ff11 Whitespace and other minor changes 2019-05-27 19:34:44 +02:00
Alessandro Di Federico 4103e1bbfb Merge branch 'feature/drop-osra' 2019-05-27 17:11:03 +02:00
Alessandro Di Federico 378d6366fe Let CpuLoopFunctionPass handle exception_index
`CpuLoopFunctionPass` is a pass performing some changes to
`cpu_loop`. Among these, calls to `cpu_*_exec` are replaced with the
value of `exception_index`.

This commit does not directly loads it but computes its address as an
offset from `CPUState`. This commit goes in tandem with the
corresponding QEMU commit which provide `exception_index` as an offset
from `CPUState` instead than from `env`. All of this makes CSAA more
effective.
2019-05-22 21:30:29 +02:00
Alessandro Di Federico 5009074e9e Introduce AdvancedValueInfo for JT discovery
* Introduce `ShrinkInstructionOperandsPass`: a transformation shrinking
  operands and the results of instructions if they are
  zero/sign-extended immediately before and after the instruction.
* Introduce `ConstantRangeSet`: similar to `ConstantRange` but allows
  disjoint ranges.
* Introduce `MaterializedValue`: a class that can represent a constant
  value or a symbol plus offset pair.
* Introduce `DropHelperCallsPass`: a transformation removing calls to
  helpers and replacing them with a function call reading the CSVs that
  the helper reads and writing the CSVs that the helper writes
  (according to CSAA).
* Introduce `DropRangeMetadataPass`: a transformation dropping the
  `range` metadata, which, in certain situations, lowers the quality of
  the results provided by `LazyValueInfo`.
* Introduce `AdvancedValueInfo`: an analysis exploiting results of
  `LazyValueInfo` but collecting them as `ConstantRangeSet` with a
  monotone framework. It produces `MaterializedValue`.
* Anticipate linking of helpers: `AVI` requires `CSAA`, which requires
  helper functions to be linked in.
* Drop `--no-link`.
* Force x86-64 `DataLayout`.
* Reorganize harvesting to either collect simple literals or go with
  (incremental) `AVI`.
* Drop `SET`, `OSRA`, the reaching definition analysis, the
  `SimplifyComparisonsPass` and all the sumjump-related code: e now
  clone `root`, optimize it and analyze it with `AVI`.
* Temporarily drop the `NoReturnAnalysis`.
* Link `libLLVMInstCombine`, `libLLVMCodeGen` and `libLLVMPasses`.
* Introduce tests for `AdvancedValueInfo`,
  `ShrinkInstructionOperandsPass` and `ConstantRangeSet`.
* Fix test results.
* Add `llvm.bswap.i64` and `@pc` to the LLVM template module for unit
  tests.
2019-05-22 21:30:29 +02:00
Alessandro Di Federico c8998cdece StackAnalysis: election of return SP value
Any stack pointer value greater than or equal to the original one used
to be OK for stack analysis to recognize an instruction as a
return. This commit changes this policy by collecting the value of the
stack pointer on all the return points and, at the end, elect a final
stack pointer value. All non-compliant returns are marked a
`BranchType::BrokenReturn`. The function is now considered fake only if
all the return instructions agree on a specific value of the stack
pointer, and it's lower than the original one.

* Drop `BranchType::IndirectTail`.
* `s/BranchType::FunctionSummary/BranchType::RegularFunction/`.
2019-05-22 21:30:29 +02:00
Alessandro Di Federico a9de053243 Introduce GraphAlgorithms
A series of algorithms working on `llvm::GraphTraits`.

* `nodesBetween` computes the set of nodes on all the paths from a node
  A to B.
* Factor out code to iterate over infinite loops into
  `exitless_scc_range`.
* Introduce unit tests.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico 467d25693e MonotoneFramework: support user-provided BB list
Let the user provide the list of the basic blocks to visit, in a
specific order. This is useful when the same graph has to be visited
multiple times to avoid having `MonotoneFramework` recompute the reverse
post order each time.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico b7ce437469 EnforceABI: completely ignore the stack pointer 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 09cf8ecfbc StackAnalysis: fix bug involving EmptyCallSummary 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 0e9d453be3 ZipMapIterator changes
* Introduce `KeyContainer::compare` and drop the `getKey` method.
* Let users of ZipMapIterator specify a trait class instead of using the
  default one.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico 19f6f84d73 Various improvements to the revng script
* Handle SIGINT in children gracefully (`run` function).
* `run_translate`: return 0 on success.
* Move useful information about the `revng` installation from
  `--version` to `--help`.
* Do not `execv` on external commands, otherwise the script will not
  proceed.
* Print current directory-relative paths with `--verbose`.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico 3bef125a54 PTCInstructionList: release memory after free
To release memory of a `PTCInstructionList`, we used to call
`ptc_instruction_list_free` only. However, that function does not
release memory. This commit calls `delete` to actually release the
memory and prevent memory from leaking.
2019-05-22 18:42:32 +02:00
Alessandro Di Federico 8627a32b4e dlopen: use RTLD_NODELETE to make ASan happy 2019-05-22 18:42:32 +02:00
Alessandro Di Federico ddb23e7147 CSAA: use more conventional metadata names 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 00d5a00d86 CSAA: handle casted users of env 2019-05-22 18:42:32 +02:00
Alessandro Di Federico 806108d34a Tag unit tests with the unit label
Now you can run them in a single shot with `ctest -L unit`.
2019-05-22 18:42:32 +02:00
Pietro Fezzardi f205a28d97 CPUStateAccessAnalysis: handle recursion 2019-05-22 18:42:32 +02:00
Pietro Fezzardi e5e7d760e7 Improve debug print for nullptr Value * 2019-05-21 16:46:20 +02:00
Pietro Fezzardi 90bdfb07c8 Make CPUStateAccessAnalysisPass lazy on demand
CPUStateAccessAnalysisPass can now run lazily and accumulate partial
results. Actual fixes to the accesses to the CPU State (to make them
explicit) are only applied when the analysis is run in non-lazy mode.
2019-05-21 16:46:20 +02:00
Alessandro Di Federico 6ae3b6f22f Whitespace and other minor changes
* `GeneratedCodeBasicInfo::getCSVUsedByHelperCall` and
  `GeneratedCodeBasicInfo::extractCSVs`: make the call argument an
  `Instruction`.
* Introduce `blockByName`
* Introduce `getUniqueUser`.
* Fix linking issues.
2019-05-14 16:27:13 +02:00
Alessandro Di Federico feb06d180c Use revng --verbose in tests
This enables more informative debug logs.
2019-04-22 05:40:28 +02:00
Alessandro Di Federico 17eaaa1b0c Whitelist architectures in tests
We used to list all the architectures supported by QEMU in tests,
however this not optimal. This commit switches to a whitelist for the
list of architectures to tests so that we don't test architectures for
which we have a toolchain but aren't ready for the testsuite.
2019-04-22 05:40:28 +02:00
Alessandro Di Federico d411978af7 revng translate: invoke revng-lift directly 2019-04-22 05:40:27 +02:00
Andrea Gussoni 616c162523 DotGraph and DotNode
This commit implements a simple wrapper class able to parse a GraphViz
file in an object implementing the LLVM `GraphTraits`.
2019-04-22 05:40:27 +02:00
Alessandro Di Federico 4d5493fe7f Warning on translation of non-x86-64 dynamic ELF
We can currently successfully translate only dynamic binaries for
x86-64. Warn the user about this early on instead of failing in
`revng-merge-dynamic`.
2019-04-21 10:17:08 +02:00
Alessandro Di Federico 39a5a217c4 revng script: detect AArch64 2019-04-21 10:16:51 +02:00
Alessandro Di Federico 2f2b1f6ffe revng script: wrap executables 2019-04-12 19:17:23 +02:00
Alessandro Di Federico d75e5f3b6a Improve detection of external function calls
This commit enlarges the set of external function calls we
detect. Basically, instead of assuming that the instruction jumping to
the external function is the call, we now also consider instructions in
previous basic blocks, as long as there's only one possible path
backward.
2019-04-11 19:51:32 +02:00
Alessandro Di Federico d50fbe969a Update documentation and add revng. to metadata 2019-04-11 19:51:32 +02:00
Alessandro Di Federico 2a5081328c NRA: do not iterate while deleting calls 2019-04-11 18:16:53 +02:00
Alessandro Di Federico 9f4711b770 Improve revng help and ASAN support
This commit improves the output of `--help` and reduces the output of
`--version`.  This commit, when calling `opt`, injects a `LD_PRELOAD`
for `libasan.so` in case a `librevng*.so` library uses it.
2019-04-11 18:16:53 +02:00
Alessandro Di Federico d77ad08917 Drop leftover references to revamb 2019-04-11 17:44:39 +02:00
Alessandro Di Federico dda91e8c90 ClassSentinel prevent test failures
`ClassSentinel` makes use of an undefined behavior to check if an object
has been destroyed. Disable this check in case of presence of address
sanitizer or even regular optimizations.
2019-04-04 22:58:21 +02:00
Alain Carlucci 51a58a5513 Add support for PE32+ (x86-64) 2019-04-04 22:55:45 +02:00
Alessandro Di Federico 8337f70ca6 Merge branch 'feature/preliminary-c' 2019-03-08 15:25:39 +01:00
Alessandro Di Federico 63f0efbada Temporarily disable OSRA-related failing tests 2019-03-08 15:05:10 +01:00
Pietro Fezzardi 76135b76fb Add RemoveDbgMetadata FunctionPass 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 28ceefcac3 SA: unify management of CSV indices 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 02273d58e6 Add ABI registers for architectures missing them 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 489e4b1d87 ABI analysis: ignore non-CSV used by helpers 2019-03-08 15:00:59 +01:00
Alessandro Di Federico 5904e78bdb Disable exceptions 2019-03-08 15:00:59 +01:00
Alessandro Di Federico c2d39fb702 SA: reorganize the way functions are registered 2019-03-08 15:00:59 +01:00
Alessandro Di Federico baef567365 ABI: ECSR are not "No" for function calls
Register marked as explicitly callee saved in a function used to be
marked as No both for the current function and all of its function
calls. However, the latter action is not accurate.
2019-03-08 15:00:59 +01:00