Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
931a93b
Symex: havocking a string literal has no effect
tautschnig Nov 15, 2026
7753c24
Document supported inline assembly instructions
tautschnig Mar 30, 2026
9147084
Warn when inline assembly is dropped
tautschnig Jun 10, 2026
598837a
Factor shared inline-assembly scaffolding in remove_asm
tautschnig Jun 10, 2026
c645d50
C front end: asm blocks that form a function body are gcc-style
tautschnig Nov 15, 2026
f202334
Goto conversion: make side effects in asm operands explicit
tautschnig Nov 15, 2026
d0484c5
remove_asm: model barriers and x87 control word operands precisely
tautschnig Nov 15, 2026
04ff957
remove_asm: approximate assembly that is not modeled conservatively
tautschnig Nov 15, 2026
3156fb9
Document the modeling and approximation of inline assembly
tautschnig Nov 15, 2026
210d7a2
remove_asm: model stmxcsr and ldmxcsr
tautschnig Nov 17, 2026
f8540db
remove_asm: write the outputs of statements that are modeled
tautschnig Dec 1, 2026
c17598b
C front end: asm blocks in braces are MSVC-style in all modes
tautschnig Dec 1, 2026
b385391
remove_asm: '#' starts a comment only where the target says so
tautschnig Dec 1, 2026
6afa4de
x86 library: lfence and sfence are not full fences
tautschnig Dec 1, 2026
e0c3ac8
remove_asm: dsb with a st option also orders stores before loads
tautschnig Dec 1, 2026
5e4d6f6
remove_asm: MSVC blocks name the variable of a member access
tautschnig Dec 1, 2026
781eb01
x86 library: fstcw and fnstcw do not store zeros in the other bits
tautschnig Dec 1, 2026
580ab02
Variable sensitivity: havocking keeps the variables of the environment
tautschnig Dec 1, 2026
2c23d95
goto-analyzer domains: havoc_object may change any variable
tautschnig Dec 1, 2026
b8e3dae
Document that C++ loses the operands of gcc-style inline assembly
tautschnig Dec 1, 2026
8ec5c08
remove_asm: the lock prefix is not modeled
tautschnig Dec 1, 2026
e2903d7
Inline assembly: pin the translation of each modeled statement
tautschnig Dec 1, 2026
ca672d3
Inline assembly: output addresses that depend on the other outputs
tautschnig Dec 1, 2026
edd7321
remove_asm: ';' starts a comment in MSVC-style blocks
tautschnig Dec 3, 2026
3e16e92
Symex: havoc all objects reachable from a set of pointers
tautschnig Nov 16, 2026
3a87b6f
remove_asm: havoc all objects reachable by unmodeled assembly
tautschnig Nov 16, 2026
ec2a677
goto_rw: objects that havoc_reachable reads and writes
tautschnig Nov 16, 2026
42c7db9
goto-analyzer domains: havoc_reachable may change any variable
tautschnig Nov 16, 2026
c4fa56f
Value-set analyses: transformer for havoc_reachable
tautschnig Nov 16, 2026
e006319
Symex: havoc_reachable must not truncate the candidate pointers
tautschnig Dec 1, 2026
9ccc36f
havoc_reachable: pointers may move within the objects they can reach
tautschnig Dec 1, 2026
6268bbf
VSD: a havoc in a callee must survive the three-way merge
tautschnig Dec 1, 2026
cd0fa5f
goto-instrument: read/write sets of havoc_reachable
tautschnig Dec 1, 2026
a9a893f
Value sets (FI): havoc_reachable must not take references as objects
tautschnig Dec 1, 2026
4ea1889
Symex: havoc_reachable must assign the parts of objects directly
tautschnig Dec 1, 2026
437c141
havoc_reachable: move pointers to aligned positions within objects
tautschnig Dec 1, 2026
775797f
havoc_reachable: bound the candidate values of all pointers together
tautschnig Dec 1, 2026
9d3a2b5
havoc_reachable: change failed objects and memory at integer addresses
tautschnig Dec 1, 2026
5e78f3e
havoc_reachable: arbitrary pointers must reach all compatible objects
tautschnig Dec 1, 2026
f8362ba
havoc_reachable: pointers in unions and large arrays may point anywhere
tautschnig Dec 1, 2026
20bdbab
havoc_reachable: test the value-set fallback and path exploration
tautschnig Dec 1, 2026
10c4a71
Do not run two slow havoc_reachable tests with the new SMT backend
tautschnig Dec 1, 2026
d2f2615
havoc_reachable: change errno and the other program state of the library
tautschnig Dec 3, 2026
8a31e28
asm goto: jump to the label the statement chooses
tautschnig Nov 16, 2026
9fc65d8
goto-cc-file-local/asm-goto: check that the jump may be taken
tautschnig Dec 1, 2026
a869a2a
Test asm goto statements that leave a block with local variables
tautschnig Dec 1, 2026
79ff901
dump-c: print asm goto statements with their labels
tautschnig Dec 1, 2026
4a1b56e
goto_convertt: move the asm goto dispatch into its own function
tautschnig Dec 1, 2026
70cb6a1
Inline assembly tests: do not depend on the host architecture
tautschnig Nov 16, 2026
1189434
Inline assembly: interpret x86 instructions
tautschnig Nov 16, 2026
8948872
Inline assembly: do not access memory at addresses CBMC cannot relate
tautschnig Nov 17, 2026
639fae4
remove_asm: approximate statements whose labels data refers to
tautschnig Dec 1, 2026
4c12281
Inline assembly: unspecified upper bits wherever they may be read
tautschnig Dec 1, 2026
fb558c1
Inline assembly: read immediates as GCC prints and GAS reads them
tautschnig Dec 1, 2026
d88315e
Inline assembly: do not size x86 instructions by C types of memory
tautschnig Dec 1, 2026
6f5c161
Inline assembly: model both alternatives of register-or-memory operands
tautschnig Dec 1, 2026
570bd7b
Inline assembly: approximate what breaks GCC's operand contract
tautschnig Dec 1, 2026
38488f6
Inline assembly: record the dialect and approximate Intel syntax
tautschnig Dec 1, 2026
a014a8d
Inline assembly: approximate x86 segment stores that may change objects
tautschnig Dec 1, 2026
8695f4d
Inline assembly: CF of x86 shl and shr by the operand width is undefined
tautschnig Dec 1, 2026
efca15d
Document x32 and the modeled x86 carry-flag and out instructions
tautschnig Dec 1, 2026
164f5f1
Unit tests of templates: C labels, local labels, %=, %n, and numbers
tautschnig Dec 1, 2026
4ff7fa4
Inline assembly: output addresses that depend on the other outputs
tautschnig Dec 1, 2026
d6a863f
Inline assembly: interpret AArch64 instructions
tautschnig Nov 16, 2026
8c9c81d
AArch64 inline assembly: interpret only register-neutral hints
tautschnig Dec 1, 2026
228bf12
AArch64 inline assembly: reject modifiers of immediate operands
tautschnig Dec 1, 2026
5c99010
AArch64 inline assembly: decide the monitor state along control flow
tautschnig Dec 1, 2026
62d7f0e
AArch64 inline assembly: dsb with an st option also orders loads
tautschnig Dec 1, 2026
d84e097
AArch64 inline assembly: abandon exclusive regions instead of failing
tautschnig Dec 1, 2026
9253e0c
AArch64 inline assembly: remove unused using-declarations
tautschnig Dec 1, 2026
7354c9a
AArch64 inline assembly: test data processing and memory accesses
tautschnig Dec 1, 2026
fd43f64
Inline assembly: share the ARM barrier semantics
tautschnig Nov 17, 2026
3c6a079
Inline assembly: interpret AArch32 instructions
tautschnig Nov 17, 2026
33b3b55
Inline assembly: AArch32 mode changes and operands in r8 to r14
tautschnig Dec 1, 2026
c34a049
Inline assembly: AArch32 Thumb-1 divided syntax with Thumb-2 forms
tautschnig Dec 1, 2026
6fb000e
Inline assembly: AArch32 movs in Thumb-1 divided syntax
tautschnig Dec 1, 2026
095128b
Inline assembly: AArch32 cache invalidation without cleaning
tautschnig Dec 1, 2026
7add8e9
Inline assembly: AArch32 width qualifiers in the statement-wide scan
tautschnig Dec 1, 2026
12c60f2
Inline assembly: AArch32 conditional exclusive loads and stores
tautschnig Dec 1, 2026
9abd360
Inline assembly: AArch32 carry out of shifts
tautschnig Dec 1, 2026
811cb9c
Inline assembly: document that the AArch32 processor mode is not modeled
tautschnig Dec 1, 2026
55cdac9
Inline assembly: test more AArch32 instructions and system operations
tautschnig Dec 1, 2026
798bcb9
AArch32 inline assembly: abandon exclusive regions instead of failing
tautschnig Dec 1, 2026
ab56911
Inline assembly: a differential test harness against hardware
tautschnig Nov 17, 2026
7217adc
asm_differential: observe the result of the struct field case
tautschnig Dec 1, 2026
6fa102e
asm_differential: check that the end of main is reachable
tautschnig Dec 1, 2026
a57346b
asm_differential: exercise the exchange of the x86 cmpxchg case
tautschnig Dec 1, 2026
4382492
asm_differential: document the limits and conventions of the harness
tautschnig Dec 1, 2026
9662787
Inline assembly: interpret AArch64 load/store pairs
tautschnig Nov 17, 2026
2fb714b
Inline assembly: interpret AArch32 loads and stores of multiple regis…
tautschnig Nov 17, 2026
d49f879
asm_differential: observe the base register of the ldp base case
tautschnig Dec 1, 2026
ba1e424
Inline assembly: regression test of AArch64 ldp, stp, ldnp, and stnp
tautschnig Dec 1, 2026
61eb308
Inline assembly: regression test of AArch32 ldm, stm, push, and pop
tautschnig Dec 1, 2026
922b3c6
AArch32 inline assembly: push and pop with changes of the processor mode
tautschnig Dec 1, 2026
76b8943
AArch32 inline assembly: push and pop abandon exclusive regions
tautschnig Dec 1, 2026
2a0729f
Inline assembly: replace restartable LL/SC retry loops by their last …
tautschnig Nov 17, 2026
77aa0e9
Inline assembly: test retry loops that must remain loops
tautschnig Dec 1, 2026
4c1a8c7
Inline assembly: document which retry branches are replaced
tautschnig Dec 1, 2026
2aeee22
Inline assembly: ignore instruction temporaries in retry loops
tautschnig Dec 1, 2026
7790119
Inline assembly: retry loops in the check of GCC's operand contract
tautschnig Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/architectural/front-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ you can access it <a href=
"https://svn.cprover.org/wiki/doku.php?id=cprover_tutorial">here</a>.

* \subpage memory-bounds-checking
* \subpage inline-assembly
* \subpage satabs

## For contributors:
Expand Down
239 changes: 239 additions & 0 deletions doc/architectural/inline-assembly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
\ingroup module_hidden

\page inline-assembly Inline Assembly

This page describes how `remove_asm` (`src/assembler/`) gives meaning to
inline assembly, and how to extend the instruction semantics. The user-level
description is `doc/cprover-manual/modeling-inline-asm.md`.

## Overview

`remove_asm` replaces every inline assembly statement by goto-program
instructions. Every tool runs it before linking the CPROVER library. For a
GCC-style statement (`code_asm_gcct`), it tries, in this order:

1. the instruction semantics of the configured architecture
(`config.ansi_c.arch`, see `make_asm_semantics`), if there are any: the
statement is *interpreted*;
2. the architecture-independent translation of fences, the x87 control word,
and no-ops (`handle_gcc_command` in `remove_asm.cpp`);
3. the conservative approximation (`asm_approximationt`), with a warning.

MSVC-style blocks use steps 2 and 3 only.

## Interpretation

The interpretation of a statement has these parts:

- `asm_operandst` (`asm_operands.h`) parses the constraints of the operands
and classifies each operand as a register, memory, immediate, or flag
output operand. Register inputs that are arrays decay to pointers. The
symbolic names used in `%[name]` references are kept by the C front end in
`ID_identifier`.
- `split_asm_template` (`asm_template.h`) splits the template into
instructions, and resolves `%N`, `%[name]`, `%lN`, and local label
references. It reads numbers as GAS does: `0x` is hexadecimal, `0b`
binary (unless it refers to the local label 0), and a leading `0` octal.
The modifiers of operand references are left to the semantics, which fail
on modifiers they do not understand (on x86, `%c`, `%P`, and `%n`, which
negates, are the modifiers of immediates).
- `asm_lowering_contextt` (`asm_semantics.h`) holds the goto code being
built: the storage of register operands, hardware registers, and flags (all
block-local temporaries), labels, and helpers to read and write registers
and memory, branch, and fence.
- `asm_semanticst` is the interface of the per-architecture semantics;
`asm_x86.cpp` implements x86 (i386, x86-64, x32), `asm_aarch64.cpp`
implements AArch64, `asm_arm.cpp` implements AArch32; `asm_arm_flags.h`
has the ARM condition flags and barriers. Semantics that depend on the
statement as a whole create an `asm_semantics_statet` (`make_state`), which
`lower` reads from `asm_lowering_contextt::semantics_state`.

The code of a statement consists of a prologue that evaluates the inputs, the
code of the instructions, and an epilogue that assigns the register outputs.
Memory operands are accessed in place. For an operand whose constraint
allows both a register and memory (`asm_operandt::may_be_memory`, as for
`"rm"` and `"g"`), GCC may choose either, and the instructions may have a
different effect: `remove_asmt::lower_gcc` lowers every combination of
choices (`asm_operandst::memory_alternative`; an rvalue input in memory is
a temporary object) and chooses one nondeterministically. Constraints with
several alternatives are not interpreted. Where an operand may also be an
immediate (`asm_operandt::may_be_immediate`), the semantics must fail on
uses whose effect would differ for an immediate.
The bits of a register above the
width of the input operand it holds are unspecified. `prepare` determines
whether they may be read: by a reference to the operand or to another operand
that shares the register (an output the input is tied to, or an operand bound
to the same register by its constraint), see
`asm_semanticst::reference_bits`; by the name of the register
(`register_name_bits`); by an instruction that reads the register without
naming it (`implicit_reads`); or as part of an output that shares the
register. If so, the upper bits are nondeterministic; otherwise the input is
zero-extended. Zero-extension keeps a constant input constant, which symbolic
execution relies on: otherwise, for example, a spin lock on a lock word that
is written through such an operand would make the lock word symbolic, and the
spin loops would be unwound to the unwinding bound.

The code of the instructions has the checks for undefined behaviour of C
disabled (via pragmas on its source location), as it models hardware
operations whose results are defined. The prologue additionally evaluates the
inputs at the plain source location of the statement, so that the checks
apply to the C expressions of the operands.

The following rules keep the interpretation sound. A statement that violates
one of them is not interpreted:

- The template must be in the dialect that the semantics read (AT&T on
x86). `goto-cc` sets `config.ansi_c.asm_dialect` from `-masm`, and the C
front end (`c_typecheck_baset::typecheck_asm`) records it on each
GCC-style statement as `ID_asm_dialect`, so that it survives into goto
binaries; `remove_asmt::lower_gcc` does not interpret statements in
another dialect, and `lower_instructions` does not interpret templates
that switch to Intel syntax with `.intel_syntax`.
- Every instruction, prefix, operand form, and directive must be understood.
- Instructions in another section (`.pushsection`/`.section`) are not
executed in sequence; they may be executed when another instruction faults
(exception fixups). Data in another section that refers to a label of the
statement, or to a C label of `asm goto`, records the label for run-time
patching (the Linux kernel's jump tables, `__jump_table`, by which a `jmp`
becomes a `nop` or vice versa) or as the continuation of a fault (exception
tables, `__ex_table`): the statement may then jump where its instructions
do not show. Such references are allowed only in `.smp_locks`, which
records lock prefixes that the kernel replaces by a no-op prefix on a
single processor, and in the sections that the linker discards
(`.discard.*`). Other data in other sections is ignored. This check is in
`remove_asmt::lower_instructions` and applies to all architectures.
- A write to a hardware register that is neither bound to an operand by its
constraint nor clobbered may be a write to a register variable
(`register long x asm("rax")`), which the front end does not record.
- A memory access must not use an address that may depend on a value that
is not modeled: a hardware register that the statement does not
initialise (which may hold a register variable), a nondeterministic value
(such as a system register, or `rdtsc`), an output operand read before it
is written, or memory that such a value was stored to. CBMC cannot relate
such an address to the objects it may point to, so the access would change
no object. `asm_lowering_contextt::depends_on_unknown` tracks these values
per position: an unconditional assignment of a known value makes its
target known; a label joins the states of the fall-through and of the
forward branches to it; a backward branch must not make a value unknown
that its target took as known.
- An input tied to a memory output must be the same object.
- The base of the x86 segments `%fs` and `%gs` is not modeled: a
segment-relative store may change a C object, unless it is not at a memory
operand and the statement has neither a `"memory"` clobber nor a memory
output (GCC's operand contract then excludes it).
- GCC's operand contract must hold, as the operand storage does not model
registers that GCC gives to several operands
(`asm_lowering_contextt::check_operand_contract`): no instruction may
write an input-only register operand (GCC assumes it unchanged, and may
hold two inputs of the same value in one register), and no instruction
may read a register input or the address of a memory operand after an
instruction (in sequence, or in an earlier iteration of a loop formed by
a backward branch) wrote an output without the earlyclobber modifier `&`,
as GCC may allocate that output to the same register. An output that
holds its own value when the statement starts (`+`, or tied to an input)
shares a register only with an operand that GCC knows to have the same
value, which its register allocator only knows for operands of the same
machine mode; so for such an output, only operands of its width (or of
the width of an input tied to it) are considered. These checks are
independent of the architecture.

An instruction that is atomic on the hardware (on x86: lock-prefixed
instructions and `xchg` with a memory operand) is an atomic section of its
own, with a full fence; see `asm_lowering_contextt::mark_atomic`. Making the
whole statement atomic would hide races on the statement's other
instructions.

A load-exclusive followed by a store-exclusive is an atomic section from the
load to the store (`asm_lowering_contextt::begin_exclusive`, `end_exclusive`)
if there is no other memory access, branch, or label in between. Such an
access, branch, or label abandons the region
(`asm_lowering_contextt::abandon_exclusive`): the load-exclusive is then a
plain load, and a later store-exclusive is not atomic with it. Without the
atomic section the model admits more interleavings, so this is sound. The
store-exclusive succeeds nondeterministically: the architecture permits
spurious failures, and a store-exclusive without a load-exclusive in the same
statement may succeed if a load-exclusive executed before. After `clrex` or a
store-exclusive, a store-exclusive fails, unless a label or a load-exclusive
comes in between: the monitor state is decided along the control flow, and a
branch to the label may skip the instruction that cleared the monitor
(`asm_lowering_contextt::define_label` forgets that the monitor is cleared). A
store-exclusive records itself
(`asm_lowering_contextt::record_store_exclusive`), and the semantics lower
conditional branches with `retry_branch`: a backward branch that is taken only
if the recorded store failed (checked by substituting the code after the store
into the condition and simplifying it with the store succeeding), and whose
loop is restartable (`restartable`), becomes the assumption that it is not
taken. `restartable` ignores the temporaries that the semantics create with
`asm_lowering_contextt::instruction_temporary`, which only the instruction
that writes them reads: a conditional instruction (such as `moveq`) writes
them only when it executes, but they carry no value from one attempt to the
next.

AArch32 needs two statement-wide properties (`make_a32_state` in
`asm_arm.cpp`). In divided syntax, which GCC uses for inline assembly in A32
code and for Thumb-1 targets, the Thumb-1 data-processing instructions set
the flags without an `s` suffix (`add r0, r1, #1` is `adds`), depending on
their registers. Unless the statement starts with `.syntax unified` or uses
an instruction or form that GNU as does not accept in divided syntax for
Thumb-1 targets (conditional execution other than of branches, `it`, `s`
suffixes other than `movs`, the width qualifiers `.n` and `.w`, `teq`,
`clz`, ...), the flags are nondeterministic after such an instruction;
`movw`, `movt`, `cbz`, `cbnz`,
and the exclusive loads and stores are no such evidence, as ARMv8-M Baseline
has them. An explicit `.syntax divided` anywhere in the statement selects
these forms in Thumb-2 code too, where the assembler also accepts the other
instructions, so the flags are then nondeterministic in any case. In such
code, `movs` between low registers is `adds` with `#0`, which clears C and V,
so the flags are nondeterministic after `movs` as well.

And `msr` of the control field may change the processor mode, which banks r8
to r14. A statement that does so is not interpreted if it names any of these
registers, if it uses `push` or `pop`, which address the stack through the
banked `sp`, or if it uses an operand, which the compiler may allocate to one
of them, after the first such `msr`. Operands may be used before it, and as
its source, unless a label precedes it, to which a later branch could return.
The mode itself is not modeled, so that a statement that leaves the processor
in another mode (`msr cpsr_c, #0x1f`, say) is interpreted as if the mode were
unchanged: the C code after it, which uses the banked `sp` and `lr` of the new
mode, and the output operands, which the compiler may read from banked
registers, are modeled as in the original mode.
An `it` instruction has no effect: the instructions of the IT block carry
their conditions as suffixes, which the assemblers check against it.
A conditional store-exclusive may not execute, so it does not clear the
exclusive monitor. As the exclusive access region and the monitor are
tracked while lowering, not on the paths that execute the instructions, a
statement with a conditional load-exclusive, or with a conditional
store-exclusive and another store-exclusive, is not interpreted (a
conditional load-exclusive would open the region on both paths, and a
conditional store-exclusive ends it on both).
`push` and `pop` use a stack in the statement's state (`a32_statet::stack`)
rather than memory, and do not change `sp`. `make_a32_state` checks that they
are balanced in straight-line code and that `sp` is not used while registers
are pushed, and `lower` fails on memory operands while registers are pushed,
as the compiler may address them relative to `sp`.

For `asm goto`, goto conversion creates a variable that selects the label to
jump to (`code_asm_gcct::goto_target`) and dispatches on it after the
statement; the interpretation assigns it the index of the label that the
instructions jump to, or 0.

## Adding instructions or an architecture

To add an instruction, extend `lower` of the architecture's
`asm_semanticst`. Return false (via `asm_lowering_contextt::fail`, with a
reason) for any form that is not modeled exactly: the statement is then
approximated, which is always sound. Model values that the architecture
leaves undefined as nondeterministic, not as what one implementation does.

To add an architecture, implement `asm_semanticst` (syntax, register width,
canonical register names, constraint letters, flag conditions, and `lower`)
and return it from `make_asm_semantics`.

Tests that rely on the interpretation must pin the architecture with
`--arch`, as the default is the host architecture. Tests of the
architecture-independent translation and of the approximation use
`--arch riscv64`, which has no instruction semantics and for which CBMC
passes no `-m` option to the host preprocessor. The x86 tests use
preprocessed input (`main.i`), as preprocessing with `-m64` or `-m32` fails
on non-x86 hosts. Expected values of tests of instruction semantics should be
observed on hardware.
1 change: 1 addition & 0 deletions doc/cprover-manual/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [Floating Point](modeling/floating-point/)
* [Generating Environments](goto-harness/)
* [Memory-mapped I/O](modeling/mmio/)
* [Inline Assembly](modeling/inline-asm/)
* [Shadow Memory](modeling/shadow-memory/)

8. Build Systems
Expand Down
Loading
Loading