[BOLT] Fix instrumentation problem with floating point
authorMaksim Panchenko <maks@fb.com>
Fri, 1 Jul 2022 01:46:47 +0000 (18:46 -0700)
committerMaksim Panchenko <maks@fb.com>
Fri, 1 Jul 2022 22:29:36 +0000 (15:29 -0700)
If BOLT instrumentation runtime uses XMM registers, it can interfere
with the user program causing crashes and unexpected behavior. This
happens as the instrumentation code preserves general purpose registers
only.

Build BOLT instrumentation runtime with "-mno-sse".

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D128960

bolt/runtime/CMakeLists.txt
bolt/test/runtime/X86/instrumentation-xmm.c [new file with mode: 0644]

index 0ed11dd..7c1b79a 100644 (file)
@@ -23,7 +23,8 @@ set(BOLT_RT_FLAGS
   -ffreestanding
   -fno-exceptions
   -fno-rtti
-  -fno-stack-protector)
+  -fno-stack-protector
+  -mno-sse)
 
 # Don't let the compiler think it can create calls to standard libs
 target_compile_options(bolt_rt_instr PRIVATE ${BOLT_RT_FLAGS} -fPIE)
diff --git a/bolt/test/runtime/X86/instrumentation-xmm.c b/bolt/test/runtime/X86/instrumentation-xmm.c
new file mode 100644 (file)
index 0000000..06002c0
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+void foo(float a) {
+  printf("a = %f\n", a);
+}
+
+typedef void (*fptr_t)(float);
+fptr_t func = foo;
+
+int main() {
+  func(42);
+  return 0;
+}
+
+/*
+## Check that BOLT instrumentation runtime preserves xmm registers.
+
+REQUIRES: system-linux,bolt-runtime
+
+RUN: %clang %cflags %s -o %t.exe -fno-inline -Wl,-q
+RUN: llvm-bolt %t.exe --instrument -o %t.instrumented
+RUN: %t.instrumented | FileCheck %s
+
+CHECK: a = 42.000000
+*/