Fixes for updated object crate

object stopped including the ELF null
symbol and null section in the respective
iterators. We relied on this behavior for
building certain vectors in order of
symbol index. Adjust this logic to
restore the correct behavior.
This commit is contained in:
Luke Street 2024-09-29 12:00:44 -06:00
parent e430cb56f5
commit ac45676770
3 changed files with 12 additions and 8 deletions

View File

@ -281,7 +281,7 @@ fn fixup(args: FixupArgs) -> Result<()> {
}
// Write section symbols & sections
let mut section_ids: Vec<Option<SectionId>> = vec![];
let mut section_ids: Vec<Option<SectionId>> = 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<Option<SymbolId>> = vec![];
let mut symbol_ids: Vec<Option<SymbolId>> = vec![None /* ELF null symbol */];
let mut addr_to_sym: BTreeMap<SectionId, BTreeMap<u32, SymbolId>> = 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()?);
}

View File

@ -194,13 +194,15 @@ fn make_rso<P: AsRef<Path>>(
{
// 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<RsoSectionHeader> = vec![];
let mut rso_sections: Vec<RsoSectionHeader> =
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));

View File

@ -70,7 +70,7 @@ where P: AsRef<Path> {
let mut sda2_base: Option<u32> = None;
let mut sections: Vec<ObjSection> = vec![];
let mut section_indexes: Vec<Option<usize>> = vec![];
let mut section_indexes: Vec<Option<usize>> = 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<Path> {
.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<Path> {
};
let mut symbols: Vec<ObjSymbol> = vec![];
let mut symbol_indexes: Vec<Option<usize>> = vec![];
let mut symbol_indexes: Vec<Option<usize>> = vec![None /* ELF null symbol */];
let mut section_starts = IndexMap::<String, Vec<(u64, String)>>::new();
let mut name_to_index = HashMap::<String, usize>::new(); // for resolving duplicate names
let mut boundary_state = BoundaryState::LookForFile(Default::default());