Skip to content

[AArch64] Preserve erased frames through C++ cleanup - #64

Open
wizardengineer wants to merge 2 commits into
enforced_secrecy_mainfrom
codex/p13-aarch64-cleanup-experiment
Open

wizardengineer wants to merge 2 commits into
enforced_secrecy_mainfrom
codex/p13-aarch64-cleanup-experiment

Conversation

@wizardengineer

Copy link
Copy Markdown

Support escaping C++ cleanup for ordinary fixed-frame AArch64 ELF functions using the GNU C++ personality. Restore incoming caller state, erase the original allocation, then transfer through a compiler-local helper whose separate storage preserves the information needed by the unwinder. A function-wide constant continuation and helpers grouped by frame extent preserve the original frame's unwind identity without a new runtime ABI or attribute.

The permitted context is explicit: the exception interface, restored incoming LR/X21, a fixed continuation address, and a carrier address derived from the original stack pointer. The helper allocation stays below the original erased frame. Unsupported ARM32 EHABI, dynamic/realigned layouts, SVE/SME, explicitly reserved X1/X21 and other excluded protocols retain their diagnostics; the existing Android shadow-call-stack path is unchanged.

Validation, independently reproduced:

  • 240 generated C++ cases across O0/O1/O2, both unwinders, five frame extents, cleanup branches and caller sites.
  • 96 nested configurations, plus 4,096 repeated calls; all 12 deliberate restoration, residue and continuation-layout failures were detected.
  • 65 AArch64 regression pipelines and eight updated Clang source pipelines passed.
  • 93 additional native executions cover attribute combinations, PIC, section garbage collection, duplicate COMDAT, shared linkage and verification-disabled builds.
  • A reserved-X21 entry observer reproduced a helper clobber; the follow-up rejects that configuration while preserving unprotected cleanup and protected ordinary returns under both unwinders. Reserved-X1 MIR coverage also passes.

The evidence uses an assertion-enabled compiler with isolated rebuilt AArch64 objects and a replacement LLVM library. Stacking on #63 preserved the tested compiler files; the later reservation guard has a separate rebuilt-library check. A fresh combined-source CI result remains required. Exact signal-boundary failures in the pinned LLVM unwinder also reproduce with ordinary unprotected functions and are documented separately, not claimed as new asynchronous support.

Stacked on #63. Refs trailofbits/vspells-ct-internal-notes#48, trailofbits/vspells-ct-internal-notes#58, trailofbits/vspells-ct-internal-notes#59 and trailofbits/vspells-ct-internal-notes#82. This is a narrow implementation, not a declaration of full milestone completion. Assisted by Codex.

@frabert
frabert force-pushed the codex/p13-aarch64-cleanup-experiment branch from 9fe3f5f to 7153ad5 Compare November 24, 2026 10:14
@frabert
frabert force-pushed the codex/p13-aarch64-cleanup-experiment branch from c3ba77b to 2bec229 Compare November 30, 2026 14:47
@frabert
frabert added this pull request to stack #75 December 1, 2026 12:53
@frabert
frabert marked this pull request as ready for review December 1, 2026 12:54
@frabert
frabert force-pushed the codex/p13-aarch64-cleanup-experiment branch from 2bec229 to abbbb87 Compare December 1, 2026 13:44
@frabert
frabert removed this pull request from stack #75 December 1, 2026 14:41
@frabert
frabert added this pull request to stack #76 December 1, 2026 14:41
Base automatically changed from codex/p13-ffr-runtime-ci to enforced_secrecy_main December 2, 2026 00:32
Retain the erased original frame while a separate local thunk carries restored caller context. Share one constant continuation per function and emit transient unwind rows per fixed frame extent.

Experimental local branch: validated with 240 generated C++ executions, 96 nested-depth cases, 4096 repeated calls, 12 failing mutations, and 65 focused RUN pipelines. Independent review remains required; general ARM32 EHABI and asynchronous runtime support are outside this patch.
@kumarak
kumarak force-pushed the codex/p13-aarch64-cleanup-experiment branch from abbbb87 to cb4b202 Compare December 2, 2026 00:38
@CLAassistant

CLAassistant commented Dec 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Reject the carrier where its unwind protocol does not hold. Under
a Guarded Control Stack the reported continuation was never pushed
by a call. Under ILP32 the continuation's unwind rules read half
of each saved 64-bit slot. Basic-block sections and function
splitting are requested before frame lowering but assigned after
it, so test the request, not MachineFunction::hasBBSections.

Have the printer follow the decision frame lowering recorded on
the exit instead of recomputing eligibility. It used to fall back
to an ordinary call after the frame was erased and leave the
continuation undefined.

Use a temporary symbol for the continuation, so a symbol of the
module cannot claim its name.

Cover the continuation in the call-site table. The table ended
at the last invoke when the resume block was laid out in front
of it, and the personality routine calls std::terminate for an
address without an entry. Add
AsmPrinter::hasReturnAddressAfterFunctionBody and emit the
trailing entry up to the function end when it is set.

Emit one thunk per function, behind the function in its section.
The branch to it is resolved by the assembler, so it needs no
linker veneer, which would write X16 after the register clears,
and the thunk shares the section's group and flags.

Document that the linker may set X16 and X17 on the helper's
call to _Unwind_Resume.
@kumarak
kumarak force-pushed the codex/p13-aarch64-cleanup-experiment branch from 632e69b to 7afa4e4 Compare December 2, 2026 12:52
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.

3 participants