]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/linkage1.rs
Merge branch 'master' into cfg_tmp_dir
[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-android
13 // ignore-macos
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 int;
23     #[linkage = "extern_weak"]
24     static something_that_should_never_exist: *mut int;
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     assert!(!foo.is_null());
36     assert_eq!(unsafe { *foo }, 3);
37     assert!(something_that_should_never_exist.is_null());
38 }