Skip to content

[AUTOMATED] Keep a value prepared for the return out of a call to a callee whose body takes no argument register - #2103

Open
phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:fix/spurious-call-arguments
Open

phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:fix/spurious-call-arguments

Conversation

@phix33

@phix33 phix33 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Where the first argument register is also the return register, a return value set before a branch prints as an argument of a call on the other arm, even when the callee takes none. GCC's PPC32 stack-protector epilogue does this in every protected function:

cat > ssp.c <<'S'
extern void fill(char *p, int n);
extern void __stack_chk_fail(void) __attribute__((noreturn));
__attribute__((visibility("hidden"), noreturn)) void __stack_chk_fail_local(void);
int sum(int a, int n) { char buf[32]; fill(buf, n); return a * 3 + buf[n & 31]; }
int twice(int a) { char buf[16]; fill(buf, a); return buf[1] + buf[2]; }
void __stack_chk_fail_local(void) { __stack_chk_fail(); }
int after(int a) { return a + 1; }
S
powerpc-linux-gnu-gcc -O2 -fPIC -fstack-protector-all -shared -nostdlib ssp.c -o ssp.so
kuna decompile ssp.so sum
kuna decompile ssp.so twice
int sum(int a0,unsigned int a1)
  ...
    __stack_chk_fail_local(v3); // no-return
  return v3;

void twice(unsigned int a0)
  ...
    __stack_chk_fail_local((unsigned int)v3 + (unsigned int)v4); // tail-call, no-return

With the fix both calls print __stack_chk_fail_local(); and twice is int twice(unsigned int a0) again.

Fix

  • A register argument is dropped when the callee's body, which is in the image, reads no general-purpose argument register before writing it, and the value is what the function returns on a path the call is not on.
  • Nothing is decided where the caller reads the register after the call, for an undeclared external, or for a callee the walk cannot finish. A double the callee reads from d0 stays.
  • The callee walk ends at its first call unless that target cannot hand the register back: with -fipa-ra GCC reads an argument register after calling a local function that leaves it alone.
  • No option: the argument contradicts the callee's own body.

Tests

  • kuna-preparedreturn.xml over three authored fixtures (PPC32, AArch64, ARM with Thumb): 13 assertions, 5 failing on main. A CLI test compiles the library above; unit tests cover the callee walk.
  • kuna-condexeretuse.xml pinned void differ and void compl beside a callee that overwrote r0. Its callees now read r0, so its ten assertions test what they did.
  • Stack-protected PPC32 BusyBox: 433 handler calls lose the value and 4 functions regain a return, nothing else changes. On 158,574 generated calls with known arity, no call loses an argument its callee reads.

Model: anthropic/claude-mythos-5-2

@phix33
phix33 force-pushed the fix/spurious-call-arguments branch from 0f99220 to e13ce46 Compare December 5, 2026 03:57

This branch has not been deployed

No deployments
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.

1 participant