Commit Graph

2366 Commits

Author SHA1 Message Date
Ivan Krysak 11c0d7f02e Stop using \brief doxygen command 2023-03-15 10:19:01 +01:00
Ivan Krysak 0b1aaeaede Minor improvements 2023-03-15 10:19:01 +01:00
Alessandro Di Federico 6b166bf0b9 Import TaggedFunctionPass 2023-03-13 22:53:44 +01:00
Alessandro Di Federico 09541be398 getUniqueString: do not rely on named metadata
`getUniqueString` returns a dedup'd char array `GlobalVariable` given a
string. We used to rely on named metadata to dedup them. However, this
lead to issues with `LLVMContainer` cloning and linking.

The new implementation uses the name of the variable as the
de-decuplication key, circumventing the problem entirely and improving
performance.
2023-03-13 22:53:44 +01:00
Alessandro Di Federico 6f47231695 LLVMContainer: pruneDICompileUnits pre linking 2023-03-13 22:53:44 +01:00
Alessandro Di Federico 8d813e169a LLVMContainer: drop certain named MD pre linking 2023-03-13 22:53:44 +01:00
Alessandro Di Federico 4353beff22 LLVMContainer: fix how we adjust linkage
We used to turn `internal` linkage to the equivalent of C++'s inline.
We need to do the same for `private`. If we don't do this, the number of
`private` variables grows exponentially.
2023-03-13 22:53:44 +01:00
Alessandro Di Federico 9be304ece2 areMemOpCompatible: drop redundant check 2023-03-13 13:42:33 +01:00
Alessandro Di Federico e73bd95493 Improve handling of declarations
SegregateStackAccesses and PromoteStackPointer were not handling
functions declarated (but not defined) properly.

This commit fixes this, in part by adopting `TaggedFunctionPass`.
2023-03-13 13:42:33 +01:00
Alessandro Di Federico f68b7866b3 Introduce BasicBlockID
This commit introduces `BasicBlockID` as the unique identifier for a
`efa::BasicBlock` into the CFG. A `BasicBlockID` is defined by a
`MetaAddress` plus an incremental integer. This enables us to have
multiple instances of the same block in a single function, which is
particularly useful when inlining multiple times the same function.

Apart from this, the commit also does the following:

* It drops representing `MetaAddress`es a `structs` in the IR. This created
  several issues related to ABI. We now represent them as strings.

* It defines more functions in `support.h`, instead of defining prototypes
  by hand in `CodeGenerator.cpp` and the like. Specifically, `unknownPC`
  and `raise_exception_helper`. We also introduce a C "constructor" for
  `PlainMetaAddress`.

* It significantly reduces the API of `GeneratedCodeBasicInfo`, which
  was supposed to be put on a diet since a long time.  Specifically,
  many jump target related methods have been moved to free functions in
  `IRHelpers.h`.  Also `GCBI::getSuccessors` has been pushed into its
  only user, `PruneRetSuccessors`, to prevent further usage of a
  deprecated API. In the future, it would be nice to drop it entirely.

* It introduces `efa::BasicBlock::InlinedFrom`.

* Introduce an enum to represent named argument indices for `newpc`.
  This enables us to more effectively manipulate its argument list.

* It improves the verification and error reporting for
  `efa::FunctionMetadata`.

* Update tests.

This commit is preliminary to another piece of work to improve the
generality of inlining beyond the simple "fake function" scenario, for
which the feature was originally conceived.
2023-02-23 14:51:10 +01:00
Alessandro Di Federico d3f6d43ffe PromoteCSV: tag init_ functions with register
This enables downstream passes to selectively purge calls to `init_`
functions.
2023-02-23 08:30:22 +01:00
Alessandro Di Federico 969b3c0cb7 SystemV_x86_64: ignore fs register 2023-02-23 08:30:22 +01:00
Massimo Fioravanti 230036d5b1 Introduce TrackingContainer
TrackingContainer is a wrapper around KeyedObjectContainers (notably,
SortedVector) intended to figure out which elements of the underlying
container have been accessed.
2023-02-16 10:58:02 +01:00
Massimo Fioravanti 95ec36eea3 Fix error messages capitalization 2023-02-09 13:44:22 +01:00
Massimo Fioravanti 68ae1c986c DiffErrors now use DiffLocations
DiffLocation now allows to pinpoint which change of a diff generated a
issue.
2023-02-09 13:43:51 +01:00
Massimo Fioravanti 2521ef434a Rework PipelineC errors
PipelineC errors are now splitted in simple and document errors.
Error lists are gone.
2023-02-09 13:43:09 +01:00
Massimo Fioravanti 4dc2e92782 Introduce DocumentError
`DocumentError`s are the inteded way of propagating errors from the
pipeline to the frontend when a location is required to inform the user
of the error whereabouts.
2023-02-09 13:42:50 +01:00
Pietro Fezzardi 66434db5f9 Don't use named metadata revng.segment_ref
Using a named metadata is simply wrong, because we need to have many of
these metadata alive at the same time with different values.
Using a named metadata has the unpleasant side effect of making all the
`SegmentRef` functions to refer to the same segment.
2023-02-07 18:03:34 +01:00
Kacper Kołodziej 5b94a5a649 HelpersToHeaders: skip unnecessary helpers 2023-02-07 17:43:05 +01:00
Giacomo Vercesi 8a780a58aa GraphQL: return binaries in b64
This change fixes the pipeline behavior when producing targets:
* produce and extract now return rp_buffer, which has a start pointer
  and size
* the python api `revng.api` will return on produce/extract either str
  or  bytes depending on the mime type of the container
* the GraphQL api will encode bytes in base64
2023-02-07 16:54:35 +01:00
Giacomo Vercesi aa09b17964 PipelineC: fix rp_container_extract_one
To keep consistency with the rest of PipelineC, return `nullptr` when
calling `rp_container_extract_one` when the content of the specified
target hasn't been produced
2023-02-07 16:54:35 +01:00
Antonio Frighetto 7c671ed6de TupleTreeDiff: evict cached references in apply
As the input model requires to be mutable, `evictCachedReferences`
is needed in order to invalidate cached references.
2023-02-06 09:37:23 +01:00
Antonio Frighetto 15fcf98446 ProcessCallGraph: fix access to Metadata
A logic issue existed in the Pipe, as it was mistakenly relying on
`IsolatedRoot` instead of the isolated function. That was breaking
things if those functions were to be removed. This issue has been
addressed by correcting the behaviour of the Pipe.
2023-02-06 09:37:23 +01:00
Antonio Frighetto 2d086e04a1 Context: fix entry in containsReadOnlyContainer
`ReadOnlyContainers` is defined to be a `llvm::StringMap`
of a further `llvm::StringMap` of `std::unique_ptr`s of
`ContainerBase`. A logic issue has been addressed by
properly dereferincing the inner map.
2023-02-06 09:37:23 +01:00
Antonio Frighetto 308d8ee8a3 Loader: associate container name to its role
`Container` names were mistakenly associated to the name
of their declaration. This has been fixed by associating
them to their `Role`.
2023-02-06 09:37:23 +01:00
Massimo Fioravanti 9432399254 Introduce ApplyDiffAnalysis 2023-02-06 09:37:23 +01:00
Antonio Frighetto ea0a06a876 revng.daemon: accept no arguments for analysis
Let GraphQL accept zero or more parameters for analyses.
2023-02-06 09:37:23 +01:00
Massimo Fioravanti dad043027d Rework and EFA yield cross relations
Yield and EFA shared the same namespace, this commits splits them and
introduces tuple tree containers as well.
2023-02-06 09:37:23 +01:00
Antonio Frighetto c5d9a4d787 Introduce helper for location conversion 2023-02-06 09:37:23 +01:00
Antonio Frighetto c3480b6f9b CLOption: improve isSet for a cl::opt<T>
A logic issue existed when validating whether a `cl::opt<T>`
was set. This has been addressed by replacing `isDefaultOption`
method with `getNumOccurrences`, as the former one was not
meant to be used for checking if the option was set or not.
Likewise, the default Option itself is written to a `std::string`,
in method `get`; the latter is leveraged by `Invokable`.
2023-02-06 09:37:23 +01:00
Djordje Todorovic a48e518467 Introduce AttachDebugInfo pass 2023-02-02 15:26:44 +01:00
Djordje Todorovic eb6849045d FunctionMetadataCache: split an assert 2023-02-02 15:26:26 +01:00
Djordje Todorovic 3365a626df LLVMContainer: avoid copying !dbg to declarations 2023-02-02 15:26:18 +01:00
Andrea Gussoni 26a717a4ac Compute weight for untangle regions once
Compute the weight of collpased regions the first time it is requested
and cache it, and use the cached value for all successive queries.
This also prevents a bug which occurs when we query the weight two
times for the same collapsed node, whose related collapsed region object
has been in the meantime destroyed by the tiling process.
2023-02-01 09:56:36 +00:00
Andrea Gussoni ebe0729332 Improve debug graphs for collapsed nodes
Integrate the debug graph serialization for collapsed nodes in the
RegionCFG.
2023-01-31 17:25:27 +00:00
Djordje Todorovic fec0ec7034 Model: add ExportedNames for local Functions 2023-01-27 17:54:06 +01:00
Pietro Fezzardi 5e12f66ffb Drop old logger, use CombLogger instead 2023-01-18 17:58:09 +01:00
Pietro Fezzardi 97b23935de Handle FunctionTags::Exceptional
This is necessary for e.g. the abort function.
2023-01-17 11:14:47 +01:00
Pietro Fezzardi 97883844d3 Fix initialization of FunctionTags 2023-01-17 11:11:46 +01:00
Kacper Kołodziej 568bd24900 Add UnaryMinus and BinaryNot 2023-01-09 15:01:16 +01:00
Pietro Fezzardi e9d84264ff Reduce the number of emitted local variables in C
This commit does various things oriented at reducing the number of local
variables emitted in C:
- MarkAssignments now know that @Copy and @Assign involving
  @LocalVariable only have side effects that affect the local variable
  itself; this enables to reduce the number of times we're forced to
  emit a local variable due to interfering side effects
- Drop the @AssignmentMarker FunctionTag; AddAssignmentMarkerPass now
  doesn't emit @AssignmentMarker anymore; instead it emits groups of
  @LocalVariable, @Copy, and @Assign, which benefit from the previous
  point
- Drop 2 MarkAssignments::Reasons: HasManyUses and HasUsesOutsideOfBB;
  both these have now been aggregated into the AlwaysAssign reason for
  simplicity, representing all reasons non involving side effects
- Update BeautifyGHAST and how it reasons about side effects when
  beautifying; before this commit it used @AssignmentMarker, now it
  looks at @Assign
- Simplify ExitSSA; before this commit it was trying hard to be smart on
  where it emitted the store instructions representing the incoming
  values of the PHI that was being destroyed; this seemed smart when we
  originally did it but it generated C code that was not really better
  to read, so this useless complexity is finally gone
2022-12-24 02:47:10 +01:00
Pietro Fezzardi c201990e5b Print stack variable at beginning of function body 2022-12-24 02:44:38 +01:00
Djordje Todorovic 961f9e5461 Model: search debug info locally upon import
Also find prototypes in Models of dynamic libs for both PE and ELF.
2022-12-13 11:26:54 +01:00
Djordje Todorovic cad68a9876 Instroduce LDDTree 2022-12-13 11:26:25 +01:00
Djordje Todorovic 98a8b8a7a9 Ban identifiers starting with reserved prefixes 2022-12-13 11:25:56 +01:00
Massimo Fioravanti 742e1a0c56 TupleTree: switch from public fields to accessors 2022-12-12 18:36:57 +01:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Massimo Fioravanti a54d1c9dcb fix includes 2022-12-12 11:19:14 +01:00
Massimo Fioravanti 0d3133cfc9 Fix missing includes
This ensures headers make sense on their own, without implicit
assumption about includers to also include other headers before them.
2022-12-09 18:09:39 +01:00
Massimo Fioravanti 4d2f1f71b4 Remove static asserts in tuple tree references
`TupleTreeReference`s use the Root type as a pointer only so they can
operate with forward declarations. Before this commit there were static
asserts that prevented this use case, and thus required the headers
defining the root type to be included before this one to work correctly.

We drop those `static_assert`s to make sure that all headers are parsable
on their own.
2022-12-09 14:01:10 +01:00