Skip to content

Commit 4cdc6ce

Browse files
committed
rustc: Don't deduplicate libraries linked to
Linker argument order with respect to libraries is important enough that we shouldn't be attempting to filter out libraries getting passed through to the linker. When linking with a native library that has multiple dependant native libraries, it's useful to have control over the link argument order.
1 parent a15448c commit 4cdc6ce

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,10 @@ impl CStore {
154154
.collect()
155155
}
156156

157-
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind)
158-
-> bool {
157+
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {
159158
assert!(!lib.is_empty());
160159
let mut used_libraries = self.used_libraries.borrow_mut();
161-
if used_libraries.get().iter().any(|&(ref x, _)| x == &lib) {
162-
return false;
163-
}
164160
used_libraries.get().push((lib, kind));
165-
true
166161
}
167162

168163
pub fn get_used_libraries<'a>(&'a self)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all: $(call STATICLIB,foo) $(call STATICLIB,bar)
4+
$(RUSTC) main.rs
5+
$(call RUN,main)
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern void foo();
2+
3+
void bar() { foo(); }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void foo() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 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+
#[link(name = "foo")]
12+
#[link(name = "bar")]
13+
#[link(name = "foo")]
14+
extern {
15+
fn bar();
16+
}
17+
18+
fn main() {
19+
unsafe { bar() }
20+
}

0 commit comments

Comments
 (0)