Commit Graph

337 Commits

Author SHA1 Message Date
Antonio Frighetto e1528ca13c Drop StackAnalysis 2021-12-14 11:00:00 +01:00
Antonio Frighetto e892c15cc8 Integrate StackAnalysis2 with ABIAnalyses2
Integrate results of ABIAnalyses2 in StackAnalysis2
and refine such results by suppressing stack pointer
and callee-saved registers from the analyses.
2021-12-14 11:00:00 +01:00
Qian Matteo Chen 12c3ce2dba Introduce ABIAnalyses2
Architecture-agnostic and ABI-independent data-flow analyses that
traverse the recovered functions in order to detect arguments and
return values registers.
2021-12-14 10:59:56 +01:00
Antonio Frighetto 835089705e Introduce StackAnalysis2
An architecture-agnostic analysis that attempts to detect
boundaries of functions, recover the control-flow graph as
well as function prototypes (arguments and return values)
of the original program. The analysis identifies whether
the function jumps to its return address (namely, it is a
regular function), it tracks the evolution of the stack
by determining its height (in order to say if the stack is
left in a correct position upon stackframe destruction),
and it identifies callee-saved registers.
2021-12-10 12:30:11 +01:00
Antonio Frighetto a991ef2406 Introduce AAWriterPass
A simple pass that adds aliasing scope information as
comments to the IR before load and store accesses.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 6328121d02 Introduce IndirectBranchInfoPrinterPass
A simple pass that serializes the results of the StackAnalysis on disk.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 2d46979813 Introduce SegregateDirectStackAccessesPass
A pass which segregates direct stack accesses from all other
memory accesses through appropriate alias information metadata.
By doing so, we provide a way to say that stack accesses reasonably
do not interfere with any other memory access. This pass also tries
to canonicalize `inttoptr` + `add` instructions into `getelementptr`s
so as to avoid the use of `inttoptr`, which would otherwise inhibit
compiler optimizations.
2021-12-10 12:30:11 +01:00
Antonio Frighetto ebf6ab0be9 Introduce CSVAliasAnalysisPass
A pass that decorates memory accesses with
information about CSV aliasing.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 4d716a0b4f Introduce PromoteGlobalToLocalPass
A simple pass that promotes the CSVs to local variables.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 62ca93cd08 Introduce RemoveHelperCallsPass
A simple pass that removes the calls to the helpers and replaces them
with stores of an opaque value onto the CSVs clobbered by the helper.
2021-12-10 12:30:11 +01:00
Antonio Frighetto b5ba55e610 Introduce RemoveNewPCCallsPass
A simple pass that removes the calls to `newpc` marker.
2021-12-10 12:30:11 +01:00
Antonio Frighetto c9f273a93e Improve MFP 2021-12-10 12:30:11 +01:00
Antonio Frighetto ab597dc52f ProgramCounterHandler: add dissectJumpablePC
The new method `dissectJumpablePC` provides information about the
PC CSVs and allows not to make architecture-specific assumptions.
2021-12-10 12:30:11 +01:00
Antonio Frighetto ec629a20b1 JumpTargetManager: move getOption in IRHelpers 2021-12-10 12:30:11 +01:00
Antonio Frighetto 780a771064 IRHelpers: ignore abort in getFunctionCall 2021-12-10 12:30:11 +01:00
Antonio Frighetto a9315736e1 IRHelpers: refactor getPC
Dead code removal and various fixes while refactoring `getPC`.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 369a0700ac IRHelpers: overload isCallTo and getCallTo 2021-12-10 12:30:11 +01:00
Antonio Frighetto 81dd2e5cf3 GeneratedCodeBasicInfo: add purgeDomTree method
Erase element from the DominatorTree map when needed.
2021-12-10 12:30:11 +01:00
Antonio Frighetto a7d26f0148 GeneratedCodeBasicInfo: add invalidate method 2021-12-10 12:30:11 +01:00
Antonio Frighetto 9595894bcf BinaryFile: add architecture-dependent fields
Add return address register and minimal final stack offset in Arch.
2021-12-10 12:30:11 +01:00
Antonio Frighetto 2656b72eed IRHelpers: overload extract for int64_t 2021-12-10 12:30:11 +01:00
Antonio Frighetto bfb2087d43 ZipMapIterator: add support for llvm::DenseMap 2021-12-10 12:30:11 +01:00
Antonio Frighetto c9a42cec36 Model: handle NoReturn functions in CallEdge 2021-12-10 12:30:11 +01:00
Alessandro Di Federico f789a3ec5f Introduce model::FunctionAttributes 2021-12-10 12:30:11 +01:00
Alessandro Di Federico 8bb4998b47 Move GCBI.getMetaAddressMetadata to IRHelpers.h 2021-12-10 12:30:11 +01:00
Alvise de Faveri 2f4b716e6b Add Model::toString() and writeToFile()
These functions can be used in conjunction to dump the Model on a
file during a gdb session, for example:

```
(gdb)  p  writeToFile(Model->toString(), "/tmp/model.yaml")
```
2021-11-19 10:17:09 +01:00
Ivan Krysak 52f7432f1b Add model::Architecture::getPointerSize() 2021-11-08 16:17:47 +01:00
Alvise de Faveri 2e19fade43 Fix memory leak in TupleTreeKeyWrapper::clone
ConcreteTupleTreeKeyWrapper::clone() should cleanup the Target object
befor cloning, otherwise the destructor of the inner Pointer object
is never called.
2021-10-27 08:42:53 +02:00
Pietro Fezzardi c050dcb621 Handle missing model in SerializeModelPass
Before this commit, SerializeModelPass and SerializeModelWrapperPass had
hard dependencies on the passes that load the model from LLVM-IR.

This commit makes this dependency optional. When the passes for model
serialization are executed, if they see that nobody requested to load
the model, they will not try to serialize it.

This prevents them from crashing when running in pipelines that only
contain passes that ignore the model.

This is particularly beneficial because `revng opt` automatically adds
`-serialize-model` at the end of each pipeline and, before this commit,
this meant that `revng opt` could not be used for unit-testing simple
llvm passes that do not use the model.

With this commit, `revng opt` can be used for unit-tests, even on LLVM IR
with missing model.
2021-10-21 15:02:01 +02:00
Alessandro Di Federico 83f420abda Introduce dump method for model structs 2021-10-21 15:02:00 +02:00
Alessandro Di Federico eb2c3df925 Tag with MetaAddress functions and call sites 2021-10-21 15:02:00 +02:00
Alessandro Di Federico 8546a0c786 CallEdge: only indirect calls have a prototype 2021-10-21 15:01:59 +02:00
Alessandro Di Federico 89532890ed Introduce support for importing DWARF information 2021-10-21 15:01:20 +02:00
Alessandro Di Federico 3a3eea0cf5 Introduce support for dynamic functions 2021-10-21 15:01:19 +02:00
Alessandro Di Federico a023bfa7f5 Introduce ABI handling 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 0dfc81da41 Minor model improvements
* Introduce some documentation for the model.
* Improve the way enums are serialized/deserialized.
* Mark certain fields of model data structures as optional.
* introduces some error messages during model validation.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 5b50a3320f Introduce error messages during model validation 2021-10-18 20:44:58 +02:00
Alessandro Di Federico d5bfb872d6 Introduce SortedVector::isSorted
This is a debug method.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 18cfbdbfe0 Whitespace and other minor changes 2021-10-18 12:39:21 +02:00
Ivan Krysak 6714c4cb58 Add Node::copy() and Node::move()
Those member functions are an easy way to reach the underlying node data
without affecting the edges stored by the node.
2021-10-04 14:38:42 +02:00
Pietro Fezzardi a0dbea19e5 Prevent model::Type CustomNames from colliding
This commit reserves the "unnamed_" prefix for revng.
The first use of this reserved prefix is in `model::Type`s
`CustomName`s and `model::Identifier`s.
This commit also makes the `verify()` method stricter for
`model::Identifier` so that an `Identifier` whose name starts with the
reserved prefix does fails verification.
2021-09-02 14:55:47 +02:00
Pietro Fezzardi 3d38451abd Enable error checking on Model deserialization
This commit changes the `TupleTree::deserialize` method to return an
`llvm::ErrorOr<TupleTree>`, enabling users to choose their policies on
error reporting.
2021-09-02 14:42:51 +02:00
Pietro Fezzardi bae9214652 Stricten verification for model::Identifier
Now only `Identifier`s that are valid C identifiers are guaranteed to
verify.
The `fromString` factory is updated accordingly.
2021-09-02 14:42:47 +02:00
Pietro Fezzardi 48f6a60629 Fix callOnPathSteps for KeyedObjectContainer
callOnPathSteps was using linear scan search in KeyedObjectContainer.
This commit fixes it for using binary search, dramatically improving
performance in workloads that do lots of lookups.
2021-09-02 14:39:23 +02:00
Pietro Fezzardi 3f5644dd02 Add operator<=> for model::Qualifier
This allows to keep `model::Qualifier`s in ordered containers, which is
necessary e.g. in `revng-c`.
2021-09-02 14:39:23 +02:00
Pietro Fezzardi aa46b03050 Add name() members to various Model types 2021-09-02 14:39:23 +02:00
Pietro Fezzardi 44b348db6a Provide efficient getName for model::Type enums 2021-09-02 14:39:23 +02:00
Ivan Krysak 612461cffa Enable more explicit edge iteration
Add reverse iterator support
2021-09-02 11:09:29 +03:00
Ivan Krysak 509ee3c41a Disallow label-less mutable edge graphs 2021-09-02 11:09:17 +03:00
Ivan Krysak 95e983fef3 Rename has_parent into HasParent 2021-09-02 11:09:04 +03:00