forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change intends to add a new lowering for `MachInst::LoadExtName` (the pseudo-instruction behind CLIF's `func_addr` and `symbol_addr`) that uses RIP-relative addressing when the name is local to the module (`colocated`). The existing behavior is retained, which currently loads from the global offset table when the `is_pic` flag is set (a `X86GOTPCRel4` relocation) or loads a relocated immediate (an `Abs8` relocation). After this change, a `lea` instruction will calculate a RIP-relative address if the name in question is marked with CLIF's `colocated` flag. Why is this necessary? Though some users of Cranelift, like `cranelift-jit`, understand how to relocate the existing `Abs8` relocations (see [`CompiledBlob::perform_relocations`]), Wasmtime does not. Though technically Wasmtime does apply relocations (see [`CodeMemory::apply_relocations`]), these are only for libcalls. Wasmtime will attempt to resolve module-local functions, the ones targeted by `func_addr`, via some internal relocation patching in [`ModuleTextBuilder::append_func`]. When it realizes it cannot patch one of these functions, it panics because [`LabelUse::from_reloc`] only understands the `X86CallPCRel4` relocation. This prevents the use of `func_addr` when translating Wasm code. Since no current Wasmtime translation uses `func_addr` directly, this change is not technically required, but it does feel like the right option to add, normalizing `func_addr`'s behavior for local functions to `MachInst::CallKnown`'s behavior and making it more useful for other Cranelift users in the future. [`CompiledBlob::perform_relocations`]: https://github.com/bytecodealliance/wasmtime/blob/752c7ea4dd83f9cb247e00cadf9d1958c0bdf9b6/cranelift/jit/src/compiled_blob.rs#L48 [`CodeMemory::apply_relocations`]: https://github.com/bytecodealliance/wasmtime/blob/752c7ea4dd83f9cb247e00cadf9d1958c0bdf9b6/crates/jit/src/code_memory.rs#L269 [`ModuleTextBuilder::append_func`]: https://github.com/bytecodealliance/wasmtime/blob/752c7ea4dd83f9cb247e00cadf9d1958c0bdf9b6/crates/cranelift-shared/src/obj.rs#L145 [`LabelUse::from_reloc`]: https://github.com/bytecodealliance/wasmtime/blob/752c7ea4dd83f9cb247e00cadf9d1958c0bdf9b6/cranelift/codegen/src/isa/x64/inst/mod.rs#L2759
- Loading branch information
Showing
6 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters