未验证 提交 a2500db8 编写于 作者: M Mazdak Farrokhzad 提交者: GitHub

Rollup merge of #62286 - petrhosek:rustc-no-duplicate-archives, r=cramertj

Check if the archive has already been added to avoid duplicates

This avoids adding archives multiple times, which results in duplicate
objects in the resulting rlib, leading to symbol collision and link
failures. This could happen when crate contains multiple link attributes
that all reference the same archive.
......@@ -36,11 +36,20 @@ enum Addition {
name_in_archive: String,
},
Archive {
path: PathBuf,
archive: ArchiveRO,
skip: Box<dyn FnMut(&str) -> bool>,
},
}
impl Addition {
fn path(&self) -> &Path {
match self {
Addition::File { path, .. } | Addition::Archive { path, .. } => path,
}
}
}
fn is_relevant_child(c: &Child<'_>) -> bool {
match c.name() {
Some(name) => !name.contains("SYMDEF"),
......@@ -188,12 +197,16 @@ fn add_archive<F>(&mut self, archive: &Path, skip: F)
-> io::Result<()>
where F: FnMut(&str) -> bool + 'static
{
let archive = match ArchiveRO::open(archive) {
let archive_ro = match ArchiveRO::open(archive) {
Ok(ar) => ar,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
if self.additions.iter().any(|ar| ar.path() == archive) {
return Ok(())
}
self.additions.push(Addition::Archive {
archive,
path: archive.to_path_buf(),
archive: archive_ro,
skip: Box::new(skip),
});
Ok(())
......@@ -243,7 +256,7 @@ fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
strings.push(path);
strings.push(name);
}
Addition::Archive { archive, skip } => {
Addition::Archive { archive, skip, .. } => {
for child in archive.iter() {
let child = child.map_err(string_to_io_error)?;
if !is_relevant_child(&child) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册