diff --git a/compiler-rt/lib/fuzzer/CMakeLists.txt b/compiler-rt/lib/fuzzer/CMakeLists.txt --- a/compiler-rt/lib/fuzzer/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/CMakeLists.txt @@ -56,6 +56,7 @@ " HAS_THREAD_LOCAL) set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS}) +set(LIBFUZZER_NOLINK_CFLAGS ${SANITIZER_COMMON_CFLAGS}) if(OS_NAME MATCHES "Linux|Fuchsia" AND COMPILER_RT_LIBCXX_PATH AND @@ -66,11 +67,16 @@ elseif(TARGET cxx-headers OR HAVE_LIBCXX) set(LIBFUZZER_DEPS cxx-headers) endif() +if(TARGET cxx-headers OR HAVE_LIBCXX) + set(LIBFUZZER_NOLINK_DEPS cxx-headers) +endif() append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer LIBFUZZER_CFLAGS) +append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer LIBFUZZER_NOLINK_CFLAGS) if (CMAKE_CXX_FLAGS MATCHES "fsanitize-coverage") list(APPEND LIBFUZZER_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters) + list(APPEND LIBFUZZER_NOLINK_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters) endif() if(MSVC) @@ -78,9 +84,11 @@ # error by unecessarily defining thread_local when it isn't even used on # Windows. list(APPEND LIBFUZZER_CFLAGS -D_HAS_EXCEPTIONS=0) + list(APPEND LIBFUZZER_NOLINK_CFLAGS -D_HAS_EXCEPTIONS=0) else() if(NOT HAS_THREAD_LOCAL) list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread) + list(APPEND LIBFUZZER_NOLINK_CFLAGS -Dthread_local=__thread) endif() endif() @@ -173,6 +181,22 @@ endforeach() endif() +add_compiler_rt_object_libraries(RTfuzzer_nolink + OS ${FUZZER_SUPPORTED_OS} + ARCHS ${FUZZER_SUPPORTED_ARCH} + SOURCES ${LIBFUZZER_SOURCES} + ADDITIONAL_HEADERS ${LIBFUZZER_HEADERS} + CFLAGS ${LIBFUZZER_NOLINK_CFLAGS} + DEPS ${LIBFUZZER_NOLINK_DEPS}) + +add_compiler_rt_runtime(clang_rt.fuzzer_no_main + SHARED + OS ${FUZZER_SUPPORTED_OS} + ARCHS ${FUZZER_SUPPORTED_ARCH} + OBJECT_LIBS RTfuzzer_nolink + CFLAGS ${LIBFUZZER_NOLINK_CFLAGS} + PARENT_TARGET fuzzer) + if(COMPILER_RT_INCLUDE_TESTS) add_subdirectory(tests) endif()