Skip to content

[AUTOMATED] Honor embedded PowerPC32 ELF requirements and decode ISEL by default - #1827

Merged
mahaloz merged 35 commits into
Noelo-Lab:mainfrom
phix33:fix/ppc32-elf-isel
Nov 23, 2026
Merged

mahaloz merged 35 commits into
Noelo-Lab:mainfrom
phix33:fix/ppc32-elf-isel

Conversation

@phix33

@phix33 phix33 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Problem

An embedded PowerPC32 ELF can declare that it uses isel, yet default decompilation stops at that instruction. This function should return zero when a == 0 and b otherwise.

printf '%s\n' '.text' '.globl pick' '.type pick,@function' 'pick:' \
  'cmpwi 3,0' 'isel 3,0,4,2' 'blr' '.size pick,.-pick' |
  powerpc-linux-gnu-as -me500 -o pick.o
powerpc-linux-gnu-ld -e pick -Ttext 0x100000 -o pick.elf pick.o
decompiler/target/release/kuna decompile pick.elf pick \
  --assert 'prototype pick int pick(int a,int b)'
  halt_baddata(); // warn: Bad instruction - Truncating control flow here

Fix

Follow-up to #1424.

  • Honor supported APU notes by default. An SPE note selects e500. An ISEL requirement or the embedded flag alone enables ISEL with the generic PPC32 calling convention.
  • Keep generic decoding and report a diagnostic for malformed notes, including invalid owner strings. Explicit targets and --option ppcapu off retain precedence over automatic selection.
  • On e500, write only the low word of the ISEL destination so subsequent SPE instructions can read the original upper word.

Tests

The stage fixture checks both select outcomes and the fifth argument passed to a callee. QEMU and compiled emitted C agree on the upper-word witness: 42 on both paths for e500, and 1 or 2 for full-width PowerPC. Loader tests cover malformed note owners in both byte orders.

@phix33
phix33 force-pushed the fix/ppc32-elf-isel branch from d5f6293 to e5828e1 Compare November 22, 2026 05:49
mahaloz and others added 7 commits November 22, 2026 21:50
…tride

Resolves the stage-corpus file count (main's 861 plus this branch's
kuna-aif-slot-edges = 862) and re-synthesizes docs/baseline-stages.json
from both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…n export

The xrefs section on exports called through their own PLT stub now says
that ARM, AArch64, PowerPC32 absolute/BSS-PLT and PowerPC64 ELFv1 stubs
are recognized by shape, and which shapes are not joined (Thumb
interworking prefixes, --long-plt, PAC entries, PowerPC32 secure-PLT PIC
stubs), so a reader knows when to query the stub address instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
With e500 selected for every SPE-note image, ordinary integer functions lose
arguments: the e500 model drops a 32-bit argument read through mulhwu
(`ud3(u32 a) { return a / 3; }` decompiles as `ud3(void)` with an
uninitialized 64-bit local), and 64-bit integer pairs lose halves. On 414
GCC -O2 PPC32 objects given an SPE note, 23 integer-only functions went from
the DWARF parameter count to too few and 12 from too many to correct.

ppcapu becomes isel|on|off, default isel. isel selects the generic PowerPC32
model plus ISEL for an ISEL, SPE or embedded floating-point requirement or the
embedded ABI flag, so every such image decodes what main decodes plus isel.
on keeps the e500 selection for SPE requirements (the previous PR default and
main's opt-in); off keeps the generic decoder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…ot a reference to it

A name query widened to an export's own PLT stub and slot also picked up
every `data` row whose value merely equals the stub's or slot's address:
an immediate (`li r9,0x2064`, `mov w0,#0x4b50`) or an AArch64 adrp page
base that happens to equal the slot. In a position-independent image such
a value is not the export's address. refs_to_class now drops `data` rows
to the export-PLT members only; calls, jumps, reads and writes are kept,
the x86-64 veneer path is unchanged, and a query by the stub's address
still lists the row. Over 348 changed name queries on real AArch64/ARM/PPC
shared objects this removes exactly the 14 such rows and nothing else.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed a merge of main and one fix on top (377fe0a).

The ISEL part works: an ISEL note or EF_PPC_EMB now decodes isel, and images without them are byte-identical. With e500 selected by default for an SPE note, though, ordinary integer functions in those images lose arguments, as they did when #1424 kept this opt-in:

# ud3(u32 a) { return a / 3; }, as GCC 13 -O2 emits it for PPC32
printf '3d20aaaa6129aaab7c6348165463f87e4e800020' | xxd -r -p > ud3.bin
kuna decompile ud3.bin 0x1000 --raw-image --base 0x1000 --target PowerPC:BE:32:default:default
#   unsigned int sub_1000(unsigned int a0) { return a0 / 3; }
kuna decompile ud3.bin 0x1000 --raw-image --base 0x1000 --target PowerPC:BE:32:e500:default
#   unsigned int sub_1000(void) { unsigned long long v1; // r3 ... }

I compiled 414 GCC -O2 PPC32 objects and added an SPE note to each. In integer-only functions, the e500 default gave too few parameters (checked against DWARF) in 24 functions that were correct before, and corrected 12.

ppcapu is now isel|on|off, with isel as the default. An ISEL, SPE or EFP note, or the embedded flag, selects the generic+ISEL language. on keeps your e500 selection, and off keeps the generic one. The fix keeps all of the ISEL gains (205 of the -mcpu=8548 functions change, 182 of them losing halt_baddata). The SPE-note corpus now matches main, and --option ppcapu on matches your previous head byte for byte.

mahaloz and others added 6 commits November 23, 2026 00:41
mahaloz and others added 7 commits November 23, 2026 01:38
@mahaloz
mahaloz merged commit eceb7b2 into Noelo-Lab:main Nov 23, 2026
2 checks passed
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