Commit Graph

500 Commits

Author SHA1 Message Date
Pietro Fezzardi d9b5bfd99a revng-primitive-types.h: improve generic{80,96}_t
Before this commit, both `generic80_t` and `generic96_t` were always
defined as structs containing an array of chars of the proper size.

This ensured that they always had the proper size, but it didn't play
well with recompilation of decompiled C code, because it wasn't possible
to assign e.g. a `float80_t` to a `generic80_t` (or viceversa), which
was the whole point of having `generic80_t` and `generic96_t`.

This commit works around this by making sure that, whenever `float80_t`
(and `float96_t`) is defined, the definition of `generic80_t` (and
respectively of `generic96_t`) always matches, allowing error-free
recompilation of decompiled sources.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 6bc5346733 Rename tests in revng-c-model-to-header.yml
This change is intended for the name not to clash with another set of
tests that lives in revng-c.yml.
The first is intended as a set of unittests for model-to-header,
the second is intended to generated headers to test recompilation of
decompiled C code.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi eae5e3069d revng-primitive-types.h: fix 128-bits definitions
This commit guards 128-bits integer typedefs and helpers with:
`#ifdef __SIZEOF_INT128_`, because these are compiler extensions that
are not always guaranteed to be defined (e.g. they are not available
when compiling for x86 32-bits).
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 6acd265c5a Add revng helpers to decompile llvm::UndefValue
Before this commit, we used to decomple UndefValue to the literal 0.

This was causing problems in some cases, such as switch(0 /*undef*/)
where clang was issuing a warning that was impossible do disable without
turning off -Wall alltogether, which is undesirable.

This commit introduces a set of helper functions in
revng-primitive-types.h, that are now used to avoid emitting undef as
constant.
This is more semantically meaningful when looking at the decompiled
code, and it has the nice side effect that it silences the clang
warnings mentioned above.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi e2791443fb Remove extractvalue instructions in decompilation
Now extractvalue instruction are replaced by dedicated
OpaqueExtractValue custom opcode, that prevents LLVM from doing strange
things with extractvalues during optimizations (such as e.g. sinking).

This is important since extractvalue instructions and struct-typed
values in general in our LLVM IR are not real first-class citizens, but
only a byproduct of the binary lifting process, and they actually
represent bundles of registers that are returned from isolated
functions.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi 1b575e75dc Drop restore-extractvalues from the pipeline
Before this commit we were restoring opaque extractvalue instructions to
actual non-opaque extractvalue instructions in the pipeline.
We will not do this anymore, since LLVM ends up messing around too much
with them and it breaks the somewhat assumptions we're making around
values with aggregate types, that in our IR only represent tuples of
registers coming from the binary.
2023-06-30 10:48:59 +02:00
Pietro Fezzardi d2c9cbafb8 Add a DCE pass before RemoveLiftingArtifacts
This is meant to get rid of dead stuff that is left around by the revng
lifting process, so that RemoveLiftingArtifacts can be kept simpler.
2023-06-30 10:48:59 +02:00
Alessandro Di Federico 569dc8005b tests: limit inputs to ensure 1-to-1 matching 2023-06-30 10:48:59 +02:00
Alessandro Di Federico 72947f0f71 tests: limit inputs to ensure 1-to-1 matching 2023-06-23 17:57:02 +02:00
Alessandro Di Federico 0ecfbf94b9 SystemV_x86: remove VectorArgumentRegisters 2023-06-23 17:56:09 +02:00
Alessandro Di Federico fa61c784c2 Reintroduce st0_x86 as floating point return value 2023-06-23 17:54:16 +02:00
Pietro Fezzardi 6bf0de84ce Recompile tests with -Wimplicitly-unsigned-literal
This warning was disabled in the past. This commit handles the cas
properly and re-enables the warning in recompilation tests.
2023-06-14 16:06:11 +02:00
Pietro Fezzardi 228e733a65 Cleanup disabled warnings for decompiled 2023-06-12 16:39:51 +02:00
Pietro Fezzardi a263270858 Remove redundant casts on comparisons 2023-06-09 09:28:40 +02:00
Alessandro Di Federico 866e6edb10 Import CollectFunctions tests 2023-05-17 11:19:35 +02:00
Pietro Fezzardi 74df82e0ca model-to-header tests: silence bogus warnings
This commit adds the '.h' suffix to the headers used for testing
model-to-header. This enables clang to understand that they are C
headers and suppresses a set of bogus warnings that were otherwise
triggered as -Wunused-command-line-argument.

Namely, the unused arguments it complained about were:
* 'linker'
* '-c'
* '-ferror-limit=0'
* '-I'
2023-05-12 15:21:22 +02:00
Giacomo Vercesi 52d20ffc36 rcc: add commit check
Add the command-line flag `--check-commit` to `revng-check-conventions`,
this will introduce additional checks related to commits message
conformity.
2023-05-11 10:05:32 +02:00
Giacomo Vercesi 31cd2b53f9 rcc: add codespell
Add codespell to the list of checks performed by
revng-check-conventions. This should reduce the amount of typos present
in the revng codebase.
2023-05-11 10:05:32 +02:00
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +02:00
Giacomo Vercesi a13c3e5ac2 revng: fix executable/shebang in scripts
Some files had discordant executable bit presence and shebang presence.
This commit fixes these occurrences by adding removing the required
feautures where needed.
2023-05-11 10:02:46 +02:00
Giacomo Vercesi 471b9c8396 rcc: fix issues with mypy>=1.0
Add additional config options to the `revng-check-conventions` config to
make mypy work with the revng codebase (mainly related to untyped
functions now causing a warning in mypy).
2023-05-11 10:02:46 +02:00
Alessandro Di Federico 7b2e7a9312 Adopt new revng-qa sources handling 2023-05-10 14:23:32 +02:00
Alessandro Di Federico 92c028235f Introduce WellKnownModels analysis 2023-05-10 11:16:08 +02:00
Alessandro Di Federico 5542382bdb revng-qa tests: adopt full paths 2023-05-10 09:15:18 +02:00
Djordje Todorovic 9d94216dc5 ModelToHeader: Add testing infrastructure
Test structs, unions and primitive types.
Also add tests for inline types.
2023-05-03 13:13:28 +02:00
Djordje Todorovic 41678f8cb6 compile-flags: Avoid warnings on unused local typedefs
Before inline types, majority of typedefs were global,
so  we did not have this problem. But from now on, we have
some typedefs that are local to functions that may be
unused, and it is recognized by compilers as a warning.
2023-05-03 13:13:28 +02:00
Alessandro Di Federico 4b2e067574 rcc: ban functions we wrap 2023-04-28 14:34:52 +02:00
Alessandro Di Federico 596fa25a1b Introduce revng_add_test
This enables us to pass --debug-log=verify to tests.
2023-04-28 14:34:38 +02:00
Massimo Fioravanti 254dc99fcb TupleTreeGenerator: emit tracking machinery 2023-04-21 17:50:16 +02:00
Pietro Fezzardi 17cbe341c6 Remove DuplicateReferences from pipeline
The pass was necessary to prevent the creation of local variables with
reference types, caused by calls to custom opcodes tagged with
FunctionTags::IsRef.
These local variables would not be valid for decompilation, because C
doesn't have reference types.
However, creation of such variables would pop up if not deduplicated,
due to the fact these calls could have many uses, and MarkAssignments
had a policy of marking for serialization all the instructions with many
uses.
Now that policy has been dropped, so this pass doesn't need to exist
anymore.
2023-04-20 17:51:16 +02:00
Giacomo Vercesi 07be2c1cae Allow the use of valgrind with python
This commit does 2 main things:
* Adds PYTHONMALLOC=1 environment variable when `--valgrind` is used
  to force python to use normal malloc instead of the custom allocator
  python normally uses that's not friendly with valgrind
* Add a suppression file to remove a couple of false-positives that
  happen consistently and generate useless noise
2023-04-20 14:43:12 +02:00
Alessandro Di Federico 79c2ca38f6 Introduce SplitOverflowIntrinsicsPass
This pass splits calls `*.with.overflow*` intrinsics into the a pair of
instructions: the underlying operation and a call to an `Helper`-tagged
function that computes whether such operation overflowed.

For instance, we go from:

    %2 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %0, i32 %1)
    %3 = extractvalue { i32, i1 } %2, 1
    br i1 %3, label %..., label %...

To:

    %2 = mul i32 %0, %1
    %3 = call i1 @mul_overflow_u32(i32 %0, i32 %1)
    br i1 %3, label %..., label %...

This saves from handling `struct` in the backend.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 43a0be786f helpers-to-header tests: start from canonicalized 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 8860ea16e2 Introduce HoistStructPhis
This pass turns phis of invocations of pure functions into an invocation
of the pure functions with one phis per argument of the original
invocations.

This makes handling phis easier in the backend and is necessary after
the introduction of simplify-cfg with sinking enabled.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ffee4c22f0 Adapt tests to LLVM 16 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ccb660646e Introduce SimplifyCFGWithHoistAndSinkPass
This is a simple pass that enables running simplify-cfg with the legacy
pass manager enabling instruction hoisting and sinking.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico fda84a701f Decompilation: suppress more warnings 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6e0fc63b77 Reschedule AttachDebugInfo after InlineHelpers 2023-04-13 18:11:48 +02:00
Pietro Fezzardi fe7df1ae75 Add -Wno-pointer-sign to compile-flags.cfg
Now that we support C string literals, by the rules of the language they
have type `const char [N]` where `N` is a compile time constant.
They also decay to `const char *`.

This causes the `-Wpointer-sign` warning to trigger when recompiling
decompiled C code, since we assign the string literals (with type `const
char *` in C) to variables with other pointer types, some of which are
e.g. `const uint8_t * but possibly also `const generic8_t *`.

Given that we emit C code from assembly this warning is too strict to be
always enforced.
In fact, we had already disabled a similar warnings, such as
`-Wincompatible-pointer-types`, and others.
So we disable `-Wpointer-sign` as well in recompilation tests.
2023-04-04 09:31:10 +02:00
Kacper Kołodziej daead39e60 Check signedness of char in revng-primitive-types.h 2023-04-04 09:31:10 +02:00
Kacper Kołodziej 3038dd179f Add binary to MakeSegmentRefs containers in pipeline
Additional argument (--binary) in some tests is needed, because
MakeSegmentRefPipe requires access to binary file.
2023-04-04 09:31:10 +02:00
Giacomo Vercesi af237074f3 Implement AnalysesList in Python API & GraphQL
Implement the new functionality of AnalysesList on the python's side of
rev.ng and the GraphQL schema both in static and autogenerated form
2023-03-22 17:31:46 +01:00
Massimo Fioravanti 0373732b69 Add auto-analysis list
Introduces a default analysis list indede to be run first on binaries.
2023-03-22 17:31:46 +01:00
Massimo Fioravanti d9bbe33316 Add initial autoanalysis 2023-03-22 17:25:05 +01:00
Ivan Krysak e52a07a657 revng-primitive-types.h: fix a typo 2023-03-15 10:28:24 +01:00
Ivan Krysak f5c50da449 Tests: reorder the analyses to import first
The primitives were imported before the importing of the binary, which
is not valid anymore since it leads to duplicate types in cases where
the binary contains any primitive types, since one of the revng-side
commit now asserts on an attempt to insert multiples of the same type.

Also, this removes a duplicated type from the `SegregateStackAccesses`
test's `override` model.
2023-03-15 10:28:24 +01:00
Ivan Krysak eb34c2ee1f Pipes: add ConvertToCABIFunctionType analysis 2023-03-15 10:28:24 +01:00
Ivan Krysak 64d83c89c4 Testing: use the new temp file generator 2023-03-15 10:28:24 +01:00
Ivan Krysak e1ebe8ea35 ABI-testing: introduce CABI-FT correction script 2023-03-15 10:19:03 +01:00
Ivan Krysak a360b11426 ABI: fix issues with regparm abi definitions 2023-03-15 10:19:03 +01:00