Skip to content

Commit 1a23bcd

Browse files
committed
Update libFuzzer to 19.x
This updates libFuzzer to the latest LLVM version, 19.x. Specifically, commit `ab51eccf88f5321e7c60591c5546b254b6afab99`.
1 parent 94c9045 commit 1a23bcd

8 files changed

+39
-15
lines changed

libfuzzer/FuzzerDriver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static void PulseThread() {
229229

230230
static void WorkerThread(const Command &BaseCmd, std::atomic<unsigned> *Counter,
231231
unsigned NumJobs, std::atomic<bool> *HasErrors) {
232+
ScopedDisableMsanInterceptorChecks S;
232233
while (true) {
233234
unsigned C = (*Counter)++;
234235
if (C >= NumJobs) break;

libfuzzer/FuzzerFork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void FuzzWithFork(Random &Rand, const FuzzingOptions &Options,
349349
&NewFeatures, Env.Cov, &NewCov, CFPath,
350350
/*Verbose=*/false, /*IsSetCoverMerge=*/false);
351351
Env.Features.insert(NewFeatures.begin(), NewFeatures.end());
352-
Env.Cov.insert(NewFeatures.begin(), NewFeatures.end());
352+
Env.Cov.insert(NewCov.begin(), NewCov.end());
353353
RemoveFile(CFPath);
354354
}
355355

libfuzzer/FuzzerUtilFuchsia.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void CrashHandler() {
292292
zx_wait_item_t WaitItems[] = {
293293
{
294294
.handle = SignalHandlerEvent,
295-
.waitfor = ZX_SIGNAL_HANDLE_CLOSED,
295+
.waitfor = ZX_USER_SIGNAL_1,
296296
.pending = 0,
297297
},
298298
{
@@ -378,10 +378,11 @@ void CrashHandler() {
378378
}
379379

380380
void StopSignalHandler() {
381-
_zx_handle_close(SignalHandlerEvent);
381+
_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_1);
382382
if (SignalHandler.joinable()) {
383383
SignalHandler.join();
384384
}
385+
_zx_handle_close(SignalHandlerEvent);
385386
}
386387

387388
} // namespace

libfuzzer/FuzzerUtilLinux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void SetThreadName(std::thread &thread, const std::string &name) {
4444
#if LIBFUZZER_LINUX || LIBFUZZER_FREEBSD
4545
(void)pthread_setname_np(thread.native_handle(), name.c_str());
4646
#elif LIBFUZZER_NETBSD
47-
(void)pthread_set_name_np(thread.native_handle(), "%s", name.c_str());
47+
(void)pthread_setname_np(thread.native_handle(), "%s", const_cast<char *>(name.c_str()));
4848
#endif
4949
}
5050

libfuzzer/FuzzerUtilWindows.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121
#include <signal.h>
2222
#include <stdio.h>
2323
#include <sys/types.h>
24+
// clang-format off
2425
#include <windows.h>
25-
26-
// This must be included after windows.h.
26+
// These must be included after windows.h.
27+
// archicture need to be set before including
28+
// libloaderapi
29+
#include <libloaderapi.h>
30+
#include <stringapiset.h>
2731
#include <psapi.h>
32+
// clang-format on
2833

2934
namespace fuzzer {
3035

@@ -234,8 +239,25 @@ size_t PageSize() {
234239
}
235240

236241
void SetThreadName(std::thread &thread, const std::string &name) {
237-
// TODO ?
238-
// to UTF-8 then SetThreadDescription ?
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
246+
typedef HRESULT(WINAPI * proc)(HANDLE, PCWSTR);
247+
HMODULE kbase = GetModuleHandleA("KernelBase.dll");
248+
proc ThreadNameProc =
249+
reinterpret_cast<proc>(GetProcAddress(kbase, "SetThreadDescription"));
250+
if (ThreadNameProc) {
251+
std::wstring buf;
252+
auto sz = MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, nullptr, 0);
253+
if (sz > 0) {
254+
buf.resize(sz);
255+
if (MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, &buf[0], sz) > 0) {
256+
(void)ThreadNameProc(thread.native_handle(), buf.c_str());
257+
}
258+
}
259+
}
260+
#endif
239261
}
240262

241263
} // namespace fuzzer

libfuzzer/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LIBFUZZER_SRC_DIR=$(dirname $0)
33
CXX="${CXX:-clang}"
44
for f in $LIBFUZZER_SRC_DIR/*.cpp; do
5-
$CXX -g -O2 -fno-omit-frame-pointer -std=c++14 $f -c &
5+
$CXX -g -O2 -fno-omit-frame-pointer -std=c++17 $f -c &
66
done
77
wait
88
rm -f libFuzzer.a

libfuzzer/tests/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ if (APPLE)
1212
endif()
1313

1414
add_custom_target(FuzzerUnitTests)
15-
set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
15+
set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")
1616

1717
add_custom_target(FuzzedDataProviderUnitTests)
18-
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
18+
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")
1919

2020
set(LIBFUZZER_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS})
2121
list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS --driver-mode=g++)
@@ -58,7 +58,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
5858
${LIBFUZZER_TEST_RUNTIME_OBJECTS})
5959
set_target_properties(${LIBFUZZER_TEST_RUNTIME} PROPERTIES
6060
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
61-
FOLDER "Compiler-RT Runtime tests")
61+
FOLDER "Compiler-RT/Tests/Runtime")
6262

6363
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
6464
COMPILER_RT_LIBCXX_PATH AND
@@ -74,7 +74,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
7474
FuzzerUnitTests "Fuzzer-${arch}-Test" ${arch}
7575
SOURCES FuzzerUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
7676
RUNTIME ${LIBFUZZER_TEST_RUNTIME}
77-
DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS}
77+
DEPS ${LIBFUZZER_TEST_RUNTIME_DEPS}
7878
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
7979
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
8080
set_target_properties(FuzzerUnitTests PROPERTIES
@@ -84,7 +84,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
8484
generate_compiler_rt_tests(FuzzedDataProviderTestObjects
8585
FuzzedDataProviderUnitTests "FuzzerUtils-${arch}-Test" ${arch}
8686
SOURCES FuzzedDataProviderUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
87-
DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
87+
DEPS ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
8888
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
8989
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
9090
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES

update-libfuzzer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -ex
88

99
# The LLVM commit from which we are vendoring libfuzzer. This must be a commit
1010
# hash from https://github.com/llvm/llvm-project
11-
COMMIT=3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff
11+
COMMIT=ab51eccf88f5321e7c60591c5546b254b6afab99
1212

1313
cd "$(dirname $0)"
1414
project_dir="$(pwd)"

0 commit comments

Comments
 (0)