[compiler-rt] r194199 - [ASan] Add CMake configs for libclang_rt.asan_iossim_dynamic.dylib

Alexander Potapenko glider at google.com
Thu Nov 7 02:08:20 PST 2013


Author: glider
Date: Thu Nov  7 04:08:19 2013
New Revision: 194199

URL: http://llvm.org/viewvc/llvm-project?rev=194199&view=rev
Log:
[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.

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/interception/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Thu Nov  7 04:08:19 2013
@@ -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

Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Thu Nov  7 04:08:19 2013
@@ -21,17 +21,17 @@ macro(add_compiler_rt_object_library nam
   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
   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

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Thu Nov  7 04:08:19 2013
@@ -57,11 +57,13 @@ filter_available_targets(ASAN_SUPPORTED_
 
 # 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>

Modified: compiler-rt/trunk/lib/interception/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/interception/CMakeLists.txt Thu Nov  7 04:08:19 2013
@@ -13,10 +13,12 @@ set(INTERCEPTION_CFLAGS ${SANITIZER_COMM
 
 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

Modified: compiler-rt/trunk/lib/lsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Thu Nov  7 04:08:19 2013
@@ -28,10 +28,12 @@ filter_available_targets(LSAN_SUPPORTED_
 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}

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=194199&r1=194198&r2=194199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Thu Nov  7 04:08:19 2013
@@ -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})





More information about the llvm-commits mailing list