Repository navigation
Conversation
…ame header - ppc_64_le.cspec placed the first stack parameter at SP+112, the ELFv1 offset after a 48-byte header. ELFv2 (every ppc64le target) has a 32-byte header (back chain, CR, LR, TOC), so the ninth doubleword is at SP+96. Callers lost their stack arguments and callees read an unwritten slot. - Stage test kuna-ppc64le-elfv2-stack-args: callee `return i + a;`, caller `f9(n,2,3,4,5,6,7,8,n + 9)`; both fail on main.
… version 2 - Big-endian ELFv2 (musl, -mabi=elfv2) has the same 32-byte frame header as ppc64le, so stack parameters start at SP+96; the default big-endian spec stays ELFv1 (SP+112). - New compiler spec ppc_64_be_elfv2.cspec (id elfv2), chosen by the loader when e_flags & 3 == 2. - Stage test from real clang -mabi=elfv2 output (fails without the selector); loader unit test; baseline re-recorded (4344/4344).
- ELFv2 saves r2 at 0x18(r1); the copied ELFv1 inject wrote 0x28, inside the parameter save area. Only used under callmechanisms on.
…SA-selection contract
Contributor
Author
|
[AUTOMATED] Update after adversarial review (gpt-6.1-sol, deepseek-v4.1-flash; two rounds):
|
This branch has not been deployed
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.
Problem
On ppc64le, a call's ninth integer argument (the first one passed on the stack) is lost, and a callee reads its ninth parameter from an unwritten slot. This independent example is clang
-O1forpowerpc64le-linux-gnu, withf9andcallerin separate translation units:Before the fix:
Cause
ppc_64_le.cspecputs the first stack parameter atSP+112, the ELFv1 offset: a 48-byte header (back chain, CR, LR, two reserved doublewords, TOC) followed by the 64-byte parameter save area for the eight register arguments. Little-endian PowerPC64 uses the ELFv2 ABI, whose header is 32 bytes (back chain, CR, LR, TOC), so the ninth doubleword is atSP+96. The big-endian ELFv1 spec is unchanged.Fix
ppc_64_le.cspec: the stackpentrystarts at offset 96.After the fix:
Tests
kuna-ppc64le-elfv2-stack-args.xml(the example above): both assertions fail on main and pass here.powerpc64le-linux-gnu, decompiled, recompiled and compared against the native build underqemu-ppc64le),vla_variadic(0,n,2,3,4,5,6,7,8)printed its ninth argument as an uninitialised local and its later call read the wrong slot; with this spec both calls match the native results.gzip,bzip2,sed,grep,tar,diffutils,findutils,coreutils; 24,612 functions; a second base run showed no nondeterministic function; no errors on either side): 1,993 functions change. In 420 a call gains the stack arguments it was missing (e.g.sub_75b8(…,*(unsigned long *)(v9 + 0x16b68),*(unsigned long *)(v9 + 0x16b70)), previously one argument short); in 2 spurious register-save arguments that filled the misplaced slots disappear; the remaining 1,571 keep every call's argument count, and the ones I sampled differ only in renumbered variables and in locals that now hold the argument values. The big-endian ppc64 corpus is unaffected (the change is in the LE spec only).