Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jul 19, 2023
1 parent aa98c5d commit 8c9a8b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,15 @@ pub fn create_compressed_metadata_file(
metadata: &EncodedMetadata,
symbol_name: &str,
) -> Vec<u8> {
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
compressed.write_all(&(metadata.raw_data().len() as u32).to_be_bytes()).unwrap();
compressed.extend(metadata.raw_data());
let mut packed_metadata = rustc_metadata::METADATA_HEADER.to_vec();
packed_metadata.write_all(&(metadata.raw_data().len() as u32).to_be_bytes()).unwrap();
packed_metadata.extend(metadata.raw_data());

let Some(mut file) = create_object_file(sess) else {
return compressed.to_vec();
return packed_metadata.to_vec();
};
if file.format() == BinaryFormat::Xcoff {
return create_compressed_metadata_file_for_xcoff(file, &compressed, symbol_name);
return create_compressed_metadata_file_for_xcoff(file, &packed_metadata, symbol_name);
}
let section = file.add_section(
file.segment_name(StandardSegment::Data).to_vec(),
Expand All @@ -501,14 +501,14 @@ pub fn create_compressed_metadata_file(
}
_ => {}
};
let offset = file.append_section_data(section, &compressed, 1);
let offset = file.append_section_data(section, &packed_metadata, 1);

// For MachO and probably PE this is necessary to prevent the linker from throwing away the
// .rustc section. For ELF this isn't necessary, but it also doesn't harm.
file.add_symbol(Symbol {
name: symbol_name.as_bytes().to_vec(),
value: offset,
size: compressed.len() as u64,
size: packed_metadata.len() as u64,
kind: SymbolKind::Data,
scope: SymbolScope::Dynamic,
weak: false,
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl<'a> CrateLocator<'a> {
rlib: self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot)?,
dylib: self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot)?,
};
Ok(slot.map(|(_, svh, metadata)| (svh, Library { source, metadata })))
Ok(slot.map(|(svh, metadata, _)| (svh, Library { source, metadata })))
}

fn needs_crate_flavor(&self, flavor: CrateFlavor) -> bool {
Expand All @@ -535,11 +535,13 @@ impl<'a> CrateLocator<'a> {
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
// be read, it is assumed that the file isn't a valid rust library (no
// errors are emitted).
//
// The `PathBuf` in `slot` will only be used for diagnostic purposes.
fn extract_one(
&mut self,
m: FxHashMap<PathBuf, PathKind>,
flavor: CrateFlavor,
slot: &mut Option<(PathBuf, Svh, MetadataBlob)>,
slot: &mut Option<(Svh, MetadataBlob, PathBuf)>,
) -> Result<Option<(PathBuf, PathKind)>, CrateError> {
// If we are producing an rlib, and we've already loaded metadata, then
// we should not attempt to discover further crate sources (unless we're
Expand Down Expand Up @@ -595,15 +597,15 @@ impl<'a> CrateLocator<'a> {
}
};
// If we see multiple hashes, emit an error about duplicate candidates.
if slot.as_ref().is_some_and(|s| s.1 != hash) {
if slot.as_ref().is_some_and(|s| s.0 != hash) {
if let Some(candidates) = err_data {
return Err(CrateError::MultipleCandidates(
self.crate_name,
flavor,
candidates,
));
}
err_data = Some(vec![slot.take().unwrap().0]);
err_data = Some(vec![slot.take().unwrap().2]);
}
if let Some(candidates) = &mut err_data {
candidates.push(lib);
Expand Down Expand Up @@ -636,7 +638,7 @@ impl<'a> CrateLocator<'a> {
continue;
}
}
*slot = Some((lib.clone(), hash, metadata));
*slot = Some((hash, metadata, lib.clone()));
ret = Some((lib, kind));
}

Expand Down

0 comments on commit 8c9a8b6

Please sign in to comment.