Files
TheRock/compiler/amd-llvm/compiler-rt/test/xray/TestCases/Posix/dlopen.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

108 lines
2.9 KiB
C++

// Check that we can patch and un-patch DSOs loaded with dlopen.
//
// RUN: split-file %s %t
// RUN: %clangxx_xray -g -fPIC -fxray-instrument -fxray-shared -shared -std=c++11 %t/testlib.cpp -o %t/testlib.so
// RUN: %clangxx_xray -g -fPIC -rdynamic -fxray-instrument -fxray-shared -std=c++11 %t/main.cpp -o %t/main.o
//
// RUN: env XRAY_OPTIONS="patch_premain=true" %run %t/main.o %t/testlib.so 2>&1 | FileCheck %s
// REQUIRES: target={{(aarch64|x86_64)-.*}}
//--- main.cpp
#include "xray/xray_interface.h"
#include <cstdio>
#include <dlfcn.h>
void test_handler(int32_t fid, XRayEntryType type) {
printf("called: %d, type=%d\n", fid, static_cast<int32_t>(type));
}
[[clang::xray_always_instrument]] void instrumented_in_executable() {
printf("instrumented_in_executable called\n");
}
typedef void (*dso_func_type)();
int main(int argc, char **argv) {
if (argc < 2) {
printf("Shared library argument missing\n");
// CHECK-NOT: Shared library argument missing
return 1;
}
const char *dso_path = argv[1];
void *dso_handle = dlopen(dso_path, RTLD_LAZY);
if (!dso_handle) {
printf("Failed to load shared library\n");
char *error = dlerror();
if (error) {
fprintf(stderr, "%s\n", error);
return 1;
}
return 1;
}
dso_func_type instrumented_in_dso =
(dso_func_type)dlsym(dso_handle, "_Z19instrumented_in_dsov");
if (!instrumented_in_dso) {
printf("Failed to find symbol\n");
char *error = dlerror();
if (error) {
fprintf(stderr, "%s\n", error);
return 1;
}
return 1;
}
__xray_set_handler(test_handler);
instrumented_in_executable();
// CHECK: called: {{.*}}, type=0
// CHECK-NEXT: instrumented_in_executable called
// CHECK-NEXT: called: {{.*}}, type=1
instrumented_in_dso();
// CHECK-NEXT: called: {{.*}}, type=0
// CHECK-NEXT: instrumented_in_dso called
// CHECK-NEXT: called: {{.*}}, type=1
auto status = __xray_unpatch();
printf("unpatching status: %d\n", static_cast<int32_t>(status));
// CHECK-NEXT: unpatching status: 1
instrumented_in_executable();
// CHECK-NEXT: instrumented_in_executable called
instrumented_in_dso();
// CHECK-NEXT: instrumented_in_dso called
status = __xray_patch();
printf("patching status: %d\n", static_cast<int32_t>(status));
// CHECK-NEXT: patching status: 1
instrumented_in_executable();
// CHECK-NEXT: called: {{.*}}, type=0
// CHECK-NEXT: instrumented_in_executable called
// CHECK-NEXT: called: {{.*}}, type=1
instrumented_in_dso();
// CHECK-NEXT: called: {{.*}}, type=0
// CHECK-NEXT: instrumented_in_dso called
// CHECK-NEXT: called: {{.*}}, type=1
dlclose(dso_handle);
status = __xray_unpatch();
printf("unpatching status: %d\n", static_cast<int32_t>(status));
// CHECK-NEXT: unpatching status: 1
}
//--- testlib.cpp
#include <cstdio>
[[clang::xray_always_instrument]] void instrumented_in_dso() {
printf("instrumented_in_dso called\n");
}