87 Commits

Author SHA1 Message Date
Pietro Fezzardi 67523ec115 DLA: hack for unsupported function pointers
The current implementation DLA cannot reason about function pointers,
because function types have zero size.
Given this shortcoming, llvm::Functions are used (as a hack) to
represent their Functions' return types.
This representation is a key factor of how DLA is able to piece
information together interprocedurally.

This hack has consequences.
Assume we're setting up the DLA graph, and we're looking at a use of an
llvm::Function that is inside the body of an llvm::Function and is not
the callee-operand of a Call.
That use is obviously function-pointer typed.
But if we try to create a LayoutTypeSystemNode for the llvm::Value of
the used llvm::Function, the inner machinery of how the DLA graph is
set up will treat is as the return type of the function, which is
obviously wrong.
So we have to prevent that creation at all costs.
Basically creation of LayoutTypeSystemNodes in the DLA graph associated
with llvm::Functions are valid only for representing return types.

This shortcoming does not affect the power of DLA. In its current form,
it doesn't represent function types at all.
The problem is that until we undo this hack we will not be able to
properly support function types in DLA.
This will have to be fixed in the future.

In the meantime, this commit provides an helper function to centralize
how we detect the offending uses of llvm::Functions. In this way, all
the points of the codebase that are affected by this hack are clearly
marked.
2025-10-31 17:25:03 +01:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Ivan Krysak f494ae5f5f Standardize comment formatting
Use `*something*` instead of `_something_` when adding emphasis.
2025-02-13 13:09:50 +02:00
Alessandro Di Federico 36edf810ef Introduce support for function pointers 2025-01-28 15:20:45 +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
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Ivan Krysak a0f4921e07 Minor improvements 2024-11-04 19:43:03 +02:00
Alessandro Di Federico 2e4f4d09b9 Remaining FunctionTags have been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 800340d6e8 IRHelpers.cpp has been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 8706fd8459 Initialize pointers to nullptr 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 0cb3eedd37 Do not use CallBase::getCalledFunction
Use our wrapper, which does not return nullptr if the `FunctionType`s do
not match.
2024-08-07 15:40:56 +02:00
Ivan Krysak 94a0ad6b93 Adopt reworked model::Type 2024-06-27 11:07:01 +02:00
Ivan Krysak 3705906074 Model: rename Type into TypeDefinition 2024-06-27 11:07:01 +02:00
Alessandro Di Federico 988af25a7d Adopt UniquedBy* FunctionTags for deduplication 2024-06-26 12:21:58 +02:00
Alessandro Di Federico 5186a58053 s/FunctionMetadata/ControlFlowGraph/ 2024-06-18 17:56:24 +02:00
Pietro Fezzardi 05cc20cb6e Rename MallocLike Tag to ReturnsPolymorphic
Also add this Tag to the LocalVariable opcode who was missing it.
2024-03-19 09:44:00 +01:00
Alessandro Di Federico 8939e2ad2a MakeModelGEPPass: do not use trySize 2024-03-01 16:11:28 +01:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Pietro Fezzardi 8acf6c2f94 Allow type-less Segments in the Model 2024-02-09 09:04:23 +01:00
Pietro Fezzardi 51cbceaced DLA: remove dead code 2024-02-08 09:03:31 +01:00
Pietro Fezzardi d07e661ab5 DLA: rework initialization of string literals
Before this commit, DLA's frontend was representing information about
string literals in a way that had a bad outcome: very often, all (or
most) places in the binary that were using string literals ended up
collapsed on the DLA graph on the same node, causing all their types to
be a weird struct.

This was wrong, and it was the result of an aggressive creation of
equality edges.

This commit avoids to emit equality edges, and replaces them with
instance edges, that represent the fact that a call to StringLiteral
actually returns a type that represents a pointer to char.
2024-02-04 15:21:27 +01:00
Alessandro Di Federico d5ad77d2d9 Adopt model::QualifiedType::stripPointer 2023-12-12 12:04:19 +01:00
Alessandro Di Federico d267c49a58 Minor changes 2023-12-12 12:04:13 +01:00
Pietro Fezzardi 24cb43ce9c Make RawFunctionType::StackArgumentsType a TTR
This is homogeneous with all other nullable references to types in the
model, such as the StackFrameType in model::Function, and others.
2023-12-05 16:56:52 +01:00
Pietro Fezzardi 2653a6ec6b DLA: don't link formal arguments with constant
The inter-procedural part of the DLA frontend connects actual arguments
of function calls with formal arguments of the callee functions, with
instance links at offset 0.
This represents the information that the type pointed-to by the actual
argument has an instance of the type pointed-to by the formal argument
at offset 0.

Before this commit, this was done even when the actual argument was an
integer constant leading to various problems:
1. Most of the times, small integer constants passed as actual
   cannot represent valid pointers, leading to graphs bigger than
   necessary.
2. Even when an integer constant might actually represent a pointer into
   valid memory, if it does it should fall into some segment.
   If it does, by the time DLA runs, those integer constants should have
   already converted into calls to the special SegmentRef opcode, which
   is already handled properly.
3. Finally, those constants end up being very connected in the DLA
   graph, creating connections between other nodes that are otherwise
   unrelated or very far from each other. This pollutes the graph and
   rapidly degrades the quality of the results.

This commit properly guards the code so that the instance-at-offset-0
link between actual and formal arguments is never injected if the actual
argument is an integer constant.
2023-11-22 10:16:06 +01:00
Pietro Fezzardi ebb2b6a45b DLA: enable Frontend to see through ZExt 2023-11-22 00:59:52 +01:00
Pietro Fezzardi 2bca392be3 Fix typo 2023-11-22 00:59:30 +01:00
Pietro Fezzardi 71b2e8e799 DLA: drop old Logger that was creating files 2023-11-22 00:59:08 +01:00
Alessandro Di Federico d19a7c0c5d DLA: handle scPtrToInt 2023-11-20 15:52:34 +01:00
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
Pietro Fezzardi 07cf95159e DLA Frontend: fix handling of pointer-typed SCEVs
Before this commit the DLA frontend was not ready to handle all the
possible combinations of integer- and pointer-typed arithmetic that was
used to compute SCEVs.
This could cause crashes when dealing with pointer-typed SCEVs.
This commit fixes the issues by converting all pointer-typed expressions
to integers, and resizing integers to the same size before adding them.
2023-09-21 15:18:32 +02:00
Alessandro Di Federico 489dddd0e7 TupleTreeReference::isValid is for assertions only 2023-08-23 16:37:39 +02:00
Pietro Fezzardi cac7fee07d LayoutTypeSystemNode: add NonScalar field
This field represents that fact that a node of the DLA Graph is not a
scalar and it comes from the Model.
2023-08-21 16:17:36 +02:00
Pietro Fezzardi 552b8a96d9 DLA: print number of collapsed nodes for each Node 2023-08-21 16:17:21 +02:00
Pietro Fezzardi 10efe0f19d DLA: switch to revng's isCallToIsolatedFunction 2023-07-10 12:30:35 +02:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +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
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +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 ba05ddfaaf DLA: handle ConstantPointerNull 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6610213da4 DLA: drop support for InsertValue
They shouldn't appear in the IR at this stage of the pipeline.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 03bbf22a48 DLA: improve handling of phis
DLA used to support phis in return values, but didn't handle phis
referring to other phis.
This commit fixes that.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 4c469e5180 Adopt getCallToTagged
`isCallToTagged` used to return a pointer in case of success.
We now have `getCallToTagged` for that.

Also, these functions have been moved to revng.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico f86ca062b4 DLA: handle scSequentialUMinExpr 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 340f64e150 Drop usages of PointerType::getElementType 2023-04-14 14:54:14 +02:00
Alessandro Di Federico dd383076ab Drop arg_operands in favor of args 2023-04-14 14:54:14 +02:00
Kacper Kołodziej 9decc1fe51 DLA Frontend: Create nodes for StringLiterals
For segmentRef type of the segment and type returned by segmentRef
function are the same.

For cstringLiteral every call returns pointer to 1-byte type. Pointer is
offsetted by value of strlen+1. strlen is fetched from metadata.

Additionally, all uses of cstringLiteral function has same type as the
type of cstringLiteral (pointer to 1-byte).
2023-04-04 09:31:10 +02:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Massimo Fioravanti 335d402245 Change signatures to forward metadata cache. 2022-11-22 12:27:02 +01:00