mirror of https://github.com/mongodb/mongo
SERVER-113129 Reapply "SERVER-113129 Move compiler flags into toolchain" (#44581)
GitOrigin-RevId: a022bd38c8fa912976e74499f465d401a7d34350
This commit is contained in:
parent
b478a685e6
commit
ba488dc418
4
.bazelrc
4
.bazelrc
|
|
@ -503,7 +503,7 @@ common --remote_upload_local_results=False
|
|||
# Settings specific for clang-tidy
|
||||
--config=clang-tidy
|
||||
common:clang-tidy --remote_download_outputs=all
|
||||
common:clang-tidy --build_tag_filters=-third_party,-mongo-tidy-tests,-third_party_debug,-mongo-tidy-tests_debug
|
||||
common:clang-tidy --build_tag_filters=not_third_party,-mongo-tidy-tests,-mongo-tidy-tests_debug
|
||||
common:clang-tidy --//bazel/config:compiler_type=clang
|
||||
common:clang-tidy --keep_going
|
||||
common:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
|
||||
|
|
@ -512,7 +512,7 @@ common:clang-tidy --jobs=300
|
|||
|
||||
--config=mod-scanner
|
||||
common:mod-scanner --config=dbg
|
||||
common:mod-scanner --build_tag_filters=-third_party,-mongo-tidy-tests,-third_party_debug,-mongo-tidy-tests_debug
|
||||
common:mod-scanner --build_tag_filters=not_third_party,-mongo-tidy-tests,-mongo-tidy-tests_debug
|
||||
common:mod-scanner --//bazel/config:compiler_type=clang
|
||||
common:mod-scanner --//bazel/config:mongo_toolchain_version=v5
|
||||
common:mod-scanner --output_groups=report
|
||||
|
|
|
|||
|
|
@ -2166,38 +2166,6 @@ config_setting(
|
|||
},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "disable_warnings_as_errors_linux",
|
||||
match_all = [
|
||||
"@platforms//os:linux",
|
||||
":warnings_as_errors_enabled",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "disable_warnings_as_errors_posix",
|
||||
match_all = [
|
||||
":not_windows",
|
||||
":warnings_as_errors_enabled",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "disable_warnings_as_errors_macos",
|
||||
match_all = [
|
||||
"@platforms//os:macos",
|
||||
":warnings_as_errors_enabled",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "disable_warnings_as_errors_windows",
|
||||
match_all = [
|
||||
"@platforms//os:windows",
|
||||
":warnings_as_errors_enabled",
|
||||
],
|
||||
)
|
||||
|
||||
# -----------
|
||||
# ssl options
|
||||
# -----------
|
||||
|
|
|
|||
|
|
@ -47,24 +47,6 @@ Error:
|
|||
linking mongo dynamically is not currently supported on Windows
|
||||
"""
|
||||
|
||||
# This is a hack to work around the fact that the cc_library flag
|
||||
# additional_compiler_inputs doesn't exist in cc_binary. Instead, we add the
|
||||
# denylists to srcs as header files to make them visible to the compiler
|
||||
# executable.
|
||||
SANITIZER_DENYLIST_HEADERS = select({
|
||||
"//bazel/config:asan_enabled": ["//etc:asan_denylist_h"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:msan_enabled": ["//etc:msan_denylist_h"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:tsan_enabled": ["//etc:tsan_denylist_h"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:ubsan_enabled": ["//etc:ubsan_denylist_h"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
ASAN_OPTIONS = [
|
||||
"detect_leaks=1",
|
||||
"check_initialization_order=true",
|
||||
|
|
@ -179,11 +161,6 @@ SKIP_ARCHIVE_ENABLED = select({
|
|||
"//conditions:default": True,
|
||||
})
|
||||
|
||||
SKIP_ARCHIVE_FEATURE = select({
|
||||
"@platforms//os:windows": [],
|
||||
"//conditions:default": ["supports_start_end_lib"],
|
||||
})
|
||||
|
||||
SEPARATE_DEBUG_ENABLED = select({
|
||||
"//bazel/config:separate_debug_enabled": True,
|
||||
"//conditions:default": False,
|
||||
|
|
@ -222,15 +199,16 @@ SYMBOL_ORDER_FILES = [
|
|||
"//buildscripts:symbols-al2023.orderfile",
|
||||
]
|
||||
|
||||
# These are warnings are disabled globally at the toolchain level to allow external repository compilation.
|
||||
# Re-enable them for MongoDB source code.
|
||||
RE_ENABLE_DISABLED_3RD_PARTY_WARNINGS_FEATURES = select({
|
||||
# This contains a list of features that we use for third parties but disable for mongo code
|
||||
DISABLE_3RD_PARTY_FEATURES = select({
|
||||
"//bazel/config:compiler_type_clang": [
|
||||
"-disable_warnings_for_third_party_libraries_clang",
|
||||
"thread_safety_warnings",
|
||||
"-ubsan_third_party",
|
||||
],
|
||||
"//bazel/config:compiler_type_gcc": [
|
||||
"-disable_warnings_for_third_party_libraries_gcc",
|
||||
"-ubsan_third_party",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
|
@ -404,7 +382,7 @@ def mongo_cc_library(
|
|||
|
||||
if name != "mongoca" and name != "cyrus_sasl_windows_test_plugin":
|
||||
deps += MONGO_GLOBAL_SRC_DEPS
|
||||
features = features + RE_ENABLE_DISABLED_3RD_PARTY_WARNINGS_FEATURES
|
||||
features = features + DISABLE_3RD_PARTY_FEATURES
|
||||
else:
|
||||
srcs = _final_srcs_for_cc + private_hdrs
|
||||
|
||||
|
|
@ -419,10 +397,13 @@ def mongo_cc_library(
|
|||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
})
|
||||
|
||||
if "third_party" in native.package_name():
|
||||
tags = tags + ["third_party"]
|
||||
if "third_party" not in native.package_name():
|
||||
tags = tags + ["not_third_party"]
|
||||
|
||||
copts = get_copts(name, native.package_name(), copts)
|
||||
if skip_windows_crt_flags:
|
||||
features = features + ["-multithreaded_feature", "-single_threaded_feature"]
|
||||
|
||||
copts = get_copts(name, native.package_name(), copts, skip_windows_crt_flags)
|
||||
fincludes_hdr = force_includes_hdr(native.package_name(), name)
|
||||
linkopts = get_linkopts(native.package_name(), linkopts)
|
||||
|
||||
|
|
@ -443,27 +424,6 @@ def mongo_cc_library(
|
|||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
linux_rpath_flags = [
|
||||
"-Wl,-z,origin",
|
||||
"-Wl,--enable-new-dtags",
|
||||
"-Wl,-rpath,\\$ORIGIN/../lib",
|
||||
"-Wl,-h,lib" + name + ".so",
|
||||
]
|
||||
macos_rpath_flags = [
|
||||
"-Wl,-rpath,\\$ORIGIN/../lib",
|
||||
"-Wl,-install_name,@rpath/lib" + name + ".dylib",
|
||||
]
|
||||
|
||||
rpath_flags = select({
|
||||
"//bazel/config:linux_aarch64": linux_rpath_flags,
|
||||
"//bazel/config:linux_ppc64le": linux_rpath_flags,
|
||||
"//bazel/config:linux_s390x": linux_rpath_flags,
|
||||
"//bazel/config:linux_x86_64": linux_rpath_flags,
|
||||
"//bazel/config:macos_aarch64": macos_rpath_flags,
|
||||
"//bazel/config:macos_x86_64": macos_rpath_flags,
|
||||
"//bazel/config:windows_x86_64": [],
|
||||
})
|
||||
|
||||
if no_undefined_ref_DO_NOT_USE:
|
||||
undefined_ref_flag = select({
|
||||
"//bazel/config:sanitize_address_required_settings": [],
|
||||
|
|
@ -485,7 +445,7 @@ def mongo_cc_library(
|
|||
|
||||
cc_library(
|
||||
name = name + WITH_DEBUG_SUFFIX,
|
||||
srcs = srcs + SANITIZER_DENYLIST_HEADERS,
|
||||
srcs = srcs,
|
||||
hdrs = hdrs + fincludes_hdr,
|
||||
deps = deps + cc_deps,
|
||||
textual_hdrs = textual_hdrs,
|
||||
|
|
@ -503,7 +463,7 @@ def mongo_cc_library(
|
|||
local_defines = MONGO_GLOBAL_DEFINES + local_defines,
|
||||
defines = defines,
|
||||
includes = includes,
|
||||
features = SKIP_ARCHIVE_FEATURE + features,
|
||||
features = features,
|
||||
target_compatible_with = target_compatible_with,
|
||||
additional_linker_inputs = additional_linker_inputs + MONGO_GLOBAL_ADDITIONAL_LINKER_INPUTS,
|
||||
exec_properties = exec_properties,
|
||||
|
|
@ -521,7 +481,7 @@ def mongo_cc_library(
|
|||
deps = [name + WITH_DEBUG_SUFFIX],
|
||||
visibility = visibility,
|
||||
tags = tags + ["mongo_library"],
|
||||
user_link_flags = get_linkopts(native.package_name()) + undefined_ref_flag + non_transitive_dyn_linkopts + rpath_flags + visibility_support_shared_flags + select({
|
||||
user_link_flags = get_linkopts(native.package_name()) + undefined_ref_flag + non_transitive_dyn_linkopts + visibility_support_shared_flags + select({
|
||||
"//bazel/config:simple_build_id_enabled": ["-Wl,--build-id=0x" +
|
||||
hex32(hash(name)) +
|
||||
hex32(hash(name)) +
|
||||
|
|
@ -536,7 +496,7 @@ def mongo_cc_library(
|
|||
}) + select({
|
||||
"//bazel/config:simple_build_id_enabled": ["-build_id"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
}) + ["rpath_override"],
|
||||
additional_linker_inputs = additional_linker_inputs + MONGO_GLOBAL_ADDITIONAL_LINKER_INPUTS,
|
||||
exec_properties = exec_properties,
|
||||
win_def_file = win_def_file,
|
||||
|
|
@ -621,12 +581,13 @@ def _mongo_cc_binary_and_test(
|
|||
elif not in_third_party:
|
||||
# all_headers mode (binary flavor): returns a srcs list
|
||||
srcs = binary_srcs_with_all_headers(name, _final_srcs_for_cc, private_hdrs)
|
||||
tags = tags + ["not_third_party"]
|
||||
else:
|
||||
# third_party inside src/mongo: append private headers as sources
|
||||
srcs = _final_srcs_for_cc + private_hdrs
|
||||
|
||||
deps += MONGO_GLOBAL_SRC_DEPS
|
||||
features = features + RE_ENABLE_DISABLED_3RD_PARTY_WARNINGS_FEATURES
|
||||
features = features + DISABLE_3RD_PARTY_FEATURES
|
||||
else:
|
||||
# Non-mongo pkgs: append private headers as sources
|
||||
srcs = _final_srcs_for_cc + private_hdrs
|
||||
|
|
@ -643,7 +604,10 @@ def _mongo_cc_binary_and_test(
|
|||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
})
|
||||
|
||||
copts = get_copts(name, native.package_name(), copts, skip_windows_crt_flags)
|
||||
copts = get_copts(name, native.package_name(), copts)
|
||||
if skip_windows_crt_flags:
|
||||
features = features + ["-multithreaded_feature", "-single_threaded_feature"]
|
||||
|
||||
fincludes_hdr = force_includes_hdr(native.package_name(), name)
|
||||
linkopts = get_linkopts(native.package_name(), linkopts)
|
||||
|
||||
|
|
@ -691,7 +655,7 @@ def _mongo_cc_binary_and_test(
|
|||
|
||||
args = {
|
||||
"name": name + WITH_DEBUG_SUFFIX,
|
||||
"srcs": srcs + fincludes_hdr + SANITIZER_DENYLIST_HEADERS,
|
||||
"srcs": srcs + fincludes_hdr,
|
||||
"deps": all_deps,
|
||||
"visibility": visibility,
|
||||
"testonly": testonly,
|
||||
|
|
@ -715,7 +679,7 @@ def _mongo_cc_binary_and_test(
|
|||
"local_defines": MONGO_GLOBAL_DEFINES + local_defines,
|
||||
"defines": defines,
|
||||
"includes": includes,
|
||||
"features": SKIP_ARCHIVE_FEATURE + ["-pic", "pie"] + features + select({
|
||||
"features": ["-pic", "pie"] + features + select({
|
||||
"//bazel/config:windows_debug_symbols_enabled": ["generate_pdb_file"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
|
|
|
|||
|
|
@ -21,6 +21,31 @@ DEBUG_LEVEL = select({
|
|||
"@//bazel/config:gcc_or_clang_dbg_level_3": 3,
|
||||
})
|
||||
|
||||
INTERNAL_THIN_LTO_ENABLED = select({
|
||||
"@//bazel/config:thin_lto_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
COVERAGE_ENABLED = select({
|
||||
"@//bazel/config:gcov_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
COMPRESS_DEBUG_ENABLED = select({
|
||||
"@//bazel/config:compress_debug_compile_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
WARNINGS_AS_ERRORS_ENABLED = select({
|
||||
"@//bazel/config:warnings_as_errors_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
LINKSTATIC_ENABLED = select({
|
||||
"@//bazel/config:linkstatic_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
[
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-" + arch,
|
||||
|
|
@ -73,6 +98,11 @@ feature_attrs = get_common_features_attrs()
|
|||
optimization_level = feature_attrs[FEATURES_ATTR_NAMES.OPT_LEVEL],
|
||||
debug_level = DEBUG_LEVEL,
|
||||
supports_start_end_lib = True,
|
||||
internal_thin_lto_enabled = INTERNAL_THIN_LTO_ENABLED,
|
||||
coverage_enabled = COVERAGE_ENABLED,
|
||||
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
|
||||
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
|
||||
linkstatic = LINKSTATIC_ENABLED,
|
||||
)
|
||||
for arch, cpu in get_supported_apple_archs().items()
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1620,6 +1620,7 @@ def _impl(ctx):
|
|||
extension = ".dylib",
|
||||
),
|
||||
]
|
||||
|
||||
features = [
|
||||
framework_paths_feature,
|
||||
cpp_modules_feature,
|
||||
|
|
@ -1720,6 +1721,11 @@ mongo_apple_llvm_cc_toolchain_config = rule(
|
|||
"builtin_sysroot": attr.label(mandatory = True),
|
||||
"optimization_level": attr.string(mandatory = False),
|
||||
"debug_level": attr.int(mandatory = False),
|
||||
"internal_thin_lto_enabled": attr.bool(default = False, mandatory = False),
|
||||
"coverage_enabled": attr.bool(default = False, mandatory = False),
|
||||
"compress_debug_enabled": attr.bool(default = False, mandatory = False),
|
||||
"warnings_as_errors_enabled": attr.bool(default = True, mandatory = False),
|
||||
"linkstatic": attr.bool(mandatory = True),
|
||||
},
|
||||
fragments = ["apple", "cpp"],
|
||||
provides = [CcToolchainConfigInfo],
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ load(
|
|||
load(
|
||||
"//bazel/toolchains/cc:mongo_custom_features.bzl",
|
||||
"all_compile_actions",
|
||||
"all_link_actions",
|
||||
"get_common_features",
|
||||
"lto_index_actions",
|
||||
)
|
||||
|
||||
_OBJCPP_EXECUTABLE_ACTION_NAME = "objc++-executable"
|
||||
|
|
@ -247,4 +249,20 @@ def get_apple_features(ctx):
|
|||
),
|
||||
],
|
||||
),
|
||||
feature(
|
||||
name = "rpath_override",
|
||||
enabled = not ctx.attr.linkstatic,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-Wl,-rpath,\\$ORIGIN/../lib",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,12 +5,6 @@ load(
|
|||
"MONGO_LINUX_CC_COPTS",
|
||||
"MONGO_LINUX_CC_LINKFLAGS",
|
||||
)
|
||||
load(
|
||||
"//bazel/toolchains/cc/mongo_windows:mongo_compiler_flags.bzl",
|
||||
"MONGO_WIN_CC_COPTS",
|
||||
"MONGO_WIN_CC_LINKFLAGS",
|
||||
"WINDOWS_MULTITHREAD_RUNTIME_COPTS",
|
||||
)
|
||||
|
||||
# Only visible in the build system.
|
||||
visibility([
|
||||
|
|
@ -18,30 +12,6 @@ visibility([
|
|||
"//src/mongo/util",
|
||||
])
|
||||
|
||||
# Used as both link flags and copts
|
||||
# Suppress the function sanitizer check for third party libraries, because:
|
||||
#
|
||||
# - mongod (a C++ binary) links in WiredTiger (a C library)
|
||||
# - If/when mongod--built under ubsan--fails, the sanitizer will by
|
||||
# default analyze the failed execution for undefined behavior related to
|
||||
# function pointer usage. See:
|
||||
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks
|
||||
# - When this happens, the sanitizer will attempt to dynamically load to perform
|
||||
# the analysis.
|
||||
# - However, since WT was built as a C library, is not linked with the function
|
||||
# sanitizer library symbols despite its C++ dependencies referencing them.
|
||||
# - This will cause the sanitizer itself to fail, resulting in debug information
|
||||
# being unavailable.
|
||||
# - So by suppressing the function ubsan check, we won't reference symbols
|
||||
# defined in the unavailable ubsan function sanitier library and will get
|
||||
# useful debugging information.
|
||||
UBSAN_OPTS_THIRD_PARTY = select({
|
||||
"//bazel/config:sanitize_undefined_dynamic_link_settings": [
|
||||
"-fno-sanitize=function",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
def force_includes_copt(package_name, name):
|
||||
if package_name.startswith("src/mongo"):
|
||||
basic_h = "mongo/platform/basic.h"
|
||||
|
|
@ -66,28 +36,15 @@ def force_includes_copt(package_name, name):
|
|||
# TODO(SERVER-103006): Stop including this flag when ASP is able to upgrade mongoc and mongocxx
|
||||
STREAMS_THIRD_PARTY_DIR = "src/mongo/db/modules/enterprise/src/streams/third_party"
|
||||
|
||||
def package_specific_copt(package_name):
|
||||
if package_name.startswith("src/third_party") or package_name.startswith(STREAMS_THIRD_PARTY_DIR):
|
||||
return UBSAN_OPTS_THIRD_PARTY
|
||||
return []
|
||||
MONGO_GLOBAL_COPTS = MONGO_LINUX_CC_COPTS
|
||||
|
||||
def package_specific_linkflag(package_name):
|
||||
if package_name.startswith("src/third_party") or package_name.startswith(STREAMS_THIRD_PARTY_DIR):
|
||||
return UBSAN_OPTS_THIRD_PARTY
|
||||
return []
|
||||
|
||||
MONGO_GLOBAL_COPTS = MONGO_LINUX_CC_COPTS + MONGO_WIN_CC_COPTS
|
||||
|
||||
def get_copts(name, package_name, copts = [], skip_windows_crt_flags = False):
|
||||
def get_copts(name, package_name, copts = []):
|
||||
copts = MONGO_GLOBAL_COPTS + \
|
||||
package_specific_copt(package_name) + \
|
||||
copts + \
|
||||
force_includes_copt(package_name, name)
|
||||
if not skip_windows_crt_flags:
|
||||
copts = copts + WINDOWS_MULTITHREAD_RUNTIME_COPTS
|
||||
return copts
|
||||
|
||||
MONGO_GLOBAL_LINKFLAGS = MONGO_LINUX_CC_LINKFLAGS + MONGO_WIN_CC_LINKFLAGS
|
||||
MONGO_GLOBAL_LINKFLAGS = MONGO_LINUX_CC_LINKFLAGS
|
||||
|
||||
def get_linkopts(package_name, linkopts = []):
|
||||
return MONGO_GLOBAL_LINKFLAGS + package_specific_linkflag(package_name) + linkopts
|
||||
return MONGO_GLOBAL_LINKFLAGS + linkopts
|
||||
|
|
|
|||
|
|
@ -50,6 +50,18 @@ all_compile_actions = \
|
|||
ACTION_NAMES.lto_backend,
|
||||
]
|
||||
|
||||
all_link_actions = [
|
||||
ACTION_NAMES.cpp_link_executable,
|
||||
ACTION_NAMES.cpp_link_dynamic_library,
|
||||
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
|
||||
]
|
||||
|
||||
lto_index_actions = [
|
||||
ACTION_NAMES.lto_index_for_executable,
|
||||
ACTION_NAMES.lto_index_for_dynamic_library,
|
||||
ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
|
||||
]
|
||||
|
||||
FEATURES_ATTR_NAMES = struct(
|
||||
OPT_LEVEL = "optimization_level",
|
||||
)
|
||||
|
|
@ -360,4 +372,67 @@ def get_common_features(ctx):
|
|||
),
|
||||
],
|
||||
),
|
||||
feature(
|
||||
name = "internal_thin_lto",
|
||||
enabled = ctx.attr.internal_thin_lto_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-flto=thin",
|
||||
])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-flto=thin",
|
||||
])],
|
||||
),
|
||||
],
|
||||
),
|
||||
feature(
|
||||
# The mongo is added because coverage is a used feature already
|
||||
name = "coverage_mongo",
|
||||
enabled = ctx.attr.coverage_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"--coverage",
|
||||
"-fprofile-update=single",
|
||||
])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"--coverage",
|
||||
"-fprofile-update=single",
|
||||
])],
|
||||
),
|
||||
],
|
||||
),
|
||||
feature(
|
||||
name = "compress_debug",
|
||||
enabled = ctx.attr.compress_debug_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wa,--compress-debug-sections",
|
||||
])],
|
||||
),
|
||||
],
|
||||
),
|
||||
feature(
|
||||
name = "warnings_as_errors_compile",
|
||||
enabled = False,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Werror",
|
||||
])],
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,193 +1,16 @@
|
|||
"""This file contains compiler flags that are specific to linux cc compiling and linking."""
|
||||
"""
|
||||
DO NOT ADD TO THIS FILE. FLAGS SHOULD BE ADDED THROUGH THE TOOLCHAIN INSTEAD.
|
||||
This file contains compiler flags that are specific to linux cc compiling and linking.
|
||||
"""
|
||||
|
||||
load(
|
||||
"//bazel/toolchains/cc:mongo_errors.bzl",
|
||||
"BAZELISK_CHECK_ERROR_MESSAGE",
|
||||
"LIBCXX_ERROR_MESSAGE",
|
||||
"REQUIRED_SETTINGS_SANITIZER_ERROR_MESSAGE",
|
||||
"SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE",
|
||||
"THREAD_SANITIZER_ERROR_MESSAGE",
|
||||
)
|
||||
|
||||
# Flags listed in this file is only visible to the bazel build system.
|
||||
visibility("//bazel/toolchains/cc")
|
||||
|
||||
# SERVER-9761: Ensure early detection of missing symbols in dependent libraries
|
||||
# at program startup. For non-release dynamic builds we disable this behavior in
|
||||
# the interest of improved mongod startup times. Xcode15 removed bind_at_load
|
||||
# functionality so we cannot have a selection for macosx here
|
||||
# ld: warning: -bind_at_load is deprecated on macOS
|
||||
# TODO: SERVER-90596 reenable loading at startup
|
||||
BIND_AT_LOAD_LINKFLAGS = select({
|
||||
"//bazel/config:linkstatic_enabled_linux": [
|
||||
"-Wl,-z,now",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
IMPLICIT_FALLTHROUGH_COPTS = select({
|
||||
"//bazel/config:compiler_type_clang": ["-Wimplicit-fallthrough"],
|
||||
"//bazel/config:compiler_type_gcc": ["-Wimplicit-fallthrough=5"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# -fno-omit-frame-pointer should be added if any sanitizer flag is used by user
|
||||
ANY_SANITIZER_AVAILABLE_COPTS = select({
|
||||
"//bazel/config:any_sanitizer_required_setting": [
|
||||
"-fno-omit-frame-pointer",
|
||||
],
|
||||
"//bazel/config:no_enabled_sanitizer": [],
|
||||
}, no_match_error = REQUIRED_SETTINGS_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
ANY_SANITIZER_AVAILABLE_LINKFLAGS = select({
|
||||
# Sanitizer libs may inject undefined refs (for hooks) at link time, but the
|
||||
# symbols will be available at runtime via the compiler runtime lib.
|
||||
"//bazel/config:any_sanitizer_required_setting": [
|
||||
"-Wl,--allow-shlib-undefined",
|
||||
],
|
||||
"//bazel/config:no_enabled_sanitizer": [],
|
||||
}, no_match_error = REQUIRED_SETTINGS_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
ANY_SANITIZER_GCC_LINKFLAGS = select({
|
||||
# GCC's implementation of ASAN depends on libdl.
|
||||
"//bazel/config:any_sanitizer_gcc": ["-ldl"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
ADDRESS_SANITIZER_COPTS = select({
|
||||
"//bazel/config:asan_disabled": [],
|
||||
"//bazel/config:sanitize_address_required_settings": [
|
||||
"-fsanitize=address",
|
||||
"-fsanitize-blacklist=$(location //etc:asan_denylist_h)",
|
||||
],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
ADDRESS_SANITIZER_LINKFLAGS = select({
|
||||
"//bazel/config:asan_disabled": [],
|
||||
"//bazel/config:sanitize_address_required_settings": ["-fsanitize=address"],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
# Makes it easier to debug memory failures at the cost of some perf:
|
||||
# -fsanitize-memory-track-origins
|
||||
MEMORY_SANITIZER_COPTS = select({
|
||||
"//bazel/config:msan_disabled": [],
|
||||
"//bazel/config:sanitize_memory_required_settings": [
|
||||
"-fsanitize=memory",
|
||||
"-fsanitize-memory-track-origins",
|
||||
"-fsanitize-blacklist=$(location //etc:msan_denylist_h)",
|
||||
],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
SANITIZE_WITHOUT_TSAN_LINKFLAGS = select({
|
||||
"//bazel/config:sanitize_without_tsan": [
|
||||
"-rtlib=compiler-rt",
|
||||
"-unwindlib=libgcc",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Makes it easier to debug memory failures at the cost of some perf:
|
||||
# -fsanitize-memory-track-origins
|
||||
MEMORY_SANITIZER_LINKFLAGS = select({
|
||||
"//bazel/config:sanitize_memory_required_settings": ["-fsanitize=memory"],
|
||||
"//bazel/config:msan_disabled": [],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
# We can't include the fuzzer flag with the other sanitize flags. The libfuzzer
|
||||
# library already has a main function, which will cause the dependencies check
|
||||
# to fail
|
||||
FUZZER_SANITIZER_COPTS = select({
|
||||
"//bazel/config:sanitize_fuzzer_required_settings": [
|
||||
"-fsanitize=fuzzer-no-link",
|
||||
"-fprofile-instr-generate",
|
||||
"-fcoverage-mapping",
|
||||
],
|
||||
"//bazel/config:fsan_disabled": [],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE + "fuzzer")
|
||||
|
||||
# These flags are needed to generate a coverage report
|
||||
FUZZER_SANITIZER_LINKFLAGS = select({
|
||||
"//bazel/config:sanitize_fuzzer_required_settings": [
|
||||
"-fsanitize=fuzzer-no-link",
|
||||
"-fprofile-instr-generate",
|
||||
"-fcoverage-mapping",
|
||||
"-nostdlib++",
|
||||
"-lstdc++",
|
||||
],
|
||||
"//bazel/config:fsan_disabled": [],
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE + "fuzzer")
|
||||
|
||||
# Combines following two conditions -
|
||||
# 1.
|
||||
# TODO: SERVER-48622
|
||||
#
|
||||
# See https://github.com/google/sanitizers/issues/943 for why we disallow
|
||||
# combining TSAN with libunwind. We could, aternatively, have added logic to
|
||||
# automate the decision about whether to enable libunwind based on whether TSAN
|
||||
# is enabled, but that logic is already complex, and it feels better to make it
|
||||
# explicit that using TSAN means you won't get the benefits of libunwind.
|
||||
#
|
||||
# 2.
|
||||
# We add suppressions based on the library file in etc/tsan.suppressions so the
|
||||
# link-model needs to be dynamic.
|
||||
|
||||
THREAD_SANITIZER_COPTS = select({
|
||||
"//bazel/config:sanitize_thread_required_settings": [
|
||||
"-fsanitize=thread",
|
||||
"-fsanitize-blacklist=$(location //etc:tsan_denylist_h)",
|
||||
],
|
||||
"//bazel/config:tsan_disabled": [],
|
||||
}, no_match_error = THREAD_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
THREAD_SANITIZER_LINKFLAGS = select({
|
||||
"//bazel/config:sanitize_thread_required_settings": ["-fsanitize=thread"],
|
||||
"//bazel/config:tsan_disabled": [],
|
||||
}, no_match_error = THREAD_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
# By default, undefined behavior sanitizer doesn't stop on the first error. Make
|
||||
# it so. Newer versions of clang have renamed the flag. However, this flag
|
||||
# cannot be included when using the fuzzer sanitizer if we want to suppress
|
||||
# errors to uncover new ones.
|
||||
|
||||
# In dynamic builds, the `vptr` sanitizer check can require additional
|
||||
# dependency edges. That is very inconvenient, because such builds can't use
|
||||
# z,defs. The result is a very fragile link graph, where refactoring the link
|
||||
# graph in one place can have surprising effects in others. Instead, we just
|
||||
# disable the `vptr` sanitizer for dynamic builds. We tried some other
|
||||
# approaches in SERVER-49798 of adding a new descriptor type, but that didn't
|
||||
# address the fundamental issue that the correct link graph for a dynamic+ubsan
|
||||
# build isn't the same as the correct link graph for a regular dynamic build.
|
||||
|
||||
UNDEFINED_SANITIZER_COPTS = select({
|
||||
"//bazel/config:ubsan_enabled": ["-fsanitize=undefined"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:sanitize_undefined_dynamic_link_settings": [
|
||||
"-fno-sanitize=vptr",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:sanitize_undefined_without_fuzzer_settings": [
|
||||
"-fno-sanitize-recover",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:ubsan_enabled": [
|
||||
"-fsanitize-blacklist=$(location //etc:ubsan_denylist_h)",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
UNDEFINED_SANITIZER_LINKFLAGS = select({
|
||||
"//bazel/config:ubsan_enabled": ["-fsanitize=undefined"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//bazel/config:sanitize_undefined_dynamic_link_settings": [
|
||||
"-fno-sanitize=vptr",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# TODO(SERVER-101099): Remove this once builds are containerized and system libraries inside the containers
|
||||
# no longer contain debug symbols.
|
||||
#
|
||||
|
|
@ -206,70 +29,14 @@ LIBGCC_LINKFLAGS = select({
|
|||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
COMPRESS_DEBUG_COPTS = select({
|
||||
# Debug compression significantly reduces .o, .dwo, and .a sizes
|
||||
"//bazel/config:compress_debug_compile_enabled": [
|
||||
"-Wa,--compress-debug-sections",
|
||||
],
|
||||
# explicitly disable compression if its not enabled or else not passing the flag
|
||||
# by default still compresses on x86/x86_64 - nocompress is only a flag in gcc not clang
|
||||
"//bazel/config:compress_debug_compile_disabled_linux_gcc": [
|
||||
"-Wa,--nocompress-debug-sections",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
DISABLE_SOURCE_WARNING_AS_ERRORS_COPTS = select({
|
||||
"//bazel/config:disable_warnings_as_errors_linux": ["-Werror"],
|
||||
# TODO(SERVER-90183): Enable once MacOS has a custom Bazel toolchain config.
|
||||
# "//bazel/config:disable_warnings_as_errors_macos": ["-Werror"],
|
||||
"//bazel/config:disable_warnings_as_errors_windows": ["/WX"],
|
||||
"//bazel/config:warnings_as_errors_disabled": [],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
DISABLE_SOURCE_WARNING_AS_ERRORS_LINKFLAGS = select({
|
||||
"//bazel/config:disable_warnings_as_errors_linux": ["-Wl,--fatal-warnings"],
|
||||
"//bazel/config:warnings_as_errors_disabled": [],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
MTUNE_MARCH_COPTS = select({
|
||||
"//bazel/config:linux_aarch64": [
|
||||
"-march=armv8.2-a",
|
||||
"-mtune=generic",
|
||||
],
|
||||
"//bazel/config:linux_ppc64le": [
|
||||
"-mcpu=power8",
|
||||
"-mtune=power8",
|
||||
"-mcmodel=medium",
|
||||
],
|
||||
"//bazel/config:linux_s390x": [
|
||||
"-march=z196",
|
||||
"-mtune=zEC12",
|
||||
],
|
||||
# If we are enabling vectorization in sandybridge mode, we'd rather not hit
|
||||
# the 256 wide vector instructions because the heavy versions can cause
|
||||
# clock speed reductions.
|
||||
"//bazel/config:linux_x86_64": [
|
||||
"-march=sandybridge",
|
||||
"-mtune=generic",
|
||||
"-mprefer-vector-width=128",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
THIN_LTO_FLAGS = select({
|
||||
"//bazel/config:thin_lto_enabled": ["-flto=thin"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# TODO(SERVER-113302): Deprecate after 8.3 release due to using PGO instead
|
||||
SYMBOL_ORDER_COPTS = select({
|
||||
"//bazel/config:symbol_ordering_file_enabled": ["-ffunction-sections"],
|
||||
"//bazel/config:symbol_ordering_file_enabled_al2023": ["-ffunction-sections"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# TODO(SERVER-113302): Deprecate after 8.3 release due to using PGO instead
|
||||
SYMBOL_ORDER_LINKFLAGS = select({
|
||||
"//bazel/config:symbol_ordering_file_enabled": [
|
||||
"-Wl,--symbol-ordering-file=$(location //buildscripts:symbols.orderfile)",
|
||||
|
|
@ -282,33 +49,6 @@ SYMBOL_ORDER_LINKFLAGS = select({
|
|||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
SHARED_ARCHIVE_COPTS = select({
|
||||
"//bazel/config:shared_archive_enabled_gcc": [
|
||||
"-fno-gnu-unique",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
SHARED_ARCHIVE_LINKFLAGS_GNU_UNIQUE = select({
|
||||
"//bazel/config:shared_archive_enabled_gcc_not_mold": [
|
||||
"-Wl,--no-gnu-unique",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
SHARED_ARCHIVE_LINKFLAGS_B_SYMBOLIC = select({
|
||||
"//bazel/config:shared_archive_enabled_gcc": [
|
||||
"-Wl,-Bsymbolic",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Passed to both the compiler and linker
|
||||
COVERAGE_FLAGS = select({
|
||||
"//bazel/config:gcov_enabled": ["--coverage", "-fprofile-update=single"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Hack to throw an error if the user isn't running bazel through bazelisk,
|
||||
# since we want to make sure the hook inside of tools/bazel gets run.
|
||||
RUNNING_THROUGH_BAZELISK_CHECK = select({
|
||||
|
|
@ -327,38 +67,11 @@ MONGO_GLOBAL_INCLUDE_DIRECTORIES = [
|
|||
|
||||
MONGO_LINUX_CC_COPTS = (
|
||||
MONGO_GLOBAL_INCLUDE_DIRECTORIES +
|
||||
ADDRESS_SANITIZER_COPTS +
|
||||
MEMORY_SANITIZER_COPTS +
|
||||
FUZZER_SANITIZER_COPTS +
|
||||
UNDEFINED_SANITIZER_COPTS +
|
||||
THREAD_SANITIZER_COPTS +
|
||||
ANY_SANITIZER_AVAILABLE_COPTS +
|
||||
COMPRESS_DEBUG_COPTS +
|
||||
IMPLICIT_FALLTHROUGH_COPTS +
|
||||
MTUNE_MARCH_COPTS +
|
||||
DISABLE_SOURCE_WARNING_AS_ERRORS_COPTS +
|
||||
THIN_LTO_FLAGS +
|
||||
SYMBOL_ORDER_COPTS +
|
||||
COVERAGE_FLAGS +
|
||||
SHARED_ARCHIVE_COPTS +
|
||||
RUNNING_THROUGH_BAZELISK_CHECK
|
||||
)
|
||||
|
||||
MONGO_LINUX_CC_LINKFLAGS = (
|
||||
MEMORY_SANITIZER_LINKFLAGS +
|
||||
ADDRESS_SANITIZER_LINKFLAGS +
|
||||
FUZZER_SANITIZER_LINKFLAGS +
|
||||
UNDEFINED_SANITIZER_LINKFLAGS +
|
||||
THREAD_SANITIZER_LINKFLAGS +
|
||||
BIND_AT_LOAD_LINKFLAGS +
|
||||
ANY_SANITIZER_AVAILABLE_LINKFLAGS +
|
||||
ANY_SANITIZER_GCC_LINKFLAGS +
|
||||
DISABLE_SOURCE_WARNING_AS_ERRORS_LINKFLAGS +
|
||||
THIN_LTO_FLAGS +
|
||||
SYMBOL_ORDER_LINKFLAGS +
|
||||
COVERAGE_FLAGS +
|
||||
SANITIZE_WITHOUT_TSAN_LINKFLAGS +
|
||||
SHARED_ARCHIVE_LINKFLAGS_GNU_UNIQUE +
|
||||
SHARED_ARCHIVE_LINKFLAGS_B_SYMBOLIC +
|
||||
LIBGCC_LINKFLAGS
|
||||
)
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ def _impl(ctx):
|
|||
|
||||
supports_start_end_lib_feature = feature(
|
||||
name = "supports_start_end_lib",
|
||||
enabled = False,
|
||||
enabled = True,
|
||||
)
|
||||
|
||||
objcopy_embed_flags_feature = feature(
|
||||
|
|
@ -798,52 +798,6 @@ def _impl(ctx):
|
|||
],
|
||||
)
|
||||
|
||||
disable_warnings_for_third_party_libraries_clang_feature = feature(
|
||||
name = "disable_warnings_for_third_party_libraries_clang",
|
||||
enabled = ctx.attr.compiler == COMPILERS.CLANG,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-deprecated-declarations",
|
||||
"-Wno-deprecated-non-prototype",
|
||||
"-Wno-missing-template-arg-list-after-template-kw",
|
||||
"-Wno-sign-compare",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
disable_warnings_for_third_party_libraries_gcc_feature = feature(
|
||||
name = "disable_warnings_for_third_party_libraries_gcc",
|
||||
enabled = ctx.attr.compiler == COMPILERS.GCC,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_cpp_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-overloaded-virtual",
|
||||
"-Wno-dangling-reference",
|
||||
"-Wno-deprecated",
|
||||
"-Wno-deprecated-declarations",
|
||||
"-Wno-class-memaccess",
|
||||
"-Wno-uninitialized",
|
||||
"-Wno-array-bounds",
|
||||
"-Wno-sign-compare",
|
||||
"-Wno-stringop-overflow",
|
||||
"-Wno-stringop-overread",
|
||||
"-Wno-restrict",
|
||||
"-Wno-dangling-pointer",
|
||||
])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-attributes",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Disable floating-point contractions such as forming of fused multiply-add
|
||||
# operations.
|
||||
disable_floating_point_contractions_feature = feature(
|
||||
|
|
@ -1384,6 +1338,411 @@ def _impl(ctx):
|
|||
],
|
||||
)
|
||||
|
||||
shared_archive_gcc_feature = feature(
|
||||
name = "shared_archive_gcc",
|
||||
enabled = ctx.attr.shared_archive and ctx.attr.compiler == COMPILERS.GCC,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = ["-fno-gnu-unique"])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["-Wl,--no-gnu-unique", "-Wl,-Bsymbolic"] if ctx.attr.linker != LINKERS.MOLD else ["-Wl,-Bsymbolic"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# SERVER-9761: Ensure early detection of missing symbols in dependent libraries
|
||||
# at program startup. For non-release dynamic builds we disable this behavior in
|
||||
# the interest of improved mongod startup times. Xcode15 removed bind_at_load
|
||||
# functionality so we cannot have a selection for macosx here
|
||||
# ld: warning: -bind_at_load is deprecated on macOS
|
||||
# TODO: SERVER-90596 reenable loading at startup
|
||||
bind_at_load_feature = feature(
|
||||
name = "bind_at_load",
|
||||
enabled = ctx.attr.linkstatic,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [flag_group(flags = ["-Wl,-z,now"])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
implicit_fallthrough_feature = feature(
|
||||
name = "implicit_fallthrough",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["-Wimplicit-fallthrough"] if ctx.attr.compiler == COMPILERS.CLANG else ["-Wimplicit-fallthrough=5"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
any_sanitizer_feature = feature(
|
||||
name = "any_sanitizer",
|
||||
enabled = ctx.attr.any_sanitizer_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = ["-fno-omit-frame-pointer"])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
# Sanitizer libs may inject undefined refs (for hooks) at link time, but the
|
||||
# symbols will be available at runtime via the compiler runtime lib.
|
||||
flag_group(
|
||||
flags = [
|
||||
"-Wl,--allow-shlib-undefined",
|
||||
"-rtlib=compiler-rt",
|
||||
"-unwindlib=libgcc",
|
||||
] if not ctx.attr.tsan_enabled else ["-Wl,--allow-shlib-undefined"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
asan_feature = feature(
|
||||
name = "asan",
|
||||
enabled = ctx.attr.asan_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=address",
|
||||
"-fsanitize-blacklist=" + ctx.attr.asan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.asan_denylist != None else "",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["-fsanitize=address"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# We can't include the fuzzer flag with the other sanitize flags. The libfuzzer
|
||||
# library already has a main function, which will cause the dependencies check
|
||||
# to fail
|
||||
fsan_feature = feature(
|
||||
name = "fsan",
|
||||
enabled = ctx.attr.fsan_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=fuzzer-no-link",
|
||||
"-fprofile-instr-generate",
|
||||
"-fcoverage-mapping",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=fuzzer-no-link",
|
||||
"-fprofile-instr-generate",
|
||||
"-fcoverage-mapping",
|
||||
"-nostdlib++",
|
||||
"-lstdc++",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Makes it easier to debug memory failures at the cost of some perf:
|
||||
# -fsanitize-memory-track-origins
|
||||
msan_feature = feature(
|
||||
name = "msan",
|
||||
enabled = ctx.attr.msan_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=memory",
|
||||
"-fsanitize-memory-track-origins",
|
||||
"-fsanitize-blacklist=" + ctx.attr.msan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.msan_denylist != None else "",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=memory",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
tsan_feature = feature(
|
||||
name = "tsan",
|
||||
enabled = ctx.attr.tsan_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=thread",
|
||||
"-fsanitize-blacklist=" + ctx.attr.tsan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.tsan_denylist != None else "",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=thread",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# By default, undefined behavior sanitizer doesn't stop on the first error. Make
|
||||
# it so. Newer versions of clang have renamed the flag. However, this flag
|
||||
# cannot be included when using the fuzzer sanitizer if we want to suppress
|
||||
# errors to uncover new ones.
|
||||
|
||||
# In dynamic builds, the `vptr` sanitizer check can require additional
|
||||
# dependency edges. That is very inconvenient, because such builds can't use
|
||||
# z,defs. The result is a very fragile link graph, where refactoring the link
|
||||
# graph in one place can have surprising effects in others. Instead, we just
|
||||
# disable the `vptr` sanitizer for dynamic builds. We tried some other
|
||||
# approaches in SERVER-49798 of adding a new descriptor type, but that didn't
|
||||
# address the fundamental issue that the correct link graph for a dynamic+ubsan
|
||||
# build isn't the same as the correct link graph for a regular dynamic build.
|
||||
ubsan_compile_flags = []
|
||||
if not ctx.attr.fsan_enabled:
|
||||
ubsan_compile_flags += ["-fno-sanitize-recover"]
|
||||
if not ctx.attr.linkstatic:
|
||||
ubsan_compile_flags += ["-fno-sanitize=vptr"]
|
||||
ubsan_feature = feature(
|
||||
name = "ubsan",
|
||||
enabled = ctx.attr.ubsan_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=undefined",
|
||||
"-fsanitize-blacklist=" + ctx.attr.ubsan_denylist[DefaultInfo].files.to_list()[0].path if ctx.attr.ubsan_denylist != None else "",
|
||||
] + ubsan_compile_flags,
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fsanitize=undefined",
|
||||
] + ([] if ctx.attr.linkstatic else ["-fno-sanitize=vptr"]),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Suppress the function sanitizer check for third party libraries, because:
|
||||
#
|
||||
# - mongod (a C++ binary) links in WiredTiger (a C library)
|
||||
# - If/when mongod--built under ubsan--fails, the sanitizer will by
|
||||
# default analyze the failed execution for undefined behavior related to
|
||||
# function pointer usage. See:
|
||||
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks
|
||||
# - When this happens, the sanitizer will attempt to dynamically load to perform
|
||||
# the analysis.
|
||||
# - However, since WT was built as a C library, is not linked with the function
|
||||
# sanitizer library symbols despite its C++ dependencies referencing them.
|
||||
# - This will cause the sanitizer itself to fail, resulting in debug information
|
||||
# being unavailable.
|
||||
# - So by suppressing the function ubsan check, we won't reference symbols
|
||||
# defined in the unavailable ubsan function sanitier library and will get
|
||||
# useful debugging information.
|
||||
ubsan_third_party_feature = feature(
|
||||
name = "ubsan_third_party",
|
||||
enabled = ctx.attr.ubsan_enabled and not ctx.attr.linkstatic,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fno-sanitize=function",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fno-sanitize=function",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
mtune_flags = []
|
||||
if ctx.attr.is_aarch64:
|
||||
mtune_flags += ["-march=armv8.2-a", "-mtune=generic"]
|
||||
if ctx.attr.is_ppc64le:
|
||||
mtune_flags += ["-mcpu=power8", "-mtune=power8", "-mcmodel=medium"]
|
||||
if ctx.attr.is_s390x:
|
||||
mtune_flags += ["-march=z196", "-mtune=zEC12"]
|
||||
if ctx.attr.is_x86_64:
|
||||
mtune_flags += ["-march=sandybridge", "-mtune=generic", "-mprefer-vector-width=128"]
|
||||
|
||||
mtune_march_feature = feature(
|
||||
name = "mtune_march",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = mtune_flags,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
compress_debug_disable_feature = feature(
|
||||
name = "compress_debug_disable",
|
||||
enabled = not ctx.attr.compress_debug_enabled and ctx.attr.compiler == COMPILERS.GCC,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wa,--nocompress-debug-sections",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
rpath_override_feature = feature(
|
||||
name = "rpath_override",
|
||||
enabled = not ctx.attr.linkstatic,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-Wl,-z,origin",
|
||||
"-Wl,--enable-new-dtags",
|
||||
"-Wl,-rpath,\\$ORIGIN/../lib",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
warnings_as_errors_link_feature = feature(
|
||||
name = "warnings_as_errors_link",
|
||||
enabled = ctx.attr.warnings_as_errors_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions + lto_index_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wl,--fatal-warnings",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
disable_warnings_for_third_party_libraries_clang_feature = feature(
|
||||
name = "disable_warnings_for_third_party_libraries_clang",
|
||||
enabled = ctx.attr.compiler == COMPILERS.CLANG,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-deprecated-declarations",
|
||||
"-Wno-deprecated-non-prototype",
|
||||
"-Wno-missing-template-arg-list-after-template-kw",
|
||||
"-Wno-sign-compare",
|
||||
"-Wno-implicit-fallthrough",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
disable_warnings_for_third_party_libraries_gcc_feature = feature(
|
||||
name = "disable_warnings_for_third_party_libraries_gcc",
|
||||
enabled = ctx.attr.compiler == COMPILERS.GCC,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_cpp_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-overloaded-virtual",
|
||||
"-Wno-dangling-reference",
|
||||
"-Wno-deprecated",
|
||||
"-Wno-deprecated-declarations",
|
||||
"-Wno-class-memaccess",
|
||||
"-Wno-uninitialized",
|
||||
"-Wno-array-bounds",
|
||||
"-Wno-sign-compare",
|
||||
"-Wno-stringop-overflow",
|
||||
"-Wno-stringop-overread",
|
||||
"-Wno-restrict",
|
||||
"-Wno-dangling-pointer",
|
||||
"-Wno-implicit-fallthrough",
|
||||
])],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"-Wno-attributes",
|
||||
"-Wno-implicit-fallthrough",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
features = [
|
||||
enable_all_warnings_feature,
|
||||
general_clang_or_gcc_warnings_feature,
|
||||
|
|
@ -1401,14 +1760,10 @@ def _impl(ctx):
|
|||
objcopy_embed_flags_feature,
|
||||
opt_feature,
|
||||
dbg_feature,
|
||||
user_compile_flags_feature,
|
||||
sysroot_feature,
|
||||
unfiltered_compile_flags_feature,
|
||||
omitted_timestamps_feature,
|
||||
thin_archive_feature,
|
||||
extra_cflags_feature,
|
||||
extra_cxxflags_feature,
|
||||
extra_ldflags_feature,
|
||||
includes_feature,
|
||||
dependency_file_feature,
|
||||
verbose_feature,
|
||||
|
|
@ -1433,8 +1788,6 @@ def _impl(ctx):
|
|||
no_class_memaccess_warning_feature,
|
||||
no_interference_size_warning_feature,
|
||||
thread_safety_warnings_feature,
|
||||
disable_warnings_for_third_party_libraries_clang_feature,
|
||||
disable_warnings_for_third_party_libraries_gcc_feature,
|
||||
disable_floating_point_contractions_feature,
|
||||
general_clang_warnings_feature,
|
||||
general_gcc_warnings_feature,
|
||||
|
|
@ -1459,7 +1812,30 @@ def _impl(ctx):
|
|||
file_prefix_map,
|
||||
strip_debug_feature,
|
||||
clang_toolchain_resource_dir_feature,
|
||||
] + get_common_features(ctx)
|
||||
shared_archive_gcc_feature,
|
||||
bind_at_load_feature,
|
||||
implicit_fallthrough_feature,
|
||||
any_sanitizer_feature,
|
||||
asan_feature,
|
||||
fsan_feature,
|
||||
msan_feature,
|
||||
tsan_feature,
|
||||
ubsan_feature,
|
||||
ubsan_third_party_feature,
|
||||
mtune_march_feature,
|
||||
compress_debug_disable_feature,
|
||||
rpath_override_feature,
|
||||
warnings_as_errors_link_feature,
|
||||
] + get_common_features(ctx) + [
|
||||
# These flags are at the bottom so they get applied after anything else.
|
||||
# These are things like the flags people apply directly on cc_library through copts/linkopts
|
||||
user_compile_flags_feature,
|
||||
extra_cflags_feature,
|
||||
extra_cxxflags_feature,
|
||||
extra_ldflags_feature,
|
||||
disable_warnings_for_third_party_libraries_clang_feature,
|
||||
disable_warnings_for_third_party_libraries_gcc_feature,
|
||||
]
|
||||
|
||||
return [
|
||||
cc_common.create_cc_toolchain_config_info(
|
||||
|
|
@ -1516,6 +1892,24 @@ mongo_linux_cc_toolchain_config = rule(
|
|||
"propeller_profile_generate": attr.bool(default = False, mandatory = False),
|
||||
"propeller_profile_use": attr.label(default = None, allow_single_file = True, mandatory = False),
|
||||
"distributed_thin_lto": attr.bool(default = False, mandatory = False),
|
||||
"any_sanitizer_enabled": attr.bool(default = False, mandatory = False),
|
||||
"asan_enabled": attr.bool(default = False, mandatory = False),
|
||||
"asan_denylist": attr.label(default = None, mandatory = False),
|
||||
"fsan_enabled": attr.bool(default = False, mandatory = False),
|
||||
"msan_enabled": attr.bool(default = False, mandatory = False),
|
||||
"msan_denylist": attr.label(default = None, mandatory = False),
|
||||
"tsan_enabled": attr.bool(default = False, mandatory = False),
|
||||
"tsan_denylist": attr.label(default = None, mandatory = False),
|
||||
"ubsan_enabled": attr.bool(default = False, mandatory = False),
|
||||
"ubsan_denylist": attr.label(default = None, mandatory = False),
|
||||
"is_aarch64": attr.bool(default = False, mandatory = False),
|
||||
"is_ppc64le": attr.bool(default = False, mandatory = False),
|
||||
"is_s390x": attr.bool(default = False, mandatory = False),
|
||||
"is_x86_64": attr.bool(default = False, mandatory = False),
|
||||
"internal_thin_lto_enabled": attr.bool(default = False, mandatory = False),
|
||||
"coverage_enabled": attr.bool(default = False, mandatory = False),
|
||||
"compress_debug_enabled": attr.bool(default = False, mandatory = False),
|
||||
"warnings_as_errors_enabled": attr.bool(default = False, mandatory = False),
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ load(
|
|||
"@//bazel/toolchains/cc:mongo_custom_features.bzl",
|
||||
"FEATURES_ATTR_NAMES",
|
||||
"get_common_features_attrs")
|
||||
load(
|
||||
"@//bazel/toolchains/cc:mongo_errors.bzl",
|
||||
"REQUIRED_SETTINGS_SANITIZER_ERROR_MESSAGE",
|
||||
"SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE",
|
||||
"THREAD_SANITIZER_ERROR_MESSAGE",
|
||||
)
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
|
|
@ -113,6 +119,97 @@ DTLTO_ENABLED = select({
|
|||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
ANY_SANITIZER_ENABLED = select({
|
||||
"@//bazel/config:no_enabled_sanitizer": False,
|
||||
"@//bazel/config:any_sanitizer_required_setting": True,
|
||||
}, no_match_error = REQUIRED_SETTINGS_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
ASAN_ENABLED = select({
|
||||
"@//bazel/config:asan_disabled": False,
|
||||
"@//bazel/config:sanitize_address_required_settings": True,
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
ASAN_DENYLIST = "@//etc:asan_denylist_h"
|
||||
|
||||
FSAN_ENABLED = select({
|
||||
"@//bazel/config:sanitize_fuzzer_required_settings": True,
|
||||
"@//bazel/config:fsan_disabled": False,
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE + "fuzzer")
|
||||
|
||||
MSAN_ENABLED = select({
|
||||
"@//bazel/config:msan_disabled": False,
|
||||
"@//bazel/config:sanitize_memory_required_settings": True
|
||||
}, no_match_error = SYSTEM_ALLOCATOR_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
MSAN_DENYLIST = "@//etc:msan_denylist_h"
|
||||
|
||||
# Combines following two conditions -
|
||||
# 1.
|
||||
# TODO: SERVER-48622
|
||||
#
|
||||
# See https://github.com/google/sanitizers/issues/943 for why we disallow
|
||||
# combining TSAN with libunwind. We could, aternatively, have added logic to
|
||||
# automate the decision about whether to enable libunwind based on whether TSAN
|
||||
# is enabled, but that logic is already complex, and it feels better to make it
|
||||
# explicit that using TSAN means you won't get the benefits of libunwind.
|
||||
#
|
||||
# 2.
|
||||
# We add suppressions based on the library file in etc/tsan.suppressions so the
|
||||
# link-model needs to be dynamic.
|
||||
TSAN_ENABLED = select({
|
||||
"@//bazel/config:sanitize_thread_required_settings": True,
|
||||
"@//bazel/config:tsan_disabled": False,
|
||||
}, no_match_error = THREAD_SANITIZER_ERROR_MESSAGE)
|
||||
|
||||
TSAN_DENYLIST = "@//etc:tsan_denylist_h"
|
||||
|
||||
UBSAN_ENABLED = select({
|
||||
"@//bazel/config:ubsan_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
UBSAN_DENYLIST = "@//etc:ubsan_denylist_h"
|
||||
|
||||
IS_AARCH64 = select({
|
||||
"@//bazel/config:linux_aarch64": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
IS_PPC64LE = select({
|
||||
"@//bazel/config:linux_ppc64le": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
IS_S390X = select({
|
||||
"@//bazel/config:linux_s390x": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
IS_X86_64 = select({
|
||||
"@//bazel/config:linux_x86_64": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
INTERNAL_THIN_LTO_ENABLED = select({
|
||||
"@//bazel/config:thin_lto_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
COVERAGE_ENABLED = select({
|
||||
"@//bazel/config:gcov_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
COMPRESS_DEBUG_ENABLED = select({
|
||||
"@//bazel/config:compress_debug_compile_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
WARNINGS_AS_ERRORS_ENABLED = select({
|
||||
"@//bazel/config:warnings_as_errors_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
LINK_FLAGS = ["-L" + flag for flag in COMMON_LINK_FLAGS] + LINKER_LINKFLAGS
|
||||
|
||||
# Helper target for the toolchain (see below):
|
||||
|
|
@ -122,6 +219,18 @@ filegroup(
|
|||
"@//bazel/config:pgo_profile_use_clang_enabled_linkstatic_enabled": ["@pgo_data//:clang_pgo_files"],
|
||||
"@//bazel/config:pgo_profile_use_gcc_enabled_linkstatic_enabled": ["@pgo_data//:gcc_pgo_files"],
|
||||
"@//conditions:default": [],
|
||||
}) + select ({
|
||||
"@//bazel/config:asan_disabled": [],
|
||||
"@//bazel/config:sanitize_address_required_settings": ["@//etc:asan_denylist_h"],
|
||||
}) + select ({
|
||||
"@//bazel/config:msan_disabled": [],
|
||||
"@//bazel/config:sanitize_memory_required_settings": ["@//etc:msan_denylist_h"],
|
||||
}) + select ({
|
||||
"@//bazel/config:sanitize_thread_required_settings": ["@//etc:tsan_denylist_h"],
|
||||
"@//bazel/config:tsan_disabled": [],
|
||||
}) + select ({
|
||||
"@//bazel/config:ubsan_enabled": ["@//etc:ubsan_denylist_h"],
|
||||
"@//conditions:default": [],
|
||||
})
|
||||
)
|
||||
|
||||
|
|
@ -167,6 +276,24 @@ mongo_linux_cc_toolchain_config(
|
|||
pgo_profile_generate = PGO_PROFILE_GENERATE_ENABLED,
|
||||
pgo_profile_use = PGO_PROFILE_USE_ENABLED,
|
||||
distributed_thin_lto = DTLTO_ENABLED,
|
||||
any_sanitizer_enabled = ANY_SANITIZER_ENABLED,
|
||||
asan_enabled = ASAN_ENABLED,
|
||||
asan_denylist = ASAN_DENYLIST,
|
||||
fsan_enabled = FSAN_ENABLED,
|
||||
msan_enabled = MSAN_ENABLED,
|
||||
msan_denylist = MSAN_DENYLIST,
|
||||
tsan_enabled = TSAN_ENABLED,
|
||||
tsan_denylist = TSAN_DENYLIST,
|
||||
ubsan_enabled = UBSAN_ENABLED,
|
||||
ubsan_denylist = UBSAN_DENYLIST,
|
||||
is_aarch64 = IS_AARCH64,
|
||||
is_ppc64le = IS_PPC64LE,
|
||||
is_s390x = IS_S390X,
|
||||
is_x86_64 = IS_X86_64,
|
||||
internal_thin_lto_enabled = False,
|
||||
coverage_enabled = COVERAGE_ENABLED,
|
||||
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
|
||||
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
|
||||
)
|
||||
|
||||
mongo_linux_cc_toolchain_config(
|
||||
|
|
@ -215,6 +342,24 @@ mongo_linux_cc_toolchain_config(
|
|||
pgo_profile_use = PGO_PROFILE_USE_ENABLED,
|
||||
propeller_profile_generate = PROPELLER_PROFILE_GENERATE_ENABLED,
|
||||
distributed_thin_lto = DTLTO_ENABLED,
|
||||
any_sanitizer_enabled = ANY_SANITIZER_ENABLED,
|
||||
asan_enabled = ASAN_ENABLED,
|
||||
asan_denylist = ASAN_DENYLIST,
|
||||
fsan_enabled = FSAN_ENABLED,
|
||||
msan_enabled = MSAN_ENABLED,
|
||||
msan_denylist = MSAN_DENYLIST,
|
||||
tsan_enabled = TSAN_ENABLED,
|
||||
tsan_denylist = TSAN_DENYLIST,
|
||||
ubsan_enabled = UBSAN_ENABLED,
|
||||
ubsan_denylist = UBSAN_DENYLIST,
|
||||
is_aarch64 = IS_AARCH64,
|
||||
is_ppc64le = IS_PPC64LE,
|
||||
is_s390x = IS_S390X,
|
||||
is_x86_64 = IS_X86_64,
|
||||
internal_thin_lto_enabled = INTERNAL_THIN_LTO_ENABLED,
|
||||
coverage_enabled = COVERAGE_ENABLED,
|
||||
compress_debug_enabled = COMPRESS_DEBUG_ENABLED,
|
||||
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
|
|
|
|||
|
|
@ -1,119 +0,0 @@
|
|||
"""This file contains compiler flags that is specific to Windows C++ compiling and linking."""
|
||||
|
||||
# Flags listed in this file is only visible to the bazel build system.
|
||||
visibility([
|
||||
"//bazel/toolchains/cc",
|
||||
"//bazel",
|
||||
])
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
|
||||
# /MD defines _MT and _DLL and links in MSVCRT.lib into each .obj file
|
||||
# /MDd defines _DEBUG, _MT, and _DLL and link MSVCRTD.lib into each .obj file
|
||||
WINDOWS_MULTITHREAD_RUNTIME_COPTS = select({
|
||||
"//bazel/config:windows_dbg_disabled": [
|
||||
"/MD",
|
||||
],
|
||||
"//bazel/config:windows_dbg_enabled": [
|
||||
"/MDd",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# /O1 optimize for size
|
||||
# /O2 optimize for speed (as opposed to size)
|
||||
# /Oy- disable frame pointer optimization (overrides /O2, only affects 32-bit)
|
||||
# /Zo enables optimizations with modifications to make debugging easier
|
||||
WINDOWS_OPT_COPTS = select({
|
||||
# This is opt=debug, not to be confused with (opt=on && dbg=on)
|
||||
"//bazel/config:windows_opt_debug": [
|
||||
"/Ox",
|
||||
"/Zo",
|
||||
"/Oy-",
|
||||
],
|
||||
"//bazel/config:windows_opt_off": [
|
||||
"/Od",
|
||||
],
|
||||
"//bazel/config:windows_opt_on": [
|
||||
"/O2",
|
||||
"/Oy-",
|
||||
],
|
||||
"//bazel/config:windows_opt_size": [
|
||||
"/Os",
|
||||
"/Oy-",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Enable Stack Frame Run-Time Error Checking; Reports when a variable is used
|
||||
# without having been initialized (implies /Od: no optimizations)
|
||||
WINDOWS_RUNTIME_ERROR_CHECK_COPTS = select({
|
||||
"//bazel/config:windows_opt_off_dbg_enabled": [
|
||||
"/RTC1",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
WINDOWS_DEBUG_COPTS = select({
|
||||
"//bazel/config:windows_debug_symbols_enabled": [
|
||||
# Generate debug info into the object files
|
||||
"/Z7",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
WINDOWS_DEFAULT_LINKFLAGS = select({
|
||||
"//bazel/config:windows_debug_symbols_enabled": [
|
||||
# /DEBUG will tell the linker to create a .pdb file which WinDbg and
|
||||
# Visual Studio will use to resolve symbols if you want to debug a
|
||||
# release-mode image.
|
||||
#
|
||||
# Note that this means we can't do parallel links in the build.
|
||||
#
|
||||
# Also note that this has nothing to do with _DEBUG or optimization.
|
||||
|
||||
# If the user set a /DEBUG flag explicitly, don't add another. Otherwise
|
||||
# use the standard /DEBUG flag, since we always want PDBs.
|
||||
"/DEBUG",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Windows non optimized builds will cause the PDB to blow up in size, this
|
||||
# allows a larger PDB. The flag is undocumented at the time of writing but the
|
||||
# microsoft thread which brought about its creation can be found here:
|
||||
# https://developercommunity.visualstudio.com/t/pdb-limit-of-4-gib-is-likely-to-be-a-problem-in-a/904784
|
||||
#
|
||||
# Without this flag MSVC will report a red herring error message, about disk
|
||||
# space or invalid path.
|
||||
WINDOWS_PDB_PAGE_SIZE_LINKOPT = select({
|
||||
"//bazel/config:windows_opt_off": [
|
||||
"/pdbpagesize:16384",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Disable incremental link - avoid the level of indirection for function calls
|
||||
WINDOWS_INCREMENTAL_LINKOPT = select({
|
||||
"//bazel/config:windows_opt_any": [
|
||||
"/INCREMENTAL:NO",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
SASL_WINDOWS_COPTS = select({
|
||||
"@platforms//os:windows": ["-Iexternal/windows_sasl/include"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
MONGO_WIN_CC_COPTS = (
|
||||
WINDOWS_DEBUG_COPTS +
|
||||
WINDOWS_OPT_COPTS +
|
||||
WINDOWS_RUNTIME_ERROR_CHECK_COPTS +
|
||||
SASL_WINDOWS_COPTS
|
||||
)
|
||||
|
||||
MONGO_WIN_CC_LINKFLAGS = (
|
||||
WINDOWS_DEFAULT_LINKFLAGS +
|
||||
WINDOWS_PDB_PAGE_SIZE_LINKOPT +
|
||||
WINDOWS_INCREMENTAL_LINKOPT
|
||||
)
|
||||
|
|
@ -5,6 +5,41 @@ SMALLER_BINARY = select({
|
|||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
WARNINGS_AS_ERRORS_ENABLED = select({
|
||||
"@//bazel/config:warnings_as_errors_enabled": True,
|
||||
"@//conditions:default": False,
|
||||
})
|
||||
|
||||
OPT_DEBUG = select({
|
||||
"@//bazel/config:windows_opt_debug": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
OPT_OFF = select({
|
||||
"@//bazel/config:windows_opt_off": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
OPT_ON = select({
|
||||
"@//bazel/config:windows_opt_on": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
OPT_SIZE = select({
|
||||
"@//bazel/config:windows_opt_size": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
DBG = select({
|
||||
"@//bazel/config:windows_dbg_enabled": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
DEBUG_SYMBOLS = select({
|
||||
"@//bazel/config:windows_debug_symbols_enabled": True,
|
||||
"//conditions:default": False,
|
||||
})
|
||||
|
||||
DEFAULT_LINK_FLAGS = [
|
||||
"/MACHINE:X64",
|
||||
"/NODEFAULTLIB:library",
|
||||
|
|
@ -67,6 +102,13 @@ mongo_windows_cc_toolchain_config(
|
|||
toolchain_identifier = "msvc_x64",
|
||||
supports_parse_showincludes = True,
|
||||
smaller_binary = SMALLER_BINARY,
|
||||
warnings_as_errors_enabled = WARNINGS_AS_ERRORS_ENABLED,
|
||||
opt_debug = OPT_DEBUG,
|
||||
opt_off = OPT_OFF,
|
||||
opt_on = OPT_ON,
|
||||
opt_size = OPT_SIZE,
|
||||
dbg = DBG,
|
||||
debug_symbols = DEBUG_SYMBOLS,
|
||||
)
|
||||
|
||||
exports_files(["rc_wrapper.cmd"])
|
||||
|
|
|
|||
|
|
@ -1386,6 +1386,211 @@ def _impl(ctx):
|
|||
],
|
||||
)
|
||||
|
||||
warnings_as_errors_feature = feature(
|
||||
name = "warnings_as_errors",
|
||||
enabled = ctx.attr.warnings_as_errors_enabled,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/WX",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
|
||||
# /MD defines _MT and _DLL and links in MSVCRT.lib into each .obj file
|
||||
# /MDd defines _DEBUG, _MT, and _DLL and link MSVCRTD.lib into each .obj file
|
||||
multithreaded_feature = feature(
|
||||
name = "multithreaded",
|
||||
enabled = not ctx.attr.dbg,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/MD",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
single_threaded_feature = feature(
|
||||
name = "single_threaded",
|
||||
enabled = ctx.attr.dbg,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/MDd",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# /DEBUG will tell the linker to create a .pdb file which WinDbg and
|
||||
# Visual Studio will use to resolve symbols if you want to debug a
|
||||
# release-mode image.
|
||||
#
|
||||
# Note that this means we can't do parallel links in the build.
|
||||
#
|
||||
# Also note that this has nothing to do with _DEBUG or optimization.
|
||||
|
||||
# If the user set a /DEBUG flag explicitly, don't add another. Otherwise
|
||||
# use the standard /DEBUG flag, since we always want PDBs.
|
||||
debug_symbols_feature = feature(
|
||||
name = "debug_symbols",
|
||||
enabled = ctx.attr.debug_symbols,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["/Z7"],
|
||||
),
|
||||
],
|
||||
),
|
||||
flag_set(
|
||||
actions = all_link_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["/DEBUG"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# /O1 optimize for size
|
||||
# /O2 optimize for speed (as opposed to size)
|
||||
# /Oy- disable frame pointer optimization (overrides /O2, only affects 32-bit)
|
||||
# /Zo enables optimizations with modifications to make debugging easier
|
||||
opt_debug_feature = feature(
|
||||
name = "opt_debug",
|
||||
enabled = ctx.attr.opt_debug,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/Ox",
|
||||
"/Zo",
|
||||
"/Oy-",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
opt_off_feature = feature(
|
||||
name = "opt_off",
|
||||
enabled = ctx.attr.opt_off,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/Od",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
opt_on_feature = feature(
|
||||
name = "opt_on",
|
||||
enabled = ctx.attr.opt_on,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/O2",
|
||||
"/Oy-",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
opt_size_feature = feature(
|
||||
name = "opt_size",
|
||||
enabled = ctx.attr.opt_size,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [flag_group(flags = [
|
||||
"/Os",
|
||||
"/Oy-",
|
||||
])],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Enable Stack Frame Run-Time Error Checking; Reports when a variable is used
|
||||
# without having been initialized (implies /Od: no optimizations)
|
||||
stack_frame_error_checking_feature = feature(
|
||||
name = "stack_frame_error_checking",
|
||||
enabled = ctx.attr.opt_off and ctx.attr.dbg,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["/RTC1"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Windows non optimized builds will cause the PDB to blow up in size, this
|
||||
# allows a larger PDB. The flag is undocumented at the time of writing but the
|
||||
# microsoft thread which brought about its creation can be found here:
|
||||
# https://developercommunity.visualstudio.com/t/pdb-limit-of-4-gib-is-likely-to-be-a-problem-in-a/904784
|
||||
#
|
||||
# Without this flag MSVC will report a red herring error message, about disk
|
||||
# space or invalid path.
|
||||
pdb_page_size_feature = feature(
|
||||
name = "pdb_page_size",
|
||||
enabled = ctx.attr.opt_off,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["/pdbpagesize:16384"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# Disable incremental link - avoid the level of indirection for function calls
|
||||
incremental_feature = feature(
|
||||
name = "incremental",
|
||||
enabled = not ctx.attr.opt_off,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_link_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["/INCREMENTAL:NO"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
sasl_include_feature = feature(
|
||||
name = "sasl_include",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = all_compile_actions,
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = ["-Iexternal/windows_sasl/include"],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
features = [
|
||||
no_legacy_features_feature,
|
||||
nologo_feature,
|
||||
|
|
@ -1440,6 +1645,18 @@ def _impl(ctx):
|
|||
symbol_check_feature,
|
||||
mongodb_boost_all_no_lib_link_feature,
|
||||
win_level_3_warning_feature,
|
||||
warnings_as_errors_feature,
|
||||
multithreaded_feature,
|
||||
single_threaded_feature,
|
||||
debug_symbols_feature,
|
||||
opt_debug_feature,
|
||||
opt_off_feature,
|
||||
opt_on_feature,
|
||||
opt_size_feature,
|
||||
stack_frame_error_checking_feature,
|
||||
pdb_page_size_feature,
|
||||
incremental_feature,
|
||||
sasl_include_feature,
|
||||
]
|
||||
else:
|
||||
targets_windows_feature = feature(
|
||||
|
|
@ -1769,6 +1986,13 @@ mongo_windows_cc_toolchain_config = rule(
|
|||
"toolchain_identifier": attr.string(),
|
||||
"windows_version_minimal": attr.label(default = "//bazel/config:win_min_version"),
|
||||
"smaller_binary": attr.bool(default = False),
|
||||
"warnings_as_errors_enabled": attr.bool(default = True, mandatory = False),
|
||||
"opt_debug": attr.bool(default = False),
|
||||
"opt_off": attr.bool(default = False),
|
||||
"opt_on": attr.bool(default = False),
|
||||
"opt_size": attr.bool(default = False),
|
||||
"dbg": attr.bool(default = False),
|
||||
"debug_symbols": attr.bool(default = False),
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,28 +10,24 @@ exports_files([
|
|||
# This is a hack to work around the fact that the cc_library flag additional_compiler_inputs doesn't
|
||||
# exist in cc_binary. Instead, we add the denylists to srcs as header files to make them visible to
|
||||
# the compiler executable.
|
||||
symlink(
|
||||
filegroup(
|
||||
name = "asan_denylist_h",
|
||||
input = "asan.denylist",
|
||||
output = "asan.denylist.h",
|
||||
srcs = ["asan.denylist"],
|
||||
)
|
||||
|
||||
symlink(
|
||||
filegroup(
|
||||
name = "msan_denylist_h",
|
||||
input = "msan.denylist",
|
||||
output = "msan.denylist.h",
|
||||
srcs = ["msan.denylist"],
|
||||
)
|
||||
|
||||
symlink(
|
||||
filegroup(
|
||||
name = "tsan_denylist_h",
|
||||
input = "tsan.denylist",
|
||||
output = "tsan.denylist.h",
|
||||
srcs = ["tsan.denylist"],
|
||||
)
|
||||
|
||||
symlink(
|
||||
filegroup(
|
||||
name = "ubsan_denylist_h",
|
||||
input = "ubsan.denylist",
|
||||
output = "ubsan.denylist.h",
|
||||
srcs = ["ubsan.denylist"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
|
|
|||
|
|
@ -225,6 +225,8 @@ tasks:
|
|||
"src/bazel/**"
|
||||
"src/buildscripts/**"
|
||||
"src/docker_compose/**"
|
||||
"src/etc/BUILD.bazel"
|
||||
"src/etc/*san.denylist"
|
||||
"src/etc/*san.suppressions"
|
||||
"src/etc/backports_required_for_multiversion_tests.yml"
|
||||
"src/etc/evergreen.yml"
|
||||
|
|
|
|||
Loading…
Reference in New Issue