Skip to content

[AUTOMATED] fix(analysis): keep gap-walk starts out of the code a PPC64 ELFv1 symbol sizes - #1976

Merged
mahaloz merged 3 commits into
Noelo-Lab:mainfrom
phix33:fix/elfv1-sized-symbol-extents
Nov 25, 2026
Merged

mahaloz merged 3 commits into
Noelo-Lab:mainfrom
phix33:fix/elfv1-sized-symbol-extents

Conversation

@phix33

@phix33 phix33 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The problem

On PowerPC64 ELFv1, kuna can name a second function inside an exported one, whose body then ends there and loses its result. The symbol states the function's size, but its address is a descriptor in .opd, so the size was read as that of the bytes after the descriptor.

cat > sample.S <<'EOF'
.abiversion 1
.macro fn name, size
.section ".opd","aw"
.globl \name
.type \name,@function
.size \name,\size
\name: .quad .L\name,.TOC.@tocbase,0
.text
.L\name:
.endm
fn driver,100
.irp n,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
bl .Lleaf\n
.endr
blr
.irp n,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
fn leaf\n,16
std 4,-8(1); addis 5,3,1; addi 3,5,\n; blr
.endr
fn sample,28
cmpdi 3,0; beq 1f; nop
std 4,-8(1); addis 5,3,1; addi 3,5,7
1: blr
EOF
powerpc64-linux-gnu-gcc -shared -nostdlib -s -Wl,-e,driver sample.S -o sample.so   # ELFv1, big-endian
kuna decompile sample.so sample
void sample(long a0)
{
  if (a0) {
  } // warn: funcboundflow: fall-through reached the next function entry; truncating flow here
}

kuna functions also lists sub_cf8, 12 bytes into the 28-byte sample. With --option aif off it returns a0 + 0x10007, or a0 for zero.

The fix

  • The rule that drops pattern and gap-walk starts inside a sized function symbol now starts an ELFv1 symbol's extent at the code its validated descriptor names.
  • A descriptor symbol that states exactly 24 bytes is left out. The dot-symbol ABI (-mcall-aixdesc) gives every descriptor its own size, and the .name symbol at the code states the function's.
  • No option: starts from symbols, unwind data and calls are not filtered, and other targets do not change.

Tests

kuna-elfv1-symbolextent.xml covers both byte orders: the false start and the lost result fail without the fix. Controls keep a routine with no symbol, a symbol and a call target inside another function, and a routine behind a descriptor that states its own size. No existing expectation moved.

Over 1,494 ELFv1 images the fix removes 1,010 starts, all strictly inside an unwind range and none a call target, and adds none. Stripped copies of the 1,458 up to 3 MB lose 464, all likewise. 2,610 other files list the same functions.

phix33 and others added 3 commits November 26, 2026 08:19
Resolves the stage-count conflicts with Noelo-Lab#1975: the corpus count is 928
(927 + kuna-elfv1-symbolextent), and docs/baseline-stages.json is re-recorded
on the merged tree (5,480 assertions: main's 5,474 plus this stage's 6).

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

The fixtures README now names the --hash-style=both default of the toolchain that
built elfv1_symbol_extent_{be,le}.so: with it spelled out, Ubuntu's
powerpc-linux-gnu-gcc -m64 (GCC 13.3, GNU ld 2.42) rebuilds both files byte for
byte. Spec 01 adds GMP's assembly as a source of 24-byte descriptor sizes and
says a function whose code is itself 24 bytes filters nothing, as before.

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

mahaloz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits on top of e9d901e, without force:

  • 15ab4d5 merges main to resolve the stage-count conflict with [AUTOMATED] Keep the NULL comparison of a pointer tested inside && / || (truthycond ptrchain) #1975. The corpus count is now 928, and docs/baseline-stages.json was re-recorded on the merged tree (5,480 assertions).
  • 39485c4 changes docs only. The fixtures README now says that the recipe's toolchain defaults to --hash-style=both. With -Wl,--hash-style=both added, Ubuntu's powerpc-linux-gnu-gcc -m64 (GCC 13.3, ld 2.42) rebuilds both .so files byte for byte; without it they come out 64 bytes shorter. Spec 01 now names GMP's assembly as another source of 24-byte descriptor sizes, and says that a function whose code is itself 24 bytes is not filtered (the same as before).

No code changed.

@mahaloz
mahaloz merged commit bdef9d6 into Noelo-Lab:main Nov 25, 2026
2 checks passed
@phix33
phix33 deleted the fix/elfv1-sized-symbol-extents branch November 26, 2026 11:13
mahaloz pushed a commit that referenced this pull request Nov 26, 2026
… call or descriptor names (#1993)

Since #1976, a PowerPC64 ELFv1 descriptor symbol's size bounds the code that its validated descriptor names, so pattern and gap-walk starts inside it are dropped. This change refines that rule in three ways. First, a descriptor symbol's size is left out only when a sized symbol at its code states its own size, as the `.name` symbols of the dot-symbol ABI do. A function whose code is exactly 24 bytes is therefore bounded too, and keeps its body and result. Second, a descriptor symbol whose code word does not validate gives no extent. Third, a start inside another function's extent is kept when something other than a guess names it: the code word of a descriptor at any aligned .opd word, or the target of a `bl`. The Listing walk does not follow the body of an exported ELFv1 function, so such a call or descriptor may be the only evidence for that start.

The PPC64 stub matcher is marked #[inline]. This keeps its per-word scan inlined: without the hint, `functions` on PowerPC64 images ran about 2.4% more instructions.

The kuna-elfv1-symbolextent stage and the elfv1_symbol_extent fixtures gain a 24-byte function, a call from an uncalled export and a descriptor with no symbol, in both byte orders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
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