From 5c909fa013fc285f010a95e8d387e0ef3412da9c Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 30 Dec 2015 11:52:19 +0000 Subject: Vendor import of compiler-rt trunk r256633: https://llvm.org/svn/llvm-project/compiler-rt/trunk@256633 --- CMakeLists.txt | 110 +-- cmake/Modules/AddCompilerRT.cmake | 214 +++--- cmake/Modules/CompilerRTCompile.cmake | 6 +- cmake/Modules/CompilerRTDarwinUtils.cmake | 453 +++++++++++++ cmake/Modules/CompilerRTUtils.cmake | 10 + cmake/Modules/SanitizerUtils.cmake | 82 ++- cmake/config-ix.cmake | 346 ++++++++-- include/sanitizer/asan_interface.h | 4 - include/sanitizer/common_interface_defs.h | 17 + include/sanitizer/coverage_interface.h | 4 +- include/sanitizer/dfsan_interface.h | 6 +- include/sanitizer/lsan_interface.h | 2 +- include/sanitizer/msan_interface.h | 16 +- lib/CMakeLists.txt | 60 +- lib/asan/.clang-format | 1 + lib/asan/CMakeLists.txt | 149 ++-- lib/asan/README.txt | 2 +- lib/asan/asan_activation.cc | 9 +- lib/asan/asan_allocator.cc | 22 +- lib/asan/asan_allocator.h | 5 + lib/asan/asan_debugging.cc | 4 +- lib/asan/asan_fake_stack.cc | 22 +- lib/asan/asan_flags.cc | 9 +- lib/asan/asan_flags.inc | 24 +- lib/asan/asan_globals.cc | 5 +- lib/asan/asan_init_version.h | 4 +- lib/asan/asan_interceptors.cc | 74 +- lib/asan/asan_interceptors.h | 6 + lib/asan/asan_interface_internal.h | 23 +- lib/asan/asan_internal.h | 7 +- lib/asan/asan_linux.cc | 23 +- lib/asan/asan_mac.cc | 197 +----- lib/asan/asan_malloc_linux.cc | 21 +- lib/asan/asan_malloc_mac.cc | 371 +--------- lib/asan/asan_mapping.h | 33 +- lib/asan/asan_new_delete.cc | 10 +- lib/asan/asan_poisoning.cc | 29 +- lib/asan/asan_posix.cc | 10 +- lib/asan/asan_report.cc | 229 ++++--- lib/asan/asan_report.h | 67 +- lib/asan/asan_rtl.cc | 152 +++-- lib/asan/asan_stack.h | 9 +- lib/asan/asan_thread.cc | 21 +- lib/asan/asan_thread.h | 13 +- lib/asan/asan_win.cc | 20 +- lib/asan/asan_win_dll_thunk.cc | 29 +- lib/asan/asan_win_dynamic_runtime_thunk.cc | 2 + lib/asan/scripts/asan_device_setup | 184 +++-- lib/asan/scripts/asan_symbolize.py | 28 +- lib/asan/tests/CMakeLists.txt | 11 +- lib/asan/tests/asan_asm_test.cc | 10 +- lib/asan/tests/asan_interface_test.cc | 10 - lib/asan/tests/asan_mac_test.cc | 4 +- lib/asan/tests/asan_noinst_test.cc | 2 +- lib/asan/tests/asan_test.cc | 19 +- lib/asan/tests/asan_test_main.cc | 14 + lib/builtins/CMakeLists.txt | 172 +++-- lib/builtins/Darwin-excludes/10.4-x86_64.txt | 35 + lib/builtins/Darwin-excludes/10.4.txt | 96 +++ lib/builtins/Darwin-excludes/CMakeLists.txt | 4 + lib/builtins/Darwin-excludes/README.TXT | 11 + lib/builtins/Darwin-excludes/ios-armv7.txt | 57 ++ lib/builtins/Darwin-excludes/ios-armv7s.txt | 57 ++ lib/builtins/Darwin-excludes/ios.txt | 1 + lib/builtins/Darwin-excludes/ios6-armv7.txt | 120 ++++ lib/builtins/Darwin-excludes/ios6-armv7s.txt | 120 ++++ lib/builtins/Darwin-excludes/ios7-arm64.txt | 16 + lib/builtins/Darwin-excludes/iossim-i386.txt | 82 +++ lib/builtins/Darwin-excludes/iossim-x86_64.txt | 12 + lib/builtins/Darwin-excludes/iossim.txt | 1 + lib/builtins/Darwin-excludes/osx-i386.txt | 82 +++ lib/builtins/Darwin-excludes/osx-x86_64.txt | 12 + lib/builtins/Darwin-excludes/osx.txt | 1 + lib/builtins/README.txt | 4 +- lib/builtins/arm/aeabi_cdcmp.S | 96 +++ lib/builtins/arm/aeabi_cdcmpeq_check_nan.c | 16 + lib/builtins/arm/aeabi_cfcmp.S | 91 +++ lib/builtins/arm/aeabi_cfcmpeq_check_nan.c | 16 + lib/builtins/arm/aeabi_drsub.c | 19 + lib/builtins/arm/aeabi_frsub.c | 19 + lib/builtins/assembly.h | 9 + lib/builtins/atomic.c | 14 +- lib/builtins/atomic_flag_clear.c | 10 +- lib/builtins/atomic_flag_clear_explicit.c | 10 +- lib/builtins/atomic_flag_test_and_set.c | 8 + lib/builtins/atomic_flag_test_and_set_explicit.c | 8 + lib/builtins/atomic_signal_fence.c | 8 + lib/builtins/atomic_thread_fence.c | 8 + lib/builtins/comparedf2.c | 5 + lib/builtins/comparesf2.c | 5 + lib/builtins/comparetf2.c | 5 + lib/builtins/divdc3.c | 22 +- lib/builtins/divsc3.c | 22 +- lib/builtins/divtc3.c | 60 ++ lib/builtins/divxc3.c | 22 +- lib/builtins/emutls.c | 183 +++++ lib/builtins/enable_execute_stack.c | 4 +- lib/builtins/extendhfsf2.c | 4 +- lib/builtins/fixunsdfdi.c | 4 +- lib/builtins/fixunssfdi.c | 4 +- lib/builtins/floatdidf.c | 4 +- lib/builtins/floatditf.c | 50 ++ lib/builtins/floatsitf.c | 8 +- lib/builtins/floatundidf.c | 6 +- lib/builtins/floatunditf.c | 40 ++ lib/builtins/fp_add_impl.inc | 2 +- lib/builtins/fp_extend.h | 6 +- lib/builtins/fp_extend_impl.inc | 2 +- lib/builtins/fp_fixint_impl.inc | 2 +- lib/builtins/fp_fixuint_impl.inc | 4 +- lib/builtins/fp_lib.h | 22 +- lib/builtins/fp_mul_impl.inc | 2 +- lib/builtins/fp_trunc.h | 4 +- lib/builtins/fp_trunc_impl.inc | 2 +- lib/builtins/gcc_personality_v0.c | 13 +- lib/builtins/i386/chkstk.S | 4 +- lib/builtins/i386/chkstk2.S | 40 ++ lib/builtins/int_lib.h | 61 +- lib/builtins/int_math.h | 57 +- lib/builtins/int_types.h | 25 +- lib/builtins/int_util.c | 8 +- lib/builtins/int_util.h | 12 +- lib/builtins/macho_embedded/CMakeLists.txt | 4 + lib/builtins/macho_embedded/arm.txt | 16 + lib/builtins/macho_embedded/common.txt | 92 +++ lib/builtins/macho_embedded/i386.txt | 7 + lib/builtins/macho_embedded/thumb2-64.txt | 10 + lib/builtins/macho_embedded/thumb2.txt | 14 + lib/builtins/muldc3.c | 14 +- lib/builtins/mulsc3.c | 14 +- lib/builtins/multc3.c | 68 ++ lib/builtins/mulxc3.c | 14 +- lib/builtins/ppc/DD.h | 43 +- lib/builtins/ppc/divtc3.c | 5 - lib/builtins/ppc/multc3.c | 4 - lib/builtins/subdf3.c | 1 - lib/builtins/subsf3.c | 1 - lib/builtins/truncdfhf2.c | 2 + lib/builtins/truncsfhf2.c | 4 +- lib/builtins/x86_64/chkstk.S | 4 +- lib/builtins/x86_64/chkstk2.S | 42 ++ lib/cfi/CMakeLists.txt | 40 ++ lib/cfi/cfi.cc | 271 ++++++++ lib/cfi/cfi_blacklist.txt | 26 + lib/dfsan/.clang-format | 1 + lib/dfsan/CMakeLists.txt | 17 +- lib/dfsan/dfsan.cc | 97 ++- lib/dfsan/dfsan.h | 7 +- lib/dfsan/dfsan_custom.cc | 48 +- lib/dfsan/dfsan_platform.h | 107 +++ lib/dfsan/done_abilist.txt | 35 +- lib/interception/.clang-format | 1 + lib/interception/interception_linux.h | 10 +- lib/interception/interception_win.cc | 60 +- lib/interception/interception_win.h | 4 + lib/lsan/.clang-format | 1 + lib/lsan/CMakeLists.txt | 8 +- lib/lsan/lsan.cc | 2 + lib/lsan/lsan_allocator.cc | 14 +- lib/lsan/lsan_common.cc | 39 +- lib/lsan/lsan_common.h | 4 +- lib/lsan/lsan_common_linux.cc | 9 +- lib/lsan/lsan_flags.inc | 2 - lib/lsan/lsan_interceptors.cc | 10 +- lib/lsan/lsan_thread.cc | 10 +- lib/msan/.clang-format | 1 + lib/msan/CMakeLists.txt | 24 +- lib/msan/msan.cc | 44 +- lib/msan/msan.h | 82 ++- lib/msan/msan_allocator.cc | 36 +- lib/msan/msan_chained_origin_depot.cc | 10 +- lib/msan/msan_flags.inc | 4 +- lib/msan/msan_interceptors.cc | 90 ++- lib/msan/msan_interface_internal.h | 14 +- lib/msan/msan_linux.cc | 23 +- lib/msan/msan_new_delete.cc | 4 +- lib/msan/msan_thread.h | 2 +- lib/msan/tests/CMakeLists.txt | 39 +- lib/msan/tests/msan_test.cc | 26 +- lib/profile/CMakeLists.txt | 62 +- lib/profile/InstrProfData.inc | 735 ++++++++++++++++++++ lib/profile/InstrProfiling.c | 76 ++- lib/profile/InstrProfiling.h | 77 ++- lib/profile/InstrProfilingBuffer.c | 82 +-- lib/profile/InstrProfilingFile.c | 98 ++- lib/profile/InstrProfilingInternal.h | 78 +++ lib/profile/InstrProfilingPlatformDarwin.c | 45 +- lib/profile/InstrProfilingPlatformLinux.c | 59 ++ lib/profile/InstrProfilingPlatformOther.c | 48 +- lib/profile/InstrProfilingPort.h | 76 +++ lib/profile/InstrProfilingRuntime.cc | 3 +- lib/profile/InstrProfilingUtil.c | 3 +- lib/profile/InstrProfilingValue.c | 180 +++++ lib/profile/InstrProfilingWriter.c | 175 +++++ lib/safestack/.clang-format | 1 + lib/safestack/CMakeLists.txt | 20 +- lib/safestack/safestack.cc | 9 +- lib/sanitizer_common/.clang-format | 1 + lib/sanitizer_common/CMakeLists.txt | 57 +- lib/sanitizer_common/Makefile.mk | 2 + lib/sanitizer_common/sanitizer_addrhashmap.h | 8 +- lib/sanitizer_common/sanitizer_allocator.cc | 17 +- lib/sanitizer_common/sanitizer_allocator.h | 42 +- .../sanitizer_allocator_internal.h | 10 +- lib/sanitizer_common/sanitizer_asm.h | 20 +- lib/sanitizer_common/sanitizer_atomic.h | 16 + lib/sanitizer_common/sanitizer_common.cc | 190 +++++- lib/sanitizer_common/sanitizer_common.h | 79 ++- .../sanitizer_common_interceptors.inc | 684 ++++++++++++++----- .../sanitizer_common_interceptors_format.inc | 19 +- .../sanitizer_common_interceptors_ioctl.inc | 4 +- lib/sanitizer_common/sanitizer_common_libcdep.cc | 27 +- lib/sanitizer_common/sanitizer_common_nolibc.cc | 26 + lib/sanitizer_common/sanitizer_common_syscalls.inc | 4 +- lib/sanitizer_common/sanitizer_coverage_libcdep.cc | 45 +- .../sanitizer_coverage_mapping_libcdep.cc | 4 +- .../sanitizer_deadlock_detector1.cc | 8 +- .../sanitizer_deadlock_detector_interface.h | 6 +- lib/sanitizer_common/sanitizer_flag_parser.cc | 18 + lib/sanitizer_common/sanitizer_flag_parser.h | 1 + lib/sanitizer_common/sanitizer_flags.cc | 51 +- lib/sanitizer_common/sanitizer_flags.h | 2 +- lib/sanitizer_common/sanitizer_flags.inc | 26 +- .../sanitizer_interface_internal.h | 5 +- lib/sanitizer_common/sanitizer_internal_defs.h | 13 +- lib/sanitizer_common/sanitizer_lfstack.h | 8 +- lib/sanitizer_common/sanitizer_libc.cc | 46 +- lib/sanitizer_common/sanitizer_libc.h | 9 +- lib/sanitizer_common/sanitizer_libignore.cc | 15 +- lib/sanitizer_common/sanitizer_linux.cc | 237 +++++-- lib/sanitizer_common/sanitizer_linux.h | 3 +- lib/sanitizer_common/sanitizer_linux_libcdep.cc | 149 ++-- lib/sanitizer_common/sanitizer_list.h | 19 +- lib/sanitizer_common/sanitizer_mac.cc | 279 +++++++- lib/sanitizer_common/sanitizer_mac.h | 12 + lib/sanitizer_common/sanitizer_malloc_mac.inc | 329 +++++++++ .../sanitizer_persistent_allocator.h | 5 +- lib/sanitizer_common/sanitizer_platform.h | 24 +- .../sanitizer_platform_interceptors.h | 15 +- .../sanitizer_platform_limits_posix.cc | 115 +++- .../sanitizer_platform_limits_posix.h | 19 +- lib/sanitizer_common/sanitizer_posix.cc | 98 +-- lib/sanitizer_common/sanitizer_posix.h | 3 + lib/sanitizer_common/sanitizer_posix_libcdep.cc | 61 +- lib/sanitizer_common/sanitizer_printf.cc | 10 +- lib/sanitizer_common/sanitizer_procmaps_common.cc | 13 +- lib/sanitizer_common/sanitizer_procmaps_linux.cc | 6 +- lib/sanitizer_common/sanitizer_procmaps_mac.cc | 2 +- lib/sanitizer_common/sanitizer_quarantine.h | 6 +- lib/sanitizer_common/sanitizer_stackdepot.cc | 4 +- lib/sanitizer_common/sanitizer_stackdepot.h | 7 +- lib/sanitizer_common/sanitizer_stackdepotbase.h | 10 +- lib/sanitizer_common/sanitizer_stacktrace.cc | 13 +- lib/sanitizer_common/sanitizer_stacktrace.h | 6 +- .../sanitizer_stacktrace_printer.cc | 7 +- .../sanitizer_stoptheworld_linux_libcdep.cc | 102 +-- lib/sanitizer_common/sanitizer_suppressions.cc | 19 +- lib/sanitizer_common/sanitizer_suppressions.h | 6 +- .../sanitizer_symbolizer_internal.h | 62 +- .../sanitizer_symbolizer_libbacktrace.h | 1 + .../sanitizer_symbolizer_libcdep.cc | 241 +++++++ lib/sanitizer_common/sanitizer_symbolizer_mac.cc | 96 ++- .../sanitizer_symbolizer_posix_libcdep.cc | 319 +++++---- .../sanitizer_symbolizer_process_libcdep.cc | 229 ------- lib/sanitizer_common/sanitizer_symbolizer_win.cc | 141 +++- lib/sanitizer_common/sanitizer_symbolizer_win.h | 31 - .../sanitizer_syscall_linux_aarch64.inc | 138 ++++ lib/sanitizer_common/sanitizer_thread_registry.h | 8 +- lib/sanitizer_common/sanitizer_tls_get_addr.cc | 11 +- lib/sanitizer_common/sanitizer_win.cc | 177 ++++- lib/sanitizer_common/scripts/gen_dynamic_list.py | 2 +- lib/sanitizer_common/tests/CMakeLists.txt | 11 +- .../tests/sanitizer_allocator_test.cc | 4 +- .../tests/sanitizer_common_test.cc | 33 + lib/sanitizer_common/tests/sanitizer_libc_test.cc | 108 ++- lib/sanitizer_common/tests/sanitizer_linux_test.cc | 2 +- .../tests/sanitizer_stacktrace_test.cc | 2 +- .../tests/sanitizer_suppressions_test.cc | 5 +- lib/sanitizer_common/tests/sanitizer_test_main.cc | 2 + lib/tsan/.clang-format | 1 + lib/tsan/CMakeLists.txt | 153 +++-- lib/tsan/Makefile.old | 109 --- lib/tsan/analyze_libtsan.sh | 23 +- lib/tsan/check_analyze.sh | 20 +- lib/tsan/check_memcpy.sh | 31 - lib/tsan/dd/CMakeLists.txt | 18 +- lib/tsan/go/buildgo.sh | 4 +- lib/tsan/rtl/Makefile.old | 63 -- lib/tsan/rtl/tsan_clock.cc | 2 - lib/tsan/rtl/tsan_defs.h | 5 +- lib/tsan/rtl/tsan_dense_alloc.h | 2 +- lib/tsan/rtl/tsan_flags.cc | 15 +- lib/tsan/rtl/tsan_flags.inc | 1 - lib/tsan/rtl/tsan_interceptors.cc | 456 ++++++++----- lib/tsan/rtl/tsan_interceptors.h | 20 + lib/tsan/rtl/tsan_interceptors_mac.cc | 91 +++ lib/tsan/rtl/tsan_interface_ann.cc | 34 +- lib/tsan/rtl/tsan_libdispatch_mac.cc | 284 ++++++++ lib/tsan/rtl/tsan_malloc_mac.cc | 65 ++ lib/tsan/rtl/tsan_mman.cc | 16 +- lib/tsan/rtl/tsan_mman.h | 1 + lib/tsan/rtl/tsan_mutex.cc | 2 + lib/tsan/rtl/tsan_mutex.h | 2 + lib/tsan/rtl/tsan_new_delete.cc | 16 +- lib/tsan/rtl/tsan_platform.h | 753 +++++++++++++++++---- lib/tsan/rtl/tsan_platform_linux.cc | 132 ++-- lib/tsan/rtl/tsan_platform_mac.cc | 128 +++- lib/tsan/rtl/tsan_platform_posix.cc | 151 +++++ lib/tsan/rtl/tsan_platform_windows.cc | 3 + lib/tsan/rtl/tsan_ppc_regs.h | 96 +++ lib/tsan/rtl/tsan_report.cc | 32 +- lib/tsan/rtl/tsan_rtl.cc | 30 +- lib/tsan/rtl/tsan_rtl.h | 28 +- lib/tsan/rtl/tsan_rtl_aarch64.S | 206 ++++++ lib/tsan/rtl/tsan_rtl_amd64.S | 99 ++- lib/tsan/rtl/tsan_rtl_mutex.cc | 2 +- lib/tsan/rtl/tsan_rtl_ppc64.S | 288 ++++++++ lib/tsan/rtl/tsan_rtl_report.cc | 189 +++--- lib/tsan/rtl/tsan_rtl_thread.cc | 8 +- lib/tsan/rtl/tsan_stat.cc | 3 +- lib/tsan/rtl/tsan_stat.h | 3 +- lib/tsan/rtl/tsan_suppressions.cc | 13 +- lib/tsan/rtl/tsan_symbolize.cc | 10 +- lib/tsan/rtl/tsan_sync.h | 6 +- lib/tsan/tests/CMakeLists.txt | 50 +- lib/tsan/tests/rtl/CMakeLists.txt | 4 +- lib/tsan/tests/rtl/tsan_posix.cc | 21 +- lib/tsan/tests/rtl/tsan_test.cc | 7 + lib/tsan/tests/rtl/tsan_test_util.h | 10 +- lib/tsan/tests/rtl/tsan_test_util_linux.cc | 470 ------------- lib/tsan/tests/rtl/tsan_test_util_posix.cc | 523 ++++++++++++++ lib/tsan/tests/unit/tsan_clock_test.cc | 7 +- lib/tsan/tests/unit/tsan_flags_test.cc | 6 - lib/tsan/tests/unit/tsan_mman_test.cc | 4 +- lib/ubsan/CMakeLists.txt | 68 +- lib/ubsan/ubsan_checks.inc | 45 ++ lib/ubsan/ubsan_diag.cc | 74 +- lib/ubsan/ubsan_diag.h | 24 +- lib/ubsan/ubsan_flags.cc | 3 + lib/ubsan/ubsan_flags.inc | 3 +- lib/ubsan/ubsan_handlers.cc | 299 +++++--- lib/ubsan/ubsan_handlers.h | 22 +- lib/ubsan/ubsan_handlers_cxx.cc | 29 +- make/platform/clang_darwin.mk | 85 +-- make/platform/clang_darwin_test_input.c | 9 + make/platform/clang_linux.mk | 3 +- make/platform/clang_mingw.mk | 30 + test/CMakeLists.txt | 9 +- test/asan/CMakeLists.txt | 24 +- test/asan/TestCases/Android/coverage-android.cc | 12 +- test/asan/TestCases/Darwin/abort_on_error.cc | 17 + .../Darwin/atos-symbolizer-dyld-root-path.cc | 11 +- test/asan/TestCases/Darwin/atos-symbolizer.cc | 4 +- test/asan/TestCases/Darwin/crashlog-stacktraces.c | 5 + test/asan/TestCases/Darwin/dladdr-demangling.cc | 4 +- .../Darwin/dyld_insert_libraries_reexec.cc | 13 +- .../TestCases/Darwin/interface_symbols_darwin.c | 22 +- test/asan/TestCases/Darwin/suppressions-darwin.cc | 8 +- test/asan/TestCases/Darwin/suppressions-sandbox.cc | 2 +- .../Helpers/init-order-pthread-create-extra.cc | 2 - test/asan/TestCases/Linux/abort_on_error.cc | 18 + test/asan/TestCases/Linux/activation-options.cc | 71 ++ test/asan/TestCases/Linux/asan_prelink_test.cc | 2 +- test/asan/TestCases/Linux/calloc-preload.c | 36 + test/asan/TestCases/Linux/coverage-missing.cc | 12 +- test/asan/TestCases/Linux/init-order-dlopen.cc | 2 +- test/asan/TestCases/Linux/init_fini_sections.cc | 24 + .../Linux/initialization-bug-any-order.cc | 4 +- .../asan/TestCases/Linux/interface_symbols_linux.c | 14 +- test/asan/TestCases/Linux/kernel-area.cc | 6 +- test/asan/TestCases/Linux/leak.cc | 6 +- test/asan/TestCases/Linux/malloc-in-qsort.cc | 4 +- .../asan/TestCases/Linux/malloc_delete_mismatch.cc | 8 +- test/asan/TestCases/Linux/mincore.cc | 34 + test/asan/TestCases/Linux/nohugepage_test.cc | 4 +- test/asan/TestCases/Linux/odr-violation.cc | 18 +- test/asan/TestCases/Linux/overflow-in-qsort.cc | 4 +- .../asan/TestCases/Linux/pthread_create_version.cc | 23 + test/asan/TestCases/Linux/ptrace.cc | 93 ++- test/asan/TestCases/Linux/quarantine_size_mb.cc | 10 +- .../TestCases/Linux/read_binary_name_regtest.c | 4 + test/asan/TestCases/Linux/sized_delete_test.cc | 8 +- test/asan/TestCases/Linux/stack-overflow-sigbus.cc | 2 +- test/asan/TestCases/Linux/stack-trace-dlclose.cc | 2 +- test/asan/TestCases/Linux/static_tls.cc | 4 +- test/asan/TestCases/Linux/stress_dtls.c | 7 +- test/asan/TestCases/Posix/allow_user_segv.cc | 6 +- .../TestCases/Posix/asan-symbolize-bad-path.cc | 4 + .../TestCases/Posix/asan-symbolize-sanity-test.cc | 2 +- .../Posix/assign_large_valloc_to_global.cc | 7 +- test/asan/TestCases/Posix/closed-fds.cc | 33 + .../asan/TestCases/Posix/coverage-caller-callee.cc | 75 ++ .../TestCases/Posix/coverage-direct-activation.cc | 6 +- test/asan/TestCases/Posix/coverage-direct-large.cc | 4 +- test/asan/TestCases/Posix/coverage-direct.cc | 12 +- test/asan/TestCases/Posix/coverage-fork-direct.cc | 2 +- test/asan/TestCases/Posix/coverage-fork.cc | 3 +- .../TestCases/Posix/coverage-maybe-open-file.cc | 32 + .../TestCases/Posix/coverage-module-unloaded.cc | 5 +- test/asan/TestCases/Posix/coverage-sandboxing.cc | 13 +- test/asan/TestCases/Posix/coverage.cc | 13 +- .../TestCases/Posix/current_allocated_bytes.cc | 44 ++ test/asan/TestCases/Posix/deep_call_stack.cc | 25 + test/asan/TestCases/Posix/deep_thread_stack.cc | 58 ++ test/asan/TestCases/Posix/dlclose-test.cc | 106 +++ test/asan/TestCases/Posix/free_hook_realloc.cc | 34 + test/asan/TestCases/Posix/freopen.cc | 15 + test/asan/TestCases/Posix/gc-test.cc | 54 ++ test/asan/TestCases/Posix/halt_on_error-signals.c | 102 +++ test/asan/TestCases/Posix/halt_on_error-torture.cc | 87 +++ .../Posix/halt_on_error_suppress_equal_pcs.cc | 55 ++ .../TestCases/Posix/init-order-pthread-create.cc | 54 ++ test/asan/TestCases/Posix/ioctl.cc | 4 +- .../Posix/large_allocator_unpoisons_on_free.cc | 2 +- .../TestCases/Posix/log_path_fork_test.cc.disabled | 2 +- test/asan/TestCases/Posix/new_array_cookie_test.cc | 4 +- .../TestCases/Posix/new_array_cookie_uaf_test.cc | 4 +- .../Posix/new_array_cookie_with_new_from_class.cc | 3 +- test/asan/TestCases/Posix/stack-overflow.cc | 114 ++++ .../asan/TestCases/Posix/stack-use-after-return.cc | 79 +++ test/asan/TestCases/Posix/start-deactivated.cc | 10 +- test/asan/TestCases/Posix/tsd_dtor_leak.cc | 2 +- test/asan/TestCases/Posix/wait.cc | 12 - test/asan/TestCases/Posix/wait3.cc | 36 + test/asan/TestCases/Windows/bitfield_uaf.cc | 2 +- test/asan/TestCases/Windows/coverage-basic.cc | 2 +- test/asan/TestCases/Windows/demangled_names.cc | 8 +- test/asan/TestCases/Windows/dll_control_c.cc | 130 ++++ test/asan/TestCases/Windows/dll_noreturn.cc | 8 +- test/asan/TestCases/Windows/dll_poison_unpoison.cc | 6 +- .../dll_report_globals_symbolization_at_startup.cc | 2 +- .../Windows/dll_stack_use_after_return.cc | 6 +- .../Windows/dll_thread_stack_array_left_oob.cc | 8 +- test/asan/TestCases/Windows/fuse-lld.cc | 23 + test/asan/TestCases/Windows/intercept_strdup.cc | 5 +- test/asan/TestCases/Windows/null_deref.cc | 2 +- .../Windows/operator_delete_wrong_argument.cc | 2 +- .../TestCases/Windows/operator_new_left_oob.cc | 2 +- .../TestCases/Windows/operator_new_right_oob.cc | 2 +- test/asan/TestCases/Windows/operator_new_uaf.cc | 4 +- .../Windows/queue_user_work_item_report.cc | 2 +- .../Windows/report_after_syminitialize.cc | 6 +- .../TestCases/Windows/report_globals_reload_dll.cc | 2 +- .../Windows/report_globals_vs_freelibrary.cc | 2 +- test/asan/TestCases/Windows/seh.cc | 20 +- .../TestCases/Windows/shadow_mapping_failure.cc | 1 - .../TestCases/Windows/stack_use_after_return.cc | 4 +- test/asan/TestCases/Windows/symbols_path.cc | 2 +- .../Windows/thread_stack_array_left_oob.cc | 2 +- .../Windows/thread_stack_array_right_oob.cc | 2 +- test/asan/TestCases/Windows/unsymbolized.cc | 25 + test/asan/TestCases/alloca_loop_unpoisoning.cc | 7 +- test/asan/TestCases/alloca_vla_interact.cc | 8 +- test/asan/TestCases/allocator_returns_null.cc | 23 +- test/asan/TestCases/asan_and_llvm_coverage_test.cc | 4 +- test/asan/TestCases/asan_options-help.cc | 2 +- test/asan/TestCases/atexit_stats.cc | 2 +- test/asan/TestCases/atoi_strict.c | 12 +- test/asan/TestCases/atol_strict.c | 12 +- test/asan/TestCases/atoll_strict.c | 15 +- test/asan/TestCases/closed-fds.cc | 33 - test/asan/TestCases/contiguous_container.cc | 14 +- test/asan/TestCases/contiguous_container_crash.cc | 2 +- test/asan/TestCases/coverage-and-lsan.cc | 2 +- .../coverage-caller-callee-total-count.cc | 7 +- test/asan/TestCases/coverage-caller-callee.cc | 74 -- test/asan/TestCases/coverage-disabled.cc | 4 +- test/asan/TestCases/coverage-levels.cc | 18 +- test/asan/TestCases/coverage-maybe-open-file.cc | 32 - test/asan/TestCases/coverage-order-pcs.cc | 9 +- test/asan/TestCases/coverage-reset.cc | 6 +- test/asan/TestCases/coverage-tracing.cc | 17 +- test/asan/TestCases/current_allocated_bytes.cc | 44 -- test/asan/TestCases/debug_mapping.cc | 2 +- test/asan/TestCases/debug_ppc64_mapping.cc | 4 +- test/asan/TestCases/debug_report.cc | 23 +- test/asan/TestCases/debug_stacks.cc | 3 + test/asan/TestCases/deep_call_stack.cc | 26 - test/asan/TestCases/deep_stack_uaf.cc | 2 +- test/asan/TestCases/deep_thread_stack.cc | 58 -- test/asan/TestCases/dlclose-test.cc | 106 --- test/asan/TestCases/double-free.cc | 4 +- test/asan/TestCases/dump_instruction_bytes.cc | 2 +- test/asan/TestCases/free_hook_realloc.cc | 34 - test/asan/TestCases/gc-test.cc | 54 -- test/asan/TestCases/halt_on_error-1.c | 29 + test/asan/TestCases/heap-overflow.cc | 2 +- test/asan/TestCases/heavy_uar_test.cc | 13 +- test/asan/TestCases/init-order-atexit.cc | 2 +- test/asan/TestCases/init-order-pthread-create.cc | 43 -- test/asan/TestCases/initialization-blacklist.cc | 6 +- test/asan/TestCases/initialization-bug.cc | 4 +- test/asan/TestCases/initialization-constexpr.cc | 8 +- test/asan/TestCases/initialization-nobug.cc | 8 +- test/asan/TestCases/interception_failure_test.cc | 3 +- test/asan/TestCases/invalid-free.cc | 4 +- test/asan/TestCases/log-path_test.cc | 11 +- test/asan/TestCases/malloc_context_size.cc | 10 +- test/asan/TestCases/malloc_fill.cc | 4 +- test/asan/TestCases/max_redzone.cc | 4 +- test/asan/TestCases/memcmp_strict_test.cc | 4 +- test/asan/TestCases/mmap_limit_mb.cc | 12 +- test/asan/TestCases/null_deref.cc | 9 +- test/asan/TestCases/on_error_callback.cc | 3 +- test/asan/TestCases/poison_partial.cc | 4 +- test/asan/TestCases/print_summary.cc | 4 +- test/asan/TestCases/printf-1.c | 4 +- test/asan/TestCases/printf-2.c | 6 +- test/asan/TestCases/printf-3.c | 8 +- test/asan/TestCases/printf-4.c | 4 +- test/asan/TestCases/printf-5.c | 6 +- test/asan/TestCases/sleep_before_dying.c | 2 +- test/asan/TestCases/speculative_load.cc | 50 ++ test/asan/TestCases/speculative_load2.cc | 24 + test/asan/TestCases/stack-oob-frames.cc | 3 + test/asan/TestCases/stack-overflow.cc | 114 ---- test/asan/TestCases/stack-use-after-return.cc | 80 --- test/asan/TestCases/strcasestr-1.c | 13 +- test/asan/TestCases/strcasestr-2.c | 11 +- test/asan/TestCases/strcasestr_strict.c | 4 +- test/asan/TestCases/strcat_strict.c | 8 +- test/asan/TestCases/strchr_strict.c | 4 +- test/asan/TestCases/strcmp_strict.c | 4 +- test/asan/TestCases/strcspn-1.c | 11 +- test/asan/TestCases/strcspn-2.c | 11 +- test/asan/TestCases/strcspn_strict.c | 4 +- test/asan/TestCases/strip_path_prefix.c | 4 +- test/asan/TestCases/strncat_strict.c | 8 +- test/asan/TestCases/strpbrk-1.c | 11 +- test/asan/TestCases/strpbrk-2.c | 11 +- test/asan/TestCases/strpbrk_strict.c | 4 +- test/asan/TestCases/strspn-1.c | 11 +- test/asan/TestCases/strspn-2.c | 11 +- test/asan/TestCases/strspn_strict.c | 4 +- test/asan/TestCases/strstr-1.c | 11 +- test/asan/TestCases/strstr-2.c | 11 +- test/asan/TestCases/strstr_strict.c | 4 +- test/asan/TestCases/strtol_strict.c | 49 +- test/asan/TestCases/strtoll_strict.c | 33 +- .../suppressions-exec-relative-location.cc | 6 +- test/asan/TestCases/suppressions-function.cc | 7 +- test/asan/TestCases/suppressions-interceptor.cc | 2 +- test/asan/TestCases/suppressions-library.cc | 5 +- test/asan/TestCases/throw_call_test.cc | 7 +- test/asan/TestCases/uar_and_exceptions.cc | 4 +- test/asan/TestCases/use-after-poison.cc | 2 +- test/asan/TestCases/use-after-scope.cc | 2 +- test/asan/TestCases/verbose-log-path_test.cc | 5 +- test/asan/TestCases/zero_page_pc.cc | 2 +- test/asan/android_commands/android_run.py | 7 +- test/asan/lit.cfg | 39 +- test/builtins/Unit/arm/aeabi_cdcmpeq_test.c | 70 ++ test/builtins/Unit/arm/aeabi_cdcmple_test.c | 92 +++ test/builtins/Unit/arm/aeabi_cfcmpeq_test.c | 70 ++ test/builtins/Unit/arm/aeabi_cfcmple_test.c | 92 +++ test/builtins/Unit/arm/aeabi_drsub_test.c | 47 ++ test/builtins/Unit/arm/aeabi_frsub_test.c | 47 ++ test/builtins/Unit/arm/call_apsr.S | 43 ++ test/builtins/Unit/arm/call_apsr.h | 39 ++ test/builtins/Unit/divtc3_test.c | 13 +- test/builtins/Unit/fixtfdi_test.c | 71 ++ test/builtins/Unit/fixtfsi_test.c | 2 +- test/builtins/Unit/fixtfti_test.c | 83 +++ test/builtins/Unit/fixunsdfdi_test.c | 3 + test/builtins/Unit/fixunsdfsi_test.c | 2 + test/builtins/Unit/fixunsdfti_test.c | 3 + test/builtins/Unit/fixunssfdi_test.c | 2 + test/builtins/Unit/fixunssfsi_test.c | 2 + test/builtins/Unit/fixunstfdi_test.c | 8 +- test/builtins/Unit/fixunstfsi_test.c | 3 + test/builtins/Unit/fixunstfti_test.c | 103 +++ test/builtins/Unit/floatditf_test.c | 69 ++ test/builtins/Unit/floatsitf_test.c | 2 + test/builtins/Unit/floatunditf_test.c | 67 ++ test/builtins/Unit/multc3_test.c | 4 +- test/builtins/Unit/multf3_test.c | 2 +- test/cfi/CMakeLists.txt | 9 +- test/cfi/anon-namespace.cpp | 15 +- test/cfi/bad-cast.cpp | 15 +- test/cfi/base-derived-destructor.cpp | 93 +++ test/cfi/create-derivers.test | 20 + test/cfi/cross-dso/icall/icall-from-dso.cpp | 26 + test/cfi/cross-dso/icall/icall.cpp | 21 + test/cfi/cross-dso/icall/lit.local.cfg | 3 + test/cfi/cross-dso/lit.local.cfg | 9 + test/cfi/cross-dso/simple-fail.cpp | 92 +++ test/cfi/cross-dso/simple-pass.cpp | 65 ++ test/cfi/icall/bad-signature.c | 27 + test/cfi/icall/external-call.c | 27 + test/cfi/icall/lit.local.cfg | 3 + test/cfi/lit.cfg | 7 +- test/cfi/multiple-inheritance.cpp | 22 +- test/cfi/nvcall.cpp | 15 +- test/cfi/overwrite.cpp | 15 +- test/cfi/sibling.cpp | 15 +- test/cfi/simple-fail.cpp | 15 +- test/cfi/utils.h | 94 +-- test/cfi/vdtor.cpp | 15 +- test/lit.common.cfg | 37 +- test/lit.common.configured.in | 7 +- test/lsan/TestCases/cleanup_in_tsd_destructor.c | 45 ++ test/lsan/TestCases/cleanup_in_tsd_destructor.cc | 45 -- test/lsan/TestCases/disabler.c | 24 + test/lsan/TestCases/disabler.cc | 10 +- test/lsan/TestCases/disabler_in_tsd_destructor.c | 39 ++ test/lsan/TestCases/disabler_in_tsd_destructor.cc | 38 -- test/lsan/TestCases/ignore_object.c | 23 + test/lsan/TestCases/ignore_object.cc | 23 - test/lsan/TestCases/suppressions_file.cc | 6 + test/msan/Linux/forkpty.cc | 18 + test/msan/Linux/mallinfo.cc | 1 + test/msan/Linux/mincore.cc | 36 + test/msan/Linux/process_vm_readv.cc | 67 ++ test/msan/allocator_mapping.cc | 36 + test/msan/ctermid.cc | 13 + test/msan/dlerror.cc | 4 + test/msan/dlopen_executable.cc | 17 + test/msan/dtor-base-access.cc | 49 ++ test/msan/dtor-bit-fields.cc | 70 ++ test/msan/dtor-derived-class.cc | 39 ++ test/msan/dtor-member.cc | 48 ++ ...ultiple-inheritance-nontrivial-class-members.cc | 152 +++++ test/msan/dtor-multiple-inheritance.cc | 98 +++ test/msan/dtor-trivial-class-members.cc | 55 ++ test/msan/dtor-trivial.cpp | 41 ++ test/msan/dtor-vtable-multiple-inheritance.cc | 72 ++ test/msan/dtor-vtable.cc | 68 ++ test/msan/icmp_slt_allones.cc | 20 + test/msan/insertvalue_origin.cc | 1 + test/msan/memcmp_test.cc | 15 + test/msan/mmap.cc | 30 +- test/msan/mmap_below_shadow.cc | 3 + test/msan/msan_copy_shadow.cc | 34 + test/msan/param_tls_limit.cc | 4 + test/msan/pthread_setcancelstate.cc | 19 + test/msan/sem_getvalue.cc | 22 + test/msan/signal_stress_test.cc | 2 +- test/msan/strlen_of_shadow.cc | 6 +- test/msan/test.h | 15 + test/msan/use-after-dtor.cc | 45 ++ test/profile/Inputs/instrprof-shared-lib.c | 9 + test/profile/Inputs/instrprof-shared-main.c | 13 + test/profile/instrprof-bufferio.c | 128 ++++ test/profile/instrprof-error.c | 12 + test/profile/instrprof-shared.test | 75 ++ test/profile/instrprof-value-prof-2.c | 135 ++++ test/profile/instrprof-value-prof.c | 253 +++++++ test/profile/instrprof-without-libc.c | 6 + test/safestack/lit.cfg | 5 + test/safestack/overflow.c | 2 + test/sanitizer_common/CMakeLists.txt | 7 +- .../TestCases/Darwin/abort_on_error.cc | 19 + .../TestCases/Darwin/lit.local.cfg | 9 + .../TestCases/Linux/abort_on_error.cc | 20 + test/sanitizer_common/TestCases/Linux/assert.cc | 4 +- test/sanitizer_common/TestCases/Linux/fpe.cc | 30 + test/sanitizer_common/TestCases/Linux/getpass.cc | 1 + .../TestCases/Linux/hard_rss_limit_mb_test.cc | 6 +- test/sanitizer_common/TestCases/Linux/ill.cc | 27 + .../TestCases/Linux/open_memstream.cc | 30 +- test/sanitizer_common/TestCases/Linux/ptrace.cc | 45 +- .../Linux/sanitizer_set_death_callback_test.cc | 23 +- .../TestCases/Linux/sem_init_glibc.cc | 32 + .../TestCases/Linux/soft_rss_limit_mb_test.cc | 6 +- .../TestCases/Posix/decorate_proc_maps.cc | 7 +- test/sanitizer_common/TestCases/fopen_nullptr.c | 6 + test/sanitizer_common/TestCases/options-help.cc | 2 +- test/sanitizer_common/TestCases/options-include.cc | 39 +- test/sanitizer_common/TestCases/options-invalid.cc | 4 +- .../TestCases/print-stack-trace.cc | 8 +- test/sanitizer_common/lit.common.cfg | 12 + test/tsan/CMakeLists.txt | 5 +- test/tsan/Darwin/gcd-async-norace.mm | 26 + test/tsan/Darwin/gcd-async-race.mm | 38 ++ test/tsan/Darwin/gcd-groups-norace.mm | 53 ++ test/tsan/Darwin/gcd-groups-stress.mm | 43 ++ test/tsan/Darwin/gcd-once.mm | 55 ++ test/tsan/Darwin/gcd-semaphore-norace.mm | 29 + test/tsan/Darwin/gcd-serial-queue-norace.mm | 40 ++ test/tsan/Darwin/gcd-sync-norace.mm | 32 + test/tsan/Darwin/gcd-sync-race.mm | 44 ++ test/tsan/Darwin/lit.local.cfg | 9 + test/tsan/Darwin/objc-race.mm | 55 ++ test/tsan/Darwin/objc-simple.mm | 13 + test/tsan/Darwin/osspinlock-norace.cc | 30 + test/tsan/Darwin/symbolizer-atos.cc | 26 + test/tsan/Darwin/symbolizer-dladdr.cc | 27 + test/tsan/Linux/check_memcpy.cc | 15 + test/tsan/allocator_returns_null.cc | 10 +- test/tsan/atomic_free3.cc | 28 + test/tsan/barrier.cc | 3 + test/tsan/bench_acquire_only.cc | 3 + test/tsan/bench_acquire_release.cc | 3 + test/tsan/bench_local_mutex.cc | 3 + test/tsan/bench_mutex.cc | 3 + test/tsan/bench_release_only.cc | 3 + test/tsan/bench_rwmutex.cc | 3 + test/tsan/bench_single_writer.cc | 3 + test/tsan/bench_ten_mutexes.cc | 3 + test/tsan/cond_cancel.c | 8 + test/tsan/cond_version.c | 3 + test/tsan/deadlock_detector_stress_test.cc | 34 +- test/tsan/dl_iterate_phdr.cc | 3 +- test/tsan/dlclose.cc | 4 +- test/tsan/fd_tid_recycled.cc | 54 ++ test/tsan/fork_atexit.cc | 3 +- test/tsan/fork_deadlock.cc | 3 +- test/tsan/fork_multithreaded.cc | 3 +- test/tsan/fork_multithreaded3.cc | 1 + test/tsan/free_race.c | 2 +- test/tsan/getline_nohang.cc | 2 +- test/tsan/global_race.cc | 6 +- test/tsan/global_race2.cc | 6 +- test/tsan/global_race3.cc | 6 +- test/tsan/halt_on_error.cc | 2 +- test/tsan/ignore_lib0.cc | 5 +- test/tsan/ignore_lib1.cc | 4 +- test/tsan/ignore_lib2.cc | 2 +- test/tsan/ignore_lib3.cc | 5 +- test/tsan/inlined_memcpy_race.cc | 2 +- test/tsan/java_race_pc.cc | 4 + test/tsan/lit.cfg | 28 +- test/tsan/load_shared_lib.cc | 2 +- test/tsan/malloc_overflow.cc | 2 +- test/tsan/map32bit.cc | 7 +- test/tsan/memcmp_race.cc | 42 ++ test/tsan/memcpy_race.cc | 6 +- test/tsan/mmap_large.cc | 6 +- test/tsan/mop_with_offset.cc | 4 +- test/tsan/mop_with_offset2.cc | 4 +- test/tsan/mutex_cycle2.c | 8 +- test/tsan/mutexset1.cc | 2 +- test/tsan/mutexset2.cc | 2 +- test/tsan/mutexset3.cc | 4 +- test/tsan/mutexset4.cc | 4 +- test/tsan/mutexset5.cc | 4 +- test/tsan/mutexset6.cc | 16 +- test/tsan/mutexset8.cc | 2 +- test/tsan/pie_test.cc | 12 + test/tsan/pthread_atfork_deadlock.c | 2 +- test/tsan/race_on_barrier.c | 4 + test/tsan/race_on_barrier2.c | 4 + test/tsan/race_on_heap.cc | 3 +- test/tsan/race_on_mutex.c | 7 +- test/tsan/race_on_speculative_load.cc | 2 +- test/tsan/race_stress.cc | 25 + test/tsan/race_top_suppression.cc | 2 +- test/tsan/race_top_suppression1.cc | 2 +- test/tsan/real_deadlock_detector_stress_test.cc | 9 +- test/tsan/setuid2.c | 12 +- test/tsan/signal_cond.cc | 14 +- test/tsan/signal_errno.cc | 6 +- test/tsan/signal_longjmp.cc | 14 +- test/tsan/signal_recursive.cc | 2 +- test/tsan/signal_reset.cc | 1 + test/tsan/signal_sync.cc | 1 + test/tsan/signal_thread.cc | 1 + test/tsan/stack_sync_reuse.cc | 8 +- test/tsan/suppressions_global.cc | 2 +- test/tsan/suppressions_race.cc | 2 +- test/tsan/suppressions_race2.cc | 2 +- test/tsan/test.h | 75 +- test/tsan/test_output.sh | 66 -- test/tsan/thread_name2.cc | 5 +- test/tsan/tls_race.cc | 6 +- test/tsan/tls_race2.cc | 7 +- test/tsan/vfork.cc | 1 + test/tsan/virtual_inheritance_compile_bug.cc | 2 +- test/tsan/vptr_benign_race.cc | 20 +- test/ubsan/CMakeLists.txt | 7 +- test/ubsan/TestCases/Float/cast-overflow.cpp | 28 +- test/ubsan/TestCases/Integer/summary.cpp | 7 +- test/ubsan/TestCases/Integer/suppressions.cpp | 41 ++ test/ubsan/TestCases/Misc/Linux/coverage-levels.cc | 39 -- test/ubsan/TestCases/Misc/Linux/ubsan_options.cc | 2 +- test/ubsan/TestCases/Misc/bool.cpp | 7 +- test/ubsan/TestCases/Misc/coverage-levels.cc | 41 ++ test/ubsan/TestCases/Misc/log-path_test.cc | 7 +- test/ubsan/TestCases/Misc/missing_return.cpp | 2 +- test/ubsan/TestCases/Misc/nonnull-arg.cpp | 11 +- .../TestCases/TypeCheck/Function/function.cpp | 2 +- test/ubsan/TestCases/TypeCheck/misaligned.cpp | 6 +- test/ubsan/TestCases/TypeCheck/vptr.cpp | 33 +- test/ubsan/lit.common.cfg | 19 +- 784 files changed, 20780 insertions(+), 6700 deletions(-) create mode 100644 cmake/Modules/CompilerRTDarwinUtils.cmake create mode 100644 lib/asan/.clang-format create mode 100644 lib/builtins/Darwin-excludes/10.4-x86_64.txt create mode 100644 lib/builtins/Darwin-excludes/10.4.txt create mode 100644 lib/builtins/Darwin-excludes/CMakeLists.txt create mode 100644 lib/builtins/Darwin-excludes/README.TXT create mode 100644 lib/builtins/Darwin-excludes/ios-armv7.txt create mode 100644 lib/builtins/Darwin-excludes/ios-armv7s.txt create mode 100644 lib/builtins/Darwin-excludes/ios.txt create mode 100644 lib/builtins/Darwin-excludes/ios6-armv7.txt create mode 100644 lib/builtins/Darwin-excludes/ios6-armv7s.txt create mode 100644 lib/builtins/Darwin-excludes/ios7-arm64.txt create mode 100644 lib/builtins/Darwin-excludes/iossim-i386.txt create mode 100644 lib/builtins/Darwin-excludes/iossim-x86_64.txt create mode 100644 lib/builtins/Darwin-excludes/iossim.txt create mode 100644 lib/builtins/Darwin-excludes/osx-i386.txt create mode 100644 lib/builtins/Darwin-excludes/osx-x86_64.txt create mode 100644 lib/builtins/Darwin-excludes/osx.txt create mode 100644 lib/builtins/arm/aeabi_cdcmp.S create mode 100644 lib/builtins/arm/aeabi_cdcmpeq_check_nan.c create mode 100644 lib/builtins/arm/aeabi_cfcmp.S create mode 100644 lib/builtins/arm/aeabi_cfcmpeq_check_nan.c create mode 100644 lib/builtins/arm/aeabi_drsub.c create mode 100644 lib/builtins/arm/aeabi_frsub.c create mode 100644 lib/builtins/divtc3.c create mode 100644 lib/builtins/emutls.c create mode 100644 lib/builtins/floatditf.c create mode 100644 lib/builtins/floatunditf.c create mode 100644 lib/builtins/i386/chkstk2.S create mode 100644 lib/builtins/macho_embedded/CMakeLists.txt create mode 100644 lib/builtins/macho_embedded/arm.txt create mode 100644 lib/builtins/macho_embedded/common.txt create mode 100644 lib/builtins/macho_embedded/i386.txt create mode 100644 lib/builtins/macho_embedded/thumb2-64.txt create mode 100644 lib/builtins/macho_embedded/thumb2.txt create mode 100644 lib/builtins/multc3.c create mode 100644 lib/builtins/x86_64/chkstk2.S create mode 100644 lib/cfi/CMakeLists.txt create mode 100644 lib/cfi/cfi.cc create mode 100644 lib/cfi/cfi_blacklist.txt create mode 100644 lib/dfsan/.clang-format create mode 100644 lib/dfsan/dfsan_platform.h create mode 100644 lib/interception/.clang-format create mode 100644 lib/lsan/.clang-format create mode 100644 lib/msan/.clang-format create mode 100644 lib/profile/InstrProfData.inc create mode 100644 lib/profile/InstrProfilingPlatformLinux.c create mode 100644 lib/profile/InstrProfilingPort.h create mode 100644 lib/profile/InstrProfilingValue.c create mode 100644 lib/profile/InstrProfilingWriter.c create mode 100644 lib/safestack/.clang-format create mode 100644 lib/sanitizer_common/.clang-format create mode 100644 lib/sanitizer_common/sanitizer_common_nolibc.cc create mode 100644 lib/sanitizer_common/sanitizer_malloc_mac.inc delete mode 100644 lib/sanitizer_common/sanitizer_symbolizer_process_libcdep.cc delete mode 100644 lib/sanitizer_common/sanitizer_symbolizer_win.h create mode 100644 lib/sanitizer_common/sanitizer_syscall_linux_aarch64.inc create mode 100644 lib/tsan/.clang-format delete mode 100644 lib/tsan/Makefile.old delete mode 100755 lib/tsan/check_memcpy.sh delete mode 100644 lib/tsan/rtl/Makefile.old create mode 100644 lib/tsan/rtl/tsan_interceptors_mac.cc create mode 100644 lib/tsan/rtl/tsan_libdispatch_mac.cc create mode 100644 lib/tsan/rtl/tsan_malloc_mac.cc create mode 100644 lib/tsan/rtl/tsan_platform_posix.cc create mode 100644 lib/tsan/rtl/tsan_ppc_regs.h create mode 100644 lib/tsan/rtl/tsan_rtl_aarch64.S create mode 100644 lib/tsan/rtl/tsan_rtl_ppc64.S delete mode 100644 lib/tsan/tests/rtl/tsan_test_util_linux.cc create mode 100644 lib/tsan/tests/rtl/tsan_test_util_posix.cc create mode 100644 lib/ubsan/ubsan_checks.inc create mode 100644 make/platform/clang_mingw.mk create mode 100644 test/asan/TestCases/Darwin/abort_on_error.cc delete mode 100644 test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc create mode 100644 test/asan/TestCases/Linux/abort_on_error.cc create mode 100644 test/asan/TestCases/Linux/activation-options.cc create mode 100644 test/asan/TestCases/Linux/calloc-preload.c create mode 100644 test/asan/TestCases/Linux/init_fini_sections.cc create mode 100644 test/asan/TestCases/Linux/mincore.cc create mode 100644 test/asan/TestCases/Linux/pthread_create_version.cc create mode 100644 test/asan/TestCases/Posix/asan-symbolize-bad-path.cc create mode 100644 test/asan/TestCases/Posix/closed-fds.cc create mode 100644 test/asan/TestCases/Posix/coverage-caller-callee.cc create mode 100644 test/asan/TestCases/Posix/coverage-maybe-open-file.cc create mode 100644 test/asan/TestCases/Posix/current_allocated_bytes.cc create mode 100644 test/asan/TestCases/Posix/deep_call_stack.cc create mode 100644 test/asan/TestCases/Posix/deep_thread_stack.cc create mode 100644 test/asan/TestCases/Posix/dlclose-test.cc create mode 100644 test/asan/TestCases/Posix/free_hook_realloc.cc create mode 100644 test/asan/TestCases/Posix/freopen.cc create mode 100644 test/asan/TestCases/Posix/gc-test.cc create mode 100644 test/asan/TestCases/Posix/halt_on_error-signals.c create mode 100644 test/asan/TestCases/Posix/halt_on_error-torture.cc create mode 100644 test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc create mode 100644 test/asan/TestCases/Posix/init-order-pthread-create.cc create mode 100644 test/asan/TestCases/Posix/stack-overflow.cc create mode 100644 test/asan/TestCases/Posix/stack-use-after-return.cc create mode 100644 test/asan/TestCases/Posix/wait3.cc create mode 100644 test/asan/TestCases/Windows/dll_control_c.cc create mode 100644 test/asan/TestCases/Windows/fuse-lld.cc create mode 100644 test/asan/TestCases/Windows/unsymbolized.cc delete mode 100644 test/asan/TestCases/closed-fds.cc delete mode 100644 test/asan/TestCases/coverage-caller-callee.cc delete mode 100644 test/asan/TestCases/coverage-maybe-open-file.cc delete mode 100644 test/asan/TestCases/current_allocated_bytes.cc delete mode 100644 test/asan/TestCases/deep_call_stack.cc delete mode 100644 test/asan/TestCases/deep_thread_stack.cc delete mode 100644 test/asan/TestCases/dlclose-test.cc delete mode 100644 test/asan/TestCases/free_hook_realloc.cc delete mode 100644 test/asan/TestCases/gc-test.cc create mode 100644 test/asan/TestCases/halt_on_error-1.c delete mode 100644 test/asan/TestCases/init-order-pthread-create.cc create mode 100644 test/asan/TestCases/speculative_load.cc create mode 100644 test/asan/TestCases/speculative_load2.cc delete mode 100644 test/asan/TestCases/stack-overflow.cc delete mode 100644 test/asan/TestCases/stack-use-after-return.cc create mode 100644 test/builtins/Unit/arm/aeabi_cdcmpeq_test.c create mode 100644 test/builtins/Unit/arm/aeabi_cdcmple_test.c create mode 100644 test/builtins/Unit/arm/aeabi_cfcmpeq_test.c create mode 100644 test/builtins/Unit/arm/aeabi_cfcmple_test.c create mode 100644 test/builtins/Unit/arm/aeabi_drsub_test.c create mode 100644 test/builtins/Unit/arm/aeabi_frsub_test.c create mode 100644 test/builtins/Unit/arm/call_apsr.S create mode 100644 test/builtins/Unit/arm/call_apsr.h create mode 100644 test/builtins/Unit/fixtfdi_test.c create mode 100644 test/builtins/Unit/fixtfti_test.c create mode 100644 test/builtins/Unit/fixunstfti_test.c create mode 100644 test/builtins/Unit/floatditf_test.c create mode 100644 test/builtins/Unit/floatunditf_test.c create mode 100644 test/cfi/base-derived-destructor.cpp create mode 100644 test/cfi/create-derivers.test create mode 100644 test/cfi/cross-dso/icall/icall-from-dso.cpp create mode 100644 test/cfi/cross-dso/icall/icall.cpp create mode 100644 test/cfi/cross-dso/icall/lit.local.cfg create mode 100644 test/cfi/cross-dso/lit.local.cfg create mode 100644 test/cfi/cross-dso/simple-fail.cpp create mode 100644 test/cfi/cross-dso/simple-pass.cpp create mode 100644 test/cfi/icall/bad-signature.c create mode 100644 test/cfi/icall/external-call.c create mode 100644 test/cfi/icall/lit.local.cfg create mode 100644 test/lsan/TestCases/cleanup_in_tsd_destructor.c delete mode 100644 test/lsan/TestCases/cleanup_in_tsd_destructor.cc create mode 100644 test/lsan/TestCases/disabler.c create mode 100644 test/lsan/TestCases/disabler_in_tsd_destructor.c delete mode 100644 test/lsan/TestCases/disabler_in_tsd_destructor.cc create mode 100644 test/lsan/TestCases/ignore_object.c delete mode 100644 test/lsan/TestCases/ignore_object.cc create mode 100644 test/msan/Linux/forkpty.cc create mode 100644 test/msan/Linux/mincore.cc create mode 100644 test/msan/Linux/process_vm_readv.cc create mode 100644 test/msan/allocator_mapping.cc create mode 100644 test/msan/ctermid.cc create mode 100644 test/msan/dlopen_executable.cc create mode 100644 test/msan/dtor-base-access.cc create mode 100644 test/msan/dtor-bit-fields.cc create mode 100644 test/msan/dtor-derived-class.cc create mode 100644 test/msan/dtor-member.cc create mode 100644 test/msan/dtor-multiple-inheritance-nontrivial-class-members.cc create mode 100644 test/msan/dtor-multiple-inheritance.cc create mode 100644 test/msan/dtor-trivial-class-members.cc create mode 100644 test/msan/dtor-trivial.cpp create mode 100644 test/msan/dtor-vtable-multiple-inheritance.cc create mode 100644 test/msan/dtor-vtable.cc create mode 100644 test/msan/icmp_slt_allones.cc create mode 100644 test/msan/memcmp_test.cc create mode 100644 test/msan/msan_copy_shadow.cc create mode 100644 test/msan/pthread_setcancelstate.cc create mode 100644 test/msan/sem_getvalue.cc create mode 100644 test/msan/test.h create mode 100644 test/msan/use-after-dtor.cc create mode 100644 test/profile/Inputs/instrprof-shared-lib.c create mode 100644 test/profile/Inputs/instrprof-shared-main.c create mode 100644 test/profile/instrprof-bufferio.c create mode 100644 test/profile/instrprof-error.c create mode 100644 test/profile/instrprof-shared.test create mode 100644 test/profile/instrprof-value-prof-2.c create mode 100644 test/profile/instrprof-value-prof.c create mode 100644 test/sanitizer_common/TestCases/Darwin/abort_on_error.cc create mode 100644 test/sanitizer_common/TestCases/Darwin/lit.local.cfg create mode 100644 test/sanitizer_common/TestCases/Linux/abort_on_error.cc create mode 100644 test/sanitizer_common/TestCases/Linux/fpe.cc create mode 100644 test/sanitizer_common/TestCases/Linux/ill.cc create mode 100644 test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc create mode 100644 test/sanitizer_common/TestCases/fopen_nullptr.c create mode 100644 test/tsan/Darwin/gcd-async-norace.mm create mode 100644 test/tsan/Darwin/gcd-async-race.mm create mode 100644 test/tsan/Darwin/gcd-groups-norace.mm create mode 100644 test/tsan/Darwin/gcd-groups-stress.mm create mode 100644 test/tsan/Darwin/gcd-once.mm create mode 100644 test/tsan/Darwin/gcd-semaphore-norace.mm create mode 100644 test/tsan/Darwin/gcd-serial-queue-norace.mm create mode 100644 test/tsan/Darwin/gcd-sync-norace.mm create mode 100644 test/tsan/Darwin/gcd-sync-race.mm create mode 100644 test/tsan/Darwin/lit.local.cfg create mode 100644 test/tsan/Darwin/objc-race.mm create mode 100644 test/tsan/Darwin/objc-simple.mm create mode 100644 test/tsan/Darwin/osspinlock-norace.cc create mode 100644 test/tsan/Darwin/symbolizer-atos.cc create mode 100644 test/tsan/Darwin/symbolizer-dladdr.cc create mode 100644 test/tsan/Linux/check_memcpy.cc create mode 100644 test/tsan/atomic_free3.cc create mode 100644 test/tsan/fd_tid_recycled.cc create mode 100644 test/tsan/memcmp_race.cc create mode 100644 test/tsan/pie_test.cc create mode 100644 test/tsan/race_stress.cc delete mode 100755 test/tsan/test_output.sh create mode 100644 test/ubsan/TestCases/Integer/suppressions.cpp delete mode 100644 test/ubsan/TestCases/Misc/Linux/coverage-levels.cc create mode 100644 test/ubsan/TestCases/Misc/coverage-levels.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index cae5981b2b46..5f8b4d1bd269 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # Check if compiler-rt is built as a standalone project. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - project(CompilerRT C CXX) + project(CompilerRT C CXX ASM) set(COMPILER_RT_STANDALONE_BUILD TRUE) else() set(COMPILER_RT_STANDALONE_BUILD FALSE) @@ -22,7 +22,7 @@ endif() if (NOT MSVC) cmake_minimum_required(VERSION 2.8.8) else() - # Version 2.8.12.1 is required to build with Visual Studion 2013. + # Version 2.8.12.1 is required to build with Visual Studio 2013. cmake_minimum_required(VERSION 2.8.12.1) endif() @@ -43,6 +43,11 @@ endif() # Top level target used to build all compiler-rt libraries. add_custom_target(compiler-rt ALL) +option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) +mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) +option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) +mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) + if (NOT COMPILER_RT_STANDALONE_BUILD) # Compute the Clang version from the LLVM version. # FIXME: We should be able to reuse CLANG_VERSION variable calculated @@ -132,22 +137,27 @@ else() set(COMPILER_RT_TEST_COMPILER_ID GNU) endif() -# Tests using XFAIL use the first value in COMPILER_RT_TEST_TARGET_TRIPLE -set(COMPILER_RT_TEST_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING - "Default triple for cross-compiled executables") -string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_TEST_TARGET_TRIPLE}) -list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_TEST_TARGET_ARCH) -list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_TEST_TARGET_OS) -list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_TEST_TARGET_ABI) +set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING + "Default triple for which compiler-rt runtimes will be built.") +if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE) + # Backwards compatibility: this variable used to be called + # COMPILER_RT_TEST_TARGET_TRIPLE. + set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE}) +endif() + +string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) +list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH) +list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS) +list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI) # Determine if test target triple is specified explicitly, and doesn't match the # default. -if(NOT COMPILER_RT_TEST_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) - set(COMPILER_RT_HAS_EXPLICIT_TEST_TARGET_TRIPLE TRUE) +if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) + set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE) else() - set(COMPILER_RT_HAS_EXPLICIT_TEST_TARGET_TRIPLE FALSE) + set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE) endif() -if ("${COMPILER_RT_TEST_TARGET_ABI}" STREQUAL "androideabi") +if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi") set(ANDROID 1) endif() @@ -179,6 +189,8 @@ else() endif() option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF) +option(COMPILER_RT_EXTERNALIZE_DEBUGINFO + "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. pythonize_bool(COMPILER_RT_DEBUG) @@ -216,6 +228,7 @@ append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COM append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS) +append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS) @@ -250,8 +263,7 @@ endif() # FIXME: Fix all sanitizers and add -Wframe-larger-than to # SANITIZER_COMMON_FLAGS if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG - AND NOT ${LLVM_NATIVE_ARCH} STREQUAL "PowerPC" - AND NOT ${LLVM_NATIVE_ARCH} STREQUAL "Mips") + AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips") set(SANITIZER_LIMIT_FRAME_SIZE TRUE) else() set(SANITIZER_LIMIT_FRAME_SIZE FALSE) @@ -276,64 +288,6 @@ append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) -if(APPLE) - macro(find_darwin_sdk_dir var sdk_name) - # Let's first try the internal SDK, otherwise use the public SDK. - execute_process( - COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path - OUTPUT_VARIABLE ${var} - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_FILE /dev/null - ) - if(${var} STREQUAL "") - execute_process( - COMMAND xcodebuild -version -sdk ${sdk_name} Path - OUTPUT_VARIABLE ${var} - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_FILE /dev/null - ) - endif() - endmacro() - - find_darwin_sdk_dir(OSX_SDK_DIR macosx) - find_darwin_sdk_dir(IOSSIM_SDK_DIR iphonesimulator) - - set(SANITIZER_COMMON_SUPPORTED_OS osx) - string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)" - MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") - if(MACOSX_VERSION_MIN_FLAG) - set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}") - elseif(CMAKE_OSX_DEPLOYMENT_TARGET) - set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) - else() - set(SANITIZER_MIN_OSX_VERSION 10.9) - if(IOSSIM_SDK_DIR) - list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) - endif() - endif() - if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") - message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}") - endif() - - set(CMAKE_OSX_DEPLOYMENT_TARGET "") # We evaluate target OS X version above. - set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION} - -stdlib=libc++) - set(DARWIN_iossim_CFLAGS - -stdlib=libc++ - -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR}) - set(DARWIN_osx_LINKFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION} - -stdlib=libc++ -lc++ -lc++abi) - set(DARWIN_iossim_LINKFLAGS - -stdlib=libc++ -lc++ -lc++abi - -Wl,-ios_simulator_version_min,7.0.0 - -mios-simulator-version-min=7.0 - -isysroot ${IOSSIM_SDK_DIR}) - - if(OSX_SDK_DIR) - list(APPEND DARWIN_osx_CFLAGS -isysroot ${OSX_SDK_DIR}) - list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${OSX_SDK_DIR}) - endif() -endif() if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9") # Mac OS X prior to 10.9 had problems with exporting symbols from @@ -353,9 +307,17 @@ else() set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE) endif() +set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld) +if(EXISTS ${COMPILER_RT_LLD_PATH}/) + set(COMPILER_RT_HAS_LLD_SOURCES TRUE) +else() + set(COMPILER_RT_HAS_LLD_SOURCES FALSE) +endif() +pythonize_bool(COMPILER_RT_HAS_LLD_SOURCES) + add_subdirectory(lib) if(COMPILER_RT_INCLUDE_TESTS) add_subdirectory(unittests) + add_subdirectory(test) endif() -add_subdirectory(test) diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index 5ea313ba7162..6f401b1fa0c4 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -19,6 +19,7 @@ function(add_compiler_rt_object_libraries name) set(libname "${name}.${os}") set(libnames ${libnames} ${libname}) set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS}) + list_union(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) endforeach() else() foreach(arch ${LIB_ARCHS}) @@ -26,7 +27,7 @@ function(add_compiler_rt_object_libraries name) set(libnames ${libnames} ${libname}) set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS}) if(NOT CAN_TARGET_${arch}) - message(FATAL_ERROR "Archtecture ${arch} can't be targeted") + message(FATAL_ERROR "Architecture ${arch} can't be targeted") return() endif() endforeach() @@ -39,91 +40,130 @@ function(add_compiler_rt_object_libraries name) set_property(TARGET ${libname} APPEND PROPERTY COMPILE_DEFINITIONS ${LIB_DEFS}) if(APPLE) - set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}") + set_target_properties(${libname} PROPERTIES + OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") endif() endforeach() endfunction() -# Adds static or shared runtime for a given architecture and puts it in the -# proper directory in the build and install trees. -# add_compiler_rt_runtime( {STATIC,SHARED} +# Takes a list of object library targets, and a suffix and appends the proper +# TARGET_OBJECTS string to the output variable. +# format_object_libs( ...) +macro(format_object_libs output suffix) + foreach(lib ${ARGN}) + list(APPEND ${output} $) + endforeach() +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( +# {STATIC|SHARED} +# ARCHS +# OS # SOURCES # CFLAGS +# LINKFLAGS # DEFS -# OUTPUT_NAME ) -macro(add_compiler_rt_runtime name arch type) - if(CAN_TARGET_${arch}) - cmake_parse_arguments(LIB "" "OUTPUT_NAME" "SOURCES;CFLAGS;LINKFLAGS;DEFS" ${ARGN}) - add_library(${name} ${type} ${LIB_SOURCES}) - # Setup compile flags and definitions. - set_target_compile_flags(${name} - ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) - set_target_link_flags(${name} - ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS}) - set_property(TARGET ${name} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) - # Setup correct output directory in the build tree. - set_target_properties(${name} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} - LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} - RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - if ("${LIB_OUTPUT_NAME}" STREQUAL "") - set_target_properties(${name} PROPERTIES - OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX}) - else() - set_target_properties(${name} PROPERTIES - OUTPUT_NAME ${LIB_OUTPUT_NAME}) - endif() - # Add installation command. - install(TARGETS ${name} - ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} - LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} - RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) +# LINK_LIBS (only for shared library) +# OBJECT_LIBS +# PARENT_TARGET ) +function(add_compiler_rt_runtime name type) + if(NOT type MATCHES "^(STATIC|SHARED)$") + message(FATAL_ERROR "type argument must be STATIC or SHARED") + return() + endif() + cmake_parse_arguments(LIB + "" + "PARENT_TARGET" + "OS;ARCHS;SOURCES;CFLAGS;LINKFLAGS;DEFS;LINK_LIBS;OBJECT_LIBS" + ${ARGN}) + set(libnames) + if(APPLE) + foreach(os ${LIB_OS}) + if(type STREQUAL "STATIC") + set(libname "${name}_${os}") + else() + set(libname "${name}_${os}_dynamic") + set(extra_linkflags_${libname} ${DARWIN_${os}_LINKFLAGS} ${LIB_LINKFLAGS}) + endif() + list_union(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS) + if(LIB_ARCHS_${libname}) + list(APPEND libnames ${libname}) + set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${LIB_CFLAGS}) + set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) + set(sources_${libname} ${LIB_SOURCES}) + format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS}) + endif() + endforeach() else() - message(FATAL_ERROR "Archtecture ${arch} can't be targeted") + foreach(arch ${LIB_ARCHS}) + if(NOT CAN_TARGET_${arch}) + message(FATAL_ERROR "Architecture ${arch} can't be targeted") + return() + endif() + if(type STREQUAL "STATIC") + set(libname "${name}-${arch}") + set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) + else() + set(libname "${name}-dynamic-${arch}") + set(extra_linkflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS}) + if(WIN32) + set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX}) + else() + set(output_name_${libname} ${name}-${arch}${COMPILER_RT_OS_SUFFIX}) + endif() + endif() + set(sources_${libname} ${LIB_SOURCES}) + format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS}) + set(libnames ${libnames} ${libname}) + set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) + endforeach() endif() -endmacro() -# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library -# for several architectures. -# add_compiler_rt_osx_static_runtime( ARCHS -# SOURCES -# CFLAGS -# DEFS ) -macro(add_compiler_rt_osx_static_runtime name) - cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) - add_library(${name} STATIC ${LIB_SOURCES}) - set_target_compile_flags(${name} ${LIB_CFLAGS}) - set_property(TARGET ${name} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) - set_target_properties(${name} PROPERTIES - OSX_ARCHITECTURES "${LIB_ARCHS}" - ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) -endmacro() + if(NOT libnames) + return() + endif() -# Adds dynamic runtime library on osx/iossim, which supports multiple -# architectures. -# add_compiler_rt_darwin_dynamic_runtime( -# ARCHS -# SOURCES -# CFLAGS -# DEFS -# LINKFLAGS ) -macro(add_compiler_rt_darwin_dynamic_runtime name os) - cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN}) - add_library(${name} SHARED ${LIB_SOURCES}) - set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) - set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS}) - set_property(TARGET ${name} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) - set_target_properties(${name} PROPERTIES - OSX_ARCHITECTURES "${LIB_ARCHS}" - LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) -endmacro() + if(LIB_PARENT_TARGET) + set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET}) + endif() + + foreach(libname ${libnames}) + add_library(${libname} ${type} ${sources_${libname}}) + set_target_compile_flags(${libname} ${extra_cflags_${libname}}) + set_target_link_flags(${libname} ${extra_linkflags_${libname}}) + set_property(TARGET ${libname} APPEND PROPERTY + COMPILE_DEFINITIONS ${LIB_DEFS}) + set_target_properties(${libname} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} + LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} + RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME ${output_name_${libname}}) + if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED") + target_link_libraries(${libname} ${LIB_LINK_LIBS}) + endif() + install(TARGETS ${libname} + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} + ${COMPONENT_OPTION} + LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} + ${COMPONENT_OPTION} + RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} + ${COMPONENT_OPTION}) + if(APPLE) + set_target_properties(${libname} PROPERTIES + OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") + endif() + + if(type STREQUAL "SHARED") + rt_externalize_debuginfo(${libname}) + endif() + endforeach() + if(LIB_PARENT_TARGET) + add_dependencies(${LIB_PARENT_TARGET} ${libnames}) + endif() +endfunction() set(COMPILER_RT_TEST_CFLAGS) @@ -248,7 +288,8 @@ macro(add_custom_libcxx name prefix) ExternalProject_Add(${name} PREFIX ${prefix} SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} - CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} + CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM} + -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER} -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS} -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS} @@ -273,3 +314,24 @@ macro(add_custom_libcxx name prefix) DEPENDS ${LIBCXX_DEPS} ) endmacro() + +function(rt_externalize_debuginfo name) + if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO) + return() + endif() + + if(APPLE) + if(CMAKE_CXX_FLAGS MATCHES "-flto" + OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto") + + set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o) + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-object_path_lto -Wl,${lto_object}") + endif() + add_custom_command(TARGET ${name} POST_BUILD + COMMAND xcrun dsymutil $ + COMMAND xcrun strip -Sl $) + else() + message(FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!") + endif() +endfunction() diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake index b2e62dd0bac6..48f40bf4f753 100644 --- a/cmake/Modules/CompilerRTCompile.cmake +++ b/cmake/Modules/CompilerRTCompile.cmake @@ -49,6 +49,10 @@ macro(clang_compile object_file source) translate_msvc_cflags(global_flags "${global_flags}") endif() + 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) @@ -72,7 +76,7 @@ endmacro() macro(clang_compiler_add_cxx_check) if (APPLE) set(CMD - "echo '#include ' | ${COMPILER_RT_TEST_COMPILER} -E -x c++ - > /dev/null" + "echo '#include ' | ${COMPILER_RT_TEST_COMPILER} ${OSX_SYSROOT_FLAG} -E -x c++ - > /dev/null" "if [ $? != 0 ] " " then echo" " echo 'Your just-built clang cannot find C++ headers, which are needed to build and run compiler-rt tests.'" diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake new file mode 100644 index 000000000000..511361b49a7a --- /dev/null +++ b/cmake/Modules/CompilerRTDarwinUtils.cmake @@ -0,0 +1,453 @@ +# On OS X SDKs can be installed anywhere on the base system and xcode-select can +# set the default Xcode to use. This function finds the SDKs that are present in +# the current Xcode. +function(find_darwin_sdk_dir var sdk_name) + # Let's first try the internal SDK, otherwise use the public SDK. + execute_process( + COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path + OUTPUT_VARIABLE var_internal + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_FILE /dev/null + ) + if("" STREQUAL "${var_internal}") + execute_process( + COMMAND xcodebuild -version -sdk ${sdk_name} Path + OUTPUT_VARIABLE var_internal + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_FILE /dev/null + ) + endif() + set(${var} ${var_internal} PARENT_SCOPE) +endfunction() + +# There isn't a clear mapping of what architectures are supported with a given +# target platform, but ld's version output does list the architectures it can +# link for. +function(darwin_get_toolchain_supported_archs output_var) + execute_process( + COMMAND ld -v + ERROR_VARIABLE LINKER_VERSION) + + string(REGEX MATCH "configured to support archs: ([^\n]+)" + ARCHES_MATCHED "${LINKER_VERSION}") + if(ARCHES_MATCHED) + set(ARCHES "${CMAKE_MATCH_1}") + message(STATUS "Got ld supported ARCHES: ${ARCHES}") + string(REPLACE " " ";" ARCHES ${ARCHES}) + else() + # If auto-detecting fails, fall back to a default set + message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.") + set(ARCHES "i386;x86_64;armv7;armv7s;arm64") + endif() + + set(${output_var} ${ARCHES} PARENT_SCOPE) +endfunction() + +# This function takes an OS and a list of architectures and identifies the +# subset of the architectures list that the installed toolchain can target. +function(darwin_test_archs os valid_archs) + if(${valid_archs}) + message(STATUS "Using cached valid architectures for ${os}.") + return() + endif() + + set(archs ${ARGN}) + message(STATUS "Finding valid architectures for ${os}...") + set(SIMPLE_CPP ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.cpp) + file(WRITE ${SIMPLE_CPP} "#include \nint main() { std::cout << std::endl; return 0; }\n") + + set(os_linker_flags) + foreach(flag ${DARWIN_${os}_LINKFLAGS}) + set(os_linker_flags "${os_linker_flags} ${flag}") + endforeach() + + # The simple program will build for x86_64h on the simulator because it is + # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually + # a valid or useful architecture for the iOS simulator we should drop it. + if(${os} STREQUAL "iossim") + list(REMOVE_ITEM archs "x86_64h") + endif() + + set(working_archs) + foreach(arch ${archs}) + + set(arch_linker_flags "-arch ${arch} ${os_linker_flags}") + try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_CPP} + COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS} + CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}" + OUTPUT_VARIABLE TEST_OUTPUT) + if(${CAN_TARGET_${os}_${arch}}) + list(APPEND working_archs ${arch}) + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Testing compiler for supporting ${os}-${arch}:\n" + "${TEST_OUTPUT}\n") + endif() + endforeach() + set(${valid_archs} ${working_archs} + CACHE STRING "List of valid architectures for platform ${os}.") +endfunction() + +# This function checks the host cpusubtype to see if it is post-haswell. Haswell +# and later machines can run x86_64h binaries. Haswell is cpusubtype 8. +function(darwin_filter_host_archs input output) + list_union(tmp_var DARWIN_osx_ARCHS ${input}) + execute_process( + COMMAND sysctl hw.cpusubtype + OUTPUT_VARIABLE SUBTYPE) + + string(REGEX MATCH "hw.cpusubtype: ([0-9]*)" + SUBTYPE_MATCHED "${SUBTYPE}") + set(HASWELL_SUPPORTED Off) + if(SUBTYPE_MATCHED) + if(${CMAKE_MATCH_1} GREATER 7) + set(HASWELL_SUPPORTED On) + endif() + endif() + if(NOT HASWELL_SUPPORTED) + list(REMOVE_ITEM tmp_var x86_64h) + endif() + set(${output} ${tmp_var} PARENT_SCOPE) +endfunction() + +# Read and process the exclude file into a list of symbols +function(darwin_read_list_from_file output_var file) + if(EXISTS ${file}) + file(READ ${file} EXCLUDES) + string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES}) + set(${output_var} ${EXCLUDES} PARENT_SCOPE) + endif() +endfunction() + +# this function takes an OS, architecture and minimum version and provides a +# list of builtin functions to exclude +function(darwin_find_excluded_builtins_list output_var) + cmake_parse_arguments(LIB + "" + "OS;ARCH;MIN_VERSION" + "" + ${ARGN}) + + if(NOT LIB_OS OR NOT LIB_ARCH) + message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!") + endif() + + darwin_read_list_from_file(${LIB_OS}_BUILTINS + ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt) + darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS + ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt) + + if(LIB_MIN_VERSION) + file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt) + foreach(builtin_list ${builtin_lists}) + string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}") + if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION) + if(NOT smallest_version) + set(smallest_version ${CMAKE_MATCH_1}) + elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version) + set(smallest_version ${CMAKE_MATCH_1}) + endif() + endif() + endforeach() + + if(smallest_version) + darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS + ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt) + endif() + endif() + + set(${output_var} + ${${LIB_ARCH}_${LIB_OS}_BUILTINS} + ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS} + ${${LIB_OS}_BUILTINS} PARENT_SCOPE) +endfunction() + +# adds a single builtin library for a single OS & ARCH +macro(darwin_add_builtin_library name suffix) + cmake_parse_arguments(LIB + "" + "PARENT_TARGET;OS;ARCH" + "SOURCES;CFLAGS;DEFS" + ${ARGN}) + set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}") + add_library(${libname} STATIC ${LIB_SOURCES}) + if(DARWIN_${LIB_OS}_SYSROOT) + set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT}) + endif() + set_target_compile_flags(${libname} + ${sysroot_flag} + ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG} + ${LIB_CFLAGS}) + set_property(TARGET ${libname} APPEND PROPERTY + COMPILE_DEFINITIONS ${LIB_DEFS}) + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX}) + set_target_properties(${libname} PROPERTIES + OSX_ARCHITECTURES ${LIB_ARCH}) + + if(LIB_PARENT_TARGET) + add_dependencies(${LIB_PARENT_TARGET} ${libname}) + endif() + + list(APPEND ${LIB_OS}_${suffix}_libs ${libname}) + list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $) +endmacro() + +function(darwin_lipo_libs name) + cmake_parse_arguments(LIB + "" + "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR" + "LIPO_FLAGS;DEPENDS" + ${ARGN}) + if(LIB_DEPENDS AND LIB_LIPO_FLAGS) + add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a + COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR} + COMMAND lipo -output + ${LIB_OUTPUT_DIR}/lib${name}.a + -create ${LIB_LIPO_FLAGS} + DEPENDS ${LIB_DEPENDS} + ) + add_custom_target(${name} + DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a) + add_dependencies(${LIB_PARENT_TARGET} ${name}) + install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a + DESTINATION ${LIB_INSTALL_DIR}) + else() + message(WARNING "Not generating lipo target for ${name} because no input libraries exist.") + endif() +endfunction() + +# Filter out generic versions of routines that are re-implemented in +# architecture specific manner. This prevents multiple definitions of the +# same symbols, making the symbol selection non-deterministic. +function(darwin_filter_builtin_sources output_var exclude_or_include excluded_list) + if(exclude_or_include STREQUAL "EXCLUDE") + set(filter_action GREATER) + set(filter_value -1) + elseif(exclude_or_include STREQUAL "INCLUDE") + set(filter_action LESS) + set(filter_value 0) + else() + message(FATAL_ERROR "darwin_filter_builtin_sources called without EXCLUDE|INCLUDE") + endif() + + set(intermediate ${ARGN}) + foreach (_file ${intermediate}) + get_filename_component(_name_we ${_file} NAME_WE) + list(FIND ${excluded_list} ${_name_we} _found) + if(_found ${filter_action} ${filter_value}) + list(REMOVE_ITEM intermediate ${_file}) + elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c") + get_filename_component(_name ${_file} NAME) + string(REPLACE ".S" ".c" _cname "${_name}") + list(REMOVE_ITEM intermediate ${_cname}) + endif () + endforeach () + set(${output_var} ${intermediate} PARENT_SCOPE) +endfunction() + +function(darwin_add_eprintf_library) + cmake_parse_arguments(LIB + "" + "" + "CFLAGS" + ${ARGN}) + + add_library(clang_rt.eprintf STATIC eprintf.c) + set_target_compile_flags(clang_rt.eprintf + -isysroot ${DARWIN_osx_SYSROOT} + ${DARWIN_osx_BUILTIN_MIN_VER_FLAG} + -arch i386 + ${LIB_CFLAGS}) + set_target_properties(clang_rt.eprintf PROPERTIES + OUTPUT_NAME clang_rt.eprintf${COMPILER_RT_OS_SUFFIX}) + set_target_properties(clang_rt.eprintf PROPERTIES + OSX_ARCHITECTURES i386) + add_dependencies(builtins clang_rt.eprintf) + set_target_properties(clang_rt.eprintf PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) + install(TARGETS clang_rt.eprintf + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) +endfunction() + +# Generates builtin libraries for all operating systems specified in ARGN. Each +# OS library is constructed by lipo-ing together single-architecture libraries. +macro(darwin_add_builtin_libraries) + set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes) + + set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer") + set(CMAKE_C_FLAGS "") + set(CMAKE_CXX_FLAGS "") + set(CMAKE_ASM_FLAGS "") + + set(PROFILE_SOURCES ../profile/InstrProfiling + ../profile/InstrProfilingBuffer + ../profile/InstrProfilingPlatformDarwin) + foreach (os ${ARGN}) + list_union(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH) + foreach (arch ${DARWIN_BUILTIN_ARCHS}) + darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS + OS ${os} + ARCH ${arch} + MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER}) + + darwin_filter_builtin_sources(filtered_sources + EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS + ${${arch}_SOURCES}) + + darwin_add_builtin_library(clang_rt builtins + OS ${os} + ARCH ${arch} + SOURCES ${filtered_sources} + CFLAGS ${CFLAGS} -arch ${arch} + PARENT_TARGET builtins) + endforeach() + + # Don't build cc_kext libraries for simulator platforms + if(NOT DARWIN_${os}_SKIP_CC_KEXT) + foreach (arch ${DARWIN_BUILTIN_ARCHS}) + # By not specifying MIN_VERSION this only reads the OS and OS-arch lists. + # We don't want to filter out the builtins that are present in libSystem + # because kexts can't link libSystem. + darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS + OS ${os} + ARCH ${arch}) + + darwin_filter_builtin_sources(filtered_sources + EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS + ${${arch}_SOURCES}) + + # In addition to the builtins cc_kext includes some profile sources + darwin_add_builtin_library(clang_rt cc_kext + OS ${os} + ARCH ${arch} + SOURCES ${filtered_sources} ${PROFILE_SOURCES} + CFLAGS ${CFLAGS} -arch ${arch} -mkernel + DEFS KERNEL_USE + PARENT_TARGET builtins) + endforeach() + set(archive_name clang_rt.cc_kext_${os}) + if(${os} STREQUAL "osx") + set(archive_name clang_rt.cc_kext) + endif() + darwin_lipo_libs(${archive_name} + 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}) + endif() + endforeach() + + darwin_add_eprintf_library(CFLAGS ${CFLAGS}) + + # 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() + endforeach() + darwin_add_embedded_builtin_libraries() +endmacro() + +macro(darwin_add_embedded_builtin_libraries) + # this is a hacky opt-out. If you can't target both intel and arm + # architectures we bail here. + set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7) + set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7) + if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*") + list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx) + if(i386_idx GREATER -1) + list(APPEND DARWIN_HARD_FLOAT_ARCHS i386) + endif() + + list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx) + if(x86_64_idx GREATER -1) + list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64) + endif() + + set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded) + + set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding") + set(CMAKE_C_FLAGS "") + set(CMAKE_CXX_FLAGS "") + set(CMAKE_ASM_FLAGS "") + + set(SOFT_FLOAT_FLAG -mfloat-abi=soft) + set(HARD_FLOAT_FLAG -mfloat-abi=hard) + + set(ENABLE_PIC Off) + set(PIC_FLAG -fPIC) + set(STATIC_FLAG -static) + + 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) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR + ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") + + darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt) + darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt) + darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt) + darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt) + darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt) + + + set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS}) + set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS}) + set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS}) + set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS}) + set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS}) + set(x86_64_FUNCTIONS ${common_FUNCTIONS}) + + foreach(arch ${DARWIN_macho_embedded_ARCHS}) + darwin_filter_builtin_sources(${arch}_filtered_sources + INCLUDE ${arch}_FUNCTIONS + ${${arch}_SOURCES}) + if(NOT ${arch}_filtered_sources) + message("${arch}_SOURCES: ${${arch}_SOURCES}") + message("${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}") + message(FATAL_ERROR "Empty filtered sources!") + endif() + endforeach() + + foreach(float_type SOFT HARD) + foreach(type PIC STATIC) + string(TOLOWER "${float_type}_${type}" lib_suffix) + foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS}) + set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT}) + set(float_flag) + if(${arch} MATCHES "^arm") + # x86 targets are hard float by default, but the complain about the + # float ABI flag, so don't pass it unless we're targeting arm. + set(float_flag ${${float_type}_FLOAT_FLAG}) + endif() + darwin_add_builtin_library(clang_rt ${lib_suffix} + OS macho_embedded + ARCH ${arch} + SOURCES ${${arch}_filtered_sources} + CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}} + PARENT_TARGET builtins) + endforeach() + foreach(lib ${macho_embedded_${lib_suffix}_libs}) + set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C) + endforeach() + darwin_lipo_libs(clang_rt.${lib_suffix} + PARENT_TARGET builtins + LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags} + DEPENDS ${macho_embedded_${lib_suffix}_libs} + OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR} + INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR}) + endforeach() + endforeach() + endif() +endmacro() diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake index f7f60a4ac6f4..cf690f4a33c5 100644 --- a/cmake/Modules/CompilerRTUtils.cmake +++ b/cmake/Modules/CompilerRTUtils.cmake @@ -57,3 +57,13 @@ macro(append_have_file_definition filename varname list) endif() list(APPEND ${list} "${varname}=${${varname}}") endmacro() + +macro(list_union output input1 input2) + set(${output}) + foreach(it ${${input1}}) + list(FIND ${input2} ${it} index) + if( NOT (index EQUAL -1)) + list(APPEND ${output} ${it}) + endif() + endforeach() +endmacro() diff --git a/cmake/Modules/SanitizerUtils.cmake b/cmake/Modules/SanitizerUtils.cmake index c040b42122ce..3eb49c83f51c 100644 --- a/cmake/Modules/SanitizerUtils.cmake +++ b/cmake/Modules/SanitizerUtils.cmake @@ -4,46 +4,60 @@ set(SANITIZER_GEN_DYNAMIC_LIST set(SANITIZER_LINT_SCRIPT ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh) -# Create a target "-symbols" that would generate the list of symbols -# that need to be exported from sanitizer runtime "". Function +# Create a target "--symbols" that would generate the list of +# symbols that need to be exported from sanitizer runtime "". Function # interceptors are exported automatically, user can also provide files with # symbol names that should be exported as well. -# add_sanitizer_rt_symbols( ) +# add_sanitizer_rt_symbols( +# ARCHS +# PARENT_TARGET +# EXTRA ) macro(add_sanitizer_rt_symbols name) - set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${name}.syms-stamp) - set(extra_args) - foreach(arg ${ARGN}) - list(APPEND extra_args "--extra" ${arg}) - endforeach() - add_custom_command(OUTPUT ${stamp} - COMMAND ${PYTHON_EXECUTABLE} - ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $ - > $.syms - COMMAND ${CMAKE_COMMAND} -E touch ${stamp} - DEPENDS ${name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Generating exported symbols for ${name}" - VERBATIM) - add_custom_target(${name}-symbols ALL - DEPENDS ${stamp} - SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN}) + cmake_parse_arguments(ARG + "" + "PARENT_TARGET" + "ARCHS;EXTRA" + ${ARGN}) + foreach(arch ${ARG_ARCHS}) + set(target_name ${name}-${arch}) + set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.syms-stamp) + set(extra_args) + foreach(arg ${ARG_EXTRA}) + list(APPEND extra_args "--extra" ${arg}) + endforeach() + add_custom_command(OUTPUT ${stamp} + COMMAND ${PYTHON_EXECUTABLE} + ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $ + > $.syms + COMMAND ${CMAKE_COMMAND} -E touch ${stamp} + DEPENDS ${target_name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating exported symbols for ${target_name}" + VERBATIM) + add_custom_target(${target_name}-symbols ALL + DEPENDS ${stamp} + SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA}) - if(NOT CMAKE_VERSION VERSION_LESS 3.0) - install(FILES $.syms - DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - else() - # Per-config install location. - if(CMAKE_CONFIGURATION_TYPES) - foreach(c ${CMAKE_CONFIGURATION_TYPES}) - get_target_property(libfile ${name} LOCATION_${c}) - install(FILES ${libfile}.syms CONFIGURATIONS ${c} - DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - endforeach() + if(NOT CMAKE_VERSION VERSION_LESS 3.0) + install(FILES $.syms + DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) else() - get_target_property(libfile ${name} LOCATION_${CMAKE_BUILD_TYPE}) - install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + # Per-config install location. + if(CMAKE_CONFIGURATION_TYPES) + foreach(c ${CMAKE_CONFIGURATION_TYPES}) + get_target_property(libfile ${target_name} LOCATION_${c}) + install(FILES ${libfile}.syms CONFIGURATIONS ${c} + DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + endforeach() + else() + get_target_property(libfile ${target_name} LOCATION_${CMAKE_BUILD_TYPE}) + install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + endif() endif() - endif() + if(ARG_PARENT_TARGET) + add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols) + endif() + endforeach() endmacro() macro(add_sanitizer_rt_version_list name) diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index c645be4d88d6..f91530bb4403 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -27,7 +27,14 @@ check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUN check_cxx_compiler_flag(-std=c++11 COMPILER_RT_HAS_STD_CXX11_FLAG) check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC) check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) -check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG) +check_cxx_compiler_flag("-Werror -msse3" COMPILER_RT_HAS_MSSE3_FLAG) +check_cxx_compiler_flag(-std=c99 COMPILER_RT_HAS_STD_C99_FLAG) +check_cxx_compiler_flag(--sysroot=. COMPILER_RT_HAS_SYSROOT_FLAG) + +if(NOT WIN32 AND NOT CYGWIN) + # MinGW warns if -fvisibility-inlines-hidden is used. + check_cxx_compiler_flag("-fvisibility-inlines-hidden" COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG) +endif() check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG) check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG) @@ -61,7 +68,7 @@ check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG) check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) # Libraries. -check_library_exists(c printf "" COMPILER_RT_HAS_LIBC) +check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC) check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL) check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT) check_library_exists(m pow "" COMPILER_RT_HAS_LIBM) @@ -71,6 +78,7 @@ check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX) # Linker flags. if(ANDROID) check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) + check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG) endif() # Architectures. @@ -120,8 +128,8 @@ macro(test_target_arch arch def) endif() if(${CAN_TARGET_${arch}}) list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) - elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}" AND - COMPILER_RT_HAS_EXPLICIT_TEST_TARGET_TRIPLE) + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND + COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE) # Bail out if we cannot target the architecture we plan to test. message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") endif() @@ -168,12 +176,11 @@ endif() # Generate the COMPILER_RT_SUPPORTED_ARCH list. if(ANDROID) - # Can't rely on LLVM_NATIVE_ARCH in cross-compilation. - # Examine compiler output instead. + # Examine compiler output to determine target architecture. detect_target_arch() set(COMPILER_RT_OS_SUFFIX "-android") -else() - if("${LLVM_NATIVE_ARCH}" STREQUAL "X86") +elseif(NOT APPLE) # Supported archs for Apple platforms are generated later + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64") if(NOT MSVC) test_target_arch(x86_64 "" "-m64") # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may @@ -188,42 +195,38 @@ else() test_target_arch(x86_64 "" "") endif() endif() - elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc") TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN) if(HOST_IS_BIG_ENDIAN) test_target_arch(powerpc64 "" "-m64") else() test_target_arch(powerpc64le "" "-m64") endif() - elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el") # Gcc doesn't accept -m32/-m64 so we do the next best thing and use # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match # clang's default CPU's. In the 64-bit case, we must also specify the ABI # since the default ABI differs between gcc and clang. # FIXME: Ideally, we would build the N32 library too. - if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el") - # regex for mipsel, mips64el - test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu") - test_target_arch(mips64el "" "-mips64r2" "-mabi=n64") - else() - test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu") - test_target_arch(mips64 "" "-mips64r2" "-mabi=n64") - endif() - elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm") - test_target_arch(arm "" "-march=armv7-a") - elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch32") + test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu") + test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips") + test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu") + test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm") + test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft") + test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32") test_target_arch(aarch32 "" "-march=armv8-a") - elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64") test_target_arch(aarch64 "" "-march=armv8-a") endif() set(COMPILER_RT_OS_SUFFIX "") endif() -message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}") - # Takes ${ARGN} and puts only supported architectures in @out_var list. function(filter_available_targets out_var) - set(archs) + set(archs ${${out_var}}) foreach(arch ${ARGN}) list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch}) @@ -239,30 +242,264 @@ function(get_target_flags_for_arch arch out_var) if(ARCH_INDEX EQUAL -1) message(FATAL_ERROR "Unsupported architecture: ${arch}") else() - set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE) + if (NOT APPLE) + set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE) + else() + # This is only called in constructing cflags for tests executing on the + # host. This will need to all be cleaned up to support building tests + # for cross-targeted hardware (i.e. iOS). + set(${out_var} -arch ${arch} PARENT_SCOPE) + endif() endif() endfunction() -# Architectures supported by compiler-rt libraries. -filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH - x86_64 i386 i686 powerpc64 powerpc64le arm aarch64 mips mips64 mipsel mips64el) -# LSan and UBSan common files should be available on all architectures supported -# by other sanitizers (even if they build into dummy object files). -filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH - ${SANITIZER_COMMON_SUPPORTED_ARCH}) -filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH - ${SANITIZER_COMMON_SUPPORTED_ARCH}) -filter_available_targets(ASAN_SUPPORTED_ARCH - x86_64 i386 i686 powerpc64 powerpc64le arm mips mipsel mips64 mips64el) -filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) -filter_available_targets(LSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) -filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) -filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64 - mipsel mips64el aarch64 powerpc64 powerpc64le) -filter_available_targets(TSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) -filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips - mipsel mips64 mips64el powerpc64 powerpc64le) -filter_available_targets(SAFESTACK_SUPPORTED_ARCH x86_64 i386 i686) +set(ARM64 aarch64) +set(ARM32 arm armhf) +set(X86 i386 i686) +set(X86_64 x86_64) +set(MIPS32 mips mipsel) +set(MIPS64 mips64 mips64el) +set(PPC64 powerpc64 powerpc64le) + +if(APPLE) + set(ARM64 arm64) + set(ARM32 armv7 armv7s) + set(X86_64 x86_64 x86_64h) +endif() + +set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} + ${MIPS32} ${MIPS64}) +set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} + ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}) +set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} + ${MIPS32} ${MIPS64} ${PPC64}) +set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) +set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) +set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) +set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64} + ${MIPS32} ${MIPS64}) +set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64}) +set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} + ${MIPS32} ${MIPS64} ${PPC64}) +set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64}) +set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64}) + +if(APPLE) + include(CompilerRTDarwinUtils) + + # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not + # the command line tools. If this is the case, we need to find the OS X + # sysroot to pass to clang. + if(NOT EXISTS /usr/include) + execute_process(COMMAND xcodebuild -version -sdk macosx Path + OUTPUT_VARIABLE OSX_SYSROOT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}") + endif() + + option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off) + + find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx) + find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator) + find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos) + + # Note: In order to target x86_64h on OS X the minimum deployment target must + # be 10.8 or higher. + set(SANITIZER_COMMON_SUPPORTED_OS osx) + set(BUILTIN_SUPPORTED_OS osx) + set(PROFILE_SUPPORTED_OS osx) + set(TSAN_SUPPORTED_OS osx) + if(NOT SANITIZER_MIN_OSX_VERSION) + string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)" + MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") + if(MACOSX_VERSION_MIN_FLAG) + set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}") + elseif(CMAKE_OSX_DEPLOYMENT_TARGET) + set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) + else() + set(SANITIZER_MIN_OSX_VERSION 10.9) + endif() + if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") + message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}") + endif() + endif() + + # We're setting the flag manually for each target OS + set(CMAKE_OSX_DEPLOYMENT_TARGET "") + + set(DARWIN_COMMON_CFLAGS -stdlib=libc++) + set(DARWIN_COMMON_LINKFLAGS + -stdlib=libc++ + -lc++ + -lc++abi) + + set(DARWIN_osx_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) + set(DARWIN_osx_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) + set(DARWIN_osx_BUILTIN_MIN_VER 10.5) + set(DARWIN_osx_BUILTIN_MIN_VER_FLAG + -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER}) + + if(DARWIN_osx_SYSROOT) + list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT}) + list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${DARWIN_osx_SYSROOT}) + endif() + + # Figure out which arches to use for each OS + darwin_get_toolchain_supported_archs(toolchain_arches) + message(STATUS "Toolchain supported arches: ${toolchain_arches}") + + if(NOT MACOSX_VERSION_MIN_FLAG) + darwin_test_archs(osx + DARWIN_osx_ARCHS + ${toolchain_arches}) + message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}") + foreach(arch ${DARWIN_osx_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + + # Need to build a 10.4 compatible libclang_rt + set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT}) + set(DARWIN_10.4_BUILTIN_MIN_VER 10.4) + set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG + -mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER}) + set(DARWIN_10.4_SKIP_CC_KEXT On) + darwin_test_archs(10.4 + DARWIN_10.4_ARCHS + ${toolchain_arches}) + message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}") + if(DARWIN_10.4_ARCHS) + # don't include the Haswell slice in the 10.4 compatibility library + list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h) + list(APPEND BUILTIN_SUPPORTED_OS 10.4) + endif() + + if(DARWIN_iossim_SYSROOT) + set(DARWIN_iossim_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mios-simulator-version-min=7.0 + -isysroot ${DARWIN_iossim_SYSROOT}) + set(DARWIN_iossim_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mios-simulator-version-min=7.0 + -isysroot ${DARWIN_iossim_SYSROOT}) + set(DARWIN_iossim_BUILTIN_MIN_VER 6.0) + set(DARWIN_iossim_BUILTIN_MIN_VER_FLAG + -mios-simulator-version-min=${DARWIN_iossim_BUILTIN_MIN_VER}) + + set(DARWIN_iossim_SKIP_CC_KEXT On) + darwin_test_archs(iossim + DARWIN_iossim_ARCHS + ${toolchain_arches}) + message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}") + if(DARWIN_iossim_ARCHS) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) + list(APPEND BUILTIN_SUPPORTED_OS iossim) + list(APPEND PROFILE_SUPPORTED_OS iossim) + endif() + foreach(arch ${DARWIN_iossim_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + + if(DARWIN_ios_SYSROOT AND COMPILER_RT_ENABLE_IOS) + set(DARWIN_ios_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -miphoneos-version-min=7.0 + -isysroot ${DARWIN_ios_SYSROOT}) + set(DARWIN_ios_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -miphoneos-version-min=7.0 + -isysroot ${DARWIN_ios_SYSROOT}) + set(DARWIN_ios_BUILTIN_MIN_VER 6.0) + set(DARWIN_ios_BUILTIN_MIN_VER_FLAG + -miphoneos-version-min=${DARWIN_ios_BUILTIN_MIN_VER}) + + darwin_test_archs(ios + DARWIN_ios_ARCHS + ${toolchain_arches}) + message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}") + if(DARWIN_ios_ARCHS) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios) + list(APPEND BUILTIN_SUPPORTED_OS ios) + list(APPEND PROFILE_SUPPORTED_OS ios) + endif() + foreach(arch ${DARWIN_ios_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + endif() + + # for list_union + include(CompilerRTUtils) + + list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches) + + list_union(SANITIZER_COMMON_SUPPORTED_ARCH + ALL_SANITIZER_COMMON_SUPPORTED_ARCH + COMPILER_RT_SUPPORTED_ARCH + ) + set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}) + set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}) + list_union(ASAN_SUPPORTED_ARCH + ALL_ASAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(DFSAN_SUPPORTED_ARCH + ALL_DFSAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(LSAN_SUPPORTED_ARCH + ALL_LSAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(MSAN_SUPPORTED_ARCH + ALL_MSAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(PROFILE_SUPPORTED_ARCH + ALL_PROFILE_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(TSAN_SUPPORTED_ARCH + ALL_TSAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(UBSAN_SUPPORTED_ARCH + ALL_UBSAN_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(SAFESTACK_SUPPORTED_ARCH + ALL_SAFESTACK_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) + list_union(CFI_SUPPORTED_ARCH + ALL_CFI_SUPPORTED_ARCH + SANITIZER_COMMON_SUPPORTED_ARCH) +else() + # Architectures supported by compiler-rt libraries. + filter_available_targets(BUILTIN_SUPPORTED_ARCH + ${ALL_BUILTIN_SUPPORTED_ARCH}) + filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH + ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) + # LSan and UBSan common files should be available on all architectures + # supported by other sanitizers (even if they build into dummy object files). + filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH + ${SANITIZER_COMMON_SUPPORTED_ARCH}) + filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH + ${SANITIZER_COMMON_SUPPORTED_ARCH}) + filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH}) + filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH}) + filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH}) + filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_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}) + filter_available_targets(SAFESTACK_SUPPORTED_ARCH + ${ALL_SAFESTACK_SUPPORTED_ARCH}) + filter_available_targets(CFI_SUPPORTED_ARCH ${ALL_CFI_SUPPORTED_ARCH}) +endif() + +message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}") if(ANDROID) set(OS_NAME "Android") @@ -329,7 +566,7 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Linux|FreeBSD") + OS_NAME MATCHES "Darwin|Linux|FreeBSD") set(COMPILER_RT_HAS_TSAN TRUE) else() set(COMPILER_RT_HAS_TSAN FALSE) @@ -342,17 +579,16 @@ else() set(COMPILER_RT_HAS_UBSAN FALSE) endif() -# -msse3 flag is not valid for Mips therefore clang gives a warning -# message with -msse3. But check_c_compiler_flags() checks only for -# compiler error messages. Therefore COMPILER_RT_HAS_MSSE3_FLAG turns out to be -# true on Mips, so we make it false here. -if("${LLVM_NATIVE_ARCH}" STREQUAL "Mips") - set(COMPILER_RT_HAS_MSSE3_FLAG FALSE) -endif() - if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND OS_NAME MATCHES "Darwin|Linux|FreeBSD") set(COMPILER_RT_HAS_SAFESTACK TRUE) else() set(COMPILER_RT_HAS_SAFESTACK FALSE) endif() + +if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH AND + OS_NAME MATCHES "Linux") + set(COMPILER_RT_HAS_CFI TRUE) +else() + set(COMPILER_RT_HAS_CFI FALSE) +endif() diff --git a/include/sanitizer/asan_interface.h b/include/sanitizer/asan_interface.h index 7763389ab257..97ba0ceb0b23 100644 --- a/include/sanitizer/asan_interface.h +++ b/include/sanitizer/asan_interface.h @@ -110,10 +110,6 @@ extern "C" { void __asan_report_error(void *pc, void *bp, void *sp, void *addr, int is_write, size_t access_size); - // Sets the exit code to use when reporting an error. - // Returns the old value. - int __asan_set_error_exit_code(int exit_code); - // Deprecated. Call __sanitizer_set_death_callback instead. void __asan_set_death_callback(void (*callback)(void)); diff --git a/include/sanitizer/common_interface_defs.h b/include/sanitizer/common_interface_defs.h index ef645e527119..b736ed9e5235 100644 --- a/include/sanitizer/common_interface_defs.h +++ b/include/sanitizer/common_interface_defs.h @@ -105,12 +105,29 @@ extern "C" { int __sanitizer_verify_contiguous_container(const void *beg, const void *mid, const void *end); + // Similar to __sanitizer_verify_contiguous_container but returns the address + // of the first improperly poisoned byte otherwise. Returns null if the area + // is poisoned properly. + const void *__sanitizer_contiguous_container_find_bad_address( + const void *beg, const void *mid, const void *end); + // Print the stack trace leading to this call. Useful for debugging user code. void __sanitizer_print_stack_trace(); // Sets the callback to be called right before death on error. // Passing 0 will unset the callback. void __sanitizer_set_death_callback(void (*callback)(void)); + + // Interceptor hooks. + // Whenever a libc function interceptor is called it checks if the + // corresponding weak hook is defined, and it so -- calls it. + // The primary use case is data-flow-guided fuzzing, where the fuzzer needs + // to know what is being passed to libc functions, e.g. memcmp. + // FIXME: implement more hooks. + void __sanitizer_weak_hook_memcmp(void *called_pc, const void *s1, + const void *s2, size_t n); + void __sanitizer_weak_hook_strncmp(void *called_pc, const char *s1, + const char *s2, size_t n); #ifdef __cplusplus } // extern "C" #endif diff --git a/include/sanitizer/coverage_interface.h b/include/sanitizer/coverage_interface.h index 404b71e3086f..b93111b859bc 100644 --- a/include/sanitizer/coverage_interface.h +++ b/include/sanitizer/coverage_interface.h @@ -27,9 +27,11 @@ extern "C" { // descriptor. Returns -1 on failure, or if coverage dumping is disabled. // This is intended for use by sandboxing code. intptr_t __sanitizer_maybe_open_cov_file(const char *name); - // Get the number of total unique covered entities (blocks, edges, calls). + // Get the number of unique covered blocks (or edges). // This can be useful for coverage-directed in-process fuzzers. uintptr_t __sanitizer_get_total_unique_coverage(); + // Get the number of unique indirect caller-callee pairs. + uintptr_t __sanitizer_get_total_unique_caller_callee_pairs(); // Reset the basic-block (edge) coverage to the initial state. // Useful for in-process fuzzing to start collecting coverage from scratch. diff --git a/include/sanitizer/dfsan_interface.h b/include/sanitizer/dfsan_interface.h index 84ffd49f8afe..05666f736718 100644 --- a/include/sanitizer/dfsan_interface.h +++ b/include/sanitizer/dfsan_interface.h @@ -91,16 +91,18 @@ void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback); ///