Skip to content

Commit aaad0cd

Browse files
BradshawzMongoDB Bot
authored and
MongoDB Bot
committed
SERVER-104108 Add simple_build_id and use linkopt -S on AL2023 (#35238)
GitOrigin-RevId: 2f65683f1441b5424de6137fef03b1461d0ae1fb
1 parent dabc243 commit aaad0cd

File tree

13 files changed

+110
-3
lines changed

13 files changed

+110
-3
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ common --flag_alias=tsan=//bazel/config:tsan
119119
common --flag_alias=ubsan=//bazel/config:ubsan
120120
common --flag_alias=dbg_level=//bazel/config:dbg_level
121121
common --flag_alias=mongo_toolchain_version=//bazel/config:mongo_toolchain_version
122+
common --flag_alias=simple_build_id=//bazel/config:simple_build_id
122123

123124
#############################################################################################################################
124125
# BUILD 'PROFILES' - this is the area to set up configurations of flags to be used by developers.

MODULE.bazel

+4
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@ register_toolchains(
176176
setup_local_host_values = use_repo_rule("//bazel/platforms:local_host_values.bzl", "setup_local_host_values")
177177

178178
setup_local_host_values(name = "local_host_values")
179+
180+
setup_evergreen_variables = use_repo_rule("//bazel/repository_rules:evergreen_variables.bzl", "setup_evergreen_variables")
181+
182+
setup_evergreen_variables(name = "evergreen_variables")

bazel/config/BUILD.bazel

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ load(
3535
"separate_debug",
3636
"server_js",
3737
"shared_archive",
38+
"simple_build_id",
3839
"skip_archive",
3940
"spider_monkey_dbg",
4041
"ssl",
@@ -2647,6 +2648,22 @@ selects.config_setting_group(
26472648
],
26482649
)
26492650

2651+
# --------------------------------------
2652+
# simple_build_id
2653+
# --------------------------------------
2654+
2655+
bool_flag(
2656+
name = "simple_build_id",
2657+
build_setting_default = False,
2658+
)
2659+
2660+
config_setting(
2661+
name = "simple_build_id_enabled",
2662+
flag_values = {
2663+
"//bazel/config:simple_build_id": "True",
2664+
},
2665+
)
2666+
26502667
# --------------------------------------
26512668
# running_through_bazelisk
26522669
# --------------------------------------

bazel/config/configs.bzl

+14
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@ compress_debug_compile = rule(
391391
build_setting = config.bool(flag = True),
392392
)
393393

394+
# =========
395+
# simple_build_id
396+
# =========
397+
398+
simple_build_id_provider = provider(
399+
doc = "Replace linker build-id with a simpler one based off output file name.",
400+
fields = ["enabled"],
401+
)
402+
403+
simple_build_id = rule(
404+
implementation = lambda ctx: simple_build_id_provider(enabled = ctx.build_setting_value),
405+
build_setting = config.bool(flag = True),
406+
)
407+
394408
# =========
395409
# detect_odr_violations
396410
# =========

bazel/mongo_src_rules.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ load(
3232
"extract_debuginfo_test",
3333
)
3434
load("@local_host_values//:local_host_values_set.bzl", "NUM_CPUS")
35+
load("@evergreen_variables//:evergreen_variables.bzl", "UNSAFE_COMPILE_VARIANT", "UNSAFE_VERSION_ID")
3536

3637
# These will throw an error if the following condition is not met:
3738
# (libunwind == on && os == linux) || libunwind == off || libunwind == auto
@@ -814,6 +815,9 @@ def _mongo_cc_binary_and_test(
814815
"//bazel/config:thin_lto_enabled": ["-Wl,--threads=" + str(NUM_CPUS)],
815816
"//bazel/config:bolt_enabled": ["-Wl,--threads=" + str(NUM_CPUS)],
816817
"//conditions:default": [],
818+
}) + select({
819+
"//bazel/config:simple_build_id_enabled": ["-Wl,--build-id=0x%x%x" % (hash(name), hash(str(UNSAFE_VERSION_ID) + str(UNSAFE_COMPILE_VARIANT)))],
820+
"//conditions:default": [],
817821
}),
818822
"linkstatic": LINKSTATIC_ENABLED,
819823
"local_defines": MONGO_GLOBAL_DEFINES + local_defines,
@@ -822,6 +826,9 @@ def _mongo_cc_binary_and_test(
822826
"features": SKIP_ARCHIVE_FEATURE + ["-pic", "pie"] + features + select({
823827
"//bazel/config:windows_debug_symbols_enabled": ["generate_pdb_file"],
824828
"//conditions:default": [],
829+
}) + select({
830+
"//bazel/config:simple_build_id_enabled": ["-build_id"],
831+
"//conditions:default": [],
825832
}),
826833
"dynamic_deps": select({
827834
"//bazel/config:linkstatic_disabled": deps,

bazel/repository_rules/BUILD.bazel

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def _setup_evergreen_variables(ctx):
2+
compile_variant = ctx.os.environ.get("compile_variant")
3+
version_id = ctx.os.environ.get("version_id")
4+
5+
ctx.file(
6+
"BUILD.bazel",
7+
"",
8+
)
9+
ctx.file(
10+
"evergreen_variables.bzl",
11+
"""
12+
UNSAFE_COMPILE_VARIANT = "%s"
13+
UNSAFE_VERSION_ID = "%s"
14+
""" % (compile_variant, version_id),
15+
)
16+
17+
setup_evergreen_variables = repository_rule(
18+
implementation = _setup_evergreen_variables,
19+
environ = ["compile_variant", "version_id"],
20+
)

bazel/toolchains/cc/mongo_linux/mongo_linux_cc_toolchain_config.bzl

+15-3
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,6 @@ def _impl(ctx):
10671067
flag_set(
10681068
actions = all_link_actions,
10691069
flag_groups = [flag_group(flags = [
1070-
# Explicitly enable GNU build id's if the linker supports it.
1071-
"-Wl,--build-id",
1072-
10731070
# Explicitly use the new gnu hash section if the linker offers it.
10741071
"-Wl,--hash-style=gnu",
10751072

@@ -1088,6 +1085,20 @@ def _impl(ctx):
10881085
],
10891086
)
10901087

1088+
build_id_feature = feature(
1089+
name = "build_id",
1090+
enabled = ctx.attr.compiler == COMPILERS.CLANG or ctx.attr.compiler == COMPILERS.GCC,
1091+
flag_sets = [
1092+
flag_set(
1093+
actions = all_link_actions,
1094+
flag_groups = [flag_group(flags = [
1095+
# Explicitly enable GNU build id's if the linker supports it.
1096+
"-Wl,--build-id",
1097+
])],
1098+
),
1099+
],
1100+
)
1101+
10911102
global_libs_feature = feature(
10921103
name = "global_libs",
10931104
enabled = True,
@@ -1210,6 +1221,7 @@ def _impl(ctx):
12101221
compress_debug_sections_feature,
12111222
rdynamic_feature,
12121223
global_libs_feature,
1224+
build_id_feature,
12131225
]
12141226

12151227
return [

etc/evergreen_yml_components/definitions.yml

+13
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,19 @@ functions:
25602560
content_type: application/gzip
25612561
display_name: Bazel JVM dump
25622562

2563+
"save bazel exec logs":
2564+
command: s3.put
2565+
params:
2566+
optional: true
2567+
aws_key: ${aws_key}
2568+
aws_secret: ${aws_secret}
2569+
local_file: src/bazel_exec.log
2570+
content_type: application/octet-stream
2571+
remote_file: ${project}/${build_variant}/${revision}/artifacts/bazel-exec.log.${build_id}-${task_name}.${execution}
2572+
bucket: mciuploads
2573+
permissions: public-read
2574+
display_name: Bazel exec log
2575+
25632576
### Attach report & artifacts ###
25642577
"create bazel test report":
25652578
command: subprocess.exec

etc/evergreen_yml_components/tasks/compile_tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ variables:
5454
- func: "save failed unittests"
5555
- func: "save bazel headers"
5656
- func: "save bazel jvm dump"
57+
- func: "save bazel exec logs"
5758
- func: "save hang analyzer debugger files"
5859
- func: "save disk statistics"
5960
- func: "save system resource information"

etc/evergreen_yml_components/tasks/compile_tasks_shared.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ variables:
2828
- func: "save failed unittests"
2929
- func: "save bazel headers"
3030
- func: "save bazel jvm dump"
31+
- func: "save bazel exec logs"
3132
- func: "save hang analyzer debugger files"
3233
- func: "save disk statistics"
3334
- func: "save system resource information"

etc/evergreen_yml_components/variants/amazon/test_dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ buildvariants:
9494
download_mongot_release: true
9595
compile_variant: *amazon-linux2023-arm64-static-compile
9696
evergreen_remote_exec: on
97+
skip_debug_link: true
9798
tasks:
9899
- name: compile_test_parallel_unittest_stream_TG
99100
- name: compile_test_parallel_core_stream_and_pretty_printer_tests_TG

evergreen/bazel_compile.sh

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ if [ "${build_mongot}" = "true" ]; then
8585
bazel_args="${bazel_args} --include_mongot=True"
8686
fi
8787

88+
# This is hacky way to pass off build time from archive_dist_test to archive_dist_test_debug
89+
# We create stripped binaries in archive_dist_test to avoid link time due to debug symbols
90+
# We then create the symbols normally in archive_dist_test_debug. We have to force the
91+
# build-id for debugging as they will be different when -Wl,-S is passed in.
92+
# The relinked binaries should still be hash identical when stripped with strip
93+
if [ "${skip_debug_link}" = "true" ]; then
94+
export compile_variant="${compile_variant}"
95+
export version_id="${version_id}"
96+
if [ "${task_name}" = "archive_dist_test" ]; then
97+
task_compile_flags="${task_compile_flags} --simple_build_id=True --linkopt='-Wl,-S' --separate_debug=False"
98+
fi
99+
if [ "${task_name}" = "archive_dist_test_debug" ]; then
100+
task_compile_flags="${task_compile_flags} --simple_build_id=True"
101+
fi
102+
fi
103+
88104
set -o pipefail
89105

90106
# Use `eval` to force evaluation of the environment variables in the echo statement:

0 commit comments

Comments
 (0)