llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.57k stars 11.81k forks source link

BOLT and shared libraries #69846

Open zamazan4ik opened 12 months ago

zamazan4ik commented 12 months ago

Hi!

From the README file right now it's not clear how to use BOLT properly for optimizing shared libraries.

I have a case where I want to optimize with BOLT a shared library but I have no possibility to instrument the calling this binary library (because it could be simply a Python interpreter).

Is it possible in this case to optimize the library with BOLT? If yes, are there any special additional steps for that? I have tried to instrument the library and call it from a non-instrumented binary - no profiles are written to the disk.

I expect something like it's already done for the Instrumentation PGO in Clang (PGO profiles are dumped to the disk for each instrumented shared library after the library unload).

aaupov commented 12 months ago

You can either collect perf profile that would include samples in your shared library, or you can instrument that shared library the same way as you would instrument an executable.

I assume you know where to look for instrumentation profile: by default it's in /tmp/prof.fdata, otherwise it can be set with --instrumentation-file option.

Instrumentation profile is normally dumped via hook to _fini which requires a graceful exit. You can modify the default behavior and dump the profile at regular intervals using --instrumentation-sleep-time option. Let me know if it helps.