Repository navigation
Prerequisite: harden raw assembly diagnostics and constant-time validation (#28447) #29269
Replies: 6 comments 1 reply
|
Scope correction: all implementation work from this point is V3-only. The diagnostics, label/operand validation, register-pressure checks, target gates, and constant-time floor belong in the V3 compiler/toolchain. V1 raw-assembly work is reference material only and is not a target for this plan. |
|
Scoping the rest of this before writing more code, because items 1-4 and 6 add user-visible checker diagnostics. Measured on master Done. Item 5 for Not done, and what the checker does today.
Proposal: small PRs in this order, each one a checker diagnostic plus fixtures.
Each PR would be checked the same way: no new diagnostics on the in-tree raw fixtures, a mutation test that must fire (drop a clobber, change a width suffix, duplicate a label), and gcc/clang as the oracle for the width diagnostics. Questions for the maintainers.
I can start with step 1 once the direction is agreed. |
|
PR 0 of the plan above is up: #31044 adds the shared raw-template decoder/tokenizer (string-literal decoding with a per-byte source-offset map, statement splitting, operand classification) with no diagnostics yet. Every raw-template helper in |
Implementation planMeasured on master PR 0 — shared raw-template decoder and tokenizer (open: #31044)Problem. Every text helper in Deliverable (
Known gaps deferred to the PRs that need them: x86 PR 1 — label hygiene (item 4), warningRule: in a raw block inside a function body, a label definition Definitions only — references to external symbols ( PR 2 — operand width vs mnemonic for raw AT&T (item 2), errorFor an AT&T mnemonic with an explicit size suffix (
The Intel width driver keys on Intel operand order, so AT&T is not fed through it; the pure PR 3 — clobber completeness (item 1), error for proven cases onlyPer-instruction PR 4 — register-pressure feasibility (item 3), error for the decidable subsetCount per class (GPR, XMM/YMM/ZMM, k-mask): fixed-register constraints ( PR 5 — constant-time floor (item 6): design firstNot a code PR yet. A short design proposal, here or linked from here: an opt-in attribute Open points before PR 1
|
|
PR 1 (item 4, label hygiene) is up: #31167. It adds a warning for a label defined in a raw template inside a function without |
|
PR 2 is open: #31198. It adds the AT&T size-suffix width check for x86 raw templates. A suffix such as Not checked yet: Intel-syntax raw blocks, arm64, and numeric |
Uh oh!
There was an error while loading. Please reload this page.
Follow-up to #28447. This is a prerequisite for #28457.
Goal
Make raw assembly exacting but caught: every supported transcription error
should become a V compiler diagnostic at the correct source line, rather than
silent corruption or an opaque C-toolchain failure. Users still write real
assembly; the compiler supplies the safety and diagnostic boundary around it.
This work should land before converting production crypto primitives or using
OpenSSL 4.0.2 as the performance target.
Required diagnostics and checks
Clobber completeness
Analyze the instructions in a raw template and detect registers and flags
written by the template but absent from the clobber list. Cover GPRs, XMM,
YMM, ZMM, condition codes, and memory effects where the instruction table
can prove them. Use a conservative diagnostic when the analyzer cannot
determine the effect. The primary target is preventing
-prodmiscompiles.Operand width versus mnemonic
Generalize the width validation from checker: reject narrow hard registers next to named intel asm operands (fix #28364) #28369 to raw templates. Check typed
operands, explicit register names, operand modifiers, and mnemonic width
together. Cases such as a
movlusing an operand bound from au64mustproduce a V diagnostic with the template and source location.
Register-pressure feasibility
Model usable register classes after fixed registers, inputs, outputs, and
clobbers are accounted for. Report impossible constraints such as a block
requiring more GPRs or vector registers than the target ABI can provide,
before invoking the C compiler. Include Win64 nonvolatile registers and
target-specific reserved registers in the model.
Label hygiene
Detect numeric or named labels and references in reusable raw templates.
Warn or error when a label does not use GNU
%=uniqueness, or when adocumented local-label convention is not followed. The diagnostic must
explain why inlining or multiple instantiations can collide.
Target-capability gates
When GNU raw assembly is selected under
-cc msvc, emit a direct V errorat the assembly block: MSVC x64 does not support this form; use the external
.S, MASM.asm, or prebuilt.objpath instead. Do not defer this to anundeclared symbol, impossible constraint, or C-toolchain error.
Constant-time floor
Define an opt-in way to mark a crypto kernel as constant-time and decide
which checks can be enforced statically. At minimum, reject or flag
data-dependent branches and data-dependent memory addressing in the
supported instruction subset. For instructions or templates outside that
subset, provide a blessed constant-time test harness and require an
explicit review annotation rather than implying that assembly is safe.
Implementation tasks
structured assembly validation.
checking so diagnostics identify the V statement and template line.
modifiers, and target-specific syntax. Unknown effects must not silently
pass as verified.
-prod.intentional skips.
wrong widths, duplicated labels, and impossible constraints.
the constant-time review/test process.
Acceptance criteria
correct source location and an actionable remediation.
-prodacrosssupported compilers.
repeatable blessed harness and review requirement.
.S, MASM.asm, or prebuilt.objintegration behavior.
Non-goals
All reactions