Commit Graph

90 Commits

Author SHA1 Message Date
Alessandro Di Federico cb8aa3d929 Adopt .prototype()
Also adopt `QualifiedType::getFunctionType` where appropriate in order
to unwrap typedefs.
2023-10-05 19:18:38 +02:00
Alessandro Di Federico cae213b36b Minor changes 2023-10-05 18:45:17 +02:00
Alessandro Di Federico 489dddd0e7 TupleTreeReference::isValid is for assertions only 2023-08-23 16:37:39 +02:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +00:00
Ivan Krysak 3c584cfabc Formatting: set AllowShortEnumsOnASingleLine
The new value is `false`.
2023-07-05 06:05:04 +00:00
Pietro Fezzardi e2791443fb Remove extractvalue instructions in decompilation
Now extractvalue instruction are replaced by dedicated
OpaqueExtractValue custom opcode, that prevents LLVM from doing strange
things with extractvalues during optimizations (such as e.g. sinking).

This is important since extractvalue instructions and struct-typed
values in general in our LLVM IR are not real first-class citizens, but
only a byproduct of the binary lifting process, and they actually
represent bundles of registers that are returned from isolated
functions.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 56a340bcb1 MakeModelGEPPass.cpp: improve debug prints 2023-06-30 10:48:59 +02:00
Pietro Fezzardi 386a6cc8aa MakeModelGEPPass.cpp: remove old dead classes 2023-06-30 10:48:59 +02:00
Pietro Fezzardi d1c1a79553 MakeModelGEPPass: drop old too stric assertions
It's actually legal to have a void PointeeType on LLVM IR, so the
removed assertions were just too strict and wrong.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi dfa279cfec MakeModelGEPPass: ignore zero-size types
If the base pointer that we're trying to use to build a ModelGEP points
to a zero-sized type, just ignore it, since we wouldn't be able to
traverse that type in any sensible way.
2023-06-21 15:17:28 +02:00
Pietro Fezzardi 3016c2ad41 MakeModelGEPPass: enable operator [] on pointers
This commit enables to emit accesses with the square bracket array
access operator on pointers.

This is accomplished by adding an additional mandatory argument to
ModelGEP (AND NOT to ModelGEPRef) to represent this case.

MakeModelGEPPass is updated to take this into account, together with all
the other passes that handle ModelGEPs.
2023-06-20 18:15:24 +02:00
Pietro Fezzardi 35fded0b38 MakeModelGEPPass: handle affine indices in arrays
With this commit we now support emitting array indices in the form:

array[const + coefficient_0 * index_0 + ... + coefficient_n * index_n]
2023-06-14 16:07:20 +02:00
Pietro Fezzardi 63970fb925 MakeModelGEPPass.cpp: use IRSummationin ChildInfo
to represent generalized inputs in the form of:
`constant + sum(coefficient_i * unknown_index_i)`
2023-06-14 16:06:11 +02:00
Pietro Fezzardi aa63ede37b MakeModelGEP: refactor to support partial mismatch
This commit is a major refactor of the data structures underlying the
MakeModelGEPPass, and of all the functions that manipulate them.
The refactor is aimed at fixing a major but of the previous design,
that made impossible to support MakeModelGEPs with partial mismatch.
This meant that until now we were emitting code that was not
semantically preserving whenever we could only match a part of the IR of
with a ModelGEP.
In particular, whenever a partial match was detected, the ModelGEP of
the matched part was still emitted, but we completely failed to emit the
mismatching part as raw pointer arithmetic.
This was due to the old design of the data structure, that cause the old
algorithm to lose track of the mismatch part at some point, without any
safeguard to avoid that.
Now all the data structures have been designed to properly represent the
mismatching part, so that the algorithms can avoid to lose track of
them, and finally emit the proper ModelGEP with additional pointer
arithmetic in case of partial match.
2023-06-12 13:36:18 +02:00
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +02:00
Alessandro Di Federico a823db7ea7 Adopt revng::verify 2023-04-28 13:54:12 +02:00
Alessandro Di Federico a9eae1c96b Purge remaining traces of InsertValueInst
InsertValue has long been superseded by `struct_initialier`, so we don't
expect it in the IR we work on.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b73bb90d0c Handle the freeze instruction 2023-04-14 14:54:14 +02:00
Alessandro Di Federico f87a86677d MakeModelGEP: handle multiple identical incoming
Since MakeModelGEP works Use-wise, if a `Value` was used multiple times
in a phi, we used to replace them with distinct model GEPs. This led to
generate illegal IR.

This commit fixes this situation by detecting the situation and reusing
the same model GEP.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ef6ec4ed0f Minor changes 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 017aa6a47f Drop CallToLifted
We no longer have such tag, we now inspect the callee using
`isCallToIsolatedFunction`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 4a3b75757d s/zextOrSelf/zext/g 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 95615cf400 Adopt new APInt::toString signature 2023-04-14 14:54:14 +02:00
Alessandro Di Federico e2ee3f5495 Switch from llvm::Optional to std::optional 2023-04-14 14:54:14 +02:00
Pietro Fezzardi 96390027b7 MakeModelGEPPass.cpp: fix outOfBound in lowerBound 2023-04-11 15:54:20 +02:00
Pietro Fezzardi 28713ba7fe MakeModelGEPPass.cpp: drop leftover debug log 2023-04-06 22:54:25 +02:00
Ivan Krysak 4e2159d9b5 MakeModelGEP: fix aggregate return value support 2023-03-15 10:28:24 +01:00
Ivan Krysak 56cdd8f876 Model: make model::Type::size() stricter 2023-03-15 10:28:24 +01:00
Ivan Krysak c2f0fc19e5 ABI: FunctionType.h -> FunctionType/Layout.h 2023-03-15 10:28:24 +01:00
Alessandro Di Federico f5a5990a30 Drop buildStringPtr in favor of getUniqueString 2023-03-13 13:42:33 +01:00
Alessandro Di Federico e9b9ba50d1 MakeModelGEP: ignore negative strides 2023-02-21 16:48:35 +01:00
Pietro Fezzardi 72b32dafa2 MakeModelGEP: array accesses jumping many elements
Before this commit we couldn't handle gracefully situations where the
model had an array with elements of given size X and the IR had strided
accesses with a stride Y that was larger than X.

This commit gracefully handles that case, but for now it always bail
out.

In the future we could think of handling this better if Y is a multiple
of X.
2023-02-07 08:12:42 +01:00
Pietro Fezzardi f0573995ba MakeModelGEP: use branch-and-bound approach
Before this commit, MakeModelGEPPass was materializing all possible
traversals of the type system to select the best match for translating
some pointer arithmetic on the IR into ModelGEPs.

This proved to be very slow and to do a lot of useless computation on
larger binaries with big type systems.

This commit partially rewrites MakeModelGEPPass to adopt a
branch-and-bound approach to only explore paths on the type system that
have some chance of improving the best match.
2023-01-31 11:39:28 +01:00
Pietro Fezzardi e33f6818cd MakeModelGEPPass: ignore non-pointer-sized Values 2023-01-17 11:11:55 +01:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Pietro Fezzardi b0e974f7a4 MakeModelGEPPass: fix adds with constants 2022-12-02 17:23:25 +01:00
Alessandro Di Federico d5f1ee1155 MakeModelGEP: handle returning aggregates 2022-11-30 18:16:13 +01:00
Pietro Fezzardi acb4b495f7 MakeModelGEPPass: refactor YAML serialization 2022-11-30 18:16:13 +01:00
Ivan Krysak 033ccbe51a Adopt FunctionType::Layout to improve CABI support 2022-11-30 18:16:13 +01:00
Ivan Krysak 654afbef0c Move pointer creation away from model::Binary 2022-11-30 18:16:13 +01:00
Massimo Fioravanti 335d402245 Change signatures to forward metadata cache. 2022-11-22 12:27:02 +01:00
Pietro Fezzardi 8497ab4b88 MakeModelGEP: don't crash on undef and poison 2022-11-10 13:05:51 +01:00
Pietro Fezzardi 0097af6dd0 Fix peelConstAndTypedefs for model::TypedefType
Before this commit typedefs were not unwrapped correctly, leading to
infinite loops.
2022-11-09 11:59:51 +01:00
Pietro Fezzardi 35b8d1b298 MakeModelGEP: avoid crash on function pointers 2022-11-08 14:09:07 +01:00
Pietro Fezzardi 73210ab4ae Adopt TupleTreeReference caching 2022-10-31 09:08:17 +01:00
Pietro Fezzardi 25119c4377 Drop bugged addPointerQualifier for getPointerTo
This commit removes the bugged addPointerQualifier helper function,
that was wrongly pushing the pointer qualifier at the end.

Instead, we now use the correct model::Binary::getPointerTo method.
2022-10-21 09:45:28 +02:00
Pietro Fezzardi 4df861a099 MakeModeGEPPass: fix makeBestGEPArgs for arrays 2022-10-18 17:05:50 +02:00
Pietro Fezzardi 46f54c4065 MakeModelGEPPass: std::move pickBestTAP results 2022-10-18 17:05:50 +02:00
Pietro Fezzardi 83737745af MakeModelGEPPass: fix ChildInfo dump() method 2022-10-18 17:05:46 +02:00
Pietro Fezzardi 8ab42d2899 MakeModeGEP: prevent copy of intermediate results 2022-10-07 18:15:25 +02:00