Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
65 changes: 65 additions & 0 deletions .claude/board/EPIPHANIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,71 @@
> `**Status:**`/`**Confidence:**` line. A correction gets its own new,
> dated entry that references the one it corrects — the storno rule.

## 2026-08-25 — E-LGJ-GHIDRAS-SEAM-IS-AN-INTERFACE-AND-ITS-VOCABULARY-CANNOT-FLATTEN-1

**Status:** MEASURED — R12 + the Ghidra source trace. No code swapped yet.
**Confidence:** High on both halves; each is a citation or a VM-reported number.

Starting the `r2il-machine-semantic-contract-v1` arc from the GHIDRA end
while a sibling session drives W0-W4. Two findings, and they point the
same way.

**1. The seam is an interface, and no core fork is required.** Traced:

```
Language (INTERFACE, model/lang/Language.java:29)
.parse(MemBuffer, ProcessorContext, boolean)
-> InstructionPrototype (INTERFACE, :35)
.getPcode(context, override) -> PcodeOp[]
```

`InstructionDB.getPcode()` (`:608-628`) does nothing but delegate to
`proto.getPcode(...)`. `InstructionPrototype` has exactly TWO
implementations — `SleighInstructionPrototype` and `InvalidPrototype` —
and `SleighLanguage` constructs the former at exactly ONE site
(`SleighLanguage.java:392`). `Instruction` is itself an interface with an
`InstructionStub` already in tree, so alternative implementations are an
established pattern rather than a hack.

This was an OPEN UNKNOWN that had been flagged twice this session and
never checked; it gates the whole Java half, and the answer is favourable.

**2. Ghidra's P-code vocabulary cannot be carried as value classes — its
identity can.** R12, field shapes transcribed from
`Varnode.java:51-54` / `PcodeOp.java:102-105`, run on the JEP 401 EA build
with the VM reporting element sizes:

| shape | flat? |
|---|---|
| `VarnodePayload(int,int,long)` 16 B | **no** |
| `PcodeOpPayload(int,long)` 12 B | **no** |
| `VarnodeRef` / `PcodeOpRef` / `InstructionRef` (`long`) | **yes**, element size 8 |

And those Payload rows are the OPTIMISTIC bound — every reference deleted.
The real `Varnode` holds an `Address`; the real `PcodeOp` holds a
`SequenceNumber`, a `Varnode[]` and a `Varnode`, so **a 2-input `PcodeOp`
is five heap objects**. That is "ONE ROW IS NOT ONE JAVA OBJECT" at its
worst: one instruction becomes a small object graph.

**Why this needs nothing new.** The verdict — *address the vocabulary,
don't carry it* — is the same result `LaneId`/`Ordinal`/`MaskId` already
rely on, and the same reason `RowRange` (16 B) does not flatten. The
existing descriptor discipline answers W5's central question before W5
starts.

**The unanticipated part, recorded so it is not lost.** `VarnodeNarrow`
(`spaceId:u8`, `size:u8`, 48-bit offset) ALSO flattens. So 8 bytes is
enough to carry a varnode's real CONTENT, not merely a pointer to it — a
content-bearing descriptor that reads space and size without a lane
round-trip. Bounded by exactly one condition: a 48-bit offset. Whether
that suffices is a W0/W1 address-space question, not a Valhalla one.
**Named as an option, NOT proposed as the design** — pre-empting W1's
tenant carving from this side is precisely what the plan's R1 rule
("no private object graph then serialize") forbids one layer up.

Cross-ref: `.claude/plans/r2il-machine-semantic-contract-v1.md` §2 (the
facade-not-data-model correction) and §6 W5, both in lance-graph.

## 2026-08-25 — E-LGJ-A-CONSTANT-COPIED-THREE-TIMES-HAS-NO-FALSIFIER-1

**Status:** SHIPPED — ABI minor 8, docs/abi.md §17.
Expand Down
23 changes: 23 additions & 0 deletions .claude/board/LATEST_STATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
## 2026-08-25 — the Ghidra end of the R2IL arc: seam verified, vocabulary measured

Working the `r2il-machine-semantic-contract-v1` plan (lance-graph, PR #1027,
merged) from the GHIDRA side while a sibling session drives W0-W4.

- **The seam is an interface.** `Language.parse` -> `InstructionPrototype`
-> `getPcode()`, both interfaces, `InstructionPrototype` with exactly two
implementations and ONE construction site
(`SleighLanguage.java:392`). **No Ghidra core fork required** — this was
an open unknown gating the whole Java half.
- **R12** (`valhalla-lab/reproducers/`): Ghidra's P-code payloads do NOT
flatten even at their optimistic lower bound (16 B / 12 B, references
deleted); ordinals do, at VM element size 8. A real 2-input `PcodeOp` is
**five heap objects**. Verdict: the W5 facade ADDRESSES the vocabulary
rather than carrying it — which needs nothing new, it is what
`LaneId`/`Ordinal`/`MaskId` already do.
- **Unanticipated:** an 8-byte `VarnodeNarrow` (u8 space, u8 size, 48-bit
offset) also flattens — so a content-bearing descriptor is possible, not
only a pointer. Recorded as an option for W1, deliberately not proposed
as the design.
- Nothing swapped, nothing minted, no layout touched. Measurement + trace
only.

## 2026-08-25 — ABI minor 8: the register groupings are DATA, and the load gate stopped requiring the whole manifest

- **The wire encoding of §14's `carving` is no longer written anywhere by
Expand Down
49 changes: 49 additions & 0 deletions valhalla-lab/reproducers/R12-observed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
R12 — Ghidra's P-code vocabulary against the 8-byte array-flattening cliff
JDK: Picked up JAVA_TOOL_OPTIONS: -Djavax.net.ssl.trustStore=/root/.ccr/java-truststore.p12 -Djavax.net.ssl.trustStorePassword=changeit -Djavax.net.ssl.trustStoreType=PKCS12 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=35207 -Dhttp.nonProxyHosts=localhost|127.0.0.1|::1|127.*|0.*|::|169.254.*|api.anthropic.com|api-staging.anthropic.com|api-pr-preview.anthropic.com|mcp-proxy.anthropic.com|mcp-proxy-staging.anthropic.com|registry.npmjs.org|jsr.io|npm.jsr.io|pypi.org|files.pythonhosted.org|index.crates.io|proxy.golang.org|host.docker.internal|10.*|172.16.*|172.17.*|172.18.*|172.19.*|172.20.*|172.21.*|172.22.*|172.23.*|172.24.*|172.25.*|172.26.*|172.27.*|172.28.*|172.29.*|172.30.*|172.31.*|192.168.*|100.64.0.0/10|*.svc.cluster.local|*.svc.cluster.local -Djdk.http.auth.tunneling.disabledSchemes= -Djdk.http.auth.proxying.disabledSchemes=
VM element sizes shown via -XX:+PrintFlatArrayLayout.

R12 ? Ghidra's P-code vocabulary against the 8-byte array-flattening cliff

shape nonAtomic atomic transcribed from
-------------------------------- --------- ------- ------------------------------
VarnodePayload(int,int,long) false false Varnode.java:51-54, refs deleted
PcodeOpPayload(int,long) false false PcodeOp.java:102-105, refs deleted
Flat Type Array: [LR12_GhidraPcodeVocabularyVsCliff$VarnodeNarrow; {0x000000002d042d20}
- element klass: 'R12_GhidraPcodeVocabularyVsCliff$VarnodeNarrow'
- layout kind: NULL_FREE_ATOMIC_FLAT
- array properties: NULL_RESTRICTED ATOMIC
- element size 8 aligned layout size 8
VarnodeNarrow(8B packed) true true narrowed content
Flat Type Array: [LR12_GhidraPcodeVocabularyVsCliff$VarnodeRef; {0x000000002d0433b0}
- element klass: 'R12_GhidraPcodeVocabularyVsCliff$VarnodeRef'
- layout kind: NULL_FREE_NON_ATOMIC_FLAT
- array properties: NULL_RESTRICTED NON_ATOMIC
- element size 8 aligned layout size 8
VarnodeRef(long) true true ordinal into a lane
Flat Type Array: [LR12_GhidraPcodeVocabularyVsCliff$PcodeOpRef; {0x000000002d043a40}
- element klass: 'R12_GhidraPcodeVocabularyVsCliff$PcodeOpRef'
- layout kind: NULL_FREE_NON_ATOMIC_FLAT
- array properties: NULL_RESTRICTED NON_ATOMIC
- element size 8 aligned layout size 8
PcodeOpRef(long) true true ordinal into a lane
Flat Type Array: [LR12_GhidraPcodeVocabularyVsCliff$InstructionRef; {0x000000002d044230}
- element klass: 'R12_GhidraPcodeVocabularyVsCliff$InstructionRef'
- layout kind: NULL_FREE_NON_ATOMIC_FLAT
- array properties: NULL_RESTRICTED NON_ATOMIC
- element size 8 aligned layout size 8
InstructionRef(long) true true ordinal into a lane

Reading the table:
* The two *Payload rows are the OPTIMISTIC lower bound for Ghidra's real
types ? every reference deleted. The real Varnode additionally holds an
Address, and the real PcodeOp a SequenceNumber, a Varnode[] and a Varnode.
* A 2-input PcodeOp is therefore FIVE heap objects: the op, its
SequenceNumber, the input array, and one Varnode per operand.

refs flat: 3/3 payloads flat: 0/2

VERDICT: the facade must ADDRESS the vocabulary, not CARRY it.
Ordinals flatten; Ghidra's payloads do not, even at their lower bound.
This is the same result LaneId/Ordinal/MaskId already rely on, and the
same reason RowRange (16 B) does not flatten. Nothing new is needed ?
the existing descriptor discipline already answers it.
120 changes: 120 additions & 0 deletions valhalla-lab/reproducers/R12_GhidraPcodeVocabularyVsCliff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Reproducer R12 — can Ghidra's P-code vocabulary cross the Panama membrane as Valhalla
// value classes, or must the facade address it instead of carrying it?
//
// Motivation: the r2il-machine-semantic-contract-v1 plan's W5 puts a lance-graph-java facade
// under Ghidra — `PcodeOp`/`Instruction`/`Varnode` as lazy views over handles + masks, with
// `getPcode()` paying materialization ONLY when called. Before designing that facade, one
// question decides its whole shape: are Ghidra's own P-code types flattenable?
//
// The field shapes below are TRANSCRIBED from Ghidra at the paths cited, not invented:
//
// Varnode (program/model/pcode/Varnode.java:51-54)
// private Address address; // a REFERENCE
// private int size;
// private int spaceID;
// private long offset;
//
// PcodeOp (program/model/pcode/PcodeOp.java:102-105)
// private int opcode;
// private SequenceNumber seqnum; // a REFERENCE
// private Varnode[] input; // a REFERENCE to an array of REFERENCES
// private Varnode output; // a REFERENCE
//
// R2 measured the cliff at an 8-byte payload; R4 added the finding that a reference-holding
// composition can REPORT flat while storing its components as references (`Four8AsTwo8`, 32 B,
// VM element size 8). Both traps are live here, so both are measured rather than assumed.
//
// javac --enable-preview -source 27 -target 27 \
// --add-exports java.base/jdk.internal.value=ALL-UNNAMED -d out \
// R12_GhidraPcodeVocabularyVsCliff.java
// java --enable-preview --add-exports java.base/jdk.internal.value=ALL-UNNAMED \
// -cp out R12_GhidraPcodeVocabularyVsCliff
// Add -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlatArrayLayout for the VM's own element sizes.
import jdk.internal.value.ValueClass;

public class R12_GhidraPcodeVocabularyVsCliff {

// ── A: Ghidra's shapes as-is, minus the references it is not legal to model here ──
// `Address` and `SequenceNumber` are identity classes; a value record cannot hold one
// without giving up flatness by construction. So these are the OPTIMISTIC lower bounds:
// the payload with every reference DELETED. If even these do not flatten, the real types
// certainly cannot.
static value record VarnodePayload(int size, int spaceID, long offset) {} // 16 B
static value record PcodeOpPayload(int opcode, long seq) {} // 12 B

// ── B: the same identity spelled as an ORDINAL into a lane ──
// The mask-native reading: a varnode's identity is WHERE it is, not what it contains.
static value record VarnodeRef(long ordinal) {} // 8 B
static value record PcodeOpRef(long ordinal) {} // 8 B
static value record InstructionRef(long ordinal) {} // 8 B

// ── C: the narrowed-content middle ground, to find where the line actually falls ──
// Is 8 B enough to carry the varnode's real content rather than a pointer to it?
// spaceID as u8, size as u8, offset as 48 bits.
static value record VarnodeNarrow(byte spaceId, byte size, short offHi, int offLo) {} // 8 B

record Case(String name, Class<?> type, Object init, String cited) {}

public static void main(String[] args) {
Case[] cases = {
new Case("VarnodePayload(int,int,long)", VarnodePayload.class,
new VarnodePayload(0, 0, 0L), "Varnode.java:51-54, refs deleted"),
new Case("PcodeOpPayload(int,long)", PcodeOpPayload.class,
new PcodeOpPayload(0, 0L), "PcodeOp.java:102-105, refs deleted"),
new Case("VarnodeNarrow(8B packed)", VarnodeNarrow.class,
new VarnodeNarrow((byte) 0, (byte) 0, (short) 0, 0), "narrowed content"),
new Case("VarnodeRef(long)", VarnodeRef.class,
new VarnodeRef(0L), "ordinal into a lane"),
new Case("PcodeOpRef(long)", PcodeOpRef.class,
new PcodeOpRef(0L), "ordinal into a lane"),
new Case("InstructionRef(long)", InstructionRef.class,
new InstructionRef(0L), "ordinal into a lane"),
};

System.out.println("R12 — Ghidra's P-code vocabulary against the 8-byte array-flattening cliff");
System.out.println();
System.out.printf("%-32s %-9s %-7s %s%n", "shape", "nonAtomic", "atomic", "transcribed from");
System.out.printf("%-32s %-9s %-7s %s%n", "-".repeat(32), "-".repeat(9), "-".repeat(7), "-".repeat(30));

int flatRefs = 0;
int flatPayloads = 0;
for (Case c : cases) {
boolean nonAtomic = ValueClass.isFlatArray(
ValueClass.newNullRestrictedNonAtomicArray(c.type(), 16, c.init()));
boolean atomic = ValueClass.isFlatArray(
ValueClass.newNullRestrictedAtomicArray(c.type(), 16, c.init()));
System.out.printf("%-32s %-9s %-7s %s%n", c.name(), nonAtomic, atomic, c.cited());
if (c.name().endsWith("Ref(long)") && nonAtomic) {
flatRefs++;
}
if (c.name().startsWith("VarnodePayload") || c.name().startsWith("PcodeOpPayload")) {
if (nonAtomic) {
flatPayloads++;
}
}
}

System.out.println();
System.out.println("Reading the table:");
System.out.println(" * The two *Payload rows are the OPTIMISTIC lower bound for Ghidra's real");
System.out.println(" types — every reference deleted. The real Varnode additionally holds an");
System.out.println(" Address, and the real PcodeOp a SequenceNumber, a Varnode[] and a Varnode.");
System.out.println(" * A 2-input PcodeOp is therefore FIVE heap objects: the op, its");
System.out.println(" SequenceNumber, the input array, and one Varnode per operand.");
System.out.println();
System.out.printf(" refs flat: %d/3 payloads flat: %d/2%n", flatRefs, flatPayloads);

if (flatRefs == 3 && flatPayloads == 0) {
System.out.println();
System.out.println(" VERDICT: the facade must ADDRESS the vocabulary, not CARRY it.");
System.out.println(" Ordinals flatten; Ghidra's payloads do not, even at their lower bound.");
System.out.println(" This is the same result LaneId/Ordinal/MaskId already rely on, and the");
System.out.println(" same reason RowRange (16 B) does not flatten. Nothing new is needed —");
System.out.println(" the existing descriptor discipline already answers it.");
} else {
System.out.println();
System.out.println(" UNEXPECTED: re-measure before designing the facade. The cliff did not");
System.out.println(" fall where R2/R4 measured it, so those findings need re-checking first.");
}
}
}
47 changes: 47 additions & 0 deletions valhalla-lab/reproducers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,50 @@ layout was already data at every boundary except the store's constructor.**
**Honest scope:** a whole-row consumer inverts the preference — AoS is contiguous for "all
32 facets of one row", SoA scattered. The schema is a per-workload choice, which is exactly
why it belongs in data rather than in code.

## R12 — Ghidra's P-code vocabulary against the cliff

**Question.** The `r2il-machine-semantic-contract-v1` plan's W5 puts a
lance-graph-java facade under Ghidra: `PcodeOp` / `Instruction` / `Varnode`
as lazy views over handles + masks. Before designing it, one measurement
decides its whole shape — are Ghidra's own P-code types flattenable?

**Method.** Field shapes TRANSCRIBED from Ghidra at cited paths, not
invented (`Varnode.java:51-54`, `PcodeOp.java:102-105`), then run through
R2/R4's harness on the JEP 401 EA build with `-XX:+PrintFlatArrayLayout`
so the VM reports its own element sizes rather than the program asserting
them.

**Measured.**

| shape | nonAtomic | atomic | VM element size |
|---|---|---|---|
| `VarnodePayload(int,int,long)` — 16 B | false | false | — |
| `PcodeOpPayload(int,long)` — 12 B | false | false | — |
| `VarnodeNarrow` — 8 B packed content | **true** | **true** | 8 (`NULL_FREE_ATOMIC_FLAT`) |
| `VarnodeRef(long)` | **true** | **true** | 8 (`NULL_FREE_NON_ATOMIC_FLAT`) |
| `PcodeOpRef(long)` | **true** | **true** | 8 |
| `InstructionRef(long)` | **true** | **true** | 8 |

The two `*Payload` rows are the **optimistic lower bound** for Ghidra's
real types — every reference deleted. The real `Varnode` additionally holds
an `Address`; the real `PcodeOp` holds a `SequenceNumber`, a `Varnode[]`
and a `Varnode`, so **a 2-input `PcodeOp` is five heap objects**.

**Verdict: the facade must ADDRESS the vocabulary, not CARRY it** — which
needs nothing new. It is the same result `LaneId` / `Ordinal` / `MaskId`
already rely on, and the same reason `RowRange` (16 B) does not flatten.

**The finding the plan did not anticipate.** `VarnodeNarrow` — `spaceId:u8`,
`size:u8`, 48-bit offset — **also flattens**. So 8 bytes is enough to carry
a varnode's real CONTENT, not merely a pointer to it. That is a live design
option for W5 (a content-bearing descriptor, no lane round-trip to read a
varnode's space or size) and it is bounded by exactly one condition: a
48-bit offset. Whether that suffices is a W0/W1 question about the address
space, not a Valhalla one — recorded here so the option is not lost, NOT
proposed as the design.

Note the layout kinds differ: the single-`long` refs are `NON_ATOMIC_FLAT`,
the multi-field `VarnodeNarrow` is `ATOMIC_FLAT`. Both flatten at element
size 8; only the tearing guarantee differs.