| 1 | // Checking that DSOs are automatically patched upon load, if patch_premain is passed. |
| 2 | |
| 3 | // RUN: split-file %s %t |
| 4 | // RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -shared -std=c++11 %t/testlib.cpp -o %t/testlib.so |
| 5 | // RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -std=c++11 %t/main.cpp %t/testlib.so -Wl,-rpath,%t -o %t/main.o |
| 6 | |
| 7 | // RUN: XRAY_OPTIONS="patch_premain=true,verbosity=1" %run %t/main.o 2>&1 | FileCheck %s |
| 8 | |
| 9 | // REQUIRES: target={{(aarch64|x86_64)-.*}} |
| 10 | |
| 11 | //--- main.cpp |
| 12 | |
| 13 | #include "xray/xray_interface.h" |
| 14 | |
| 15 | #include <cstdio> |
| 16 | |
| 17 | void test_handler(int32_t fid, XRayEntryType type) { |
| 18 | printf(format: "called: %d, type=%d\n" , fid, static_cast<int32_t>(type)); |
| 19 | } |
| 20 | |
| 21 | [[clang::xray_always_instrument]] void instrumented_in_executable() { |
| 22 | printf(format: "instrumented_in_executable called\n" ); |
| 23 | } |
| 24 | |
| 25 | extern void instrumented_in_dso(); |
| 26 | |
| 27 | int main() { |
| 28 | __xray_set_handler(entry: test_handler); |
| 29 | instrumented_in_executable(); |
| 30 | // CHECK: called: {{.*}}, type=0 |
| 31 | // CHECK-NEXT: instrumented_in_executable called |
| 32 | // CHECK-NEXT: called: {{.*}}, type=1 |
| 33 | instrumented_in_dso(); |
| 34 | // CHECK-NEXT: called: {{.*}}, type=0 |
| 35 | // CHECK-NEXT: instrumented_in_dso called |
| 36 | // CHECK-NEXT: called: {{.*}}, type=1 |
| 37 | } |
| 38 | |
| 39 | //--- testlib.cpp |
| 40 | |
| 41 | #include <cstdio> |
| 42 | |
| 43 | [[clang::xray_always_instrument]] void instrumented_in_dso() { |
| 44 | printf(format: "instrumented_in_dso called\n" ); |
| 45 | } |
| 46 | |