Skip to content

[AUTOMATED] fix(analysis): every ELF name at a function's address selects that function - #751

Merged
mahaloz merged 6 commits into
Noelo-Lab:mainfrom
phix33:fix/arm-thumb-symbol-aliases
Sep 30, 2026
Merged

mahaloz merged 6 commits into
Noelo-Lab:mainfrom
phix33:fix/arm-thumb-symbol-aliases

Conversation

@phix33

@phix33 phix33 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When several ELF symbols name one address, the loader kept only the first, so the others selected nothing or, when a PLT stub shared the name, the stub. Here answer shares its address with a local ARM veneer name and also labels a PLT stub, so kuna decompile decompiles the stub:

cat > veneer.s <<'ASM'
.syntax unified
.text
.arm
.type __answer_from_arm,%function
__answer_from_arm:
.global answer
.type answer,%function
answer: ldr ip, [pc, #4]; add ip, ip, pc; bx ip
  .word (real_answer + 1) - .
.thumb
.type real_answer,%function
.thumb_func
real_answer: movs r0, #7; bx lr
.global caller
.type caller,%function
.thumb_func
caller: push {lr}; bl answer(PLT); pop {pc}
.section .note.GNU-stack,"",%progbits
ASM
clang --target=armv7a-linux-gnueabihf -c veneer.s -o veneer.o
ld.lld -shared -o veneer.so veneer.o
decompiler/target/release/kuna decompile veneer.so answer
void answer(void)
{
  (*dat_30274)(); // jump-as-call
}

Fix

  • The loader still reports the first name at an address (.symtab, PLT, .dynsym order), the name call sites print. Every other distinct ELF name there, linked or relocatable, becomes a lookup-only alias of that entry.
  • A name reached through an alias picks the definition over an import stub of the same name, so answer now selects the veneer. Otherwise an alias never outbids a function's own name: a static shared still wins over another function's same-address alias shared.
  • xrefs --to answer now reports the definition, which is reached only through its PLT stub, so it lists no callers. Main already answers that way for a plain gcc -shared library.

Tests

  • tests/stages/kuna-elfaliasnames.xml: answer decompiles to return 7; (main decompiles the stub). In a gcc fixture where shared is both an alias of twin and a static function, shared still selects the static one.
  • Loader and CLI tests: linked and relocatable images, with and without the veneer, both symbol orders, .symtab/.dynsym repeats, the shared clash through decompile, --json and decompile-all --functions.
  • Every name in the 41 binaries whose symbols gained an alias, main vs this branch: 46,274 select the same function, 1,751 that matched nothing now select one, 66 move from a PLT stub to the definition, 9 that matched nothing are now reported ambiguous (two versioned definitions), none that selected a function stops selecting it. Reported names and decompile-all output do not change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG

@phix33
phix33 force-pushed the fix/arm-thumb-symbol-aliases branch from 5c45e4a to c3e76b3 Compare September 30, 2026 00:14
@phix33 phix33 changed the title [AUTOMATED] Preserve ELF ARM and Thumb symbol aliases [AUTOMATED] fix(analysis): preserve ARM and Thumb function aliases Sep 30, 2026
@phix33
phix33 force-pushed the fix/arm-thumb-symbol-aliases branch from c3e76b3 to 3841ecf Compare September 30, 2026 01:01
mahaloz and others added 4 commits September 30, 2026 01:53
…t reported names

Retaining every ELF name in the loader's symbol stream let a later alias
outrank the first symbol-table name by entry_name_rank, so whole-binary
output renamed functions (131 in the static-glibc mcount fixture, e.g.
gsignal -> raise) while their callers still printed the old spelling. The
loader now keeps its first-name-per-address stream and exposes the other
distinct names through ObjectLoadImage::func_symbol_aliases; the console
appends them to the canonical entry at the Thumb-normalized address, so
name lookup reaches the definition while the reported name is unchanged.

Adds a clang/ld.lld-built ARM veneer fixture and the stages test
kuna-elfaliasnames.xml (fails on main: the exported name decompiled the
PLT stub), moves the spec prose into the 1.2 loader text beside the
definition-over-import rule, and re-records the stages baseline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG
…on's own name

Review follow-up. A loader alias spelled like a different function's own
name made that name ambiguous (a global alias `shared` of `twin` beside a
static `shared`; 103 names in the sweep, e.g. libasound versioned names and
chibios' chSysLockFromISR), breaking the promise that a name that selected
a function still does. After the definition-over-import-stub rule, name
lookup now drops the candidates it reaches only through a loader alias
whenever another candidate remains, in both resolve_entry and
find_entry_by_name. A loader alias whose address has no entry yet is still
a candidate there, so the text path (no discovery) and --json agree.

Adds the gcc-built elfaliasclash_x86_64 fixture to the stage test and a
CLI test, tests the alias shift under adjust_vma, renames the CLI test to
elf_symbol_aliases.rs, and documents ELF same-address names in docs/cli.md
and the 1.2 spec text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG
Resolves the stage-corpus count (83 + 277 = 360) and re-records
docs/baseline-stages.json from the merged tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG
@mahaloz mahaloz changed the title [AUTOMATED] fix(analysis): preserve ARM and Thumb function aliases [AUTOMATED] fix(analysis): every ELF name at a function's address selects that function Sep 30, 2026
@mahaloz
mahaloz merged commit 9032e73 into Noelo-Lab:main Sep 30, 2026
2 checks passed
@phix33
phix33 deleted the fix/arm-thumb-symbol-aliases branch October 1, 2026 01:36
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