Skip to content

Commit 172ba70

Browse files
committed
A collection of test cases showing how the new -C prefer-dynamic=crate,... flag can be used to resolve issue 82151.
These differ from the diamonds-*.rs in a couple of ways: * The most foundational library is being compiled to multiple crate output types, and * The most foundational library is being compiled to a `cdylib`, not a `dylib`. These two details seemed to be critical for reproducing the exact set of unfortunate link-time behaviors that we observed on issue 82151, as illustrated by the family of tests named `issue-82151-serverctl-*.rs`. ---- issue-82151-serverctl-prefdyn.rs works around ld-binary specific details by adding extra normalization to test, including normalizing stage number in output.
1 parent 8d63ba2 commit 172ba70

19 files changed

+335
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![crate_name="bar"]
2+
#![crate_type="rlib"]
3+
#![crate_type="cdylib"]
4+
5+
pub struct Bar;
6+
7+
pub fn bar() -> Bar {
8+
Bar
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name="bar"]
2+
#![crate_type="rlib"]
3+
#![crate_type="cdylib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub struct Bar;
8+
9+
pub fn bar() -> Bar {
10+
Bar
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name="bar"]
2+
#![crate_type="rlib"]
3+
#![crate_type="cdylib"]
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic
7+
8+
pub struct Bar;
9+
10+
pub fn bar() -> Bar {
11+
Bar
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name="bar"]
2+
#![crate_type="rlib"]
3+
#![crate_type="cdylib"]
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std
7+
8+
pub struct Bar;
9+
10+
pub fn bar() -> Bar {
11+
Bar
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name="bar"]
2+
#![crate_type="rlib"]
3+
#![crate_type="cdylib"]
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=shared,std -Z prefer-dynamic-subset
7+
8+
pub struct Bar;
9+
10+
pub fn bar() -> Bar {
11+
Bar
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_name="foo"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic
5+
6+
extern crate bar;
7+
8+
pub struct Foo;
9+
pub use bar::bar;
10+
11+
pub fn foo() -> Foo {
12+
Foo
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_name="foo"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic
6+
7+
extern crate bar;
8+
9+
pub struct Foo;
10+
pub use bar::bar;
11+
12+
pub fn foo() -> Foo {
13+
Foo
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_name="foo"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std
6+
7+
extern crate bar;
8+
9+
pub struct Foo;
10+
pub use bar::bar;
11+
12+
pub fn foo() -> Foo {
13+
Foo
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_name="foo"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic=shared,std -Z prefer-dynamic-subset
6+
7+
extern crate bar;
8+
9+
pub struct Foo;
10+
pub use bar::bar;
11+
12+
pub fn foo() -> Foo {
13+
Foo
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![crate_name="shared"]
2+
#![crate_type="dylib"]
3+
4+
// no-prefer-dynamic
5+
6+
extern crate foo;
7+
8+
pub struct Test;
9+
10+
impl Test {
11+
pub fn new() -> Self {
12+
let _ = foo::foo();
13+
let _ = foo::bar();
14+
// let _ = bar::bar();
15+
Self
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name="shared"]
2+
#![crate_type="dylib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic
6+
7+
extern crate foo;
8+
9+
pub struct Test;
10+
11+
impl Test {
12+
pub fn new() -> Self {
13+
let _ = foo::foo();
14+
let _ = foo::bar();
15+
// let _ = bar::bar();
16+
Self
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name="shared"]
2+
#![crate_type="dylib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std
6+
7+
extern crate foo;
8+
9+
pub struct Test;
10+
11+
impl Test {
12+
pub fn new() -> Self {
13+
let _ = foo::foo();
14+
let _ = foo::bar();
15+
// let _ = bar::bar();
16+
Self
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name="shared"]
2+
#![crate_type="dylib"]
3+
4+
// no-prefer-dynamic
5+
// compile-flags: -C prefer-dynamic=shared,std -Z prefer-dynamic-subset
6+
7+
extern crate foo;
8+
9+
pub struct Test;
10+
11+
impl Test {
12+
pub fn new() -> Self {
13+
let _ = foo::foo();
14+
let _ = foo::bar();
15+
// let _ = bar::bar();
16+
Self
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-fail
2+
3+
// no-prefer-dynamic
4+
5+
// aux-build: aaa_issue_82151_bar_noprefdyn.rs
6+
// aux-build: aaa_issue_82151_foo_noprefdyn.rs
7+
// aux-build: aaa_issue_82151_shared_noprefdyn.rs
8+
9+
extern crate shared;
10+
11+
fn main() {
12+
let _ = shared::Test::new();
13+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
error: cannot satisfy dependencies so `std` only shows up once (previously required dynamic, via [`issue_82151_serverctl_noprefdyn`], and now also requires static, via [`shared`])
2+
|
3+
= help: having upstream crates all available in one format will likely make this go away
4+
5+
error: cannot satisfy dependencies so `core` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
6+
|
7+
= help: having upstream crates all available in one format will likely make this go away
8+
9+
error: cannot satisfy dependencies so `compiler_builtins` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
10+
|
11+
= help: having upstream crates all available in one format will likely make this go away
12+
13+
error: cannot satisfy dependencies so `rustc_std_workspace_core` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
14+
|
15+
= help: having upstream crates all available in one format will likely make this go away
16+
17+
error: cannot satisfy dependencies so `alloc` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
18+
|
19+
= help: having upstream crates all available in one format will likely make this go away
20+
21+
error: cannot satisfy dependencies so `libc` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
22+
|
23+
= help: having upstream crates all available in one format will likely make this go away
24+
25+
error: cannot satisfy dependencies so `unwind` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
26+
|
27+
= help: having upstream crates all available in one format will likely make this go away
28+
29+
error: cannot satisfy dependencies so `cfg_if` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
30+
|
31+
= help: having upstream crates all available in one format will likely make this go away
32+
33+
error: cannot satisfy dependencies so `hashbrown` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
34+
|
35+
= help: having upstream crates all available in one format will likely make this go away
36+
37+
error: cannot satisfy dependencies so `rustc_std_workspace_alloc` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
38+
|
39+
= help: having upstream crates all available in one format will likely make this go away
40+
41+
error: cannot satisfy dependencies so `rustc_demangle` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
42+
|
43+
= help: having upstream crates all available in one format will likely make this go away
44+
45+
error: cannot satisfy dependencies so `std_detect` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
46+
|
47+
= help: having upstream crates all available in one format will likely make this go away
48+
49+
error: cannot satisfy dependencies so `addr2line` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
50+
|
51+
= help: having upstream crates all available in one format will likely make this go away
52+
53+
error: cannot satisfy dependencies so `gimli` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
54+
|
55+
= help: having upstream crates all available in one format will likely make this go away
56+
57+
error: cannot satisfy dependencies so `object` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
58+
|
59+
= help: having upstream crates all available in one format will likely make this go away
60+
61+
error: cannot satisfy dependencies so `miniz_oxide` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
62+
|
63+
= help: having upstream crates all available in one format will likely make this go away
64+
65+
error: cannot satisfy dependencies so `adler` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
66+
|
67+
= help: having upstream crates all available in one format will likely make this go away
68+
69+
error: cannot satisfy dependencies so `panic_unwind` only shows up once (two static copies from multiple different locations, via [`std`, `shared`])
70+
|
71+
= help: having upstream crates all available in one format will likely make this go away
72+
73+
error: cannot satisfy dependencies so `bar` only shows up once (previously required static, via [`shared`], and now also requires dynamic, via [`issue_82151_serverctl_noprefdyn`])
74+
|
75+
= help: having upstream crates all available in one format will likely make this go away
76+
77+
error: aborting due to 19 previous errors
78+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build-fail
2+
// normalize-stderr-test "note: .*undefined reference to `bar::bar'" -> "note: undefined reference to `bar::bar'"
3+
// normalize-stderr-test "note: .cc..*" -> "note: $$CC_INVOCATION"
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic
7+
8+
// aux-build: aaa_issue_82151_bar_prefdyn.rs
9+
// aux-build: aaa_issue_82151_foo_prefdyn.rs
10+
// aux-build: aaa_issue_82151_shared_prefdyn.rs
11+
12+
extern crate shared;
13+
14+
fn main() {
15+
let _ = shared::Test::new();
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: linking with `cc` failed: exit status: 1
2+
|
3+
= note: $CC_INVOCATION
4+
= note: undefined reference to `bar::bar'
5+
collect2: error: ld returned 1 exit status
6+
7+
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
8+
= note: use the `-l` flag to specify native libraries to link
9+
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
10+
11+
error: aborting due to previous error
12+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` flag to allow *only* `std` to be
4+
// linked dynamically via the rustc injected flags, and then also manually link
5+
// to `shared`.
6+
7+
// no-prefer-dynamic
8+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std -lshared
9+
10+
// aux-build: aaa_issue_82151_bar_prefdynstd.rs
11+
// aux-build: aaa_issue_82151_foo_prefdynstd.rs
12+
// aux-build: aaa_issue_82151_shared_prefdynstd.rs
13+
14+
extern crate shared;
15+
16+
fn main() {
17+
let _ = shared::Test::new();
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` to choose `shared` and `std` to be linked dynamically.
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=shared,std -Z prefer-dynamic-subset
7+
8+
// aux-build: aaa_issue_82151_bar_prefdynsubset.rs
9+
// aux-build: aaa_issue_82151_foo_prefdynsubset.rs
10+
// aux-build: aaa_issue_82151_shared_prefdynsubset.rs
11+
12+
extern crate shared;
13+
14+
fn main() {
15+
let _ = shared::Test::new();
16+
}

0 commit comments

Comments
 (0)