MCPcopy Index your code
hub / github.com/encounter/objdiff / map_section_relocations

Function map_section_relocations

objdiff-core/src/obj/read.rs:461–595  ·  view source on GitHub ↗
(
    arch: &dyn Arch,
    obj_file: &object::File,
    obj_section: &object::Section,
    symbol_indices: &[usize],
    ordered_symbols: &[Vec<object::Symbol>],
)

Source from the content-addressed store, hash-verified

459}
460
461fn map_section_relocations(
462 arch: &dyn Arch,
463 obj_file: &object::File,
464 obj_section: &object::Section,
465 symbol_indices: &[usize],
466 ordered_symbols: &[Vec<object::Symbol>],
467) -> Result<Vec<Relocation>> {
468 let mut relocations = Vec::<Relocation>::with_capacity(obj_section.relocations().count());
469 for (address, reloc) in obj_section.relocations() {
470 let mut target_reloc = RelocationOverride {
471 target: match reloc.target() {
472 object::RelocationTarget::Symbol(symbol) => {
473 RelocationOverrideTarget::Symbol(symbol)
474 }
475 object::RelocationTarget::Section(section) => {
476 RelocationOverrideTarget::Section(section)
477 }
478 _ => RelocationOverrideTarget::Skip,
479 },
480 addend: reloc.addend(),
481 };
482
483 // Allow the architecture to override the relocation target and addend
484 match arch.relocation_override(obj_file, obj_section, address, &reloc)? {
485 Some(reloc_override) => {
486 match reloc_override.target {
487 RelocationOverrideTarget::Keep => {}
488 target => {
489 target_reloc.target = target;
490 }
491 }
492 target_reloc.addend = reloc_override.addend;
493 }
494 None => {
495 ensure!(
496 !reloc.has_implicit_addend(),
497 "Unsupported {:?} implicit relocation {:?}",
498 obj_file.architecture(),
499 reloc.flags()
500 );
501 }
502 }
503
504 // Resolve the relocation target symbol
505 let (symbol_index, addend) = match target_reloc.target {
506 RelocationOverrideTarget::Keep => unreachable!(),
507 RelocationOverrideTarget::Skip => continue,
508 RelocationOverrideTarget::Symbol(symbol_index) => {
509 // Sometimes used to indicate "absolute"
510 if symbol_index.0 == u32::MAX as usize {
511 continue;
512 }
513
514 // If the target is a section symbol, try to resolve a better symbol as the target
515 if let Some(section_symbol) = obj_file
516 .symbol_by_index(symbol_index)
517 .ok()
518 .filter(|s| s.kind() == object::SymbolKind::Section)

Callers 1

map_relocationsFunction · 0.85

Calls 7

SymbolClass · 0.85
SectionClass · 0.85
best_symbolFunction · 0.85
getMethod · 0.80
indexMethod · 0.80
pushMethod · 0.80
relocation_overrideMethod · 0.45

Tested by

no test coverage detected