Skip to content

Commit 0493bb8

Browse files
committed
Update libfuzzer to 4a4cafa
1 parent 9108379 commit 0493bb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1259
-666
lines changed

libfuzzer/CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ set(LIBFUZZER_HEADERS
4646
FuzzerUtil.h
4747
FuzzerValueBitMap.h)
4848

49+
include_directories(../../include)
50+
4951
CHECK_CXX_SOURCE_COMPILES("
5052
static thread_local int blah;
5153
int main() {
@@ -82,8 +84,6 @@ else()
8284
endif()
8385
endif()
8486

85-
set(FUZZER_SUPPORTED_OS ${SANITIZER_COMMON_SUPPORTED_OS})
86-
8787
add_compiler_rt_component(fuzzer)
8888

8989
add_compiler_rt_object_libraries(RTfuzzer
@@ -101,6 +101,13 @@ add_compiler_rt_object_libraries(RTfuzzer_main
101101
CFLAGS ${LIBFUZZER_CFLAGS}
102102
DEPS ${LIBFUZZER_DEPS})
103103

104+
add_compiler_rt_object_libraries(RTfuzzer_interceptors
105+
OS ${FUZZER_SUPPORTED_OS}
106+
ARCHS ${FUZZER_SUPPORTED_ARCH}
107+
SOURCES FuzzerInterceptors.cpp
108+
CFLAGS ${LIBFUZZER_CFLAGS}
109+
DEPS ${LIBFUZZER_DEPS})
110+
104111
add_compiler_rt_runtime(clang_rt.fuzzer
105112
STATIC
106113
OS ${FUZZER_SUPPORTED_OS}
@@ -117,6 +124,14 @@ add_compiler_rt_runtime(clang_rt.fuzzer_no_main
117124
CFLAGS ${LIBFUZZER_CFLAGS}
118125
PARENT_TARGET fuzzer)
119126

127+
add_compiler_rt_runtime(clang_rt.fuzzer_interceptors
128+
STATIC
129+
OS ${FUZZER_SUPPORTED_OS}
130+
ARCHS ${FUZZER_SUPPORTED_ARCH}
131+
OBJECT_LIBS RTfuzzer_interceptors
132+
CFLAGS ${LIBFUZZER_CFLAGS}
133+
PARENT_TARGET fuzzer)
134+
120135
if(OS_NAME MATCHES "Linux|Fuchsia" AND
121136
COMPILER_RT_LIBCXX_PATH AND
122137
COMPILER_RT_LIBCXXABI_PATH)
@@ -143,12 +158,17 @@ if(OS_NAME MATCHES "Linux|Fuchsia" AND
143158
add_custom_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_${arch}_PREFIX}
144159
CFLAGS ${TARGET_CFLAGS}
145160
CMAKE_ARGS -DCMAKE_CXX_COMPILER_WORKS=ON
146-
-DLIBCXX_ABI_NAMESPACE=Fuzzer)
161+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
162+
-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF
163+
-DLIBCXX_ABI_NAMESPACE=__Fuzzer)
147164
target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
148165
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build)
149166
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
150167
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build)
168+
target_compile_options(RTfuzzer_interceptors.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
169+
add_dependencies(RTfuzzer_interceptors.${arch} libcxx_fuzzer_${arch}-build)
151170
partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch})
171+
partially_link_libcxx(fuzzer_interceptors ${LIBCXX_${arch}_PREFIX} ${arch})
152172
partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch})
153173
endforeach()
154174
endif()

libfuzzer/FuzzerBuiltins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#ifndef LLVM_FUZZER_BUILTINS_H
1212
#define LLVM_FUZZER_BUILTINS_H
1313

14-
#include "FuzzerDefs.h"
14+
#include "FuzzerPlatform.h"
1515

1616
#if !LIBFUZZER_MSVC
1717
#include <cstdint>

libfuzzer/FuzzerBuiltinsMsvc.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
#ifndef LLVM_FUZZER_BUILTINS_MSVC_H
1313
#define LLVM_FUZZER_BUILTINS_MSVC_H
1414

15-
#include "FuzzerDefs.h"
15+
#include "FuzzerPlatform.h"
1616

1717
#if LIBFUZZER_MSVC
18-
#if !defined(_M_ARM) && !defined(_M_X64)
19-
#error "_BitScanReverse64 unavailable on this platform so MSVC is unsupported."
20-
#endif
2118
#include <intrin.h>
2219
#include <cstdint>
2320
#include <cstdlib>
@@ -40,7 +37,18 @@ inline uint64_t Bswap(uint64_t x) { return _byteswap_uint64(x); }
4037
// outside of Windows.
4138
inline uint32_t Clzll(uint64_t X) {
4239
unsigned long LeadZeroIdx = 0;
40+
41+
#if !defined(_M_ARM) && !defined(_M_X64)
42+
// Scan the high 32 bits.
43+
if (_BitScanReverse(&LeadZeroIdx, static_cast<unsigned long>(X >> 32)))
44+
return static_cast<int>(63 - (LeadZeroIdx + 32)); // Create a bit offset from the MSB.
45+
// Scan the low 32 bits.
46+
if (_BitScanReverse(&LeadZeroIdx, static_cast<unsigned long>(X)))
47+
return static_cast<int>(63 - LeadZeroIdx);
48+
49+
#else
4350
if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
51+
#endif
4452
return 64;
4553
}
4654

@@ -50,7 +58,13 @@ inline uint32_t Clz(uint32_t X) {
5058
return 32;
5159
}
5260

53-
inline int Popcountll(unsigned long long X) { return __popcnt64(X); }
61+
inline int Popcountll(unsigned long long X) {
62+
#if !defined(_M_ARM) && !defined(_M_X64)
63+
return __popcnt(X) + __popcnt(X >> 32);
64+
#else
65+
return __popcnt64(X);
66+
#endif
67+
}
5468

5569
} // namespace fuzzer
5670

0 commit comments

Comments
 (0)