Repository navigation
[AUTOMATED] Drop a value left in the AArch64 hidden-return register from a call - #941
Merged
Merged
Conversation
mahaloz
force-pushed
the
fix/fix854
branch
2 times, most recently
from
October 6, 2026 02:53
68c36b1 to
56463ab
Compare
…rom a call On AArch64 a value a function leaves in x8, the indirect-result register, was printed as the next call's first argument (`mov x8,#0x38; mov x0,#3; bl foo` -> `foo(0x38,3)`), throughout glibc and bionic after every `svc` and in clang -O0 code that uses w8 as scratch. New option `hiddenretarg` (default on) rescores an active x8 trial no-use when the callee's own body never takes x8, when the value was already dropped from another call it reaches (frame addresses excepted), or when it is a constant in the null page. A callee that reads x8 or reaches `svc` with it unwritten keeps it, and so does a real struct return. Fixes #854 Part of #890 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Qihrih8NnnexavqvZxp8CF
38 of 42 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On AArch64, a value a function leaves in
x8before a call is printed as that call's first argument.x8is the indirect-result register for a struct-returning callee, andfoobelow neither takes it nor returns a struct:The same happens across AArch64 glibc and bionic, where
x8still holds the syscall number (__openprintssub_d4de8(0x38,v3 & 0xffffffff,...)), and in clang -O0 code, which usesw8as a scratch register.Fix
hiddenretarg(default on). Once scoring has made anx8trial active, the trial is rescored with the evidence below.calleedeadargcaches. A callee that never takesx8drops it: no read before a write, and no exit to unread code whilex8is unwritten. A callee that readsx8keeps it, whatever the value; that covers a struct return through it, a tail call into one, and a helper that loops on it. So does a callee that reachessvcwith the caller'sx8, since the kernel reads it as the syscall number.if (pg < 1) return corrupt(4321); if (pagecount(bt) == 0) ...at -O0). A value whose every leaf is a constant below 0x1000 is dropped too, because no OS maps that page.x8by its own convention, behind an import the walk cannot read, loses it. The OCaml runtime'scaml_allocN(0x90)now printscaml_allocN(). Only register entries are touched: SPARC's[sp+64]slot and tricore's shareda4are left alone.Tests
tests/stages/gh854-hiddenretarg-a64.xml, two passes.option hiddenretarg offreproducesfoo(0x38,3),foo(a1 + 1,3),lib(0x38)andcancel(a1). Both passes must keepcorrupt(0x10e1),helper(0x40,1),cnt(10,...),mk(v1,7)andmkthunk(v1,9). Three of its functions also run under the Apple (-a64apple) and Windows (-a64win) compiler specs.x8value. The rest also align arguments with their parameters: 34 parameters gain a pointer type and 12 lose one, and five calls now pass the argument the source does (sqlite3StatusDown(1,1),jsonAppendSeparator(v1)).__errno(0x81)for a leftoverx0(__errno(v7)), and 3 OCamlcaml_allocNcalls lose their size (the limit above).decompile-all, min of 11, interleaved): gzip +0.73%, kmod -0.01%, grep-O0 -1.99%, ls +0.32%, ld-linux +1.12%, bzip2 -O0 -2.96%; total +0.30%.Fixes #854
Part of #890
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qihrih8NnnexavqvZxp8CF