]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/linkage1.rs
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
[rust.git] / src / test / run-pass / linkage1.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-windows
12 // ignore-macos
13 // ignore-emscripten doesn't support this linkage
14 // aux-build:linkage1.rs
15
16 #![feature(linkage)]
17
18 extern crate linkage1 as other;
19
20 extern {
21     #[linkage = "extern_weak"]
22     static foo: *const isize;
23     #[linkage = "extern_weak"]
24     static something_that_should_never_exist: *mut isize;
25 }
26
27 fn main() {
28     // It appears that the --as-needed flag to linkers will not pull in a dynamic
29     // library unless it satisfies a non weak undefined symbol. The 'other' crate
30     // is compiled as a dynamic library where it would only be used for a
31     // weak-symbol as part of an executable, so the dynamic library would be
32     // discarded. By adding and calling `other::bar`, we get around this problem.
33     other::bar();
34
35     unsafe {
36         assert!(!foo.is_null());
37         assert_eq!(*foo, 3);
38         assert!(something_that_should_never_exist.is_null());
39     }
40 }