[PATCH] [ASan] Add CMake configs for libclang_rt.asan_iossim_dynamic.dylib
Alexander Potapenko
glider at google.com
Thu Oct 31 10:59:42 PDT 2013
Hi samsonov, ddunbar,
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.
http://llvm-reviews.chandlerc.com/D2080
Files:
../projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake
../projects/compiler-rt/lib/asan/CMakeLists.txt
../projects/compiler-rt/lib/interception/CMakeLists.txt
../projects/compiler-rt/lib/lsan/CMakeLists.txt
../projects/compiler-rt/lib/sanitizer_common/CMakeLists.txt
Index: ../projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake
===================================================================
--- ../projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ ../projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -2,6 +2,15 @@
include(LLVMParseArguments)
include(CompilerRTUtils)
+execute_process(
+ COMMAND xcodebuild -version -sdk iphonesimulator Path
+ OUTPUT_VARIABLE iossim_sdk_path
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+set(LIB_CFLAGS_IOSSIM
+ ${LIB_CFLAGS} -mios-simulator-version-min=7.0 -isysroot ${iossim_sdk_path}
+)
+
# Tries to add "object library" target for a given architecture
# with name "<name>.<arch>" if architecture can be targeted.
# add_compiler_rt_object_library(<name> <arch>
@@ -37,6 +46,28 @@
COMPILE_DEFINITIONS ${LIB_DEFS})
endmacro()
+if (iossim_sdk_path)
+# Same as above, but adds universal osx library with name "<name>.iossim"
+# targeting multiple architectures on the iOS simulator.
+# add_compiler_rt_iossim_object_library(<name> ARCH <architectures>
+# SOURCES <source files>
+# CFLAGS <compile flags>)
+# DEFS <compile definitions>)
+macro(add_compiler_rt_iossim_object_library name)
+ parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
+ set(libname "${name}.iossim")
+ add_library(${libname} OBJECT ${LIB_SOURCES})
+ set_target_compile_flags(${libname} ${LIB_CFLAGS_IOSSIM})
+ set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
+ set_property(TARGET ${libname} APPEND PROPERTY
+ COMPILE_DEFINITIONS ${LIB_DEFS})
+endmacro()
+else()
+macro(add_compiler_rt_object_library_iossim name arch)
+ add_custom_target(${name})
+endmacro()
+endif()
+
# Adds static runtime for a given architecture and puts it in the proper
# directory in the build and install trees.
# add_compiler_rt_static_runtime(<name> <arch>
@@ -105,6 +136,41 @@
add_dependencies(compiler-rt ${name})
endmacro()
+
+
+if (iossim_sdk_path)
+# Adds an iOS simulator dynamic runtime library on osx.
+# This cannot be in the same multiarch library as the x86 ones.
+# add_compiler_rt_iossim_dynamic_runtime(<name> ARCH <architectures>
+# SOURCES <source files>
+# CFLAGS <compile flags>
+# DEFS <compile definitions>
+# LINKFLAGS <link flags>)
+macro(add_compiler_rt_iossim_dynamic_runtime name)
+ parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
+ add_library(${name} SHARED ${LIB_SOURCES})
+ set_target_compile_flags(${name} ${LIB_CFLAGS_IOSSIM})
+ set_target_link_flags(${name} ${LIB_LINKFLAGS}
+ -Wl,-ios_simulator_version_min,7.0.0
+ -Wl,-syslibroot,${iossim_sdk_path}
+ )
+ set_property(TARGET ${name} APPEND PROPERTY
+ COMPILE_DEFINITIONS ${LIB_DEFS})
+ set_target_properties(${name} PROPERTIES
+ OSX_ARCHITECTURES "${LIB_ARCH}"
+ LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ install(TARGETS ${name}
+ LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ add_dependencies(compiler-rt ${name})
+endmacro()
+
+else()
+
+macro(add_compiler_rt_iossim_dynamic_runtime name)
+ add_custom_target(${name})
+endmacro()
+endif()
+
# Unittests support.
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc)
Index: ../projects/compiler-rt/lib/asan/CMakeLists.txt
===================================================================
--- ../projects/compiler-rt/lib/asan/CMakeLists.txt
+++ ../projects/compiler-rt/lib/asan/CMakeLists.txt
@@ -62,6 +62,11 @@
SOURCES ${ASAN_SOURCES}
CFLAGS ${ASAN_CFLAGS}
DEFS ${ASAN_COMMON_DEFINITIONS})
+ add_compiler_rt_iossim_object_library(RTAsan
+ ARCH ${ASAN_SUPPORTED_ARCH}
+ SOURCES ${ASAN_SOURCES}
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS})
elseif(ANDROID)
add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
@@ -91,6 +96,20 @@
LINKFLAGS "-framework Foundation"
"-undefined dynamic_lookup")
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic)
+ add_compiler_rt_iossim_dynamic_runtime(clang_rt.asan_iossim_dynamic
+ ARCH ${ASAN_SUPPORTED_ARCH}
+ SOURCES $<TARGET_OBJECTS:RTAsan.iossim>
+ $<TARGET_OBJECTS:RTInterception.iossim>
+ $<TARGET_OBJECTS:RTSanitizerCommon.iossim>
+ $<TARGET_OBJECTS:RTLSanCommon.iossim>
+ CFLAGS ${ASAN_CFLAGS} -mios-simulator-version-min=7.0
+ DEFS ${ASAN_COMMON_DEFINITIONS}
+ # Dynamic lookup is needed because shadow scale and offset are
+ # provided by the instrumented modules.
+ LINKFLAGS "-undefined dynamic_lookup" -mios-simulator-version-min=7.0
+ )
+ list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_iossim_dynamic)
+
elseif(ANDROID)
add_library(clang_rt.asan-arm-android SHARED
$<TARGET_OBJECTS:RTAsan.arm.android>
Index: ../projects/compiler-rt/lib/interception/CMakeLists.txt
===================================================================
--- ../projects/compiler-rt/lib/interception/CMakeLists.txt
+++ ../projects/compiler-rt/lib/interception/CMakeLists.txt
@@ -17,6 +17,10 @@
ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
SOURCES ${INTERCEPTION_SOURCES}
CFLAGS ${INTERCEPTION_CFLAGS})
+ add_compiler_rt_iossim_object_library(RTInterception
+ ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES ${INTERCEPTION_SOURCES}
+ CFLAGS ${INTERCEPTION_CFLAGS})
elseif(ANDROID)
add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES})
set_target_compile_flags(RTInterception.arm.android
Index: ../projects/compiler-rt/lib/lsan/CMakeLists.txt
===================================================================
--- ../projects/compiler-rt/lib/lsan/CMakeLists.txt
+++ ../projects/compiler-rt/lib/lsan/CMakeLists.txt
@@ -32,6 +32,10 @@
ARCH ${LSAN_COMMON_SUPPORTED_ARCH}
SOURCES ${LSAN_COMMON_SOURCES}
CFLAGS ${LSAN_CFLAGS})
+ add_compiler_rt_iossim_object_library(RTLSanCommon
+ ARCH ${LSAN_COMMON_SUPPORTED_ARCH}
+ SOURCES ${LSAN_COMMON_SOURCES}
+ CFLAGS ${LSAN_CFLAGS})
elseif(NOT ANDROID)
foreach(arch ${LSAN_COMMON_SUPPORTED_ARCH})
add_compiler_rt_object_library(RTLSanCommon ${arch}
Index: ../projects/compiler-rt/lib/sanitizer_common/CMakeLists.txt
===================================================================
--- ../projects/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ ../projects/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -83,6 +83,11 @@
SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES}
CFLAGS ${SANITIZER_CFLAGS})
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.osx)
+ add_compiler_rt_iossim_object_library(RTSanitizerCommon
+ ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES}
+ CFLAGS ${SANITIZER_CFLAGS})
+ list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.iossim)
elseif(ANDROID)
add_library(RTSanitizerCommon.arm.android OBJECT
${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2080.1.patch
Type: text/x-patch
Size: 7329 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131031/12371965/attachment.bin>
More information about the llvm-commits
mailing list