Commit Graph

3168 Commits

Author SHA1 Message Date
Giacomo Vercesi 6ac7c0c557 Implement container cache pruning
Implement the pruning of container caches (resume directory) when there
is a mismatch between the current revng components' hash and the saved
one. This functionality is activated via `-check-components-version`.
2024-01-26 17:46:21 +01:00
Giacomo Vercesi 06f6137004 ResourceFinder: implement getComponentsHash
Implement the `getComponentsHash` function which returns a hash string
for all the components currently installed in revng.
2024-01-26 17:46:21 +01:00
Giacomo Vercesi 443301a402 S3StorageClient: fix directory detection
The detection of directories in S3StorageClient was flawed as it did not
account for files with a suffix. This commit forces the use of a `/` at
the end to guarantee that the matched path is a sub-{file,directory}.
2024-01-26 17:46:21 +01:00
Giacomo Vercesi 9a701a0665 GzipTarWriter: fix append for empty files
The `GzipTarWriter::append` method erroneously added an empty block of
padding when an empty file (size == 0) was supplied. This corrects the
algorithm by excluding 512 as a valid padding size.
2024-01-26 17:46:21 +01:00
Giacomo Vercesi af1e927e7e Drop ApplyDiffAnalysis' files
The files `ApplyDiffAnalysis.{cpp,h}` were mis-re-merged in c276a439.
Drop them.
2024-01-26 17:46:21 +01:00
Pietro Fezzardi 73cf39d206 DLA: add MergePointeesOfPointerUnion DLAStep 2024-01-26 16:49:52 +01:00
Pietro Fezzardi 8df6b0d7d8 DLA: relax assertions on MergePointerNodes
The DLAStep can now effectively run at any time, without assuming any
specific property of the underlying graph.
2024-01-26 16:49:52 +01:00
Pietro Fezzardi f598df6113 DLA: fix moveEdgeTargetWithoutSumming
Before this commit, the method could partly fail in moving the edge
target even in legitimate scenarios, because of a bug in how it fixed up
the Successors link in the edge source.
This commit fixes the bug.
2024-01-26 16:49:52 +01:00
Pietro Fezzardi 04bb1d0fb3 Backend: avoid casting to uint8_t in conditions
Explicitly casting to uint8_t has the semantics of truncating, in case
the value being casted is larger than 8 bits.
Avoiding the cast default to regular C behavior, where every non-zero
integer is considered true.
2024-01-26 16:49:47 +01:00
Pietro Fezzardi c30ee01d85 MakeLocalVariables uses initModelTypes
This enables to generate LocalVariables with nicer-looking types,
learning from Stores that write values into them.

RemoveLoadStore had to be updated to handle cstringLiteral as a corner
case.

In the future, we can probably treat cstringLiteral homogeneously if we
change MakeSegmentRefs so to inject AddressOf around cstringLiteral, and
change cstringLiteral itself to have reference semantics.
2024-01-26 16:49:47 +01:00
Pietro Fezzardi 5d1ab13289 Drop old RemoveRefDeref pass
The pass has always been redundant, only used to simplify the IR and not
for anything useful.
Recently, after the work done to tidy up casts, it has started to give
problems: turns out ModelGEPRefs without indices are not always
redundant, and removing them can cause `trunc` instructions that then
end pessimizing the C code generation.

This commit drops the pass altogether.
2024-01-26 16:49:37 +01:00
Pietro Fezzardi 9db3c53f1e Convert FIXMEs to TODOs 2024-01-26 16:45:20 +01:00
Andrea Gussoni 8125a19379 JumpTargetManager: improve rebuildDispatcher
Improve the way in which we connect the non reachable `JumpTargets` when
rebuilding the dispatcher for non `SemanticsPreserving` `CFGForm`s.

When connecting group of jump targets that are not currently reachable
from the entry dispatcher, we elect the jump target with the lowest
program counter value, as the one to be connected to the dispatcher.
We also mark the jump targets now transitively reachables from the
elected one, as reachable, so to avoid adding other unnecessary edges
from the dispatcher.
2024-01-18 11:06:17 +01:00
Pietro Fezzardi 000b4bc481 Segregate: fix iteration on OpaqueExtractValues
Before this commit, the code was making a couple of broken assumptions on
OpaqueExtractValues
- that OpaqueExtractValues were always ordered in the same way as struct
  fields (e.g. the OpaqueExtractValue extracting field 0 was always the
  first use of the struct-typed value it was extracting from)
- that there was always one and exactly one OpaqueExtractValue for each
  field index in the struct

This commit fixes the issue, while reusing available facilities for
dealing with OpaqueExtractValues.
2024-01-09 09:32:25 +01:00
Pietro Fezzardi d6a6e29ae0 TANP: inject UnaryMinus on negative call arguments 2024-01-09 09:32:25 +01:00
Massimo Fioravanti 2ec4683874 Fix: invalidation map and invalidation cache
The invalidation map passed by callers of pipeline invalidate was
assumed to be always empty. This requirement has been relaxed.

The pipe invalidation cache now checks that what must be removed is
actually present. This is relevant for targets that are killed by later
pipes before the end of the step.
2024-01-02 15:08:26 +01:00
Massimo Fioravanti d7c56bd1f4 Remove redundant model copy 2024-01-02 12:10:21 +01:00
Massimo Fioravanti f6ff8e544d Add tracking debug infrastructure
Add a mechanism to make the program crash when a given element of the
model is read or written.
2024-01-02 11:14:56 +01:00
Massimo Fioravanti c276a439b5 Add pipeline invalidation
Replace the stub implementation of invalidation with the proper
implementation. A ReadPathCache is added to each global so that it can
keep tracks of what target are associated to which read paths.
2024-01-02 11:14:56 +01:00
Massimo Fioravanti 86e45461a0 Introduce pipeline execution context 2024-01-02 11:05:50 +01:00
Pietro Fezzardi 4b01849e59 AddAssignmentMarkerPass: relax assertion 2023-12-19 01:57:11 +01:00
Pietro Fezzardi 8475e73fb5 Segregate: drop unnecessary variable 2023-12-19 01:57:06 +01:00
Pietro Fezzardi 72fc2be260 Add missing NoMerge function attributes 2023-12-19 01:27:12 +01:00
Alessandro Di Federico 03c3372c57 ConvertToCABI: fix VerifyHelper usage 2023-12-12 14:00:04 +01:00
Pietro Fezzardi e4f0c5fc1f MarkAssignment: refactor and update comments 2023-12-12 13:59:41 +01:00
Pietro Fezzardi 4b9de08832 MarkAssignments: fix ReturnMethod::ModelAggregate
This commit teaches AddAssignmentMarkerPass how to properly handle calls
to isolated functions that return an aggregate and are not SPTAR.
2023-12-12 13:59:41 +01:00
Alessandro Di Federico d648f9b970 s/Layout::returnsAggregateType/Layout::hasSPTAR/ 2023-12-12 12:04:34 +01:00
Alessandro Di Federico f997f85efd PromoteCSVs: always recreate allocas 2023-12-12 12:04:33 +01:00
Alessandro Di Federico 98f5304c54 InlineHelpers: do not inline recursive functions
Also, turn it into a ModulePass.
2023-12-12 12:04:33 +01:00
Alessandro Di Federico 2de10213d4 Segregate: improve returning aggregates support
This commit heavily reworks how we handle returned values, making things
a bit more elegant.

Apart from this, it fixes how were handling types that on the model are
aggregates but were being returned via registers on the IR.
2023-12-12 12:04:21 +01:00
Alessandro Di Federico 2ea71aba16 PrepareLLVMIRForMLIR: give names to more structs
We were not considering artificial structs returned by indirect function
calls.
2023-12-12 12:04:20 +01:00
Alessandro Di Federico bb0a8cd495 CCodeGenerator: fix nullptr dereference 2023-12-12 12:04:19 +01:00
Alessandro Di Federico d5ad77d2d9 Adopt model::QualifiedType::stripPointer 2023-12-12 12:04:19 +01:00
Alessandro Di Federico 3165682b9e PrepareLLVMIRForMLIR: there are no StructType args 2023-12-12 12:04:18 +01:00
Alessandro Di Federico 02d6f75d4b Segregate: add missing assignment 2023-12-12 12:04:17 +01:00
Alessandro Di Federico 75cfb52fce DetectStackSize: handle CABIFunctionType
DetectStackSize only updates RawFunctionTypes. However it must also
handle CABIFunctionTypes, when met in a call site.  This commit employs
abi::FunctionType::Layout to fix the situation.
2023-12-12 12:04:16 +01:00
Alessandro Di Federico 3709deebc8 SegregateStack: use alloca for stack arguments
This commit:

1. Introduces an alloca for stack arguments of a function. This enables
   us to "write" to stack argument. In order to do so, we simply map the
   relevant stack portion to the alloca that, since it's a memory
   object, can be `load`'d from and `store`'d to.

   Note that `llvm::Argument`s are always scalar since if the original
   argument was an aggregate, it would have been passed as a pointer,
   which is a scalar.

   Note also that previously we were using scalar arguments as if they
   were *pointers* to the stack arguments. This commit fixes that too
   (and updates the tests accordingly).

2. Introduces an alloca for *scalar* stack arguments of a call site.
   The alloca is then mapped to the corresponding part of the stack.
   Previously, there was no redirection and negative offsets from
   `_stack_frame` would pop up.
2023-12-12 12:04:15 +01:00
Alessandro Di Federico 95327c313d SegregateStackAccesses: delay handleMemoryAccess
This commit splits in two stages handleCallSite and
handleMemoryAccess. Running the latter after all the call sites have
been handled, is necessary in order to properly replace certain memory
accesses targeting stack arguments of a call site.
2023-12-12 12:04:15 +01:00
Alessandro Di Federico d267c49a58 Minor changes 2023-12-12 12:04:13 +01:00
Alessandro Di Federico c561a71089 s/Layout::returnsAggregateType/Layout::hasSPTAR/ 2023-12-12 12:04:12 +01:00
Alessandro Di Federico 9d4cea6d7f RemoveLiftingArtifacts: update what gets purged
We used to manually purge `raise_exception_helper`, which has now been
split in `_abort` and `_unreachable`.  We want to purge the latter but
keep the former. The latter is marked as `Exceptional`, so this commit
updates the logic to purge all functions with `Exceptional` tag.

Also, due to the inability of the backend to emit globals of `struct`
type, we ban `set_PlainMetaAddress`, which is not critical for
decompiled code.
2023-12-12 10:58:58 +01:00
Alessandro Di Federico 1344bba5b7 HoistStructPhis: handle undef and poison 2023-12-12 10:58:53 +01:00
Alessandro Di Federico 0e7d3a9a71 Pass PlainMetaAddress by pointer 2023-12-12 10:20:51 +01:00
Alessandro Di Federico 2e283fdf2a raise_exception_helper -> _abort and _unreachable 2023-12-12 10:20:35 +01:00
Alessandro Di Federico ef3ec71cf1 DetectABI: reorder functions 2023-12-12 10:20:32 +01:00
Alessandro Di Federico e63feda848 Outliner::getCallSiteInfo: drop unused argument 2023-12-12 10:05:30 +01:00
Alessandro Di Federico 28a0fa5b7d DetectABI: run to fixed point and more
This commit switches the approach with which we run the ABI analyses: we
now run them until we reach a fixed point. This enables proper
interprocedural propagation of arguments and return values.

Basically, we now inject reads before call sites, so that, if a function
immediately calls another one, the arguments of the callee are
propagated to the caller.

This commit also updates the logic with which we propagate function
prototypes (and names) to callers. The main advantage of this, is that
function wrappers (in particular, PLT entries) now have the same name as
the function they wrap.
2023-12-12 10:05:22 +01:00
Alessandro Di Federico 29f9f23654 Minor changes 2023-12-11 16:29:56 +01:00
Alessandro Di Federico d8e41028b7 RegisterClobberer -> OpaqueRegisterUser
Extend RegisterClobberer to support also performing opaque reads.
Also, record all the generated instructions for easy purging.
2023-12-11 16:29:13 +01:00
Alessandro Di Federico 02458724b0 Drop CallSummarizer::RegistersClobberedPool 2023-12-11 16:29:13 +01:00