Fix libFuzzer not building with pthreads on Windows (#109525)
authorZentrik <llvm.zentrik@gmail.com>
Tue, 24 Sep 2024 20:33:57 +0000 (21:33 +0100)
committerTobias Hieta <tobias@hieta.se>
Fri, 11 Oct 2024 05:56:48 +0000 (07:56 +0200)
Fixes https://github.com/llvm/llvm-project/issues/106871

(cherry picked from commit b4130bee6bfd34d8045f02fc9f951bcb5db9d85c)

compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp

index db80eb383885e65360a94be7824c99185655f15f..73eea07cf869ffc93d41c97ad7b5cdfe86fa0e4d 100644 (file)
@@ -239,6 +239,10 @@ size_t PageSize() {
 }
 
 void SetThreadName(std::thread &thread, const std::string &name) {
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) ||                                 \
+    defined(_GLIBCXX_GCC_GTHR_POSIX_H)
+  (void)pthread_setname_np(thread.native_handle(), name.c_str());
+#else
   typedef HRESULT(WINAPI * proc)(HANDLE, PCWSTR);
   HMODULE kbase = GetModuleHandleA("KernelBase.dll");
   proc ThreadNameProc =
@@ -253,6 +257,7 @@ void SetThreadName(std::thread &thread, const std::string &name) {
       }
     }
   }
+#endif
 }
 
 } // namespace fuzzer