Skip to content

[AUTOMATED] AArch64: print MTE tag instructions and barriers as ACLE intrinsics (option acleintrinsics) - #1672

Merged
mahaloz merged 11 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/aarch64-mte-acle
Nov 19, 2026
Merged

mahaloz merged 11 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/aarch64-mte-acle

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

On AArch64 the memory-tagging instructions lose their tag effect, so a function that tags a pointer decompiles as returning its argument, and barriers and hints print under their SLEIGH instruction names instead of the ACLE intrinsics the source called.

cat > acle.c <<'EOF'
#include <arm_acle.h>
void barrier(volatile int *p) { *p = 1; __dmb(11); __dsb(15); __isb(15); }
void idle(void) { __wfi(); __yield(); }
void *tag(void *p) { return __arm_mte_create_random_tag(p, 0); }
void settag(void *p) { __arm_mte_set_tag(p); }
EOF
clang --target=aarch64-linux-gnu -march=armv8.5-a+memtag -O2 -ffreestanding -c acle.c -o acle.o
ld.lld -shared -o acle.elf acle.o
kuna decompile-all acle.elf
void barrier(unsigned int *a0)
{
  *a0 = 1;
  DataMemoryBarrier(2,3);
  DataSynchronizationBarrier(3,3,0);
  InstructionSynchronizationBarrier();
}
unsigned long tag(unsigned long a0)
{
  return a0;              // irg x0, x0
}
void settag(void)         // stg x0, [x0]
{
  return;
}

With this change the same command prints __dmb(11); __dsb(15); __isb(15);, __wfi(); __yield();, return __arm_mte_create_random_tag(a0,0); and __arm_mte_set_tag(a0);.

The change

  • New option acleintrinsics (on|off, default on, AArch64 only). off gives the output above, byte for byte.
  • On sets the ShowMemTag context to 1 before a function is lifted. Only the memory-tagging constructors read that context, so it needs no ELF note or segment check: code without irg/stg lifts exactly as before, and code with them shows them.
  • The ShowMemTag=1 constructors in AARCH64base.sinc now make the tagged pointer the result of the user op (Rd = RandomizePtrTag_Exclude(Rn, Xm)). Before, the op had no output and the register stayed a copy, so tag would still have read return a0;. The AlignmentFault() branch before each stg is gone: it added a block that is in no source and cost the function its return value.
  • p9_emit/kuna_acleintrinsics.rs renames by user-op name: __dmb/__dsb with the domain and type operands recombined into CRm, __isb with CRm read from the instruction, __wfi, __wfe, __yield, __sev, __sevl, and __arm_mte_create_random_tag, _increment_tag, _exclude_tag, _get_tag, _set_tag.
  • ldg x1, [x0] and stg x1, [x0] name another granule and have no ACLE spelling; they print as LoadPtrTag(a1,a0) and StorePtrTag(a0,a1).

Tests

  • tests/stages/kuna-acleintrinsics.xml: the functions above plus hand-assembled stg/st2g/ldg/addg/subg/isb #1/stzg shapes, decompiled with the option off and then on in one session.
  • make test stays 675/675 with the option on. One existing stage expectation moves: the dmb ish control in kuna-syscallregs-aarch64.xml now reads __dmb(11);.
  • Speed: decompile-all of a 730 KB arm64e daemon takes 22.1 s of CPU with and without the change, and its output is byte-identical (it has no barriers or tag instructions).

The exclusive-monitor user ops keep their names: <arm_acle.h> has no AArch64 intrinsic for them.

Fixes #1626

coleleavitt and others added 6 commits November 18, 2026 16:03
…nd print ACLE intrinsics

AARCH64.pspec leaves the ShowMemTag context at 0, under which irg, addg, subg, gmi and ldg lift
as a pointer copy or add and the stg family as nothing, so
`return __arm_mte_create_random_tag(p, 0);` decompiled to `return a0;`. Barriers and hints
printed under their SLEIGH instruction names (`DataMemoryBarrier(2,3)`) instead of the
<arm_acle.h> intrinsic the source called (`__dmb(11)`).

The new option `acleintrinsics` (on|off, default on, AArch64 only) does two things:

- `p2_lift/kuna_memtag.rs` sets ShowMemTag to 1 over the code space before a function is
  lifted. Only the memory-tagging constructors read that context, so code without those
  instructions lifts as before. The ShowMemTag=1 constructors now make the tagged pointer the
  result of the user op (new ops AddPtrTag, ExcludePtrTag, LoadPtrTag, StorePtrTag), and no
  longer branch to AlignmentFault() before a tag store.
- `p9_emit/kuna_acleintrinsics.rs` prints the barrier, hint and memory-tagging user ops as
  __dmb, __dsb, __isb, __wfi, __wfe, __yield, __sev, __sevl and __arm_mte_create_random_tag,
  _increment_tag, _exclude_tag, _get_tag and _set_tag. A barrier's domain and type operands
  recombine into CRm; isb's CRm is read from the instruction. A tag load or store that names
  another granule keeps its user-op name.

`off` restores the previous output byte for byte. make test stays 675/675 with the option on;
the dmb control in kuna-syscallregs-aarch64.xml now reads __dmb(11). The AArch64 compiler
digest and the ccmp lift fixture (unique-space offsets only) are regenerated.

Fixes Noelo-Lab#1626
…ter reads contradict

The shared-push rule took a declared parameter at the pushed slot as proof the
push is an argument on both arms. MinGW GCC passes a static function's
arguments in EAX/EDX/ECX while its debug information lists them as ordinary
parameters, so wine's MSVCRT_longjmp handed the padding slot GCC re-reserves
after IsBadReadPtr to the indirect unwind call: `(*jmp->UnwindFunc)(jmp,frame)`.
A declared list with no register parameter, for a direct callee whose entry
reads EAX, ECX or EDX before writing it, no longer counts as that proof.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
…ead of refusing any

A MinGW thiscall member declared from its mangled name lists `this` as a
stack parameter while its code reads ECX and takes the rest on the stack, so
refusing every declared list whose callee reads an argument register dropped
the speculative-devirtualization gains of the shared-push rule
(std::ctype::do_tolower's virtual call). The callee's stack arguments are the
declared parameters after the r it takes in registers; only a slot above them
is refused. Adds a thiscall control to the fixture and stage test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
The option turns ShowMemTag on, so the EL1 bulk tag instructions now lift
with upstream's ShowMemTag=1 LoadMemTag/StoreMemTag loops instead of
ldgm reading as zero; the chapter said they were unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Resolves the stage-corpus count in kuna-base/src/xml.rs (782) and
re-synthesizes docs/baseline-stages.json (main's 4516 plus this PR's 13).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits on top of yours:

  • 4e7a54e8c (spec only): docs/spec/02-lift-and-flow.md said ldgm/stgm/stzgm are unchanged. With the option on they now lift as upstream's ShowMemTag=1 LoadMemTag/StoreMemTag loops instead of ldgm reading as zero, and the paragraph now says so.
  • 7b31f22bd: merges current main, which conflicted on the stage-corpus count in kuna-base/src/xml.rs (now 782) and on docs/baseline-stages.json (main's assertions plus this PR's 13).

No code changes. The AArch64 digest 6120405649… reproduces with slacomp on the merged tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOMATED] AArch64: MTE tag instructions decompile as plain pointer copies, and barriers print as SLEIGH op names

2 participants