You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Use section symbols for relocations where required to avoid preemption.
// Otherwise, the linker will fail with:
// relocation R_X86_64_PC32 against symbol `SomeSymbolName' can not be used when
// making a shared object; recompile with -fPIC
let symbol = &self.symbols[relocation.symbol.0];
ifwant_section_symbol(relocation, symbol){
ifletSome(section) = symbol.section.id(){
relocation.addend += symbol.valueasi64;
relocation.symbol = self.section_symbol(section);
}
}
The problem that this hack works around is that cranelift is emitting R_X86_64_PC32 relocations for preemptible symbols. The proper solution is that either cranelift should not emit these relocations (and use things like PLT relocations instead), or cranelift should tell object that the symbol is not preemptible (although there's no way to do that currently).
An initial solution would be to delete the hack and change object to set STV_PROTECTED for all exported symbols so that they are never preemptible, which matches what cranelift is expecting. We can then later add a way to control this, and fix cranelift and rustc_codegen_cranelift to agree with each other about weak and preemptible symbols.
Using STV_PROTECTED isn't a solution either, since ld.bfd still generates the error (because function pointers should go via the GOT even for protected symbols so that pointer comparisons work).
As part of working on #585, it would be nice to delete this hack:
object/src/write/elf/object.rs
Lines 188 to 198 in 32888b4
The problem that this hack works around is that cranelift is emitting
R_X86_64_PC32
relocations for preemptible symbols. The proper solution is that either cranelift should not emit these relocations (and use things like PLT relocations instead), or cranelift should tellobject
that the symbol is not preemptible (although there's no way to do that currently).cranelift already has
Linkage::Preemptible
to control whether it emits these relocations. However, this is currently being passed on toobject
as a request for a weak symbol, which is a different concept:https://github.com/bytecodealliance/wasmtime/blob/e0bfa7336de20f76048edbdc0157ee637a2c5fea/cranelift/object/src/backend.rs#L902-L903
and the reason that code was written like that is because
rustc_codegen_cranelift
translates rust's weak linkage intoLinkage::Preemptible
, which I think is wrong:https://github.com/rust-lang/rustc_codegen_cranelift/blob/48ca2d9703742149aa33b3f84ae933d063213d19/src/linkage.rs#L16
An initial solution would be to delete the hack and change
object
to setSTV_PROTECTED
for all exported symbols so that they are never preemptible, which matches what cranelift is expecting. We can then later add a way to control this, and fix cranelift and rustc_codegen_cranelift to agree with each other about weak and preemptible symbols.cc @bjorn3
The text was updated successfully, but these errors were encountered: