Commit Graph

6113 Commits

Author SHA1 Message Date
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 3d3d3abfc3 Layout: add info about return values
This commit introduces two new methods that describe the return value of
a function:

* `returnMethod`: describes how the return value is passed to the
  caller.
* `returnValueAggregateType`: the type of the aggregate that is being
  returned, in case `returnMethod` is `LocalVariable`.
2023-12-12 12:04:34 +01:00
Alessandro Di Federico d648f9b970 s/Layout::returnsAggregateType/Layout::hasSPTAR/ 2023-12-12 12:04:34 +01:00
Alessandro Di Federico 73a1827c29 Import QualifiedType::stripPointer 2023-12-12 12:04:34 +01:00
Alessandro Di Federico a3a549be48 EnforceABI step: reduce work done by InlineHelpers
InlineHelpers often inlines functions that contain a switch on an
argument that is constant on the call site. Specifically, this is true
for the `cc_compute_c` and `cc_compute_all` helpers of x86
architectures. The LLVM inliner, in such situations, is smart and
inlines a reduced amount of code, significantly reducing the maximum
size of the modules we work with.

However, before this commit, we couldn't capture this fact due to
`newpc` preventing constant propagation of the values of CSV set in an
instruction into their usage in the next instruction.

Running `PromoteCSV` before `InlineHelpers`, along with `mem2reg`
enables us to capture this behavior effectively.
2023-12-12 12:04:33 +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 ca7041741f fetch_debuginfo: fix PDB URL computation
The pefile library changed its API.
On top updating the code accordingly, we now also properly pad hex
numbers.
2023-12-12 12:04:33 +01:00
Alessandro Di Federico 35f31ad469 fetch_debuginfo: do not catch Exception 2023-12-12 12:04:32 +01:00
Alessandro Di Federico 8302717da7 fetch_debuginfo: use HTTPS for msdl.microsoft.com 2023-12-12 12:04:32 +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 071cdb1781 Enable ConvertToCABI analysis 2023-12-12 12:04:13 +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 1b4e03c2ad Merge branch 'feature/efa-4-minus' 2023-12-12 11:22:43 +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 4b4bac8910 Merge branch 'feature/efa-4-minus' 2023-12-12 10:44:09 +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 f2977128fa ABIs: mark link registers as callee-saved 2023-12-11 16:29:13 +01:00
Alessandro Di Federico 02458724b0 Drop CallSummarizer::RegistersClobberedPool 2023-12-11 16:29:13 +01:00
Alessandro Di Federico 3ba166bf5b EFA: improve logging 2023-12-11 16:29:13 +01:00
Alessandro Di Federico 070b51a644 Minor changes 2023-12-11 16:29:13 +01:00
Alessandro Di Federico 0ed33be551 Merge branch 'feature/ui-qa-fixes' 2023-12-11 13:22:27 +01:00
Alessandro Di Federico 9fe7b869e2 Merge branch 'feature/ui-qa-fixes' 2023-12-11 13:22:25 +01:00
Giacomo Vercesi 4d83c5e879 Allow renaming RawFunctionType return fields
Add the needed attributes to allow the fields of the return of a
RawFunctionType to be renamed.
2023-12-11 12:03:48 +01:00
Giacomo Vercesi 8504a96020 RawFunctionType: use NamedTypedRegister for return
Use the `NamedTypedRegister` type for return values in
`RawFunctionType`. This allows return values to be renamed at the user's
discretion.
2023-12-11 12:03:45 +01:00
Giacomo Vercesi 194bcecc41 Drop getReturnField
Drop the `getReturnField` helper, the cases in which it was used are now
covered by the `NamedTypeRegister::name` method.
2023-12-11 10:21:40 +01:00
Giacomo Vercesi fd24487666 C code: fix location for RawFunction return struct
Fix the needed attributes to allow navigation from the use of an
artificial return struct for raw functions to their definition in
`types-and-globals.h`.
2023-12-11 10:21:40 +01:00
Giacomo Vercesi 37ef77933c NamedTypedRegister: change name to use 'register'
Change the prefix used by `NamedTypedRegister` when `CustomName` is not
present from `_argument_` to `_register_`.
2023-12-11 10:21:02 +01:00
Massimo Fioravanti b3a1aeaa89 Unify pipeline pipes yml files 2023-12-06 16:26:19 +01:00
Pietro Fezzardi a6aae59949 Merge branch 'feature/dla-compact-arrays-overrun' 2023-12-05 16:59:29 +01:00
Pietro Fezzardi 7c1021ffc1 DLA: rearrange Middleend steps
Now CompactCompatibleArrays runs after ArrangeAccessesHierarchically.
Rearranging the accesses hierarchically first allows the following step,
that compacts compatible arrays, to achieve better results, and overall
recover much better looking arrays.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi 7ea3b507df DLA: CompactCompatibleArrays on non-strided
This commit extends the CompactCompatibleArrays DLAStep to also consider
non-strided accesses.
Strided accesses are still always considered first, and they are still
considered the only real source of information on arrays, but after
having tried to compact all the compatible arrays,
CompactCompatibleArrays now also considers non-strided instance edges to
see if they can be compacted with the rest of the inferred array.
This has shown to handle gracefully a number of real-world examples and
reduce unions.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi 1c5e8371a7 DLA: add isNonStridedInstance helper 2023-12-05 16:59:08 +01:00
Pietro Fezzardi bf69d271cf DLA: replace some auto with uint64_t
Explicit is better than implicit.
2023-12-05 16:59:08 +01:00