Home | History | Annotate | Download | only in asan
      1 # Build for the AddressSanitizer runtime support library.
      2 
      3 set(ASAN_SOURCES
      4   asan_allocator.cc
      5   asan_allocator2.cc
      6   asan_fake_stack.cc
      7   asan_globals.cc
      8   asan_interceptors.cc
      9   asan_linux.cc
     10   asan_mac.cc
     11   asan_malloc_linux.cc
     12   asan_malloc_mac.cc
     13   asan_malloc_win.cc
     14   asan_new_delete.cc
     15   asan_poisoning.cc
     16   asan_posix.cc
     17   asan_preinit.cc
     18   asan_report.cc
     19   asan_rtl.cc
     20   asan_stack.cc
     21   asan_stats.cc
     22   asan_thread.cc
     23   asan_thread_registry.cc
     24   asan_win.cc
     25   )
     26 
     27 set(ASAN_DYLIB_SOURCES
     28   ${ASAN_SOURCES}
     29   )
     30 
     31 include_directories(..)
     32 
     33 set(ASAN_CFLAGS
     34   ${SANITIZER_COMMON_CFLAGS}
     35   -fno-rtti)
     36 
     37 set(ASAN_COMMON_DEFINITIONS
     38   ASAN_HAS_EXCEPTIONS=1)
     39 
     40 if(ANDROID)
     41   list(APPEND ASAN_COMMON_DEFINITIONS
     42     ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
     43     ASAN_NEEDS_SEGV=0
     44     ASAN_LOW_MEMORY=1)
     45 else()
     46   list(APPEND ASAN_COMMON_DEFINITIONS
     47     ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
     48     ASAN_NEEDS_SEGV=1)
     49 endif()
     50 
     51 # Architectures supported by ASan.
     52 filter_available_targets(ASAN_SUPPORTED_ARCH
     53   x86_64 i386 powerpc64 powerpc)
     54 
     55 set(ASAN_RUNTIME_LIBRARIES)
     56 if(APPLE)
     57   # Build universal binary on APPLE.
     58   add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic
     59     ARCH ${ASAN_SUPPORTED_ARCH}
     60     SOURCES ${ASAN_DYLIB_SOURCES}
     61             $<TARGET_OBJECTS:RTInterception.osx>
     62             $<TARGET_OBJECTS:RTSanitizerCommon.osx>
     63     CFLAGS ${ASAN_CFLAGS}
     64     DEFS ${ASAN_COMMON_DEFINITIONS}
     65     # Dynamic lookup is needed because shadow scale and offset are
     66     # provided by the instrumented modules.
     67     LINKFLAGS "-framework Foundation"
     68               "-undefined dynamic_lookup")
     69   list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic)
     70 elseif(ANDROID)
     71   add_library(clang_rt.asan-arm-android SHARED
     72     ${ASAN_SOURCES}
     73     $<TARGET_OBJECTS:RTInterception.arm.android>
     74     $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>
     75     )
     76   set_target_compile_flags(clang_rt.asan-arm-android
     77     ${ASAN_CFLAGS})
     78   set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
     79     COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
     80   target_link_libraries(clang_rt.asan-arm-android dl)
     81   list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
     82 else()
     83   # Otherwise, build separate libraries for each target.
     84   foreach(arch ${ASAN_SUPPORTED_ARCH})
     85     add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
     86       SOURCES ${ASAN_SOURCES}
     87               $<TARGET_OBJECTS:RTInterception.${arch}>
     88               $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
     89       CFLAGS ${ASAN_CFLAGS}
     90       DEFS ${ASAN_COMMON_DEFINITIONS})
     91     list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
     92   endforeach()
     93 endif()
     94 
     95 if(LLVM_INCLUDE_TESTS)
     96   add_subdirectory(tests)
     97 endif()
     98 
     99 add_subdirectory(lit_tests)
    100