This is an archive of the discontinued LLVM Phabricator instance.

[Fuzzer] SetThreadName implementation for Windows
Needs RevisionPublic

Authored by devnexen on Jul 26 2023, 4:57 AM.

Diff Detail

Event Timeline

devnexen created this revision.Jul 26 2023, 4:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 4:57 AM
Herald added a subscriber: Enna1. · View Herald Transcript
devnexen requested review of this revision.Jul 26 2023, 4:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 4:57 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Jul 26 2023, 5:22 PM
vitalybuka added inline comments.
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
239–241

Why just 16?

This revision is now accepted and ready to land.Jul 26 2023, 5:22 PM
devnexen added inline comments.Jul 26 2023, 10:46 PM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
239–241

just precaution, the real limit is probably higher I just do not know, we can always adjust later.

This revision was landed with ongoing or failed builds.Jul 26 2023, 10:55 PM
This revision was automatically updated to reflect the committed changes.

Not sure I really get the fuzzer failure, what s going on about gtest ?

This revision is now accepted and ready to land.Jul 27 2023, 9:10 AM
vitalybuka added inline comments.Jul 27 2023, 9:20 AM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240

ah right your changes make sense

Not big deal, as a very few bots run libFuzzer on Windows, but asking for review is not quick fix.

From https://llvm.org/docs/DeveloperPolicy.html#id18

If you break a buildbot in a way which can’t be quickly fixed, please revert.

vitalybuka added inline comments.Jul 27 2023, 9:29 AM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240

I don't have Windows, about is a guess, I am not sure if it's compile as-is.

vitalybuka added inline comments.Jul 27 2023, 9:30 AM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240
vitalybuka added inline comments.Jul 27 2023, 9:31 AM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240

and obviously wname[0] -> &wname[0] in the second call

devnexen added inline comments.Jul 27 2023, 1:12 PM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240

in fact, in the first call wname[0] is not even needed no ? according to the example.

devnexen added inline comments.Jul 27 2023, 1:21 PM
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
240

ah you said it already.. ok I ll get to it soonish

devnexen updated this revision to Diff 544945.Jul 27 2023, 3:08 PM

advices from vitalybuka

This revision was automatically updated to reflect the committed changes.
phosek added a subscriber: phosek.Jul 27 2023, 8:22 PM

This broke the Windows build, would it be possible to take a look and revert if necessary?

/b/s/w/ir/x/w/llvm_build/./bin/clang-cl --target=x86_64-pc-windows-msvc  /nologo -TP -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_HARDENED_MODE -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/fuzzer/../../include -Xclang -ivfsoverlay -Xclang /b/s/w/ir/cache/windows_sdk/llvm-vfsoverlay.yaml /winsysroot /b/s/w/ir/cache/windows_sdk /Zc:inline /Zc:__cplusplus /Oi /bigobj /permissive- -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -w14062 -we4238 /Gw -no-canonical-prefixes /W4 -Wno-unused-parameter  /Z7 /O2 /Ob1  -std:c++17 -MT -fno-builtin -fno-sanitize=safe-stack -fno-lto /Oy- /GS- /Zc:threadSafeInit- -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta /Z7 -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions /wd4146 /wd4291 /wd4391 /wd4722 /wd4800 -D_HAS_EXCEPTIONS=0 /showIncludes /Focompiler-rt/lib/fuzzer/CMakeFiles/RTfuzzer.x86_64.dir/FuzzerUtilWindows.cpp.obj /Fdcompiler-rt/lib/fuzzer/CMakeFiles/RTfuzzer.x86_64.dir/ -c -- /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp(239,16): error: no matching constructor for initialization of 'std::wstring' (aka 'basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>')
  239 |   std::wstring wname(sz);
      |                ^     ~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2619,27): note: candidate constructor not viable: no known conversion from 'int' to 'const std::allocator<wchar_t>' for 1st argument
 2619 |     _CONSTEXPR20 explicit basic_string(const _Alloc& _Al) noexcept : _Mypair(_One_then_variadic_args_t{}, _Al) {
      |                           ^            ~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2624,18): note: candidate constructor not viable: no known conversion from 'int' to 'const basic_string<wchar_t>' for 1st argument
 2624 |     _CONSTEXPR20 basic_string(const basic_string& _Right)
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2673,18): note: candidate constructor not viable: no known conversion from 'int' to 'const wchar_t *const' for 1st argument
 2673 |     _CONSTEXPR20 basic_string(_In_z_ const _Elem* const _Ptr) : _Mypair(_Zero_then_variadic_args_t{}) {
      |                  ^                   ~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2887,18): note: candidate constructor not viable: no known conversion from 'int' to 'basic_string<wchar_t>' for 1st argument
 2887 |     _CONSTEXPR20 basic_string(basic_string&& _Right) noexcept
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(3221,18): note: candidate constructor not viable: no known conversion from 'int' to 'initializer_list<wchar_t>' for 1st argument
 3221 |     _CONSTEXPR20 basic_string(initializer_list<_Elem> _Ilist, const _Alloc& _Al = allocator_type())
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(3021,27): note: candidate template ignored: requirement 'conjunction_v<std::is_convertible<const int &, std::basic_string_view<wchar_t, std::char_traits<wchar_t>>>, std::negation<std::is_convertible<const int &, const wchar_t *>>>' was not satisfied [with _StringViewIsh = int]
 3021 |     _CONSTEXPR20 explicit basic_string(const _StringViewIsh& _Right, const _Alloc& _Al = _Alloc())
      |                           ^
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2613,18): note: candidate constructor not viable: requires 0 arguments, but 1 was provided
 2613 |     _CONSTEXPR20 basic_string() noexcept(is_nothrow_default_constructible_v<_Alty>)
      |                  ^
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2629,18): note: candidate constructor not viable: requires 2 arguments, but 1 was provided
 2629 |     _CONSTEXPR20 basic_string(const basic_string& _Right, const _Alloc& _Al)
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2662,18): note: candidate constructor not viable: requires 2 arguments, but 1 was provided
 2662 |     _CONSTEXPR20 basic_string(_In_reads_(_Count) const _Elem* const _Ptr, _CRT_GUARDOVERFLOW const size_type _Count)
      |                  ^                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2684,18): note: candidate constructor template not viable: requires 2 arguments, but 1 was provided
 2684 |     _CONSTEXPR20 basic_string(_In_z_ const _Elem* const _Ptr, const _Alloc& _Al)
      |                  ^                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2689,18): note: candidate constructor not viable: requires 2 arguments, but 1 was provided
 2689 |     _CONSTEXPR20 basic_string(_CRT_GUARDOVERFLOW const size_type _Count, const _Elem _Ch)
      |                  ^                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2893,18): note: candidate constructor not viable: requires 2 arguments, but 1 was provided
 2893 |     _CONSTEXPR20 basic_string(basic_string&& _Right, const _Alloc& _Al) noexcept(
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2634,18): note: candidate constructor not viable: requires at least 2 arguments, but 1 was provided
 2634 |     _CONSTEXPR20 basic_string(const basic_string& _Right, const size_type _Roff, const _Alloc& _Al = _Alloc())
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2667,18): note: candidate constructor not viable: requires 3 arguments, but 1 was provided
 2668 |     _CONSTEXPR20 basic_string(
      |                  ^
 2669 |         _In_reads_(_Count) const _Elem* const _Ptr, _CRT_GUARDOVERFLOW const size_type _Count, const _Alloc& _Al)
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2697,18): note: candidate constructor template not viable: requires 3 arguments, but 1 was provided
 2697 |     _CONSTEXPR20 basic_string(_CRT_GUARDOVERFLOW const size_type _Count, const _Elem _Ch, const _Alloc& _Al)
      |                  ^                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2703,18): note: candidate constructor template not viable: requires at least 2 arguments, but 1 was provided
 2703 |     _CONSTEXPR20 basic_string(_Iter _First, _Iter _Last, const _Alloc& _Al = _Alloc())
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2945,18): note: candidate constructor not viable: requires 3 arguments, but 1 was provided
 2945 |     _CONSTEXPR20 basic_string(_String_constructor_concat_tag, basic_string& _Left, basic_string& _Right)
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2641,18): note: candidate constructor not viable: requires at least 3 arguments, but 1 was provided
 2642 |     _CONSTEXPR20 basic_string(
      |                  ^
 2643 |         const basic_string& _Right, const size_type _Roff, const size_type _Count, const _Alloc& _Al = _Alloc())
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(3028,18): note: candidate constructor template not viable: requires at least 3 arguments, but 1 was provided
 3029 |     _CONSTEXPR20 basic_string(
      |                  ^
 3030 |         const _Ty& _Right, const size_type _Roff, const size_type _Count, const _Alloc& _Al = _Alloc())
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/b/s/w/ir/cache/windows_sdk/VC/Tools/MSVC/14.34.31933/include/xstring(2908,18): note: candidate constructor not viable: requires 6 arguments, but 1 was provided
 2908 |     _CONSTEXPR20 basic_string(_String_constructor_concat_tag, const basic_string& _Source_of_al,
      |                  ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2909 |         const _Elem* const _Left_ptr, const size_type _Left_size, const _Elem* const _Right_ptr,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2910 |         const size_type _Right_size)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@phosek done
@vitalybuka almost there :) what about ?

std::wstring wname;
wname.resize(sz);
devnexen reopened this revision.Jul 28 2023, 1:12 AM
This revision is now accepted and ready to land.Jul 28 2023, 1:12 AM
devnexen updated this revision to Diff 545236.Jul 28 2023, 11:54 AM

new attempt

devnexen updated this revision to Diff 545265.Jul 28 2023, 1:51 PM
if (sz == MultiByteToWideChar(CP_UTF8, 0, name.data, name.size, &wname[0], sz) > 0)

Compilation failures on name.data and name.size invocations without paranthesis is breaking the builds.
Can you please fix this ASAP or revert? Thank you.

vitalybuka requested changes to this revision.EditedAug 28 2023, 12:27 PM

Now it fails with

---------------------------
fuzzer-oom.test.tmp-OutOfMemoryTest.exe - Entry Point Not Found
---------------------------
The procedure entry point SetThreadDescription could not be located in the dynamic link library C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\fuzzer\X86_64DefaultWindowsConfig\Output\fuzzer-oom.test.tmp-OutOfMemoryTest.exe. 
---------------------------
OK   
---------------------------
This revision now requires changes to proceed.Aug 28 2023, 12:27 PM

oh it feels like you can t call it directly but maybe via a dlopen/dlsym sort of mechanism. getting complicated :) but we ll see.