Skip to content

[AUTOMATED] Load big-endian Octeon ELF32 images that declare O64 or no ABI as Octeon O64 - #1987

Merged
mahaloz merged 6 commits into
Noelo-Lab:mainfrom
phix33:fix/octeon-elf32-o64-selection
Nov 26, 2026
Merged

mahaloz merged 6 commits into
Noelo-Lab:mainfrom
phix33:fix/octeon-elf32-o64-selection

Conversation

@phix33

@phix33 phix33 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What this changes

A big-endian Octeon ELF32 image that declares O64, or no ABI at all, loads as generic MIPS32, so Octeon's bbit0 reads as a COP2 load and 64-bit instructions such as dext do not decode. With Ubuntu's binutils-mips64-linux-gnuabi64:

cat > octeon.s <<'EOF'
        .globl  f
        .type   f, @function
f:      bbit0   $4, 15, 1f
        dext    $2, $4, 35, 10
        jr      $31
1:      move    $2, $0
        jr      $31
        .size   f, .-f
EOF
mips64-linux-gnuabi64-as -march=octeon -mabi=o64 -msoft-float -o octeon.o octeon.s
kuna decompile octeon.o f
void f(void *a0) // warn: Control flow encountered bad instruction data
{
  unsigned int v1; // t7
  
  setCopReg(2,v1,*(unsigned int *)((int)a0 + 3));
  halt_baddata(); // warn: Bad instruction - Truncating control flow here
}

With this change the same command prints:

unsigned long long f(unsigned long long a0)
{
  if (a0 >> 0xf & 1)
    return a0 >> 0x23 & 0x3ff;
  return 0;
}

With the header's ABI bits cleared, as toolchains that write none leave them (printf '\200\213\000\000' | dd of=octeon.o bs=1 seek=36 conv=notrunc status=none), both outputs stay the same, and this branch also notes 64-bit MIPS instructions in ELF32 with no ABI declaration; assuming O64 (MIPS:BE:64:octeon-32addr:o64); use --target to specify another ABI.

The change

  • An ELF32 image with the original Octeon machine tag and MIPS64r2 that declares O64 or no ABI selects MIPS:BE:64:octeon-32addr:o64, the target added in [AUTOMATED] Add an explicit soft-float O64 target for big-endian Octeon ELF32 #1828. The output equals that --target's.
  • With no ABI declared, the image is taken as O64 unless it shows O32 code: GNU as sets EF_MIPS_32BITMODE for O32 on a 64-bit ISA, and GCC emits a .mdebug.abi32 section. The generic selector already makes this assumption for images without a machine tag.
  • An image whose metadata contradicts this keeps the selection it has today, and a note says why: hard float (O64 has only a soft-float model, and the original Octeon has no FPU), 32-bit registers, another ISA or extension, or a conflicting ABI-flags record or .mdebug marker. So do Octeon Plus and later, which have no O64 model, and little-endian images. --target still wins.

Tests

tests/fixtures/octeon-elf32/ adds GCC 7.3 images, with their recipe, for these cases, a PIC O64 shared object, and a generic MIPS64r2 image with a real lwc2. tests/stages/kuna-mips-octeon-elf32-o64.xml checks a CRC's bit-15 branch, a five-argument call and the lwc2 control; all five assertions fail on main. CLI tests check each note, --target, and that automatic output equals the explicit target's. The CRC's instructions under QEMU Octeon68XX and its emitted C at -O0 and -O2 with UBSan match binascii.crc_hqx on 259 inputs.

Model: anthropic/claude-opus-5-5

phix33 and others added 2 commits November 26, 2026 20:04
… spec 01

The O32 evidence for an Octeon ELF32 image without an ABI declaration is
EF_MIPS_32BITMODE, which the assembler writes, an ABI-flags record with
32-bit GPRs, or a GCC .mdebug.abi* marker; the paragraph credited GCC with
the header flag and left out the ABI-flags record the code also checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed 071d08c, a spec-only wording fix: spec 01 credited GCC with writing EF_MIPS_32BITMODE (GNU as writes it) and left out the ABI-flags record with 32-bit GPRs, which the selector also treats as O32 evidence. No code or test changes.

mahaloz and others added 4 commits November 26, 2026 10:02
…O64 selection branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…O64 selection branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz
mahaloz merged commit e66a080 into Noelo-Lab:main Nov 26, 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.

2 participants