-
Notifications
You must be signed in to change notification settings - Fork 937
Description
Background
Async-profiler currently extracts symbols from .symtab
and .dynsym
sections of shared libraries on a disk. Additionally, it locates GOT (global offset table) in loaded libraries and searches it for the addresses of dlopen
and certain pthreads
functions to hook them. However, if the address in GOT differs from the address resolved by async-profiler for some reason (e.g. GOT has already been patched by a previous version of async-profiler), the following error will occurs:
Could not set dlopen hook. Unsupported JVM?
Proposal
Instead of looking for GOT entries by an address, resolve imported symbols like a dynamic linker does. To do this, parse ELF program headers in memory and the dynamic section in particular. Find the relocation entries associated with the imported symbols in .rela.plt
or .rela.dyn
table, using the data in .dynsym
/.dynstr
sections to resolve symbolic function names.
Outcome
New approach to parsing dynamic linking structures opens a path to solving the following problems:
- ✅ Fix
Could not set dlopen hook
issue and allow running multiple instances of the profiler simultaneously. - ✅ Parse symbols of shared libraries that were removed from a disk (it's typical to extract a JNI library in a temporary directory and remove it immediately after loading).
- (future work) Provide a mechanism to hook other library functions in runtime, e.g.,
malloc
andfree
for native memory profiling.