Commit Graph

986 Commits

Author SHA1 Message Date
Alessandro Di Federico e9470d6329 Pipeline: improve naming and docs 2023-08-01 12:17:20 +02:00
Alessandro Di Federico 14525d91f5 Adopt llvm::Task 2023-08-01 10:51:16 +02:00
Alessandro Di Federico 2c8c06e4ab Introduce ProgressListeners 2023-08-01 10:49:41 +02:00
Giacomo Vercesi f77d4d6d1f PTML: introduce data-scope-location
Introduce the new `data-scope-location` tag that's to be used for
switching between C and ASM. Include the tag when generating ASM
instructions.
2023-07-31 16:05:51 +02:00
Giacomo Vercesi db7ad24175 PipelineManager: add produceTargets with checks
Move much of the logic of `rp_manager_produce_targets` to a method
inside `PipelineManager`, add additional checks for the existence of the
targets that are requested to be produced.
2023-07-31 16:05:51 +02:00
Kacper Kołodziej 46e9ea0e10 HexDump implementation
HexDumpPipe dumps content of binary file in the similar way as hexdump
tool with addition of PTML markup for instructions addresses.

Continuous parts of binary code are wrapped with <span
data-location-definition=""></span> where data-location-definition
attribute contains Entry/BasicBlock/Instruction addresses in generic
form. <span> tags can be nested if byte(s) belong to many instructions
in code.

At the end of the line every <span> is closed and opened on the next
line again if it still applies to the next byte.

MetaAddress are converted to IntervalMetaAddress (which implements own,
optional-less operator-) and stored in boost::icl::intruval_map. This
map is used to get addresses of instructions to which each byte belongs.
2023-07-31 11:29:41 +02:00
Kacper Kołodziej c0f226fa70 Add const qualifiers to some functions
getJumpTargetBlock takes llvm::BasicBlock * as argument, but doesn't
need to modify it, so const it adds const to it and other functions that
are used by getJumpTargetBlock: findJumpTarget, isTranslated, getType,
isJumpTarget.
2023-07-31 11:29:40 +02:00
Alessandro Di Federico 8e213ade74 TypeShrinking: shrink zext(value) == constant 2023-07-26 10:16:25 +02:00
Alessandro Di Federico 6ed958d614 Improve TypeShrinking
This commit fixes a TypeShrinking bug and extends it to better handle
more instructions. Specifically, we now handle shift left, select, phi
and bitwise operations.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico e0c7038f46 Rework RootAnalyzer::optimize pipeline
This commit reorganizes and explains the reasoning behind the design of
the RootAnalyzer optimization pipeline.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico 99fec2cb10 AdvancedValueInfo: improve logging 2023-07-26 10:16:25 +02:00
Alessandro Di Federico dcc7ca3c6b AdvancedValueInfoMFI: zero-extend constraints
This commit introduces a change in AdvancedValueInfoMFI which forces to
consider constraints valid on 32-bit values to be valid on their
untruncated 64-bit counterparts.

While being unsound, this is important to easily devirtualize indirect
branches on 64-bit architectures where often constraints are expressed
on 32-bit switch values.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico a24f3479ca JumpTargetManager::readFromPointer: fix unmapped
This commit introduces a fix to correctly handle trying to read from an
unmapped region.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico ee335eadf1 GraphTraits: improve handling of const MFP::Graph
Improve the handling of const MFP::Graph in GraphTraits and
DOTGraphTraits.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico d4d9e5dac5 DropRangeMetadataPass: preserve all analyses 2023-07-26 10:16:25 +02:00
Alessandro Di Federico 73a7041396 Introduce GenericGraph::verify 2023-07-26 10:16:25 +02:00
Alessandro Di Federico 0b5404b8ac AdvancedValueInfo: include MFP's DOTGraphTraits
The fact we were missing this include led to dump mute graphs.
2023-07-26 10:16:25 +02:00
Alessandro Di Federico 22b3da2a02 Remove {DataFlow,ControlFlowEdges}Graph::Base 2023-07-26 10:16:25 +02:00
Ivan Krysak 2136e05115 Fix a nasty issue caused by an uninitialized flag 2023-07-21 17:25:24 +02:00
Ivan Krysak 19138353f7 abi::FunctionType: preserve return value comments 2023-07-21 17:25:24 +02:00
Ivan Krysak 11c221299e Yield: add the function comment to assembly view 2023-07-21 17:25:24 +02:00
Ivan Krysak ed4efb0bd9 yield::ptml: add functionComment function 2023-07-21 17:25:24 +02:00
Ivan Krysak 18204ccb9f yield::ptml: add comment function
This is a generic way to format an arbitrary type with `Comment`
field as a comment and emit it using PTML.
2023-07-21 17:25:24 +02:00
Ivan Krysak 5c31405e63 Model: rework edit path helpers from the ground up 2023-07-21 17:25:24 +02:00
Ivan Krysak 0c8a5aaffb Model: move edit path helpers in from PTML 2023-07-21 17:25:24 +02:00
Ivan Krysak 485ef34a12 Model: add Comment field all across the board 2023-07-21 17:25:24 +02:00
Ivan Krysak 8a9b253314 Model: clean type constructors up 2023-07-21 17:25:24 +02:00
Pietro Fezzardi 8683e889db EnforceABI: copy attributes on function calls
Before this commit, we were blinding adding the `nomerge` attribute to
function calls. Now we copy attributes over, so we preserve all the
attributes.

In this way the only place where we add the `nomerge` attribute becomes
Isolate.
2023-07-20 20:30:46 +02:00
Pietro Fezzardi 53bc3ebc17 Isolate: add nomerge attribute to DynamicFunctions 2023-07-20 20:30:45 +02:00
Kacper Kołodziej 2c470ec036 Add propagating prototypes in DetectABI pass
The goal of this update is to propagate prototypes of functions called
in wrappers to this wrappers.

When some function hasn't it's own prototype, but the only thing it does
is calling another function, DetectABI pass sets callee prototype as
caller prototype also.

This behaviour is limited to callers that:
 1. have only one basic block
 2. end with call
 3. don't write arguments of callee
 4. don't modify stack pointer
 5. don't write to memory.
2023-07-20 18:09:48 +02:00
Kacper Kołodziej 75ed8f7788 Add WrittenRegisters set to FunctionSummary
WrittenRegisters will be used in propagating prototypes to wrappers
functionality to check if function writes to arguments or stack pointer.
2023-07-20 18:09:48 +02:00
Ivan Krysak 7d235f4fd0 Enforce licence header consistency
Also do some basic cleanup: capitalize first letters, add `.`
at the end of the sentences, and so on.
2023-07-03 15:23:10 +00:00
Ivan Krysak ee0dc1866d Forbid clang format off 2023-07-03 15:23:10 +00:00
Ivan Krysak 9f1d9fd5d0 Use Container::contains() where appropriate 2023-07-02 15:06:11 +00:00
Ivan Krysak 690df84eca Concepts: prefer non-strict SpecializationOf
Not every case can benefit from extra liniency, so they were manually
reviewed on a case by case basis.

Additionally, this drops a couple of "this should be a non-strict
specialization" commits, because of a bug with clang
(see the GenericGraph concepts rework commit for more details) as
to avoid confusion (we wouldn't want anyone trying to solve these
"todo"s) until the clang struct type deduction is fixed. Especially
considering that there are currently no cases where these softer
versions would be beneficial (we never inherit from templates in
question).
2023-07-02 15:06:11 +00:00
Ivan Krysak a123ec2c35 Remove clang-format off around concepts
Now that clang-format no longer breaks anything involving a concept or
a requires clause on sight, these are no longer necessary
2023-07-02 13:20:49 +02:00
Ivan Krysak bc98e0079f Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-02 13:20:49 +02:00
Ivan Krysak 01b4ec36c9 Formatting: set AllowShortEnumsOnASingleLine
The new value is `false`.
2023-07-02 13:15:08 +02:00
Ivan Krysak 7ed14ca65c Minor improvements 2023-07-02 11:06:55 +00:00
Alessandro Di Federico 5885e4f9c8 ValueMaterializer: fix handling of ptr 2023-06-30 16:57:33 +02:00
Alessandro Di Federico 56d43ff089 Isolate/Enforce: add nomerge to calls
Isolated functions already have the `nomerge` attribute, but calls do
not.  This is important in presence of indirect calls.
2023-06-30 16:54:01 +02:00
Alessandro Di Federico a65ccc3413 Introduce ValueMaterializer
`ValueMaterializer` is a rewrite of what was called `AdvancedValueInfo`
which follows the same principles.

The main benefits over the old version is:

* We materialize the data-flow graph and the CFG of the relevant part of
  root. This makes debugging significantly easier.
* We drop the old MonotoneFramework infrastructure in favor of
  getMaximalFixedPoint.
* We significantly reduce the amount of queries we make to
  AdvancedValueInfo.
2023-06-30 13:39:22 +02:00
Alessandro Di Federico 4edcb6dd49 MetaAddress::decomposeIntegerPC: accept APInt 2023-06-30 13:35:04 +02:00
Alessandro Di Federico 466871e866 Introduce RegisterClobberer 2023-06-30 13:28:36 +02:00
Alessandro Di Federico f120ad334c Statistics.h: rework 2023-06-30 13:06:58 +02:00
Alessandro Di Federico 6ca6692d1e getUniqueJumpTarget: do not abort if PC unwritten
Sometimes code performs an indirect jump without changing the value of
the PC.  In most cases this is due to non-code or some other faulty
situation, but it is in principle possible that an instruction performs
an indirect branch to its own address.

This commit ensures that this situation does not end up in an hard
failure.
2023-06-30 12:35:18 +02:00
Alessandro Di Federico 3706f77960 LDDTree: mark Logger static 2023-06-30 12:35:18 +02:00
Alessandro Di Federico 942cc1323a revng::verify: dump module upon failure 2023-06-23 17:54:55 +02:00
Alessandro Di Federico 55d433e020 Layout::verify: be stricter on return values
We now ensure that, if we have multiple return values, each one of them
covers at most one register.
2023-06-21 10:56:27 +02:00
Alessandro Di Federico 0af9b34a0a Layout: make ReturnValues empty in case of void 2023-06-21 10:55:50 +02:00