[llvm] 822c31a - [llvm-exegesis] Guard `__builtin_thread_pointer` behind a configure check

Markus Böck via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 23:03:34 PDT 2023


Author: Markus Böck
Date: 2023-07-21T08:03:26+02:00
New Revision: 822c31a0fe827a6f33601ad6b44eb2818350da36

URL: https://github.com/llvm/llvm-project/commit/822c31a0fe827a6f33601ad6b44eb2818350da36
DIFF: https://github.com/llvm/llvm-project/commit/822c31a0fe827a6f33601ad6b44eb2818350da36.diff

LOG: [llvm-exegesis] Guard `__builtin_thread_pointer` behind a configure check

Due to arguably a bug in GCC[0], using `__has_builtin` is not sufficient to check whether `__builtin_thread_pointer` can actually be compiled by GCC. This makes it impossible to compile LLVM with `llvm-exegesis` enabled with e.g. GCC 10 as it does have the builtin, but no implementation for architectures such as x86.

This patch works around this issue by making it a cmake configure check whether the builtin can be compiled and used, rather than relying on the broken preprocessor macro.

[0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96952, demonstration: https://godbolt.org/z/9z5nWM6Ef

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

Added: 
    

Modified: 
    llvm/cmake/config-ix.cmake
    llvm/include/llvm/Config/config.h.cmake
    llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 1c11056593e9ac..f63c3f1a351f4d 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -10,6 +10,7 @@ include(CheckCXXSymbolExists)
 include(CheckFunctionExists)
 include(CheckStructHasMember)
 include(CheckCCompilerFlag)
+include(CheckCSourceCompiles)
 include(CMakePushCheckState)
 
 include(CheckCompilerVersion)
@@ -63,12 +64,17 @@ check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
 check_include_file(fenv.h HAVE_FENV_H)
 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
+check_c_source_compiles("
+        void *foo() {
+          return __builtin_thread_pointer();
+        }
+        int main(void) { return 0; }"
+        HAVE_BUILTIN_THREAD_POINTER)
 
 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
 check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
 if(APPLE)
-  include(CheckCSourceCompiles)
-  CHECK_C_SOURCE_COMPILES("
+  check_c_source_compiles("
      static const char *__crashreporter_info__ = 0;
      asm(\".desc ___crashreporter_info__, 0x10\");
      int main(void) { return 0; }"

diff  --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake
index 216919078c7aa5..fc1f9bf342f8d5 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -331,4 +331,6 @@
 
 #cmakedefine HAVE_PROC_PID_RUSAGE 1
 
+#cmakedefine HAVE_BUILTIN_THREAD_POINTER ${HAVE_BUILTIN_THREAD_POINTER}
+
 #endif

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 5acc8856d95405..e429ea57b5b27f 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -39,7 +39,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-#if defined(__GLIBC__) && __has_include(<sys/rseq.h>) && __has_builtin(__builtin_thread_pointer)
+#if defined(__GLIBC__) && __has_include(<sys/rseq.h>) && defined(HAVE_BUILTIN_THREAD_POINTER)
 #include <sys/rseq.h>
 #ifdef RSEQ_SIG
 #define GLIBC_INITS_RSEQ


        


More information about the llvm-commits mailing list