[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / lib / xray / xray_dso_init.cpp
blobeb754db54c64fa37b67f5819fc901048dabc4608
1 //===-- xray_init.cpp -------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of XRay, a dynamic runtime instrumentation system.
11 // XRay initialisation logic for DSOs.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_common/sanitizer_atomic.h"
15 #include "xray_defs.h"
16 #include "xray_flags.h"
17 #include "xray_interface_internal.h"
19 using namespace __sanitizer;
21 extern "C" {
22 extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
23 __attribute__((visibility("hidden")));
24 extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
25 __attribute__((visibility("hidden")));
26 extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
27 __attribute__((visibility("hidden")));
28 extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
29 __attribute__((visibility("hidden")));
31 #if SANITIZER_APPLE
32 // HACK: This is a temporary workaround to make XRay build on
33 // Darwin, but it will probably not work at runtime.
34 extern const XRaySledEntry __start_xray_instr_map[] = {};
35 extern const XRaySledEntry __stop_xray_instr_map[] = {};
36 extern const XRayFunctionSledIndex __start_xray_fn_idx[] = {};
37 extern const XRayFunctionSledIndex __stop_xray_fn_idx[] = {};
38 #endif
41 // Handler functions to call in the patched entry/exit sled.
42 extern atomic_uintptr_t XRayPatchedFunction;
43 extern atomic_uintptr_t XRayArgLogger;
44 extern atomic_uintptr_t XRayPatchedCustomEvent;
45 extern atomic_uintptr_t XRayPatchedTypedEvent;
47 static int __xray_object_id{-1};
49 // Note: .preinit_array initialization does not work for DSOs
50 __attribute__((constructor(0))) static void
51 __xray_init_dso() XRAY_NEVER_INSTRUMENT {
52 // Register sleds in main XRay runtime.
53 __xray_object_id =
54 __xray_register_dso(__start_xray_instr_map, __stop_xray_instr_map,
55 __start_xray_fn_idx, __stop_xray_fn_idx, {});
58 __attribute__((destructor(0))) static void
59 __xray_finalize_dso() XRAY_NEVER_INSTRUMENT {
60 // Inform the main runtime that this DSO is no longer used.
61 __xray_deregister_dso(__xray_object_id);