From 4dcb50169f7af2d97d0b59a6bb2d1bfc2cb4cfc7 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 13 Aug 2021 10:58:40 +0300 Subject: [PATCH] link: rely on the default metadata loader. --- crates/rustc_codegen_spirv/src/lib.rs | 19 +------------------ crates/rustc_codegen_spirv/src/link.rs | 24 ------------------------ 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index 2d4f8f8fd6..ce23c88b36 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -167,10 +167,9 @@ use rustc_codegen_ssa::traits::{ }; use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, ModuleKind}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::MetadataRef; use rustc_errors::{ErrorReported, FatalError, Handler}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; +use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, query, DefIdTree, Instance, InstanceDef, TyCtxt}; @@ -262,18 +261,6 @@ impl ThinBufferMethods for SpirvThinBuffer { } } -struct SpirvMetadataLoader; - -impl MetadataLoader for SpirvMetadataLoader { - fn get_rlib_metadata(&self, _: &Target, path: &Path) -> Result { - link::read_metadata(path) - } - - fn get_dylib_metadata(&self, target: &Target, path: &Path) -> Result { - rustc_codegen_ssa::back::metadata::DefaultMetadataLoader.get_dylib_metadata(target, path) - } -} - #[derive(Clone)] struct SpirvCodegenBackend; @@ -299,10 +286,6 @@ impl CodegenBackend for SpirvCodegenBackend { } } - fn metadata_loader(&self) -> Box { - Box::new(SpirvMetadataLoader) - } - fn provide(&self, providers: &mut query::Providers) { // This is a lil weird: so, we obviously don't support C ABIs at all. However, libcore does declare some extern // C functions: diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs index 2e13664c0e..2672798d83 100644 --- a/crates/rustc_codegen_spirv/src/link.rs +++ b/crates/rustc_codegen_spirv/src/link.rs @@ -8,9 +8,6 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul use rustc_codegen_ssa::back::write::CodegenContext; use rustc_codegen_ssa::{CodegenResults, NativeLib, METADATA_FILENAME}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::owning_ref::OwningRef; -use rustc_data_structures::rustc_erase_owner; -use rustc_data_structures::sync::MetadataRef; use rustc_errors::FatalError; use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; @@ -481,27 +478,6 @@ fn create_archive(files: &[&Path], metadata: &[u8], out_filename: &Path) { builder.into_inner().unwrap(); } -pub fn read_metadata(rlib: &Path) -> Result { - fn read_metadata_internal(rlib: &Path) -> Result, std::io::Error> { - let mut archive = Archive::new(File::open(rlib).unwrap()); - while let Some(entry) = archive.next_entry() { - let mut entry = entry?; - if entry.header().identifier() == METADATA_FILENAME.as_bytes() { - let mut bytes = Vec::new(); - entry.read_to_end(&mut bytes)?; - let buf: OwningRef, [u8]> = OwningRef::new(bytes); - return Ok(Some(rustc_erase_owner!(buf.map_owner_box()))); - } - } - Ok(None) - } - match read_metadata_internal(rlib) { - Ok(Some(m)) => Ok(m), - Ok(None) => Err(format!("No .metadata file in rlib: {:?}", rlib)), - Err(io) => Err(format!("Failed to read rlib at {:?}: {}", rlib, io)), - } -} - /// This is the actual guts of linking: the rest of the link-related functions are just digging through rustc's /// shenanigans to collect all the object files we need to link. fn do_link(