62 lines · plain
1# Test the different ways of hooking the fini function for instrumentation (via2# DT_FINI and via DT_FINI_ARRAY). We test the latter for both PIE and non-PIE3# binaries because of the different ways of handling relocations (static or4# dynamic).5# All tests perform the following steps:6# - Compile and link for the case to be tested7# - Some sanity-checks on the dynamic section and relocations in the binary to8# verify it has the shape we want for testing:9# - DT_FINI or DT_FINI_ARRAY in dynamic section10# - No relative relocations for non-PIE11# - Instrument12# - Run instrumented binary13# - Verify generated profile14REQUIRES: system-linux,bolt-runtime15 16RUN: %clang %cflags -pie %p/Inputs/basic-instrumentation.s -Wl,-q -o %t.exe17RUN: llvm-readelf -d %t.exe | FileCheck --check-prefix=DYN-FINI %s18RUN: llvm-readelf -r %t.exe | FileCheck --check-prefix=RELOC-PIE %s19RUN: llvm-bolt %t.exe -o %t --instrument \20RUN: --instrumentation-file=%t \21RUN: --instrumentation-file-append-pid22RUN: rm -f %t.*.fdata23RUN: %t24RUN: cat %t.*.fdata | FileCheck %s25 26RUN: %clang %cflags -pie %p/Inputs/basic-instrumentation.s -Wl,-q,-fini=0 -o %t-no-fini.exe27RUN: llvm-readelf -d %t-no-fini.exe | FileCheck --check-prefix=DYN-NO-FINI %s28RUN: llvm-readelf -r %t-no-fini.exe | FileCheck --check-prefix=RELOC-PIE %s29RUN: llvm-bolt %t-no-fini.exe -o %t-no-fini --instrument \30RUN: --instrumentation-file=%t-no-fini \31RUN: --instrumentation-file-append-pid32RUN: rm -f %t-no-fini.*.fdata33RUN: %t-no-fini34RUN: cat %t-no-fini.*.fdata | FileCheck %s35 36RUN: %clang %cflags -no-pie %p/Inputs/basic-instrumentation.s -Wl,-q,-fini=0 -o %t-no-pie-no-fini.exe37RUN: llvm-readelf -d %t-no-pie-no-fini.exe | FileCheck --check-prefix=DYN-NO-FINI %s38RUN: llvm-readelf -r %t-no-pie-no-fini.exe | FileCheck --check-prefix=RELOC-NO-PIE %s39RUN: llvm-bolt %t-no-pie-no-fini.exe -o %t-no-pie-no-fini --instrument \40RUN: --instrumentation-file=%t-no-pie-no-fini \41RUN: --instrumentation-file-append-pid42RUN: rm -f %t-no-pie-no-fini.*.fdata43RUN: %t-no-pie-no-fini44RUN: cat %t-no-pie-no-fini.*.fdata | FileCheck %s45 46# With fini: dynamic section should contain DT_FINI47DYN-FINI: (FINI)48 49# Without fini: dynamic section should only contain DT_FINI_ARRAY50DYN-NO-FINI-NOT: (FINI)51DYN-NO-FINI: (FINI_ARRAY)52DYN-NO-FINI: (FINI_ARRAYSZ)53 54# With PIE: binary should have relative relocations55RELOC-PIE: R_AARCH64_RELATIVE56 57# Without PIE: binary should not have relative relocations58RELOC-NO-PIE-NOT: R_AARCH64_RELATIVE59 60# The instrumented profile should at least say main was called once61CHECK: main 0 0 1{{$}}62