SERVER-107041 Have default CI build with Clang LTO PGO (#41626)

GitOrigin-RevId: 12685112b052141b84371dd9f614ae316d16f1ec
This commit is contained in:
Andrew Bradshaw 2025-09-23 11:45:11 -07:00 committed by MongoDB Bot
parent cf41a80d0f
commit 1a437f9251
17 changed files with 87 additions and 26 deletions

View File

@ -323,7 +323,7 @@ common:opt --//bazel/config:dbg=False
common:opt --//bazel/config:dbg_level=2 common:opt --//bazel/config:dbg_level=2
common:opt --//bazel/config:debug_symbols=True common:opt --//bazel/config:debug_symbols=True
common:opt --//bazel/config:separate_debug=False common:opt --//bazel/config:separate_debug=False
common:opt --//bazel/config:compiler_type=gcc common:opt --//bazel/config:compiler_type=clang
common:opt --//bazel/config:linker=auto common:opt --//bazel/config:linker=auto
common:opt --//bazel/config:linkstatic=True common:opt --//bazel/config:linkstatic=True
common:opt --//bazel/config:build_enterprise=True common:opt --//bazel/config:build_enterprise=True
@ -345,7 +345,6 @@ common:opt_profiled --//bazel/config:separate_debug=True
common:opt_profiled --//bazel/config:compiler_type=clang common:opt_profiled --//bazel/config:compiler_type=clang
common:opt_profiled --//bazel/config:dtlto=True common:opt_profiled --//bazel/config:dtlto=True
common:opt_profiled --//bazel/config:pgo_profile_use=True common:opt_profiled --//bazel/config:pgo_profile_use=True
common:opt_profiled --//bazel/config:bolt_profile_use=True
common:opt_profiled --enable_platform_specific_config=true common:opt_profiled --enable_platform_specific_config=true
--config=evg --config=evg

View File

@ -2305,11 +2305,13 @@ config_setting(
) )
selects.config_setting_group( selects.config_setting_group(
name = "dtlto_linux_clang_enabled_fission_disabled", name = "dtlto_linux_clang_enabled_fission_disabled_linkstatic_enabled",
match_all = [ match_all = [
":linux_clang", ":linux_clang",
":linkstatic_enabled",
":dtlto_enabled", ":dtlto_enabled",
":fission_disabled", ":fission_disabled",
":not_s390x_or_ppc",
], ],
) )
@ -2392,17 +2394,21 @@ config_setting(
) )
selects.config_setting_group( selects.config_setting_group(
name = "pgo_profile_use_clang_enabled", name = "pgo_profile_use_clang_enabled_linkstatic_enabled",
match_all = [ match_all = [
":linux_clang", ":linux_clang",
":linkstatic_enabled",
":not_s390x_or_ppc",
":pgo_profile_use_enabled", ":pgo_profile_use_enabled",
], ],
) )
selects.config_setting_group( selects.config_setting_group(
name = "pgo_profile_use_gcc_enabled", name = "pgo_profile_use_gcc_enabled_linkstatic_enabled",
match_all = [ match_all = [
":linux_gcc", ":linux_gcc",
":linkstatic_enabled",
":not_s390x_or_ppc",
":pgo_profile_use_enabled", ":pgo_profile_use_enabled",
], ],
) )

View File

@ -1108,6 +1108,21 @@ def _impl(ctx):
], ],
) )
clang_toolchain_resource_dir_feature = feature(
name = "clang_toolchain_resource_dir",
enabled = ctx.attr.compiler == COMPILERS.CLANG,
flag_sets = [
flag_set(
actions = all_link_actions + lto_index_actions,
flag_groups = [
flag_group(
flags = ["-resource-dir=" + CLANG_RESOURCE_DIR],
),
],
),
],
)
# Some of the linux versions are missing libatomic.so.1 - this is a hack so mold will use the one contained # Some of the linux versions are missing libatomic.so.1 - this is a hack so mold will use the one contained
# within the mongo toolchain rather than needing one installed on the machine # within the mongo toolchain rather than needing one installed on the machine
mold_shared_libraries_feature = feature( mold_shared_libraries_feature = feature(
@ -1154,14 +1169,6 @@ def _impl(ctx):
), ),
], ],
), ),
flag_set(
actions = all_link_actions + lto_index_actions,
flag_groups = [
flag_group(
flags = ["-resource-dir=" + CLANG_RESOURCE_DIR] if ctx.attr.compiler == COMPILERS.CLANG else [""],
),
],
),
], ],
) )
@ -1424,6 +1431,7 @@ def _impl(ctx):
debug_types_section_feature, debug_types_section_feature,
no_debug_types_section_feature, no_debug_types_section_feature,
strip_debug_feature, strip_debug_feature,
clang_toolchain_resource_dir_feature,
] + get_common_features(ctx) ] + get_common_features(ctx)
return [ return [

View File

@ -98,8 +98,8 @@ PGO_PROFILE_GENERATE_ENABLED = select({
}) })
PGO_PROFILE_USE_ENABLED = select({ PGO_PROFILE_USE_ENABLED = select({
"@//bazel/config:pgo_profile_use_clang_enabled": "@pgo_data//:clang_pgo_files", "@//bazel/config:pgo_profile_use_clang_enabled_linkstatic_enabled": "@pgo_data//:clang_pgo_files",
"@//bazel/config:pgo_profile_use_gcc_enabled": "@pgo_data//:gcc_pgo_files", "@//bazel/config:pgo_profile_use_gcc_enabled_linkstatic_enabled": "@pgo_data//:gcc_pgo_files",
"@//conditions:default": None, "@//conditions:default": None,
}) })
@ -109,9 +109,9 @@ PROPELLER_PROFILE_GENERATE_ENABLED = select({
}) })
DTLTO_ENABLED = select({ DTLTO_ENABLED = select({
"@//bazel/config:dtlto_linux_clang_enabled_fission_disabled": True, "@//bazel/config:dtlto_linux_clang_enabled_fission_disabled_linkstatic_enabled": True,
"@//bazel/config:dtlto_disabled": False, "@//conditions:default": False,
}, no_match_error = "Distributed Thin LTO is only available for linux clang with fission disabled.") })
LINK_FLAGS = ["-L" + flag for flag in COMMON_LINK_FLAGS] + LINKER_LINKFLAGS LINK_FLAGS = ["-L" + flag for flag in COMMON_LINK_FLAGS] + LINKER_LINKFLAGS
@ -119,8 +119,8 @@ LINK_FLAGS = ["-L" + flag for flag in COMMON_LINK_FLAGS] + LINKER_LINKFLAGS
filegroup( filegroup(
name = "all_files", name = "all_files",
srcs = glob(["**/*"]) + select({ srcs = glob(["**/*"]) + select({
"@//bazel/config:pgo_profile_use_clang_enabled": ["@pgo_data//:clang_pgo_files"], "@//bazel/config:pgo_profile_use_clang_enabled_linkstatic_enabled": ["@pgo_data//:clang_pgo_files"],
"@//bazel/config:pgo_profile_use_gcc_enabled": ["@pgo_data//:gcc_pgo_files"], "@//bazel/config:pgo_profile_use_gcc_enabled_linkstatic_enabled": ["@pgo_data//:gcc_pgo_files"],
"@//conditions:default": [], "@//conditions:default": [],
}) })
) )

View File

@ -6,8 +6,10 @@ def _extensions_transition_impl(settings, attr):
""" """
return { return {
"//bazel/config:allocator": "system", "//bazel/config:allocator": "system",
"//bazel/config:dtlto": False,
"//bazel/config:shared_archive": True, "//bazel/config:shared_archive": True,
"//bazel/config:linkstatic": True, "//bazel/config:linkstatic": True,
"//bazel/config:pgo_profile_use": False,
"//bazel/config:skip_archive": True, "//bazel/config:skip_archive": True,
"//bazel/config:asan": settings.get("//bazel/config:asan", False), "//bazel/config:asan": settings.get("//bazel/config:asan", False),
"//bazel/config:fsan": settings.get("//bazel/config:fsan", False), "//bazel/config:fsan": settings.get("//bazel/config:fsan", False),
@ -22,8 +24,10 @@ extensions_transition = transition(
inputs = [], inputs = [],
outputs = [ outputs = [
"//bazel/config:allocator", "//bazel/config:allocator",
"//bazel/config:dtlto",
"//bazel/config:shared_archive", "//bazel/config:shared_archive",
"//bazel/config:linkstatic", "//bazel/config:linkstatic",
"//bazel/config:pgo_profile_use",
"//bazel/config:skip_archive", "//bazel/config:skip_archive",
"//bazel/config:asan", "//bazel/config:asan",
"//bazel/config:fsan", "//bazel/config:fsan",

View File

@ -15,6 +15,9 @@ ALLOW_LINES = [
"common --config=local", "common --config=local",
"--experimental_throttle_remote_action_building", "--experimental_throttle_remote_action_building",
"--noexperimental_throttle_remote_action_building", "--noexperimental_throttle_remote_action_building",
"--dtlto=False",
"--pgo_profile_use=False",
"--bolt_profile_use=False",
] ]

View File

@ -127,6 +127,7 @@ tasks:
${additional_compile_targets|} ${additional_compile_targets|}
bazel_args: >- bazel_args: >-
--config=evg --config=evg
--config=opt_profiled
- func: "f_expansions_write" - func: "f_expansions_write"
- command: subprocess.exec - command: subprocess.exec
params: params:
@ -282,6 +283,7 @@ tasks:
archive-dist-test-debug install-dist-test archive-dist-test-debug install-dist-test
bazel_args: >- bazel_args: >-
--config=evg --config=evg
--config=opt_profiled
- func: "upload debugsymbols" - func: "upload debugsymbols"
- func: "f_expansions_write" - func: "f_expansions_write"
- command: subprocess.exec - command: subprocess.exec
@ -419,6 +421,7 @@ tasks:
${additional_package_targets|} ${additional_package_targets|}
bazel_args: >- bazel_args: >-
--config=evg --config=evg
--config=opt_profiled
- command: subprocess.exec - command: subprocess.exec
params: params:
binary: bash binary: bash

View File

@ -153,6 +153,7 @@ buildvariants:
--jobs=1600 --jobs=1600
--build_atlas=True --build_atlas=True
--config=opt_profiled --config=opt_profiled
--bolt_profile_use=True
unittest_library_compile_flags: >- unittest_library_compile_flags: >-
--config=evg --config=evg
--linkstatic=False --linkstatic=False

View File

@ -20,6 +20,7 @@ buildvariants:
# We need to compensate for SMT8 setting the cpu count very high and lower the amount of parallelism down # We need to compensate for SMT8 setting the cpu count very high and lower the amount of parallelism down
bazel_compile_flags: >- bazel_compile_flags: >-
--define=MONGO_DISTMOD=rhel81 --define=MONGO_DISTMOD=rhel81
--compiler_type=gcc
core_analyzer_distro_name: rhel81-power8-large core_analyzer_distro_name: rhel81-power8-large
resmoke_jobs_factor: 0.25 resmoke_jobs_factor: 0.25
has_packages: true has_packages: true
@ -89,6 +90,7 @@ buildvariants:
# We need to compensate for SMT8 setting the cpu count very high and lower the amount of parallelism down # We need to compensate for SMT8 setting the cpu count very high and lower the amount of parallelism down
bazel_compile_flags: >- bazel_compile_flags: >-
--define=MONGO_DISTMOD=rhel9 --define=MONGO_DISTMOD=rhel9
--compiler_type=gcc
core_analyzer_distro_name: rhel9-power-large core_analyzer_distro_name: rhel9-power-large
resmoke_jobs_factor: 0.25 resmoke_jobs_factor: 0.25
has_packages: true has_packages: true
@ -134,6 +136,7 @@ buildvariants:
bazel_compile_flags: >- bazel_compile_flags: >-
--linkstatic=False --linkstatic=False
--define=MONGO_DISTMOD=rhel9 --define=MONGO_DISTMOD=rhel9
--compiler_type=gcc
compile_variant: enterprise-rhel-9-ppc64le-shared compile_variant: enterprise-rhel-9-ppc64le-shared
tasks: tasks:
- name: compile_test_serial_TG - name: compile_test_serial_TG
@ -159,6 +162,7 @@ buildvariants:
test_flags: --excludeWithAnyTags=incompatible_with_s390x test_flags: --excludeWithAnyTags=incompatible_with_s390x
bazel_compile_flags: >- bazel_compile_flags: >-
--define=MONGO_DISTMOD=rhel83 --define=MONGO_DISTMOD=rhel83
--compiler_type=gcc
core_analyzer_distro_name: rhel83-zseries-large core_analyzer_distro_name: rhel83-zseries-large
resmoke_jobs_max: 2 resmoke_jobs_max: 2
has_packages: true has_packages: true
@ -200,6 +204,7 @@ buildvariants:
bazel_compile_flags: >- bazel_compile_flags: >-
--linkstatic=False --linkstatic=False
--define=MONGO_DISTMOD=rhel83 --define=MONGO_DISTMOD=rhel83
--compiler_type=gcc
compile_variant: enterprise-rhel-83-s390x-shared compile_variant: enterprise-rhel-83-s390x-shared
exec_timeout_secs: 86400 # 24 hours exec timeout exec_timeout_secs: 86400 # 24 hours exec timeout
tasks: tasks:
@ -226,6 +231,7 @@ buildvariants:
test_flags: --excludeWithAnyTags=incompatible_with_s390x test_flags: --excludeWithAnyTags=incompatible_with_s390x
bazel_compile_flags: >- bazel_compile_flags: >-
--define=MONGO_DISTMOD=rhel9 --define=MONGO_DISTMOD=rhel9
--compiler_type=gcc
core_analyzer_distro_name: rhel9-zseries-large core_analyzer_distro_name: rhel9-zseries-large
resmoke_jobs_max: 2 resmoke_jobs_max: 2
has_packages: true has_packages: true
@ -267,6 +273,7 @@ buildvariants:
bazel_compile_flags: >- bazel_compile_flags: >-
--linkstatic=False --linkstatic=False
--define=MONGO_DISTMOD=rhel9 --define=MONGO_DISTMOD=rhel9
--compiler_type=gcc
compile_variant: enterprise-rhel-9-s390x-shared compile_variant: enterprise-rhel-9-s390x-shared
exec_timeout_secs: 86400 # 24 hours exec timeout exec_timeout_secs: 86400 # 24 hours exec timeout
tasks: tasks:

View File

@ -91,6 +91,10 @@ variables:
bazel_compile_flags: >- bazel_compile_flags: >-
--remote_execution_priority=3 --remote_execution_priority=3
--dbg=True --dbg=True
--compiler_type=gcc
--dtlto=False
--pgo_profile_use=False
--bolt_profile_use=False
--opt=on --opt=on
--build_otel=True --build_otel=True
--build_enterprise=False --build_enterprise=False
@ -756,6 +760,8 @@ buildvariants:
--opt=on --opt=on
--ubsan=True --ubsan=True
--compiler_type=clang --compiler_type=clang
--dtlto=False
--pgo_profile_use=False
--allocator=tcmalloc-gperf --allocator=tcmalloc-gperf
--separate_debug=False --separate_debug=False
compile_variant: *rhel8-debug-ubsan-roll-back-incremental-feature-flags compile_variant: *rhel8-debug-ubsan-roll-back-incremental-feature-flags

View File

@ -405,6 +405,8 @@ buildvariants:
--opt=on --opt=on
--ubsan=True --ubsan=True
--compiler_type=clang --compiler_type=clang
--dtlto=False
--pgo_profile_use=False
--allocator=tcmalloc-gperf --allocator=tcmalloc-gperf
--separate_debug=False --separate_debug=False
compile_variant: *rhel8-debug-ubsan-all-feature-flags compile_variant: *rhel8-debug-ubsan-all-feature-flags

View File

@ -31,6 +31,8 @@ buildvariants:
bazel_compile_flags: >- bazel_compile_flags: >-
--define=MONGO_DISTMOD=ubuntu2204 --define=MONGO_DISTMOD=ubuntu2204
--compiler_type=clang --compiler_type=clang
--dtlto=False
--pgo_profile_use=False
--copt=-fsanitize-coverage=trace-pc-guard --copt=-fsanitize-coverage=trace-pc-guard
--linkopt=-lvoidstar --linkopt=-lvoidstar

View File

@ -49,5 +49,5 @@ tests:
- thread_level: 1 - thread_level: 1
metrics: metrics:
- name: instructions_per_iteration_mean - name: instructions_per_iteration_mean
threshold_limit: 350 threshold_limit: 13000
bound_direction: upper bound_direction: upper

View File

@ -1,7 +1,6 @@
load("@poetry//:dependencies.bzl", "dependency") load("@poetry//:dependencies.bzl", "dependency")
load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_binary", "mongo_cc_fuzzer_test", "mongo_cc_integration_test", "mongo_cc_library", "mongo_cc_unit_test", "mongo_idl_library") load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_binary", "mongo_cc_fuzzer_test", "mongo_cc_integration_test", "mongo_cc_library", "mongo_cc_unit_test", "mongo_idl_library")
load("//bazel/config:render_template.bzl", "render_template") load("//bazel/config:render_template.bzl", "render_template")
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_flags_v5.bzl", "CLANG_RESOURCE_DIR")
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
@ -3683,7 +3682,6 @@ mongo_cc_binary(
"//bazel/config:pgo_profile_generate_clang_enabled": [ "//bazel/config:pgo_profile_generate_clang_enabled": [
"-fprofile-generate=mongod_perf", "-fprofile-generate=mongod_perf",
"-fno-data-sections", "-fno-data-sections",
"-resource-dir=" + CLANG_RESOURCE_DIR,
], ],
"//bazel/config:pgo_profile_generate_gcc_enabled": [ "//bazel/config:pgo_profile_generate_gcc_enabled": [
"-fprofile-generate=mongod_perf", "-fprofile-generate=mongod_perf",

View File

@ -85,9 +85,11 @@ if __name__ == "__main__":
try: try:
gdb.execute("run") gdb.execute("run")
gdb.execute("frame function main") gdb.execute("frame function main")
test_decorable() # TODO(SERVER-110170): Currently bugged in clang
# test_decorable()
test_dbname_nss() test_dbname_nss()
test_string_map() # TODO(SERVER-110170): Currently bugged in clang
# test_string_map()
test_boost_optional() test_boost_optional()
gdb.write("TEST PASSED\n") gdb.write("TEST PASSED\n")
except Exception as err: except Exception as err:

View File

@ -550,6 +550,10 @@ mongo_cc_library(
"dist/absl/base/internal/unscaledcycleclock.cc", "dist/absl/base/internal/unscaledcycleclock.cc",
], ],
hdrs = ABSEIL_HEADERS, hdrs = ABSEIL_HEADERS,
copts = select({
"//bazel/config:ppc_or_s390x": ["-Wno-sign-conversion"],
"//conditions:default": [],
}),
includes = ["dist"], includes = ["dist"],
skip_global_deps = ABSEIL_SKIP_GLOBAL_DEPS, skip_global_deps = ABSEIL_SKIP_GLOBAL_DEPS,
deps = [ deps = [
@ -779,6 +783,10 @@ mongo_cc_library(
"dist/absl/debugging/stacktrace.cc", "dist/absl/debugging/stacktrace.cc",
], ],
hdrs = ABSEIL_HEADERS, hdrs = ABSEIL_HEADERS,
copts = select({
"//bazel/config:ppc_or_s390x": ["-Wno-shorten-64-to-32"],
"//conditions:default": [],
}),
includes = ["dist"], includes = ["dist"],
skip_global_deps = ABSEIL_SKIP_GLOBAL_DEPS, skip_global_deps = ABSEIL_SKIP_GLOBAL_DEPS,
deps = [ deps = [
@ -1943,7 +1951,14 @@ mongo_cc_library(
], ],
hdrs = ABSEIL_HEADERS, hdrs = ABSEIL_HEADERS,
copts = select({ copts = select({
"//bazel/config:gcc_or_clang": ["-Wno-pass-failed"], "//bazel/config:gcc_or_clang": [
"-Wno-pass-failed",
],
"//conditions:default": [],
}) + select({
"//bazel/config:ppc_or_s390x": [
"-Wno-deprecate-lax-vec-conv-all",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
includes = ["dist"], includes = ["dist"],

View File

@ -79,6 +79,11 @@ mongo_cc_library(
"-Wno-deprecated-volatile", "-Wno-deprecated-volatile",
"-Wno-sign-compare", "-Wno-sign-compare",
], ],
}) + select({
"//bazel/config:ppc_or_s390x": [
"-Wno-unused-but-set-variable",
],
"//conditions:default": [],
}), }),
features = select({ features = select({
"//bazel/config:compiler_type_gcc": ["no_volatile"], "//bazel/config:compiler_type_gcc": ["no_volatile"],