-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: link C++ stdlib dynamically in sanitizer runs #8019
Changes from all commits
081cb2b
8c471f7
2e26761
63fa17b
f020460
1e244cc
140f473
e3551fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ build --experimental_local_memory_estimate | |
build --experimental_strict_action_env=true | ||
build --host_force_python=PY2 | ||
build --action_env=BAZEL_LINKLIBS=-l%:libstdc++.a | ||
build --action_env=BAZEL_LINKOPTS=-lm:-static-libgcc | ||
build --action_env=BAZEL_LINKOPTS=-lm | ||
build --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 | ||
build --javabase=@bazel_tools//tools/jdk:remote_jdk11 | ||
|
||
|
@@ -25,19 +25,21 @@ build --action_env=CC | |
build --action_env=CXX | ||
build --action_env=PATH | ||
|
||
# Common flags for sanitizers | ||
build:sanitizer --define tcmalloc=disabled | ||
build:sanitizer --linkopt -ldl | ||
build:sanitizer --build_tag_filters=-no_san | ||
build:sanitizer --test_tag_filters=-no_san | ||
|
||
# Basic ASAN/UBSAN that works for gcc | ||
build:asan --action_env=BAZEL_LINKLIBS= | ||
build:asan --action_env=BAZEL_LINKOPTS=-lstdc++:-lm | ||
build:asan --config=sanitizer | ||
# ASAN install its signal handler, disable ours so the stacktrace will be printed by ASAN | ||
build:asan --define signal_trace=disabled | ||
build:asan --define ENVOY_CONFIG_ASAN=1 | ||
build:asan --copt -fsanitize=address,undefined | ||
build:asan --linkopt -fsanitize=address,undefined | ||
build:asan --copt -fno-sanitize=vptr | ||
build:asan --linkopt -fno-sanitize=vptr | ||
build:asan --linkopt -ldl | ||
build:asan --define tcmalloc=disabled | ||
build:asan --build_tag_filters=-no_asan | ||
build:asan --test_tag_filters=-no_asan | ||
build:asan --define signal_trace=disabled | ||
build:asan --copt -DADDRESS_SANITIZER=1 | ||
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:detect_odr_violation=1 | ||
|
@@ -59,21 +61,20 @@ build:macos-asan --copt -DGRPC_BAZEL_BUILD | |
build:macos-asan --dynamic_mode=off | ||
|
||
# Clang TSAN | ||
build:clang-tsan --config=sanitizer | ||
build:clang-tsan --define ENVOY_CONFIG_TSAN=1 | ||
build:clang-tsan --copt -fsanitize=thread | ||
build:clang-tsan --linkopt -fsanitize=thread | ||
build:clang-tsan --linkopt -fuse-ld=lld | ||
build:clang-tsan --linkopt -static-libsan | ||
build:clang-tsan --define tcmalloc=disabled | ||
# Needed due to https://github.com/libevent/libevent/issues/777 | ||
build:clang-tsan --copt -DEVENT__DISABLE_DEBUG_MODE | ||
|
||
# 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). | ||
build:clang-msan --config=sanitizer | ||
build:clang-msan --define ENVOY_CONFIG_MSAN=1 | ||
build:clang-msan --copt -fsanitize=memory | ||
build:clang-msan --linkopt -fsanitize=memory | ||
build:clang-msan --define tcmalloc=disabled | ||
build:clang-msan --copt -fsanitize-memory-track-origins=2 | ||
|
||
# Clang with libc++ | ||
|
@@ -105,6 +106,7 @@ build:rbe-toolchain-clang-libc++ --config=rbe-toolchain | |
build:rbe-toolchain-clang-libc++ --crosstool_top=@rbe_ubuntu_clang_libcxx//cc:toolchain | ||
build:rbe-toolchain-clang-libc++ --extra_toolchains=@rbe_ubuntu_clang_libcxx//config:cc-toolchain | ||
build:rbe-toolchain-clang-libc++ --action_env=CC=clang --action_env=CXX=clang++ --action_env=PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/llvm-8/bin | ||
build:rbe-toolchain-clang-libc++ --define force_libcpp=enabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change unrelated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is related, we didn't need this before because toolchain handled all |
||
|
||
build:rbe-toolchain-gcc --config=rbe-toolchain | ||
build:rbe-toolchain-gcc --crosstool_top=@rbe_ubuntu_gcc//cc:toolchain | ||
|
@@ -147,4 +149,4 @@ build:asan-fuzzer --define=FUZZING_ENGINE=libfuzzer | |
build:asan-fuzzer --copt=-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION | ||
build:asan-fuzzer --copt=-fsanitize-coverage=trace-pc-guard | ||
# Remove UBSAN halt_on_error to avoid crashing on protobuf errors. | ||
build:asan-fuzzer --test_env=UBSAN_OPTIONS=print_stacktrace=1 | ||
build:asan-fuzzer --test_env=UBSAN_OPTIONS=print_stacktrace=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
load("//bazel:envoy_build_system.bzl", "envoy_package") | ||
|
||
envoy_package() | ||
|
||
load("//bazel:envoy_internal.bzl", "envoy_select_force_libcpp") | ||
|
||
exports_files([ | ||
"gen_sh_test_runner.sh", | ||
"sh_test_wrapper.sh", | ||
"cc_wrapper.py", | ||
]) | ||
|
||
genrule( | ||
|
@@ -37,6 +40,25 @@ genrule( | |
stamp = 1, | ||
) | ||
|
||
# A target to optionally link C++ standard library dynamically in sanitizer runs. | ||
# TSAN doesn't support libc/libstdc++ static linking per doc: | ||
# http://releases.llvm.org/8.0.1/tools/clang/docs/ThreadSanitizer.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: unintended(?) indent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intended 😅 |
||
cc_library( | ||
name = "dynamic_stdlib", | ||
linkopts = envoy_select_force_libcpp( | ||
["-lc++"], | ||
["-lstdc++"], | ||
), | ||
) | ||
|
||
cc_library( | ||
name = "static_stdlib", | ||
linkopts = select({ | ||
"//bazel:linux": ["-static-libgcc"], | ||
"//conditions:default": [], | ||
}), | ||
) | ||
|
||
config_setting( | ||
name = "windows_opt_build", | ||
values = { | ||
|
@@ -81,6 +103,11 @@ config_setting( | |
values = {"define": "ENVOY_CONFIG_ASAN=1"}, | ||
) | ||
|
||
config_setting( | ||
name = "tsan_build", | ||
values = {"define": "ENVOY_CONFIG_TSAN=1"}, | ||
) | ||
|
||
config_setting( | ||
name = "coverage_build", | ||
values = {"define": "ENVOY_CONFIG_COVERAGE=1"}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
diff --git a/src/dynamic_load_unix.cpp b/src/dynamic_load_unix.cpp | ||
index 17e08fd..d25e0c8 100644 | ||
--- a/src/dynamic_load_unix.cpp | ||
+++ b/src/dynamic_load_unix.cpp | ||
@@ -35,7 +35,11 @@ DynamicallyLoadTracingLibrary(const char* shared_library, | ||
std::string& error_message) noexcept try { | ||
dlerror(); // Clear any existing error. | ||
|
||
- const auto handle = dlopen(shared_library, RTLD_NOW | RTLD_LOCAL); | ||
+ const auto handle = dlopen(shared_library, RTLD_NOW | RTLD_LOCAL | ||
+#ifdef __SANITIZE_ADDRESS__ | ||
+ | RTLD_NODELETE | ||
+#endif | ||
+ ); | ||
if (handle == nullptr) { | ||
error_message = dlerror(); | ||
return make_unexpected(dynamic_load_failure_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to lose this? I don't think this is replaced elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why we did need this originally because it doesn't fail, what is the original reason for this? For ASAN symbolizer? TSAN worked well without this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, I just noticed that it was removed here and I wanted to make sure you meant to do it. Seems fine to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me do a quick try on ASAN failure (ASSERT(false)) to see if signal_trace does something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes it eats the stacktrace in case of SIGABRT though this stinks a bit (
nested bug
means we might have asan fault in the signal tracer but not sure), bring it back in this PR.