Repository navigation
Conversation
… entries - The ELFv2 ABI passes a function's own address in r12 to its global entry, which derives the TOC pointer from it (addis r2,r12,hi; addi r2,r2,lo). Without that fact r2 was an unknown input and TOC-relative globals printed as offsets from an uninitialised register. - New P1 pass ppc64r12 (the analog of mips_gp's t9 seed): r12 = entry at each defined STT_FUNC whose st_other declares a distinct local entry. - CLI test ppc64_global_entry_toc with a 1.4 KB clang fixture; prototype_call_mechanisms' `on` assertion now checks the clobber, since the stored TOC resolves to a constant instead of printing as r2save.
- st_other entry bits mean nothing under ELFv1; the ELFv1 descriptor reader already gates on e_flags & 3.
- The on arm now checks the store's RHS is the constant the return reads back, not only that the local is clobbered.
Contributor
Author
|
[AUTOMATED] Update after adversarial review (gpt-6.1-sol, deepseek-v4.1-flash):
|
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 function entered at its global entry reaches every global through an uninitialised register. This independent example is clang
-O1forpowerpc64le-linux-gnu:Before the fix:
Cause
The OpenPOWER ELFv2 ABI requires a caller that enters at the global entry to pass the entry address in
r12. The prologue derives the TOC pointer from it. Nothing in kuna stated that, sor2stayed an unknown function input and every TOC-relative access printed as an offset from it (it also does not recompile).Fix
New P1 analysis pass
ppc64r12(kuna-analysis/src/loader/kuna_ppc64r12.rs), the analog ofmips_gp'st9 = entryseed: it recordsr12 = entryas a tracked register value at each defined PPC64STT_FUNCwhosest_otherdeclares a distinct local entry (the annotation that says the function begins with ther12-based TOC setup). Self-gated: empty on every other image.After the fix:
Tests
ppc64_global_entry_tocwith the 1.4 KB fixture above: fails on main (*(unsigned long *)(v1 + 0x20028) = a0;), passes here.prototype_call_mechanisms::default_keeps_a_local_in_the_elfv1_toc_slot_of_an_elfv2_frame: withcallmechanisms onthe r2Save store now writes the resolved TOC constant instead of printingr2save. The assertion now checks the behaviour it is about (the local is clobbered underon;offandautoare unchanged and still compared verbatim).powerpc64le-linux-gnu, decompiled, recompiled, compared with the native build underqemu-ppc64le),sample_vla_escapewroteescaped_vla_addressthroughr12 + 0x22068and crashed; with this pass it writes the global and matches.r12-relative access with the named global (e.g.(**(void (**)(void))(v2 + 0x234c0))();becomes(*obstack_alloc_failed_handler)();). Big-endian ELFv1 images have no local-entry annotations and do not change.