BOLT: Optimizing relocatable files

It looks like BOLT requires binaries to be real executables/DSOs, i.e. contain at least one PT_LOAD segment. I wonder, is there (or planned) a support for optimizing random object files/archives? I assume that in this case many optimizations (e.g. DCE) should be disabled, but at least peephole, BB/function reordering should still work?

I’m not aware of such plans but for BB/functions reordering you would still need to have profile data which you would still probably get from executable or shared library anyway. Plus AFAIK bolt does not have option to re-emit static relocations, there might be other complications with linker after it too…
Just curious, you would like to distribute pre-optimized static libraries?

Yeah, I basically have custom AOT-compiled code that I would like to optimize and distribute. The object file is actually self-contained (just raw code with symbols) and doesn’t have any static/dynamic relocations. I do have a profile collected on some executable compiled with this object file. So, in theory, I assume many optimizations could be performed on this object file selectively (but not on the rest of the binary).

On a slightly similar problem: is there a way to selectively enable functions for optimization (reverse for

-skip-funcs=

)?

--funcs=foo,bar,.*baz.* should work. If you are debugging something, you can also use --max-funcs=<N> to limit processing to the first N functions.