diff --git a/.bazelrc b/.bazelrc index 88a480bc0b0ff..c04d9c634c87c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -24,6 +24,15 @@ build:asan --copt -D__SANITIZE_ADDRESS__ build:asan --test_env=ASAN_OPTIONS=handle_abort=1:allow_addr2line=true:check_initialization_order=true:strict_init_order=true build:asan --test_env=UBSAN_OPTIONS=halt_on_error=true:print_stacktrace=1 build:asan --test_env=ASAN_SYMBOLIZER_PATH +# TODO(htuch): these are temporary workarounds, remove when +# https://github.com/bazelbuild/rules_foreign_cc/issues/154#issuecomment-466504751 is resolved. +build:asan --action_env=CC +build:asan --action_env=CXX +build:asan --action_env=CFLAGS="-fsanitize=address,undefined -fno-sanitize=vptr" +build:asan --action_env=CXXFLAGS="-fsanitize=address,undefined -fno-sanitize=vptr" +# This is needed for host protoc. TODO(htuch): Figure out why.. +build:asan --action_env=LSAN_OPTIONS=verbosity=1:log_threads=1 +build:asan --test_env=LSAN_OPTIONS=verbosity=1:log_threads=1 # Clang ASAN/UBSAN build:clang-asan --config=asan @@ -37,8 +46,16 @@ build:macos-asan --copt -D_FORTIFY_SOURCE=0 # Clang TSAN build:clang-tsan --define ENVOY_CONFIG_TSAN=1 build:clang-tsan --copt -fsanitize=thread +# This is needed because of https://github.com/libevent/libevent/issues/777 +build:clang-tsan --copt -DEVENT__DISABLE_DEBUG_MODE build:clang-tsan --linkopt -fsanitize=thread build:clang-tsan --define tcmalloc=disabled +# TODO(htuch): these are temporary workarounds, remove when +# https://github.com/bazelbuild/rules_foreign_cc/issues/154#issuecomment-466504751 is resolved. +build:clang-tsan --action_env=CC +build:clang-tsan --action_env=CXX +build:clang-tsan --action_env=CFLAGS="-fsanitize=thread -DEVENT__DISABLE_DEBUG_MODE" +build:clang-tsan --action_env=CXXFLAGS="-fsanitize=thread" # Clang MSAN - broken today since we need to rebuild lib[std]c++ and external deps with MSAN # support (see https://github.com/envoyproxy/envoy/issues/443). diff --git a/bazel/BUILD b/bazel/BUILD index 90271e7d9699e..62834f28ed52c 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -75,6 +75,11 @@ config_setting( values = {"compilation_mode": "dbg"}, ) +config_setting( + name = "asan_build", + values = {"define": "ENVOY_CONFIG_ASAN=1"}, +) + config_setting( name = "coverage_build", values = {"define": "ENVOY_CONFIG_COVERAGE=1"}, diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index 3791c8f3adbdf..28c34462d4a81 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -32,6 +32,13 @@ cc_library( configure_make( name = "luajit", configure_command = "build.py", + configure_env_vars = select({ + # This shouldn't be needed! See + # https://github.com/bazelbuild/rules_foreign_cc/issues/154#issuecomment-470704365 + # TODO(htuch): Remove when the rules_foreign_cc issue is fixed + "//bazel:asan_build": {"ENVOY_CONFIG_ASAN": "1"}, + "//conditions:default": {}, + }), lib_source = "@com_github_luajit_luajit//:all", make_commands = [], static_libraries = [ diff --git a/bazel/foreign_cc/luajit.patch b/bazel/foreign_cc/luajit.patch index 15b025595e7e3..c79557f0fc058 100644 --- a/bazel/foreign_cc/luajit.patch +++ b/bazel/foreign_cc/luajit.patch @@ -48,7 +48,7 @@ new file mode 100755 index 0000000..9c71271 --- /dev/null +++ b/build.py -@@ -0,0 +1,28 @@ +@@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import argparse @@ -73,7 +73,14 @@ index 0000000..9c71271 + # fail on it. + os.environ["LSAN_OPTIONS"] = "exitcode=0" + -+ os.system('make V=1 PREFIX="{}" install'.format(args.prefix)) ++ # Blacklist LuaJIT from ASAN for now. ++ # TODO(htuch): Remove this when https://github.com/envoyproxy/envoy/issues/6084 is resolved. ++ if "ENVOY_CONFIG_ASAN" in os.environ: ++ os.environ["TARGET_CFLAGS"] += " -fsanitize-blacklist=%s/com_github_luajit_luajit/clang-asan-blacklist.txt" % os.environ["PWD"] ++ with open("clang-asan-blacklist.txt", "w") as f: ++ f.write("fun:lj_*\nfun:bcread_*\n") ++ ++ os.system('make V=1 PREFIX="{}" XCFLAGS=-DLUAJIT_ENABLE_GC64 install'.format(args.prefix)) + +main() +