In LLVM it is possible to specify prefix data for a function: https://llvm.org/docs/LangRef.html#prefix-data. It allows access to certain metadata from the function pointer. Is it possible to support similar things in cranelift (because it assumes a unified address space for both data and code, and also interleaved storage for data and code)? I know wasm might have different opinions on function vs data pointers, and cranelift is mainly used as a backend for wasmtime, so I wonder if such a feature can be implemented.
Prefix data is very useful for attaching metadata to function code and avoid double indirection (without prefix data, one must use metadata/function pointer pairs instead, so calling the function from metadata pointer involves double indirection; with prefix data, both can be accessed from the function pointer itself). As one of the examples, the Spineless Tagless G-machine paper describes such an optimisation for closures (https://www.microsoft.com/en-us/research/wp-content/uploads/1992/04/spineless-tagless-gmachine.pdf, Section 7.6).
cranelift-codegen doesn't care about this at all. It just takes clif ir for a single function and emits a machine code blob. Any user of cranelift-codegen can add data before or after it as it wishes. cranelift-object doesn't support this, but it should be possible to add it. It would probably either require a change to cranelift_module::Module
to allow passing the extra prefix data as argument to a (new) method, or adding a new method to cranelift_object::ObjectModule
outside of the Module
trait.
Last updated: Dec 23 2024 at 12:05 UTC