Commit Graph

6113 Commits

Author SHA1 Message Date
Alessandro Di Federico bf9c6fa137 Merge branch 'feature/improve-robustness' 2019-05-27 19:50:25 +02:00
Alessandro Di Federico 707ec7c1fa Introduce preliminary Mach-O support 2019-05-27 19:36:12 +02:00
AndreaJegher 8492c56333 Enable AArch64 support (no tests)
This commit enables AArch64 as an input architecture. However, tests are
not enabled yet due to some known bugs.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico c7e1c992de DropMarkerCalls: fix dangling pointer refs
`DropMarkerCalls` used to take an `ArrayRef<StringRef>` as an argument,
however the `ArrayRef` was copied in a class field, leading to a
reference to a temporary array.

This commit switches from `ArrayRef` to `SmallVector`.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 50396ab721 revng-merge-dynamic: handle missing DT_VERNEED 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 9eb3cfd06a FunctionIsolation: update PHINodes
This commit improves the function isolation pass to fix references to
predecessor basic blocks in phi nodes.

The commit also improves handling of instruction operands to ensure no
unmapped Values are used.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 8d009296ef FCI: ignore non-translated basic blocks 2019-05-27 19:36:12 +02:00
Alessandro Di Federico b9ef70c8dc AdvancedValueInfo: handle pointer types 2019-05-27 19:36:12 +02:00
Alessandro Di Federico 877ba895af Rewrite get{BasicBlockPC,PrevPCWrite}
This commit reimplements `getBasicBlockPC` and `getPrevPCWrite` using
`BackwardBFSVisitor`, making them much more effective.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico d0e5f61b20 CSAA: allow recursion in untainted paths 2019-05-27 19:36:12 +02:00
Andrea Gussoni 9f97826806 raise_exception_helper calls exception_warning
The call to `exception_warning` in `support.c` is now performed
directly by the `raise_exception_helper` function defined in
`support.c`, so that we can avoid calling two different functions in the
translated and isolated module.
2019-05-27 19:36:12 +02:00
Alessandro Di Federico 4b542de82f Drop unnecessary masking loading CSVs
When loading a CSV, we sometimes need to mask part of the loaded
value. However, this happened also when the source and target types had
the same size, leading to complex code doing nothing.

This bug has been discovered due to a problem in i386: all the function
calls were identified as indirect.
2019-05-27 19:36:12 +02:00
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
Andrea Gussoni c76ba641aa Fix head region candidate election 2019-05-27 18:23:50 +02:00
Andrea Gussoni 5c5ae0a9de Improve metaregion collapse 2019-05-27 18:12:35 +02:00
Alessandro Di Federico 4103e1bbfb Merge branch 'feature/drop-osra' 2019-05-27 17:11:03 +02:00
Andrea Gussoni dd772f5f5f Enhance findReachableNodes algorithm
Enhanced the `findReachableNodes` algorithm, with a new `StackSet`
parallel data structure which is used to quickly check if we are
encountering a node already on the visit stack.

Modified the `findReachableNodes` to include in the returned set of
nodes also nodes which are encountered on self loop paths and that
should consequently be included in this set.
2019-05-24 18:35:52 +02:00
Andrea Gussoni 4777c81800 Add dummy node as source of retreating edges
Add a new dummy node as the source of each backedge found in the graph,
during the preprocessing.

This help in the semplification phase of the SCS, since the new dummy
node helps triggering merging of metaregions with have a non empty
intersection.
2019-05-24 18:35:52 +02:00
Andrea Gussoni 84aec352a3 Head election now always elect the first RPOT node
For now, we disable the complex criterion for the head election of an
SCS with a simple election of the first node of the region in RPOT
2019-05-24 18:35:52 +02:00
Andrea Gussoni ac34e38b2f New merge criterion for SCS regions
The new SCS merging criterion, checks that there are no abnormal
retreating nodes between SCS, meaning retreatings which exit from the
current SCS and do not point to the head of another SCS.

This kind of situation, if ignored could cause the introduction of some
cycles between outlined nodes and existing nodes, inserting new cycles
during the restructuring, which is a behavior which we aim to avoid.
2019-05-24 18:35:45 +02:00
Andrea Gussoni ead83260d6 Outlined nodes inserted in parent metaregions
When outlining nodes, we now include them in eventual parent metaregions
that included the nodes collapsed.

This should lead to minor duplication (as in the `cp` benchmark), since
we avoid duplicating two times nodes if also the external region causes
the first iteration outlining.
2019-05-24 16:10:02 +02:00
Andrea Gussoni 20a419cff2 WeightTraits to expose a generic object weight
The method which computes the weight for a `BasicBlockNode` now relies
on a new `WeightTraits` which is specialized for `BasicBlock` and for
`DotNode`.

In this way, we can change the implementation of the `getWeight` method
without having to modify the implementation inside the `revng` project.
2019-05-24 15:36:45 +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
Andrea Gussoni f9a46b26c1 Update RPOT instead of re-computing it
We know keep updated the RPOT during node removals (otherwise we have
situation of pointer clashes) instead of recomputing it at each
metaregion restructuring iteration.
2019-05-22 16:03:10 +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
Andrea Gussoni 603b80e695 getWeight implementation for BasicBlockNode
Implement a new `getWeight` method for the `BasicBlockNode` class.
This method is later used in the `untangle` pass to obtain an estimate
of the weight in terms of original instructions of the node under
analysis.

In case of a collapsed node the method recursively explore all the
collapsed region and return the sum of the weights of the nodes
composing the collapsed region.
2019-05-10 17:55:55 +02:00
Andrea Gussoni b2deb54dea Improve weight computation
Improve the computation of the weight for the nodes between the
immediate postdominator and all the exits from the region.

To do this we exploit the `findReachableNodes` helper function, since at
this point all the exits from the region are connected to the `Sink`
node.
2019-05-10 17:55:55 +02:00