diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-06 13:40:00 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-06 13:53:39 -0800 |
| commit | 48b6aef6605794a9da0d9254960a91bbea0a0737 (patch) | |
| tree | 93abc56a14ed15074ac2f0358a2fd4d38e402ad0 | |
| parent | 0b56e9b1cb2fc00d7d9bc044e2a78b8fb12f2f1b (diff) | |
| download | rust-48b6aef6605794a9da0d9254960a91bbea0a0737.tar.gz rust-48b6aef6605794a9da0d9254960a91bbea0a0737.zip | |
rustc: Don't fall back to -L if using --extern
The compiler would previously fall back to using `-L` and normal lookup paths if a `--extern` path was specified but it did not match (wrong architecture, for example). This commit removes this behavior and forces the hand of the crate loader to *always* use the `--extern` path if specified, no matter whether it is correct or not. This fixes a bug today where the compiler's own libraries are favored in cross compilation by accident. For example when a crate using the crates.io version of `log` was cross compiled, Cargo would compile `log` for the target architecture. When loading the macros, however, the compiler currently favors using the *host* architecture (for plugins), and because the `--extern log=...` pointed at an rlib for the target architecture, that lookup failed. The crate loader then fell back on `-L` paths to find the compiler-used `log` crate (the wrong one!) and then a compile failure happened because the logging macros are slightly different.
| -rw-r--r-- | src/librustc/metadata/loader.rs | 12 | ||||
| -rw-r--r-- | src/test/run-make/use-extern-for-plugins/Makefile | 13 | ||||
| -rw-r--r-- | src/test/run-make/use-extern-for-plugins/bar.rs | 19 | ||||
| -rw-r--r-- | src/test/run-make/use-extern-for-plugins/baz.rs | 18 | ||||
| -rw-r--r-- | src/test/run-make/use-extern-for-plugins/foo.rs | 19 |
5 files changed, 72 insertions, 9 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index d30df131d4d..6d94f075290 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -357,9 +357,8 @@ impl<'a> Context<'a> { // must be loaded via -L plus some filtering. if self.hash.is_none() { self.should_match_name = false; - match self.find_commandline_library() { - Some(l) => return Some(l), - None => {} + if let Some(s) = self.sess.opts.externs.get(self.crate_name) { + return self.find_commandline_library(s); } self.should_match_name = true; } @@ -596,12 +595,7 @@ impl<'a> Context<'a> { (t.options.dll_prefix.clone(), t.options.dll_suffix.clone()) } - fn find_commandline_library(&mut self) -> Option<Library> { - let locs = match self.sess.opts.externs.get(self.crate_name) { - Some(s) => s, - None => return None, - }; - + fn find_commandline_library(&mut self, locs: &[String]) -> Option<Library> { // First, filter out all libraries that look suspicious. We only accept // files which actually exist that have the correct naming scheme for // rlibs/dylibs. diff --git a/src/test/run-make/use-extern-for-plugins/Makefile b/src/test/run-make/use-extern-for-plugins/Makefile new file mode 100644 index 00000000000..84032b45159 --- /dev/null +++ b/src/test/run-make/use-extern-for-plugins/Makefile @@ -0,0 +1,13 @@ +-include ../tools.mk + +HOST := $(shell $(RUSTC) -vV | grep 'host:' | sed 's/host: //') +ifeq ($(findstring i686,$(HOST)),i686) +TARGET := $(subst i686,x86_64,$(HOST)) +else +TARGET := $(subst x86_64,i686,$(HOST)) +endif + +all: + $(RUSTC) foo.rs -C extra-filename=-host + $(RUSTC) bar.rs -C extra-filename=-targ --target $(TARGET) + $(RUSTC) baz.rs --extern a=$(TMPDIR)/liba-targ.rlib --target $(TARGET) diff --git a/src/test/run-make/use-extern-for-plugins/bar.rs b/src/test/run-make/use-extern-for-plugins/bar.rs new file mode 100644 index 00000000000..f279893b77b --- /dev/null +++ b/src/test/run-make/use-extern-for-plugins/bar.rs @@ -0,0 +1,19 @@ +// 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. + +#![feature(no_std)] +#![no_std] +#![crate_type = "lib"] +#![crate_name = "a"] + +#[macro_export] +macro_rules! bar { + () => () +} diff --git a/src/test/run-make/use-extern-for-plugins/baz.rs b/src/test/run-make/use-extern-for-plugins/baz.rs new file mode 100644 index 00000000000..89d6c6bc58c --- /dev/null +++ b/src/test/run-make/use-extern-for-plugins/baz.rs @@ -0,0 +1,18 @@ +// 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. + +#![feature(no_std)] +#![no_std] +#![crate_type = "lib"] + +#[macro_use] +extern crate a; + +bar!(); diff --git a/src/test/run-make/use-extern-for-plugins/foo.rs b/src/test/run-make/use-extern-for-plugins/foo.rs new file mode 100644 index 00000000000..554c0fe0326 --- /dev/null +++ b/src/test/run-make/use-extern-for-plugins/foo.rs @@ -0,0 +1,19 @@ +// 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. + +#![feature(no_std)] +#![no_std] +#![crate_type = "lib"] +#![crate_name = "a"] + +#[macro_export] +macro_rules! foo { + () => () +} |
