[llvm] [BOLT] Support instrumentation hook via DT_FINI_ARRAY (PR #67348)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 04:04:07 PDT 2023


================
@@ -1276,6 +1280,57 @@ void RewriteInstance::discoverFileObjects() {
   registerFragments();
 }
 
+Error RewriteInstance::discoverFiniAddress() {
----------------
mtvec wrote:

I feel like the one call to `getRuntimeLibrary` does not warrant moving those functions to the runtime library. But maybe we should abstract-away that call into something like `RewriteInstance::getFiniAddress` so that the logic here doesn't need to know about runtime libraries at all.

But the main reason for me is still that all this logic is very ELF-specific and would be completely different on Mach-O, for example. So implementing this in `RewriteInstance` and `MachORewriteInstance` seems to make more sense to me. Moreover, the logic is not only contained in `discoverFiniAddress` and `updateFiniReloc`; part of it is also in `readELFDynamic` and, if you consider the old logic of just updating `DT_FINI` as part of the same feature (which I do), in `patchELFDynamic`. The handling of `DT_FINI` in the latter two functions could also be seen as runtime library specific but moving them to the runtime library does not seem logical or even possible.

The way I see it, the runtime library simply wants to say "make sure this address is called after main"; it's up to the implementation of a particular object format (i.e., `RewriteInstance` or `MachORewriteInstance`) to make sure that actually happens.

https://github.com/llvm/llvm-project/pull/67348


More information about the llvm-commits mailing list