Skip to content

Commit 2855959

Browse files
committed
bazel: simplify lto flags
Introduce --config=lto mixin which sets -flto=thin for C++ compile and link. Remove src/v/redpanda specific handling of the link flag, we pass this to all links now. This is effectively a no-op as lld will use LTO mode when inputs have only IR anyway. You can mix --config=lto with other build modes (most usefully, release) even without PGO.
1 parent f0b1836 commit 2855959

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

.bazelrc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ build:san-all --//bazel:sanitizer_mode=all
132132
build:san-all --copt=-fsanitize=address,undefined,vptr,function,alignment
133133
build:san-all --linkopt=-fsanitize=address,undefined,vptr,function,alignment
134134

135+
# LTO mixin: enable LTO for C++ and Rust. Usually mixed in with
136+
# PGO + release, but should work with any.
137+
build:lto --copt -flto=thin
138+
build:lto --linkopt -flto=thin
139+
build:lto --@rules_rust//rust/settings:lto=fat
140+
build:lto --@rules_rust//rust/settings:extra_rustc_flag=-Ccodegen-units=1
141+
# I've seen others claim these flags help with LTO and the final binary, but these also
142+
# require a specific version of clang and I don't really want to tie rustc version with
143+
# clang version.
144+
# build:lto --@rules_rust//rust/settings:extra_rustc_flag=-Clinker-plugin-lto
145+
# build:lto --@rules_rust//rust/settings:extra_rustc_flag=-Cembed-bitcode=yes
146+
# build:lto --@rules_rust//rust/settings:extra_rustc_flag=-Clink-arg=-fuse-ld=lld
147+
135148
################################################
136149
# PRIMARY BUILD MODES
137150
#
@@ -251,23 +264,10 @@ build:release --host_cxxopt=-U_LIBCPP_HARDENING_MODE
251264
build:release --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE
252265
build:release --host_cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE
253266

254-
# Separate PGO configs to be combined with release
255-
256-
# Enable LTO only in PGO build to save time in other builds
257-
build:pgo-base --//src/v/redpanda:lto=True
258-
build:pgo-base --copt -flto=thin
259-
build:pgo-base --@rules_rust//rust/settings:lto=fat
260-
build:pgo-base --@rules_rust//rust/settings:extra_rustc_flag=-Ccodegen-units=1
261-
# I've seen others claim these flags help with LTO and the final binary, but these also
262-
# require a specific version of clang and I don't really want to tie rustc version with
263-
# clang version.
264-
# build:pgo-base --@rules_rust//rust/settings:extra_rustc_flag=-Clinker-plugin-lto
265-
# build:pgo-base --@rules_rust//rust/settings:extra_rustc_flag=-Cembed-bitcode=yes
266-
# build:pgo-base --@rules_rust//rust/settings:extra_rustc_flag=-Clink-arg=-fuse-ld=lld
267267

268268
# Instrumentation/training step
269269
# Empty arg is intentional, we provide the path via env var at run time
270-
build:pgo-instrument --config=pgo-base --fdo_instrument=
270+
build:pgo-instrument --config=lto --fdo_instrument=
271271

272272
# Final/Optimization build step
273273

@@ -278,7 +278,7 @@ build:pgo-instrument --config=pgo-base --fdo_instrument=
278278

279279
# bazel seems to pass -fprofile-correction unconditionally but that only exists
280280
# in gcc so need to make clang ignore it
281-
build:pgo-optimize --config=pgo-base --copt -Wno-ignored-optimization-argument
281+
build:pgo-optimize --config=lto --copt -Wno-ignored-optimization-argument
282282

283283

284284
build:stamp --stamp --workspace_status_command=./bazel/stamp_vars.sh

src/v/redpanda/BUILD

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,6 @@ redpanda_cc_library(
124124
],
125125
)
126126

127-
# Enable or disable (thin) LTO for the redpanda binary (only)
128-
bool_flag(
129-
name = "lto",
130-
build_setting_default = False,
131-
)
132-
133-
config_setting(
134-
name = "use_lto",
135-
flag_values = {
136-
":lto": "true",
137-
},
138-
visibility = ["//visibility:public"],
139-
)
140-
141127
# Enable or disable --emit-relocs for the redpanda binary (only)
142128
bool_flag(
143129
name = "emit_relocs",
@@ -158,14 +144,6 @@ redpanda_cc_binary(
158144
"main.cc",
159145
],
160146
linkopts =
161-
select({
162-
":use_lto": [
163-
"-flto=thin",
164-
"-ffat-lto-objects",
165-
],
166-
"//conditions:default": [
167-
],
168-
}) +
169147
select({
170148
":use_emit_relocs": [
171149
"-Wl,--emit-relocs",

0 commit comments

Comments
 (0)