summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2013-11-07 10:08:19 +0000
committerAlexander Potapenko <glider@google.com>2013-11-07 10:08:19 +0000
commit49496747758bf44163768ce3e07e40c8f95ccba9 (patch)
tree894adbc0718aac47996d64de69114deb53d72953
parentf16dc4234098a22a9d0d56f0198d87905481e7fd (diff)
downloadcompiler-rt-49496747758bf44163768ce3e07e40c8f95ccba9.tar.gz
compiler-rt-49496747758bf44163768ce3e07e40c8f95ccba9.tar.bz2
compiler-rt-49496747758bf44163768ce3e07e40c8f95ccba9.tar.xz
[ASan] Add CMake configs for libclang_rt.asan_iossim_dynamic.dylib
CMake changes to build the ASan runtime for the iOS simulator. This is a universal library targeting the same architectures as the OSX ASan runtime does, thus the iossim version can't live in the same universal libclang_rt.asan_osx_dynamic.dylib The difference between the OSX and iossim builds is in the -mios-simulator-version-min and -ios_simulator_version_min flags that tell Clang to compile and link iossim code. The iossim runtime can only be built on a machine with both Xcode and the iOS Simulator SDK installed. If xcodebuild -version -sdk iphonesimulator Path returns a nonempty path, it is used when compiling and linking the iossim runtime. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194199 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt22
-rw-r--r--cmake/Modules/AddCompilerRT.cmake38
-rw-r--r--lib/asan/CMakeLists.txt41
-rw-r--r--lib/interception/CMakeLists.txt10
-rw-r--r--lib/lsan/CMakeLists.txt10
-rw-r--r--lib/sanitizer_common/CMakeLists.txt12
6 files changed, 83 insertions, 50 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2d968beb..2cd09be9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -180,15 +180,31 @@ endif()
check_cxx_compiler_flag(-Wglobal-constructors SUPPORTS_GLOBAL_CONSTRUCTORS_FLAG)
# Not all sanitizers forbid global constructors.
-# Setup min Mac OS X version.
if(APPLE)
+ # Obtain the iOS Simulator SDK path from xcodebuild.
+ execute_process(
+ COMMAND xcodebuild -version -sdk iphonesimulator Path
+ OUTPUT_VARIABLE IOSSIM_SDK_DIR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ set(SANITIZER_COMMON_SUPPORTED_DARWIN_OS osx)
+ if (IOSSIM_SDK_DIR)
+ list(APPEND SANITIZER_COMMON_SUPPORTED_DARWIN_OS iossim)
+ endif()
+
if(COMPILER_RT_USES_LIBCXX)
set(SANITIZER_MIN_OSX_VERSION 10.7)
else()
set(SANITIZER_MIN_OSX_VERSION 10.6)
endif()
- list(APPEND SANITIZER_COMMON_CFLAGS
- -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
+ set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
+ set(DARWIN_iossim_CFLAGS
+ -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR})
+ set(DARWIN_osx_LINKFLAGS)
+ set(DARWIN_iossim_LINKFLAGS
+ -Wl,-ios_simulator_version_min,7.0.0
+ -mios-simulator-version-min=7.0
+ -Wl,-syslibroot,${IOSSIM_SDK_DIR})
endif()
# Architectures supported by Sanitizer runtimes. Specific sanitizers may
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index def0c071..eee23ea6 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -21,17 +21,17 @@ macro(add_compiler_rt_object_library name arch)
endif()
endmacro()
-# Same as above, but adds universal osx library with name "<name>.osx"
-# targeting multiple architectures.
-# add_compiler_rt_osx_object_library(<name> ARCH <architectures>
-# SOURCES <source files>
-# CFLAGS <compile flags>)
-# DEFS <compile definitions>)
-macro(add_compiler_rt_osx_object_library name)
+# Same as above, but adds universal osx library for either OSX or iOS simulator
+# with name "<name>.<os>" targeting multiple architectures.
+# add_compiler_rt_darwin_object_library(<name> <os> ARCH <architectures>
+# SOURCES <source files>
+# CFLAGS <compile flags>
+# DEFS <compile definitions>)
+macro(add_compiler_rt_darwin_object_library name os)
parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
- set(libname "${name}.osx")
+ set(libname "${name}.${os}")
add_library(${libname} OBJECT ${LIB_SOURCES})
- set_target_compile_flags(${libname} ${LIB_CFLAGS})
+ set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
@@ -84,17 +84,19 @@ macro(add_compiler_rt_osx_static_runtime name)
add_dependencies(compiler-rt ${name})
endmacro()
-# Adds dynamic runtime library on osx, which supports multiple architectures.
-# add_compiler_rt_osx_dynamic_runtime(<name> ARCH <architectures>
-# SOURCES <source files>
-# CFLAGS <compile flags>
-# DEFS <compile definitions>
-# LINKFLAGS <link flags>)
-macro(add_compiler_rt_osx_dynamic_runtime name)
+# Adds dynamic runtime library on osx/iossim, which supports multiple
+# architectures.
+# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
+# ARCH <architectures>
+# SOURCES <source files>
+# CFLAGS <compile flags>
+# DEFS <compile definitions>
+# LINKFLAGS <link flags>)
+macro(add_compiler_rt_darwin_dynamic_runtime name os)
parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
add_library(${name} SHARED ${LIB_SOURCES})
- set_target_compile_flags(${name} ${LIB_CFLAGS})
- set_target_link_flags(${name} ${LIB_LINKFLAGS})
+ 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
diff --git a/lib/asan/CMakeLists.txt b/lib/asan/CMakeLists.txt
index 17552b3a..ba5dc05d 100644
--- a/lib/asan/CMakeLists.txt
+++ b/lib/asan/CMakeLists.txt
@@ -57,11 +57,13 @@ filter_available_targets(ASAN_SUPPORTED_ARCH
# Compile ASan sources into an object library.
if(APPLE)
- add_compiler_rt_osx_object_library(RTAsan
- ARCH ${ASAN_SUPPORTED_ARCH}
- SOURCES ${ASAN_SOURCES}
- CFLAGS ${ASAN_CFLAGS}
- DEFS ${ASAN_COMMON_DEFINITIONS})
+ foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
+ add_compiler_rt_darwin_object_library(RTAsan ${os}
+ ARCH ${ASAN_SUPPORTED_ARCH}
+ SOURCES ${ASAN_SOURCES}
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS})
+ endforeach()
elseif(ANDROID)
add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
@@ -78,19 +80,26 @@ endif()
# Build ASan runtimes shipped with Clang.
set(ASAN_RUNTIME_LIBRARIES)
if(APPLE)
- add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic
- ARCH ${ASAN_SUPPORTED_ARCH}
- SOURCES $<TARGET_OBJECTS:RTAsan.osx>
- $<TARGET_OBJECTS:RTInterception.osx>
- $<TARGET_OBJECTS:RTSanitizerCommon.osx>
- $<TARGET_OBJECTS:RTLSanCommon.osx>
- CFLAGS ${ASAN_CFLAGS}
- DEFS ${ASAN_COMMON_DEFINITIONS}
+ foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
# Dynamic lookup is needed because shadow scale and offset are
# provided by the instrumented modules.
- LINKFLAGS "-framework Foundation"
- "-undefined dynamic_lookup")
- list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic)
+ set(ASAN_RUNTIME_LDFLAGS
+ "-undefined dynamic_lookup")
+ if (os STREQUAL "osx")
+ list(APPEND ASAN_RUNTIME_LDFLAGS "-framework Foundation")
+ endif()
+ add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
+ ARCH ${ASAN_SUPPORTED_ARCH}
+ SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
+ $<TARGET_OBJECTS:RTInterception.${os}>
+ $<TARGET_OBJECTS:RTSanitizerCommon.${os}>
+ $<TARGET_OBJECTS:RTLSanCommon.${os}>
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS}
+ LINKFLAGS ${ASAN_RUNTIME_LDFLAGS})
+ list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic)
+ endforeach()
+
elseif(ANDROID)
add_library(clang_rt.asan-arm-android SHARED
$<TARGET_OBJECTS:RTAsan.arm.android>
diff --git a/lib/interception/CMakeLists.txt b/lib/interception/CMakeLists.txt
index cd9e6e75..1dfdaffb 100644
--- a/lib/interception/CMakeLists.txt
+++ b/lib/interception/CMakeLists.txt
@@ -13,10 +13,12 @@ set(INTERCEPTION_CFLAGS ${SANITIZER_COMMON_CFLAGS})
if(APPLE)
# Build universal binary on APPLE.
- add_compiler_rt_osx_object_library(RTInterception
- ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
- SOURCES ${INTERCEPTION_SOURCES}
- CFLAGS ${INTERCEPTION_CFLAGS})
+ foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
+ add_compiler_rt_darwin_object_library(RTInterception ${os}
+ ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES ${INTERCEPTION_SOURCES}
+ CFLAGS ${INTERCEPTION_CFLAGS})
+ endforeach()
elseif(ANDROID)
add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES})
set_target_compile_flags(RTInterception.arm.android
diff --git a/lib/lsan/CMakeLists.txt b/lib/lsan/CMakeLists.txt
index b91b675d..b2e88bca 100644
--- a/lib/lsan/CMakeLists.txt
+++ b/lib/lsan/CMakeLists.txt
@@ -28,10 +28,12 @@ filter_available_targets(LSAN_SUPPORTED_ARCH
set(LSAN_RUNTIME_LIBRARIES)
if(APPLE)
- add_compiler_rt_osx_object_library(RTLSanCommon
- ARCH ${LSAN_COMMON_SUPPORTED_ARCH}
- SOURCES ${LSAN_COMMON_SOURCES}
- CFLAGS ${LSAN_CFLAGS})
+ foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
+ add_compiler_rt_darwin_object_library(RTLSanCommon ${os}
+ ARCH ${LSAN_COMMON_SUPPORTED_ARCH}
+ SOURCES ${LSAN_COMMON_SOURCES}
+ CFLAGS ${LSAN_CFLAGS})
+ endforeach()
elseif(NOT ANDROID)
foreach(arch ${LSAN_COMMON_SUPPORTED_ARCH})
add_compiler_rt_object_library(RTLSanCommon ${arch}
diff --git a/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt
index 8c2f2e40..4ec37195 100644
--- a/lib/sanitizer_common/CMakeLists.txt
+++ b/lib/sanitizer_common/CMakeLists.txt
@@ -79,11 +79,13 @@ endif()
set(SANITIZER_RUNTIME_LIBRARIES)
if(APPLE)
# Build universal binary on APPLE.
- add_compiler_rt_osx_object_library(RTSanitizerCommon
- ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
- SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES}
- CFLAGS ${SANITIZER_CFLAGS})
- list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.osx)
+ foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
+ add_compiler_rt_darwin_object_library(RTSanitizerCommon ${os}
+ ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES}
+ CFLAGS ${SANITIZER_CFLAGS})
+ list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${os})
+ endforeach()
elseif(ANDROID)
add_library(RTSanitizerCommon.arm.android OBJECT
${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES})