Skip to content

Commit

Permalink
Fix linkage1 test which fails due to --as-needed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nrc authored and alexcrichton committed Mar 18, 2014
1 parent 083d423 commit 3301223
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/test/auxiliary/linkage1.rs
Expand Up @@ -10,3 +10,5 @@

#[no_mangle]
pub static foo: int = 3;

pub fn bar() {}
7 changes: 7 additions & 0 deletions src/test/run-pass/linkage1.rs
Expand Up @@ -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());
Expand Down

0 comments on commit 3301223

Please sign in to comment.