[llvm] [BOLT] Support instrumentation hook via DT_FINI_ARRAY (PR #67348)
Vladislav Khmelevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 09:54:47 PDT 2023
================
@@ -0,0 +1,61 @@
+# Test the different ways of hooking the fini function for instrumentation (via
+# DT_FINI and via DT_FINI_ARRAY). We test the latter for both PIE and non-PIE
+# binaries because of the different ways of handling relocations (static or
+# dynamic).
+# All tests perform the following steps:
+# - Compile and link for the case to be tested
+# - Some sanity-checks on the dynamic section and relocations in the binary to
+# verify it has the shape we want for testing:
+# - DT_FINI or DT_FINI_ARRAY in dynamic section
+# - No relative relocations for non-PIE
+# - Instrument
+# - Run instrumented binary
+# - Verify generated profile
+REQUIRES: system-linux,bolt-runtime
+
+RUN: %clang %p/Inputs/basic-instrumentation.s -Wl,-q -o %t.exe
+RUN: llvm-readelf -d %t.exe | FileCheck --check-prefix=DYN-FINI %s
+RUN: llvm-readelf -r %t.exe | FileCheck --check-prefix=RELOC-PIE %s
+RUN: llvm-bolt %t.exe -o %t --instrument \
+RUN: --instrumentation-file=%t \
+RUN: --instrumentation-file-append-pid
+RUN: rm -f %t.*.fdata
+RUN: %t
+RUN: cat %t.*.fdata | FileCheck %s
+
+RUN: %clang %p/Inputs/basic-instrumentation.s -Wl,-q,-fini=0 -o %t-no-fini.exe
----------------
yota9 wrote:
Well you can replace _fini symbol (I guess it is in .s file) to myfini and pass if to -fini flag if needed, otherwise it would be empty. Probably it is better option, I'm not sure if this is legit method that would continue to work..
https://github.com/llvm/llvm-project/pull/67348
More information about the llvm-commits
mailing list