Skip to content

Commit f6195f5

Browse files
committed
Fix linkage1 test which fails due to --as-needed
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 linkage1 test was creating a dynamic library where it was only used for a weak-symbol as part of an executable, so the dynamic library was getting discarded. This commit adds another symbol to the library which satisfies a strong undefined symbol, so the library is pulled in to resolve the weak reference.
1 parent af93684 commit f6195f5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/test/auxiliary/linkage1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
#[no_mangle]
1212
pub static foo: int = 3;
13+
14+
pub fn bar() {}

src/test/run-pass/linkage1.rs

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ extern {
2626
}
2727

2828
fn main() {
29+
// It appears that the --as-needed flag to linkers will not pull in a dynamic
30+
// library unless it satisfies a non weak undefined symbol. The 'other' crate
31+
// is compiled as a dynamic library where it would only be used for a
32+
// weak-symbol as part of an executable, so the dynamic library woudl be
33+
// discarded. By adding and calling `other::bar`, we get around this problem.
34+
other::bar();
35+
2936
assert!(!foo.is_null());
3037
assert_eq!(unsafe { *foo }, 3);
3138
assert!(something_that_should_never_exist.is_null());

0 commit comments

Comments
 (0)