Skip to content

Commit cfa95fa

Browse files
committed
Always check if the SVH of rlib and dylibs matches other crate sources
If a crate is both an rlib and cdylib, the metadata loader would previously incorrectly assume that it is possible to link against the cdylib. Cdylibs don't export all symbols required for linking as rust library. Possibly fixes issue number 82151
1 parent fb6da33 commit cfa95fa

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

compiler/rustc_metadata/src/locator.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,8 @@ impl<'a> CrateLocator<'a> {
503503
// the errors and notes are emitted about the set of libraries.
504504
//
505505
// With only one library in the set, this function will extract it, and then
506-
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
507-
// be read, it is assumed that the file isn't a valid rust library (no
508-
// errors are emitted).
506+
// read the metadata from it. If the metadata couldn't be read, it is assumed
507+
// that the file isn't a valid rust library (no errors are emitted).
509508
fn extract_one(
510509
&mut self,
511510
m: FxHashMap<PathBuf, PathKind>,
@@ -521,17 +520,8 @@ impl<'a> CrateLocator<'a> {
521520
//
522521
// See also #68149 which provides more detail on why emitting the
523522
// dependency on the rlib is a bad thing.
524-
//
525-
// We currently do not verify that these other sources are even in sync,
526-
// and this is arguably a bug (see #10786), but because reading metadata
527-
// is quite slow (especially from dylibs) we currently do not read it
528-
// from the other crate sources.
529-
if slot.is_some() {
530-
if m.is_empty() || !self.needs_crate_flavor(flavor) {
531-
return Ok(None);
532-
} else if m.len() == 1 {
533-
return Ok(Some(m.into_iter().next().unwrap()));
534-
}
523+
if slot.is_some() && !self.needs_crate_flavor(flavor) {
524+
return Ok(None);
535525
}
536526

537527
let mut ret: Option<(PathBuf, PathKind)> = None;

0 commit comments

Comments
 (0)