diff --git a/src/test/auxiliary/linkage1.rs b/src/test/auxiliary/linkage1.rs index 9017ee88363b7..a74c8c47cd9b7 100644 --- a/src/test/auxiliary/linkage1.rs +++ b/src/test/auxiliary/linkage1.rs @@ -10,3 +10,5 @@ #[no_mangle] pub static foo: int = 3; + +pub fn bar() {} diff --git a/src/test/run-pass/linkage1.rs b/src/test/run-pass/linkage1.rs index 8f8b0cfecb28d..c6f672c5d34d0 100644 --- a/src/test/run-pass/linkage1.rs +++ b/src/test/run-pass/linkage1.rs @@ -26,6 +26,13 @@ extern { } fn main() { + // 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 + // weak-symbol as part of an executable, so the dynamic library woudl be + // discarded. By adding and calling `other::bar`, we get around this problem. + other::bar(); + assert!(!foo.is_null()); assert_eq!(unsafe { *foo }, 3); assert!(something_that_should_never_exist.is_null());