aya: fix call relocation bug

Take the section offset into account when looking up relocation entries
pull/67/head
Alessandro Decina 3 years ago
parent dc4b928ec5
commit 59a1854a6b

@ -257,20 +257,21 @@ impl<'a> FunctionLinker<'a> {
continue; continue;
} }
let callee_address = let callee_address = if let Some(rel) =
if let Some(rel) = rel_info(((ins_index - start_ins) * INS_SIZE) as u64) { rel_info((fun.section_offset + (ins_index - start_ins) * INS_SIZE) as u64)
// We have a relocation entry for the instruction at `ins_index`, the address of {
// the callee is the address of the relocation's target symbol. // We have a relocation entry for the instruction at `ins_index`, the address of
rel_target_address(rel, self.symbol_table)? // the callee is the address of the relocation's target symbol.
} else { rel_target_address(rel, self.symbol_table)?
// The caller and the callee are in the same ELF section and this is a pc-relative } else {
// call. Resolve the pc-relative imm to an absolute address. // The caller and the callee are in the same ELF section and this is a pc-relative
let ins_size = INS_SIZE as i64; // call. Resolve the pc-relative imm to an absolute address.
(fun.section_offset as i64 let ins_size = INS_SIZE as i64;
+ ((ins_index - start_ins) as i64) * ins_size (fun.section_offset as i64
+ (program.instructions[ins_index].imm + 1) as i64 * ins_size) + ((ins_index - start_ins) as i64) * ins_size
as u64 + (program.instructions[ins_index].imm + 1) as i64 * ins_size)
}; as u64
};
// lookup and link the callee if it hasn't been linked already. `callee_ins_index` will // lookup and link the callee if it hasn't been linked already. `callee_ins_index` will
// contain the instruction index of the callee inside the program. // contain the instruction index of the callee inside the program.

Loading…
Cancel
Save