Skip to content

Commit

Permalink
Remove -U_FORTIFY_SOURCE when thin_lto is enabled (bazelbuild#15433)
Browse files Browse the repository at this point in the history
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 <keithbsmiley@gmail.com>
  • Loading branch information
ckolli5 and keith committed May 9, 2022
1 parent 3d85b88 commit abd7a9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 0 additions & 3 deletions tools/cpp/unix_cc_configure.bzl
Expand Up @@ -530,9 +530,6 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
"%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
"%{compile_flags}": get_starlark_list(
[
# Security hardening requires optimization.
# We need to undef it as some distributions now have it enabled by default.
"-U_FORTIFY_SOURCE",
"-fstack-protector",
# All warnings are enabled. Maybe enable -Werror as well?
"-Wall",
Expand Down
15 changes: 15 additions & 0 deletions tools/cpp/unix_cc_toolchain_config.bzl
Expand Up @@ -173,6 +173,21 @@ def _impl(ctx):
name = "default_compile_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
# Security hardening requires optimization.
# We need to undef it as some distributions now have it enabled by default.
flags = ["-U_FORTIFY_SOURCE"],
),
],
with_features = [
with_feature_set(
not_features = ["thin_lto"],
),
],
),
flag_set(
actions = all_compile_actions,
flag_groups = ([
Expand Down

0 comments on commit abd7a9f

Please sign in to comment.