Skip to content

Commit e34d6e4

Browse files
keithcopybara-github
authored andcommitted
Remove -U_FORTIFY_SOURCE when thin_lto is enabled
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 #15007. PiperOrigin-RevId: 440314037
1 parent 01d337f commit e34d6e4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tools/cpp/unix_cc_configure.bzl

Lines changed: 0 additions & 3 deletions
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.
538535
"-Wall",

tools/cpp/unix_cc_toolchain_config.bzl

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

0 commit comments

Comments
 (0)