unsafe fn visit_import_slots(
base: usize,
dynp: *const Elf64Dyn,
symbol: &[u8],
visit: &mut dyn FnMut(*mut *mut c_void),
)Expand description
Hand every GOT slot through which one loaded library calls symbol to visit, by walking its
PT_DYNAMIC array — the only way to interpose without an LD_PRELOAD object, or to read where the
dynamic linker bound an import — covering both the lazy-PLT and -fno-plt relocation forms
because NVIDIA ships the latter.
- Parse
.dynamic: iterate theElf64Dynentries untilDT_NULL, recording the dynamic symbol table, string table, PLT relocation table (DT_JMPREL/DT_PLTRELSZ), and general relocation table (DT_RELA/DT_RELASZ). Table addresses are resolved throughdyn_addrto handle the glibc-absolute vs musl-relative pointer conventions. - Sanity-gate the tables: bail if the symbol or string table is missing, and — via the
readableclosure overpage_prot— bail if a table’s mapping is known but lacks read permission (an address whose mapping cannot be determined is presumed readable), so a wrong relative/absolute guess fromdyn_addrcannot fault on first dereference. - Visit both relocation tables: hand each present, adequately-sized, readable table to
visit_reloc_table. The PLT table (.rela.plt) carries the classic lazily-boundJUMP_SLOTentries; the general table (.rela.dyn) carries theGLOB_DATslot that-fno-pltNVIDIA builds use to bindioctl.