348 Commits

Author SHA1 Message Date
Giacomo Vercesi b4f9147646 Introduce LLVMFunctionsContainer
Add another container for LLVM modules. This one stores one
`llvm::Module` per function (all modules share the same
`llvm::LLVMContext` for performance reasons).
2025-11-18 17:47:54 +01:00
Giacomo Vercesi a39906ca85 Factor out cloneFiltered from LLVMContainer
Move the body of `cloneFiltered` from `LLVMContainer` into a free
function in `IRHelpers.h`.
2025-11-17 10:04:13 +01:00
Giacomo Vercesi 153fcf2773 InitRevng: initialize LLVM components
In the constructor of `InitRevng` also call all the `llvm::initialize*`
functions. This is done to be less implementation-specific and having
these functions be called in
`LLVMPipelineRegistry.libraryInitialization`.
2025-11-17 10:04:13 +01:00
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Alessandro Di Federico 1429b526ab Introduce libtcg
This commit drops libptc in favor of its new form libtcg.

It brings several improvements, among which:

* The QEMU version we work on has been upgraded.
* CPUStateAccessAnalysis has been reimplemented in a way that makes it
  easier to debug and solves some limitations (e.g., tracking leaking
  pointers).
* Identification of pieces of the CPU state that are read by each helper
  and fixing access to the CPU state is now performed at build-time.
* We no longer mmap the code we need to translate, dropping all the
  issues related to code that needed to be mapped where something is
  already present.
* We now have two distinct flavors of helper modules: the full one and
  the "slim" one. The latter contains the definition only of functions
  we intend to inline. It is used in most of the pipeline, a good thing
  since we spend less time optimizing code we don't really care about.
  The full module is only used on the re-compilation branch of the
  pipeline.
* We no longer split the `cpu_loop` function.
* We change MetaAddress to rely on architectures from `model::` as
  opposed to the LLVM ones.
* We no longer attach debug info to LLVM IR containing the original
  assembly.
* We now verify that the lifted code only contains code we expect.
2025-10-31 17:25:03 +01:00
Alessandro Di Federico 246e0d9b59 Logger: handle nameless loggers 2025-10-29 10:57:19 +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 2ba5ca3e3d Suppress selected IRBuilder checks 2025-10-21 19:17:37 +03:00
Ivan Krysak 3561c2b907 Adopt IRBuilder wrapper 2025-10-21 19:17:01 +03:00
Giacomo Vercesi e57442fafe Introduce Tar.h
Split off the `GzipTarReader` into `Tar.h`, include a normal
`TarWriter` class which leverages libarchive to generate the tar file.
2025-10-16 16:08:05 +02:00
Giacomo Vercesi 2f83d8f5c9 Introduce CUniquePtr
Add a helper using of `std::unique_ptr` that allows easier wrapping of
C pointer with destructors.
2025-10-16 16:08:05 +02:00
Ivan Krysak e56f543b1a Split module.bc.zstd 2025-10-13 10:26:41 +03:00
Ivan Krysak 5717d835f8 Add missing llvm::Error checks 2025-10-13 10:26:37 +03:00
Ivan Krysak dadd836035 MetaAddress: assert validity 2025-10-08 12:22:34 +03:00
Ivan Krysak a88747cf99 Drop unused includes 2025-10-08 12:22:34 +03:00
Lauri Vasama 375d40fc59 Move CTarget.h under revng/Support 2025-09-29 18:05:54 +03:00
Ivan Krysak 79d2719347 dumpModule: set IsForDebug to true
This is purely for consistency sake. All the other module dumping
wrappers set this argument, except for this one.
2025-09-10 17:44:00 +02:00
Ivan Krysak 98a3b00535 Minor Improvements 2025-09-10 17:44:00 +02:00
Ivan Krysak a285ad2785 IRHelperRegister: get a comment from Description 2025-07-23 11:38:53 +02:00
Ivan Krysak b5337d78da Minor Improvements 2025-07-23 11:38:50 +02:00
Andrea Gussoni 1faa781e6a CommandLine: drop pathToStream
Remove `pathToStream` in favour of `llvm::ToolOutputFile`.
2025-07-23 11:34:13 +02:00
Giacomo Vercesi f4a1d5bba6 OnQuit: clean up
Split the handlers in `OnQuit` between the repeatable and non-repeatable
ones. Trigger the non-repeatable ones only on program exit.
2025-05-07 16:42:20 +02:00
Giacomo Vercesi fede2f2090 ProgramRunner: allow redirection of streams
Change ProgramRunner's API to allow to optionally provide stdin and
capture stdout/stderr.
2025-05-05 17:28:48 +02:00
Ivan Krysak 1bce76f511 Bring name mangling out into a support helper 2025-04-24 13:22:14 +02:00
Pietro Fezzardi 5ca182578b Add InstCombineNoArraysPass
This pass wraps LLVM's vanilla InstCombine, to hijack one of its
options. The goal of this hijack is to prevent InstCombine from
splitting and replacing accesses to arrays with GEPs and smaller
accesses.
2025-04-22 17:23:37 +02:00
Pietro Fezzardi ef2c3a7626 Add SROANoArraysPass
This pass wraps LLVM's vanilla SROA, to hijack one of its options.
The goal of this hijack is to prevent SROA from splitting and replacing
memory accesses to arrays with GEPs and smaller accesses.
2025-04-22 17:19:56 +02:00
Pietro Fezzardi 3b10a3c5d9 Move SimplifyCFGWithHoistAndSinkPass to new file
This will be used to collect various customizations of LLVM passes, that
are necessary to enable setting different default options to passes for
insertion in the revng pipeline.
2025-04-22 17:18:26 +02:00
Ivan Krysak 79964eac74 Avoid ' misuse in error messages and comments 2025-04-17 16:41:21 +02:00
Ivan Krysak 514e6c56e0 ProgramCounterHandler: adopt helper registry 2025-04-17 11:19:17 +03:00
Ivan Krysak 48a7822923 FunctionTags: adopt helper registry 2025-04-17 11:19:17 +03:00
Ivan Krysak aa15d8ca21 Standardize abort-like function usage 2025-04-17 11:19:17 +03:00
Ivan Krysak a3c8ced826 getUniqueString: use hash for empty strings 2025-04-17 11:19:17 +03:00
Ivan Krysak 169383daa8 MetaAddress: introduce toIdentifier() method
It's equivalent to the existing `toString()` except for the fact that
it uses an identifier-friendly separator (`_`).
2025-04-15 16:35:42 +03:00
Alessandro Di Federico c5c657d11b Lift: increase determinism 2025-04-15 15:31:10 +02:00
Giacomo Vercesi 042108bc44 ProgramRunner: cleanup
Clean up the `ProgramRunner` class:
* use llvm-provided wrappers and system-agnostic variables to compute
  the `Paths` variable
* pre-compute the list of path variables so it's not re-computed on
  every invocation of `run` or `isProgramAvailable`
* Wrap the logging code so that it's not triggered if the logger is
  disabled
2025-03-13 16:23:21 +01:00
Giacomo Vercesi 442020bf22 ProgramRunner: print exit code to logger
Print the exit code of the invoked program to the `program-runner`
logger.
2025-03-13 15:16:17 +01:00
Alessandro Di Federico cac8b5d1b1 ELFImporter: search libs in the input directory 2025-03-05 09:57:51 +01:00
Alessandro Di Federico d4cd9beb77 Minor changes 2025-03-05 09:57:51 +01:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Ivan Krysak ab1da1d986 FunctionTags: introduce Comment 2025-02-13 13:09:50 +02:00
Pietro Fezzardi e9528f4647 Fix getCopyType function type
This commit changes the prototype of getCopeType, so that it now takes 2
arguments.
1. The llvm::Type returned by the Copy function. This can be any scalar
   llvm::Type.
2. The llvm::type of the argument representing the reference to the
   value being copied. This should be a pointer-sized integer, where
   pointer-sized means with the same size of a pointer in the
   architecture in the input binary.

The second argument is not strictly necessary for now, because the whole
decompilation framework expects a binary with a single architecture,
hence a well defined unambiguous pointer size.
This will be used fully only when we start supporting multiple binaries.
Whenever that happens, if we haven't already fully dropped the Copy
helper function we will have to update the associated
OpaqueFunctionsPool to a type pair as key: the return type and the type
of the argument.
2025-01-29 15:17:15 +01:00
Alessandro Di Federico 2128a80cc8 Preserve metadata after Function::deleteBody
Also, introduce and adopt a simple helper class to get this right.
2025-01-28 12:19:16 +01:00
Andrea Gussoni fa69bd24e5 ScopeGraph: introduce the ScopeGraph
Introduce the `ScopeCloser` and `GotoTarget` annotations in the IR, and
the relative necessary machinery, needed to handle scope closer and goto
edges for the new backend.

A specialization of the `llvm::GraphTraits`, called `ScopeGraph`, that
is able to handle both the above mentioned annotations is provided.

For the `llvm::GraphTraits` implementation, we introduce the
`GeneratorIterator` class, which uses a coroutine to store the status of
the iteration.

A debug logger pass is added, so that we are able to test the
functionality with `FileCheck`.
2024-12-05 15:43:57 +01:00
Andrea Gussoni 023771f084 FunctionTags: correct typo
Correct `function-dispatcher` typo.
2024-12-04 11:22:00 +01:00
Alessandro Di Federico 6e733427bc emitMessage: fix function calle emission 2024-11-27 17:18:39 +01:00
Giacomo Vercesi 58b326b8fa ZstdStream: remove manual memory management
Remove the use of manual memory management, convert to the use of
`std::unique_ptr`.
2024-11-26 09:48:37 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Alessandro Di Federico 2e4f4d09b9 Remaining FunctionTags have been moved to revng 2024-11-04 15:09:56 +01:00
Alessandro Di Federico e239e18b0c Adopt FunctionPoolTag 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