Skip to content

[AUTOMATED] xrefs: an address formed from the PC is a reference below 0x1000 - #1371

Merged
mahaloz merged 7 commits into
mainfrom
fix-1364-lowpage-xref
Nov 1, 2026
Merged

mahaloz merged 7 commits into
mainfrom
fix-1364-lowpage-xref

Conversation

@mahaloz

@mahaloz mahaloz commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

In a zero-based image, kuna xrefs drops an address the program forms from the program counter when the address is below 0x1000. Take the issue's assembly, linked as an arm64 dylib (clang -arch arm64 -dynamiclib fixture.s -o fixture.dylib; this layout puts _audit_target at 0x2d0):

$ kuna xrefs fixture.dylib --from _audit_address
# 0 references from _audit_address @ 0x2ec
$ kuna xrefs fixture.dylib --to _audit_target
# 1 reference to _audit_target @ 0x2d0
0x2e0	call	_audit_direct+0x8	bl 0x2d0

_audit_address is adrp x0, 0x0; add x0, x0, #0x2d0. The same miss happens to a lea rdi,[rip+...] into the .rodata that ld.lld puts first in a shared object or PIE, to _start passing main in an older x86-64 PIE, to an auipc pair, and to A32/Thumb adr in firmware linked at 0. With the fix:

# 1 reference from _audit_address @ 0x2ec
0x2d0	data	_audit_target	@0x2f0	add x0, x0, #0x2d0

The fix:

  • The 4096 floor is there to tell numbers from addresses among immediates. A value computed from the instruction's own address is not an immediate, so it is now exempt; it still has to land in a mapped section. PIC pool composition already worked this way.
  • SLEIGH folds most PC-relative operands into a plain constant, and mov x0,#0x2d0 lifts the same as adrp. The new listing/kuna_pcform.rs recognises the forms from the encoding: AArch64 adr/adrp, x86-64 RIP-relative lea, and A32/Thumb adr. It recomputes their value from the bytes, and only a constant equal to that value is exempt.
  • The register-pair carry treats auipc's own-address operand as PC-relative too. A value stays PC-relative through an add or subtract of something that is not. A difference of two (sub eax,r13d after two lea [rip]), a mask, a shift or a truncation below 32 bits (movzx ecx,al) is a number. Values composed through the i386 PIC base are exempt too.
  • The recogniser is only built for an image that maps something below 0x1000. Every PIE and shared object does, and there it costs 6 to 24 ns per decoded instruction (0.1-0.4% of the walk over the x86-64, AArch64 and ARM C libraries and bash). A fixed-address executable walks exactly as before. This only changes the read-only xref query, so it has no option.

Tests: five prebuilt fixtures (lowpage_*: arm64 dylib, x86-64 and RV64 .so, i386 PIE, ARM image at 0x100), each with a control_number(s) function that builds the same addresses as plain immediates. kuna-cli/tests/xrefs_low_page.rs fails on main for every PC-relative form and checks that the controls stay empty. Unit tests cover the encodings, the floor exemption, and the difference and truncation rules. Over 375 images (angr test corpus, fixtures, decbench PIEs, zlib linked by ld.lld for seven targets), no row is lost. 700 rows are added, and each one checks out as a PC-relative formation, either against capstone or GNU objdump or by hand. Emitted C is unchanged.

Fixes #1364

🤖 Generated with Claude Code

https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE

… 0x1000

A zero-based image (an arm64 Mach-O dylib, an ELF shared object or PIE whose
first page ld.lld fills with .rodata, firmware linked at 0) keeps real
addresses under the checkOperands 4096 floor, and the floor dropped every
address the program formed there: `adrp x0,0x0; add x0,x0,#0x2d0` naming a
dylib's first function, `lea rdi,[rip+...]` into first-page .rodata, an
auipc pair, A32/Thumb adr.

The floor separates numbers from addresses among immediates, so a value
computed from the instruction's own address is now exempt and only has to
land in a mapped section. listing/kuna_pcform.rs recognises the forms SLEIGH
folds into plain constants (AArch64 adr/adrp, x86-64 RIP-relative lea,
A32/Thumb adr) from the encoding and recomputes their value from the bytes;
only a constant equal to it is exempt. regcarry tracks PC-relativity through
add/sub of a non-PC value (auipc's visible inst_start included), never
through a difference of two, a mask or a shift; picbase exempts values
composed through the proven base. Built only for images that map something
below the floor. Read-only xref query: no option.

Over 375 images no row is lost; 700 rows are added, each verified as a
PC-relative formation (capstone, GNU objdump, by hand).

Fixes #1364

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Oct 31, 2026
mahaloz and others added 4 commits October 31, 2026 23:47
A PC-relative value kept its exemption from the checkOperands floor through
any low-part read, so `lea rax,[rip+tB]; movzx ecx,al; lea rdx,[rcx+0x300]`
(and Thumb `adr; uxtb; adds`) filed (tB & 0xff) + 0x300 as a data reference
in a zero-based image. The exemption now survives a truncation only to 32
bits or wider (`lea eax,[rip+..]`, `sext.w`), the narrowest a pointer gets.
The 382-image low-page sweep is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
Resolve the overlap with #1366 (fall-through addresses) by keeping both
behaviours: data_refs takes both the PC-formed values and the delay-slot
probe; regcarry files a fall-through value unless the instruction calls, and
admits a PC-relative value below the floor; picbase admits a fall-through
unless the instruction links, with the PC flag of what it composed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
…d get two readers (#1303)

One function of Ubuntu 26.04's bash (5.3-2ubuntu1, `sub_e87b0`) came out empty: three IMULs
share the 16-byte flag temporary `u0x5a200`, heritage carries it across blocks, and splitting
its lanes would give a free varnode four readers. `TransformManager::apply` now runs
`check_free_fanout` before rewriting anything: temporaries and non-input lanes are checked,
constants are exempt (each later reader of a constant gets its own copy). `ActionLaneDivide`
counts a refusal as a failed trace, so it tries the next lane size and the function decompiles
instead of failing; an error after rewriting has started still fails the function.
`RuleSplitFlow` and `RuleSubfloatConvert` no longer leave a half-rewritten function for this
error. Output is otherwise byte-identical across 67,194 SIMD-heavy functions. New stage test
kuna-lanedivide-freefanout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
…g branch target, and say why a target has no row (#1370)

`disassemble --follow` clipped a branch target's decode at the next row the fall-through
path had already decoded, so a target inside a reachable instruction got no row, and its
"decoded from" note counted the plain listing's skipped targets rather than what `--follow`
anchored. A reachable decode is now kept however another path read the same bytes, so rows
can overlap (as docs/cli.md promised); `--count` keeps the lowest-addressed rows and spends at
most 4 decodes per row. Each target still without a row gets one stated reason (window end,
budget, undecodable, or only unreached bytes name it), and the re-anchor note counts only
targets that got a row. JSON `end`/`bytes` are the furthest row end; under `--follow`,
`truncated` is set only by the 1024-instruction cap. The literal-pool fold needs contiguous
rows, and the web study view's bytes and asm panes handle overlapping rows. Plain listings are
unchanged.

Fixes #1363.

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

mahaloz commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

[AUTOMATED] Pushed two commits.

3447b00: a PC-relative value kept its floor exemption through a low-byte read, so lea rax,[rip+tB]; movzx ecx,al; lea rdx,[rcx+0x300] in an ld.lld x86-64 .so (and Thumb adr r0,tB; uxtb r1,r0; adds r1,#0x80 in an image linked at 0x100) filed (tB & 0xff) + K as a data row. Now the exemption survives a truncation only when the result is 32 bits or wider. A unit test covers the 1-, 2- and 4-byte cases. The 382-image low-page sweep is unchanged: 702 rows added, 0 lost.

fa582af: merges main with #1366. data_refs takes both the PC-formed values and the delay-slot probe. regcarry and picbase keep #1366's link test and add the floor exemption. On top of main the PR adds the same 702 rows and removes none, and the adrnext_* fixtures are unchanged.

phix33 and others added 2 commits November 1, 2026 00:56
… support (#1346)

Add explicit big-endian Octeon, Octeon Plus, Octeon II and Octeon III targets (N64 and N32
soft-float). They lift bbit branches with delay slots, baddu/pop/dpop/seq/sne/seqi/snei,
exts/cins and dmul, plus the II/III indexed loads, as ordinary p-code instead of generic
special2()/getCopReg calls. On a target whose default data space is truncated (MIPS
64-32addr/N32, PowerPC e500 and 32addr, AArch64 ilp32), option truncptrflow (default on) runs
RulePtrFlow, rebuilds a stack register wider than its address space as PIECE(upper, low) at
entry, and skips RuleSelectCse visits of unheritaged outputs, so stack frames, stack arguments
and pointer arithmetic are recovered; this costs about 10-50% more time on those explicit
targets, and off restores the previous output. Untruncated targets are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
@mahaloz
mahaloz merged commit c3568e7 into main Nov 1, 2026
8 checks passed
@mahaloz
mahaloz deleted the fix-1364-lowpage-xref branch November 1, 2026 01:05
mahaloz added a commit that referenced this pull request Nov 1, 2026
Brings in the Go options pushed to main since #1346 (gobounds, the Go
write-barrier guards, Go 1.18 struct offsets) plus #1298 and #1371.
clonephiorder sits on top; every count is re-derived from phases.toml and
the test directories: 356 settables, tiers 127 core / 137 transform /
92 analysis, 164 with a live field, 355 "},\n" separators, 356 fixture
rows, KUNA-CATALOG #15 = 362, corpus 625 files (83 datatests + 542
stages). docs/options.md and phase_catalog.json regenerated with the
merged build. docs/baseline-stages.json re-recorded on the merged tree:
main's set plus RETCOPYCLONE #1-#9, with KUNA-CATALOG #15 renamed
(3417 assertions).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWRVoTEYHNosYwYRoSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AArch64 xrefs miss address formation in the first page of a zero-based Mach-O

3 participants