[compiler-rt] r351855 - [libFuzzer][MSVC] Enable building libFuzzer with MSVC
Jonathan Metzman via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 10:59:25 PST 2019
Author: metzman
Date: Tue Jan 22 10:59:25 2019
New Revision: 351855
URL: http://llvm.org/viewvc/llvm-project?rev=351855&view=rev
Log:
[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
Modified:
compiler-rt/trunk/cmake/config-ix.cmake
compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h
compiler-rt/trunk/lib/fuzzer/FuzzerSHA1.cpp
compiler-rt/trunk/lib/fuzzer/FuzzerValueBitMap.h
Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=351855&r1=351854&r2=351855&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Tue Jan 22 10:59:25 2019
@@ -317,13 +317,13 @@ if(APPLE)
# We're setting the flag manually for each target OS
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
-
+
set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
set(DARWIN_COMMON_LINK_FLAGS
-stdlib=libc++
-lc++
-lc++abi)
-
+
check_linker_flag("-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
if(COMPILER_RT_HAS_APP_EXTENSION)
list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension")
@@ -344,7 +344,7 @@ if(APPLE)
# Figure out which arches to use for each OS
darwin_get_toolchain_supported_archs(toolchain_arches)
message(STATUS "Toolchain supported arches: ${toolchain_arches}")
-
+
if(NOT MACOSX_VERSION_MIN_FLAG)
darwin_test_archs(osx
DARWIN_osx_ARCHS
@@ -648,10 +648,7 @@ else()
endif()
if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
- OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|OpenBSD|Fuchsia|Windows" AND
- # TODO: Support builds with MSVC.
- NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND
- NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
+ OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|OpenBSD|Fuchsia|Windows")
set(COMPILER_RT_HAS_FUZZER TRUE)
else()
set(COMPILER_RT_HAS_FUZZER FALSE)
Modified: compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/CMakeLists.txt?rev=351855&r1=351854&r2=351855&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/fuzzer/CMakeLists.txt Tue Jan 22 10:59:25 2019
@@ -71,8 +71,14 @@ if (CMAKE_CXX_FLAGS MATCHES "fsanitize-c
list(APPEND LIBFUZZER_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters)
endif()
-if(NOT HAS_THREAD_LOCAL)
- list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread)
+if(OS_NAME MATCHES "Windows")
+ # Silence warnings with /Ehsc and avoid an error by unecessarily defining
+ # thread_local when it isn't even used on Windows.
+ list(APPEND LIBFUZZER_CFLAGS /EHsc)
+else()
+ if(NOT HAS_THREAD_LOCAL)
+ list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread)
+ endif()
endif()
set(FUZZER_SUPPORTED_OS ${SANITIZER_COMMON_SUPPORTED_OS})
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h?rev=351855&r1=351854&r2=351855&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerBuiltinsMsvc.h Tue Jan 22 10:59:25 2019
@@ -24,7 +24,7 @@
// __builtin_return_address() cannot be compiled with MSVC. Use the equivalent
// from <intrin.h>
-#define GET_CALLER_PC() reinterpret_cast<uintptr_t>(_ReturnAddress())
+#define GET_CALLER_PC() _ReturnAddress()
namespace fuzzer {
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerSHA1.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerSHA1.cpp?rev=351855&r1=351854&r2=351855&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerSHA1.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerSHA1.cpp Tue Jan 22 10:59:25 2019
@@ -31,7 +31,8 @@ namespace { // Added for LibFuzzer
#ifdef __BIG_ENDIAN__
# define SHA_BIG_ENDIAN
-#elif defined __LITTLE_ENDIAN__
+// Windows is always little endian and MSVC doesn't have <endian.h>
+#elif defined __LITTLE_ENDIAN__ || LIBFUZZER_WINDOWS
/* override */
#elif defined __BYTE_ORDER
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerValueBitMap.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerValueBitMap.h?rev=351855&r1=351854&r2=351855&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerValueBitMap.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerValueBitMap.h Tue Jan 22 10:59:25 2019
@@ -34,7 +34,7 @@ struct ValueBitMap {
uintptr_t WordIdx = Idx / kBitsInWord;
uintptr_t BitIdx = Idx % kBitsInWord;
uintptr_t Old = Map[WordIdx];
- uintptr_t New = Old | (1UL << BitIdx);
+ uintptr_t New = Old | (1ULL << BitIdx);
Map[WordIdx] = New;
return New != Old;
}
@@ -48,7 +48,7 @@ struct ValueBitMap {
assert(Idx < kMapSizeInBits);
uintptr_t WordIdx = Idx / kBitsInWord;
uintptr_t BitIdx = Idx % kBitsInWord;
- return Map[WordIdx] & (1UL << BitIdx);
+ return Map[WordIdx] & (1ULL << BitIdx);
}
size_t SizeInBits() const { return kMapSizeInBits; }
More information about the llvm-commits
mailing list