Просмотр исходного кода

Add support for silencing nano zone warnings that arise from asan+macOS (#2177)

Note this will need to be set per-cc_binary, but I don't think there's a good way to avoid that.

I didn't try hijacking the `cc_binary` rule name because that felt a bit excessive. We probably will have a few binaries we want to run directly, but I don't think it needs to be addressed on every last one.

This is part of addressing #1404
Jon Ross-Perkins 3 лет назад
Родитель
Сommit
6ce534a1e3
3 измененных файлов с 51 добавлено и 0 удалено
  1. 32 0
      bazel/macos_malloc/BUILD
  2. 16 0
      bazel/macos_malloc/env.bzl
  3. 3 0
      explorer/BUILD

+ 32 - 0
bazel/macos_malloc/BUILD

@@ -0,0 +1,32 @@
+# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+# Exceptions. See /LICENSE for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+exports_files(["env.bzl"])
+
+selects.config_setting_group(
+    name = "macos_asan",
+    match_all = [":is_macos", ":macos_asan_build_modes"],
+)
+
+config_setting(
+    name = "is_macos",
+    constraint_values = ["@platforms//os:osx"],
+)
+
+selects.config_setting_group(
+    name = "macos_asan_build_modes",
+    match_any = [":dbg", ":fastbuild"],
+)
+
+config_setting(
+    name = "dbg",
+    values = {"compilation_mode": "dbg"},
+)
+
+config_setting(
+    name = "fastbuild",
+    values = {"compilation_mode": "fastbuild"},
+)

+ 16 - 0
bazel/macos_malloc/env.bzl

@@ -0,0 +1,16 @@
+# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+# Exceptions. See /LICENSE for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Provides support for macOS-specific malloc issues."""
+
+def macos_malloc_env():
+    """Disable nano malloc when running asan.
+
+    On macOS, there's a nano zone allocation warning due to asan (arises
+    in fastbuild/dbg). This suppresses the warning in `bazel run`.
+    """
+    return select({
+        "//bazel/macos_malloc:macos_asan": {"MallocNanoZone": "0"},
+        "//conditions:default": {},
+    })

+ 3 - 0
explorer/BUILD

@@ -2,6 +2,8 @@
 # Exceptions. See /LICENSE for license information.
 # Exceptions. See /LICENSE for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 
+load("//bazel/macos_malloc:env.bzl", "macos_malloc_env")
+
 package(default_visibility = [
 package(default_visibility = [
     "//bazel/check_deps:__pkg__",
     "//bazel/check_deps:__pkg__",
     "//explorer:__subpackages__",
     "//explorer:__subpackages__",
@@ -35,6 +37,7 @@ cc_binary(
         ":main",
         ":main",
         "@llvm-project//llvm:Support",
         "@llvm-project//llvm:Support",
     ],
     ],
+    env = macos_malloc_env(),
 )
 )
 
 
 py_binary(
 py_binary(