Commit Graph

3168 Commits

Author SHA1 Message Date
Alvise de Faveri 91f9a17e4a Backend: Add cast to return value 2022-06-01 11:37:25 +02:00
Alvise de Faveri dd6ef1d4a8 Backend: Improve parenthesis 2022-06-01 11:35:50 +02:00
Alvise de Faveri 06d72f1cd9 Backend: Improve logging 2022-06-01 11:34:18 +02:00
Alvise de Faveri 51df8ad64d Backend: Fix select emission 2022-06-01 11:29:09 +02:00
Alvise de Faveri 52dd37d0ed HelpersToHeader: Whitelist helpers
Explicitly list the functions whose prototype should be serialized
in the `revng_helpers` header. This is more robust with respect to
future opcodes added in the IR.
2022-06-01 11:27:34 +02:00
Alvise de Faveri 99b06894c4 GHAST: Fix NotAAnd(Not)B short-circuiting 2022-06-01 11:24:20 +02:00
Alvise de Faveri 7f37a22b5d Support: Improve peelConstAndTypedefs constness 2022-06-01 11:21:02 +02:00
Alvise de Faveri e9fcdc3f2a Support: Convert LLVM types as generic types 2022-06-01 11:09:15 +02:00
Alvise de Faveri c7264badae Support: Add serializeToLLVMString(QualifiedT) 2022-06-01 11:08:29 +02:00
Alvise de Faveri 189fbe4651 Support: Fix the key for OpaqueExtractValue pool
Calls to `OpaqueExtractValue()` are meant to replace `extractvalue`s
found in the LLVM IR. Since the type of an `OpaqueExtractValue` is
identified by both the return type (extracted value) and the first
argument's type (aggregate operand of the `extractvalue` instruction),
we need to consider both when building the associated FunctionPool.

Previously, we were identifying each `OpaqueExtractValue` variant using
only the returned value, which was wrong. In fact, if we have two
`extractvalue` instructions that extract a value of the same type
(e.g. i32) from two different aggregate types (e.g. structA and
structB), we have to define two different `OpaqueExtractValue`: one
that returns an i32 and has a parameter of type structA, and one that
returns an i32 and has a parameter of structB. If we use only the
return type, we are not able to distinguish the two.
2022-06-01 11:05:31 +02:00
Pietro Fezzardi f62cdc1181 RemoveLiftingArtifacts: promote init_* to undef 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 18b9e481c8 Backend: fix emission of integer constants
Before this commit we were using a suboptimal API that often resulted in
expressions with many zeros for the 0 constant, e.g. 0000000 instead of
just 0.

This commit fixes the problem.
2022-05-31 12:40:52 +02:00
Pietro Fezzardi 229648a6cb Backend: fix casts in assignments expressions
Before this commit source and destination types were swapped.
2022-05-31 12:40:52 +02:00
Pietro Fezzardi d02f51c0f0 SegregateStackAccessesPass: handle dead code
Before this commit, SegregateStackAccessesPass always expected to find
calls stack_size_at_call_site markers injected by
InjectStackSizeProbesAtCallSitesPass.

This is not always true, because aggressive LLVM optimizations can
remove dead code.

As an example, if the user or some analysis earlier in the pipeline
wrongly marks registers as non-arguments, the optimization pipeline will
throw away and eliminate everything that descends from the initial
values of those registers.

This commit enables SegregateStackAccessesPass to cope with calls to
stack_size_at_call_site that were eliminated, and keep going just
considering the calls that are still there.
2022-05-31 12:40:52 +02:00
Pietro Fezzardi 4ed636cbba Support emission in C of null pointers 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 35e0e688d2 Support emission in C of integer or pointers undef 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 67c6c81e53 MakeModelGEP: ignore undef and null addresses 2022-05-31 12:40:52 +02:00
Pietro Fezzardi 2651b8765b DLA: drop CollapseCompatibleArrays
This pass was never implemented and we don't have plans to do it soon.
This commit just drops it to reduce the noise.
Whenever we decide to implement something similar we'll do it from
scratch.
2022-05-27 17:06:49 +02:00
Pietro Fezzardi 31419a5fd1 Remove old unused dla::Layout class
This class was introduced before having model::Type, to represent
roughly the same information.

Now it's dead code and this commit removes it.
2022-05-26 16:46:47 +02:00
Pietro Fezzardi 3e78b3c9e6 DLA: fix handling of Functions without stack args 2022-05-25 17:23:42 +02:00
Pietro Fezzardi b09be7d34d SegregateStackAccesses: handle stackless Functions 2022-05-25 17:23:42 +02:00
Massimo Fioravanti b184360340 Make DetectStackSizePass into a pipeline analysis 2022-05-25 15:49:38 +02:00
Massimo Fioravanti f40cf6471d Transformed DLA in a pipeline analysis 2022-05-25 15:48:27 +02:00
Giacomo Vercesi 7052f2a8a0 Support analyses and globals in Python
This commit adds the newly implemented functionality in PipelineC both
in revng.api and the graphql api, allowing:

* retrieval of global variable names
* unwrapping of a single target
* execution of analyses
2022-05-24 10:56:02 +02:00
Massimo Fioravanti 1508a1bc72 revng-pipeline: support out of line analyses 2022-05-24 08:59:08 +02:00
Massimo Fioravanti e38dfc74cc PipelineC: introduce run_all_analyses 2022-05-24 08:59:08 +02:00
Massimo Fioravanti f0a5ffe3b3 revng-pipeline: globals, extractOne and analyses 2022-05-24 08:58:48 +02:00
Alessandro Di Federico 22d469aa10 mv librevngUnitTestHelpers.{a,so} 2022-05-12 21:55:18 +02:00
Pietro Fezzardi 20fea32ce1 FunctionStringMap: improve code-reuse
The serialize() method now uses the serialize() function provided by
revng/Support/YAMLTraits.h, so we don't have to explictly const_cast.
2022-05-12 17:00:13 +02:00
Pietro Fezzardi 1bb5bd6eee ModelGlobal: don't move the underlying model::Binary
Moving it was causing the address of the model to change, while for the
functionality of revng-pipeline we need it to be stable.

So we pay the price of expensive copy, for the sake of downstream
stability.
2022-05-12 16:59:47 +02:00
Pietro Fezzardi b190f1a47c Refactor logic to compact function targets
This commit introduces a reusable function to compact
pipeline::TargetLists that represent functions.

Initially this reasoning was only needed by TaggedFunctionKind, but now
also FunctionStringMap needs it, and potentially others in the future,
so it makes sense to keep only a single implementation for it instead of
duplicating code (and likely bugs).
2022-05-11 16:16:49 +02:00
Pietro Fezzardi ca566a76f0 Rename StringMapContainer to FunctionStringMap
This new naming more closely describes the fact that each element in the
map must be associated with a model::Function
2022-05-11 16:16:32 +02:00
Pietro Fezzardi 7d097ba3e0 Move CDecompilationPipe in lib/Backend 2022-05-11 15:21:41 +02:00
Pietro Fezzardi 42b52bb22b Add DecompiledYAMLToCPipe 2022-05-11 15:21:39 +02:00
Pietro Fezzardi 4188b709be Merge BeautifyGHAST back into RestructureCFG
The beautification library was split into a separate library for
historical reason, having to do with LLVM passes, their dependencies,
and dirty hacks we had around.

Now the LLVM passes, and the hacks are gone, so we can merge back
everything together.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi d8d7779a37 DecompileFunction.cpp: improve logging 2022-05-11 15:19:34 +02:00
Pietro Fezzardi 29afe90460 DecompileFunction.cpp: skip over empty functions
This is necessary because with the port to revng-pipeline there will
be isolated functions with empty bodies.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi 97f0f8c521 IRHelpers: add deleteOnlyBody helper 2022-05-11 15:19:34 +02:00
Pietro Fezzardi 604d370239 Remove LLVM passes RestructureCFG, BeautifyGHAST
Now that the late stage of the decompilation pipeline is managed with
revng-pipeline, and we have a standalone tool for decompilation, we
have no need to use LLVM passes anymore for those stages.

This commit also renames the directories to avoid the confusing Pass
suffix, not what LLVM passes are gone.
2022-05-11 15:19:34 +02:00
Pietro Fezzardi 0e4681dc38 Add -m option to revng-decompile to override Model 2022-05-11 15:19:34 +02:00
Pietro Fezzardi fc40f646a4 Replace CBackendPass with revng-decompile tool
This commit replace the old CBackendPass with a standalone tool:
revng-decompile.
This pass at the moment runs the three stages of decompilation:
  - CFG restructuring
  - Beautify GHAST
  - C Code generation
2022-05-11 15:19:25 +02:00
Pietro Fezzardi bce0bd70b1 StringMapContainer: fix enumeration for * target 2022-05-11 14:52:22 +02:00
Pietro Fezzardi 2dea29d926 StringMapContainer: use multiline strings in YAML 2022-05-11 14:39:31 +02:00
Pietro Fezzardi 238b98c3da Switch all revng-c to revng-pipeline 2022-05-11 12:42:38 +02:00
Pietro Fezzardi f8c512f0b8 Drop LLVM passes from lib/HeadersGeneration
Now the emission of C headers for decompilation is entirely handled
through the new revng-pipeline infrastructure and/or via standalone
tools.
2022-05-11 12:42:38 +02:00
Pietro Fezzardi 96148248b1 Drop old unused flag: -dla-flatc-dir 2022-05-11 12:42:38 +02:00
Pietro Fezzardi c88504afbf Drop old flag -single-decompilation
This flag was used with the old C backend to decompile only a single
function from a binary.

The logic of selecting functions in a binary for decompilation is now
part of revng-pipeline, so the -single-decompilation option and the
associated TargetFunctionOption library can be dropped.
2022-05-11 12:42:38 +02:00
Pietro Fezzardi 5071fe8dc4 Add CDecompilationPipe 2022-05-11 12:42:38 +02:00
Pietro Fezzardi 56de892efb Add HelpersToHeaderPipe 2022-05-11 12:42:38 +02:00
Pietro Fezzardi 7e926db200 Add ModelToHeaderPipe 2022-05-11 12:36:32 +02:00