Skip to content

Use precise alias regions for statically-known entity imports - #14115

Open
fitzgen wants to merge 3 commits into
bytecodealliance:mainfrom
fitzgen:known-memories-tables-globals-alias-regions
Open

Use precise alias regions for statically-known entity imports#14115
fitzgen wants to merge 3 commits into
bytecodealliance:mainfrom
fitzgen:known-memories-tables-globals-alias-regions

Conversation

@fitzgen

@fitzgen fitzgen commented Aug 10, 2026

Copy link
Copy Markdown
Member

Accesses of statically-known globals, memories, and tables now use
AliasRegionKey::Defined{Global,Memory,Table} rather than the conservative
Public{Global,Memory,Table} region shared by every entity of that kind which
crosses a module boundary.

However, unlike known_imported_functions, this requires an extra condition:
every module that ever imports an entity must always import that same
entity. Otherwise a function that accesses, e.g., a memory via the conservative
region could be inlined into one that uses the precise region, and accessing the
same bytes through two different alias regions is invalid and leads to
miscompiles. That is, all of the importing modules and the defining module must
agree on the alias region.

Depends on #14114

@fitzgen
fitzgen requested review from a team as code owners August 10, 2026 22:03
@fitzgen
fitzgen requested review from alexcrichton and removed request for a team August 10, 2026 22:03
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. labels Aug 10, 2026

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this analysis done here I'm worried about the case where a module imports something and reexports it, although I can't quite place my finger on why so I wanted to ask about that. It seems like an import could be considered unambiguous but then an export could be considered ambiguous, but in that scenario we'd want the import to additionally be considered ambiguous. Does this handle that sort of case already?

Comment thread crates/cranelift/src/func_environ.rs
Accesses of statically-known globals, memories, and tables now use
`AliasRegionKey::Defined{Global,Memory,Table}` rather than the conservative
`Public{Global,Memory,Table}` region shared by every entity of that kind which
crosses a module boundary.

However, unlike `known_imported_functions`, this requires an extra condition:
every module that ever imports an entity must always import that same
entity. Otherwise a function that accesses, e.g., a memory via the conservative
region could be inlined into one that uses the precise region, and accessing the
same bytes through two different alias regions is invalid and leads to
miscompiles. That is, all of the importing modules and the defining module must
agree on the alias region.
@fitzgen
fitzgen force-pushed the known-memories-tables-globals-alias-regions branch from c946840 to 5f6a554 Compare August 18, 2026 16:20
@fitzgen

fitzgen commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

@alexcrichton good catch, there was indeed a bug with re-exports. I've fixed it and added .wast tests that will fail when run with inlining enabled (e.g. by the wast-file fuzzer) if we mess up our alias regions in this way again (and checked locally with wasmtime wast -Cinlining=y that they failed before the fix and pass afterwards).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants