1import("//compiler-rt/target.gni") 2 3source_set("cxx_sources") { 4 configs -= [ "//llvm/utils/gn/build:llvm_code" ] 5 configs += [ "//llvm/utils/gn/build:crt_code" ] 6 sources = [ "asan_new_delete.cpp" ] 7} 8 9if (current_os == "mac") { 10 asan_target_type = "shared_library" 11} else { 12 asan_target_type = "static_library" 13} 14 15target(asan_target_type, "asan") { 16 configs -= [ "//llvm/utils/gn/build:llvm_code" ] 17 configs += [ "//llvm/utils/gn/build:crt_code" ] 18 19 output_dir = crt_current_out_dir 20 if (current_os == "mac") { 21 output_name = "clang_rt.asan_osx_dynamic" 22 } else { 23 assert(current_os != "win", "FIXME") 24 output_name = "clang_rt.asan$crt_current_target_suffix" 25 } 26 27 deps = [ 28 "//compiler-rt/lib/interception:sources", 29 "//compiler-rt/lib/lsan:common_sources", 30 "//compiler-rt/lib/sanitizer_common:sources", 31 "//compiler-rt/lib/ubsan:cxx_sources", 32 "//compiler-rt/lib/ubsan:sources", 33 ] 34 35 if (asan_target_type == "static_library") { 36 complete_static_lib = true 37 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 38 deps += [ ":asan_cxx" ] 39 } else { 40 deps += [ ":cxx_sources" ] 41 defines = [ "ASAN_DYNAMIC" ] 42 } 43 44 sources = [ 45 "asan_activation.cpp", 46 "asan_activation.h", 47 "asan_activation_flags.inc", 48 "asan_allocator.cpp", 49 "asan_allocator.h", 50 "asan_debugging.cpp", 51 "asan_descriptions.cpp", 52 "asan_descriptions.h", 53 "asan_errors.cpp", 54 "asan_errors.h", 55 "asan_fake_stack.cpp", 56 "asan_fake_stack.h", 57 "asan_flags.cpp", 58 "asan_flags.h", 59 "asan_flags.inc", 60 "asan_fuchsia.cpp", 61 "asan_globals.cpp", 62 "asan_globals_win.cpp", 63 "asan_init_version.h", 64 "asan_interceptors.cpp", 65 "asan_interceptors.h", 66 "asan_interceptors_memintrinsics.cpp", 67 "asan_interceptors_memintrinsics.h", 68 "asan_interface.inc", 69 "asan_interface_internal.h", 70 "asan_internal.h", 71 "asan_linux.cpp", 72 "asan_lock.h", 73 "asan_mac.cpp", 74 "asan_malloc_linux.cpp", 75 "asan_malloc_local.h", 76 "asan_malloc_mac.cpp", 77 "asan_malloc_win.cpp", 78 "asan_mapping.h", 79 "asan_mapping_myriad.h", 80 "asan_memory_profile.cpp", 81 "asan_poisoning.cpp", 82 "asan_poisoning.h", 83 "asan_posix.cpp", 84 "asan_premap_shadow.cpp", 85 "asan_premap_shadow.h", 86 "asan_report.cpp", 87 "asan_report.h", 88 "asan_rtems.cpp", 89 "asan_rtl.cpp", 90 "asan_scariness_score.h", 91 "asan_shadow_setup.cpp", 92 "asan_stack.cpp", 93 "asan_stack.h", 94 "asan_stats.cpp", 95 "asan_stats.h", 96 "asan_suppressions.cpp", 97 "asan_suppressions.h", 98 "asan_thread.cpp", 99 "asan_thread.h", 100 "asan_win.cpp", 101 ] 102 if (target_os != "mac" && target_os != "win") { 103 sources += [ "asan_interceptors_vfork.S" ] 104 } 105 106 # To be able to include sanitizer_common. 107 include_dirs = [ ".." ] 108 109 # FIXME: have SANITIZER_COMMON_CFLAGS thingy? should fno-builtin be in 110 # crt_code? 111 cflags = [ "-fno-builtin" ] 112 if (target_os != "win") { 113 cflags += [ "-ftls-model=initial-exec" ] 114 } 115 116 # FIXME: link rt dl m pthread log 117 # FIXME: dep on libcxx-headers? 118 # FIXME: add_sanitizer_rt_version_list (cf hwasan) 119 # FIXME: need libclang_rt.asan*.a.syms? 120 # FIXME: windows flags (-Zl -nodefaultlibs) 121 # FIXME: asan_blacklist.txt 122 123 if (target_os == "android") { 124 ldflags = [ "-Wl,-z,global" ] 125 } 126 127 if (target_os == "mac") { 128 # The -U flags below correspond to the add_weak_symbols() calls in CMake. 129 ldflags = [ 130 "-lc++", 131 "-lc++abi", 132 133 # asan 134 "-Wl,-U,___asan_default_options", 135 "-Wl,-U,___asan_default_suppressions", 136 "-Wl,-U,___asan_on_error", 137 "-Wl,-U,___asan_set_shadow_00", 138 "-Wl,-U,___asan_set_shadow_f1", 139 "-Wl,-U,___asan_set_shadow_f2", 140 "-Wl,-U,___asan_set_shadow_f3", 141 "-Wl,-U,___asan_set_shadow_f4", 142 "-Wl,-U,___asan_set_shadow_f5", 143 "-Wl,-U,___asan_set_shadow_f6", 144 "-Wl,-U,___asan_set_shadow_f7", 145 "-Wl,-U,___asan_set_shadow_f8", 146 147 # lsan 148 "-Wl,-U,___lsan_default_options", 149 "-Wl,-U,___lsan_default_suppressions", 150 "-Wl,-U,___lsan_is_turned_off", 151 152 # ubsan 153 "-Wl,-U,___ubsan_default_options", 154 155 # sanitizer_common 156 "-Wl,-U,___sanitizer_free_hook", 157 "-Wl,-U,___sanitizer_malloc_hook", 158 "-Wl,-U,___sanitizer_report_error_summary", 159 "-Wl,-U,___sanitizer_sandbox_on_notify", 160 "-Wl,-U,___sanitizer_symbolize_code", 161 "-Wl,-U,___sanitizer_symbolize_data", 162 "-Wl,-U,___sanitizer_symbolize_demangle", 163 "-Wl,-U,___sanitizer_symbolize_flush", 164 165 # xray 166 "-Wl,-U,___start_xray_fn_idx", 167 "-Wl,-U,___start_xray_instr_map", 168 "-Wl,-U,___stop_xray_fn_idx", 169 "-Wl,-U,___stop_xray_instr_map", 170 171 # FIXME: better 172 "-Wl,-install_name,@rpath/libclang_rt.asan_osx_dynamic.dylib", 173 ] 174 # FIXME: -Wl,-rpath 175 # FIXME: codesign (??) 176 } 177} 178 179if (asan_target_type == "static_library") { 180 static_library("asan_cxx") { 181 assert(current_os != "win", "FIXME") 182 output_dir = crt_current_out_dir 183 output_name = "clang_rt.asan_cxx$crt_current_target_suffix" 184 complete_static_lib = true 185 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 186 deps = [ ":cxx_sources" ] 187 } 188} 189 190# FIXME: Move these to real targets. 191source_set("unused") { 192 sources = [ 193 "asan_preinit.cpp", 194 "asan_win_dll_thunk.cpp", 195 "asan_win_dynamic_runtime_thunk.cpp", 196 ] 197} 198