aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/include/xray/xray_interface.h37
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc2
-rw-r--r--compiler-rt/test/builtins/Unit/fixunstfdi_test.c19
-rw-r--r--compiler-rt/test/builtins/Unit/multc3_test.c26
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp3
-rw-r--r--compiler-rt/test/xray/TestCases/Posix/patching-unpatching.c56
6 files changed, 107 insertions, 36 deletions
diff --git a/compiler-rt/include/xray/xray_interface.h b/compiler-rt/include/xray/xray_interface.h
index 675ea0c..3ef8ee3 100644
--- a/compiler-rt/include/xray/xray_interface.h
+++ b/compiler-rt/include/xray/xray_interface.h
@@ -1,4 +1,4 @@
-//===- xray_interface.h -----------------------------------------*- C++ -*-===//
+//===- xray_interface.h ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -14,10 +14,17 @@
#ifndef XRAY_XRAY_INTERFACE_H
#define XRAY_XRAY_INTERFACE_H
+#ifdef __cplusplus
#include <cstddef>
#include <cstdint>
+#else
+#include <stddef.h>
+#include <stdint.h>
+#endif
+#ifdef __cplusplus
extern "C" {
+#endif
/// Synchronize this with AsmPrinter::SledKind in LLVM.
enum XRayEntryType {
@@ -49,7 +56,7 @@ enum XRayEntryType {
/// achieved by marking them all with: __attribute__((xray_never_instrument))
///
/// Returns 1 on success, 0 on error.
-extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));
+extern int __xray_set_handler(void (*entry)(int32_t, enum XRayEntryType));
/// This removes whatever the currently provided handler is. Returns 1 on
/// success, 0 on error.
@@ -60,7 +67,7 @@ extern int __xray_remove_handler();
/// start logging their subsequent affected function calls (if patched).
///
/// Returns 1 on success, 0 on error.
-extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,
+extern int __xray_set_handler_arg1(void (*entry)(int32_t, enum XRayEntryType,
uint64_t));
/// Disables the XRay handler used to log first arguments of function calls.
@@ -68,7 +75,7 @@ extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,
extern int __xray_remove_handler_arg1();
/// Provide a function to invoke when XRay encounters a custom event.
-extern int __xray_set_customevent_handler(void (*entry)(void *, std::size_t));
+extern int __xray_set_customevent_handler(void (*entry)(void *, size_t));
/// This removes whatever the currently provided custom event handler is.
/// Returns 1 on success, 0 on error.
@@ -95,39 +102,39 @@ enum XRayPatchingStatus {
/// This tells XRay to patch the instrumentation points in all currently loaded
/// objects. See XRayPatchingStatus for possible result values.
-extern XRayPatchingStatus __xray_patch();
+extern enum XRayPatchingStatus __xray_patch();
/// This tells XRay to patch the instrumentation points in the given object.
/// See XRayPatchingStatus for possible result values.
-extern XRayPatchingStatus __xray_patch_object(int32_t ObjId);
+extern enum XRayPatchingStatus __xray_patch_object(int32_t ObjId);
/// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
/// result values.
-extern XRayPatchingStatus __xray_unpatch();
+extern enum XRayPatchingStatus __xray_unpatch();
/// Reverses the effect of __xray_patch_object. See XRayPatchingStatus for
/// possible result values.
-extern XRayPatchingStatus __xray_unpatch_object(int32_t ObjId);
+extern enum XRayPatchingStatus __xray_unpatch_object(int32_t ObjId);
/// This unpacks the given (packed) function id and patches
/// the corresponding function. See XRayPatchingStatus for possible
/// result values.
-extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);
+extern enum XRayPatchingStatus __xray_patch_function(int32_t FuncId);
/// This patches a specific function in the given object. See XRayPatchingStatus
/// for possible result values.
-extern XRayPatchingStatus __xray_patch_function_in_object(int32_t FuncId,
- int32_t ObjId);
+extern enum XRayPatchingStatus __xray_patch_function_in_object(int32_t FuncId,
+ int32_t ObjId);
/// This unpacks the given (packed) function id and unpatches
/// the corresponding function. See XRayPatchingStatus for possible
/// result values.
-extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);
+extern enum XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);
/// This unpatches a specific function in the given object.
/// See XRayPatchingStatus for possible result values.
-extern XRayPatchingStatus __xray_unpatch_function_in_object(int32_t FuncId,
- int32_t ObjId);
+extern enum XRayPatchingStatus __xray_unpatch_function_in_object(int32_t FuncId,
+ int32_t ObjId);
/// This function unpacks the given (packed) function id and returns the address
/// of the corresponding function. We return 0 if we encounter any error, even
@@ -173,6 +180,8 @@ extern int32_t __xray_pack_id(int32_t FuncId, int32_t ObjId);
/// Calling __xray_init() more than once is safe across multiple threads.
extern void __xray_init();
+#ifdef __cplusplus
} // end extern "C"
+#endif
#endif // XRAY_XRAY_INTERFACE_H
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index a96d325..b10ce7f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1326,7 +1326,7 @@ PRCTL_INTERCEPTOR(int, prctl, int option, unsigned long arg2,
static const int PR_SET_SECCOMP = 22;
static const int SECCOMP_MODE_FILTER = 2;
# endif
- if (option == PR_SET_VMA && arg2 == 0UL) {
+ if (option == PR_SET_VMA && arg2 == 0UL && arg5 != 0UL) {
char *name = (char *)arg5;
COMMON_INTERCEPTOR_READ_RANGE(ctx, name, internal_strlen(name) + 1);
}
diff --git a/compiler-rt/test/builtins/Unit/fixunstfdi_test.c b/compiler-rt/test/builtins/Unit/fixunstfdi_test.c
index 982f3a4..526ba5c 100644
--- a/compiler-rt/test/builtins/Unit/fixunstfdi_test.c
+++ b/compiler-rt/test/builtins/Unit/fixunstfdi_test.c
@@ -1,24 +1,25 @@
-// XFAIL: target=aarch64-{{.*}}-windows-{{.*}}
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_fixunstfdi
#include <stdio.h>
+#include "int_lib.h"
-#if _ARCH_PPC || __aarch64__ || __arm64ec__
+#if defined(CRT_HAS_TF_MODE)
-#include "int_lib.h"
+#define QUAD_PRECISION
+#include "fp_lib.h"
// Returns: convert a to a unsigned long long, rounding toward zero.
// Negative values all become zero.
-// Assumption: long double is a 128 bit floating point type
+// Assumption: fp_t is a 128 bit floating point type
// du_int is a 64 bit integral type
-// value in long double is representable in du_int or is negative
+// value in fp_t is representable in du_int or is negative
// (no range checking performed)
-COMPILER_RT_ABI du_int __fixunstfdi(long double a);
+COMPILER_RT_ABI du_int __fixunstfdi(fp_t a);
-int test__fixunstfdi(long double a, du_int expected)
+int test__fixunstfdi(fp_t a, du_int expected)
{
du_int x = __fixunstfdi(a);
if (x != expected)
@@ -29,13 +30,13 @@ int test__fixunstfdi(long double a, du_int expected)
char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};
-char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
+char assumption_3[sizeof(fp_t)*CHAR_BIT == 128] = {0};
#endif
int main()
{
-#if _ARCH_PPC || __aarch64__ || __arm64ec__
+#if defined(CRT_HAS_TF_MODE)
if (test__fixunstfdi(0.0, 0))
return 1;
diff --git a/compiler-rt/test/builtins/Unit/multc3_test.c b/compiler-rt/test/builtins/Unit/multc3_test.c
index e9c99a7..18561cc 100644
--- a/compiler-rt/test/builtins/Unit/multc3_test.c
+++ b/compiler-rt/test/builtins/Unit/multc3_test.c
@@ -1,24 +1,26 @@
-// XFAIL: target=aarch64-{{.*}}-windows-{{.*}}
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_multc3
#include <stdio.h>
+#include "int_lib.h"
-#if _ARCH_PPC || __aarch64__ || __arm64ec__
+#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
-#include "int_lib.h"
#include <math.h>
#include <complex.h>
// Returns: the product of a + ib and c + id
-COMPILER_RT_ABI long double _Complex
-__multc3(long double __a, long double __b, long double __c, long double __d);
+COMPILER_RT_ABI Qcomplex
+__multc3(fp_t __a, fp_t __b, fp_t __c, fp_t __d);
enum {zero, non_zero, inf, NaN, non_zero_nan};
int
-classify(long double _Complex x)
+classify(Qcomplex x)
{
if (x == 0)
return zero;
@@ -41,13 +43,13 @@ classify(long double _Complex x)
return non_zero;
}
-int test__multc3(long double a, long double b, long double c, long double d)
+int test__multc3(fp_t a, fp_t b, fp_t c, fp_t d)
{
- long double _Complex r = __multc3(a, b, c, d);
+ Qcomplex r = __multc3(a, b, c, d);
// printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n",
// a, b, c, d, creall(r), cimagl(r));
- long double _Complex dividend;
- long double _Complex divisor;
+ Qcomplex dividend;
+ Qcomplex divisor;
__real__ dividend = a;
__imag__ dividend = b;
@@ -188,7 +190,7 @@ int test__multc3(long double a, long double b, long double c, long double d)
return 0;
}
-long double x[][2] =
+fp_t x[][2] =
{
{ 1.e-6, 1.e-6},
{-1.e-6, 1.e-6},
@@ -348,7 +350,7 @@ long double x[][2] =
int main()
{
-#if _ARCH_PPC || __aarch64__ || __arm64ec__
+#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
const unsigned N = sizeof(x) / sizeof(x[0]);
unsigned i, j;
for (i = 0; i < N; ++i)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
index dab1d1b..afce9dc 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
@@ -88,5 +88,8 @@ int main() {
res = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &pr);
assert(res == -1);
+ unsigned long name = reinterpret_cast<unsigned long>(nullptr);
+ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, 0, nullptr, name);
+
return 0;
}
diff --git a/compiler-rt/test/xray/TestCases/Posix/patching-unpatching.c b/compiler-rt/test/xray/TestCases/Posix/patching-unpatching.c
new file mode 100644
index 0000000..2dbc681
--- /dev/null
+++ b/compiler-rt/test/xray/TestCases/Posix/patching-unpatching.c
@@ -0,0 +1,56 @@
+// Check that we can patch and un-patch on demand, and that logging gets invoked
+// appropriately.
+//
+// Do not run on powerpc64le, as linking XRay with C compiler causes linker error
+// due to std::__throw_system_error(int) being present in XRay libraries.
+// See https://github.com/llvm/llvm-project/issues/141598
+//
+// RUN: %clang_xray -fxray-instrument -std=c23 %s -o %t
+// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s
+// RUN: %clang_xray -fxray-instrument -fno-xray-function-index -std=c23 %s -o %t
+// RUN: env XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s
+
+// UNSUPPORTED: target-is-mips64,target-is-mips64el
+// UNSUPPORTED: target=powerpc64le-{{.*}}
+
+#include "xray/xray_interface.h"
+
+#include <stdio.h>
+
+bool called = false;
+
+void test_handler(int32_t fid, enum XRayEntryType type) {
+ printf("called: %d, type=%d\n", fid, (int32_t)(type));
+ called = true;
+}
+
+[[clang::xray_always_instrument]] void always_instrument() {
+ printf("always instrumented called\n");
+}
+
+int main() {
+ __xray_set_handler(test_handler);
+ always_instrument();
+ // CHECK: always instrumented called
+ auto status = __xray_patch();
+ printf("patching status: %d\n", (int32_t)status);
+ // CHECK-NEXT: patching status: 1
+ always_instrument();
+ // CHECK-NEXT: called: {{.*}}, type=0
+ // CHECK-NEXT: always instrumented called
+ // CHECK-NEXT: called: {{.*}}, type=1
+ status = __xray_unpatch();
+ printf("patching status: %d\n", (int32_t)status);
+ // CHECK-NEXT: patching status: 1
+ always_instrument();
+ // CHECK-NEXT: always instrumented called
+ status = __xray_patch();
+ printf("patching status: %d\n", (int32_t)status);
+ // CHECK-NEXT: patching status: 1
+ __xray_remove_handler();
+ always_instrument();
+ // CHECK-NEXT: always instrumented called
+ status = __xray_unpatch();
+ printf("patching status: %d\n", (int32_t)status);
+ // CHECK-NEXT: patching status: 1
+}