Skip to content

Commit abd7a9f

Browse files
ckolli5keith
andauthored
Remove -U_FORTIFY_SOURCE when thin_lto is enabled (bazelbuild#15433)
Clang does not accept `-U` flags when doing lto backend actions: ``` clang: error: argument unused during compilation: '-U _FORTIFY_SOURCE' [-Werror,-Wunused-command-line-argument] ``` This isn't a problem for `-D` flags because of a special case: https://github.com/llvm/llvm-project/blob/10e99eb7e4adbb8e2407e2f6ae3d2e6420d060c9/clang/lib/Driver/ToolChains/Clang.cpp#L5579-L5582 Closes bazelbuild#15007. PiperOrigin-RevId: 440314037 Co-authored-by: Keith Smiley <[email protected]>
1 parent 3d85b88 commit abd7a9f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tools/cpp/unix_cc_configure.bzl

-3
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,6 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
530530
"%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
531531
"%{compile_flags}": get_starlark_list(
532532
[
533-
# Security hardening requires optimization.
534-
# We need to undef it as some distributions now have it enabled by default.
535-
"-U_FORTIFY_SOURCE",
536533
"-fstack-protector",
537534
# All warnings are enabled. Maybe enable -Werror as well?
538535
"-Wall",

tools/cpp/unix_cc_toolchain_config.bzl

+15
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ def _impl(ctx):
173173
name = "default_compile_flags",
174174
enabled = True,
175175
flag_sets = [
176+
flag_set(
177+
actions = all_compile_actions,
178+
flag_groups = [
179+
flag_group(
180+
# Security hardening requires optimization.
181+
# We need to undef it as some distributions now have it enabled by default.
182+
flags = ["-U_FORTIFY_SOURCE"],
183+
),
184+
],
185+
with_features = [
186+
with_feature_set(
187+
not_features = ["thin_lto"],
188+
),
189+
],
190+
),
176191
flag_set(
177192
actions = all_compile_actions,
178193
flag_groups = ([

0 commit comments

Comments
 (0)