chc4 / lineiform

A meta-JIT library for Rust interpreters
156 stars 4 forks source link

Handle dynamically linked functions #9

Open chc4 opened 2 years ago

chc4 commented 2 years ago

Right now we just use /proc/self/exe as the ELF to load to look for symbols. This is OK for normal Rust code, since it's statically linked by default, but not for things like "any calls to a malloc" or "any external library".

We should instead open /proc/self/maps to find what ELF the address we're trying to resolve is inside, and check that for the symbol instead. Once we're getting the section mappings from proc maps we also need to use that for finding the base address for symbol vaddr calculation. Currently we just use a .needle symbol, which is hacky af and doesn't work for external ELFs.

We should cache the ELFs (and what sections they're mapped at ) with a RangeMap<usize, Rc<Elf>> or something similar, marking each range to what ELF it's part of so we don't have to keep checking proc maps or reading the ELF from disk.

chc4 commented 2 years ago

https://github.com/gimli-rs/findshlibs