|
|
@ -360,24 +360,30 @@ impl<'a> FunctionLinker<'a> {
|
|
|
|
fun: &Function,
|
|
|
|
fun: &Function,
|
|
|
|
start: usize,
|
|
|
|
start: usize,
|
|
|
|
) -> Result<(), RelocationError> {
|
|
|
|
) -> Result<(), RelocationError> {
|
|
|
|
let off_adj = start - (fun.section_offset as usize / INS_SIZE);
|
|
|
|
|
|
|
|
let func_info = &fun.func_info.func_info;
|
|
|
|
let func_info = &fun.func_info.func_info;
|
|
|
|
let func_info = func_info.iter().map(|f| {
|
|
|
|
let func_info = func_info.iter().cloned().map(|mut info| {
|
|
|
|
let mut new = *f;
|
|
|
|
// `start` is the new instruction offset of `fun` within `program`
|
|
|
|
new.insn_off = f.insn_off + off_adj as u32;
|
|
|
|
info.insn_off = start as u32;
|
|
|
|
new
|
|
|
|
info
|
|
|
|
});
|
|
|
|
});
|
|
|
|
program.func_info.func_info.extend(func_info);
|
|
|
|
program.func_info.func_info.extend(func_info);
|
|
|
|
program.func_info.num_info = program.func_info.func_info.len() as u32;
|
|
|
|
program.func_info.num_info = program.func_info.func_info.len() as u32;
|
|
|
|
|
|
|
|
|
|
|
|
let line_info = &fun.line_info.line_info;
|
|
|
|
let line_info = &fun.line_info.line_info;
|
|
|
|
let line_info = line_info.iter().map(|l| {
|
|
|
|
if !line_info.is_empty() {
|
|
|
|
let mut new = *l;
|
|
|
|
// this is the original offset
|
|
|
|
new.insn_off = start as u32 + l.insn_off;
|
|
|
|
let original_start_off = line_info[0].insn_off;
|
|
|
|
new
|
|
|
|
|
|
|
|
});
|
|
|
|
let line_info = line_info.iter().cloned().map(|mut info| {
|
|
|
|
program.line_info.line_info.extend(line_info);
|
|
|
|
// rebase offsets on top of start, which is the offset of the
|
|
|
|
program.line_info.num_info = program.func_info.func_info.len() as u32;
|
|
|
|
// function in the program being linked
|
|
|
|
|
|
|
|
info.insn_off = start as u32 + (info.insn_off - original_start_off);
|
|
|
|
|
|
|
|
info
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
program.line_info.line_info.extend(line_info);
|
|
|
|
|
|
|
|
program.line_info.num_info = program.func_info.func_info.len() as u32;
|
|
|
|
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|