Fix review comments
This commit is contained in:
parent
aa98c5d14e
commit
8c9a8b63c9
2 changed files with 14 additions and 12 deletions
|
@ -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(),
|
||||
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -595,7 +597,7 @@ 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,
|
||||
|
@ -603,7 +605,7 @@ impl<'a> CrateLocator<'a> {
|
|||
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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue