dyld: Add nac3ld support #194

Merged
sb10q merged 3 commits from occheung/artiq-zynq:nac3ld-support into master 2022-06-01 21:27:38 +08:00
1 changed files with 25 additions and 12 deletions
Showing only changes of commit 5fba1c8bf4 - Show all commits

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);