-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Fix libFuzzer not building with pthreads on Windows #109525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mstorsjo does this look good to you? |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: None (Zentrik) ChangesFixes #106871 Full diff: https://github.com/llvm/llvm-project/pull/109525.diff 1 Files Affected:
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
index e0210aa0ac3651..ca0a2a9f958caa 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<proc>(
@@ -253,6 +256,7 @@ void SetThreadName(std::thread &thread, const std::string &name) {
}
}
}
+#endif
}
} // namespace fuzzer
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this works for me.
/cherry-pick b4130be |
Fixes llvm#106871 (cherry picked from commit b4130be)
/pull-request #110663 |
Fixes llvm#106871 (cherry picked from commit b4130be)
Fixes llvm#106871 (cherry picked from commit b4130be)
Fixes llvm#106871 (cherry picked from commit b4130be)
Fixes llvm#106871 (cherry picked from commit b4130be)
CC @devnexen This fix breaks with recent changes in libcxx, see #112094 (comment). I guess we could change this to simply not check things for libcxx - but that also puts us in an awkward position - then we know for certain that this code wouldn't simply build on top of libcxx using pthreads. Alternatively we could skip the whole setting of thread names in mingw build configurations. As far as I understand, setting the thread name is just a nice-to-have around here. As we can't really confidently know the configuration (without relying on C++ standard library internals) it is safer to simply skip it. (I'm not aware of anybody using libfuzzer in such mingw configurations - Clang doesn't even support enabling the fuzzer sanitizer in mingw configurations anyway.) |
Fixes #106871