Reland "[Fuzzer] Parametrize add_custom_libcxx"
add_custom_libcxx uses the just built compiler and installs the built libc++, e.g. for testing, neither of which is desirable in case of Fuzzer where the libc++ should be built using the host compiler and it's only linked into the libFuzzer and should never be installed. This change introduces additional arguments to add_custom_libcxx to allow parametrizing its behavior. Differential Revision: https://reviews.llvm.org/D42330 llvm-svn: 323054
This commit is contained in:
parent
3c59aec591
commit
066e4bf888
|
@ -463,40 +463,51 @@ endmacro(add_compiler_rt_script src name)
|
|||
# Can be used to build sanitized versions of libc++ for running unit tests.
|
||||
# add_custom_libcxx(<name> <prefix>
|
||||
# DEPS <list of build deps>
|
||||
# CFLAGS <list of compile flags>)
|
||||
# CFLAGS <list of compile flags>
|
||||
# USE_TOOLCHAIN)
|
||||
macro(add_custom_libcxx name prefix)
|
||||
if(NOT COMPILER_RT_LIBCXX_PATH)
|
||||
message(FATAL_ERROR "libcxx not found!")
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
|
||||
cmake_parse_arguments(LIBCXX "USE_TOOLCHAIN" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
|
||||
foreach(flag ${LIBCXX_CFLAGS})
|
||||
set(flagstr "${flagstr} ${flag}")
|
||||
endforeach()
|
||||
set(LIBCXX_CFLAGS ${flagstr})
|
||||
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND LIBCXX_DEPS clang)
|
||||
if(LIBCXX_USE_TOOLCHAIN)
|
||||
set(compiler_args -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
|
||||
-DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
set(force_deps DEPENDS clang)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSROOT)
|
||||
set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
|
||||
endif()
|
||||
|
||||
ExternalProject_Add(${name}
|
||||
DEPENDS ${LIBCXX_DEPS}
|
||||
PREFIX ${prefix}
|
||||
SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
|
||||
CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM}
|
||||
-DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
|
||||
-DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER}
|
||||
CMAKE_ARGS -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
||||
${compiler_args}
|
||||
${sysroot_arg}
|
||||
-DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
|
||||
-DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||
-DLLVM_PATH=${LLVM_MAIN_SRC_DIR}
|
||||
-DLIBCXX_STANDALONE_BUILD=On
|
||||
${LIBCXX_CMAKE_ARGS}
|
||||
STEP_TARGETS configure build install
|
||||
LOG_BUILD 1
|
||||
LOG_CONFIGURE 1
|
||||
LOG_INSTALL 1
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||
|
||||
ExternalProject_Add_Step(${name} force-reconfigure
|
||||
DEPENDERS configure
|
||||
|
@ -508,7 +519,7 @@ macro(add_custom_libcxx name prefix)
|
|||
COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
|
||||
COMMENT "Clobberring ${name} build directory..."
|
||||
DEPENDERS configure
|
||||
DEPENDS ${LIBCXX_DEPS}
|
||||
${force_deps}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ CHECK_CXX_SOURCE_COMPILES("
|
|||
set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
||||
list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=__Fuzzer)
|
||||
list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer)
|
||||
endif()
|
||||
|
||||
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer LIBFUZZER_CFLAGS)
|
||||
|
@ -84,7 +84,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
|||
set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir")
|
||||
file(MAKE_DIRECTORY ${cxx_${arch}_merge_dir})
|
||||
add_custom_command(TARGET clang_rt.${name}-${arch} POST_BUILD
|
||||
COMMAND ${CMAKE_LINKER} --whole-archive "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" --no-whole-archive ${dir}/lib/libc++.a -r -o ${name}.o
|
||||
COMMAND ${CMAKE_LINKER} --whole-archive "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" --no-whole-archive ${dir}/src/libcxx_fuzzer_${arch}-build/lib/libc++.a -r -o ${name}.o
|
||||
COMMAND ${CMAKE_OBJCOPY} --localize-hidden ${name}.o
|
||||
COMMAND ${CMAKE_COMMAND} -E remove "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>"
|
||||
COMMAND ${CMAKE_AR} qcs "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" ${name}.o
|
||||
|
@ -97,15 +97,15 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
|||
set(LIBCXX_${arch}_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_fuzzer_${arch})
|
||||
add_custom_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_${arch}_PREFIX}
|
||||
CFLAGS ${TARGET_CFLAGS}
|
||||
-D_LIBCPP_ABI_VERSION=__Fuzzer
|
||||
-D_LIBCPP_ABI_VERSION=Fuzzer
|
||||
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=1
|
||||
-fvisibility=hidden
|
||||
CMAKE_ARGS -DLIBCXX_ENABLE_EXCEPTIONS=OFF
|
||||
-DLIBCXX_CXX_ABI=none)
|
||||
target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
|
||||
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch})
|
||||
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
|
||||
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch})
|
||||
target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${COMPILER_RT_LIBCXX_PATH}/include)
|
||||
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build)
|
||||
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${COMPILER_RT_LIBCXX_PATH}/include)
|
||||
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build)
|
||||
partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch})
|
||||
partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch})
|
||||
endforeach()
|
||||
|
|
|
@ -19,7 +19,7 @@ else()
|
|||
endif()
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
||||
list(APPEND LIBFUZZER_UNITTEST_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=__Fuzzer)
|
||||
list(APPEND LIBFUZZER_UNITTEST_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer)
|
||||
endif()
|
||||
|
||||
foreach(arch ${FUZZER_SUPPORTED_ARCH})
|
||||
|
@ -38,9 +38,9 @@ foreach(arch ${FUZZER_SUPPORTED_ARCH})
|
|||
FOLDER "Compiler-RT Runtime tests")
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
||||
set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch})
|
||||
set(LIBFUZZER_TEST_RUNTIME_CFLAGS -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
|
||||
set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}/lib/libc++.a)
|
||||
set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch}-build)
|
||||
set(LIBFUZZER_TEST_RUNTIME_CFLAGS -isystem ${COMPILER_RT_LIBCXX_PATH}/include)
|
||||
set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}/src/libcxx_fuzzer_${arch}-build/lib/libc++.a)
|
||||
endif()
|
||||
|
||||
set(FuzzerTestObjects)
|
||||
|
|
|
@ -106,7 +106,7 @@ macro(add_msan_tests_for_arch arch kind cflags)
|
|||
DEPS ${MSAN_INST_LOADABLE_OBJECTS})
|
||||
|
||||
set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
|
||||
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}
|
||||
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-install
|
||||
${MSAN_LOADABLE_SO})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND MSAN_TEST_DEPS msan)
|
||||
|
@ -128,7 +128,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_LIBCXX_PATH)
|
|||
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
|
||||
add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
|
||||
DEPS ${MSAN_RUNTIME_LIBRARIES}
|
||||
CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS})
|
||||
CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
|
||||
USE_TOOLCHAIN)
|
||||
set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)
|
||||
|
||||
add_msan_tests_for_arch(${arch} "" "")
|
||||
|
|
|
@ -212,8 +212,9 @@ if(COMPILER_RT_LIBCXX_PATH AND
|
|||
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch})
|
||||
add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX}
|
||||
DEPS ${TSAN_RUNTIME_LIBRARIES}
|
||||
CFLAGS ${TARGET_CFLAGS} -fsanitize=thread)
|
||||
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch})
|
||||
CFLAGS ${TARGET_CFLAGS} -fsanitize=thread
|
||||
USE_TOOLCHAIN)
|
||||
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-install)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps})
|
||||
|
|
Loading…
Reference in New Issue