diff --git a/src/cmd/elf.rs b/src/cmd/elf.rs index 3798724..46c7cdc 100644 --- a/src/cmd/elf.rs +++ b/src/cmd/elf.rs @@ -281,7 +281,7 @@ fn fixup(args: FixupArgs) -> Result<()> { } // Write section symbols & sections - let mut section_ids: Vec> = vec![]; + let mut section_ids: Vec> = vec![None /* ELF null section */]; for section in in_file.sections() { // Skip empty sections or metadata sections if section.size() == 0 || section.kind() == SectionKind::Metadata { @@ -304,7 +304,7 @@ fn fixup(args: FixupArgs) -> Result<()> { } // Write symbols - let mut symbol_ids: Vec> = vec![]; + let mut symbol_ids: Vec> = vec![None /* ELF null symbol */]; let mut addr_to_sym: BTreeMap> = BTreeMap::new(); for symbol in in_file.symbols() { // Skip section and file symbols, we wrote them above @@ -488,7 +488,7 @@ fn info(args: InfoArgs) -> Result<()> { "{: >15} | {: <10} | {: <10} | {: <10} | {: <10}", "Name", "Type", "Size", "File Off", "Index" ); - for section in in_file.sections().skip(1) { + for section in in_file.sections() { let kind_str = match section.kind() { SectionKind::Text => "code".to_cow(), SectionKind::Data => "data".to_cow(), @@ -565,6 +565,7 @@ fn info(args: InfoArgs) -> Result<()> { ); println!("\tUnsafe global reg vars: {}", header.unsafe_global_reg_vars); println!("\n{: >10} | {: <6} | {: <6} | {: <10}", "Align", "Vis", "Active", "Symbol"); + CommentSym::from_reader(&mut reader, Endian::Big)?; // ELF null symbol for symbol in in_file.symbols() { let comment_sym = CommentSym::from_reader(&mut reader, Endian::Big)?; if symbol.is_definition() { @@ -603,7 +604,7 @@ fn info(args: InfoArgs) -> Result<()> { if let Some(virtual_addresses) = &meta.virtual_addresses { println!("\tVirtual addresses:"); println!("\t{: >10} | {: <10}", "Addr", "Symbol"); - for (symbol, addr) in in_file.symbols().zip(virtual_addresses) { + for (symbol, addr) in in_file.symbols().zip(virtual_addresses.iter().skip(1)) { if symbol.is_definition() { println!("\t{: >10} | {: <10}", format!("{:#X}", addr), symbol.name()?); } diff --git a/src/cmd/rso.rs b/src/cmd/rso.rs index a783ebd..6875c7d 100644 --- a/src/cmd/rso.rs +++ b/src/cmd/rso.rs @@ -194,13 +194,15 @@ fn make_rso>( { // Write Sections Info Table (Blank) let blank_section = RsoSectionHeader::default(); - for _ in file.sections() { + // Include ELF null section + for _ in 0..file.sections().count() + 1 { header.num_sections += 1; blank_section.to_writer(&mut out, Endian::Big)?; } } - let mut rso_sections: Vec = vec![]; + let mut rso_sections: Vec = + vec![RsoSectionHeader::default() /* ELF null section */]; for section in file.sections() { let is_valid_section = section.name().is_ok_and(|n| RSO_SECTION_NAMES.iter().any(|&s| s == n)); diff --git a/src/util/elf.rs b/src/util/elf.rs index d104230..cc35248 100644 --- a/src/util/elf.rs +++ b/src/util/elf.rs @@ -70,7 +70,7 @@ where P: AsRef { let mut sda2_base: Option = None; let mut sections: Vec = vec![]; - let mut section_indexes: Vec> = vec![]; + let mut section_indexes: Vec> = vec![None /* ELF null section */]; for section in obj_file.sections() { if section.size() == 0 { section_indexes.push(None); @@ -115,6 +115,7 @@ where P: AsRef { .context("While reading .comment section")?; log::debug!("Loaded .comment section header {:?}", header); let mut comment_syms = Vec::with_capacity(obj_file.symbols().count()); + CommentSym::from_reader(&mut reader, Endian::Big)?; // ELF null symbol for symbol in obj_file.symbols() { let comment_sym = CommentSym::from_reader(&mut reader, Endian::Big)?; log::debug!("Symbol {:?} -> Comment {:?}", symbol, comment_sym); @@ -149,7 +150,7 @@ where P: AsRef { }; let mut symbols: Vec = vec![]; - let mut symbol_indexes: Vec> = vec![]; + let mut symbol_indexes: Vec> = vec![None /* ELF null symbol */]; let mut section_starts = IndexMap::>::new(); let mut name_to_index = HashMap::::new(); // for resolving duplicate names let mut boundary_state = BoundaryState::LookForFile(Default::default());