#Issue with static variable linking on lto=thin

1 messages · Page 1 of 1 (latest)

glacial wagon
#

crate/inner/src/lib.rs:```rs
mod aaa {
pub static mut AAA: *const std::os::raw::c_void = super::panic as *const std::os::raw::c_void;
}
#[allow(unused_variables, dead_code)] #[inline]
pub unsafe fn aaa() -> () { std::mem::transmute::<_, extern "system" fn() -> ()>(aaa::AAA)() }

fn panic() -> ! {
panic!("normal!")
} `crate/src/main.rs`:rs
fn main() {
unsafe {inner::aaa()};
}``` It doesn't link with lto="thin" like if the static is treated as a function, but does link otherwise.

#

Issue with static variable linking on lto=thin

boreal pendant
glacial wagon
#

Yes, but I had this exact issue in a crate I was using

#

Ignoring ABI

boreal pendant
#

I can’t reproduce

#

lib.rs: ```rs
mod aaa {
pub static mut AAA: *const std::os::raw::c_void = super::panic as *const std::os::raw::c_void;
}
#[allow(unused_variables, dead_code)]
#[inline]
pub unsafe fn aaa() {
std::mem::transmute::<_, fn()>(aaa::AAA)()
}

fn panic() { panic!("normal!") }
main.rs:rs
fn main() {
unsafe { lto::aaa() };
}
Cargo.toml:toml
[profile.release]
lto = "thin"
output:
$ cargo run --release
Compiling lto v0.1.0 (./lto)
Finished release [optimized] target(s) in 7.33s
Running target/release/lto
thread 'main' panicked at 'normal!', src/lib.rs:11:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

#

(same behaviour with the different ABIs too)

glacial wagon
#

I used windows-gnu

#

I will see if lld fixes it

boreal pendant
#

Ah, I see the error

#

This is such a specific bug, huh

#

So, minimized: ```rs
// lib.rs
#[inline]
pub fn aaa() {
static mut F: fn() = || {};
unsafe { F() };
}
// main.rs
fn main() {
lto::aaa();
}

#

and it only occurs:
• on x86_64-pc-windows-gnu
• With thin LTO
• With #[inline]
• With a static mut or UnsafeCell
• With a function pointer

#

Okay yeah, probably best to report this to rust-lang/rust

#

or should I? @glacial wagon

#

I don’t mind either way

glacial wagon
#

Maybe?

#

This exact issue happens on a crate I used

floral scarabBOT
#
gl

OpenGL bindings

Version

0.14.0

Downloads

739 117

glacial wagon
#

Ok, I'll make an issue @boreal pendant

boreal pendant
#

Post it here when you make it