1
0
Fork 0

dyld/rebind: support rela generation with nac3ld

This commit is contained in:
occheung 2022-06-01 17:44:17 +08:00 committed by Gitea
parent 8e144e41de
commit 9ec6a1feab
1 changed files with 25 additions and 12 deletions

View File

@ -159,23 +159,36 @@ pub fn relocate<R: Relocatable>(
pub fn rebind(
arch: Arch, lib: &Library, name: &[u8], value: Elf32_Word
) -> Result<(), Error> {
for rela in lib.pltrel() {
let rel_type = RelType::new(arch, rela.type_info())
fn rebind_symbol_to_value<R: Relocatable>(
arch: Arch, lib: &Library,name: &[u8], value: Elf32_Word, relocs: &[R]
) -> Result<(), Error> {
for reloc in relocs {
let rel_type = RelType::new(arch, reloc.type_info())
.ok_or("unsupported relocation type")?;
match rel_type {
RelType::LookupAbs => {
let sym = lib.symtab().get(ELF32_R_SYM(rela.r_info) as usize)
let sym = lib.symtab().get(reloc.sym_info() as usize)
.ok_or("symbol out of bounds of symbol table")?;
let sym_name = lib.name_starting_at(sym.st_name as usize)?;
if sym_name == name {
lib.image.write(rela.offset(), value)?
lib.image.write(reloc.offset(), value)?
}
}
// No associated symbols for other relocation types.
_ => {}
}
}
Ok(())
}
if lib.pltrel().is_empty() {
rebind_symbol_to_value(arch, lib, name, value, lib.rela())?;
} else {
rebind_symbol_to_value(arch, lib, name, value, lib.pltrel())?;
}
// FIXME: the cache maintainance operations may be more than enough,
// may cause performance degradation.
dcci_slice(lib.image.data);