2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
2014-08-11 23:24:19 +00:00
|
|
|
// ignore-windows
|
2014-02-26 00:15:10 +00:00
|
|
|
// ignore-macos
|
2017-10-18 01:45:42 +00:00
|
|
|
// ignore-emscripten doesn't support this linkage
|
2019-04-24 16:26:33 +00:00
|
|
|
// ignore-sgx weak linkage not permitted
|
2014-02-26 00:15:10 +00:00
|
|
|
// aux-build:linkage1.rs
|
|
|
|
|
2014-04-04 00:55:06 +00:00
|
|
|
#![feature(linkage)]
|
2014-02-26 00:15:10 +00:00
|
|
|
|
2015-03-27 17:58:12 +00:00
|
|
|
extern crate linkage1 as other;
|
2014-02-26 00:15:10 +00:00
|
|
|
|
2020-09-01 21:12:52 +00:00
|
|
|
extern "C" {
|
2014-02-26 00:15:10 +00:00
|
|
|
#[linkage = "extern_weak"]
|
2015-03-26 00:06:52 +00:00
|
|
|
static foo: *const isize;
|
2014-02-26 00:15:10 +00:00
|
|
|
#[linkage = "extern_weak"]
|
2015-03-26 00:06:52 +00:00
|
|
|
static something_that_should_never_exist: *mut isize;
|
2014-02-26 00:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-03-17 21:54:35 +00:00
|
|
|
// It appears that the --as-needed flag to linkers will not pull in a dynamic
|
|
|
|
// library unless it satisfies a non weak undefined symbol. The 'other' crate
|
|
|
|
// is compiled as a dynamic library where it would only be used for a
|
2014-08-01 23:42:13 +00:00
|
|
|
// weak-symbol as part of an executable, so the dynamic library would be
|
2014-03-17 21:54:35 +00:00
|
|
|
// discarded. By adding and calling `other::bar`, we get around this problem.
|
|
|
|
other::bar();
|
|
|
|
|
2017-07-08 00:01:11 +00:00
|
|
|
unsafe {
|
|
|
|
assert!(!foo.is_null());
|
|
|
|
assert_eq!(*foo, 3);
|
|
|
|
assert!(something_that_should_never_exist.is_null());
|
|
|
|
}
|
2014-02-26 00:15:10 +00:00
|
|
|
}
|