diff options
| author | bors <bors@rust-lang.org> | 2014-03-20 08:21:46 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-20 08:21:46 -0700 |
| commit | c01e2f05a3ef27e464d1f0057ddabcde6ffde70c (patch) | |
| tree | 406e59332c306f95e106320f69d7e95c8e1f6b43 /src | |
| parent | 8cfef59cc0922f15979bf4e8a0b344cecfa8d9e2 (diff) | |
| parent | 068740b3433099d148c8e2d4bcc9b25309f40701 (diff) | |
| download | rust-c01e2f05a3ef27e464d1f0057ddabcde6ffde70c.tar.gz rust-c01e2f05a3ef27e464d1f0057ddabcde6ffde70c.zip | |
auto merge of #13017 : alexcrichton/rust/issue-13010, r=huonw
Previously, any library of the pattern `lib<name>-<hash>-<version>.so` was >considered a candidate (rightly so) for loading a crate. Sets are generated for each unique `<hash>`, and then from these sets a candidate is selected. If a set contained more than one element, then it immediately generated an error saying that multiple copies of the same dylib were found. This is incorrect because each candidate needs to be validated to actually contain a rust library (valid metadata). This commit alters the logic to filter each set of candidates for a hash to only libraries which are actually rust libraries. This means that if multiple false positives are found with the right name pattern, they're all ignored. Closes #13010
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/metadata/loader.rs | 46 | ||||
| -rw-r--r-- | src/test/run-make/suspicious-library/Makefile | 7 | ||||
| -rw-r--r-- | src/test/run-make/suspicious-library/bar.rs | 13 | ||||
| -rw-r--r-- | src/test/run-make/suspicious-library/foo.rs | 13 |
4 files changed, 60 insertions, 19 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 6a1e3663a54..eb47b30b9c0 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -284,38 +284,46 @@ impl<'a> Context<'a> { // reading dylib metadata is quite slow. fn extract_one(&mut self, m: HashSet<Path>, flavor: &str, slot: &mut Option<MetadataBlob>) -> Option<Path> { - if m.len() == 0 { return None } - if m.len() > 1 { - self.sess.span_err(self.span, - format!("multiple {} candidates for `{}` \ - found", flavor, self.crate_id.name)); - for (i, path) in m.iter().enumerate() { - self.sess.span_note(self.span, - format!(r"candidate \#{}: {}", i + 1, - path.display())); - } - return None - } + let mut ret = None::<Path>; + let mut error = 0; - let lib = m.move_iter().next().unwrap(); - if slot.is_none() { + for lib in m.move_iter() { info!("{} reading metadata from: {}", flavor, lib.display()); - match get_metadata_section(self.os, &lib) { + let metadata = match get_metadata_section(self.os, &lib) { Ok(blob) => { if self.crate_matches(blob.as_slice()) { - *slot = Some(blob); + blob } else { info!("metadata mismatch"); - return None; + continue } } Err(_) => { info!("no metadata found"); - return None + continue } + }; + if ret.is_some() { + self.sess.span_err(self.span, + format!("multiple {} candidates for `{}` \ + found", flavor, self.crate_id.name)); + self.sess.span_note(self.span, + format!(r"candidate \#1: {}", + ret.get_ref().display())); + error = 1; + ret = None; + } + if error > 0 { + error += 1; + self.sess.span_note(self.span, + format!(r"candidate \#{}: {}", error, + lib.display())); + continue } + *slot = Some(metadata); + ret = Some(lib); } - return Some(lib); + return if error > 0 {None} else {ret} } fn crate_matches(&mut self, crate_data: &[u8]) -> bool { diff --git a/src/test/run-make/suspicious-library/Makefile b/src/test/run-make/suspicious-library/Makefile new file mode 100644 index 00000000000..621f3064b5c --- /dev/null +++ b/src/test/run-make/suspicious-library/Makefile @@ -0,0 +1,7 @@ +-include ../tools.mk + +all: + $(RUSTC) foo.rs + touch $(call DYLIB,foo-something-special) + touch $(call DYLIB,foo-something-special2) + $(RUSTC) bar.rs diff --git a/src/test/run-make/suspicious-library/bar.rs b/src/test/run-make/suspicious-library/bar.rs new file mode 100644 index 00000000000..ed0e8a7e23e --- /dev/null +++ b/src/test/run-make/suspicious-library/bar.rs @@ -0,0 +1,13 @@ +// Copyright 2014 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. + +extern crate foo; + +fn main() { foo::foo() } diff --git a/src/test/run-make/suspicious-library/foo.rs b/src/test/run-make/suspicious-library/foo.rs new file mode 100644 index 00000000000..890fd3a7dd6 --- /dev/null +++ b/src/test/run-make/suspicious-library/foo.rs @@ -0,0 +1,13 @@ +// Copyright 2014 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. + +#[crate_type = "dylib"]; + +pub fn foo() {} |
