brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.0 KiB · 483d56b Raw
297 lines · plain
1import("//compiler-rt/target.gni")2 3if (current_toolchain == host_toolchain) {4  copy("ignorelist") {5    sources = [ "asan_ignorelist.txt" ]6    outputs = [ "$clang_resource_dir/share/{{source_target_relative}}" ]7  }8} else {9  asan_sources = [10    "asan_aix.cpp",11    "asan_activation.cpp",12    "asan_activation.h",13    "asan_activation_flags.inc",14    "asan_allocator.cpp",15    "asan_allocator.h",16    "asan_debugging.cpp",17    "asan_descriptions.cpp",18    "asan_descriptions.h",19    "asan_errors.cpp",20    "asan_errors.h",21    "asan_fake_stack.cpp",22    "asan_fake_stack.h",23    "asan_flags.cpp",24    "asan_flags.h",25    "asan_flags.inc",26    "asan_fuchsia.cpp",27    "asan_globals.cpp",28    "asan_globals_win.cpp",29    "asan_init_version.h",30    "asan_interceptors.cpp",31    "asan_interceptors.h",32    "asan_interceptors_memintrinsics.cpp",33    "asan_interceptors_memintrinsics.h",34    "asan_interface.inc",35    "asan_interface_internal.h",36    "asan_internal.h",37    "asan_linux.cpp",38    "asan_mac.cpp",39    "asan_malloc_linux.cpp",40    "asan_malloc_mac.cpp",41    "asan_malloc_win.cpp",42    "asan_mapping.h",43    "asan_memory_profile.cpp",44    "asan_poisoning.cpp",45    "asan_poisoning.h",46    "asan_posix.cpp",47    "asan_premap_shadow.cpp",48    "asan_premap_shadow.h",49    "asan_report.cpp",50    "asan_report.h",51    "asan_rtl.cpp",52    "asan_scariness_score.h",53    "asan_shadow_setup.cpp",54    "asan_stack.cpp",55    "asan_stack.h",56    "asan_stats.cpp",57    "asan_stats.h",58    "asan_suppressions.cpp",59    "asan_suppressions.h",60    "asan_thread.cpp",61    "asan_thread.h",62    "asan_win.cpp",63  ]64  if (current_os != "mac" && current_os != "win") {65    asan_sources += [ "asan_interceptors_vfork.S" ]66  }67  config("asan_config") {68    cflags = []69    if (current_os != "win") {70      cflags += [ "-ftls-model=initial-exec" ]71    } else {72      cflags += [ "/MD" ]73      ldflags = [ "/OPT:NOICF" ]74    }75 76    # FIXME: link rt dl m pthread log77    # FIXME: dep on libcxx-headers?78    # FIXME: add_sanitizer_rt_version_list (cf hwasan)79    # FIXME: need libclang_rt.asan*.a.syms?80 81    if (current_os == "android") {82      ldflags = [ "-Wl,-z,global" ]83    }84 85    if (current_os == "mac") {86      # The -U flags below correspond to the add_weak_symbols() calls in CMake.87      ldflags = [88        "-lc++",89        "-lc++abi",90 91        # asan92        "-Wl,-U,___asan_default_options",93        "-Wl,-U,___asan_default_suppressions",94        "-Wl,-U,___asan_on_error",95        "-Wl,-U,___asan_set_shadow_00",96        "-Wl,-U,___asan_set_shadow_f1",97        "-Wl,-U,___asan_set_shadow_f2",98        "-Wl,-U,___asan_set_shadow_f3",99        "-Wl,-U,___asan_set_shadow_f4",100        "-Wl,-U,___asan_set_shadow_f5",101        "-Wl,-U,___asan_set_shadow_f6",102        "-Wl,-U,___asan_set_shadow_f7",103        "-Wl,-U,___asan_set_shadow_f8",104 105        # lsan106        "-Wl,-U,___lsan_default_options",107        "-Wl,-U,___lsan_default_suppressions",108        "-Wl,-U,___lsan_is_turned_off",109 110        # ubsan111        "-Wl,-U,___ubsan_default_options",112 113        # sanitizer_common114        "-Wl,-U,___sanitizer_free_hook",115        "-Wl,-U,___sanitizer_malloc_hook",116        "-Wl,-U,___sanitizer_report_error_summary",117        "-Wl,-U,___sanitizer_sandbox_on_notify",118        "-Wl,-U,___sanitizer_symbolize_code",119        "-Wl,-U,___sanitizer_symbolize_data",120        "-Wl,-U,___sanitizer_symbolize_frame",121        "-Wl,-U,___sanitizer_symbolize_demangle",122        "-Wl,-U,___sanitizer_symbolize_flush",123        "-Wl,-U,___sanitizer_symbolize_set_demangle",124        "-Wl,-U,___sanitizer_symbolize_set_inline_frames",125 126        # xray127        "-Wl,-U,___start_xray_fn_idx",128        "-Wl,-U,___start_xray_instr_map",129        "-Wl,-U,___stop_xray_fn_idx",130        "-Wl,-U,___stop_xray_instr_map",131 132        # FIXME: better133        "-Wl,-install_name,@rpath/libclang_rt.asan_osx_dynamic.dylib",134      ]135      # FIXME: -Wl,-rpath136      # FIXME: codesign (??)137    }138  }139 140  source_set("cxx_sources") {141    configs -= [ "//llvm/utils/gn/build:llvm_code" ]142    configs += [ "//llvm/utils/gn/build:crt_code" ]143    sources = [ "asan_new_delete.cpp" ]144  }145 146  source_set("static_sources") {147    configs -= [ "//llvm/utils/gn/build:llvm_code" ]148    configs += [ "//llvm/utils/gn/build:crt_code" ]149    sources = [ "asan_rtl_static.cpp" ]150    if (current_os != "mac" && current_os != "win") {151      sources += [ "asan_rtl_x86_64.S" ]152    }153  }154 155  source_set("preinit_sources") {156    configs -= [ "//llvm/utils/gn/build:llvm_code" ]157    configs += [ "//llvm/utils/gn/build:crt_code" ]158    sources = [ "asan_preinit.cpp" ]159  }160 161  shared_library("asan_shared_library") {162    output_dir = crt_current_out_dir163    if (current_os == "mac") {164      output_name = "clang_rt.asan_osx_dynamic"165    } else if (current_os == "win") {166      output_name = "clang_rt.asan_dynamic$crt_current_target_suffix"167    } else {168      output_name = "clang_rt.asan$crt_current_target_suffix"169    }170    configs -= [ "//llvm/utils/gn/build:llvm_code" ]171    configs += [ "//llvm/utils/gn/build:crt_code" ]172    configs += [ ":asan_config" ]173    sources = asan_sources174    deps = [175      ":cxx_sources",176      "//compiler-rt/lib/interception:sources",177      "//compiler-rt/lib/lsan:common_sources",178      "//compiler-rt/lib/sanitizer_common:sources",179      "//compiler-rt/lib/ubsan:cxx_sources",180      "//compiler-rt/lib/ubsan:sources",181    ]182    defines = [ "ASAN_DYNAMIC" ]183    if (current_os == "win") {184      defines += [ "INTERCEPTION_DYNAMIC_CRT" ]185    }186  }187 188  if (current_os != "mac" && current_os != "win") {189    static_library("asan_static_library") {190      output_dir = crt_current_out_dir191      output_name = "clang_rt.asan$crt_current_target_suffix"192      complete_static_lib = true193      configs -= [ "//llvm/utils/gn/build:llvm_code" ]194      configs += [ "//llvm/utils/gn/build:crt_code" ]195      configs += [ ":asan_config" ]196      configs -= [ "//llvm/utils/gn/build:thin_archive" ]197      sources = asan_sources198      deps = [199        ":preinit_sources",200        "//compiler-rt/lib/interception:sources",201        "//compiler-rt/lib/lsan:common_sources",202        "//compiler-rt/lib/sanitizer_common:sources",203        "//compiler-rt/lib/ubsan:sources",204      ]205    }206 207    static_library("asan_cxx") {208      output_dir = crt_current_out_dir209      output_name = "clang_rt.asan_cxx$crt_current_target_suffix"210      complete_static_lib = true211      configs -= [ "//llvm/utils/gn/build:thin_archive" ]212      deps = [213        ":cxx_sources",214        "//compiler-rt/lib/ubsan:cxx_sources",215      ]216    }217 218    static_library("asan_static") {219      output_dir = crt_current_out_dir220      output_name = "clang_rt.asan_static$crt_current_target_suffix"221      complete_static_lib = true222      configs -= [ "//llvm/utils/gn/build:thin_archive" ]223      deps = [ ":static_sources" ]224    }225 226    static_library("asan_preinit") {227      output_dir = crt_current_out_dir228      output_name = "clang_rt.asan-preinit$crt_current_target_suffix"229      complete_static_lib = true230      configs -= [ "//llvm/utils/gn/build:thin_archive" ]231      deps = [ ":preinit_sources" ]232    }233  }234  if (current_os == "win") {235    static_library("asan_static_runtime_thunk") {236      output_dir = crt_current_out_dir237      output_name =238          "clang_rt.asan_static_runtime_thunk$crt_current_target_suffix"239      configs -= [ "//llvm/utils/gn/build:llvm_code" ]240      configs += [ "//llvm/utils/gn/build:crt_code" ]241      complete_static_lib = true242      configs -= [ "//llvm/utils/gn/build:thin_archive" ]243      sources = [244        "asan_globals_win.cpp",245        "asan_malloc_win_thunk.cpp",246        "asan_win_common_runtime_thunk.cpp",247        "asan_win_static_runtime_thunk.cpp",248      ]249      defines = [ "SANITIZER_STATIC_RUNTIME_THUNK" ]250      deps = [251        "//compiler-rt/lib/interception:sources",252        "//compiler-rt/lib/sanitizer_common:runtime_thunk",253        "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk",254        "//compiler-rt/lib/ubsan:runtime_thunk",255      ]256    }257    static_library("asan_dynamic_runtime_thunk") {258      output_dir = crt_current_out_dir259      output_name =260          "clang_rt.asan_dynamic_runtime_thunk$crt_current_target_suffix"261      configs -= [ "//llvm/utils/gn/build:llvm_code" ]262      configs += [ "//llvm/utils/gn/build:crt_code" ]263      complete_static_lib = true264      configs -= [ "//llvm/utils/gn/build:thin_archive" ]265      sources = [266        "asan_globals_win.cpp",267        "asan_win_common_runtime_thunk.cpp",268        "asan_win_dynamic_runtime_thunk.cpp",269      ]270      defines = [ "SANITIZER_DYNAMIC_RUNTIME_THUNK" ]271      deps = [272        "//compiler-rt/lib/sanitizer_common:runtime_thunk",273        "//compiler-rt/lib/sanitizer_common:sancov_runtime_thunk",274        "//compiler-rt/lib/ubsan:runtime_thunk",275      ]276      cflags = [ "-Zl" ]277    }278  }279  group("asan") {280    deps = [ ":asan_shared_library" ]281    if (current_os == "win") {282      deps += [283        ":asan_dynamic_runtime_thunk",284        ":asan_static_runtime_thunk",285      ]286    }287    if (current_os != "mac" && current_os != "win") {288      deps += [289        ":asan_cxx",290        ":asan_preinit",291        ":asan_static",292        ":asan_static_library",293      ]294    }295  }296}297