262 Commits

Author SHA1 Message Date
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
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
Pietro Fezzardi ff747c069d DLA: fix erased ptr in MergePointeesOfPointerUnion
This commit adds handling for a corner case of
MergePointeesOfPointerUnion, that wasn't handled before.
Said corner case happens when one of the scalars that gets merged as
part of the DLAStep operations is also itself a pointer to another
scalar that gets merged.
This wasn't accounted for before this commit, but it's actually a valid
scenario that can happen on some inputs.
2025-06-11 16:37:19 +02:00
Pietro Fezzardi 62c5cfc09d DLA: improve MergePointeesOfPointerUnion logging 2025-06-11 11:18:42 +02:00
Pietro Fezzardi 805b13de28 DLA: fix assertion in MakeModelTypes.cpp 2025-06-05 18:24:46 +02:00
Pietro Fezzardi dccf03236a DLA: fix creation of new model types
Before this commit DLA was not properly updating the pointee type for
some pointer types.

This commit reworks the creation of the model types so that there's no
need for in-place fixup of the pointee types: pointers are already
created consistently.
2025-05-29 09:31:26 +02:00
Giacomo Vercesi 0ac78dddba Fix codespell errors
Fix erros detected by the new version of `codespell`.
2025-04-24 13:22:14 +02:00
Ivan Krysak f070f1f1e1 Model: sunset double name system 2025-04-17 11:19:17 +03: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
Ivan Krysak 288448f009 Never include model::VerifyHelper from headers 2025-02-13 13:09:50 +02: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
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 8cd4ee3b59 Move Kinds.h to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico 4e670ac8e6 Either link revngcSupport or revngSupport 2024-11-04 15:09:56 +01: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 36e2faad3d Introduce -Wunreachable-code-break 2024-10-31 17:19:55 +01:00
Pietro Fezzardi a8e43b2910 [DLA] Fix removeBackedgesFromSCC DFS visit
The old version was unnecessarily convoluted, and had a bug that caused
invalid iterators to be dereferenced in some corner cases.

This commit reworks the DFS and makes it cleaner and easier to follow,
while fixing the iterator dereference bug.
2024-10-24 08:49:23 +02:00
Ivan Krysak 1a35cbcb77 Introduce PTMLCTypeBuilder 2024-10-15 10:45:13 +03:00
Alessandro Di Federico 8a5ae5f9c1 s/ExecutionContext &Ctx/ExecutionContext &EC/g 2024-09-27 10:35:10 +02:00
Alessandro Di Federico 8706fd8459 Initialize pointers to nullptr 2024-09-27 10:35:10 +02:00
Alessandro Di Federico ca99bbbb66 Adopt toString() 2024-09-26 17:51:08 +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
Pietro Fezzardi e1b5541462 DLA: depotentiate SimplifyInstanceAtOffset0
The DLAStep SimplifyInstanceAtOffset0 now only triggers if the parent
node has the child-at-offset-0 node as its only successor, or when the
child-at-offset-0 doesn't have other predecessors.

Doing this guarantees that it's impossible for another predecessor of
the child-at-offset-0 to start seeing memory accesses that were
initially relative to the parent.

This condition is slightly more restrictive than the previous one, but
it takes into consideration some far reaching consequences.
If SimplifyInstanceAtOffset0 aggressively like we did before, DLA can
end up inferring types in some memory locations, like executable
segments, for which there aren't clues in the binary.
This isn't bad per se, but if DLA does that, the newly recovered type is
identified as non-executable data, causing misdecompilation because
rev.ng doesn't decompile memory regions that it understands as non
executable.

This commit, making SimplifyInstanceAtOffset0 less aggressive, makes it
play better with the rest of the assumptions of the decompilation
pipeline.

It also relaxes a decompilation test that was previously working by
chance and that was effectively beyond the current expressive power of
reasoning for DLA at the moment.
2024-07-05 00:43:45 +02:00
Pietro Fezzardi 8311efb21c DLA: re-enable DeduplicateFields after fixing it 2024-07-05 00:43:35 +02:00
Pietro Fezzardi 99d4c0283a DLA: fix DeduplicateField traversal and comparison
Before this commit the breadth-first traversal was more convoluted and
it used a broken criterion for bailing out, resulting sometimes in
considering a pointer edge as if it was an instance edge.
This in turn caused bugs to the point of the DLA Graph failing
verification.

This commit rewrites and simplifies the main traversal and comparisons
in DeduplicateField to make them robust against these bugs.
2024-07-05 00:43:35 +02:00
Ivan Krysak 94a0ad6b93 Adopt reworked model::Type 2024-06-27 11:07:01 +02:00
Ivan Krysak c2b4fb70bb Model: rename TypePath to DefinitionReference 2024-06-27 11:07:01 +02:00
Ivan Krysak 3705906074 Model: rename Type into TypeDefinition 2024-06-27 11:07:01 +02:00
Pietro Fezzardi fc02a98aa3 DLA: disable DeduplicateFields
The DLAStep has bugs that are preventing other useful features to be
merged.
2024-06-26 12:21:58 +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 4fc37fe7eb DLA: improve ArrangeAccessesHierarchically logs 2024-06-18 11:19:50 +02:00
Pietro Fezzardi 64d41a9b1d DLA: fix ArrangeAccessesHierarchically iteration
Before this commit the code was wrong in 2 ways:
- if failed to iterate on children, because it iterated a range that was
  effectively [begin, begin) instead of [begin, end)
- the update of the ARootNext iterator in the loop was broken, but it
  was impossible to realize that since the loop was never taken

This commit fixes both these intertwined problems.
2024-06-18 11:19:50 +02:00
Alessandro Di Federico e22ea4b2d8 Minor changes 2024-05-29 12:23:32 +02:00
Pietro Fezzardi b50aca6a15 MergePointeesOfPointerUnion: improve Model types
Before this commit, the DLAStep MergePointeesOfPointerUnion wasn't
really equipped for dealing with LayoutTypeSystemNodes representing
types imported from Model.
There was some code that tried to deal with them but it was mostly an
afterthought and it wasn't robust.

This commit fixes that, and is able to handle a strict superset of the
scenarios envisioned before, while preserving the property that nodes
representing types imported from Model should be preserved (in
particular their size).
2024-03-21 11:51:10 +01: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
Alessandro Di Federico 539b2bd435 Rename dla analysis into analyze-data-layout 2024-02-09 09:03:34 +01:00
Pietro Fezzardi 0a90048663 DLA: recursively update nested struct types
This enables e.g. updating nested structs representing Sections inside
Segments.
2024-02-08 18:09:12 +01:00
Pietro Fezzardi fa48e50403 DLA: simplify fillStructWithRecoveredDLATypes
The function now takes 2 arguments less.
2024-02-08 18:09:12 +01:00