summaryrefslogtreecommitdiff
path: root/llvm/utils/gn/secondary/compiler-rt/test/hwasan/BUILD.gn
blob: ee658381dbd49c2b9a6b14b7f0ca932f50be4d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import("//compiler-rt/target.gni")
import("//compiler-rt/test/test.gni")
import("//llvm/utils/gn/build/toolchain/compiler.gni")
import("//llvm/utils/gn/build/write_cmake_config.gni")
import("//llvm/version.gni")

write_cmake_config("lit_site_cfg") {
  input = "lit.site.cfg.in"
  output = "$target_gen_dir/lit.site.cfg"

  values = [
    "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",

    "HWASAN_TEST_CONFIG_SUFFIX=-$crt_current_target",
    "HWASAN_TEST_TARGET_CFLAGS=$target_flags_string",
    "HWASAN_TEST_TARGET_ARCH=$crt_current_target_arch",

    "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
    "HWASAN_LIT_SOURCE_DIR=" + rebase_path("."),
  ]

  if (current_os == "android") {
    values += [ "HWASAN_ANDROID_FILES_TO_PUSH=[\"" + rebase_path(
                    "$crt_current_out_dir/libclang_rt.hwasan-$crt_current_target.so") + "\", \"" + rebase_path(
                    "$root_out_dir/bin/llvm-symbolizer") + "\"]" ]
  } else {
    values += [ "HWASAN_ANDROID_FILES_TO_PUSH=[]" ]
  }
}

if (current_toolchain != host_toolchain) {
  group("hwasan_toolchain") {
    deps = [
      ":lit_site_cfg",
      "//compiler-rt/include($host_toolchain)",
      "//compiler-rt/lib/cfi:blacklist($host_toolchain)",
      "//compiler-rt/lib/hwasan:hwasan_shared",
      "//compiler-rt/test:lit_common_configured",
      "//llvm/utils/FileCheck($host_toolchain)",
      "//llvm/utils/llvm-lit($host_toolchain)",
      "//llvm/utils/not($host_toolchain)",
    ]

    # FIXME: Make the host use the stage2 llvm-symbolizer as well, for
    # consistency. Currently lit.common.cfg sets up the sanitizer runtime to
    # look for llvm-symbolizer in llvm_tools_dir, and also looks there for
    # other tools which are built with the host toolchain.
    if (current_os == host_os && current_cpu == host_cpu) {
      deps += [ "//llvm/tools/llvm-symbolizer($host_toolchain)" ]
    } else {
      deps += [ "//llvm/tools/llvm-symbolizer" ]
    }
  }
}

supported_toolchains = []
if (host_os == "linux" && host_cpu == "x64") {
  supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
}
if (android_ndk_path != "") {
  supported_toolchains +=
      [ "//llvm/utils/gn/build/toolchain:stage2_android_aarch64" ]
}

group("hwasan") {
  deps = []
  foreach(toolchain, supported_toolchains) {
    deps += [ ":hwasan_toolchain($toolchain)" ]
  }
}

if (supported_toolchains != []) {
  action("check-hwasan") {
    script = "$root_build_dir/bin/llvm-lit"
    if (host_os == "win") {
      script += ".py"
    }
    args = [ "-sv" ]
    foreach(toolchain, supported_toolchains) {
      args += [ rebase_path(
              get_label_info(":lit_site_cfg($toolchain)", "target_gen_dir"),
              root_build_dir) ]
    }
    outputs = [
      "$target_gen_dir/run-lit",  # Non-existing, so that ninja runs it each time.
    ]

    # Since check-hwasan is always dirty, //:default doesn't depend on it so that
    # it's not part of the default ninja target.  Hence, check-hwasan shouldn't
    # have any deps except :hwasan. so that the default target is sure to build
    # all the deps.
    deps = [
      ":hwasan",
    ]
    testonly = true

    pool = "//:console"
  }
}