Skip to content

Commit 87f4bc0

Browse files
authored
[compiler-rt] [fuzzer] Skip trying to set the thread name on MinGW (llvm#115167)
Since b4130be, we check for _LIBCPP_HAS_THREAD_API_PTHREAD to decide between using SetThreadDescription or pthread_setname_np for setting the thread name. c6f3b7b changed how libcxx defines their configuration macros - now they are always defined, but defined to 0 or 1, while they previously were either defined or undefined. As these libcxx defines used to be defined to an empty string (rather than expanding to 1) if enabled, we can't easily produce an expression that works both with older and newer libcxx. Additionally, these defines are libcxx internal config macros that aren't a detail that isn't supported and isn't meant to be relied upon. Simply skip trying to set thread name on MinGW as we can't easily know which kind of thread native handle we have. Setting the thread name is only a nice to have, quality of life improvement - things should work the same even without it. Additionally, libfuzzer isn't generally usable on MinGW targets yet (Clang doesn't include it in the getSupportedSanitizers() method for the MinGW target), so this shouldn't make any difference in practice anyway.
1 parent 21ded66 commit 87f4bc0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ size_t PageSize() {
239239
}
240240

241241
void SetThreadName(std::thread &thread, const std::string &name) {
242-
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
243-
defined(_GLIBCXX_GCC_GTHR_POSIX_H)
244-
(void)pthread_setname_np(thread.native_handle(), name.c_str());
245-
#else
242+
#ifndef __MINGW32__
243+
// Not setting the thread name in MinGW environments. MinGW C++ standard
244+
// libraries can either use native Windows threads or pthreads, so we
245+
// don't know with certainty what kind of thread handle we're getting
246+
// from thread.native_handle() here.
246247
typedef HRESULT(WINAPI * proc)(HANDLE, PCWSTR);
247248
HMODULE kbase = GetModuleHandleA("KernelBase.dll");
248249
proc ThreadNameProc = reinterpret_cast<proc>(

0 commit comments

Comments
 (0)