From 88fbe993b7d572c3ff595c1bf8de95bb04e23be5 Mon Sep 17 00:00:00 2001 From: Andrew Bradshaw Date: Fri, 22 May 2026 15:24:38 -0700 Subject: [PATCH] SERVER-113557 Bolt binary before we split off symbols (#53518) GitOrigin-RevId: 069728752853014198cebeeb28d972538d2c8c5a --- BUILD.bazel | 25 +++---------------------- bazel/config/BUILD.bazel | 5 +++++ bazel/install_rules/bolt.bzl | 31 +++++++++++++++++++++++++------ bazel/mongo_src_rules.bzl | 21 ++++++++++++++++++++- src/mongo/db/BUILD.bazel | 1 + 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 41cd2dbffd3..d5bbf0cb6ad 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -8,7 +8,7 @@ load("@rules_pkg//:pkg.bzl", "pkg_tar") load("@rules_python//python:defs.bzl", "py_binary") load("//bazel:mongo_js_rules.bzl", "mongo_js_library") load("//bazel/config:render_template.bzl", "render_template") -load("//bazel/install_rules:bolt.bzl", "bolt_instrument", "bolt_optimize") +load("//bazel/install_rules:bolt.bzl", "bolt_instrument") load("//bazel/install_rules:install_rules.bzl", "TEST_TAGS", "mongo_install") load("//bazel/toolchains/cc/mongo_linux:mongo_gdb.bzl", "setup_gdb_toolchain_aliases") load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain.bzl", "setup_mongo_toolchain_aliases") @@ -241,14 +241,12 @@ mongo_install( mongo_install( name = "dist", srcs = [ + "//src/mongo/db:mongod", "//src/mongo/installer/compass:compass_files", "//src/mongo/s:mongos", ] + select({ "@platforms//os:windows": ["@local_windows_msvc//:vc_redist_x64"], "//conditions:default": [], - }) + select({ - "//bazel/config:bolt_profile_use_enabled": ["//:bolt_optimized_mongod"], - "//conditions:default": ["//src/mongo/db:mongod"], }), include_files = select({ "//bazel/config:al2023_x86_64": { @@ -331,6 +329,7 @@ copy_to_directory( mongo_install( name = "dist-test", srcs = [ + "//src/mongo/db:mongod", "//src/mongo/db:mongotrafficreader", "//src/mongo/db/query/query_tester:mongotest", "//src/mongo/db/query/search/mongotmock", @@ -352,9 +351,6 @@ mongo_install( }) + select({ "//bazel/config:include_mongot_enabled": ["//:mongot_folder"], "//conditions:default": [], - }) + select({ - "//bazel/config:bolt_profile_use_enabled": ["//:bolt_optimized_mongod"], - "//conditions:default": ["//src/mongo/db:mongod"], }), include_files = select({ "//bazel/config:al2023_x86_64": { @@ -618,21 +614,6 @@ bolt_instrument( }), ) -bolt_optimize( - name = "bolt_optimized_mongod", - binary_to_optimize = "//src/mongo/db:mongod", - exec_properties = { - "no-cache": "1", - "no-remote": "1", - "local": "1", - }, - perf_data = "@bolt_data//:bolt_fdata", - target_compatible_with = select({ - "//bazel/config:bolt_profile_use_enabled": [], - "//conditions:default": ["@platforms//:incompatible"], - }), -) - filegroup( name = "clang_tidy_config_files", srcs = [ diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index b87863ef024..ed8c81eeb56 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -2543,8 +2543,13 @@ bool_flag( config_setting( name = "bolt_profile_use_enabled", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], flag_values = { "//bazel/config:bolt_profile_use": "True", + "//bazel/config:compiler_type": "clang", }, ) diff --git a/bazel/install_rules/bolt.bzl b/bazel/install_rules/bolt.bzl index af304b3731c..f28e8a699fc 100644 --- a/bazel/install_rules/bolt.bzl +++ b/bazel/install_rules/bolt.bzl @@ -35,17 +35,17 @@ bolt_instrument = rule( attrs = { "binary_to_instrument": attr.label(allow_files = True), "instrumentation_output_file": attr.string(), - "_bolt_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt", executable = True, cfg = "host"), + "_bolt_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt", executable = True, cfg = "exec"), "_bolt_needed_lib": attr.label(allow_single_file = True, default = "@bolt_binaries//:libbolt_rt_instr"), }, ) def _bolt_optimize_impl(ctx): input_binary = ctx.files.binary_to_optimize[0] - output_binary = ctx.actions.declare_file(ctx.files.binary_to_optimize[0].basename) + output_binary = ctx.actions.declare_file(ctx.label.name + "/" + input_binary.basename) functions_to_skip = ",".join(SKIP_FUNCTIONS) ctx.actions.run( - inputs = [input_binary], + inputs = [input_binary, ctx.files.perf_data[0]], outputs = [output_binary], executable = ctx.executable._bolt_binary, arguments = [ @@ -62,17 +62,36 @@ def _bolt_optimize_impl(ctx): "-dyno-stats", "--lite", "--update-debug-sections", + # objcopy will leave bad data like program headers in the .debug file without this + "--use-gnu-stack", "-skip-funcs=" + functions_to_skip, ], mnemonic = "BoltOptimize", + execution_requirements = { + "no-cache": "1", + "no-sandbox": "1", + "no-remote": "1", + "local": "1", + }, ) - return DefaultInfo(files = depset([output_binary])) + + return [ + DefaultInfo(files = depset([output_binary]), executable = output_binary), + ctx.attr.binary_to_optimize[CcInfo], + ctx.attr.binary_to_optimize[DebugPackageInfo], + RunEnvironmentInfo( + environment = ctx.attr.binary_to_optimize[RunEnvironmentInfo].environment, + inherited_environment = ctx.attr.binary_to_optimize[RunEnvironmentInfo].inherited_environment, + ), + ] bolt_optimize = rule( implementation = _bolt_optimize_impl, attrs = { - "binary_to_optimize": attr.label(allow_files = True), + "binary_to_optimize": attr.label(allow_files = True, providers = [CcInfo]), "perf_data": attr.label(allow_single_file = True), - "_bolt_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt", executable = True, cfg = "host"), + "_bolt_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt", executable = True, cfg = "exec"), }, + executable = True, + provides = [CcInfo, DefaultInfo], ) diff --git a/bazel/mongo_src_rules.bzl b/bazel/mongo_src_rules.bzl index 6c58e3199d8..30d06a1d7dd 100644 --- a/bazel/mongo_src_rules.bzl +++ b/bazel/mongo_src_rules.bzl @@ -13,6 +13,7 @@ load( ) load("@bazel_skylib//lib:selects.bzl", "selects") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") +load("//bazel/install_rules:bolt.bzl", "bolt_optimize") load("@com_github_grpc_grpc//bazel:generate_cc.bzl", "generate_cc") load("@poetry//:dependencies.bzl", "dependency") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_shared_library") @@ -545,6 +546,7 @@ def _mongo_cc_binary_and_test( skip_global_deps = [], env = {}, _program_type = "", + bolt_profile = None, skip_windows_crt_flags = False, auto_header = True, srcs_select = None, @@ -720,9 +722,24 @@ def _mongo_cc_binary_and_test( if _program_type == "binary": cc_binary(**args) + + if bolt_profile != None: + bolt_optimize( + name = name + "_bolt", + binary_to_optimize = ":" + name + WITH_DEBUG_SUFFIX, + perf_data = bolt_profile, + target_compatible_with = select({ + "//bazel/config:bolt_profile_use_enabled": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + ) + extract_debuginfo_binary( name = name, - binary_with_debug = ":" + name + WITH_DEBUG_SUFFIX, + binary_with_debug = select({ + "//bazel/config:bolt_profile_use_enabled": ":" + name + "_bolt", + "//conditions:default": ":" + name + WITH_DEBUG_SUFFIX, + }) if bolt_profile != None else ":" + name + WITH_DEBUG_SUFFIX, type = "program", tags = original_tags + ["final_target"], enabled = SEPARATE_DEBUG_ENABLED, @@ -766,6 +783,7 @@ def mongo_cc_binary( exec_properties = {}, skip_global_deps = [], env = {}, + bolt_profile = None, **kwargs): """Wrapper around cc_binary. @@ -818,6 +836,7 @@ def mongo_cc_binary( skip_global_deps, env, _program_type = "binary", + bolt_profile = bolt_profile, **kwargs ) diff --git a/src/mongo/db/BUILD.bazel b/src/mongo/db/BUILD.bazel index 25524a727f9..e74a45c076c 100644 --- a/src/mongo/db/BUILD.bazel +++ b/src/mongo/db/BUILD.bazel @@ -2858,6 +2858,7 @@ mongo_cc_binary( srcs = [ "mongod.cpp", ], + bolt_profile = "@bolt_data//:bolt_fdata", cxxopts = select({ "//bazel/config:pgo_profile_generate_clang_enabled": [ "-fprofile-generate=mongod_perf",