]> git.lizzy.rs Git - rust.git/blob - tests/ui/linkage-attr/linkage1.rs
Auto merge of #107529 - Zoxc:inline-tweak-profile, r=cjgillot
[rust.git] / tests / ui / linkage-attr / linkage1.rs
1 // run-pass
2 // ignore-windows
3 // ignore-macos
4 // ignore-emscripten doesn't support this linkage
5 // ignore-sgx weak linkage not permitted
6 // aux-build:linkage1.rs
7
8 #![feature(linkage)]
9
10 extern crate linkage1 as other;
11
12 extern "C" {
13     #[linkage = "extern_weak"]
14     static foo: *const isize;
15     #[linkage = "extern_weak"]
16     static something_that_should_never_exist: *mut isize;
17 }
18
19 fn main() {
20     // It appears that the --as-needed flag to linkers will not pull in a dynamic
21     // library unless it satisfies a non weak undefined symbol. The 'other' crate
22     // is compiled as a dynamic library where it would only be used for a
23     // weak-symbol as part of an executable, so the dynamic library would be
24     // discarded. By adding and calling `other::bar`, we get around this problem.
25     other::bar();
26
27     unsafe {
28         assert!(!foo.is_null());
29         assert_eq!(*foo, 3);
30         assert!(something_that_should_never_exist.is_null());
31     }
32 }