Skip to content

[AUTOMATED] fix(analysis): bound 24-byte PPC64 ELFv1 functions and keep the starts a call or descriptor names - #1993

Merged
mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/elfv1-named-starts
Nov 26, 2026
Merged

mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/elfv1-named-starts

Conversation

@phix33

@phix33 phix33 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The problem

Since #1976, kuna drops a gap-walk start inside a sized PowerPC64 ELFv1 function even when a call names it, and still splits a function of exactly 24 bytes, whose size it skips. Below, sample is 24 bytes, and caller, which nothing calls, calls into the middle of other.

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,24
cmpdi 3,0; beq 1f
std 4,-8(1); addis 5,3,1; addi 3,5,7
1: blr
fn caller,8
bl .Lmid; blr
fn other,28
cmpdi 3,0; beq 1f; nop
.Lmid: std 4,-8(1); addis 5,3,1; addi 3,5,9
1: blr
EOF
powerpc-linux-gnu-gcc -m64 -shared -nostdlib -s -Wl,-e,driver sample.S -o sample.so   # ELFv1, big-endian
kuna decompile sample.so sample
kuna functions sample.so | grep -E 'd3c|d60'
void sample(long a0)
{
  if (a0) { // warn: funcboundflow: fall-through reached the next function entry; truncating flow here
  }
}
0xd3c	sub_d3c

sub_d3c is 8 bytes into sample. 0xd60, the target of caller's call, was listed before #1976 and no longer is.

The fix

  • A descriptor symbol's size is left out only when a sized symbol at its code states its own, as the .name symbols of the dot-symbol ABI (-mcall-aixdesc) do. A 24-byte function is then bounded like any other, and the spec's note that it filters nothing is replaced.
  • Exported ELFv1 bodies are not decoded, so a call from one, or a descriptor with no symbol, can be the only thing that names an entry inside another function. A start that a validated .opd descriptor or a bl names is kept.
  • A descriptor symbol whose code word does not validate gives no extent, where it gave one starting in .opd.

Tests

kuna-elfv1-symbolextent.xml gains a 24-byte function, a call from an uncalled export and a descriptor with no symbol, in both byte orders. On current main the 24-byte function's false start and lost result fail, and so do the two kept starts. The existing assertions move with the fixture's addresses, and its dot-symbol descriptor gains the .dotted symbol that ABI emits, since a 24-byte descriptor symbol without one now bounds 24 bytes of code. Unit tests cover the .name rule, the named starts and an unvalidated descriptor. Over 1,494 ELFv1 images and 1,458 stripped copies, no listed function changes against current main, and listing time is unchanged.

phix33 and others added 4 commits November 26, 2026 20:13
Resolves the docs/baseline-stages.json conflict by re-recording it on the merged
tree: 5,538 assertions, main's 5,536 plus this PR's two new elfv1-symbolextent
assertions (Noelo-Lab#7, Noelo-Lab#8), with Noelo-Lab#1-Noelo-Lab#3 renamed. The corpus count stays 935.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
decode_ppc64_stubs calls kuna_ppc64_stubs::stub_at once for every .text word,
and on PowerPC resolve_from_sections runs about 20 times per load. The code
this PR adds to kuna-analysis changed LLVM's inlining, and stub_at became an
out-of-line call. Under callgrind, `kuna functions` then ran 2.4-2.5% more
instructions on ELFv1 libglib and libstdc++, and on ppc64el ELFv2 libglib,
where none of the PR's logic runs. #[inline] restores it: +0.22% / +0.28%
(the cost of the PR's named-start scan) and +0.03% on ELFv2. This is only an
inlining hint and changes no output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
Main moved to 64a81b6 (Noelo-Lab#1990 added a stage). The corpus count auto-merges to
936, and docs/baseline-stages.json is re-recorded on the merged tree: 5,542
assertions, main's 5,540 plus this PR's two new elfv1-symbolextent assertions.

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

mahaloz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed three commits on top of 512acfb, without force:

  • b667297 and c91a3cc merge main, which moved twice during the review. The corpus count auto-merges to 936, and docs/baseline-stages.json was re-recorded on the merged tree (5,542 assertions: main's 5,540 plus this stage's Fix test stages #7 and Perf/actionpool cursor #8).
  • 6cb48c2 marks kuna_ppc64_stubs::stub_at #[inline]. The code this PR adds to kuna-analysis changed LLVM's inlining, so the per-word stub scan called stub_at out of line. Under callgrind, kuna functions then ran +2.4-2.5% more instructions on ELFv1 libglib and libstdc++, and +2.4% on ppc64el ELFv2 libglib, where none of this PR's logic runs. With the hint it is +0.22% / +0.28% (the cost of the named-start scan) and +0.03% on ELFv2. Output does not change.

@mahaloz
mahaloz merged commit 9fceac9 into Noelo-Lab:main Nov 26, 2026
2 checks passed
@phix33
phix33 deleted the fix/elfv1-named-starts branch November 26, 2026 12:38
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