Skip to content

Commit

Permalink
Update libFuzzer to 19.x
Browse files Browse the repository at this point in the history
This updates libFuzzer to the latest LLVM version, 19.x. Specifically, commit
`ab51eccf88f5321e7c60591c5546b254b6afab99`.
  • Loading branch information
fitzgen committed Nov 7, 2024
1 parent 94c9045 commit 1a23bcd
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions libfuzzer/FuzzerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static void PulseThread() {

static void WorkerThread(const Command &BaseCmd, std::atomic<unsigned> *Counter,
unsigned NumJobs, std::atomic<bool> *HasErrors) {
ScopedDisableMsanInterceptorChecks S;
while (true) {
unsigned C = (*Counter)++;
if (C >= NumJobs) break;
Expand Down
2 changes: 1 addition & 1 deletion libfuzzer/FuzzerFork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void FuzzWithFork(Random &Rand, const FuzzingOptions &Options,
&NewFeatures, Env.Cov, &NewCov, CFPath,
/*Verbose=*/false, /*IsSetCoverMerge=*/false);
Env.Features.insert(NewFeatures.begin(), NewFeatures.end());
Env.Cov.insert(NewFeatures.begin(), NewFeatures.end());
Env.Cov.insert(NewCov.begin(), NewCov.end());
RemoveFile(CFPath);
}

Expand Down
5 changes: 3 additions & 2 deletions libfuzzer/FuzzerUtilFuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void CrashHandler() {
zx_wait_item_t WaitItems[] = {
{
.handle = SignalHandlerEvent,
.waitfor = ZX_SIGNAL_HANDLE_CLOSED,
.waitfor = ZX_USER_SIGNAL_1,
.pending = 0,
},
{
Expand Down Expand Up @@ -378,10 +378,11 @@ void CrashHandler() {
}

void StopSignalHandler() {
_zx_handle_close(SignalHandlerEvent);
_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_1);
if (SignalHandler.joinable()) {
SignalHandler.join();
}
_zx_handle_close(SignalHandlerEvent);
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion libfuzzer/FuzzerUtilLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void SetThreadName(std::thread &thread, const std::string &name) {
#if LIBFUZZER_LINUX || LIBFUZZER_FREEBSD
(void)pthread_setname_np(thread.native_handle(), name.c_str());
#elif LIBFUZZER_NETBSD
(void)pthread_set_name_np(thread.native_handle(), "%s", name.c_str());
(void)pthread_setname_np(thread.native_handle(), "%s", const_cast<char *>(name.c_str()));
#endif
}

Expand Down
30 changes: 26 additions & 4 deletions libfuzzer/FuzzerUtilWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
// clang-format off
#include <windows.h>

// This must be included after windows.h.
// These must be included after windows.h.
// archicture need to be set before including
// libloaderapi
#include <libloaderapi.h>
#include <stringapiset.h>
#include <psapi.h>
// clang-format on

namespace fuzzer {

Expand Down Expand Up @@ -234,8 +239,25 @@ size_t PageSize() {
}

void SetThreadName(std::thread &thread, const std::string &name) {
// TODO ?
// to UTF-8 then SetThreadDescription ?
#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>(GetProcAddress(kbase, "SetThreadDescription"));
if (ThreadNameProc) {
std::wstring buf;
auto sz = MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, nullptr, 0);
if (sz > 0) {
buf.resize(sz);
if (MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, &buf[0], sz) > 0) {
(void)ThreadNameProc(thread.native_handle(), buf.c_str());
}
}
}
#endif
}

} // namespace fuzzer
Expand Down
2 changes: 1 addition & 1 deletion libfuzzer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
LIBFUZZER_SRC_DIR=$(dirname $0)
CXX="${CXX:-clang}"
for f in $LIBFUZZER_SRC_DIR/*.cpp; do
$CXX -g -O2 -fno-omit-frame-pointer -std=c++14 $f -c &
$CXX -g -O2 -fno-omit-frame-pointer -std=c++17 $f -c &
done
wait
rm -f libFuzzer.a
Expand Down
10 changes: 5 additions & 5 deletions libfuzzer/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if (APPLE)
endif()

add_custom_target(FuzzerUnitTests)
set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")

add_custom_target(FuzzedDataProviderUnitTests)
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")

set(LIBFUZZER_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS})
list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS --driver-mode=g++)
Expand Down Expand Up @@ -58,7 +58,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
${LIBFUZZER_TEST_RUNTIME_OBJECTS})
set_target_properties(${LIBFUZZER_TEST_RUNTIME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
FOLDER "Compiler-RT Runtime tests")
FOLDER "Compiler-RT/Tests/Runtime")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
COMPILER_RT_LIBCXX_PATH AND
Expand All @@ -74,7 +74,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
FuzzerUnitTests "Fuzzer-${arch}-Test" ${arch}
SOURCES FuzzerUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
RUNTIME ${LIBFUZZER_TEST_RUNTIME}
DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS}
DEPS ${LIBFUZZER_TEST_RUNTIME_DEPS}
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
set_target_properties(FuzzerUnitTests PROPERTIES
Expand All @@ -84,7 +84,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
generate_compiler_rt_tests(FuzzedDataProviderTestObjects
FuzzedDataProviderUnitTests "FuzzerUtils-${arch}-Test" ${arch}
SOURCES FuzzedDataProviderUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
DEPS ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
set_target_properties(FuzzedDataProviderUnitTests PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion update-libfuzzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -ex

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

cd "$(dirname $0)"
project_dir="$(pwd)"
Expand Down

0 comments on commit 1a23bcd

Please sign in to comment.