Rollup merge of #118905 - bzEq:revert-u64-on-xcoff, r=WaffleLapkin
[AIX] Fix XCOFF metadata #118344 accidentally changed the way to get metadata from XCOFF file and broken our internal CI. This PR reverts part of #118344 .
This commit is contained in:
commit
18294d6e1d
@ -158,12 +158,13 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
|
|||||||
file.symbols().find(|sym| sym.name() == Ok(AIX_METADATA_SYMBOL_NAME))
|
file.symbols().find(|sym| sym.name() == Ok(AIX_METADATA_SYMBOL_NAME))
|
||||||
{
|
{
|
||||||
let offset = metadata_symbol.address() as usize;
|
let offset = metadata_symbol.address() as usize;
|
||||||
if offset < 8 {
|
// The offset specifies the location of rustc metadata in the .info section of XCOFF.
|
||||||
|
// Each string stored in .info section of XCOFF is preceded by a 4-byte length field.
|
||||||
|
if offset < 4 {
|
||||||
return Err(format!("Invalid metadata symbol offset: {offset}"));
|
return Err(format!("Invalid metadata symbol offset: {offset}"));
|
||||||
}
|
}
|
||||||
// The offset specifies the location of rustc metadata in the comment section.
|
// XCOFF format uses big-endian byte order.
|
||||||
// The metadata is preceded by a 8-byte length field.
|
let len = u32::from_be_bytes(info_data[(offset - 4)..offset].try_into().unwrap()) as usize;
|
||||||
let len = u64::from_le_bytes(info_data[(offset - 8)..offset].try_into().unwrap()) as usize;
|
|
||||||
if offset + len > (info_data.len() as usize) {
|
if offset + len > (info_data.len() as usize) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"Metadata at offset {offset} with size {len} is beyond .info section"
|
"Metadata at offset {offset} with size {len} is beyond .info section"
|
||||||
@ -478,9 +479,12 @@ pub fn create_wrapper_file(
|
|||||||
file.add_section(Vec::new(), b".text".to_vec(), SectionKind::Text);
|
file.add_section(Vec::new(), b".text".to_vec(), SectionKind::Text);
|
||||||
file.section_mut(section).flags =
|
file.section_mut(section).flags =
|
||||||
SectionFlags::Xcoff { s_flags: xcoff::STYP_INFO as u32 };
|
SectionFlags::Xcoff { s_flags: xcoff::STYP_INFO as u32 };
|
||||||
|
// Encode string stored in .info section of XCOFF.
|
||||||
let len = data.len() as u64;
|
// FIXME: The length of data here is not guaranteed to fit in a u32.
|
||||||
let offset = file.append_section_data(section, &len.to_le_bytes(), 1);
|
// We may have to split the data into multiple pieces in order to
|
||||||
|
// store in .info section.
|
||||||
|
let len: u32 = data.len().try_into().unwrap();
|
||||||
|
let offset = file.append_section_data(section, &len.to_be_bytes(), 1);
|
||||||
// Add a symbol referring to the data in .info section.
|
// Add a symbol referring to the data in .info section.
|
||||||
file.add_symbol(Symbol {
|
file.add_symbol(Symbol {
|
||||||
name: AIX_METADATA_SYMBOL_NAME.into(),
|
name: AIX_METADATA_SYMBOL_NAME.into(),
|
||||||
@ -599,12 +603,12 @@ pub fn create_compressed_metadata_file_for_xcoff(
|
|||||||
section: SymbolSection::Section(data_section),
|
section: SymbolSection::Section(data_section),
|
||||||
flags: SymbolFlags::None,
|
flags: SymbolFlags::None,
|
||||||
});
|
});
|
||||||
let len = data.len() as u64;
|
let len: u32 = data.len().try_into().unwrap();
|
||||||
let offset = file.append_section_data(section, &len.to_le_bytes(), 1);
|
let offset = file.append_section_data(section, &len.to_be_bytes(), 1);
|
||||||
// Add a symbol referring to the rustc metadata.
|
// Add a symbol referring to the rustc metadata.
|
||||||
file.add_symbol(Symbol {
|
file.add_symbol(Symbol {
|
||||||
name: AIX_METADATA_SYMBOL_NAME.into(),
|
name: AIX_METADATA_SYMBOL_NAME.into(),
|
||||||
value: offset + 8, // The metadata is preceded by a 8-byte length field.
|
value: offset + 4, // The metadata is preceded by a 4-byte length field.
|
||||||
size: 0,
|
size: 0,
|
||||||
kind: SymbolKind::Unknown,
|
kind: SymbolKind::Unknown,
|
||||||
scope: SymbolScope::Dynamic,
|
scope: SymbolScope::Dynamic,
|
||||||
|
Loading…
Reference in New Issue
Block a user