]> git.ipfire.org Git - thirdparty/gcc.git/commit
driver: -fhardened and -z lazy/-z norelro [PR117739]
authorMarek Polacek <polacek@redhat.com>
Tue, 26 Nov 2024 19:37:21 +0000 (14:37 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 13 Feb 2025 22:17:16 +0000 (17:17 -0500)
commita134dcd8a010744a0097d190f73a4efc2e381531
treee358ce920fda691dc363074e2cfa139aec9db9e3
parenta560b5b5b508f39294989ee2559fcecdd2d8924a
driver: -fhardened and -z lazy/-z norelro [PR117739]

As the manual states, using "-fhardened -fstack-protector" will produce
a warning because -fhardened wants to enable -fstack-protector-strong,
but it can't since it's been overriden by the weaker -fstack-protector.

-fhardened also attempts to enable -Wl,-z,relro,-z,now.  By the same
logic as above, "-fhardened -z norelro" or "-fhardened -z lazy" should
produce the same warning.  But we don't detect this combination, so
this patch fixes it.  I also renamed a variable to better reflect its
purpose.

Also don't check warn_hardened in process_command, since it's always
true there.

Also tweak wording in the manual as Jon Wakely suggested on IRC.

PR driver/117739

gcc/ChangeLog:

* doc/invoke.texi: Tweak wording for -Whardened.
* gcc.cc (driver_handle_option): If -z lazy or -z norelro was
specified, don't enable linker hardening.
(process_command): Don't check warn_hardened.

gcc/testsuite/ChangeLog:

* c-c++-common/fhardened-16.c: New test.
* c-c++-common/fhardened-17.c: New test.
* c-c++-common/fhardened-18.c: New test.
* c-c++-common/fhardened-19.c: New test.
* c-c++-common/fhardened-20.c: New test.
* c-c++-common/fhardened-21.c: New test.

Reviewed-by: Jakub Jelinek <jakub@redhat.com>
gcc/doc/invoke.texi
gcc/gcc.cc
gcc/testsuite/c-c++-common/fhardened-16.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fhardened-17.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fhardened-18.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fhardened-19.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fhardened-20.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fhardened-21.c [new file with mode: 0644]