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>
121 lines
4.0 KiB
CMake
121 lines
4.0 KiB
CMake
set(ARM64 aarch64)
|
|
set(ARM32 arm armhf)
|
|
set(HEXAGON hexagon)
|
|
set(X86 i386)
|
|
set(X86_64 x86_64)
|
|
set(LOONGARCH64 loongarch64)
|
|
set(MIPS32 mips mipsel)
|
|
set(MIPS64 mips64 mips64el)
|
|
set(PPC32 powerpc powerpcspe)
|
|
set(PPC64 powerpc64 powerpc64le)
|
|
set(RISCV32 riscv32)
|
|
set(RISCV64 riscv64)
|
|
set(S390X s390x)
|
|
set(SPARC sparc)
|
|
set(SPARCV9 sparcv9)
|
|
set(WASM32 wasm32)
|
|
set(WASM64 wasm64)
|
|
set(VE ve)
|
|
|
|
if(APPLE)
|
|
set(ARM64 arm64)
|
|
set(ARM32 armv7 armv7s armv7k)
|
|
set(ARM64_32 arm64_32)
|
|
set(X86_64 x86_64 x86_64h)
|
|
endif()
|
|
|
|
if(WIN32)
|
|
set(ARM32 ${ARM32} armv7)
|
|
endif()
|
|
|
|
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
|
|
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}
|
|
${HEXAGON} ${LOONGARCH64})
|
|
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
|
|
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
|
|
${LOONGARCH64})
|
|
set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
|
|
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
|
|
set(ALL_RTSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
|
|
|
|
if(ANDROID)
|
|
set(OS_NAME "Android")
|
|
else()
|
|
set(OS_NAME "${CMAKE_SYSTEM_NAME}")
|
|
endif()
|
|
|
|
if(OS_NAME MATCHES "Linux")
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${S390X}
|
|
${RISCV64} ${LOONGARCH64})
|
|
elseif (OS_NAME MATCHES "Windows")
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64})
|
|
elseif(OS_NAME MATCHES "Android")
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64})
|
|
elseif(OS_NAME MATCHES "Fuchsia")
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
|
|
elseif(OS_NAME MATCHES "FreeBSD")
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
|
|
else()
|
|
set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64})
|
|
endif()
|
|
|
|
set(ALL_GWP_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64})
|
|
if(APPLE)
|
|
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
|
|
else()
|
|
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32}
|
|
${PPC64} ${S390X} ${RISCV64} ${HEXAGON} ${LOONGARCH64})
|
|
endif()
|
|
if (OS_NAME MATCHES "FreeBSD")
|
|
set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
|
|
else()
|
|
set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
|
|
${LOONGARCH64})
|
|
endif()
|
|
set(ALL_NSAN_SUPPORTED_ARCH ${X86_64})
|
|
set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
|
|
set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
|
|
set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} ${PPC64}
|
|
${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
|
|
${RISCV32} ${RISCV64} ${LOONGARCH64} ${WASM32})
|
|
set(ALL_CTX_PROFILE_SUPPORTED_ARCH ${X86_64})
|
|
if (OS_NAME MATCHES "FreeBSD")
|
|
set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
|
|
else()
|
|
set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
|
|
${LOONGARCH64} ${RISCV64})
|
|
endif()
|
|
set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
|
|
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
|
|
${LOONGARCH64})
|
|
if (OS_NAME MATCHES "FreeBSD")
|
|
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
|
|
else()
|
|
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64}
|
|
${HEXAGON} ${LOONGARCH64} ${SPARC} ${SPARCV9})
|
|
endif()
|
|
set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}
|
|
${HEXAGON} ${LOONGARCH64})
|
|
set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
|
|
${MIPS32} ${MIPS64} ${PPC64} ${HEXAGON} ${LOONGARCH64} ${RISCV64})
|
|
if(APPLE)
|
|
set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM64})
|
|
else()
|
|
set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}
|
|
powerpc64le ${HEXAGON} ${LOONGARCH64})
|
|
endif()
|
|
set(ALL_XRAY_DSO_SUPPORTED_ARCH ${X86_64})
|
|
set(ALL_SHADOWCALLSTACK_SUPPORTED_ARCH ${ARM64})
|
|
|
|
if (UNIX)
|
|
if (OS_NAME MATCHES "Linux")
|
|
set(ALL_ORC_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM32} ${PPC64})
|
|
else()
|
|
set(ALL_ORC_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM32})
|
|
endif()
|
|
endif()
|
|
|
|
if (WIN32)
|
|
set(ALL_ORC_SUPPORTED_ARCH ${X86_64})
|
|
endif()
|