KEMBAR78
Parse dynamic linking structures · Issue #761 · async-profiler/async-profiler · GitHub
Skip to content

Parse dynamic linking structures #761

@apangin

Description

@apangin

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:

  1. ✅ Fix Could not set dlopen hook issue and allow running multiple instances of the profiler simultaneously.
  2. ✅ 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).
  3. (future work) Provide a mechanism to hook other library functions in runtime, e.g., malloc and free for native memory profiling.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions