summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-29 07:38:50 +0000
committerbors <bors@rust-lang.org>2019-10-29 07:38:50 +0000
commiteb5ef813f0d6e3fe8edd3abb046a18f5b1a8cc48 (patch)
tree09f496e9fb2a3c149deb5c2e19b4f421a56b0a12 /src/librustc_codegen_ssa
parent2dd4e7320e620dc9a59423c55a7db3520ba8b553 (diff)
parenta63dfb3b82a44e31bdfadb13d240a5366f9979fb (diff)
downloadrust-eb5ef813f0d6e3fe8edd3abb046a18f5b1a8cc48.tar.gz
rust-eb5ef813f0d6e3fe8edd3abb046a18f5b1a8cc48.zip
Auto merge of #65435 - michaelwoerister:fix-issue-64153, r=alexcrichton
Fix #64153

This PR changes how the compiler detects if an object file from an upstream crate is a Rust object file or not. Instead of checking if the name starts with the crate name and ends with `.o` (which is not always the case, as described in #64153), it now just checks if the filename ends with `.rcgu.o`.

This fixes #64153. However, ideally we'd clean up the code around filename generation some more. Then this check could be made more robust.

r? @alexcrichton
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/back/link.rs21
-rw-r--r--src/librustc_codegen_ssa/lib.rs24
2 files changed, 26 insertions, 19 deletions
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
index 1c5d3b1a890..a2b50ea8e2b 100644
--- a/src/librustc_codegen_ssa/back/link.rs
+++ b/src/librustc_codegen_ssa/back/link.rs
@@ -3,7 +3,7 @@
 
 use rustc::session::{Session, filesearch};
 use rustc::session::config::{
-    self, RUST_CGU_EXT, DebugInfo, OutputFilenames, OutputType, PrintRequest, Sanitizer
+    self, DebugInfo, OutputFilenames, OutputType, PrintRequest, Sanitizer
 };
 use rustc::session::search_paths::PathKind;
 use rustc::middle::dependency_format::Linkage;
@@ -15,7 +15,8 @@ use rustc_fs_util::fix_windows_verbatim_for_gcc;
 use rustc_target::spec::{PanicStrategy, RelroLevel, LinkerFlavor};
 use syntax::symbol::Symbol;
 
-use crate::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION, CrateInfo, CodegenResults};
+use crate::{METADATA_FILENAME, RLIB_BYTECODE_EXTENSION, CrateInfo,
+    looks_like_rust_object_file, CodegenResults};
 use super::archive::ArchiveBuilder;
 use super::command::Command;
 use super::linker::Linker;
@@ -1549,23 +1550,9 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
                 let canonical = f.replace("-", "_");
                 let canonical_name = name.replace("-", "_");
 
-                // Look for `.rcgu.o` at the end of the filename to conclude
-                // that this is a Rust-related object file.
-                fn looks_like_rust(s: &str) -> bool {
-                    let path = Path::new(s);
-                    let ext = path.extension().and_then(|s| s.to_str());
-                    if ext != Some(OutputType::Object.extension()) {
-                        return false
-                    }
-                    let ext2 = path.file_stem()
-                        .and_then(|s| Path::new(s).extension())
-                        .and_then(|s| s.to_str());
-                    ext2 == Some(RUST_CGU_EXT)
-                }
-
                 let is_rust_object =
                     canonical.starts_with(&canonical_name) &&
-                    looks_like_rust(&f);
+                    looks_like_rust_object_file(&f);
 
                 // If we've been requested to skip all native object files
                 // (those not generated by the rust compiler) then we can skip
diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs
index 0221a04b045..dd75883f97d 100644
--- a/src/librustc_codegen_ssa/lib.rs
+++ b/src/librustc_codegen_ssa/lib.rs
@@ -22,9 +22,9 @@
 #[macro_use] extern crate rustc;
 #[macro_use] extern crate syntax;
 
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 use rustc::dep_graph::WorkProduct;
-use rustc::session::config::{OutputFilenames, OutputType};
+use rustc::session::config::{OutputFilenames, OutputType, RUST_CGU_EXT};
 use rustc::middle::lang_items::LangItem;
 use rustc::hir::def_id::CrateNum;
 use rustc::ty::query::Providers;
@@ -62,6 +62,7 @@ pub struct ModuleCodegen<M> {
 pub const METADATA_FILENAME: &str = "rust.metadata.bin";
 pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";
 
+
 impl<M> ModuleCodegen<M> {
     pub fn into_compiled_module(self,
                             emit_obj: bool,
@@ -166,3 +167,22 @@ pub fn provide_extern(providers: &mut Providers<'_>) {
     crate::back::symbol_export::provide_extern(providers);
     crate::base::provide_both(providers);
 }
+
+/// Checks if the given filename ends with the `.rcgu.o` extension that `rustc`
+/// uses for the object files it generates.
+pub fn looks_like_rust_object_file(filename: &str) -> bool {
+    let path = Path::new(filename);
+    let ext = path.extension().and_then(|s| s.to_str());
+    if ext != Some(OutputType::Object.extension()) {
+        // The file name does not end with ".o", so it can't be an object file.
+        return false
+    }
+
+    // Strip the ".o" at the end
+    let ext2 = path.file_stem()
+        .and_then(|s| Path::new(s).extension())
+        .and_then(|s| s.to_str());
+
+    // Check if the "inner" extension
+    ext2 == Some(RUST_CGU_EXT)
+}