-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[XRay] Add support for instrumentation of DSOs on x86_64 #90959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
86e252c
1bd2ac0
1dc7361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fPIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s | ||
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fpic -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s | ||
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s | ||
// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fno-PIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-PIC | ||
// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fno-pic -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-PIC | ||
|
||
// On 64 bit darwin, PIC is always enabled | ||
// RUN: %clang -### --target=x86_64-apple-darwin -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
// Check unsupported targets | ||
// RUN: not %clang -### --target=aarch64-pc-freebsd -fPIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-TARGET | ||
// RUN: not %clang -### --target=arm64-apple-macos -fPIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-TARGET | ||
|
||
// CHECK: "-cc1" {{.*}}"-fxray-instrument" {{.*}}"-fxray-shared" | ||
// ERR-TARGET: error: unsupported option '-fxray-shared' for target | ||
// ERR-PIC: error: option '-fxray-shared' cannot be specified without '-fPIC' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,27 +97,50 @@ enum XRayPatchingStatus { | |
/// for possible result values. | ||
extern XRayPatchingStatus __xray_patch(); | ||
|
||
extern XRayPatchingStatus __xray_patch_object(int32_t ObjId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: Is it possible to provide documentation to this and other added functions? |
||
|
||
/// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible | ||
/// result values. | ||
extern XRayPatchingStatus __xray_unpatch(); | ||
|
||
extern XRayPatchingStatus __xray_unpatch_object(int32_t ObjId); | ||
|
||
/// This patches a specific function id. See XRayPatchingStatus for possible | ||
/// result values. | ||
extern XRayPatchingStatus __xray_patch_function(int32_t FuncId); | ||
|
||
extern XRayPatchingStatus __xray_patch_function_in_object(int32_t FuncId, | ||
int32_t ObjId); | ||
|
||
/// This unpatches a specific function id. See XRayPatchingStatus for possible | ||
/// result values. | ||
extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId); | ||
|
||
extern XRayPatchingStatus __xray_unpatch_function_in_object(int32_t FuncId, | ||
int32_t ObjId); | ||
|
||
/// This function returns the address of the function provided a valid function | ||
/// id. We return 0 if we encounter any error, even if 0 may be a valid function | ||
/// address. | ||
extern uintptr_t __xray_function_address(int32_t FuncId); | ||
|
||
extern uintptr_t __xray_function_address_in_object(int32_t FuncId, | ||
int32_t ObjId); | ||
|
||
/// This function returns the maximum valid function id. Returns 0 if we | ||
/// encounter errors (when there are no instrumented functions, etc.). | ||
extern size_t __xray_max_function_id(); | ||
|
||
extern size_t __xray_max_function_id_in_object(int32_t ObjId); | ||
|
||
extern size_t __xray_num_objects(); | ||
|
||
extern int32_t __xray_unpack_function_id(int32_t PackedId); | ||
|
||
extern int32_t __xray_unpack_object_id(int32_t PackedId); | ||
|
||
extern int32_t __xray_pack_id(int32_t FuncId, int32_t ObjId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation for these functions would be very helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I added the missing documentation. |
||
|
||
/// Initialize the required XRay data structures. This is useful in cases where | ||
/// users want to control precisely when the XRay instrumentation data | ||
/// structures are initialized, for example when the XRay library is built with | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//===-- xray_init.cpp -------------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of XRay, a dynamic runtime instrumentation system. | ||
// | ||
// XRay initialisation logic for DSOs. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "sanitizer_common/sanitizer_atomic.h" | ||
#include "xray_defs.h" | ||
#include "xray_flags.h" | ||
#include "xray_interface_internal.h" | ||
|
||
using namespace __sanitizer; | ||
|
||
extern "C" { | ||
extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak)) | ||
__attribute__((visibility("hidden"))); | ||
extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak)) | ||
__attribute__((visibility("hidden"))); | ||
extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak)) | ||
__attribute__((visibility("hidden"))); | ||
extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak)) | ||
__attribute__((visibility("hidden"))); | ||
androm3da marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#if SANITIZER_APPLE | ||
// HACK: This is a temporary workaround to make XRay build on | ||
// Darwin, but it will probably not work at runtime. | ||
extern const XRaySledEntry __start_xray_instr_map[] = {}; | ||
extern const XRaySledEntry __stop_xray_instr_map[] = {}; | ||
extern const XRayFunctionSledIndex __start_xray_fn_idx[] = {}; | ||
extern const XRayFunctionSledIndex __stop_xray_fn_idx[] = {}; | ||
#endif | ||
} | ||
|
||
// Handler functions to call in the patched entry/exit sled. | ||
extern atomic_uintptr_t XRayPatchedFunction; | ||
extern atomic_uintptr_t XRayArgLogger; | ||
extern atomic_uintptr_t XRayPatchedCustomEvent; | ||
extern atomic_uintptr_t XRayPatchedTypedEvent; | ||
|
||
static int __xray_object_id{-1}; | ||
|
||
// Note: .preinit_array initialization does not work for DSOs | ||
__attribute__((constructor(0))) static void | ||
__xray_init_dso() XRAY_NEVER_INSTRUMENT { | ||
// Register sleds in main XRay runtime. | ||
__xray_object_id = | ||
__xray_register_dso(__start_xray_instr_map, __stop_xray_instr_map, | ||
__start_xray_fn_idx, __stop_xray_fn_idx, {}); | ||
} | ||
|
||
__attribute__((destructor(0))) static void | ||
__xray_finalize_dso() XRAY_NEVER_INSTRUMENT { | ||
// Inform the main runtime that this DSO is no longer used. | ||
__xray_deregister_dso(__xray_object_id); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.