2016-07-21 07:39:55 +00:00
|
|
|
//===-- xray_trampoline_x86.s -----------------------------------*- ASM -*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2016-07-21 07:39:55 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of XRay, a dynamic runtime instrumentation system.
|
|
|
|
//
|
|
|
|
// This implements the X86-specific assembler for the trampolines.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-15 21:18:47 +00:00
|
|
|
#include "../builtins/assembly.h"
|
2017-11-28 11:49:22 +00:00
|
|
|
#include "../sanitizer_common/sanitizer_asm.h"
|
|
|
|
|
2021-03-06 10:38:27 -08:00
|
|
|
// XRay trampolines which are not produced by intrinsics are not System V AMD64
|
|
|
|
// ABI compliant because they are called with a stack that is always misaligned
|
|
|
|
// by 8 bytes with respect to a 16 bytes alignment. This is because they are
|
|
|
|
// called immediately after the call to, or immediately before returning from,
|
|
|
|
// the function being instrumented. This saves space in the patch point, but
|
|
|
|
// misaligns the stack by 8 bytes.
|
|
|
|
|
|
|
|
.macro ALIGN_STACK_16B
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
subq $$8, %rsp
|
|
|
|
#else
|
|
|
|
subq $8, %rsp
|
|
|
|
#endif
|
|
|
|
CFI_ADJUST_CFA_OFFSET(8)
|
|
|
|
.endm
|
2017-11-28 11:49:22 +00:00
|
|
|
|
2021-03-06 10:38:27 -08:00
|
|
|
.macro RESTORE_STACK_ALIGNMENT
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
addq $$8, %rsp
|
|
|
|
#else
|
|
|
|
addq $8, %rsp
|
|
|
|
#endif
|
|
|
|
CFI_ADJUST_CFA_OFFSET(-8)
|
|
|
|
.endm
|
2017-03-15 21:18:47 +00:00
|
|
|
|
2024-05-27 16:31:17 -07:00
|
|
|
// This macro should lower the stack pointer by an odd multiple of 8.
|
2016-12-15 09:04:05 +00:00
|
|
|
.macro SAVE_REGISTERS
|
2018-08-28 10:32:50 +00:00
|
|
|
pushfq
|
2021-03-06 10:38:27 -08:00
|
|
|
CFI_ADJUST_CFA_OFFSET(8)
|
[XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.
We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.
Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc
Reviewed By: echristo
Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D40894
llvm-svn: 323940
2018-02-01 02:21:54 +00:00
|
|
|
subq $240, %rsp
|
2021-03-06 10:38:27 -08:00
|
|
|
CFI_ADJUST_CFA_OFFSET(240)
|
[XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.
We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.
Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc
Reviewed By: echristo
Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D40894
llvm-svn: 323940
2018-02-01 02:21:54 +00:00
|
|
|
movq %rbp, 232(%rsp)
|
|
|
|
movupd %xmm0, 216(%rsp)
|
|
|
|
movupd %xmm1, 200(%rsp)
|
|
|
|
movupd %xmm2, 184(%rsp)
|
|
|
|
movupd %xmm3, 168(%rsp)
|
|
|
|
movupd %xmm4, 152(%rsp)
|
|
|
|
movupd %xmm5, 136(%rsp)
|
|
|
|
movupd %xmm6, 120(%rsp)
|
|
|
|
movupd %xmm7, 104(%rsp)
|
|
|
|
movq %rdi, 96(%rsp)
|
|
|
|
movq %rax, 88(%rsp)
|
|
|
|
movq %rdx, 80(%rsp)
|
|
|
|
movq %rsi, 72(%rsp)
|
|
|
|
movq %rcx, 64(%rsp)
|
|
|
|
movq %r8, 56(%rsp)
|
|
|
|
movq %r9, 48(%rsp)
|
|
|
|
movq %r10, 40(%rsp)
|
|
|
|
movq %r11, 32(%rsp)
|
|
|
|
movq %r12, 24(%rsp)
|
|
|
|
movq %r13, 16(%rsp)
|
|
|
|
movq %r14, 8(%rsp)
|
|
|
|
movq %r15, 0(%rsp)
|
2016-12-15 18:54:27 +00:00
|
|
|
.endm
|
2016-07-21 07:39:55 +00:00
|
|
|
|
2016-12-15 09:04:05 +00:00
|
|
|
.macro RESTORE_REGISTERS
|
[XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.
We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.
Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc
Reviewed By: echristo
Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D40894
llvm-svn: 323940
2018-02-01 02:21:54 +00:00
|
|
|
movq 232(%rsp), %rbp
|
|
|
|
movupd 216(%rsp), %xmm0
|
|
|
|
movupd 200(%rsp), %xmm1
|
|
|
|
movupd 184(%rsp), %xmm2
|
|
|
|
movupd 168(%rsp), %xmm3
|
|
|
|
movupd 152(%rsp), %xmm4
|
|
|
|
movupd 136(%rsp), %xmm5
|
|
|
|
movupd 120(%rsp) , %xmm6
|
|
|
|
movupd 104(%rsp) , %xmm7
|
|
|
|
movq 96(%rsp), %rdi
|
|
|
|
movq 88(%rsp), %rax
|
|
|
|
movq 80(%rsp), %rdx
|
|
|
|
movq 72(%rsp), %rsi
|
|
|
|
movq 64(%rsp), %rcx
|
|
|
|
movq 56(%rsp), %r8
|
|
|
|
movq 48(%rsp), %r9
|
|
|
|
movq 40(%rsp), %r10
|
|
|
|
movq 32(%rsp), %r11
|
|
|
|
movq 24(%rsp), %r12
|
|
|
|
movq 16(%rsp), %r13
|
|
|
|
movq 8(%rsp), %r14
|
|
|
|
movq 0(%rsp), %r15
|
|
|
|
addq $240, %rsp
|
2021-03-06 10:38:27 -08:00
|
|
|
CFI_ADJUST_CFA_OFFSET(-240)
|
2018-08-28 10:32:50 +00:00
|
|
|
popfq
|
2021-03-06 10:38:27 -08:00
|
|
|
CFI_ADJUST_CFA_OFFSET(-8)
|
2017-11-15 03:35:42 +00:00
|
|
|
.endm
|
|
|
|
|
2017-11-10 07:00:55 +00:00
|
|
|
.text
|
2017-11-28 11:49:22 +00:00
|
|
|
#if !defined(__APPLE__)
|
|
|
|
.section .text
|
2018-12-28 18:53:00 +00:00
|
|
|
.file "xray_trampoline_x86.S"
|
2017-11-28 11:49:22 +00:00
|
|
|
#else
|
|
|
|
.section __TEXT,__text
|
|
|
|
#endif
|
2017-03-06 07:25:41 +00:00
|
|
|
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
.macro LOAD_HANDLER_ADDR handler
|
|
|
|
#if !defined(XRAY_PIC)
|
|
|
|
movq ASM_SYMBOL(\handler)(%rip), %rax
|
|
|
|
#else
|
|
|
|
movq ASM_SYMBOL(\handler)@GOTPCREL(%rip), %rax
|
|
|
|
movq (%rax), %rax
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
|
|
|
|
2017-03-06 07:25:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-29 19:27:25 +00:00
|
|
|
.globl ASM_SYMBOL(__xray_FunctionEntry)
|
2020-04-21 18:18:23 -04:00
|
|
|
ASM_HIDDEN(__xray_FunctionEntry)
|
2016-12-15 09:04:05 +00:00
|
|
|
.align 16, 0x90
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_TYPE_FUNCTION(__xray_FunctionEntry)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_FunctionEntry
|
2017-11-29 19:27:25 +00:00
|
|
|
ASM_SYMBOL(__xray_FunctionEntry):
|
2017-11-28 11:49:22 +00:00
|
|
|
CFI_STARTPROC
|
2016-12-15 09:04:05 +00:00
|
|
|
SAVE_REGISTERS
|
2024-05-27 16:31:17 -07:00
|
|
|
ALIGN_STACK_16B
|
2016-12-15 09:04:05 +00:00
|
|
|
|
|
|
|
// This load has to be atomic, it's concurrent with __xray_patch().
|
|
|
|
// On x86/amd64, a simple (type-aligned) MOV instruction is enough.
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray19XRayPatchedFunctionE
|
2016-12-15 09:04:05 +00:00
|
|
|
testq %rax, %rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(tmp0)
|
2016-12-15 09:04:05 +00:00
|
|
|
|
[XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.
We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.
Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc
Reviewed By: echristo
Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D40894
llvm-svn: 323940
2018-02-01 02:21:54 +00:00
|
|
|
// The patched function prologue puts its xray_instr_map index into %r10d.
|
2016-12-15 09:04:05 +00:00
|
|
|
movl %r10d, %edi
|
|
|
|
xor %esi,%esi
|
2021-03-06 10:38:27 -08:00
|
|
|
callq *%rax
|
2017-11-15 03:35:42 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(tmp0):
|
2021-03-06 10:38:27 -08:00
|
|
|
RESTORE_STACK_ALIGNMENT
|
2024-05-27 16:31:17 -07:00
|
|
|
RESTORE_REGISTERS
|
2016-07-21 07:39:55 +00:00
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_SIZE(__xray_FunctionEntry)
|
|
|
|
CFI_ENDPROC
|
2016-07-21 07:39:55 +00:00
|
|
|
|
2017-03-06 07:25:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-29 19:27:25 +00:00
|
|
|
.globl ASM_SYMBOL(__xray_FunctionExit)
|
2020-04-21 18:18:23 -04:00
|
|
|
ASM_HIDDEN(__xray_FunctionExit)
|
2016-07-21 07:39:55 +00:00
|
|
|
.align 16, 0x90
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_TYPE_FUNCTION(__xray_FunctionExit)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_FunctionExit
|
2017-11-29 19:27:25 +00:00
|
|
|
ASM_SYMBOL(__xray_FunctionExit):
|
2017-11-28 11:49:22 +00:00
|
|
|
CFI_STARTPROC
|
2021-03-06 10:38:27 -08:00
|
|
|
ALIGN_STACK_16B
|
|
|
|
|
2016-07-21 07:39:55 +00:00
|
|
|
// Save the important registers first. Since we're assuming that this
|
|
|
|
// function is only jumped into, we only preserve the registers for
|
|
|
|
// returning.
|
2021-03-06 10:38:27 -08:00
|
|
|
subq $64, %rsp
|
|
|
|
CFI_ADJUST_CFA_OFFSET(64)
|
2017-04-20 03:26:04 +00:00
|
|
|
movq %rbp, 48(%rsp)
|
2017-04-19 05:37:14 +00:00
|
|
|
movupd %xmm0, 32(%rsp)
|
|
|
|
movupd %xmm1, 16(%rsp)
|
|
|
|
movq %rax, 8(%rsp)
|
|
|
|
movq %rdx, 0(%rsp)
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray19XRayPatchedFunctionE
|
2016-07-21 07:39:55 +00:00
|
|
|
testq %rax,%rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(tmp2)
|
2016-07-21 07:39:55 +00:00
|
|
|
|
|
|
|
movl %r10d, %edi
|
|
|
|
movl $1, %esi
|
2021-03-06 10:38:27 -08:00
|
|
|
callq *%rax
|
2017-11-15 03:35:42 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(tmp2):
|
2016-12-15 09:04:05 +00:00
|
|
|
// Restore the important registers.
|
2017-04-20 03:26:04 +00:00
|
|
|
movq 48(%rsp), %rbp
|
2017-04-19 05:37:14 +00:00
|
|
|
movupd 32(%rsp), %xmm0
|
|
|
|
movupd 16(%rsp), %xmm1
|
|
|
|
movq 8(%rsp), %rax
|
|
|
|
movq 0(%rsp), %rdx
|
2021-03-06 10:38:27 -08:00
|
|
|
addq $64, %rsp
|
|
|
|
CFI_ADJUST_CFA_OFFSET(-64)
|
|
|
|
|
|
|
|
RESTORE_STACK_ALIGNMENT
|
2016-07-21 07:39:55 +00:00
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_SIZE(__xray_FunctionExit)
|
|
|
|
CFI_ENDPROC
|
2016-11-02 04:11:29 +00:00
|
|
|
|
2017-03-06 07:25:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-29 19:27:25 +00:00
|
|
|
.globl ASM_SYMBOL(__xray_FunctionTailExit)
|
2020-04-21 18:18:23 -04:00
|
|
|
ASM_HIDDEN(__xray_FunctionTailExit)
|
2016-11-02 04:11:29 +00:00
|
|
|
.align 16, 0x90
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_TYPE_FUNCTION(__xray_FunctionTailExit)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_FunctionTailExit
|
2017-11-29 19:27:25 +00:00
|
|
|
ASM_SYMBOL(__xray_FunctionTailExit):
|
2017-11-28 11:49:22 +00:00
|
|
|
CFI_STARTPROC
|
2016-12-15 09:04:05 +00:00
|
|
|
SAVE_REGISTERS
|
2024-05-27 16:31:17 -07:00
|
|
|
ALIGN_STACK_16B
|
2016-11-02 04:11:29 +00:00
|
|
|
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray19XRayPatchedFunctionE
|
2016-11-02 04:11:29 +00:00
|
|
|
testq %rax,%rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(tmp4)
|
2016-11-02 04:11:29 +00:00
|
|
|
|
|
|
|
movl %r10d, %edi
|
2017-09-18 06:18:03 +00:00
|
|
|
movl $2, %esi
|
2021-03-06 10:38:27 -08:00
|
|
|
callq *%rax
|
2016-11-02 04:11:29 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(tmp4):
|
2021-03-06 10:38:27 -08:00
|
|
|
RESTORE_STACK_ALIGNMENT
|
2024-05-27 16:31:17 -07:00
|
|
|
RESTORE_REGISTERS
|
2016-11-02 04:11:29 +00:00
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_SIZE(__xray_FunctionTailExit)
|
|
|
|
CFI_ENDPROC
|
2017-03-06 07:25:41 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-29 19:27:25 +00:00
|
|
|
.globl ASM_SYMBOL(__xray_ArgLoggerEntry)
|
2020-04-21 18:18:23 -04:00
|
|
|
ASM_HIDDEN(__xray_ArgLoggerEntry)
|
2017-03-06 07:25:41 +00:00
|
|
|
.align 16, 0x90
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_TYPE_FUNCTION(__xray_ArgLoggerEntry)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_ArgLoggerEntry
|
2017-11-29 19:27:25 +00:00
|
|
|
ASM_SYMBOL(__xray_ArgLoggerEntry):
|
2017-11-28 11:49:22 +00:00
|
|
|
CFI_STARTPROC
|
2017-03-06 07:25:41 +00:00
|
|
|
SAVE_REGISTERS
|
2024-05-27 16:31:17 -07:00
|
|
|
ALIGN_STACK_16B
|
2017-03-06 07:25:41 +00:00
|
|
|
|
|
|
|
// Again, these function pointer loads must be atomic; MOV is fine.
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray13XRayArgLoggerE
|
2017-03-06 07:25:41 +00:00
|
|
|
testq %rax, %rax
|
2023-06-16 12:04:28 -07:00
|
|
|
jne LOCAL_LABEL(arg1entryLog)
|
2017-03-06 07:25:41 +00:00
|
|
|
|
|
|
|
// If [arg1 logging handler] not set, defer to no-arg logging.
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray19XRayPatchedFunctionE
|
2017-03-06 07:25:41 +00:00
|
|
|
testq %rax, %rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(arg1entryFail)
|
2017-03-06 07:25:41 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(arg1entryLog):
|
2017-05-12 01:07:41 +00:00
|
|
|
|
2017-09-28 05:29:59 +00:00
|
|
|
// First argument will become the third
|
2017-05-12 01:07:41 +00:00
|
|
|
movq %rdi, %rdx
|
|
|
|
|
2017-09-28 05:29:59 +00:00
|
|
|
// XRayEntryType::LOG_ARGS_ENTRY into the second
|
|
|
|
mov $0x3, %esi
|
2017-05-12 01:07:41 +00:00
|
|
|
|
|
|
|
// 32-bit function ID becomes the first
|
|
|
|
movl %r10d, %edi
|
2021-03-06 10:38:27 -08:00
|
|
|
|
|
|
|
callq *%rax
|
2017-03-06 07:25:41 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(arg1entryFail):
|
2021-03-06 10:38:27 -08:00
|
|
|
RESTORE_STACK_ALIGNMENT
|
2024-05-27 16:31:17 -07:00
|
|
|
RESTORE_REGISTERS
|
2017-03-06 07:25:41 +00:00
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_SIZE(__xray_ArgLoggerEntry)
|
|
|
|
CFI_ENDPROC
|
2017-03-15 21:18:47 +00:00
|
|
|
|
2017-05-12 01:07:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2024-04-12 10:49:39 -07:00
|
|
|
// __xray_*Event have default visibility so that they can be referenced by user
|
|
|
|
// DSOs that do not link against the runtime.
|
2017-11-29 19:27:25 +00:00
|
|
|
.global ASM_SYMBOL(__xray_CustomEvent)
|
2017-05-12 01:07:41 +00:00
|
|
|
.align 16, 0x90
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_TYPE_FUNCTION(__xray_CustomEvent)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_CustomEvent
|
2017-11-29 19:27:25 +00:00
|
|
|
ASM_SYMBOL(__xray_CustomEvent):
|
2017-11-28 11:49:22 +00:00
|
|
|
CFI_STARTPROC
|
2017-08-23 04:42:37 +00:00
|
|
|
SAVE_REGISTERS
|
2017-05-12 01:07:41 +00:00
|
|
|
|
|
|
|
// We take two arguments to this trampoline, which should be in rdi and rsi
|
[XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.
We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.
Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc
Reviewed By: echristo
Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D40894
llvm-svn: 323940
2018-02-01 02:21:54 +00:00
|
|
|
// already.
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray22XRayPatchedCustomEventE
|
2017-05-12 01:07:41 +00:00
|
|
|
testq %rax,%rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(customEventCleanup)
|
2017-05-12 01:07:41 +00:00
|
|
|
|
2021-03-06 10:38:27 -08:00
|
|
|
callq *%rax
|
2017-05-12 01:07:41 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(customEventCleanup):
|
2017-08-23 04:42:37 +00:00
|
|
|
RESTORE_REGISTERS
|
2017-05-12 01:07:41 +00:00
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2017-11-28 11:49:22 +00:00
|
|
|
ASM_SIZE(__xray_CustomEvent)
|
|
|
|
CFI_ENDPROC
|
2017-05-12 01:07:41 +00:00
|
|
|
|
2018-04-17 21:28:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
.global ASM_SYMBOL(__xray_TypedEvent)
|
|
|
|
.align 16, 0x90
|
|
|
|
ASM_TYPE_FUNCTION(__xray_TypedEvent)
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-BEGIN __xray_TypedEvent
|
2018-04-17 21:28:53 +00:00
|
|
|
ASM_SYMBOL(__xray_TypedEvent):
|
|
|
|
CFI_STARTPROC
|
|
|
|
SAVE_REGISTERS
|
|
|
|
|
|
|
|
// We pass three arguments to this trampoline, which should be in rdi, rsi
|
|
|
|
// and rdx without our intervention.
|
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.
Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting
I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).
**Original description:**
This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects
These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.
Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).
This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.
---------
Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 09:15:25 +01:00
|
|
|
LOAD_HANDLER_ADDR _ZN6__xray21XRayPatchedTypedEventE
|
2018-04-17 21:28:53 +00:00
|
|
|
testq %rax,%rax
|
2023-06-16 12:04:28 -07:00
|
|
|
je LOCAL_LABEL(typedEventCleanup)
|
2018-04-17 21:28:53 +00:00
|
|
|
|
2021-03-06 10:38:27 -08:00
|
|
|
callq *%rax
|
2018-04-17 21:28:53 +00:00
|
|
|
|
2023-06-16 12:04:28 -07:00
|
|
|
LOCAL_LABEL(typedEventCleanup):
|
2018-04-17 21:28:53 +00:00
|
|
|
RESTORE_REGISTERS
|
|
|
|
retq
|
2018-05-08 01:57:51 +00:00
|
|
|
# LLVM-MCA-END
|
2018-04-17 21:28:53 +00:00
|
|
|
ASM_SIZE(__xray_TypedEvent)
|
|
|
|
CFI_ENDPROC
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-15 21:18:47 +00:00
|
|
|
NO_EXEC_STACK_DIRECTIVE
|