From 0c1067433727a18d37aa49620e564ab68e646d62 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Sat, 21 Sep 2024 10:10:29 +0100 Subject: [PATCH 1/2] Fix libFuzzer not building with pthreads on Windows Fixes https://github.com/llvm/llvm-project/issues/106871 --- compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp index e0210aa0ac365..ca0a2a9f958ca 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp @@ -239,6 +239,9 @@ 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 = reinterpret_cast( @@ -253,6 +256,7 @@ void SetThreadName(std::thread &thread, const std::string &name) { } } } +#endif } } // namespace fuzzer From 907a0b2c502870351ab512c98c284bd39bc2b291 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Sat, 21 Sep 2024 10:22:12 +0100 Subject: [PATCH 2/2] Format --- compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp index ca0a2a9f958ca..37aecae7237ae 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp @@ -239,7 +239,8 @@ 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) +#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);