Commit Graph

6113 Commits

Author SHA1 Message Date
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
Kacper Kołodziej 9decc1fe51 DLA Frontend: Create nodes for StringLiterals
For segmentRef type of the segment and type returned by segmentRef
function are the same.

For cstringLiteral every call returns pointer to 1-byte type. Pointer is
offsetted by value of strlen+1. strlen is fetched from metadata.

Additionally, all uses of cstringLiteral function has same type as the
type of cstringLiteral (pointer to 1-byte).
2023-04-04 09:31:10 +02:00
Kacper Kołodziej 3776c9a382 Add case for StringLiteral in getExpectedModelType
Use Signed instead of Generic Int8 for StringLiteral return type
2023-04-04 09:31:10 +02:00
Kacper Kołodziej 3dd647cb28 Handle StringLiteral tag in InitModelTypes
InitModelTypes: use argument type as return type for cstringLiteral
2023-04-04 09:31:10 +02:00
Kacper Kołodziej c61c59c474 Handle StringLiteral tag in DecompileFunction 2023-04-04 09:31:10 +02:00
Kacper Kołodziej 2445c5e740 MakeSegmentRefPass: emit cstringLiteral
This commit changes MakeSegmentRefPass so that it's now a ModulePass and
it uses the binary to detect integer constants that represent the
address of strings.
When it detects address of constant strings, instead of injecting calls
to SegmentRef, we now inject calls to cstringLiteral, so that we can
later emit them as inline string literals in C.

In segmentRef we use integer type meaning address in memory, so we
generate segmentRef function with non-pointer type. For cstringLiteral
function we need real pointer type of operand.

Save MetaAddress, size, offset and original type for every
cstringLiteral call in metadata as we do for segmentRef calls.

For cstringLiteral "revng.cstring_literal" metadata name is used.

StringLiteralPool needs tuple of address, size, offset and type to
keep distinct string decorator functions for each string. This tuple is
represented by StringLiteralPoolKey struct.

Pipe for MakeSegmentRefPass needs to be defined explicitly, because
additional wrapper passes are required in MakeSegmentRef:

 1. LoadModelWrapperPass
 2. LoadBinaryWrapperPass

MakeSegmentRefPass requires access to RawBinaryView to detect cstring
literals in binary.

Fix printed command in MakeSegmentRefPipe

This printed command might not work. @ale commented it will be replaced
with `revng pipe run-pipe` once we will have it.

Update IRHelpers to new revng API

Switch String and Namespace arguments in getUniqueString
2023-04-04 09:31:10 +02:00
Kacper Kołodziej f83cb94e1f Add StringLiteral tag and corresponding f. pool
StringLiteral tag will be used to mark cstring decorators in generated
IR.
2023-04-04 09:31:10 +02:00
Kacper Kołodziej bbebdd44b4 Prefer String.empty() case first 2023-04-04 09:30:09 +02:00
Kacper Kołodziej 17b0ecd78a Compare to nullptr instead of implicit cast
Prefer explicit comparing to nullptr instead of implicit casting pointer
to bool.
2023-04-04 09:30:09 +02:00
Kacper Kołodziej e7bb7d09df Rename getStrByAddress to getStringByAddress
We don't use abbreviations in names.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi 8801fc3b33 Support empty strings in getUniqueString
This commit works around a quirk of
`llvm::ConstantDataArray::getString`, which returns a
`llvm::ConstantAggregateZero` for empty strings.

This quirk caused assertions in the previous implementation when passing
an empty `String` to `getUniqueString`.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi 91af14007f Assert non-empty namespace in getUniqueString
Using an empty namespace causes the creation of a named metadata with an
empty string as name.
`llvm::verifyModule` does not check for that, so the `Module` still
verifies, but the on-disk serialization generated by `AsmPrinter.cpp`
prints `"empty name"` instead of the metadata name, and if the
serialized `Module` is then reparsed it parses succesfully but it does
not verify anymore.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi ec17b36801 Fix attributes of build_PlainMetaAddress function
These allow it to be DCE'd and CSE'd if possible directly by LLVM
instead of requiring us to handle it esplicitly as a special case.
2023-04-04 09:30:09 +02:00
Pietro Fezzardi 4c2602e956 RawBinaryView: add getStrByAddress method
This method is similar to `getByAddress`, but it returns an
`llvm::StringRef`.

It is intended for those users that need to manipulate the bytes as
strings. In those cases, the `llvm::ArrayRef<uint8_t>` returned by
`getByAddress` is not suitable, because it triggers warnings due to
`uint8_t` not being the same as `char`.
2023-04-04 09:30:09 +02:00
Kacper Kołodziej 1b8801c9dc Add RawBinaryView::isReadOnly method
isReadOnly returns true if segment which contains region defined with
 MetaAddress and size is not writable.
2023-04-04 09:30:08 +02:00
Kacper Kołodziej d281d1fa05 Add --binary argument to llvm_pipeline.py 2023-04-04 09:30:08 +02:00
Giacomo Vercesi f7c796553b ContainerSet: fix typo
Fix a typo in the code of ContainerSet.intersect that would lead to an
incorrect intersection.
2023-03-31 15:50:46 +02:00
Alessandro Di Federico 94676ffde8 Merge branch 'feature/analyses-list' 2023-03-23 11:33:31 +01:00
Giacomo Vercesi 2e96e09f63 Drop analyze-all
Drop all the uses of analyzeAll and swap its use with the invocation of
the appropriate analysesList
2023-03-22 17:50:02 +01: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
Giacomo Vercesi 23286dc58f GraphQL: expose analysis options
Add an additional parameter that allows specifying options for analyses
as a serialized json string
2023-03-22 17:31:46 +01:00
Giacomo Vercesi 1f097bb46a revng.api: Fix leftover snake_case in as_dict
This commit fixes the name of the fields returned by the `as_dict`
function that were left in snake_case when the field in the schema was
camelCase
2023-03-22 17:31:46 +01:00
Giacomo Vercesi a926ca8fcb revng: make cmd tools analysesList-aware
Add the possibility to use analyses lists on tools where the use of
analyses names is allowed
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 312e2e8d53 Add analyses lists
Introduces the possibility of specifiying lists of analyses as way to
give them coherent names.
2023-03-22 17:31:46 +01:00
Massimo Fioravanti d9bbe33316 Add initial autoanalysis 2023-03-22 17:25:05 +01:00
Alessandro Di Federico b866e9010e ELFImporter: fix setting gp_mips canonical value
We used to set the canonical value of the MIPS gp register even in
absence of PLT, leading to a crash (specifically on archlinux librt.so).
2023-03-22 14:22:24 +01:00
Djordje Todorovic 956160e667 TypeCopier: Avoid copying the types twice 2023-03-22 11:38:12 +01:00
Alessandro Di Federico 2fdfaef77e Merge branch 'feature/fix-rename' 2023-03-20 16:38:11 +01:00
Giacomo Vercesi c7d13fd176 PipelineC: fix model verification clause
In the previous implementation of Model.verify an llvm::Error was
returned. Some call sites retained the logic associated with it. Fix
these with the correct logic.
Also fix an instance of `verify` that was missing an assert.
2023-03-20 16:20:06 +01:00
Giacomo Vercesi 3b94dfae4b PipelineC: rework rp_error data type
Drop the use of unique_ptr within the rp_error data type and instead use
std::monostate. Also fix the functions to allow the use of `nullptr` as
the error parameter
2023-03-20 16:08:04 +01:00
Alessandro Di Federico 92dd38c603 TypeCopier: copy PrimitiveTypes only when needed 2023-03-16 15:39:55 +01:00
Pietro Fezzardi 5d4cbbbda3 Merge branch 'feature/stack-argument-alignment' 2023-03-15 14:49:11 +01:00
Alessandro Di Federico d24a8ff120 Merge branch 'feature/stack-argument-alignment' 2023-03-15 14:07:47 +01:00
Ivan Krysak e52a07a657 revng-primitive-types.h: fix a typo 2023-03-15 10:28:24 +01:00
Ivan Krysak 47213e1669 Backend: remove an obsolete log file 2023-03-15 10:28:24 +01:00
Alessandro Di Federico b0024a302f Fixes for SPTAR passed on the stack 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 4e2159d9b5 MakeModelGEP: fix aggregate return value support 2023-03-15 10:28:24 +01:00
Ivan Krysak d08c9387d2 DLA: stop updating aggregate return value types 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 89774a1789 RemoveStackAlignmentPass: Add empty input support 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
Alessandro Di Federico d325e3b64a SSA: support shadow arguments on stack 2023-03-15 10:28:24 +01:00
Ivan Krysak 85fcd92f0e Backend: reword a comment 2023-03-15 10:28:24 +01:00
Ivan Krysak 56cdd8f876 Model: make model::Type::size() stricter 2023-03-15 10:28:24 +01:00
Ivan Krysak c2f0fc19e5 ABI: FunctionType.h -> FunctionType/Layout.h 2023-03-15 10:28:24 +01:00
Ivan Krysak 9475eefe76 ABI-testing: add unit tests for the alignment 2023-03-15 10:19:03 +01:00