Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_dso_init.cpp
213766 views
//===-- xray_init.cpp -------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of XRay, a dynamic runtime instrumentation system.9//10// XRay initialisation logic for DSOs.11//===----------------------------------------------------------------------===//1213#include "sanitizer_common/sanitizer_atomic.h"14#include "xray_defs.h"15#include "xray_flags.h"16#include "xray_interface_internal.h"1718using namespace __sanitizer;1920extern "C" {21extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))22__attribute__((visibility("hidden")));23extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))24__attribute__((visibility("hidden")));25extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))26__attribute__((visibility("hidden")));27extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))28__attribute__((visibility("hidden")));2930#if SANITIZER_APPLE31// HACK: This is a temporary workaround to make XRay build on32// Darwin, but it will probably not work at runtime.33extern const XRaySledEntry __start_xray_instr_map[] = {};34extern const XRaySledEntry __stop_xray_instr_map[] = {};35extern const XRayFunctionSledIndex __start_xray_fn_idx[] = {};36extern const XRayFunctionSledIndex __stop_xray_fn_idx[] = {};37#endif38}3940// Handler functions to call in the patched entry/exit sled.41extern atomic_uintptr_t XRayPatchedFunction;42extern atomic_uintptr_t XRayArgLogger;43extern atomic_uintptr_t XRayPatchedCustomEvent;44extern atomic_uintptr_t XRayPatchedTypedEvent;4546static int __xray_object_id{-1};4748// Note: .preinit_array initialization does not work for DSOs49__attribute__((constructor(0))) static void50__xray_init_dso() XRAY_NEVER_INSTRUMENT {51// Register sleds in main XRay runtime.52__xray_object_id =53__xray_register_dso(__start_xray_instr_map, __stop_xray_instr_map,54__start_xray_fn_idx, __stop_xray_fn_idx, {});55}5657__attribute__((destructor(0))) static void58__xray_finalize_dso() XRAY_NEVER_INSTRUMENT {59// Inform the main runtime that this DSO is no longer used.60__xray_deregister_dso(__xray_object_id);61}626364