From 3923fc3f0e130cea94cba96073660eabebb5083f Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 5 Nov 2022 16:04:48 -0400 Subject: everything working as before now --- src/elf.rs | 5 ++++- src/main.rs | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/elf.rs b/src/elf.rs index f53ba98..acc3e18 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -425,6 +425,7 @@ impl RelType { pub struct Relocation { pub r#type: RelType, + pub entry_offset: u64, // file offset of relocation metadata (for debugging) pub offset: u64, // where the relocation should be applied. for ET_REL, this is a file offset; otherwise, it's an address. pub symbol: Symbol, pub addend: i64, @@ -498,6 +499,7 @@ impl Reader for Reader32LE { for (s_idx, shdr) in shdrs.iter().enumerate() { let mut data = vec![0; shdr.size as usize]; + reader.seek(io::SeekFrom::Start(shdr.offset.into()))?; reader.read_exact(&mut data)?; section_data.push(data); @@ -565,7 +567,7 @@ impl Reader for Reader32LE { reader.seek(io::SeekFrom::Start(shdr.offset.into()))?; let my_symbols = symtabs.get(shdr.link as usize).ok_or(BadLink(shdr.link))?; - for _ in 0..count { + for r_idx in 0..count { let info; let mut offset; @@ -602,6 +604,7 @@ impl Reader for Reader32LE { relocations.push(Relocation { r#type: RelType::from_u8(info as u8, ehdr.machine.into()), + entry_offset: shdr.offset as u64 + r_idx as u64 * shdr.entsize as u64, symbol: symbol.clone(), addend: addend.into(), offset: offset.into(), diff --git a/src/main.rs b/src/main.rs index 7640a69..2300c27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -620,7 +620,9 @@ impl Linker { symbol: &elf::Symbol, ) -> Result<(), ObjectError> { let mut data_offset = None; - let name_id = self.symbol_names.add(elf.symbol_name(symbol)?); + let name = elf.symbol_name(symbol)?; + println!("{name}"); + let name_id = self.symbol_names.add(name); let value = match symbol.value { elf::SymbolValue::Undefined => None, @@ -695,7 +697,7 @@ impl Linker { } else { self.emit_warning(LinkWarning::RelNoData( self.source_name(source_id).into(), - 0, // @TODO + rel.entry_offset )); } } -- cgit v1.2.3