gn build: Only build the hwasan runtime in aliasing mode on x86.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 17 May 2021 18:44:06 +0000 (11:44 -0700)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 17 May 2021 18:48:49 +0000 (11:48 -0700)
The LAM mode is currently untested by check-hwasan, so we only need
to build the runtime in aliasing mode. Because LAM mode will always
need to be conditional (because only certain hardware will support
it) we can always just disable the LAM lit tests if it ever starts
being tested.

llvm/utils/gn/secondary/compiler-rt/lib/hwasan/BUILD.gn

index 919d234..1008935 100644 (file)
@@ -1,5 +1,11 @@
 import("//compiler-rt/target.gni")
 
+if (current_cpu == "x64") {
+  hwasan_name = "hwasan_aliases"
+} else {
+  hwasan_name = "hwasan"
+}
+
 action("version_script") {
   script = "//compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py"
   sources = [ "hwasan.syms.extra" ]
@@ -13,10 +19,10 @@ action("version_script") {
     "--extra",
     rebase_path(sources[0], root_build_dir),
     rebase_path(
-        "$crt_current_out_dir/libclang_rt.hwasan$crt_current_target_suffix.a",
+        "$crt_current_out_dir/libclang_rt.$hwasan_name$crt_current_target_suffix.a",
         root_build_dir),
     rebase_path(
-        "$crt_current_out_dir/libclang_rt.hwasan_cxx$crt_current_target_suffix.a",
+        "$crt_current_out_dir/libclang_rt.${hwasan_name}_cxx$crt_current_target_suffix.a",
         root_build_dir),
     "--nm-executable",
     "nm",
@@ -29,6 +35,9 @@ source_set("sources") {
   configs -= [ "//llvm/utils/gn/build:llvm_code" ]
   configs += [ "//llvm/utils/gn/build:crt_code" ]
   defines = [ "HWASAN_WITH_INTERCEPTORS=1" ]
+  if (current_cpu == "x64") {
+    defines += [ "HWASAN_ALIASING_MODE" ]
+  }
   deps = [
     "//compiler-rt/lib/interception:sources",
     "//compiler-rt/lib/sanitizer_common:sources",
@@ -76,7 +85,7 @@ source_set("cxx_sources") {
 
 static_library("hwasan") {
   output_dir = crt_current_out_dir
-  output_name = "clang_rt.hwasan$crt_current_target_suffix"
+  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
   complete_static_lib = true
   configs -= [
     "//llvm/utils/gn/build:llvm_code",
@@ -88,7 +97,7 @@ static_library("hwasan") {
 
 static_library("hwasan_cxx") {
   output_dir = crt_current_out_dir
-  output_name = "clang_rt.hwasan_cxx$crt_current_target_suffix"
+  output_name = "clang_rt.${hwasan_name}_cxx$crt_current_target_suffix"
   complete_static_lib = true
   configs -= [
     "//llvm/utils/gn/build:llvm_code",
@@ -100,7 +109,7 @@ static_library("hwasan_cxx") {
 
 shared_library("hwasan_shared") {
   output_dir = crt_current_out_dir
-  output_name = "clang_rt.hwasan$crt_current_target_suffix"
+  output_name = "clang_rt.$hwasan_name$crt_current_target_suffix"
   configs -= [ "//llvm/utils/gn/build:llvm_code" ]
   configs += [ "//llvm/utils/gn/build:crt_code" ]
   deps = [