Skip to content

wasm32: the interface accessor cell tag is bit 30, so the vtable's relocation fits - #813

Merged
ASDAlexander77 merged 1 commit into
mainfrom
wasm32-accessor-tag
Nov 11, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
wasm32-accessor-tag

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes the "LEB is outside Varint32 range" error that stopped wasm32 programs from linking when a class fills an interface field with accessors.

What went wrong

  • In an interface's vtable, a field that a class fills with get/set holds the address of a cell of accessors, plus a tag that marks it as a cell. The tag was the sign bit, which an offset never has.
  • In the object file that is a relocation, @cell + 0x80000000. A wasm object stores a relocation's addend as a signed 32-bit LEB, and an address plus 2^31 is out of that range.
  • wasm-ld failed with "LEB is outside Varint32 range", and so did llvm-objdump.

The fix

  • On wasm32 the tag is now bit 30 (INTERFACE_ACCESSOR_CELL_TAG(sizeBits, isWasm) in Defines.h).
  • That's safe because a wasm32 program's static data is at the bottom of linear memory, far below 1 GB, and no offset into an object reaches 1 GB either.
  • A slot counts as a cell when the tag bit is set (LowerToLLVM.cpp, InterfaceAccessorCell). On every other target that's still the sign bit, so it's the same test as before.

Tests

  • 00class_accessor_implements_field, 00interface_field_getter_owned, 00class_accessor_increment and 00class_redeclared_field are removed from wasm_skips.txt. They now run on wasm32, including the --di --opt_level=0 builds.
  • Native ctest: 6970/6970.
  • wasm suites, release and debug, 0 failures:
Suite none / rc own
tester, wasm32 575 pass (was 571) 421 pass
tester, wasm64 572 pass 419 pass
defaultlib 181 pass 180 pass

🤖 Generated with Claude Code

…location fits

A field a class fills with accessors has, in an interface's vtable, the address of a cell of
accessors plus a tag - the sign bit, which an offset never has. A wasm object keeps a relocation's
addend as a signed 32-bit LEB, and an address plus 2^31 is out of its range: wasm-ld (and any reader
of the object, llvm-objdump too) stopped with "LEB is outside Varint32 range". On wasm32 the tag is
now bit 30: a wasm32 program's static data is at the bottom of its linear memory, far below 1 GB, and
no offset into an object reaches 1 GB either. A slot is a cell when the tag bit is set - on every other
target the sign bit, as before.

00class_accessor_implements_field, 00interface_field_getter_owned, 00class_accessor_increment and
00class_redeclared_field now run on wasm32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 233e575 into main Nov 11, 2026
@ASDAlexander77
ASDAlexander77 deleted the wasm32-accessor-tag branch November 11, 2026 21:10
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