From: patrick Date: Fri, 17 Dec 2021 12:26:52 +0000 (+0000) Subject: Import LLVM 13.0.0 release. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d89ec533011f513df1010f142a111086a0785f09;p=openbsd Import LLVM 13.0.0 release. --- diff --git a/gnu/llvm/compiler-rt/.clang-tidy b/gnu/llvm/compiler-rt/.clang-tidy new file mode 100644 index 00000000000..c7dba46ad74 --- /dev/null +++ b/gnu/llvm/compiler-rt/.clang-tidy @@ -0,0 +1,2 @@ +Checks: '-readability-identifier-naming,-llvm-header-guard' +InheritParentConfig: true diff --git a/gnu/llvm/compiler-rt/.gitignore b/gnu/llvm/compiler-rt/.gitignore new file mode 100644 index 00000000000..f7d4697ebc5 --- /dev/null +++ b/gnu/llvm/compiler-rt/.gitignore @@ -0,0 +1,6 @@ +*~ +darwin_fat +clang_darwin +multi_arch +*.sw? +*.pyc diff --git a/gnu/llvm/compiler-rt/CMakeLists.txt b/gnu/llvm/compiler-rt/CMakeLists.txt index fa62814b635..e12d1eb1ceb 100644 --- a/gnu/llvm/compiler-rt/CMakeLists.txt +++ b/gnu/llvm/compiler-rt/CMakeLists.txt @@ -3,11 +3,7 @@ # An important constraint of the build is that it only produces libraries # based on the ability of the host toolchain to target various platforms. -cmake_minimum_required(VERSION 3.4.3) - -if(POLICY CMP0075) - cmake_policy(SET CMP0075 NEW) -endif() +cmake_minimum_required(VERSION 3.13.4) # Check if compiler-rt is built as a standalone project. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) @@ -45,8 +41,12 @@ option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON) mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER) option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON) mark_as_advanced(COMPILER_RT_BUILD_PROFILE) +option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON) +mark_as_advanced(COMPILER_RT_BUILD_MEMPROF) option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF) mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT) +option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON) +mark_as_advanced(COMPILER_RT_BUILD_ORC) set(COMPILER_RT_ASAN_SHADOW_SCALE "" CACHE STRING "Override the shadow scale to be used in ASan runtime") @@ -67,8 +67,12 @@ if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "") -D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION}) endif() -set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOL - "Enable libc interceptors in HWASan (testing mode)") +if(FUCHSIA) + set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF) +else() + set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON) +endif() +set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)") set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL "Build for a bare-metal target.") @@ -81,38 +85,23 @@ if (COMPILER_RT_STANDALONE_BUILD) set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc") endif() - if(CMAKE_VERSION VERSION_LESS 3.12) - # Find Python interpreter. - include(FindPythonInterp) - if(NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR " - Unable to find Python interpreter required testing. Please install Python - or specify the PYTHON_EXECUTABLE CMake variable.") + find_package(Python3 COMPONENTS Interpreter) + if(NOT Python3_Interpreter_FOUND) + message(WARNING "Python3 not found, using python2 as a fallback") + find_package(Python2 COMPONENTS Interpreter REQUIRED) + if(Python2_VERSION VERSION_LESS 2.7) + message(SEND_ERROR "Python 2.7 or newer is required") endif() + # Treat python2 as python3 add_executable(Python3::Interpreter IMPORTED) set_target_properties(Python3::Interpreter PROPERTIES - IMPORTED_LOCATION ${PYTHON_EXECUTABLE}) - set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) - else() - find_package(Python3 COMPONENTS Interpreter) - if(NOT Python3_Interpreter_FOUND) - message(WARNING "Python3 not found, using python2 as a fallback") - find_package(Python2 COMPONENTS Interpreter REQUIRED) - if(Python2_VERSION VERSION_LESS 2.7) - message(SEND_ERROR "Python 2.7 or newer is required") - endif() - - # Treat python2 as python3 - add_executable(Python3::Interpreter IMPORTED) - set_target_properties(Python3::Interpreter PROPERTIES - IMPORTED_LOCATION ${Python2_EXECUTABLE}) - set(Python3_EXECUTABLE ${Python2_EXECUTABLE}) - endif() + IMPORTED_LOCATION ${Python2_EXECUTABLE}) + set(Python3_EXECUTABLE ${Python2_EXECUTABLE}) endif() # Ensure that fat libraries are built correctly on Darwin - if(CMAKE_HOST_APPLE AND APPLE) + if(APPLE) include(UseLibtool) endif() @@ -129,16 +118,16 @@ construct_compiler_rt_default_triple() if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$") if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm") set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf") + CHECK_SYMBOL_EXISTS (__thumb__ "" COMPILER_RT_ARM_THUMB) endif() endif() if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*") set(ANDROID 1) + string(REGEX MATCH "-target(=| +)[^ ]+android[a-z]*([0-9]+)" ANDROID_API_LEVEL "${CMAKE_C_FLAGS}") + set(ANDROID_API_LEVEL ${CMAKE_MATCH_2}) endif() pythonize_bool(ANDROID) -set(ANDROID_NDK_VERSION 18 - CACHE STRING "Set this to the Android NDK version that you are using") - set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) @@ -190,14 +179,18 @@ endif() option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON) -set(SANITIZE_CAN_USE_CXXABI OFF) +set(SANITIZER_CAN_USE_CXXABI OFF) if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI) set(SANITIZER_CAN_USE_CXXABI ON) endif() pythonize_bool(SANITIZER_CAN_USE_CXXABI) macro(handle_default_cxx_lib var) - if (${var} STREQUAL "default") + # Specifying -stdlib= in CMAKE_CXX_FLAGS overrides the defaults. + if (CMAKE_CXX_FLAGS MATCHES "-stdlib=([a-zA-Z+]*)") + set(${var}_LIBNAME "${CMAKE_MATCH_1}") + set(${var}_SYSTEM 1) + elseif (${var} STREQUAL "default") if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") set(${var}_LIBNAME "libc++") set(${var}_SYSTEM 1) @@ -285,7 +278,11 @@ if(NOT COMPILER_RT_HAS_FUNC_SYMBOL) add_definitions(-D__func__=__FUNCTION__) endif() -# Provide some common commmandline flags for Sanitizer runtimes. +# Provide some common commandline flags for Sanitizer runtimes. +if("${ANDROID_API_LEVEL}" GREATER_EQUAL 29) + list(APPEND SANITIZER_COMMON_CFLAGS -fno-emulated-tls) + string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " -fno-emulated-tls") +endif() if(NOT WIN32) append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS) endif() @@ -362,6 +359,17 @@ endif() append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS) +if(CMAKE_CXX_COMPILER_ID MATCHES Clang) + list(APPEND THREAD_SAFETY_FLAGS + "-Werror=thread-safety" + "-Werror=thread-safety-reference" + "-Werror=thread-safety-beta" + ) + list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS}) + string(REPLACE ";" " " thread_safety_flags_space_sep "${THREAD_SAFETY_FLAGS}") + string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${thread_safety_flags_space_sep}") +endif() + # If we're using MSVC, # always respect the optimization flags set by CMAKE_BUILD_TYPE instead. if (NOT MSVC) @@ -421,7 +429,6 @@ endif() append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS) -append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS) @@ -445,12 +452,39 @@ else() endif() append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS) - if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia") - list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) list(APPEND SANITIZER_COMMON_LINK_LIBS zircon) endif() +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia") + set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT ON) +else() + set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT OFF) +endif() +option(SANITIZER_NO_UNDEFINED_SYMBOLS "Report error on unresolved symbol references" ${SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT}) +if (SANITIZER_NO_UNDEFINED_SYMBOLS) + list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs) +endif() + +# TODO: COMPILER_RT_COMMON_CFLAGS and COMPILER_RT_COMMON_LINK_FLAGS are +# intended for use in non-sanitizer runtimes such as libFuzzer, profile or XRay, +# move these higher to include common flags, then derive SANITIZER_COMMON_CFLAGS +# and SANITIZER_COMMON_LINK_FLAGS from those and append sanitizer-specific flags. +set(COMPILER_RT_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS}) +set(COMPILER_RT_COMMON_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) + +# We don't use the C++ standard library, so avoid including it by mistake. +append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS) +append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS) + +# Remove -stdlib= which is unused when passing -nostdinc++... +string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}") +string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + +# ...we need it to build some runtimes and tests so readd it where appropriate. +list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag}) +list(APPEND COMPILER_RT_COMMON_LINK_FLAGS ${stdlib_flag}) + macro(append_libcxx_libs var) if (${var}_INTREE) if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) @@ -483,6 +517,54 @@ elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++") append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES) endif() +# TODO: There's a lot of duplication across lib/*/tests/CMakeLists.txt files, +# move some of the common flags to COMPILER_RT_UNITTEST_CFLAGS. + +# Unittests need access to C++ standard library. +string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${stdlib_flag}") + +# When cross-compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help in compilation +# and linking of unittests. +string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") +set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) + +# Unittests support. +set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) +set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc) +set(COMPILER_RT_GTEST_CFLAGS + -DGTEST_NO_LLVM_SUPPORT=1 + -DGTEST_HAS_RTTI=0 + -I${COMPILER_RT_GTEST_PATH}/include + -I${COMPILER_RT_GTEST_PATH} +) +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + # FreeBSD has its pthread functions marked with thread safety annotations, but + # googletest is not compatible with such annotations. Disable the thread + # safety warnings-as-errors until googletest has been fixed. + list(APPEND NO_THREAD_SAFETY_FLAGS ${THREAD_SAFETY_FLAGS}) + list(TRANSFORM NO_THREAD_SAFETY_FLAGS REPLACE "error=" "no-") + list(APPEND COMPILER_RT_GTEST_CFLAGS ${NO_THREAD_SAFETY_FLAGS}) +endif() + +# Mocking support. +set(COMPILER_RT_GMOCK_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock) +set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc) +set(COMPILER_RT_GMOCK_CFLAGS + -DGTEST_NO_LLVM_SUPPORT=1 + -DGTEST_HAS_RTTI=0 + -I${COMPILER_RT_GMOCK_PATH}/include + -I${COMPILER_RT_GMOCK_PATH} +) + +append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS) +append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS) +append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS) + +if(MSVC) + # gtest use a lot of stuff marked as deprecated on Windows. + list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) +endif() + # Warnings to turn off for all libraries, not just sanitizers. append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS) @@ -497,6 +579,15 @@ if (CMAKE_LINKER MATCHES "link.exe$") set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221") endif() +if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + set(CMAKE_C_ARCHIVE_CREATE " -X32_64 qc ") + set(CMAKE_CXX_ARCHIVE_CREATE " -X32_64 qc ") + set(CMAKE_C_ARCHIVE_APPEND " -X32_64 q ") + set(CMAKE_CXX_ARCHIVE_APPEND " -X32_64 q ") + set(CMAKE_C_ARCHIVE_FINISH " -X32_64 ") + set(CMAKE_CXX_ARCHIVE_FINISH " -X32_64 ") +endif() + add_subdirectory(include) option(COMPILER_RT_USE_LIBCXX @@ -537,14 +628,26 @@ else() set(COMPILER_RT_HAS_LLD TRUE) endif() endif() + +if(ANDROID) + set(COMPILER_RT_HAS_LLD TRUE) + set(COMPILER_RT_TEST_USE_LLD TRUE) + append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS) + append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld COMPILER_RT_UNITTEST_LINK_FLAGS) + if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) + set(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT FALSE) + endif() +endif() pythonize_bool(COMPILER_RT_HAS_LLD) +pythonize_bool(COMPILER_RT_TEST_USE_LLD) add_subdirectory(lib) if(COMPILER_RT_INCLUDE_TESTS) add_subdirectory(unittests) add_subdirectory(test) - if (COMPILER_RT_STANDALONE_BUILD) + # Don't build llvm-lit for runtimes-build, it will clean up map_config. + if (COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD) # If we have a valid source tree, generate llvm-lit into the bin directory. # The user can still choose to have the check targets *use* a different lit # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless. diff --git a/gnu/llvm/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/gnu/llvm/compiler-rt/cmake/Modules/AddCompilerRT.cmake index dab55707338..bc69ec95c41 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/gnu/llvm/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -109,11 +109,11 @@ endfunction() function(add_asm_sources output) set(${output} ${ARGN} PARENT_SCOPE) - # Xcode will try to compile asm files as C ('clang -x c'), and that will fail. - if (${CMAKE_GENERATOR} STREQUAL "Xcode") - enable_language(ASM) - else() - # Pass ASM file directly to the C++ compiler. + # CMake doesn't pass the correct architecture for Apple prior to CMake 3.19. https://gitlab.kitware.com/cmake/cmake/-/issues/20771 + # MinGW didn't work correctly with assembly prior to CMake 3.17. https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287 and https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09 + # Workaround these two issues by compiling as C. + # Same workaround used in libunwind. Also update there if changed here. + if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR (MINGW AND CMAKE_VERSION VERSION_LESS 3.17)) set_source_files_properties(${ARGN} PROPERTIES LANGUAGE C) endif() endfunction() @@ -124,6 +124,21 @@ macro(set_output_name output name arch) else() if(ANDROID AND ${arch} STREQUAL "i386") set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}") + elseif("${arch}" MATCHES "^arm") + if(COMPILER_RT_DEFAULT_TARGET_ONLY) + set(triple "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}") + else() + set(triple "${TARGET_TRIPLE}") + endif() + # When using arch-suffixed runtime library names, clang only looks for + # libraries named "arm" or "armhf", see getArchNameForCompilerRTLib in + # clang. Therefore, try to inspect both the arch name and the triple + # if it seems like we're building an armhf target. + if ("${arch}" MATCHES "hf$" OR "${triple}" MATCHES "hf$") + set(${output} "${name}-armhf${COMPILER_RT_OS_SUFFIX}") + else() + set(${output} "${name}-arm${COMPILER_RT_OS_SUFFIX}") + endif() else() set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}") endif() @@ -133,26 +148,28 @@ endmacro() # Adds static or shared runtime for a list of architectures and operating # systems and puts it in the proper directory in the build and install trees. # add_compiler_rt_runtime( -# {OBJECT|STATIC|SHARED} +# {OBJECT|STATIC|SHARED|MODULE} # ARCHS # OS # SOURCES # CFLAGS # LINK_FLAGS # DEFS +# DEPS # LINK_LIBS (only for shared library) # OBJECT_LIBS # PARENT_TARGET # ADDITIONAL_HEADERS
) function(add_compiler_rt_runtime name type) - if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$") - message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED") + if(NOT type MATCHES "^(OBJECT|STATIC|SHARED|MODULE)$") + message(FATAL_ERROR + "type argument must be OBJECT, STATIC, SHARED or MODULE") return() endif() cmake_parse_arguments(LIB "" "PARENT_TARGET" - "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS" + "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS" ${ARGN}) set(libnames) # Until we support this some other way, build compiler-rt runtime without LTO @@ -329,6 +346,9 @@ function(add_compiler_rt_runtime name type) RUNTIME DESTINATION ${install_dir_${libname}} ${COMPONENT_OPTION}) endif() + if(LIB_DEPS) + add_dependencies(${libname} ${LIB_DEPS}) + endif() set_target_properties(${libname} PROPERTIES OUTPUT_NAME ${output_name_${libname}}) set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") @@ -351,7 +371,7 @@ function(add_compiler_rt_runtime name type) add_custom_command(TARGET ${libname} POST_BUILD COMMAND codesign --sign - $ - WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} + WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} ) endif() endif() @@ -376,39 +396,6 @@ function(add_compiler_rt_runtime name type) endif() endfunction() -# when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help -# in compilation and linking of unittests. -string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") -set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) - -# Unittests support. -set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) -set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc) -set(COMPILER_RT_GTEST_CFLAGS - -DGTEST_NO_LLVM_SUPPORT=1 - -DGTEST_HAS_RTTI=0 - -I${COMPILER_RT_GTEST_PATH}/include - -I${COMPILER_RT_GTEST_PATH} -) - -# Mocking support. -set(COMPILER_RT_GMOCK_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock) -set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc) -set(COMPILER_RT_GMOCK_CFLAGS - -DGTEST_NO_LLVM_SUPPORT=1 - -DGTEST_HAS_RTTI=0 - -I${COMPILER_RT_GMOCK_PATH}/include - -I${COMPILER_RT_GMOCK_PATH} -) - -append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS) -append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS) - -if(MSVC) - # gtest use a lot of stuff marked as deprecated on Windows. - list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations) -endif() - # Compile and register compiler-rt tests. # generate_compiler_rt_tests( # @@ -524,7 +511,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) add_custom_target(${target_name} DEPENDS ${dst_file}) # Install in Clang resource directory. install(FILES ${file_name} - DESTINATION ${COMPILER_RT_INSTALL_PATH}/share + DESTINATION ${COMPILER_RT_INSTALL_DATA_DIR} COMPONENT ${component}) add_dependencies(${component} ${target_name}) @@ -541,7 +528,7 @@ macro(add_compiler_rt_script name) add_custom_target(${name} DEPENDS ${dst}) install(FILES ${dst} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) + DESTINATION ${COMPILER_RT_INSTALL_BINARY_DIR}) endmacro(add_compiler_rt_script src name) # Builds custom version of libc++ and installs it in . @@ -563,7 +550,7 @@ macro(add_custom_libcxx name prefix) 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 AND NOT RUNTIMES_BUILD) + if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD) set(toolchain_deps $) set(force_deps DEPENDS $) endif() @@ -612,6 +599,10 @@ macro(add_custom_libcxx name prefix) CMAKE_OBJDUMP CMAKE_STRIP CMAKE_SYSROOT + LIBCXX_HAS_MUSL_LIBC + PYTHON_EXECUTABLE + Python3_EXECUTABLE + Python2_EXECUTABLE CMAKE_SYSTEM_NAME) foreach(variable ${PASSTHROUGH_VARIABLES}) get_property(is_value_set CACHE ${variable} PROPERTY VALUE SET) diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake new file mode 100644 index 00000000000..3b61430f471 --- /dev/null +++ b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTAIXUtils.cmake @@ -0,0 +1,80 @@ +include(CMakeParseArguments) +include(CompilerRTUtils) + +function(get_aix_libatomic_default_link_flags link_flags export_list) + set(linkopts + "-Wl,-H512 -Wl,-D0 \ + -Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok \ + -Wl,-bnoentry -Wl,-bexport:${export_list} \ + -Wl,-bmodtype:SRE -Wl,-lc") + # Add `-Wl,-G`. Quoted from release notes of cmake-3.16.0 + # > On AIX, runtime linking is no longer enabled by default. + # See https://cmake.org/cmake/help/latest/release/3.16.html + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") + set(linkopts "-Wl,-G" "${linkopts}") + endif() + set(${link_flags} ${linkopts} PARENT_SCOPE) +endfunction() + +function(get_aix_libatomic_type type) + if(${CMAKE_VERSION} VERSION_LESS "3.16.0") + set(${type} SHARED PARENT_SCOPE) + else() + set(${type} MODULE PARENT_SCOPE) + endif() +endfunction() + +macro(archive_aix_libatomic name) + cmake_parse_arguments(LIB + "" + "" + "ARCHS;PARENT_TARGET" + ${ARGN}) + set(shared_libraries_to_archive "") + foreach (arch ${LIB_ARCHS}) + if(CAN_TARGET_${arch}) + set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/libatomic-${arch}.dir") + # FIXME: Target name should be kept consistent with definition + # in AddCompilerRT.cmake added by + # add_compiler_rt_runtime( SHARED ...) + set(target ${name}-dynamic-${arch}) + if(TARGET ${target}) + file(MAKE_DIRECTORY ${output_dir}) + add_custom_command(OUTPUT "${output_dir}/libatomic.so.1" + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E + copy "$" + "${output_dir}/libatomic.so.1" + # If built with MODULE, F_LOADONLY is set. + # We have to remove this flag at POST_BUILD. + COMMAND ${CMAKE_STRIP} -X32_64 -E + "${output_dir}/libatomic.so.1" + DEPENDS ${target}) + list(APPEND shared_libraries_to_archive "${output_dir}/libatomic.so.1") + endif() + endif() + endforeach() + if(shared_libraries_to_archive) + set(output_dir "") + set(install_dir "") + # If LLVM defines top level library directory, we want to deliver + # libatomic.a at top level. See `llvm/cmake/modules/AddLLVM.cmake' + # setting _install_rpath on AIX for reference. + if(LLVM_LIBRARY_OUTPUT_INTDIR AND CMAKE_INSTALL_PREFIX) + set(output_dir "${LLVM_LIBRARY_OUTPUT_INTDIR}") + set(install_dir "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") + else() + get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir) + get_compiler_rt_install_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} install_dir) + endif() + add_custom_command(OUTPUT "${output_dir}/libatomic.a" + COMMAND ${CMAKE_AR} -X32_64 r "${output_dir}/libatomic.a" + ${shared_libraries_to_archive} + DEPENDS ${shared_libraries_to_archive}) + install(FILES "${output_dir}/libatomic.a" + DESTINATION ${install_dir}) + add_custom_target(aix-libatomic + DEPENDS "${output_dir}/libatomic.a") + endif() + add_dependencies(${LIB_PARENT_TARGET} aix-libatomic) +endmacro() diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTCompile.cmake b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTCompile.cmake index 07b589beb2d..1b42f24c08d 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTCompile.cmake +++ b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTCompile.cmake @@ -70,29 +70,36 @@ function(clang_compile object_file source) if (TARGET CompilerRTUnitTestCheckCxx) list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx) endif() - string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath}) - string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath}) - if(is_cxx) - string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}") - else() - string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}") - endif() + if(COMPILER_RT_STANDALONE_BUILD) + # Only add global flags in standalone build. + string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath}) + if(is_cxx) + string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}") + else() + string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}") + endif() - if (MSVC) - translate_msvc_cflags(global_flags "${global_flags}") - endif() + if (MSVC) + translate_msvc_cflags(global_flags "${global_flags}") + endif() - if (APPLE) - set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags}) + if (APPLE) + set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags}) + endif() + + # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options + # which are not supported by Clang. + list(APPEND global_flags -Wno-unknown-warning-option) + set(compile_flags ${global_flags} ${SOURCE_CFLAGS}) + else() + set(compile_flags ${SOURCE_CFLAGS}) endif() + + string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath}) if (is_objc) - list(APPEND global_flags -ObjC) + list(APPEND compile_flags "-ObjC") endif() - # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options - # which are not supported by Clang. - list(APPEND global_flags -Wno-unknown-warning-option) - set(compile_flags ${global_flags} ${SOURCE_CFLAGS}) add_custom_command( OUTPUT ${object_file} COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c @@ -136,7 +143,7 @@ macro(clang_compiler_add_cxx_check) COMMAND bash -c "${CMD}" COMMENT "Checking that just-built clang can find C++ headers..." VERBATIM) - if (NOT COMPILER_RT_STANDALONE_BUILD AND NOT RUNTIMES_BUILD) + if (NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD) ADD_DEPENDENCIES(CompilerRTUnitTestCheckCxx clang) endif() endif() diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake index be8d7e733c7..276fcbb9c0e 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake +++ b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake @@ -289,6 +289,15 @@ macro(darwin_add_builtin_library name suffix) endforeach(cflag) endif() + if ("${LIB_OS}" MATCHES ".*sim$") + # Pass an explicit -simulator environment to the -target option to ensure + # that we don't rely on the architecture to infer whether we're building + # for the simulator. + string(REGEX REPLACE "sim" "" base_os "${LIB_OS}") + list(APPEND builtin_cflags + -target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator") + endif() + set_target_compile_flags(${libname} ${sysroot_flag} ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG} @@ -386,12 +395,28 @@ macro(darwin_add_builtin_libraries) set(CMAKE_CXX_FLAGS "") set(CMAKE_ASM_FLAGS "") - set(PROFILE_SOURCES ../profile/InstrProfiling - ../profile/InstrProfilingBuffer - ../profile/InstrProfilingPlatformDarwin - ../profile/InstrProfilingWriter) + append_string_if(COMPILER_RT_HAS_ASM_LSE " -DHAS_ASM_LSE" CFLAGS) + + set(PROFILE_SOURCES ../profile/InstrProfiling.c + ../profile/InstrProfilingBuffer.c + ../profile/InstrProfilingPlatformDarwin.c + ../profile/InstrProfilingWriter.c + ../profile/InstrProfilingInternal.c + ../profile/InstrProfilingVersionVar.c) foreach (os ${ARGN}) list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH) + + if((arm64 IN_LIST DARWIN_BUILTIN_ARCHS OR arm64e IN_LIST DARWIN_BUILTIN_ARCHS) AND NOT TARGET lse_builtin_symlinks) + add_custom_target( + lse_builtin_symlinks + BYPRODUCTS ${lse_builtins} + ${arm64_lse_commands} + ) + + set(deps_arm64 lse_builtin_symlinks) + set(deps_arm64e lse_builtin_symlinks) + endif() + foreach (arch ${DARWIN_BUILTIN_ARCHS}) darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS OS ${os} @@ -406,6 +431,7 @@ macro(darwin_add_builtin_libraries) darwin_add_builtin_library(clang_rt builtins OS ${os} ARCH ${arch} + DEPS ${deps_${arch}} SOURCES ${filtered_sources} CFLAGS ${CFLAGS} -arch ${arch} PARENT_TARGET builtins) @@ -430,6 +456,7 @@ macro(darwin_add_builtin_libraries) darwin_add_builtin_library(clang_rt cc_kext OS ${os} ARCH ${arch} + DEPS ${deps_${arch}} SOURCES ${filtered_sources} ${PROFILE_SOURCES} CFLAGS ${CFLAGS} -arch ${arch} -mkernel DEFS KERNEL_USE @@ -444,21 +471,18 @@ macro(darwin_add_builtin_libraries) PARENT_TARGET builtins LIPO_FLAGS ${${os}_cc_kext_lipo_flags} DEPENDS ${${os}_cc_kext_libs} - OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR} - INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR} + INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR}) endif() endforeach() - # We put the x86 sim slices into the archives for their base OS foreach (os ${ARGN}) - if(NOT ${os} MATCHES ".*sim$") - darwin_lipo_libs(clang_rt.${os} - PARENT_TARGET builtins - LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags} - DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs} - OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR} - INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - endif() + darwin_lipo_libs(clang_rt.${os} + PARENT_TARGET builtins + LIPO_FLAGS ${${os}_builtins_lipo_flags} + DEPENDS ${${os}_builtins_libs} + OUTPUT_DIR ${COMPILER_RT_OUTPUT_LIBRARY_DIR} + INSTALL_DIR ${COMPILER_RT_INSTALL_LIBRARY_DIR}) endforeach() darwin_add_embedded_builtin_libraries() endmacro() @@ -496,9 +520,9 @@ macro(darwin_add_embedded_builtin_libraries) set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64) set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR - ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/macho_embedded) set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR - ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) + ${COMPILER_RT_INSTALL_LIBRARY_DIR}/macho_embedded) set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") set(CFLAGS_i386 "-march=pentium") diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake new file mode 100644 index 00000000000..1080a4d0a79 --- /dev/null +++ b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake @@ -0,0 +1,75 @@ +# This macro mocks enough of the changes `LLVMConfig.cmake` makes so that +# compiler-rt can successfully configure itself when a LLVM toolchain is +# available but the corresponding CMake build files are not. +# +# The motivation for this is to be able to generate the compiler-rt +# lit tests suites and run them against an arbitrary LLVM toolchain +# which doesn't ship the LLVM CMake build files. +macro(compiler_rt_mock_llvm_cmake_config) + message(STATUS "Attempting to mock the changes made by LLVMConfig.cmake") + compiler_rt_mock_llvm_cmake_config_set_cmake_path() + compiler_rt_mock_llvm_cmake_config_set_target_triple() + compiler_rt_mock_llvm_cmake_config_include_cmake_files() +endmacro() + +macro(compiler_rt_mock_llvm_cmake_config_set_cmake_path) + # Point `LLVM_CMAKE_PATH` at the source tree in the monorepo. + set(LLVM_CMAKE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") + if (NOT EXISTS "${LLVM_CMAKE_PATH}") + message(FATAL_ERROR "LLVM_CMAKE_PATH (${LLVM_CMAKE_PATH}) does not exist") + endif() + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + message(STATUS "LLVM_CMAKE_PATH: \"${LLVM_CMAKE_PATH}\"") +endmacro() + +function(compiler_rt_mock_llvm_cmake_config_set_target_triple) + # Various bits of compiler-rt depend on the `TARGET_TRIPLE`variable being + # defined. This function tries to set a sensible value for the variable. + # This is a function rather than a macro to avoid polluting the variable + # namespace. + set(COMPILER_OUTPUT "") + + # If the user provides `COMPILER_RT_DEFAULT_TARGET_ONLY` and `CMAKE_C_COMPILER_TARGET` + # (see `construct_compiler_rt_default_triple`) then prefer that to examining the + # compiler. + if (COMPILER_RT_DEFAULT_TARGET_ONLY) + if (NOT "${CMAKE_C_COMPILER_TARGET}" STREQUAL "") + message(STATUS + "Using CMAKE_C_COMPILER_TARGET (${CMAKE_C_COMPILER_TARGET}) as TARGET_TRIPLE") + endif() + set(COMPILER_OUTPUT "${CMAKE_C_COMPILER_TARGET}") + endif() + + # Try asking the compiler for its default target triple. + set(HAD_ERROR FALSE) + if ("${COMPILER_OUTPUT}" STREQUAL "") + if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang|GNU") + # Note: Clang also supports `-print-target-triple` but gcc doesn't + # support this flag. + execute_process( + COMMAND "${CMAKE_C_COMPILER}" -dumpmachine + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE COMPILER_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + message(FATAL_ERROR + "Fetching target triple from compiler \"${CMAKE_C_COMPILER_ID}\" " + "is not implemented.") + endif() + endif() + + if (HAD_ERROR) + message(FATAL_ERROR "Fetching target triple from compiler failed") + endif() + set(TARGET_TRIPLE "${COMPILER_OUTPUT}") + message(STATUS "TARGET_TRIPLE: \"${TARGET_TRIPLE}\"") + if ("${TARGET_TRIPLE}" STREQUAL "") + message(FATAL_ERROR "TARGET_TRIPLE cannot be empty") + endif() + set(TARGET_TRIPLE "${TARGET_TRIPLE}" PARENT_SCOPE) +endfunction() + +macro(compiler_rt_mock_llvm_cmake_config_include_cmake_files) + # Some compiler-rt CMake code needs to call code in this file. + include("${LLVM_CMAKE_PATH}/AddLLVM.cmake") +endmacro() diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 99b9f0e4af4..5543e3c6afc 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/gnu/llvm/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -158,6 +158,7 @@ macro(detect_target_arch) check_symbol_exists(__i386__ "" __I386) check_symbol_exists(__mips__ "" __MIPS) check_symbol_exists(__mips64__ "" __MIPS64) + check_symbol_exists(__powerpc__ "" __PPC) check_symbol_exists(__powerpc64__ "" __PPC64) check_symbol_exists(__powerpc64le__ "" __PPC64LE) check_symbol_exists(__riscv "" __RISCV) @@ -172,17 +173,25 @@ macro(detect_target_arch) elseif(__AARCH64) add_default_target_arch(aarch64) elseif(__X86_64) - add_default_target_arch(x86_64) + if(CMAKE_SIZEOF_VOID_P EQUAL "4") + add_default_target_arch(x32) + elseif(CMAKE_SIZEOF_VOID_P EQUAL "8") + add_default_target_arch(x86_64) + else() + message(FATAL_ERROR "Unsupported pointer size for X86_64") + endif() elseif(__I386) add_default_target_arch(i386) elseif(__MIPS64) # must be checked before __MIPS add_default_target_arch(mips64) elseif(__MIPS) add_default_target_arch(mips) - elseif(__PPC64) + elseif(__PPC64) # must be checked before __PPC add_default_target_arch(powerpc64) elseif(__PPC64LE) add_default_target_arch(powerpc64le) + elseif(__PPC) + add_default_target_arch(powerpc) elseif(__RISCV) if(CMAKE_SIZEOF_VOID_P EQUAL "4") add_default_target_arch(riscv32) @@ -206,6 +215,57 @@ macro(detect_target_arch) endif() endmacro() +function(get_compiler_rt_root_source_dir ROOT_DIR_VAR) + # Compute the path to the root of the Compiler-RT source tree + # regardless of how the project was configured. + # + # This function is useful because using `${CMAKE_SOURCE_DIR}` + # is error prone due to the numerous ways Compiler-RT can be + # configured. + # + # `ROOT_DIR_VAR` - the name of the variable to write the result to. + # + # TODO(dliew): When CMake min version is 3.17 or newer use + # `CMAKE_CURRENT_FUNCTION_LIST_DIR` instead. + if ("${ROOT_DIR_VAR}" STREQUAL "") + message(FATAL_ERROR "ROOT_DIR_VAR cannot be empty") + endif() + + # Compiler-rt supports different source root paths. + # Handle each case here. + set(PATH_TO_COMPILER_RT_SOURCE_ROOT "") + if (DEFINED CompilerRTBuiltins_SOURCE_DIR) + # Compiler-RT Builtins standalone build. + # `llvm-project/compiler-rt/lib/builtins` + set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRTBuiltins_SOURCE_DIR}/../../") + elseif(DEFINED CompilerRT_SOURCE_DIR) + # Compiler-RT standalone build. + # `llvm-project/compiler-rt` + set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRT_SOURCE_DIR}") + elseif (EXISTS "${CMAKE_SOURCE_DIR}/../compiler-rt") + # In tree build with LLVM as the root project. + # See `llvm-project/projects/`. + # Assumes monorepo layout. + set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/../compiler-rt") + else() + message(FATAL_ERROR "Unhandled Compiler-RT source root configuration.") + endif() + + get_filename_component(ROOT_DIR "${PATH_TO_COMPILER_RT_SOURCE_ROOT}" ABSOLUTE) + if (NOT EXISTS "${ROOT_DIR}") + message(FATAL_ERROR "Path \"${ROOT_DIR}\" doesn't exist") + endif() + + # Sanity check: Make sure we can locate the current source file via the + # computed path. + set(PATH_TO_CURRENT_FILE "${ROOT_DIR}/cmake/Modules/CompilerRTUtils.cmake") + if (NOT EXISTS "${PATH_TO_CURRENT_FILE}") + message(FATAL_ERROR "Could not find \"${PATH_TO_CURRENT_FILE}\"") + endif() + + set("${ROOT_DIR_VAR}" "${ROOT_DIR}" PARENT_SCOPE) +endfunction() + macro(load_llvm_config) if (NOT LLVM_CONFIG_PATH) find_program(LLVM_CONFIG_PATH "llvm-config" @@ -216,6 +276,20 @@ macro(load_llvm_config) "Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config.") endif() endif() + + # Compute path to LLVM sources assuming the monorepo layout. + # We don't set `LLVM_MAIN_SRC_DIR` directly to avoid overriding a user provided + # CMake cache value. + get_compiler_rt_root_source_dir(COMPILER_RT_ROOT_SRC_PATH) + get_filename_component(LLVM_MAIN_SRC_DIR_DEFAULT "${COMPILER_RT_ROOT_SRC_PATH}/../llvm" ABSOLUTE) + if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_DEFAULT}") + # TODO(dliew): Remove this legacy fallback path. + message(WARNING + "LLVM source tree not found at \"${LLVM_MAIN_SRC_DIR_DEFAULT}\". " + "You are not using the monorepo layout. This configuration is DEPRECATED.") + endif() + + set(FOUND_LLVM_CMAKE_PATH FALSE) if (LLVM_CONFIG_PATH) execute_process( COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir" @@ -233,10 +307,20 @@ macro(load_llvm_config) set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree") set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib") - set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin") set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers") + if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_DEFAULT}") + # TODO(dliew): Remove this legacy fallback path. + message(WARNING + "Consulting llvm-config for the LLVM source path " + "as a fallback. This behavior will be removed in the future.") + # We don't set `LLVM_MAIN_SRC_DIR` directly to avoid overriding a user + # provided CMake cache value. + set(LLVM_MAIN_SRC_DIR_DEFAULT "${MAIN_SRC_DIR}") + message(STATUS "Using LLVM source path (${LLVM_MAIN_SRC_DIR_DEFAULT}) from llvm-config") + endif() + # Detect if we have the LLVMXRay and TestingSupport library installed and # available from llvm-config. execute_process( @@ -295,13 +379,44 @@ macro(load_llvm_config) set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") endif() - list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") - # Get some LLVM variables from LLVMConfig. - include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + set(LLVM_CMAKE_INCLUDE_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + if (EXISTS "${LLVM_CMAKE_INCLUDE_FILE}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_INCLUDE_FILE}") + set(FOUND_LLVM_CMAKE_PATH TRUE) + else() + set(FOUND_LLVM_CMAKE_PATH FALSE) + message(WARNING "LLVM CMake path (${LLVM_CMAKE_INCLUDE_FILE}) reported by llvm-config does not exist") + endif() + unset(LLVM_CMAKE_INCLUDE_FILE) set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) endif() + + # Finally set the cache variable now that `llvm-config` has also had a chance + # to set `LLVM_MAIN_SRC_DIR_DEFAULT`. + set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree") + message(STATUS "LLVM_MAIN_SRC_DIR: \"${LLVM_MAIN_SRC_DIR}\"") + if (NOT EXISTS "${LLVM_MAIN_SRC_DIR}") + # TODO(dliew): Make this a hard error + message(WARNING "LLVM_MAIN_SRC_DIR (${LLVM_MAIN_SRC_DIR}) does not exist. " + "You can override the inferred path by adding " + "`-DLLVM_MAIN_SRC_DIR=` to your CMake invocation " + "where `` is the path to the `llvm` directory in " + "the `llvm-project` repo. " + "This will be treated as error in the future.") + endif() + + if (NOT FOUND_LLVM_CMAKE_PATH) + # This configuration tries to configure without the prescence of `LLVMConfig.cmake`. It is + # intended for testing purposes (generating the lit test suites) and will likely not support + # a build of the runtimes in compiler-rt. + include(CompilerRTMockLLVMCMakeConfig) + compiler_rt_mock_llvm_cmake_config() + endif() + endmacro() macro(construct_compiler_rt_default_triple) @@ -323,6 +438,14 @@ macro(construct_compiler_rt_default_triple) string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH) + + # Map various forms of the architecture names to the canonical forms + # (as they are used by clang, see getArchNameForCompilerRTLib). + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "^i.86$") + # Android uses i686, but that's remapped at a later stage. + set(COMPILER_RT_DEFAULT_TARGET_ARCH "i386") + endif() + # Determine if test target triple is specified explicitly, and doesn't match the # default. if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) @@ -375,18 +498,18 @@ endfunction() function(get_compiler_rt_install_dir arch install_dir) if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) get_compiler_rt_target(${arch} target) - set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE) + set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE) else() - set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR} PARENT_SCOPE) endif() endfunction() function(get_compiler_rt_output_dir arch output_dir) if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) get_compiler_rt_target(${arch} target) - set(${output_dir} ${COMPILER_RT_OUTPUT_DIR}/lib/${target} PARENT_SCOPE) + set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE) else() - set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE) + set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR} PARENT_SCOPE) endif() endfunction() diff --git a/gnu/llvm/compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt b/gnu/llvm/compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt index e61c222587e..6c6680023c7 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt +++ b/gnu/llvm/compiler-rt/cmake/Modules/CustomLibcxx/CMakeLists.txt @@ -1,8 +1,12 @@ -cmake_minimum_required(VERSION 3.4.3) +# TODO(phosek): We should use the runtimes build instead configured with +# LLVM_ENABLE_RUNTIMES=libcxxabi;libcxx to avoid duplication of logic. + +cmake_minimum_required(VERSION 3.13.4) project(custom-libcxx C CXX) +find_package(Python3 REQUIRED COMPONENTS Interpreter) + # Build static libcxxabi. -set(LIBCXXABI_STANDALONE_BUILD 1) set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "") set(LIBCXXABI_ENABLE_EXCEPTIONS ON CACHE BOOL "") set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE STRING "") @@ -11,7 +15,6 @@ set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "") add_subdirectory(${COMPILER_RT_LIBCXXABI_PATH} ${CMAKE_CURRENT_BINARY_DIR}/cxxabi) # Build static libcxx without exceptions. -set(LIBCXX_STANDALONE_BUILD 1) set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "") set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "") set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "") diff --git a/gnu/llvm/compiler-rt/cmake/Modules/UseLibtool.cmake b/gnu/llvm/compiler-rt/cmake/Modules/UseLibtool.cmake index 38d197d4846..130810c970d 100644 --- a/gnu/llvm/compiler-rt/cmake/Modules/UseLibtool.cmake +++ b/gnu/llvm/compiler-rt/cmake/Modules/UseLibtool.cmake @@ -34,6 +34,14 @@ if(CMAKE_LIBTOOL) set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o ") endforeach() + + # By default, CMake invokes ranlib on a static library after installing it. + # libtool will have produced the table of contents for us already, and ranlib + # does not understanding universal binaries, so skip this step. It's important + # to set it to empty instead of unsetting it to shadow the cache variable, and + # we don't want to unset the cache variable to not affect anything outside + # this scope. + set(CMAKE_RANLIB "") endif() # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands diff --git a/gnu/llvm/compiler-rt/cmake/base-config-ix.cmake b/gnu/llvm/compiler-rt/cmake/base-config-ix.cmake index 964dd598f10..c11342e6881 100644 --- a/gnu/llvm/compiler-rt/cmake/base-config-ix.cmake +++ b/gnu/llvm/compiler-rt/cmake/base-config-ix.cmake @@ -5,7 +5,6 @@ include(CheckIncludeFile) include(CheckCXXSourceCompiles) -include(TestBigEndian) check_include_file(unwind.h HAVE_UNWIND_H) @@ -69,8 +68,8 @@ else() "Path where built compiler-rt libraries should be stored.") set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH "Path where built compiler-rt executables should be stored.") - set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH - "Path where built compiler-rt libraries should be installed.") + set(COMPILER_RT_INSTALL_PATH "" CACHE PATH + "Prefix for directories where built compiler-rt artifacts should be installed.") option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) # Use a host compiler to compile/link tests. @@ -86,20 +85,45 @@ else() set(COMPILER_RT_TEST_COMPILER_ID GNU) endif() +function(extend_install_path joined_path current_segment) + if("${current_segment}" STREQUAL "") + set(temp_path "${COMPILER_RT_INSTALL_PATH}") + elseif("${COMPILER_RT_INSTALL_PATH}" STREQUAL "") + set(temp_path "${current_segment}") + elseif(IS_ABSOLUTE "${current_segment}") + message(WARNING "Since \"${current_segment}\" is absolute, it overrides COMPILER_RT_INSTALL_PATH: \"${COMPILER_RT_INSTALL_PATH}\".") + set(temp_path "${current_segment}") + else() + set(temp_path "${COMPILER_RT_INSTALL_PATH}/${current_segment}") + endif() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() + if(NOT DEFINED COMPILER_RT_OS_DIR) string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) endif() if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(COMPILER_RT_LIBRARY_OUTPUT_DIR - ${COMPILER_RT_OUTPUT_DIR}) - set(COMPILER_RT_LIBRARY_INSTALL_DIR - ${COMPILER_RT_INSTALL_PATH}) -else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) - set(COMPILER_RT_LIBRARY_OUTPUT_DIR + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) + extend_install_path(default_install_path lib) + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") +else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) - set(COMPILER_RT_LIBRARY_INSTALL_DIR - ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) + extend_install_path(default_install_path "lib/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") endif() +extend_install_path(default_install_path bin) +set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt executables should be installed.") +extend_install_path(default_install_path include) +set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH + "Path where compiler-rt headers should be installed.") +extend_install_path(default_install_path share) +set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH + "Path where compiler-rt data files should be installed.") if(APPLE) # On Darwin if /usr/include/c++ doesn't exist, the user probably has Xcode but @@ -171,16 +195,8 @@ macro(test_targets) add_default_target_arch(${COMPILER_RT_DEFAULT_TARGET_ARCH}) elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64") if(NOT MSVC) - if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") - if (CMAKE_SIZEOF_VOID_P EQUAL 4) - test_target_arch(i386 __i386__ "-m32") - else() - test_target_arch(x86_64 "" "-m64") - endif() - else() - test_target_arch(x86_64 "" "-m64") - test_target_arch(i386 __i386__ "-m32") - endif() + test_target_arch(x86_64 "" "-m64") + test_target_arch(i386 __i386__ "-m32") else() if (CMAKE_SIZEOF_VOID_P EQUAL 4) test_target_arch(i386 "" "") @@ -188,19 +204,13 @@ macro(test_targets) test_target_arch(x86_64 "" "") endif() endif() + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le") + test_target_arch(powerpc64le "" "-m64") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc") - # Strip out -nodefaultlibs when calling TEST_BIG_ENDIAN. Configuration - # will fail with this option when building with a sanitizer. - cmake_push_check_state() - string(REPLACE "-nodefaultlibs" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN) - cmake_pop_check_state() - - if(HOST_IS_BIG_ENDIAN) - test_target_arch(powerpc64 "" "-m64") - else() - test_target_arch(powerpc64le "" "-m64") + if(CMAKE_SYSTEM_NAME MATCHES "AIX") + test_target_arch(powerpc "" "-m32") endif() + test_target_arch(powerpc64 "" "-m64") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x") test_target_arch(s390x "" "") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc") diff --git a/gnu/llvm/compiler-rt/cmake/builtin-config-ix.cmake b/gnu/llvm/compiler-rt/cmake/builtin-config-ix.cmake index 8de901513be..fe5661b7763 100644 --- a/gnu/llvm/compiler-rt/cmake/builtin-config-ix.cmake +++ b/gnu/llvm/compiler-rt/cmake/builtin-config-ix.cmake @@ -10,7 +10,6 @@ builtin_check_c_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) builtin_check_c_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG) builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG) builtin_check_c_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG) -builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG) builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FREESTANDING_FLAG) builtin_check_c_compiler_flag(-fxray-instrument COMPILER_RT_HAS_XRAY_COMPILER_FLAG) @@ -22,14 +21,28 @@ int foo(int x, int y) { } ") +builtin_check_c_compiler_source(COMPILER_RT_HAS_FLOAT16 +" +_Float16 foo(_Float16 x) { + return x; +} +" +) + +builtin_check_c_compiler_source(COMPILER_RT_HAS_ASM_LSE +" +asm(\".arch armv8-a+lse\"); +asm(\"cas w0, w1, [x2]\"); +") set(ARM64 aarch64) -set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) +set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv8m.main armv8.1m.main) set(HEXAGON hexagon) set(X86 i386) set(X86_64 x86_64) set(MIPS32 mips mipsel) set(MIPS64 mips64 mips64el) +set(PPC32 powerpc) set(PPC64 powerpc64 powerpc64le) set(RISCV32 riscv32) set(RISCV64 riscv64) @@ -47,7 +60,7 @@ endif() set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} - ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} + ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC32} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64} ${VE}) @@ -108,7 +121,7 @@ if(APPLE) set(DARWIN_watchos_BUILTIN_MIN_VER 2.0) set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER}) - set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k) + set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k arm64_32) set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86}) endif() if(COMPILER_RT_ENABLE_TVOS) diff --git a/gnu/llvm/compiler-rt/cmake/config-ix.cmake b/gnu/llvm/compiler-rt/cmake/config-ix.cmake index 2edc1dabd90..39b9120f00a 100644 --- a/gnu/llvm/compiler-rt/cmake/config-ix.cmake +++ b/gnu/llvm/compiler-rt/cmake/config-ix.cmake @@ -6,7 +6,7 @@ include(CheckLibraryExists) include(CheckSymbolExists) include(TestBigEndian) -function(check_linker_flag flag out_var) +function(compiler_rt_check_linker_flag flag out_var) cmake_push_check_state() set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") check_cxx_compiler_flag("" ${out_var}) @@ -55,6 +55,7 @@ endif () # CodeGen options. check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG) +check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG) check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG) check_cxx_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) check_cxx_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) @@ -106,6 +107,7 @@ check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRT check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG) check_cxx_compiler_flag("-Werror -Wunused-parameter" COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG) check_cxx_compiler_flag("-Werror -Wcovered-switch-default" COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG) +check_cxx_compiler_flag("-Werror -Wsuggest-override" COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG) check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC) check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG) @@ -121,7 +123,9 @@ check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG) check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) # Includes. -check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV) +check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG) +check_cxx_compiler_flag(-nostdlib++ COMPILER_RT_HAS_NOSTDLIBXX_FLAG) +check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV) # Libraries. check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL) @@ -131,17 +135,18 @@ check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD) check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO) # Look for terminfo library, used in unittests that depend on LLVMSupport. +if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON) + set(MAYBE_REQUIRED REQUIRED) +else() + set(MAYBE_REQUIRED) +endif() if(LLVM_ENABLE_TERMINFO) - foreach(library terminfo tinfo curses ncurses ncursesw) - string(TOUPPER ${library} library_suffix) - check_library_exists( - ${library} setupterm "" COMPILER_RT_HAS_TERMINFO_${library_suffix}) - if(COMPILER_RT_HAS_TERMINFO_${library_suffix}) - set(COMPILER_RT_HAS_TERMINFO TRUE) - set(COMPILER_RT_TERMINFO_LIB "${library}") - break() - endif() - endforeach() + find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED}) +endif() +if(COMPILER_RT_TERMINFO_LIB) + set(LLVM_ENABLE_TERMINFO 1) +else() + set(LLVM_ENABLE_TERMINFO 0) endif() if (ANDROID AND COMPILER_RT_HAS_LIBDL) @@ -152,11 +157,24 @@ check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX) check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX) # Linker flags. -check_linker_flag("-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) -check_linker_flag("-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) +compiler_rt_check_linker_flag("-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) +compiler_rt_check_linker_flag("-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) + +set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat") +compiler_rt_check_linker_flag("${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + +set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers) +file(WRITE ${DUMMY_VERS} "{};") +set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}") +if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + # Solaris 11.4 ld only supports --version-script with + # -z gnu-version-script-compat. + string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}") +endif() +compiler_rt_check_linker_flag("${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT) if(ANDROID) - check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) + compiler_rt_check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG) endif() @@ -202,7 +220,7 @@ endfunction() # specific architecture. When cross-compiling, this is controled via # COMPILER_RT_TEST_COMPILER and COMPILER_RT_TEST_COMPILER_CFLAGS. macro(get_test_cc_for_arch arch cc_out cflags_out) - if(ANDROID OR ${arch} MATCHES "arm|aarch64") + if(ANDROID OR ${arch} MATCHES "arm|aarch64|riscv32|riscv64") # This is only true if we are cross-compiling. # Build all tests with host compiler and use host tools. set(${cc_out} ${COMPILER_RT_TEST_COMPILER}) @@ -261,6 +279,7 @@ set(X86 i386) set(X86_64 x86_64) set(MIPS32 mips mipsel) set(MIPS64 mips64 mips64el) +set(PPC32 powerpc) set(PPC64 powerpc64 powerpc64le) set(RISCV32 riscv32) set(RISCV64 riscv64) @@ -269,6 +288,7 @@ set(SPARC sparc) set(SPARCV9 sparcv9) set(WASM32 wasm32) set(WASM64 wasm64) +set(VE ve) if(APPLE) set(ARM64 arm64) @@ -278,9 +298,9 @@ endif() set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} +set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64}) +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64} ${VE}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) if(ANDROID) @@ -290,7 +310,7 @@ else() endif() if(OS_NAME MATCHES "Linux") - set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64}) + set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${S390X}) elseif (OS_NAME MATCHES "Windows") set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64}) elseif(OS_NAME MATCHES "Android") @@ -299,23 +319,24 @@ else() set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64}) endif() -set(ALL_GWP_ASAN_SUPPORTED_ARCH ${X86} ${X86_64}) +set(ALL_GWP_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}) if(APPLE) set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64}) else() - set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32} ${PPC64} ${S390X}) + set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32} ${PPC64} ${S390X} ${RISCV64}) endif() set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}) set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64}) -set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64} +set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64}) +set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} ${PPC64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64}) +set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}) set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9}) set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64}) set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64}) set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64}) -set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64}) +set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64}) if(APPLE) set(ALL_XRAY_SUPPORTED_ARCH ${X86_64}) else() @@ -323,6 +344,10 @@ set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} powe endif() set(ALL_SHADOWCALLSTACK_SUPPORTED_ARCH ${ARM64}) +if (UNIX) +set(ALL_ORC_SUPPORTED_ARCH ${X86_64}) +endif() + if(APPLE) include(CompilerRTDarwinUtils) @@ -379,6 +404,7 @@ if(APPLE) set(TSAN_SUPPORTED_OS osx) set(XRAY_SUPPORTED_OS osx) set(FUZZER_SUPPORTED_OS osx) + set(ORC_SUPPORTED_OS osx) # Note: In order to target x86_64h on OS X the minimum deployment target must # be 10.8 or higher. @@ -412,7 +438,7 @@ if(APPLE) -lc++ -lc++abi) - check_linker_flag("-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION) + compiler_rt_check_linker_flag("-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION) if(COMPILER_RT_HAS_APP_EXTENSION) list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension") endif() @@ -534,6 +560,9 @@ if(APPLE) list_intersect(HWASAN_SUPPORTED_ARCH ALL_HWASAN_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH) + list_intersect(MEMPROF_SUPPORTED_ARCH + ALL_MEMPROF_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) list_intersect(PROFILE_SUPPORTED_ARCH ALL_PROFILE_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH) @@ -564,6 +593,9 @@ if(APPLE) list_intersect(SHADOWCALLSTACK_SUPPORTED_ARCH ALL_SHADOWCALLSTACK_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH) + list_intersect(ORC_SUPPORTED_ARCH + ALL_ORC_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) else() filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) @@ -582,6 +614,7 @@ else() filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH}) filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH}) filter_available_targets(HWASAN_SUPPORTED_ARCH ${ALL_HWASAN_SUPPORTED_ARCH}) + filter_available_targets(MEMPROF_SUPPORTED_ARCH ${ALL_MEMPROF_SUPPORTED_ARCH}) filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH}) filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH}) filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH}) @@ -594,6 +627,7 @@ else() filter_available_targets(SHADOWCALLSTACK_SUPPORTED_ARCH ${ALL_SHADOWCALLSTACK_SUPPORTED_ARCH}) filter_available_targets(GWP_ASAN_SUPPORTED_ARCH ${ALL_GWP_ASAN_SUPPORTED_ARCH}) + filter_available_targets(ORC_SUPPORTED_ARCH ${ALL_ORC_SUPPORTED_ARCH}) endif() if (MSVC) @@ -608,7 +642,8 @@ else() set(CAN_SYMBOLIZE 1) endif() -find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") +find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld") +find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold DOC "GNU gold") if(COMPILER_RT_SUPPORTED_ARCH) list(REMOVE_DUPLICATES COMPILER_RT_SUPPORTED_ARCH) @@ -621,7 +656,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}") if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND - (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|OpenBSD|Fuchsia|SunOS" OR + (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS" OR (OS_NAME MATCHES "Windows" AND NOT CYGWIN AND (NOT MINGW OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")))) set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE) @@ -635,8 +670,7 @@ else() set(COMPILER_RT_HAS_INTERCEPTION FALSE) endif() -if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND - NOT OS_NAME MATCHES "OpenBSD") +if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH) set(COMPILER_RT_HAS_ASAN TRUE) else() set(COMPILER_RT_HAS_ASAN FALSE) @@ -664,7 +698,7 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Darwin|Linux|NetBSD|Fuchsia") + OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|Fuchsia") set(COMPILER_RT_HAS_LSAN TRUE) else() set(COMPILER_RT_HAS_LSAN FALSE) @@ -684,8 +718,15 @@ else() set(COMPILER_RT_HAS_HWASAN FALSE) endif() +if (COMPILER_RT_HAS_SANITIZER_COMMON AND MEMPROF_SUPPORTED_ARCH AND + OS_NAME MATCHES "Linux") + set(COMPILER_RT_HAS_MEMPROF TRUE) +else() + set(COMPILER_RT_HAS_MEMPROF FALSE) +endif() + if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND - OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD") + OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX") set(COMPILER_RT_HAS_PROFILE TRUE) else() set(COMPILER_RT_HAS_PROFILE FALSE) @@ -699,14 +740,14 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|OpenBSD|Windows|Android|Fuchsia|SunOS") + OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS") set(COMPILER_RT_HAS_UBSAN TRUE) else() set(COMPILER_RT_HAS_UBSAN FALSE) endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Linux|FreeBSD|NetBSD|OpenBSD|Android|Darwin") + OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Android|Darwin") set(COMPILER_RT_HAS_UBSAN_MINIMAL TRUE) else() set(COMPILER_RT_HAS_UBSAN_MINIMAL FALSE) @@ -741,14 +782,20 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND - OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|OpenBSD|Fuchsia") + OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Fuchsia") set(COMPILER_RT_HAS_XRAY TRUE) else() set(COMPILER_RT_HAS_XRAY FALSE) endif() +if (ORC_SUPPORTED_ARCH) + set(COMPILER_RT_HAS_ORC TRUE) +else() + set(COMPILER_RT_HAS_ORC FALSE) +endif() + if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND - OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|OpenBSD|Fuchsia|Windows") + OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|Fuchsia|Windows") set(COMPILER_RT_HAS_FUZZER TRUE) else() set(COMPILER_RT_HAS_FUZZER FALSE) diff --git a/gnu/llvm/compiler-rt/docs/BuildingCompilerRT.rst b/gnu/llvm/compiler-rt/docs/BuildingCompilerRT.rst new file mode 100644 index 00000000000..2ab6f083fc6 --- /dev/null +++ b/gnu/llvm/compiler-rt/docs/BuildingCompilerRT.rst @@ -0,0 +1,92 @@ +.. _BuildingCompilerRT: + +=============== +Building Compiler-RT +=============== + +.. contents:: + :local: + +.. _build instructions: + +The instructions on this page are aimed at vendors who ship Compiler-RT as part of an +operating system distribution, a toolchain or similar shipping vehicules. If you +are a user merely trying to use Compiler-RT in your program, you most likely want to +refer to your vendor's documentation, or to the general documentation for using +LLVM, Clang, the various santizers, etc. + +CMake Options +============= + +Here are some of the CMake variables that are used often, along with a +brief explanation and LLVM-specific notes. For full documentation, check the +CMake docs or execute ``cmake --help-variable VARIABLE_NAME``. + +**CMAKE_BUILD_TYPE**:STRING + Sets the build type for ``make`` based generators. Possible values are + Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio + the user sets the build type with the IDE settings. + +**CMAKE_INSTALL_PREFIX**:PATH + Path where LLVM will be installed if "make install" is invoked or the + "INSTALL" target is built. + +**CMAKE_CXX_COMPILER**:STRING + The C++ compiler to use when building and testing Compiler-RT. + + +.. _compiler-rt-specific options: + +Compiler-RT specific options +----------------------- + +.. option:: COMPILER_RT_INSTALL_PATH:PATH + + **Default**: ```` (empty relative path) + + Prefix for directories where built Compiler-RT artifacts should be installed. + Can be an absolute path, like the default empty string, in which case it is + relative ``CMAKE_INSTALL_PREFIX``. If setting a relative path, make sure to + include the ``:PATH`` with your ``-D``, i.e. use + ``-DCOMPILER_RT_INSTALL_PATH:PATH=...`` not + ``-DCOMPILER_RT_INSTALL_PATH=...``, otherwise CMake will convert the + path to an absolute path. + +.. option:: COMPILER_RT_INSTALL_LIBRARY_DIR:PATH + + **Default**: ``lib`` + + Path where built Compiler-RT libraries should be installed. If a relative + path, relative to ``COMPILER_RT_INSTALL_PATH``. + +.. option:: COMPILER_RT_INSTALL_BINARY_DIR:PATH + + **Default**: ``bin`` + + Path where built Compiler-RT executables should be installed. If a relative + path, relative to ``COMPILER_RT_INSTALL_PATH``. + +.. option:: COMPILER_RT_INSTALL_INCLUDE_DIR:PATH + + **Default**: ``include`` + + Path where Compiler-RT headers should be installed. If a relative + path, relative to ``COMPILER_RT_INSTALL_PATH``. + +.. option:: COMPILER_RT_INSTALL_DATA_DIR:PATH + + **Default**: ``share`` + + Path where Compiler-RT data should be installed. If a relative + path, relative to ``COMPILER_RT_INSTALL_PATH``. + +.. _LLVM-specific variables: + +LLVM-specific options +--------------------- + +.. option:: LLVM_LIBDIR_SUFFIX:STRING + + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` + to install libraries to ``/usr/lib64``. diff --git a/gnu/llvm/compiler-rt/include/CMakeLists.txt b/gnu/llvm/compiler-rt/include/CMakeLists.txt index d47d7baeb11..7b415f0b88a 100644 --- a/gnu/llvm/compiler-rt/include/CMakeLists.txt +++ b/gnu/llvm/compiler-rt/include/CMakeLists.txt @@ -20,6 +20,12 @@ if (COMPILER_RT_BUILD_SANITIZERS) ) endif(COMPILER_RT_BUILD_SANITIZERS) +if (COMPILER_RT_BUILD_MEMPROF) + set(MEMPROF_HEADERS + sanitizer/memprof_interface.h + ) +endif(COMPILER_RT_BUILD_MEMPROF) + if (COMPILER_RT_BUILD_XRAY) set(XRAY_HEADERS xray/xray_interface.h @@ -37,6 +43,7 @@ endif(COMPILER_RT_BUILD_PROFILE) set(COMPILER_RT_HEADERS ${SANITIZER_HEADERS} ${FUZZER_HEADERS} + ${MEMPROF_HEADERS} ${XRAY_HEADERS} ${PROFILE_HEADERS}) @@ -62,22 +69,22 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") install(FILES ${SANITIZER_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) + DESTINATION ${COMPILER_RT_INSTALL_INCLUDE_DIR}/sanitizer) # Install fuzzer headers. install(FILES ${FUZZER_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer) + DESTINATION ${COMPILER_RT_INSTALL_INCLUDE_DIR}/fuzzer) # Install xray headers. install(FILES ${XRAY_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) + DESTINATION ${COMPILER_RT_INSTALL_INCLUDE_DIR}/xray) # Install profile headers. install(FILES ${PROFILE_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile) + DESTINATION ${COMPILER_RT_INSTALL_INCLUDE_DIR}/profile) if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. add_custom_target(install-compiler-rt-headers diff --git a/gnu/llvm/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/gnu/llvm/compiler-rt/include/fuzzer/FuzzedDataProvider.h index 83bcd0134a7..71cb427ec4a 100644 --- a/gnu/llvm/compiler-rt/include/fuzzer/FuzzedDataProvider.h +++ b/gnu/llvm/compiler-rt/include/fuzzer/FuzzedDataProvider.h @@ -14,11 +14,13 @@ #define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_ #include +#include #include #include #include #include #include +#include #include #include #include @@ -71,6 +73,8 @@ class FuzzedDataProvider { // Returns a value from the given array. template T PickValueInArray(const T (&array)[size]); + template + T PickValueInArray(const std::array &array); template T PickValueInArray(std::initializer_list list); // Writes data to the given destination and returns number of bytes written. @@ -301,6 +305,12 @@ T FuzzedDataProvider::PickValueInArray(const T (&array)[size]) { return array[ConsumeIntegralInRange(0, size - 1)]; } +template +T FuzzedDataProvider::PickValueInArray(const std::array &array) { + static_assert(size > 0, "The array must be non empty."); + return array[ConsumeIntegralInRange(0, size - 1)]; +} + template T FuzzedDataProvider::PickValueInArray(std::initializer_list list) { // TODO(Dor1s): switch to static_assert once C++14 is allowed. @@ -380,7 +390,7 @@ TS FuzzedDataProvider::ConvertUnsignedToSigned(TU value) { return static_cast(value); } else { constexpr auto TS_min = std::numeric_limits::min(); - return TS_min + static_cast(value - TS_min); + return TS_min + static_cast(value - TS_min); } } diff --git a/gnu/llvm/compiler-rt/include/profile/InstrProfData.inc b/gnu/llvm/compiler-rt/include/profile/InstrProfData.inc index a6913527e67..7d2097cfc29 100644 --- a/gnu/llvm/compiler-rt/include/profile/InstrProfData.inc +++ b/gnu/llvm/compiler-rt/include/profile/InstrProfData.inc @@ -6,15 +6,15 @@ |* \*===----------------------------------------------------------------------===*/ /* - * This is the master file that defines all the data structure, signature, + * This is the main file that defines all the data structure, signature, * constant literals that are shared across profiling runtime library, * compiler (instrumentation), and host tools (reader/writer). The entities * defined in this file affect the profile runtime ABI, the raw profile format, * or both. * - * The file has two identical copies. The master copy lives in LLVM and + * The file has two identical copies. The primary copy lives in LLVM and * the other one sits in compiler-rt/lib/profile directory. To make changes - * in this file, first modify the master copy and copy it over to compiler-rt. + * in this file, first modify the primary copy and copy it over to compiler-rt. * Testing of any change in this file can start only after the two copies are * synced up. * @@ -129,6 +129,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \ #endif INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic()) INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version()) +INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL)) INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize) INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters) INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize) @@ -154,17 +155,7 @@ INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last) VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \ INSTR_PROF_COMMA VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA -#ifndef VALUE_RANGE_PROF VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx)) -#else /* VALUE_RANGE_PROF */ -VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx)) \ - INSTR_PROF_COMMA -VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeStart, Type::getInt64Ty(Ctx)) \ - INSTR_PROF_COMMA -VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeLast, Type::getInt64Ty(Ctx)) \ - INSTR_PROF_COMMA -VALUE_PROF_FUNC_PARAM(uint64_t, LargeValue, Type::getInt64Ty(Ctx)) -#endif /*VALUE_RANGE_PROF */ #undef VALUE_PROF_FUNC_PARAM #undef INSTR_PROF_COMMA /* VALUE_PROF_FUNC_PARAM end */ @@ -655,11 +646,11 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure, (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129 /* Raw profile format version (start from 1). */ -#define INSTR_PROF_RAW_VERSION 5 +#define INSTR_PROF_RAW_VERSION 7 /* Indexed profile format version (start from 1). */ -#define INSTR_PROF_INDEX_VERSION 6 +#define INSTR_PROF_INDEX_VERSION 7 /* Coverage mapping format version (start from 0). */ -#define INSTR_PROF_COVMAP_VERSION 3 +#define INSTR_PROF_COVMAP_VERSION 5 /* Profile version is always of type uint64_t. Reserve the upper 8 bits in the * version for other variants of profile. We set the lowest bit of the upper 8 @@ -671,8 +662,10 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure, #define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL) #define VARIANT_MASK_IR_PROF (0x1ULL << 56) #define VARIANT_MASK_CSIR_PROF (0x1ULL << 57) +#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58) #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version #define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime +#define INSTR_PROF_PROFILE_COUNTER_BIAS_VAR __llvm_profile_counter_bias /* The variable that holds the name of the profile data * specified via command line. */ @@ -753,9 +746,9 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure, #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target #define INSTR_PROF_VALUE_PROF_FUNC_STR \ INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC) -#define INSTR_PROF_VALUE_RANGE_PROF_FUNC __llvm_profile_instrument_range -#define INSTR_PROF_VALUE_RANGE_PROF_FUNC_STR \ - INSTR_PROF_QUOTE(INSTR_PROF_VALUE_RANGE_PROF_FUNC) +#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC __llvm_profile_instrument_memop +#define INSTR_PROF_VALUE_PROF_MEMOP_FUNC_STR \ + INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_MEMOP_FUNC) /* InstrProfile per-function control data alignment. */ #define INSTR_PROF_DATA_ALIGNMENT 8 @@ -783,3 +776,122 @@ typedef struct InstrProfValueData { #endif #undef COVMAP_V2_OR_V3 + +#ifdef INSTR_PROF_VALUE_PROF_MEMOP_API + +#ifdef __cplusplus +#define INSTR_PROF_INLINE inline +#else +#define INSTR_PROF_INLINE +#endif + +/* The value range buckets (22 buckets) for the memop size value profiling looks + * like: + * + * [0, 0] + * [1, 1] + * [2, 2] + * [3, 3] + * [4, 4] + * [5, 5] + * [6, 6] + * [7, 7] + * [8, 8] + * [9, 15] + * [16, 16] + * [17, 31] + * [32, 32] + * [33, 63] + * [64, 64] + * [65, 127] + * [128, 128] + * [129, 255] + * [256, 256] + * [257, 511] + * [512, 512] + * [513, UINT64_MAX] + * + * Each range has a 'representative value' which is the lower end value of the + * range and used to store in the runtime profile data records and the VP + * metadata. For example, it's 2 for [2, 2] and 64 for [65, 127]. + */ +#define INSTR_PROF_NUM_BUCKETS 22 + +/* + * Clz and Popcount. This code was copied from + * compiler-rt/lib/fuzzer/{FuzzerBuiltins.h,FuzzerBuiltinsMsvc.h} and + * llvm/include/llvm/Support/MathExtras.h. + */ +#if defined(_MSC_VER) && !defined(__clang__) + +#include +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE +int InstProfClzll(unsigned long long X) { + unsigned long LeadZeroIdx = 0; +#if !defined(_M_ARM64) && !defined(_M_X64) + // Scan the high 32 bits. + if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X >> 32))) + return (int)(63 - (LeadZeroIdx + 32)); // Create a bit offset + // from the MSB. + // Scan the low 32 bits. + if (_BitScanReverse(&LeadZeroIdx, (unsigned long)(X))) + return (int)(63 - LeadZeroIdx); +#else + if (_BitScanReverse64(&LeadZeroIdx, X)) return 63 - LeadZeroIdx; +#endif + return 64; +} +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE +int InstProfPopcountll(unsigned long long X) { + // This code originates from https://reviews.llvm.org/rG30626254510f. + unsigned long long v = X; + v = v - ((v >> 1) & 0x5555555555555555ULL); + v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL); + v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL; + return (int)((unsigned long long)(v * 0x0101010101010101ULL) >> 56); +} + +#else + +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE +int InstProfClzll(unsigned long long X) { return __builtin_clzll(X); } +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE +int InstProfPopcountll(unsigned long long X) { return __builtin_popcountll(X); } + +#endif /* defined(_MSC_VER) && !defined(__clang__) */ + +/* Map an (observed) memop size value to the representative value of its range. + * For example, 5 -> 5, 22 -> 17, 99 -> 65, 256 -> 256, 1001 -> 513. */ +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE uint64_t +InstrProfGetRangeRepValue(uint64_t Value) { + if (Value <= 8) + // The first ranges are individually tracked. Use the value as is. + return Value; + else if (Value >= 513) + // The last range is mapped to its lowest value. + return 513; + else if (InstProfPopcountll(Value) == 1) + // If it's a power of two, use it as is. + return Value; + else + // Otherwise, take to the previous power of two + 1. + return (UINT64_C(1) << (64 - InstProfClzll(Value) - 1)) + 1; +} + +/* Return true if the range that an (observed) memop size value belongs to has + * only a single value in the range. For example, 0 -> true, 8 -> true, 10 -> + * false, 64 -> true, 100 -> false, 513 -> false. */ +INSTR_PROF_VISIBILITY INSTR_PROF_INLINE unsigned +InstrProfIsSingleValRange(uint64_t Value) { + if (Value <= 8) + // The first ranges are individually tracked. + return 1; + else if (InstProfPopcountll(Value) == 1) + // If it's a power of two, there's only one value. + return 1; + else + // Otherwise, there's more than one value in the range. + return 0; +} + +#endif /* INSTR_PROF_VALUE_PROF_MEMOP_API */ diff --git a/gnu/llvm/compiler-rt/include/sanitizer/asan_interface.h b/gnu/llvm/compiler-rt/include/sanitizer/asan_interface.h index 6af93aad651..792ef9cfaa3 100644 --- a/gnu/llvm/compiler-rt/include/sanitizer/asan_interface.h +++ b/gnu/llvm/compiler-rt/include/sanitizer/asan_interface.h @@ -188,8 +188,8 @@ const char *__asan_get_report_description(void); /// \param addr Address to locate. /// \param name Buffer to store the variable's name. /// \param name_size Size in bytes of the variable's name buffer. -/// \param region_address [out] Address of the region. -/// \param region_size [out] Size of the region in bytes. +/// \param[out] region_address Address of the region. +/// \param[out] region_size Size of the region in bytes. /// /// \returns Returns the category of the given pointer as a constant string. const char *__asan_locate_address(void *addr, char *name, size_t name_size, @@ -204,7 +204,7 @@ const char *__asan_locate_address(void *addr, char *name, size_t name_size, /// \param addr A heap address. /// \param trace A buffer to store the stack trace. /// \param size Size in bytes of the trace buffer. -/// \param thread_id [out] The thread ID of the address. +/// \param[out] thread_id The thread ID of the address. /// /// \returns Returns the number of stored frames or 0 on error. size_t __asan_get_alloc_stack(void *addr, void **trace, size_t size, @@ -219,7 +219,7 @@ size_t __asan_get_alloc_stack(void *addr, void **trace, size_t size, /// \param addr A heap address. /// \param trace A buffer to store the stack trace. /// \param size Size in bytes of the trace buffer. -/// \param thread_id [out] The thread ID of the address. +/// \param[out] thread_id The thread ID of the address. /// /// \returns Returns the number of stored frames or 0 on error. size_t __asan_get_free_stack(void *addr, void **trace, size_t size, @@ -228,8 +228,8 @@ size_t __asan_get_free_stack(void *addr, void **trace, size_t size, /// Gets the current shadow memory mapping (useful for calling from the /// debugger). /// -/// \param shadow_scale [out] Shadow scale value. -/// \param shadow_offset [out] Offset value. +/// \param[out] shadow_scale Shadow scale value. +/// \param[out] shadow_offset Offset value. void __asan_get_shadow_mapping(size_t *shadow_scale, size_t *shadow_offset); /// This is an internal function that is called to report an error. However, @@ -302,8 +302,8 @@ void *__asan_get_current_fake_stack(void); /// /// \param fake_stack An opaque handler to a fake stack. /// \param addr Address to test. -/// \param beg [out] Beginning of fake frame. -/// \param end [out] End of fake frame. +/// \param[out] beg Beginning of fake frame. +/// \param[out] end End of fake frame. /// \returns Stack address or NULL. void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg, void **end); diff --git a/gnu/llvm/compiler-rt/include/sanitizer/common_interface_defs.h b/gnu/llvm/compiler-rt/include/sanitizer/common_interface_defs.h index f979c6a8f63..cd69285b8d4 100644 --- a/gnu/llvm/compiler-rt/include/sanitizer/common_interface_defs.h +++ b/gnu/llvm/compiler-rt/include/sanitizer/common_interface_defs.h @@ -43,6 +43,9 @@ void __sanitizer_set_report_path(const char *path); // Tell the tools to write their reports to the provided file descriptor // (casted to void *). void __sanitizer_set_report_fd(void *fd); +// Get the current full report file path, if a path was specified by +// an earlier call to __sanitizer_set_report_path. Returns null otherwise. +const char *__sanitizer_get_report_path(); // Notify the tools that the sandbox is going to be turned on. The reserved // parameter will be used in the future to hold a structure with functions @@ -320,7 +323,7 @@ void __sanitizer_print_memory_profile(size_t top_percent, /// signal callback runs during the switch, it will not benefit from stack /// use-after-return detection. /// -/// \param fake_stack_save [out] Fake stack save location. +/// \param[out] fake_stack_save Fake stack save location. /// \param bottom Bottom address of stack. /// \param size Size of stack in bytes. void __sanitizer_start_switch_fiber(void **fake_stack_save, @@ -335,8 +338,8 @@ void __sanitizer_start_switch_fiber(void **fake_stack_save, /// __sanitizer_start_switch_fiber(). /// /// \param fake_stack_save Fake stack save location. -/// \param bottom_old [out] Bottom address of old stack. -/// \param size_old [out] Size of old stack in bytes. +/// \param[out] bottom_old Bottom address of old stack. +/// \param[out] size_old Size of old stack in bytes. void __sanitizer_finish_switch_fiber(void *fake_stack_save, const void **bottom_old, size_t *size_old); diff --git a/gnu/llvm/compiler-rt/include/sanitizer/dfsan_interface.h b/gnu/llvm/compiler-rt/include/sanitizer/dfsan_interface.h index 81546e5df71..cd3b6d6e2b1 100644 --- a/gnu/llvm/compiler-rt/include/sanitizer/dfsan_interface.h +++ b/gnu/llvm/compiler-rt/include/sanitizer/dfsan_interface.h @@ -21,33 +21,15 @@ extern "C" { #endif -typedef uint16_t dfsan_label; - -/// Stores information associated with a specific label identifier. A label -/// may be a base label created using dfsan_create_label, with associated -/// text description and user data, or an automatically created union label, -/// which represents the union of two label identifiers (which may themselves -/// be base or union labels). -struct dfsan_label_info { - // Fields for union labels, set to 0 for base labels. - dfsan_label l1; - dfsan_label l2; - - // Fields for base labels. - const char *desc; - void *userdata; -}; +typedef uint8_t dfsan_label; +typedef uint32_t dfsan_origin; /// Signature of the callback argument to dfsan_set_write_callback(). typedef void (*dfsan_write_callback_t)(int fd, const void *buf, size_t count); -/// Computes the union of \c l1 and \c l2, possibly creating a union label in -/// the process. +/// Computes the union of \c l1 and \c l2, resulting in a union label. dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2); -/// Creates and returns a base label with the given description and user data. -dfsan_label dfsan_create_label(const char *desc, void *userdata); - /// Sets the label for each address in [addr,addr+size) to \c label. void dfsan_set_label(dfsan_label label, void *addr, size_t size); @@ -63,26 +45,24 @@ void dfsan_add_label(dfsan_label label, void *addr, size_t size); /// value. dfsan_label dfsan_get_label(long data); +/// Retrieves the immediate origin associated with the given data. The returned +/// origin may point to another origin. +/// +/// The type of 'data' is arbitrary. +dfsan_origin dfsan_get_origin(long data); + /// Retrieves the label associated with the data at the given address. dfsan_label dfsan_read_label(const void *addr, size_t size); -/// Retrieves a pointer to the dfsan_label_info struct for the given label. -const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label); - /// Returns whether the given label label contains the label elem. int dfsan_has_label(dfsan_label label, dfsan_label elem); -/// If the given label label contains a label with the description desc, returns -/// that label, else returns 0. -dfsan_label dfsan_has_label_with_desc(dfsan_label label, const char *desc); - -/// Returns the number of labels allocated. -size_t dfsan_get_label_count(void); - /// Flushes the DFSan shadow, i.e. forgets about all labels currently associated -/// with the application memory. Will work only if there are no other -/// threads executing DFSan-instrumented code concurrently. -/// Use this call to start over the taint tracking within the same procces. +/// with the application memory. Use this call to start over the taint tracking +/// within the same process. +/// +/// Note: If another thread is working with tainted data during the flush, that +/// taint could still be written to shadow after the flush. void dfsan_flush(void); /// Sets a callback to be invoked on calls to write(). The callback is invoked @@ -90,12 +70,6 @@ void dfsan_flush(void); /// callback executes. Pass in NULL to remove any callback. void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback); -/// Writes the labels currently used by the program to the given file -/// descriptor. The lines of the output have the following format: -/// -///