Skip to content

[AUTOMATED] Type a parameter read only at field offsets of 0x1000 or more as a pointer - #1994

Merged
mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/pointer-param-large-field-offsets
Nov 26, 2026
Merged

mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/pointer-param-large-field-offsets

Conversation

@phix33

@phix33 phix33 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What this changes

A pointer parameter that a function reads only at offsets of 0x1000 or more is declared an integer. When a function starts at such an offset, the read prints as a subscript of that function. With GCC on x86-64 Linux:

cat > page.c <<'EOF'
struct page { char pad[0x1000]; unsigned int id; unsigned int window; };
int update(struct page *c, unsigned int v)
{
    c->window += v;
    return c->id == v;
}
EOF
gcc -O2 -fPIC -shared -nostdlib -o page.so page.c
kuna decompile page.so update
bool update(long a0,int a1)
{
  *(int *)(a0 + 0x1004) = *(int *)(a0 + 0x1004) + a1;
  return *(int *)&update[a0] == a1;
}

With this change:

bool update(void *a0,int a1)
{
  *(int *)((long)a0 + 0x1004) = *(int *)((long)a0 + 0x1004) + a1;
  return ((int *)a0)[0x400] == a1;
}

The change

  • ptrfromuse tells p->field from table[i] by whether the constant could be a global's address. In an image with a section table, a constant outside every data section and outside the code is now a field offset, and so is a function's address.
  • Everywhere else the old grading stays: data sections and the rest of code hold tables, including .rodata that firmware links into .text. Images without a section table are unchanged.
  • charptr, castarith and floatreg use the same test. For example, zlib's deflate_state reads print as ((int *)a0)[0x52d] instead of *(int *)&((char *)0x14b4)[(long)a0].

Tests

tests/stages/kuna-ptrfromuse-faroffset.xml loads five GCC 15 images from tests/fixtures/field-offset-pointers/. Parameters read at 0x1000 and 0x48a0 become void *, and parameters that index .data, .bss and .text tables stay integers. The five assertions for the fix fail on main, and no existing test expectation changes. In Kuna's Go 386 fixtures, runtime.wbBufFlush1 and its caller lose their pointer parameter, because the walk now reaches the existing refusal of a pointer difference.

Model: anthropic/claude-opus-5-5

@phix33
phix33 force-pushed the fix/pointer-param-large-field-offsets branch from e6df964 to 5d64b05 Compare November 26, 2026 12:39
@phix33
phix33 force-pushed the fix/pointer-param-large-field-offsets branch from 5d64b05 to 0cf20c2 Compare November 26, 2026 12:46
mahaloz and others added 3 commits November 26, 2026 12:49
… far field-offset reading

The section test read every constant outside the image's data sections and
code as a field offset. Two kinds of constant there are still addresses: one
of 1 MiB or more (a microcontroller's peripheral or RAM word, a relocatable
object's extern slot, text decoded as code), and one at most 0x100 bytes
below a data section, where `table[c - 'a']` puts the base of a byte table
at the start of its section. Both now keep the old grading, so either can
only restore the output the image had before the far-offset reading.

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

`absolute.c` (GCC 15, recipe and hashes in the fixture README) adds a read of
the absolute address 0x40020000 at an offset in the parameter, a byte table
at the start of `.rodata` indexed from a character, and a relocatable
object's extern table; each parameter stays an integer. Spec 05 describes the
two limits, names the context fields `ArchContext::`, and records that a
field address subtracted from another pointer is refused at any offset.

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] I pushed three commits on top of your rebased head (d675c76).

The section test also read some absolute addresses as field offsets. With GCC on x86-64:

cat > absolute.c <<'C'
extern char ext_table[];
static const char letters[32] = "abcdefghijklmnopqrstuvwxyz";
unsigned int read_reg(unsigned long off) { return *(volatile unsigned int *)(0x40020000UL + off); }
int letter_rank(long c) { return letters[c - 'a']; }
int get_ext(long i) { return ext_table[i]; }
C
gcc -O2 -fPIC -shared -nostdlib -o absolute.so absolute.c && gcc -O2 -c -o absolute.o absolute.c
kuna decompile-all absolute.so; kuna decompile-all absolute.o

Before the fix, read_reg(void *a0) printed ((unsigned int *)a0)[0x10008000], letter_rank(void *a0) printed ((char *)a0)[0x1f9f], and the object's get_ext(void *a0) printed ((char *)a0)[0x402000]. On stripped decbench ARM firmware it accounted for 53 of the 84 new pointer parameters: three are RIOT's pm_block(unsigned mode), which indexes a data section at 0x20000204 whose ELF type is not data, and the other 50 sit in code with no debug info, at offsets such as 0x64657669. Two limits now keep those constants on the old grading: a constant of 1 MiB or more, and one at most 0x100 bytes below a data section. On x86-64 every flip that DWARF can check is unchanged (89 correct, 0 wrong), and so are the Go amd64 and arm64 results.

absolute.c and its two images are added to tests/fixtures/field-offset-pointers/ (GCC 15, the recipe and hashes are in the README), with three assertions in the stage. Spec 05 now describes both limits.

@mahaloz
mahaloz merged commit 214c832 into Noelo-Lab:main Nov 26, 2026
2 checks passed
@phix33
phix33 deleted the fix/pointer-param-large-field-offsets branch November 26, 2026 15:46
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