1 //===-- xray_init.cpp -------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
;
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")));
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
[] = {};
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.
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
);