wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

cranelift-object: Support marking data object as used

Open bjorn3 opened this issue 8 months ago • 1 comments

Feature

See title.

Benefit

This is required for implementing #[used(linker)] in cg_clif. This attribute is equivalent to attribute((used)) in C. And on all non-ELF platforms it is the default. when #[used] is used. On ELF platforms it may become the default in the future.

Implementation

Add a flag to DataDescription and then set the right symbol flag for the given object file format.

bjorn3 avatar May 09 '25 20:05 bjorn3

Note that #[used(linker)] is __attribute__((used,retain)), not __attribute__((used)), which is just #[used(compiler)].

Compiler Linker
GCC C __attribute__((used)) __attribute__((retain)) (note that you need both)
Rust #[used(compiler)] #[used(linker)]
LLVM @llvm.compiler.used @llvm.used
ELF - SHT_GNU_RETAIN ("R" in Assembly)

Noratrieb avatar May 29 '25 16:05 Noratrieb

https://github.com/bytecodealliance/wasmtime/pull/11206 implements this on the Cranelift side and https://github.com/rust-lang/rustc_codegen_cranelift/tree/used_static has the cg_clif changes.

bjorn3 avatar Jul 09 '25 10:07 bjorn3