Commit Graph

3168 Commits

Author SHA1 Message Date
Djordje Todorovic 286eb4d734 c-backend: Introduce PTMLCBuilder
This will be used to generate plain C.
2023-06-09 15:40:23 +02:00
Pietro Fezzardi a263270858 Remove redundant casts on comparisons 2023-06-09 09:28:40 +02:00
Pietro Fezzardi f4020c9fa6 TNAP: fix handling of wraparounds
Before this commit, the TwosComplementArithmeticNormalizationPass wasn't
taking into consideration properly all the cases where the arithmetic
can wrap around in case of expression such as (x + const1 <=> const2) or
(x - const1 <=> const 2).

This caused 2 different classes of problems that affected semantics.
1) In some cases we were emitting comparisons that were too broad,
   meaning that they were true in a larger set of cases than the
   original one.
2) In other cases we were emitting tautological comparisons, i.e.
   comparisons that were always demonstrably true or false at compile
   time.

This commit fixes the problem, treating all the cases in a generalized
unique way that works correctly for every case.
2023-06-09 09:24:52 +02:00
Pietro Fezzardi fceaa57f80 InitModelTypes: UnaryMinus is considered Signed 2023-06-09 09:23:55 +02:00
Pietro Fezzardi 9330e711b9 ExitSSAPass: fix PHIs with intersecting live range
Before this commit, ExitSSAPass was collapsing PHINodes too aggressively
onto the same variable.
In particular we were mishandling the case where two PHINodes were
candidates for being collapsed to the same variable, but they had
overlapping live ranges.
Having overlapping live ranges means that they don't store the same
value (otherwise LLVM would have CSE'd them), so if we collapse them
onto the same variable we end up losing the value.
2023-06-09 09:23:28 +02:00
Pietro Fezzardi faa1fd5169 Add missing whitespace before } in decompiled C 2023-06-09 09:23:01 +02:00
Pietro Fezzardi b4ac5b59c6 Drop useless \n at after StructInitializers in C 2023-06-09 09:22:59 +02:00
Pietro Fezzardi af068cb286 OperatorPrecedence: omit parentheses in [] 2023-05-26 11:50:48 +02:00
Ivan Krysak 66fc161f73 Assembly: choose disassembler based on basic block
Before now, it was choosen based on the function, but that led to
problems when disassembling thumb functions calling non-thumb PLTs.
2023-05-25 09:49:13 +02:00
Ivan Krysak 29eae116fd Assembly: handle addresses in a special way 2023-05-25 06:37:40 +00:00
Ivan Krysak 5cdb1642bb Assembly: rework tag processing 2023-05-25 06:37:30 +00:00
Ivan Krysak f0a29f17b9 Assembly: Introduce address style options 2023-05-25 06:37:21 +00:00
Ivan Krysak 9dfc350b1a Assembly: do not add "next instruction" as target 2023-05-25 06:36:26 +00:00
Ivan Krysak c21f2649c9 Assembly: introduce new tags
This also reorders the enum, because when two tags collide (they have
the same `from` and `to` points, they are sorted based on the enum
values.

The new order ensures that the values we are more likely to choose
to preserve are closer to the bottom. Since each token can only have one
type associated with it, we choose the lowest one by default.
2023-05-25 06:36:02 +00:00
Ivan Krysak 6a407a94bf Assembly: partition label helper
This moves the internal implemetation details into a separate
function `labelImpl` as well as renames the `label` into
`labelDefinition`.
2023-05-25 06:35:58 +00:00
Ivan Krysak f3918e3305 Assembly: change label to accept BasicBlockID 2023-05-25 06:25:25 +00:00
Ivan Krysak 02978910b0 STLExtras: introduce zip_pairs skip flavour
I found that it leads to better looking code when the check of whether
the range in question even has enough elements to skip is inside
the helper.

As such a separate type of skip entry point was introduced: one that
allows to iterate over the container pairwise

Now, instead of asserting, the loop just does nothing in cases like
```cpp
for (const auto &Element : zip_pairs(make_empty_range())
  do_stuff();
```
2023-05-25 06:25:07 +00:00
Ivan Krysak d1cefaee04 PTML: ensure invalid labels are never emitted 2023-05-25 06:25:07 +00:00
Ivan Krysak 560bf16d1f Disassembler: support arbitrarily sized tags 2023-05-25 06:25:07 +00:00
Ivan Krysak 4699c2da72 Assembly: remove ShouldSymbolizeOperands option 2023-05-25 06:25:07 +00:00
Ivan Krysak f9a72125d3 Aseembly: accept relative jump targets
Drops the comment about an attempt to switch to the absolute targets
and sets `setPrintBranchImmAsAddress` to `false` no matter what
immediate style is selected.
2023-05-25 06:25:07 +00:00
Ivan Krysak 83e48bbc3a LLVMDisassemblerInterface: remove unused argument 2023-05-25 06:25:07 +00:00
Ivan Krysak 5b2af637de Minor Changes 2023-05-25 06:25:07 +00:00
Ivan Krysak 0170c0dfeb Model: add segment overlap check to verification 2023-05-17 14:08:06 +02:00
Ivan Krysak c838d2b019 CrossRelations: greatly simplify Relation Targets
This improves readability of the serialized version quite a bit.
2023-05-17 14:08:06 +02:00
Ivan Krysak eae029d156 CrossRelations: merge IsCalledFrom flavors
`IsDynamicallyCalledFrom` is removed in favour of `IsCalledFrom`.

Looking at just how similar the actual uses of both are, there's not
much reason to keep them separate.
2023-05-17 14:08:06 +02:00
Ivan Krysak 641fb61f7b EFA: upgrade buildControlFlowGraph
It now assumes that the nodes of the graph it constructs also require
the function entry point on top of the basic block ID.
2023-05-17 14:08:05 +02:00
Ivan Krysak fade3ec01f CallGraph: switch to pipeline::Location 2023-05-17 14:08:05 +02:00
Ivan Krysak 7322d1a845 ControlFlow: switch to pipeline::Location 2023-05-17 14:08:05 +02:00
Ivan Krysak 50b5abf505 Yield: add isEmpty() helper to graph nodes 2023-05-17 14:08:05 +02:00
Ivan Krysak 013696a939 yield: move SVG out of the ControlFlow
Since the file is also used for call graphs, it's placement is not ideal
2023-05-17 14:08:05 +02:00
Ivan Krysak 045cdefcac GraphLayout: move outside of yield 2023-05-17 14:08:04 +02:00
Ivan Krysak d99b0241e8 Minor improvements 2023-05-17 14:08:04 +02:00
Alessandro Di Federico 14b40ebe45 CFEP: ignore if already part of another block
We used to ignore CFEPs that matched the starting address of a basic
block of a previously detect function.
We now also exclude such CFEPs even if the candidate is *part* of an
existing block.
2023-05-17 11:19:32 +02:00
Alessandro Di Federico 739bed3c1d DetectABI: serialize CFG in root
This is done mainly so that downstream passes do not need to run
`CollectCFG` to store information that has already been computed but not
serialized.

This come at the cost of computing the CFG also of functions we don't
want to analyze in `DetectABI`.
2023-05-17 11:17:44 +02:00
Alessandro Di Federico d0b235c1f4 JTM::findCodePointers: ignore non-aligned data 2023-05-17 11:17:41 +02:00
Alessandro Di Federico b3eaae6f83 ELFImporter: fix handling of DT_{INIT,FINI} 2023-05-17 11:17:39 +02:00
Pietro Fezzardi 412dd85556 DecompileFunction.cpp: avoid useless casts in ICmp 2023-05-12 16:12:48 +02:00
Pietro Fezzardi 9b62b751ee DecompileFunction.cpp: refactor emitting constants 2023-05-12 15:21:22 +02:00
Valentina Sona 0e61bf3fd2 TANP: Move constants to right side of comparisons
Implements transforms when the results of sub or add with a constant
operand are compared against constant:
1) x + a == b --> x == b - a
2) x + a != b --> x != b - a
3) x + a <= b --> x <= b - a
4) x + a < b --> x < b - a
5) x + a >= b --> x >= b - a
6) x + a > b --> x > b - a

After the transformation, the right hand side is also enqued for
analysis to detect opporunities to use unary minus if a-b is a negative
constant.
2023-05-12 15:21:22 +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
Alessandro Di Federico bd9828ea8f TypeFlowGraph: adopt GenericGraph constructors 2023-05-10 14:23:07 +02:00
Alessandro Di Federico 92c028235f Introduce WellKnownModels analysis 2023-05-10 11:16:08 +02:00
Alessandro Di Federico b112d51154 LDDTree: rewrite findLibrary
`findLibrary` has been rewritten to adhere more strictly to `man ld.so`.
Also, `lddtree` no longer relies on sections headers.
2023-05-10 11:04:52 +02:00
Alessandro Di Federico abc380017b {ELF,Dwarf}Importer: fix ExportedNames
Under certain conditions, upon import, functions where not being added
`ExportedNames`, which was preventing them from finding the prototypes
from dynamic libraries' debug information.
2023-05-10 09:21:43 +02:00
Alessandro Di Federico f562d0373f Importers: fix usage of BaseAddress
This commit ensure the BaseAddress is propagate as appropriate to all
levels of the importers and that it is ignored for executables
(non-PIC).

This was a recurring source of importing the same function twice, once
relocated, once not.
2023-05-10 09:20:40 +02:00
Alessandro Di Federico 5fbaebe153 DwarfImporter: handle DW_AT_abstract_origin 2023-05-10 09:20:15 +02:00
Alessandro Di Federico 73fb1a31c9 Outline TypeCopier
This commit also drop the suggestion that it should be used for copying
prototypes only.
2023-05-10 09:20:15 +02:00
Alessandro Di Federico 4c0f809626 Introduce PathList::list 2023-05-10 09:17:35 +02:00