Commit Graph

3168 Commits

Author SHA1 Message Date
Pietro Fezzardi 290f3a557c SegregateStack: emit ModelGEPs in only legacy mode 2025-01-29 15:17:15 +01:00
Pietro Fezzardi fd46acc72b SegregateStack: LocalVariableBuilder for stack arg 2025-01-29 15:17:15 +01:00
Pietro Fezzardi a6883064fd SegregateStack: refactor creation of AddressOf 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 8fff02b45c SegregateStack: LocalVariableBuilder for stack 2025-01-29 15:17:15 +01:00
Pietro Fezzardi fcab2e0c19 SegregateStack: LocalVariableBuilder for locals 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 59a1434fab Segregate: add template for legacy local variables
Introduce LegacySegregateStackAccessesPipe

This commit restructures the SegregateStackAccesses pass and
SegregateStackAccessesPipe so that they can have 2 modes of operations:
1. Legacy, with the same behavior as the old version, injecting local
   variables as custom llvm::Functions representing opcodes, such as
   LocalVariable, AddressOf, StackFrameAllocator, and CallStackArguments
   allocator.
2. Non-legacy, that is meant to operate with the new LocalVariableHelper
   to inject local variables as regular alloca instructions, with
   additional metadata to discriminate among them.

This commit renames the old SegregateStackAccessesPipe to
LegacySegregateStackAccessesPipe.
It then re-uses the old SegregateStackAccessesPipe name for a new pipe,
meant to work in non-legacy mode.

The pipeline definition YAML file is updated to keep using the legacy
version for now.

For now the implementation is still the same.
2025-01-29 15:17:15 +01:00
Pietro Fezzardi 189693140d Add LocalVariableBuilder 2025-01-29 15:17:15 +01:00
Pietro Fezzardi a9c16f8c79 Add helpers to manipulate model type metadata 2025-01-29 15:17:15 +01:00
Pietro Fezzardi e9528f4647 Fix getCopyType function type
This commit changes the prototype of getCopeType, so that it now takes 2
arguments.
1. The llvm::Type returned by the Copy function. This can be any scalar
   llvm::Type.
2. The llvm::type of the argument representing the reference to the
   value being copied. This should be a pointer-sized integer, where
   pointer-sized means with the same size of a pointer in the
   architecture in the input binary.

The second argument is not strictly necessary for now, because the whole
decompilation framework expects a binary with a single architecture,
hence a well defined unambiguous pointer size.
This will be used fully only when we start supporting multiple binaries.
Whenever that happens, if we haven't already fully dropped the Copy
helper function we will have to update the associated
OpaqueFunctionsPool to a type pair as key: the return type and the type
of the argument.
2025-01-29 15:17:15 +01:00
Pietro Fezzardi b0a071d2af Segregate: simplify ReturnMethod::ModelAggregate
This is preliminary to unifying the creation and handling of local
variable declarations, to simplify switching over to local variables
represented by plain allocas.
2025-01-29 15:17:15 +01:00
Pietro Fezzardi 18ec6ac53c MakeSegmentRef: use hasSegmentKeyMetadata helper 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 142428c9a1 TypeNames: assert no CABIFT returns a RegisterSet
This assertion mirrors the equivalent set of assertions on RFT, that
never return ModelAggregate.
2025-01-29 15:17:15 +01:00
Pietro Fezzardi 1fb613579f Drop leftover useless files 2025-01-29 15:17:15 +01:00
Alessandro Di Federico 36edf810ef Introduce support for function pointers 2025-01-28 15:20:45 +01:00
Alessandro Di Federico b523889742 DwarfImporter: try .debug before giving up
Also, improve logging.
2025-01-28 15:20:45 +01:00
Alessandro Di Federico dfe0970715 FromUnusedAddressesPass: use simple literals
Consider simple literals as candidates for the second run of function
collection.
2025-01-28 15:20:45 +01:00
Alessandro Di Federico 2128a80cc8 Preserve metadata after Function::deleteBody
Also, introduce and adopt a simple helper class to get this right.
2025-01-28 12:19:16 +01:00
Alessandro Di Federico b70b3cbe55 RootAnalyzer: improve logging 2025-01-28 12:19:16 +01:00
Andrea Gussoni 1855bb9e87 ScopeGraph: fix marker call prototypes 2025-01-27 23:27:59 +01:00
Pietro Fezzardi 3137de6146 DLA: fix stack type size initialization
Before this commit, the DLA frontend wasn't initializing the size of
stack types properly, nor tracking the fact that they are not scalar.

These 2 problems were causing stack types to be merged with other types
in the DLA pipeline, possibly even scalar types and in some situations
changing the size of the stack type.
All these consequences were just wrong and need to be avoided because
they break assumptions of the DLA pipeline, leading to crashes in the
DLA backend, when trying update the model to integrate DLA's results.

This commit prevents all the mentioned wrong manipulation of stack
types, simply by correctly assigning an the size of the stack type from
the beginning, and marking it as non scalar.
2025-01-15 11:48:21 +01:00
Pietro Fezzardi 6ceca5891b MakeSegmentRef: ignore args of OpaqueExtractValue 2025-01-10 16:47:05 +01:00
Lauri Vasama 4a0867e394 Add emit-c MLIR pass 2025-01-10 08:04:20 +02:00
Lauri Vasama bda55aac19 Add Clift C Backend 2025-01-10 08:04:20 +02:00
Lauri Vasama aaddafa15b Add check for conflicting local names in Clift 2025-01-10 08:03:20 +02:00
Lauri Vasama 4cedc22efb Merge access ops into AccessOp with indirect flag 2025-01-02 11:25:32 +02:00
Lauri Vasama 769c357648 Merge SizedType into TypeDefinitionAttr 2025-01-02 11:25:32 +02:00
Lauri Vasama 9f6003f1f4 Add SwitchOp::getConditionType 2025-01-02 11:25:32 +02:00
Lauri Vasama fe2e70e885 Improve label and goto ops 2025-01-02 11:25:32 +02:00
Lauri Vasama da8e581861 Loosen LocalVariableOp verification 2025-01-02 11:25:32 +02:00
Lauri Vasama 3b8e9dc3bb Loosen YieldOp verification
Yield is not return. There is no need to verify the types being yielded.
f; is a valid expression statement, even when f is a function. In this
case a function is yielded, but that is fine.
2025-01-02 11:25:32 +02:00
Lauri Vasama 03ef33f65c Add function location reference functions 2025-01-02 11:25:32 +02:00
Lauri Vasama 814e025ee2 Remove moves before return in NameBuilder.cpp 2025-01-02 11:25:32 +02:00
Lauri Vasama 1195617e5b Add revng_register_library, use for MLIR libs 2025-01-02 11:25:32 +02:00
Giacomo Vercesi 05041a302a PipelineManager: save after running analyses
Save the context after an analysis (or analyses-list) has run. This
guarantees that at least the model is preserved in case of crash.
2024-12-20 12:24:28 +01:00
Andrea Gussoni 26cf42eb12 ESE: Introduce the Enforce Single Exit pass
Introduce the Enforce Single Exit pass, whose task is to normalize a
generic `ScopeGraph`, which may have multiple exit blocks (and/or
infinite loop regions), in order to have a single `sink_block` as exit
block.

This is done by adding a new entry block, a `sink_block`, and some
`scope_closer` edges (which are visible only on the `ScopeGraph`) that
enforce the property.

This is done taking inspiration from how the internally the
`PostDominatorTree` pass construct the temporary graph on which the post
dominance information is computed on.

Some unit tests are added in order to verify that the pass works as
expected.
2024-12-18 10:51:40 +01:00
Alessandro Di Federico 276a4aa974 Generate model docs 2024-12-11 16:15:10 +01:00
Andrea Gussoni fa69bd24e5 ScopeGraph: introduce the ScopeGraph
Introduce the `ScopeCloser` and `GotoTarget` annotations in the IR, and
the relative necessary machinery, needed to handle scope closer and goto
edges for the new backend.

A specialization of the `llvm::GraphTraits`, called `ScopeGraph`, that
is able to handle both the above mentioned annotations is provided.

For the `llvm::GraphTraits` implementation, we introduce the
`GeneratorIterator` class, which uses a coroutine to store the status of
the iteration.

A debug logger pass is added, so that we are able to test the
functionality with `FileCheck`.
2024-12-05 15:43:57 +01:00
Andrea Gussoni 023771f084 FunctionTags: correct typo
Correct `function-dispatcher` typo.
2024-12-04 11:22:00 +01:00
Alessandro Di Federico ab0010b3f6 Reduce usage of PostHelper jump targets 2024-12-03 12:13:15 +01:00
Alessandro Di Federico 832840c307 Importers: ignore unmapped code
This commit ensures that parts of the model that must point to code
(specifically `Binary::EntryPoint`, `Binary::ExtraCodeAddresses` and
`Function::Entry`) actually point to a segment mapped as +x.
2024-11-28 15:22:10 +01:00
Alessandro Di Federico 37feb2dd77 Binary::verify: verify executable addresses
Fail if code addresses are not within an executable segment.
2024-11-28 14:04:36 +01:00
Alessandro Di Federico 278c6f625c Importers: first of all, Segments
This commit makes sure that before setting EntryPoint, adding
ExtraCodeAddresses or Function entry points, we completed the processing
of Segments.
2024-11-28 14:04:36 +01:00
Alessandro Di Federico d1252046ce Importers: do not set EntryPoint, if absent 2024-11-28 13:58:29 +01:00
Alessandro Di Federico 1e2a55e372 Minor changes 2024-11-28 13:58:28 +01:00
Alessandro Di Federico 6e733427bc emitMessage: fix function calle emission 2024-11-27 17:18:39 +01:00
Alessandro Di Federico 11d8515f46 ModelToHeader: adjust blank lines 2024-11-27 17:18:12 +01:00
Giacomo Vercesi 58b326b8fa ZstdStream: remove manual memory management
Remove the use of manual memory management, convert to the use of
`std::unique_ptr`.
2024-11-26 09:48:37 +01:00
Giacomo Vercesi 3a936a650c Tracing/Runner: lazily initialize CommandHandler
Avoid initializing `CommandHandler` statically, as this causes the
constructor to run every time `libPipelineC` is linked against.
2024-11-25 16:25:48 +01:00
Giacomo Vercesi 1b6ff00595 Tracing/Runner: delay registering signal handlers
On the C++ side of revng it is important that LLVM's signal handlers are
registered within the initialization of `revng::InitRevng`, as this
allows downstream users (e.g. `revng daemon`) to preserve its signal
handlers before setting up the C++ infrastructure. In
`Tracing/Runner.cpp` there's `CommandHandler` which is statically
initialized and called `llvm::sys::AddSignalHandler`, this happened at
`dlopen` time, breaking the promise outlined above. Rework the code so
that the function is called lazily instead of statically.
2024-11-25 14:55:01 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00