https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126823
Bug ID: 126823
Summary: -fhardened applied partially after target rejection,
with no per-constituent report
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: hello at bjornpagen dot com
Target Milestone: ---
Host: aarch64-apple-darwin24
Target: aarch64-apple-darwin24
Build: aarch64-apple-darwin24
On Darwin, GCC rejects -fhardened but keeps two of its constituents enabled. It
silently drops the other compile-side constituents. GCC should either reject
the option before applying any constituent or report the exact partial result.
Testcase:
int main(){return 0;}
Command:
g++-16 -fhardened -Whardened -O2 -E -dM -x c++ /dev/null | grep -E
'SSP|FORTIFY|GLIBCXX'
Compiler output:
cc1plus: warning: '-fhardened' not supported for this target
#define __SSP_STRONG__ 3
A plain -O2 run defines none of these macros. _FORTIFY_SOURCE and
_GLIBCXX_ASSERTIONS are absent with -fhardened.
The matching -Q --help=common comparison shows:
-fhardened [disabled] -> [enabled]
-fstack-protector-strong [disabled] -> [enabled]
-ftrivial-auto-var-init=... uninitialized -> zero
-fstack-clash-protection remains disabled in both runs. -Whardened reports none
of these differences.
Expected result:
If GCC rejects -fhardened, it enables no constituents. Otherwise, GCC reports
each enabled and skipped constituent.
Versions tested:
GCC 16.1.0 reproduces the defect on aarch64-apple-darwin24.
GCC master commit 475e9efffaf8de781d7e17b687faf1807e104b01 was inspected, not
run on Darwin. The option ordering and target gate remain unchanged.
The Linux control on GCC 16.1.0 enables the full umbrella without this warning.
No official Darwin GCC build is available.
Environment:
Using built-in specs.
COLLECT_GCC=g++-16
COLLECT_LTO_WRAPPER=/Users/bjorn/.gcc/versions/16.1.0/libexec/gcc/aarch64-apple-darwin24/16.1.0/lto-wrapper
Target: aarch64-apple-darwin24
Configured with: ../gcc-16.1.0/configure
--prefix=/Users/bjorn/.gcc/versions/16.1.0 --enable-languages=c,c++
--disable-nls --enable-checking=release --program-suffix=-16 --with-system-zlib
--build=aarch64-apple-darwin24
--with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.1.0 (GCC)
PR 126822 reports the separate warning-class defect for the same target
rejection.