[PATCH] D37631: [libFuzzer] Support using libc++
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 14 11:31:24 PDT 2017
phosek updated this revision to Diff 115251.
phosek edited the summary of this revision.
phosek added a comment.
This does seem to work. Right now it's only used if `COMPILER_RT_ENABLE_LIBCXX` is set, but we can make it the default whenever libc++ source is available if that's fine with you.
https://reviews.llvm.org/D37631
Files:
lib/fuzzer/CMakeLists.txt
Index: lib/fuzzer/CMakeLists.txt
===================================================================
--- lib/fuzzer/CMakeLists.txt
+++ lib/fuzzer/CMakeLists.txt
@@ -32,6 +32,20 @@
set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
+option(COMPILER_RT_ENABLE_LIBCXX "Use libc++ if available." OFF)
+
+if (COMPILER_RT_ENABLE_LIBCXX)
+ check_cxx_compiler_flag("-stdlib=libc++" COMPILER_RT_CXX_SUPPORTS_STDLIB)
+ if(COMPILER_RT_CXX_SUPPORTS_STDLIB)
+ list(APPEND LIBFUZZER_CFLAGS -stdlib=libc++)
+ if(COMPILER_RT_HAS_LIBCXX_SOURCES)
+ list(APPEND LIBFUZZER_CFLAGS -D_LIBCPP_ABI_VERSION=Fuzzer)
+ endif()
+ else()
+ message(WARNING "Can't specify libc++ with '-stdlib='")
+ endif()
+endif()
+
if (CMAKE_CXX_FLAGS MATCHES "fsanitize-coverage")
list(APPEND LIBFUZZER_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters)
endif()
@@ -72,6 +86,25 @@
CFLAGS ${LIBFUZZER_CFLAGS}
PARENT_TARGET fuzzer)
+if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
+ COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang")
+ foreach(arch ${FUZZER_SUPPORTED_ARCH})
+ get_target_flags_for_arch(${arch} TARGET_CFLAGS)
+ set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_fuzzer_${arch})
+ add_custom_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_PREFIX}
+ CFLAGS ${TARGET_CFLAGS} -D_LIBCPP_ABI_VERSION=Fuzzer)
+ add_dependencies(clang_rt.fuzzer-${arch} libcxx_fuzzer_${arch})
+ add_custom_command(TARGET clang_rt.fuzzer-${arch} POST_BUILD
+ COMMAND
+ ${PYTHON_EXECUTABLE} ${COMPILER_RT_LIBCXX_PATH}/utils/merge_archives.py
+ ARGS
+ -o $<TARGET_LINKER_FILE:clang_rt.fuzzer-${arch}>
+ "$<TARGET_LINKER_FILE:clang_rt.fuzzer-${arch}>"
+ "${CMAKE_CURRENT_BINARY_DIR}/libcxx_fuzzer_${arch}/lib/libc++.a"
+ )
+ endforeach()
+endif()
+
if(COMPILER_RT_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37631.115251.patch
Type: text/x-patch
Size: 1879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170914/4129648b/attachment.bin>
More information about the llvm-commits
mailing list