File tree Expand file tree Collapse file tree 5 files changed +82
-0
lines changed
src/test/run-make-fulldeps/redundant-libs Expand file tree Collapse file tree 5 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ -include ../tools.mk
2+ RUSTC_FLAGS = \
3+ -l static=bar \
4+ -l foo \
5+ -l static=baz \
6+ -l foo \
7+ -Z print-link-args
8+
9+ all : $(call DYLIB,foo) $(call STATICLIB,bar) $(call STATICLIB,baz)
10+ $(RUSTC ) $(RUSTC_FLAGS ) main.rs
11+ $(call RUN,main)
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ void bar () {
12+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ extern void foo1 ();
12+ extern void foo2 ();
13+
14+ void baz () {
15+ foo1 ();
16+ foo2 ();
17+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ void foo1 () {}
12+ void foo2 () {}
Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ // rustc will remove one of the two redundant references to foo below. Depending on which one gets
12+ // removed, we'll get a linker error on SOME platforms (like Linux). On these platforms, when a
13+ // library is referenced, the linker will only pull in the symbols needed _at that point in time_.
14+ // If a later library depends on additional symbols from the library, they will not have been
15+ // pulled in, and you'll get undefined symbols errors.
16+ //
17+ // So in this example, we need to ensure that rustc keeps the _later_ reference to foo, and not the
18+ // former one.
19+
20+ extern "C" {
21+ fn bar ( ) ;
22+ fn baz ( ) ;
23+ }
24+
25+ fn main ( ) {
26+ unsafe {
27+ bar ( ) ;
28+ baz ( ) ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments