]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #57018 - dcreager:redundant-linker, r=alexcrichton
authorbors <bors@rust-lang.org>
Wed, 20 Mar 2019 14:42:47 +0000 (14:42 +0000)
committerbors <bors@rust-lang.org>
Wed, 20 Mar 2019 14:42:47 +0000 (14:42 +0000)
Keep last redundant linker flag, not first

When a library (L1) is passed to the linker multiple times, this is sometimes purposeful: there might be several other libraries in the linker command (L2 and L3) that all depend on L1.  You'd end up with a (simplified) linker command that looks like:

```
-l2 -l1 -l3 -l1
```

With the previous behavior, when rustc encountered a redundant library, it would keep the first instance, and remove the later ones, resulting in:

```
-l2 -l1 -l3
```

This can cause a linker error, because on some platforms (e.g. Linux), the linker will only include symbols from L1 that are needed *at the point it's referenced in the command line*.  So if L3 depends on additional symbols from L1, which aren't needed by L2, the linker won't know to include them, and you'll end up with "undefined symbols" errors.

A better behavior is to keep the *last* instance of the library:

```
-l2 -l3 -l1
```

This ensures that all "downstream" libraries have been included in the linker command before the "upstream" library is referenced.

Fixes rust-lang#47989

1  2 
src/librustc_metadata/lib.rs
src/librustc_metadata/native_libs.rs

index b4f68399d9febc59aaca4163b6dd1b186e515234,480c344f38123be10fac238979946fc444326066..14416b5ce075950573f843416fe02e6c99f2d20a
@@@ -1,6 -1,19 +1,7 @@@
 -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
 -// file at the top-level directory of this distribution and at
 -// http://rust-lang.org/COPYRIGHT.
 -//
 -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 -// option. This file may not be copied, modified, or distributed
 -// except according to those terms.
 -
 -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
 -       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
 -       html_root_url = "https://doc.rust-lang.org/nightly/")]
 +#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
  
  #![feature(box_patterns)]
+ #![feature(drain_filter)]
  #![feature(libc)]
  #![feature(nll)]
  #![feature(proc_macro_internals)]
Simple merge