Commit Graph

6113 Commits

Author SHA1 Message Date
Ivan Krysak e4d9a022cd ToCABI: factor alignment computation out
Alignment considerations all over the place where growing increasingly
verbose and complex, increasing the likelihood of getting them wrong.

This unifies all the alignment logic in one place.
2025-02-12 16:43:05 +02:00
Ivan Krysak a5a2bead4f ABI: fix success detection and trailing padding
There were issues with how trailing padding is processed which sometimes
led to it being discarded. That should not happen from now on.

As a size benefit this also strictens the exit condition and improves
wording on some of the comments.
2025-02-12 16:40:59 +02:00
Ivan Krysak 7ad6b52974 ABI: improve distributor safety
This makes sure we never try to use a distributor object after
discarding some of its outputs.
2025-02-12 16:36:20 +02:00
Ivan Krysak ab535feb13 ABI: always use distributor for index selection 2025-02-12 16:36:20 +02:00
Ivan Krysak 8e85515969 ABI: fix mishandling of the top of the stack
Some ABI's (think mips) require a part of the stack to be reserved,
but before this patch we treated those fields as arguments.

Note that this analysis never inserts fields, so if there are no
sufficient field already inserted before-hand it's just going to fail
the conversion (for example, if the field at the *newly adjusted*
offset 0 is not present).
2025-02-12 16:36:20 +02:00
Ivan Krysak 566cbad8ae ToCABI: switch argument verification pair
Before this, arguments were verified in a (current, next) pair,
this makes it so (previous, next) pair is used instead.
2025-02-12 16:36:20 +02:00
Ivan Krysak c861e1c552 ToCABI: bundle argument-specific data together 2025-02-12 16:36:20 +02:00
Ivan Krysak 2521ffc1be ABI: allow ValueDistributor reassignment 2025-02-12 16:36:20 +02:00
Ivan Krysak 69144a7e3b ToCABI: improve function name logging 2025-02-12 16:36:18 +02:00
Ivan Krysak 492c169217 ToCABI: mark AAPCS64 as a safe ABI 2025-02-12 16:26:56 +02:00
Ivan Krysak 9186d476d2 ToCABI: fix mistreating of the safe cli argument 2025-02-12 16:26:56 +02:00
Ivan Krysak 850677115e Minor improvements 2025-02-12 16:26:56 +02:00
Alessandro Di Federico 06f5e976f4 Merge branch 'feature/ui-qa-2025-01-16' 2025-02-06 22:57:03 +01:00
Giacomo Vercesi a06b380ce0 S3StorageClient: implement parallel upload
Allow uploads to S3 to be executed in parallel, this should reduce the
time it takes for a `save` operation to conclude.
2025-02-06 12:21:23 +01:00
Giacomo Vercesi 761e84fc9f Add revng::cantFail
Add the `revng::cantFail` function which allows to wrap functions with
`std::error_code` and check their result. This is analogous to
`llvm::cantFail` for `llvm::Error`.
2025-02-05 10:46:00 +01:00
Giacomo Vercesi 5e386d2a8d model.ts: disable key sorting
Disable sorting of model keys, as that worsens the readability of the
model.
2025-02-05 10:38:16 +01:00
Pietro Fezzardi a18c32dd95 Decompile Function: fix escaping of char literals
Before this commit, char literals were always printed with html
escaping, even if the associated PTML builder was set to Tagless.

This commit fixes the problem.
2025-02-03 17:24:12 +01:00
Pietro Fezzardi c33b7c9c4a DecompileFunction: drop unused Model arguments 2025-02-03 17:07:36 +01:00
Pietro Fezzardi 4efcce2867 DLA: fixed invalid access to NotMergedNode
Before this commit, the DLAStep DeduplicateFields was using
NotMergedNode (a reference) in an assertion, in a place where it was
already invalidated by a preceding call to
CollapseSingleChild::collapseSingle that can mutate the graph.

This caused the assertion to trigger erroneously in some situations.

This commit moves the assertion earlier, in a place where the reference
is guaranteed to always be valid.
2025-01-30 18:00:21 +01:00
Pietro Fezzardi 298e49d80b DLA: add comment on assumptions 2025-01-30 18:00:00 +01:00
Pietro Fezzardi 2c79e3f5b8 DLA: reuse number of children in DeduplicateFields 2025-01-30 17:57:41 +01:00
Pietro Fezzardi d5a96cd98f Merge branch 'feature/clift-legalization' 2025-01-30 14:13:58 +01:00
Lauri Vasama 6343bfcb40 Add c-verify pass 2025-01-30 14:52:47 +02:00
Lauri Vasama 998114501b Replace PlatformInfo with TargetCImplementation 2025-01-30 14:52:47 +02:00
Lauri Vasama 06d91d485d Factor visitation out of ModuleOp verify 2025-01-30 14:52:47 +02:00
Lauri Vasama b7047d3854 Remove Clift backend PTML tags unit test 2025-01-29 23:58:24 +01:00
Lauri Vasama fc203afb49 Remove unused CastOp purpose attribute 2025-01-29 23:58:24 +01:00
Pietro Fezzardi 6759e02e9c Merge branch 'feature/variable-producers' 2025-01-29 23:57:22 +01:00
Pietro Fezzardi 5dc4d86f81 Pipeline: squash late-optimize into segregate
Passes without an artifact and a single successor are pointless anyway.
You can't get their output with revng artifact but you need to save
them on disk.
2025-01-29 23:55:49 +01:00
Pietro Fezzardi 1f0c8e1ae5 Pipeline: remove import-clift-types Pipe
At the moment this pipe is broken, because it claims to be producing
artifacts with function rank, while it only produces types.

This pipe should be extended and turned into a pipe that generates
the whole Clift module including functions from LLVM IR, and not just
types.

We should add an input LLVMContainer, and the run() method should first
import types, and then create the functions and their bodies.

For the time being the Pipe is removed from the pipeline.
2025-01-29 23:55:49 +01:00
Pietro Fezzardi 9e0f015eb8 Drop old conversion from LLVM to MLIR
The previous conversion from LLVM to MLIR was translating plain LLVM IR
to LLVM MLIR Dialect, as a preliminary step for further conversion from
LLVM MLIR Dialect to Clift.
This is not how things are expected to work anymore, so the old code is
now dead and can be removed.
2025-01-29 23:55:49 +01:00
Pietro Fezzardi 6e17dbed58 Tests: test the prepare-for-clift artifact
This is the initial part of the clift-based decomilation pipeline.
2025-01-29 23:55:49 +01:00
Pietro Fezzardi 186798c2aa Add initial part of clift-based decompilation 2025-01-29 23:55:49 +01:00
Pietro Fezzardi 7be6491258 Pipeline: avoid duplicate SingleTargetFilename 2025-01-29 23:55:49 +01:00
Pietro Fezzardi 391f5c780f SwitchToStatements: use LocalVariableBuilder 2025-01-29 23:55:49 +01:00
Pietro Fezzardi 0f2466e84b SegregateStack: drop old unused LocalVarPool 2025-01-29 15:17:15 +01:00
Pietro Fezzardi 1676ecdd8f SegregateStack: emit AddressOf only in legacy mode 2025-01-29 15:17:15 +01:00
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 1d7cf58907 Support LoadInst in mayReadMemory 2025-01-29 15:17:15 +01:00
Pietro Fezzardi f37c933ee7 Support StoreInst in hasSideEffects
Before this commit `StoreInst` weren't supported because they weren't
expected to reach the late stages of the decompilation pipeline where
the `hasSideEffects` helper function is used.
They were expected to be replaced by custom opcodes marked with
`FunctionTags::Assign`.

With the upcoming switch to the new decompilation pipeline, this helper
needs to be able to handle `StoreInst`s, because the custom opcode
functions will be dropped in favor of regular LLVM memory accesses.
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