Commit Graph

326 Commits

Author SHA1 Message Date
Ivan Krysak eb67826da6 PathList: accept non-owning strings as arguments 2023-03-15 10:19:02 +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 927f5b38be PromoteCSVs/EnforceABI: handle declarations
PromoteCSVs and EnforceABI were not handling declarated functions
properly, leading to issues downstream.
2023-03-13 22:53:44 +01:00
Alessandro Di Federico 77ea6c6db6 Fix serialization of Segment key 2023-03-13 13:42:33 +01:00
Alessandro Di Federico f5a5990a30 Drop buildStringPtr in favor of getUniqueString 2023-03-13 13:42:33 +01:00
Pietro Fezzardi f3e466c989 DecompileFunction.cpp: fix format for int literals 2023-03-01 12:22:35 +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 c18dca0031 Adopt new approach for MetaAddress serialization 2023-02-21 16:48:35 +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
Djordje Todorovic 83905cf5ed Fix the level for FetchDebugInfo 2023-01-27 17:53:47 +01:00
Kacper Kołodziej 568bd24900 Add UnaryMinus and BinaryNot 2023-01-09 15:01:16 +01:00
Alessandro Di Federico c6630a2414 eraseIfNoUse: check if WeakVH is dead 2023-01-03 20:51:45 +01:00
Alessandro Di Federico dd5914ce61 ProgramCounterHandler: initialize field
The uninitialized field led to SIGSEGVs.
2023-01-02 14:22:56 +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
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
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Alessandro Di Federico 3a7b78584f Externalize cl::opt generations in Debug.h
These have a significant impact on build times.
2022-12-09 09:07:59 +01:00
Kacper Kołodziej 83ab07d7fb Enable printing integers as bool, hex or char
This commit adds a new pass, PrettyIntFormatting, that injects calls to
decorator functions print_hex, print_char, and print_bool around
llvm::ConstantInt in various situations.

It also updates the rest of passes of the decompilation pipelin to
understand these new decorator functions and to properly emit decorated
integer literals in the decompiled C code.
2022-12-02 10:08:00 +01:00
Pietro Fezzardi 4937fd29a0 ModelHelpers: handle returning aggregates 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 389a184fc2 Handle CABIFunctionTypes returning struct types 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 3d6020139f Add type argument to 'revng_call_stack_arguments'
The additional argument is a pointer to a constant string that represent
the serialized model::QualifiedType of the argument.
2022-11-30 18:16:13 +01:00
Pietro Fezzardi 05c96a1a3a Adopt abi::FunctionType::ArgumentKind 2022-11-30 18:16:13 +01:00
Pietro Fezzardi daec840e37 Fix getStrongModelInfo for stack arguments
Before this commit, the code was assuming that we only passed stack
arguments to fuctions with RawFunction type. This is not true anymore.

This commit adds support to getStrongModelInfo for when we are passing
stack arguments to CABIFunctionType.
2022-11-30 18:16:13 +01:00
Alessandro Di Federico 537c1e7524 IRHelpers: introduce emitMessage 2022-11-30 18:16:13 +01:00
Pietro Fezzardi 7c643f3d1b ModelHelpers: support generic80_t and generic96_t 2022-11-30 18:16:13 +01:00
Pietro Fezzardi e92f6a3ddd ModelHelpers.cpp: refactor handling of ModelGEP 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 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
Giacomo Vercesi dad9dbcec8 getCurrentRoot: improve /proc/self/maps parsing
This fixes a behavior in getCurrentRoot that would lead it to reporting
an incorrect path if revng was installed in a path with spaces.
2022-11-02 11:50:40 +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 887701e6f0 InitModelTypes: better support CABIFunctionType 2022-10-20 10:22:20 +02:00
Giacomo Vercesi 7fda1ef459 PipelineC: drop AbortHook
Handle crashes via signal handlers. Switch python's revng.api from
a normal python function to faulthandler, which works also in the
case of harsher interruptions (e.g. SIGABRT).
2022-10-04 14:13:56 +02:00
Alessandro Di Federico f93eefda66 replaceAll: move to STLExtras.h 2022-08-31 18:07:47 +02:00
Alessandro Di Federico a844589739 ProgramCounterHandler: align PC address
ProgramCounterHandler now emits code masked with an alignment mask to
ease the job of various analyses.
2022-08-08 13:55:26 +02:00
Alessandro Di Federico 4d69437548 Split moveBlocksInto off moveToNewFunctionType 2022-08-08 13:55:25 +02:00
Alessandro Di Federico 01ed4fb687 PCH: handle a dispatcher with 0 elements 2022-08-03 18:36:52 +02:00
Davide Depau 0d55cd4c51 Do not explicitly print stack trace on abort
Let the signal handler take care of that
2022-07-22 21:04:03 +02:00
Antonio Frighetto 19d7f8b2c9 Late decompilation: support model::Segment
Backend and InitModelTypes now handle the opaque `segmentRef` marker.
2022-07-19 13:53:21 +02:00
Antonio Frighetto d9bc64b29d Introduce MakeSegmentRefPass
A simple pass that scans constant expressions and literals and
replaces them with opaque calls so that they can be easily dealt
with by the Backend, in an attempt of emitting better-looking
decompiled code.
2022-07-19 13:48:50 +02:00
Antonio Frighetto 0ca87e8840 ModelHelpers: drop createEmptyStruct
`createEmptyStruct` has been upstreamed into revng.
2022-07-19 13:47:44 +02:00
Alvise de Faveri a788a5ba62 Add helpers for inferring model types from the IR
1. Add a common helper to traverse ModelGEPs (`traverseModelGEP`)
2. Add a centralized way to deduce the model type of values that
   have strong model information attached to them (e.g. isolated
   functions and ModelGEPs)
3. Add a similar helper for deducing formal types of operands in known
   cases
2022-07-18 15:37:31 +02:00
Alvise de Faveri 490a09e8c1 Add Marker tag to Parentheses 2022-07-15 17:17:04 +02:00
Alvise de Faveri c2481aeb7b Support: Add deserializeFromLLVMString
Instead of having `paseQualifiedType` and `parseAndDeserialize`,
we now have a single function that is symmetric to
`serializeToLLVMString`.
2022-07-15 17:17:04 +02:00
Giacomo Vercesi 05dc27715d Improve pipeline saving capabilities
This commit introduces some changes to how the revng pipeline handles
serializing to disk. Specificaly:

* Pipeline globals (specifically model.yml) are better handled if they
  are in a subdirectory. They are now saved in the "context"
  subdirectory.
* In python:revng.api the pipeline is serialized whenever there is a
  non-reproducible change to the state (e.g. binary upload or model
  change).
  In the case of analyses this is done conservatively by checking that
  the diff produced is not empty.
* The logic for computing a step's subdirectory has been moved to the
  pipeline runner, consequently if a step is asked to serialize it
  will not create any subdirectories.
* Functionality for saving a single step/context has been exposed in
  Pipeline C.
* Finally, all path concatenations are now handled by
  llvm::sys::path::append, for extra os-agnosticism.
2022-06-29 14:50:58 +02:00
Alvise de Faveri f3b2bf2e2d IRCanonicalization: Remove early-cse 2022-06-28 10:29:54 +02:00