Skip to content

Mangle alloc-body private labels per-alloc to stop jmp.w collisions - #89

Merged
manz merged 1 commit into
masterfrom
fix/jmpw-local-alloc-collision
May 31, 2026
Merged

manz merged 1 commit into
masterfrom
fix/jmpw-local-alloc-collision

Conversation

@manz

@manz manz commented May 31, 2026

Copy link
Copy Markdown
Owner

Why

jmp.w <local> to a label inside the same .alloc silently jumped into a different routine. Underscore-private labels (_loop, _done, _scan) in sibling allocs of one module all exported the same bare LOCAL name, so they collided in the flat symbol table — only one survived. A jmp.w _loop relocation (absolute, resolved at link) then bound to whichever duplicate the linker placed last: a layout-dependent wild branch that presented as "random memory corruption" / "vwf8 breaks build_menu" downstream.

bra/bcc were unaffected (relative, resolved in-module at assemble time); only the link-deferred absolute jmp.w hit the colliding symbol.

PR #88 fixed the cross-module half of this (resolve a relocation's LOCAL operands against the emitting object). This is the cross-alloc-within-one-module half — the actual reported shape (8 allocs each declaring _done).

What

Resolver._export_name: underscore-private labels in an AllocBodyScope now export under a per-alloc-mangled name (__sc<idx>__name) instead of bare. Public (non-underscore) labels stay bare so cross-alloc refs + .extern still resolve by source name. The relocation renamer routes through the same path, so a jmp.w _loop relocation gets the matching mangled name and resolves to its own alloc's label.

Test plan

Not in this PR

brl (16-bit PC-relative long branch) is still unaccepted — the report notes it as the natural primitive for long intra-routine jumps. Separate follow-up.

Underscore-private labels in sibling allocs of one module exported the same
bare name, so a jmp.w to a local bound to whichever duplicate the linker
placed last (a layout-dependent wild branch). Export them per-alloc-mangled.
@sonarqubecloud

Copy link
Copy Markdown

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying a816 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0faa6a7
Status: ✅  Deploy successful!
Preview URL: https://b7d24c37.a816.pages.dev
Branch Preview URL: https://fix-jmpw-local-alloc-collisi.a816.pages.dev

View logs

@manz
manz merged commit ddd4981 into master May 31, 2026
4 checks passed
@manz
manz deleted the fix/jmpw-local-alloc-collision branch May 31, 2026 20:19
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.

1 participant