Skip to content

Support narrow p-code stack pointers - #363

Open
zardus wants to merge 1 commit into
masterfrom
feature/pcode-narrow
Open

Support narrow p-code stack pointers#363
zardus wants to merge 1 commit into
masterfrom
feature/pcode-narrow

Conversation

@zardus

@zardus zardus commented Aug 9, 2026

Copy link
Copy Markdown
Member

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

ArchPcode derived the initial stack pointer with an expression that assumed a stack pointer at least 16 bits wide, so constructing an architecture with a narrower one — the 8051 and the 8048 have a one-byte stack pointer on a 16-bit address space — raised ValueError: negative shift count.

Deriving the value from the stack pointer's own width instead fixes it where the register sizes are read, and leaves every architecture with a wider stack pointer exactly where it was.

The regression constructs ArchPcode("8051:BE:16:default") and pins the unchanged value for z80, 68000 and x86-64.

Validation: #363 (comment)

Related: angr/cle#717, angr/angr#6793.

ArchPcode derived the initial stack pointer with an expression that assumed a
stack pointer at least 16 bits wide, so an architecture with a narrower one --
the 8051's stack pointer is a single byte -- raised "ValueError: negative shift
count" during construction. Derive the value from the stack pointer's own width
instead; it is unchanged for every wider architecture.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@zardus

zardus commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Validation record for head 08d2caf1ef8cf15be8a5fe494dab33a9e45ddf42 against baseline da171ca0dd8eec1e16dd9c4f04576b2c958e2aea.

  • Reproducer: python -c "import archinfo; archinfo.ArchPcode('8051:BE:16:default')"ValueError: negative shift count on the baseline
  • Regression: python -m pytest tests/test_pcode.py::TestArchPcode::test_arch_with_narrow_stack_pointer — fails on the baseline with that error, passes on the head
  • Full suite: python -m pytest tests — 18 passed
  • Lint/type: pylint 4.0.6 and pyright 1.1.411, scored per changed file against the merge base the way the hosted Lint and Typecheck jobs score them — archinfo/arch_pcode.py 10.00 -> 10.00 and badness 0.238 -> 0.235, tests/test_pcode.py 10.00 -> 10.00 and badness 0.0 -> 0.0
  • Hooks: pre-commit run --all-files — every hook passes and leaves the tree unchanged
  • Coverage: on the head, constructing ArchPcode for every language pypcode 4.0.1 exposes succeeds, with no exception anywhere in the list
  • Environment: Python 3.12.13, pytest 9.1.1, pypcode 4.0.1

Caveats: initial_sp is still taken from the address space width when the stack pointer register is not literally named sp (PIC-16 calls it stkptr), and AARCH64:BE:32:ilp32 still gets a value from its 64-bit sp that sits outside the 32-bit address space; both predate this change and are untouched by it.

@angr-bot

angr-bot commented Aug 9, 2026

Copy link
Copy Markdown
Member

Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/archinfo_363

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