Rework .splitmeta, now .note.split

Uses actual ELF .note format, which is
more standard and handled better by mwld.
This commit is contained in:
2024-03-04 18:12:20 -07:00
parent 96b13be11d
commit b829e15438
4 changed files with 28 additions and 23 deletions

View File

@@ -601,12 +601,18 @@ fn info(args: InfoArgs) -> Result<()> {
let data = split_meta_section.uncompressed_data()?;
if !data.is_empty() {
let meta =
SplitMeta::from_reader(&mut data.as_ref(), in_file.endianness(), in_file.is_64())
.context("While reading .splitmeta section")?;
println!("\nSplit metadata (.splitmeta):");
SplitMeta::from_section(split_meta_section, in_file.endianness(), in_file.is_64())
.context("While reading .note.split section")?;
println!("\nSplit metadata (.note.split):");
if let Some(generator) = &meta.generator {
println!("\tGenerator: {}", generator);
}
if let Some(module_name) = &meta.module_name {
println!("\tModule name: {}", module_name);
}
if let Some(module_id) = meta.module_id {
println!("\tModule ID: {}", module_id);
}
if let Some(virtual_addresses) = &meta.virtual_addresses {
println!("\tVirtual addresses:");
println!("\t{: >10} | {: <10}", "Addr", "Symbol");

View File

@@ -133,15 +133,13 @@ where P: AsRef<Path> {
if data.is_empty() {
None
} else {
let mut reader = Cursor::new(&*data);
let metadata =
SplitMeta::from_reader(&mut reader, obj_file.endianness(), obj_file.is_64())
.context("While reading .splitmeta section")?;
log::debug!("Loaded .splitmeta section");
ensure!(
data.len() - reader.position() as usize == 0,
".splitmeta section data not fully read"
);
let metadata = SplitMeta::from_section(
split_meta_section,
obj_file.endianness(),
obj_file.is_64(),
)
.context("While reading .note.split section")?;
log::debug!("Loaded .note.split section");
Some(metadata)
}
} else {
@@ -456,7 +454,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
None
};
// Generate .splitmeta section
// Generate .note.split section
let mut split_meta = if let Some(metadata) = &obj.split_meta {
// Reserve section
let name = writer.add_section_name(SPLITMETA_SECTION.as_bytes());
@@ -472,7 +470,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
virtual_address: None,
});
// Generate .splitmeta data
// Generate .note.split data
let mut out = metadata.clone();
out.virtual_addresses = Some(vec![
0, // Null symbol
@@ -667,7 +665,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
out_section.offset = writer.reserve(comment_data.len(), 32);
}
// Reserve .splitmeta section
// Reserve .note.split section
if let Some((metadata, idx)) = &split_meta {
let out_section = &mut out_sections[*idx];
out_section.offset = writer.reserve(metadata.write_size(false), 32);
@@ -786,7 +784,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
writer.write(comment_data);
}
// Write .splitmeta section
// Write .note.split section
if let Some((metadata, idx)) = &split_meta {
let out_section = &out_sections[*idx];
writer.write_align(32);
@@ -856,7 +854,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
});
}
// Write .splitmeta section header
// Write .note.split section header
if let Some((metadata, idx)) = &split_meta {
let out_section = &out_sections[*idx];
writer.write_section_header(&SectionHeader {
@@ -868,8 +866,8 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
sh_size: metadata.write_size(false) as u64,
sh_link: 0,
sh_info: 0,
sh_addralign: 1,
sh_entsize: 1,
sh_addralign: 4,
sh_entsize: 0,
});
}