Skip to content

Commit 1c6a859

Browse files
author
metzman
committed
[libFuzzer][MSVC] Enable building libFuzzer with MSVC
Summary: Enable building libFuzzer with MSVC. * Don't try to include <endian.h> in FuzzerSHA1.cpp. MSVC doesn't have this header, and WINDOWS is always little endian (even on ARM) Subscribers: srhines, mgorny, javed.absar, kristof.beyls Differential Revision: https://reviews.llvm.org/D56510 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer@351855 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4028449 commit 1c6a859

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ if (CMAKE_CXX_FLAGS MATCHES "fsanitize-coverage")
7171
list(APPEND LIBFUZZER_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters)
7272
endif()
7373

74-
if(NOT HAS_THREAD_LOCAL)
75-
list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread)
74+
if(OS_NAME MATCHES "Windows")
75+
# Silence warnings with /Ehsc and avoid an error by unecessarily defining
76+
# thread_local when it isn't even used on Windows.
77+
list(APPEND LIBFUZZER_CFLAGS /EHsc)
78+
else()
79+
if(NOT HAS_THREAD_LOCAL)
80+
list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread)
81+
endif()
7682
endif()
7783

7884
set(FUZZER_SUPPORTED_OS ${SANITIZER_COMMON_SUPPORTED_OS})

FuzzerBuiltinsMsvc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// __builtin_return_address() cannot be compiled with MSVC. Use the equivalent
2626
// from <intrin.h>
27-
#define GET_CALLER_PC() reinterpret_cast<uintptr_t>(_ReturnAddress())
27+
#define GET_CALLER_PC() _ReturnAddress()
2828

2929
namespace fuzzer {
3030

FuzzerSHA1.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace { // Added for LibFuzzer
3131

3232
#ifdef __BIG_ENDIAN__
3333
# define SHA_BIG_ENDIAN
34-
#elif defined __LITTLE_ENDIAN__
34+
// Windows is always little endian and MSVC doesn't have <endian.h>
35+
#elif defined __LITTLE_ENDIAN__ || LIBFUZZER_WINDOWS
3536
/* override */
3637
#elif defined __BYTE_ORDER
3738
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

FuzzerValueBitMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct ValueBitMap {
3434
uintptr_t WordIdx = Idx / kBitsInWord;
3535
uintptr_t BitIdx = Idx % kBitsInWord;
3636
uintptr_t Old = Map[WordIdx];
37-
uintptr_t New = Old | (1UL << BitIdx);
37+
uintptr_t New = Old | (1ULL << BitIdx);
3838
Map[WordIdx] = New;
3939
return New != Old;
4040
}
@@ -48,7 +48,7 @@ struct ValueBitMap {
4848
assert(Idx < kMapSizeInBits);
4949
uintptr_t WordIdx = Idx / kBitsInWord;
5050
uintptr_t BitIdx = Idx % kBitsInWord;
51-
return Map[WordIdx] & (1UL << BitIdx);
51+
return Map[WordIdx] & (1ULL << BitIdx);
5252
}
5353

5454
size_t SizeInBits() const { return kMapSizeInBits; }

0 commit comments

Comments
 (0)