about summary refs log tree commit diff
path: root/tests/ui/linking/executable-no-mangle-strip.rs
blob: cc283dc53ee3a8ac578226c479cabba8ae89b11b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//@ run-pass
//@ ignore-windows-gnu: only statics marked with used can be GC-ed on windows-gnu

// Regression test for <https://github.com/rust-lang/rust/issues/139744>.
// Functions in the binary marked with no_mangle should be GC-ed if they
// are not indirectly referenced by main.

#![feature(used_with_arg)]

#[cfg_attr(windows, link(name = "this_lib_does_not_exist", kind = "raw-dylib"))]
unsafe extern "C" {
    unsafe static THIS_SYMBOL_SHOULD_BE_UNDEFINED: usize;
}

#[unsafe(no_mangle)]
pub unsafe fn function_marked_with_no_mangle() {
    println!("FUNCTION_MARKED_WITH_NO_MANGLE = {}", unsafe { THIS_SYMBOL_SHOULD_BE_UNDEFINED });
}

#[used(compiler)]
pub static FUNCTION_MARKED_WITH_USED: unsafe fn() = || {
    println!("FUNCTION_MARKED_WITH_USED = {}", unsafe { THIS_SYMBOL_SHOULD_BE_UNDEFINED });
};

fn main() {
    println!("MAIN");
}