mirror of https://github.com/encounter/objdiff.git
API updates for ARM backend
This commit is contained in:
parent
c9b11db2fa
commit
fc54e93681
|
@ -1,6 +1,9 @@
|
||||||
use std::{borrow::Cow, collections::HashMap};
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
collections::{BTreeMap, HashMap},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use object::{
|
use object::{
|
||||||
elf, File, Object, ObjectSection, ObjectSymbol, Relocation, RelocationFlags, SectionIndex,
|
elf, File, Object, ObjectSection, ObjectSymbol, Relocation, RelocationFlags, SectionIndex,
|
||||||
SectionKind, Symbol,
|
SectionKind, Symbol,
|
||||||
|
@ -14,7 +17,7 @@ use unarm::{
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{ObjArch, ProcessCodeResult},
|
arch::{ObjArch, ProcessCodeResult},
|
||||||
diff::DiffObjConfig,
|
diff::DiffObjConfig,
|
||||||
obj::{ObjInfo, ObjIns, ObjInsArg, ObjInsArgValue, ObjSection, SymbolRef},
|
obj::{ObjIns, ObjInsArg, ObjInsArgValue, ObjReloc, ObjSection},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ObjArchArm {
|
pub struct ObjArchArm {
|
||||||
|
@ -50,28 +53,25 @@ impl ObjArchArm {
|
||||||
impl ObjArch for ObjArchArm {
|
impl ObjArch for ObjArchArm {
|
||||||
fn process_code(
|
fn process_code(
|
||||||
&self,
|
&self,
|
||||||
obj: &ObjInfo,
|
address: u64,
|
||||||
symbol_ref: SymbolRef,
|
code: &[u8],
|
||||||
|
section_index: usize,
|
||||||
|
relocations: &[ObjReloc],
|
||||||
|
line_info: &BTreeMap<u64, u64>,
|
||||||
config: &DiffObjConfig,
|
config: &DiffObjConfig,
|
||||||
) -> Result<ProcessCodeResult> {
|
) -> Result<ProcessCodeResult> {
|
||||||
let (section, symbol) = obj.section_symbol(symbol_ref);
|
let start_addr = address as u32;
|
||||||
let section = section.ok_or_else(|| anyhow!("Code symbol section not found"))?;
|
let end_addr = start_addr + code.len() as u32;
|
||||||
let code = §ion.data
|
|
||||||
[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
|
||||||
|
|
||||||
let start_addr = symbol.address as u32;
|
|
||||||
let end_addr = start_addr + symbol.size as u32;
|
|
||||||
|
|
||||||
// Mapping symbols decide what kind of data comes after it. $a for ARM code, $t for Thumb code and $d for data.
|
// Mapping symbols decide what kind of data comes after it. $a for ARM code, $t for Thumb code and $d for data.
|
||||||
let fallback_mappings =
|
let fallback_mappings = [DisasmMode { address: start_addr, mapping: ParseMode::Arm }];
|
||||||
[DisasmMode { address: symbol.address as u32, mapping: ParseMode::Arm }];
|
|
||||||
let mapping_symbols = self
|
let mapping_symbols = self
|
||||||
.disasm_modes
|
.disasm_modes
|
||||||
.get(&SectionIndex(section.orig_index))
|
.get(&SectionIndex(section_index))
|
||||||
.map(|x| x.as_slice())
|
.map(|x| x.as_slice())
|
||||||
.unwrap_or(&fallback_mappings);
|
.unwrap_or(&fallback_mappings);
|
||||||
let first_mapping_idx =
|
let first_mapping_idx =
|
||||||
match mapping_symbols.binary_search_by_key(&(symbol.address as u32), |x| x.address) {
|
match mapping_symbols.binary_search_by_key(&start_addr, |x| x.address) {
|
||||||
Ok(idx) => idx,
|
Ok(idx) => idx,
|
||||||
Err(idx) => idx - 1,
|
Err(idx) => idx - 1,
|
||||||
};
|
};
|
||||||
|
@ -96,10 +96,9 @@ impl ObjArch for ObjArchArm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let line = section.line_info.range(..=address as u64).last().map(|(_, &b)| b);
|
let line = line_info.range(..=address as u64).last().map(|(_, &b)| b);
|
||||||
|
|
||||||
let reloc =
|
let reloc = relocations.iter().find(|r| (r.address as u32 & !1) == address).cloned();
|
||||||
section.relocations.iter().find(|r| (r.address as u32 & !1) == address).cloned();
|
|
||||||
|
|
||||||
let mut reloc_arg = None;
|
let mut reloc_arg = None;
|
||||||
if let Some(reloc) = &reloc {
|
if let Some(reloc) = &reloc {
|
||||||
|
|
|
@ -59,6 +59,7 @@ impl ObjArch for ObjArchMips {
|
||||||
&self,
|
&self,
|
||||||
address: u64,
|
address: u64,
|
||||||
code: &[u8],
|
code: &[u8],
|
||||||
|
_section_index: usize,
|
||||||
relocations: &[ObjReloc],
|
relocations: &[ObjReloc],
|
||||||
line_info: &BTreeMap<u64, u64>,
|
line_info: &BTreeMap<u64, u64>,
|
||||||
config: &DiffObjConfig,
|
config: &DiffObjConfig,
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub trait ObjArch: Send + Sync {
|
||||||
&self,
|
&self,
|
||||||
address: u64,
|
address: u64,
|
||||||
code: &[u8],
|
code: &[u8],
|
||||||
|
section_index: usize,
|
||||||
relocations: &[ObjReloc],
|
relocations: &[ObjReloc],
|
||||||
line_info: &BTreeMap<u64, u64>,
|
line_info: &BTreeMap<u64, u64>,
|
||||||
config: &DiffObjConfig,
|
config: &DiffObjConfig,
|
||||||
|
|
|
@ -33,6 +33,7 @@ impl ObjArch for ObjArchPpc {
|
||||||
&self,
|
&self,
|
||||||
address: u64,
|
address: u64,
|
||||||
code: &[u8],
|
code: &[u8],
|
||||||
|
_section_index: usize,
|
||||||
relocations: &[ObjReloc],
|
relocations: &[ObjReloc],
|
||||||
line_info: &BTreeMap<u64, u64>,
|
line_info: &BTreeMap<u64, u64>,
|
||||||
config: &DiffObjConfig,
|
config: &DiffObjConfig,
|
||||||
|
|
|
@ -30,6 +30,7 @@ impl ObjArch for ObjArchX86 {
|
||||||
&self,
|
&self,
|
||||||
address: u64,
|
address: u64,
|
||||||
code: &[u8],
|
code: &[u8],
|
||||||
|
_section_index: usize,
|
||||||
relocations: &[ObjReloc],
|
relocations: &[ObjReloc],
|
||||||
line_info: &BTreeMap<u64, u64>,
|
line_info: &BTreeMap<u64, u64>,
|
||||||
config: &DiffObjConfig,
|
config: &DiffObjConfig,
|
||||||
|
|
|
@ -25,7 +25,14 @@ pub fn process_code_symbol(
|
||||||
let section = section.ok_or_else(|| anyhow!("Code symbol section not found"))?;
|
let section = section.ok_or_else(|| anyhow!("Code symbol section not found"))?;
|
||||||
let code = §ion.data
|
let code = §ion.data
|
||||||
[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
||||||
obj.arch.process_code(symbol.address, code, §ion.relocations, §ion.line_info, config)
|
obj.arch.process_code(
|
||||||
|
symbol.address,
|
||||||
|
code,
|
||||||
|
section.orig_index,
|
||||||
|
§ion.relocations,
|
||||||
|
§ion.line_info,
|
||||||
|
config,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn no_diff_code(out: &ProcessCodeResult, symbol_ref: SymbolRef) -> Result<ObjSymbolDiff> {
|
pub fn no_diff_code(out: &ProcessCodeResult, symbol_ref: SymbolRef) -> Result<ObjSymbolDiff> {
|
||||||
|
|
Loading…
Reference in New Issue