Index: cmake/Modules/CompilerRTDarwinUtils.cmake =================================================================== --- cmake/Modules/CompilerRTDarwinUtils.cmake +++ cmake/Modules/CompilerRTDarwinUtils.cmake @@ -64,7 +64,7 @@ # 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") + if(${os} MATCHES "^(iossim|tvossim|watchossim)$") list(REMOVE_ITEM archs "x86_64h") endif() Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -195,6 +195,14 @@ test_target_arch(x86_64 "" "") endif() endif() + + execute_process( + COMMAND xcodebuild -version -sdk iphoneos Path + OUTPUT_VARIABLE IOS_SDK_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + test_target_arch(arm64 "-arch arm64 -isysroot ${IOS_SDK_DIR}") + test_target_arch(armv7 "-arch armv7 -isysroot ${IOS_SDK_DIR}") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc") TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN) if(HOST_IS_BIG_ENDIAN) @@ -263,7 +271,7 @@ if(APPLE) set(ARM64 arm64) - set(ARM32 armv7 armv7s) + set(ARM32 armv7 armv7s armv7k) set(X86_64 x86_64 x86_64h) endif() @@ -297,11 +305,17 @@ set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}") endif() - option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off) + option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" On) + option(COMPILER_RT_ENABLE_TVOS "Enable building for AppleTVOS - Experimental" On) + option(COMPILER_RT_ENABLE_WATCHOS "Enable building for AppleWatchOS - Experimental" On) find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx) find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator) find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos) + find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator) + find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos) + find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator) + find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos) # Note: In order to target x86_64h on OS X the minimum deployment target must # be 10.8 or higher. @@ -434,6 +448,125 @@ set(CAN_TARGET_${arch} 1) endforeach() endif() + + if(COMPILER_RT_ENABLE_TVOS) + if(DARWIN_tvossim_SYSROOT) + set(DARWIN_tvossim_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mtvos-simulator-version-min=9.0 + -isysroot ${DARWIN_tvossim_SYSROOT}) + set(DARWIN_tvossim_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mtvos-simulator-version-min=9.0 + -isysroot ${DARWIN_tvossim_SYSROOT}) + set(DARWIN_tvossim_BUILTIN_MIN_VER 9.0) + set(DARWIN_tvossim_BUILTIN_MIN_VER_FLAG + -mtvos-simulator-version-min=${DARWIN_tvossim_BUILTIN_MIN_VER}) + + set(DARWIN_tvossim_SKIP_CC_KEXT On) + darwin_test_archs(tvossim + DARWIN_tvossim_ARCHS + ${toolchain_arches}) + if(DARWIN_tvossim_ARCHS) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS tvossim) + endif() + message(STATUS "TVOS Simulator supported arches: ${DARWIN_tvossim_ARCHS}") + foreach(arch ${DARWIN_tvossim_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + + if(DARWIN_tvos_SYSROOT) + set(DARWIN_tvos_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mtvos-version-min=9.0 + -isysroot ${DARWIN_tvos_SYSROOT}) + set(DARWIN_tvos_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mtvos-version-min=9.0 + -isysroot ${DARWIN_tvos_SYSROOT}) + set(DARWIN_tvos_BUILTIN_MIN_VER 9.0) + set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG + -mtvos-version-min=${DARWIN_tvos_BUILTIN_MIN_VER}) + + darwin_test_archs(tvos + DARWIN_tvos_ARCHS + ${toolchain_arches}) + if(DARWIN_tvos_ARCHS) + list(REMOVE_ITEM DARWIN_tvos_ARCHS armv7s) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS tvos) + list(APPEND BUILTIN_SUPPORTED_OS tvos) + list(APPEND PROFILE_SUPPORTED_OS tvos) + list(APPEND BUILTIN_SUPPORTED_OS tvossim) + list(APPEND PROFILE_SUPPORTED_OS tvossim) + endif() + message(STATUS "AppleTV supported arches: ${DARWIN_tvos_ARCHS}") + foreach(arch ${DARWIN_tvos_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + endif() + + if(COMPILER_RT_ENABLE_WATCHOS) + if(DARWIN_watchossim_SYSROOT) + set(DARWIN_watchossim_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mwatchos-simulator-version-min=1.0 + -isysroot ${DARWIN_watchossim_SYSROOT}) + set(DARWIN_watchossim_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mwatchos-simulator-version-min=1.0 + -isysroot ${DARWIN_watchossim_SYSROOT}) + set(DARWIN_watchossim_BUILTIN_MIN_VER 1.0) + set(DARWIN_watchossim_BUILTIN_MIN_VER_FLAG + -mwatchos-simulator-version-min=${DARWIN_watchossim_BUILTIN_MIN_VER}) + + set(DARWIN_watchossim_SKIP_CC_KEXT On) + darwin_test_archs(watchossim + DARWIN_watchossim_ARCHS + ${toolchain_arches}) + if(DARWIN_watchossim_ARCHS) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS watchossim) + endif() + message(STATUS "Apple Watch Simulator supported arches: ${DARWIN_watchossim_ARCHS}") + foreach(arch ${DARWIN_watchossim_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + + if(DARWIN_watchos_SYSROOT) + set(DARWIN_watchos_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mwatchos-version-min=1.0 + -isysroot ${DARWIN_watchos_SYSROOT}) + set(DARWIN_watchos_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mwatchos-version-min=1.0 + -isysroot ${DARWIN_watchos_SYSROOT}) + set(DARWIN_watchos_BUILTIN_MIN_VER 1.0) + set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG + -mwatchos-version-min=${DARWIN_watchos_BUILTIN_MIN_VER}) + + darwin_test_archs(watchos + DARWIN_watchos_ARCHS + ${toolchain_arches}) + if(DARWIN_watchos_ARCHS) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS watchos) + list(APPEND BUILTIN_SUPPORTED_OS watchos) + list(APPEND PROFILE_SUPPORTED_OS watchos) + list(APPEND BUILTIN_SUPPORTED_OS watchossim) + list(APPEND PROFILE_SUPPORTED_OS watchossim) + endif() + message(STATUS "watchOS supported arches: ${DARWIN_watchos_ARCHS}") + foreach(arch ${DARWIN_watchos_ARCHS}) + list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) + set(CAN_TARGET_${arch} 1) + endforeach() + endif() + endif() endif() # for list_union Index: lib/asan/asan_internal.h =================================================================== --- lib/asan/asan_internal.h +++ lib/asan/asan_internal.h @@ -33,6 +33,12 @@ # define ASAN_HAS_EXCEPTIONS 1 #endif +#ifndef ASAN_LOW_MEMORY +#if SANITIZER_IOS +# define ASAN_LOW_MEMORY 1 +#endif +#endif + // If set, values like allocator chunk size, as well as defaults for some flags // will be changed towards less memory overhead. #ifndef ASAN_LOW_MEMORY Index: lib/asan/asan_mac.cc =================================================================== --- lib/asan/asan_mac.cc +++ lib/asan/asan_mac.cc @@ -36,6 +36,12 @@ #include #include +// from , but we don't have that file on iOS +extern "C" { + extern char ***_NSGetArgv(void); + extern char ***_NSGetEnviron(void); +} + namespace __asan { void InitializePlatformInterceptors() {} Index: lib/asan/asan_mapping.h =================================================================== --- lib/asan/asan_mapping.h +++ lib/asan/asan_mapping.h @@ -115,7 +115,7 @@ static const u64 kDefaultShadowOffset64 = 1ULL << 44; static const u64 kDefaultShort64bitShadowOffset = 0x7FFF8000; // < 2G. static const u64 kIosShadowOffset32 = 1ULL << 30; // 0x40000000 -static const u64 kIosShadowOffset64 = 0x130000000; +static const u64 kIosShadowOffset64 = 0x120200000; static const u64 kIosSimShadowOffset32 = 1ULL << 30; static const u64 kIosSimShadowOffset64 = kDefaultShadowOffset64; static const u64 kAArch64_ShadowOffset64 = 1ULL << 36; @@ -145,8 +145,14 @@ # else # define SHADOW_OFFSET kDefaultShadowOffset32 # endif -#else -# if defined(__aarch64__) +# else +# if SANITIZER_IOS +# if SANITIZER_IOSSIM +# define SHADOW_OFFSET kIosSimShadowOffset64 +# else +# define SHADOW_OFFSET kIosShadowOffset64 +# endif +# elif defined(__aarch64__) # define SHADOW_OFFSET kAArch64_ShadowOffset64 # elif defined(__powerpc64__) # define SHADOW_OFFSET kPPC64_ShadowOffset64 Index: lib/builtins/CMakeLists.txt =================================================================== --- lib/builtins/CMakeLists.txt +++ lib/builtins/CMakeLists.txt @@ -341,6 +341,7 @@ set(armhf_SOURCES ${arm_SOURCES}) set(armv7_SOURCES ${arm_SOURCES}) set(armv7s_SOURCES ${arm_SOURCES}) +set(armv7k_SOURCES ${arm_SOURCES}) set(arm64_SOURCES ${aarch64_SOURCES}) # macho_embedded archs Index: lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc +++ lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc @@ -53,25 +53,9 @@ _(FIONBIO, READ, sizeof(int)); _(FIONCLEX, NONE, 0); _(FIOSETOWN, READ, sizeof(int)); - _(SIOCADDMULTI, READ, struct_ifreq_sz); _(SIOCATMARK, WRITE, sizeof(int)); - _(SIOCDELMULTI, READ, struct_ifreq_sz); - _(SIOCGIFADDR, WRITE, struct_ifreq_sz); - _(SIOCGIFBRDADDR, WRITE, struct_ifreq_sz); _(SIOCGIFCONF, CUSTOM, 0); - _(SIOCGIFDSTADDR, WRITE, struct_ifreq_sz); - _(SIOCGIFFLAGS, WRITE, struct_ifreq_sz); - _(SIOCGIFMETRIC, WRITE, struct_ifreq_sz); - _(SIOCGIFMTU, WRITE, struct_ifreq_sz); - _(SIOCGIFNETMASK, WRITE, struct_ifreq_sz); _(SIOCGPGRP, WRITE, sizeof(int)); - _(SIOCSIFADDR, READ, struct_ifreq_sz); - _(SIOCSIFBRDADDR, READ, struct_ifreq_sz); - _(SIOCSIFDSTADDR, READ, struct_ifreq_sz); - _(SIOCSIFFLAGS, READ, struct_ifreq_sz); - _(SIOCSIFMETRIC, READ, struct_ifreq_sz); - _(SIOCSIFMTU, READ, struct_ifreq_sz); - _(SIOCSIFNETMASK, READ, struct_ifreq_sz); _(SIOCSPGRP, READ, sizeof(int)); _(TIOCCONS, NONE, 0); _(TIOCEXCL, NONE, 0); @@ -92,6 +76,25 @@ _(TIOCSTI, READ, sizeof(char)); _(TIOCSWINSZ, READ, struct_winsize_sz); +#if !SANITIZER_IOS + _(SIOCADDMULTI, READ, struct_ifreq_sz); + _(SIOCDELMULTI, READ, struct_ifreq_sz); + _(SIOCGIFADDR, WRITE, struct_ifreq_sz); + _(SIOCGIFBRDADDR, WRITE, struct_ifreq_sz); + _(SIOCGIFDSTADDR, WRITE, struct_ifreq_sz); + _(SIOCGIFFLAGS, WRITE, struct_ifreq_sz); + _(SIOCGIFMETRIC, WRITE, struct_ifreq_sz); + _(SIOCGIFMTU, WRITE, struct_ifreq_sz); + _(SIOCGIFNETMASK, WRITE, struct_ifreq_sz); + _(SIOCSIFADDR, READ, struct_ifreq_sz); + _(SIOCSIFBRDADDR, READ, struct_ifreq_sz); + _(SIOCSIFDSTADDR, READ, struct_ifreq_sz); + _(SIOCSIFFLAGS, READ, struct_ifreq_sz); + _(SIOCSIFMETRIC, READ, struct_ifreq_sz); + _(SIOCSIFMTU, READ, struct_ifreq_sz); + _(SIOCSIFNETMASK, READ, struct_ifreq_sz); +#endif + #if (SANITIZER_LINUX && !SANITIZER_ANDROID) _(SIOCGETSGCNT, WRITE, struct_sioc_sg_req_sz); _(SIOCGETVIFCNT, WRITE, struct_sioc_vif_req_sz); Index: lib/sanitizer_common/sanitizer_mac.cc =================================================================== --- lib/sanitizer_common/sanitizer_mac.cc +++ lib/sanitizer_common/sanitizer_mac.cc @@ -71,6 +71,12 @@ #include #include +// from , but we don't have that file on iOS +extern "C" { + extern char ***_NSGetArgv(void); + extern char ***_NSGetEnviron(void); +} + namespace __sanitizer { #include "sanitizer_syscall_generic.inc" @@ -352,7 +358,12 @@ } bool IsDeadlySignal(int signum) { +#if (SANITIZER_WATCHOS || SANITIZER_TVOS) && !SANITIZER_IOSSIM + // Handling fatal signals on watchOS and tvOS devices is disallowed. + return false; +#else return (signum == SIGSEGV || signum == SIGBUS) && common_flags()->handle_segv; +#endif } MacosVersion cached_macos_version = MACOS_VERSION_UNINITIALIZED; Index: lib/sanitizer_common/sanitizer_platform.h =================================================================== --- lib/sanitizer_common/sanitizer_platform.h +++ lib/sanitizer_common/sanitizer_platform.h @@ -35,6 +35,16 @@ # include # if TARGET_OS_IPHONE # define SANITIZER_IOS 1 +# if TARGET_OS_WATCH +# define SANITIZER_WATCHOS 1 +# else +# define SANITIZER_WATCHOS 0 +# endif +# if TARGET_OS_TV +# define SANITIZER_TVOS 1 +# else +# define SANITIZER_TVOS 0 +# endif # else # define SANITIZER_IOS 0 # endif Index: lib/sanitizer_common/sanitizer_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_posix.cc +++ lib/sanitizer_common/sanitizer_posix.cc @@ -89,7 +89,11 @@ uptr GetMaxVirtualAddress() { #if SANITIZER_WORDSIZE == 64 -# if defined(__powerpc64__) || defined(__aarch64__) +# if defined(__aarch64__) && SANITIZER_IOS && !SANITIZER_IOSSIM + // Ideally, we would derive the upper bound from MACH_VM_MAX_ADDRESS. The + // upper bound can change depending on the device. + return 0x200000000 - 1; +# elif defined(__powerpc64__) || defined(__aarch64__) // On PowerPC64 we have two different address space layouts: 44- and 46-bit. // We somehow need to figure out which one we are using now and choose // one of 0x00000fffffffffffUL and 0x00003fffffffffffUL. Index: lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc +++ lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc @@ -213,6 +213,10 @@ const char* const kSymbolizerArch = "--default-arch=x86_64"; #elif defined(__i386__) const char* const kSymbolizerArch = "--default-arch=i386"; +#elif defined(__aarch64__) + const char* const kSymbolizerArch = "--default-arch=arm64"; +#elif defined(__arm__) + const char* const kSymbolizerArch = "--default-arch=arm"; #elif defined(__powerpc64__) && defined(__BIG_ENDIAN__) const char* const kSymbolizerArch = "--default-arch=powerpc64"; #elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)