Bug 2273610

Summary: -fhardened -fcf-protection=none does not cause a warning
Product: [Fedora] Fedora Reporter: Václav Kadlčík <vkadlcik>
Component: gccAssignee: Marek Polacek <mpolacek>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 40CC: dmalcolm, fweimer, jakub, jlaw, josmyers, jwakely, mcermak, mpolacek, msebor, nickc, nixuser, sipoyare
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: gcc-14.1.1-1.fc40 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-05-17 14:13:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Václav Kadlčík 2024-04-05 10:16:17 UTC
When a user uses -fhardened and explicitly weakens any of the hardening
measures implies by -fhardened, a warning should appear IIUIC.

-fhardened implies -fcf-protection=full. I tried to override it by all
the remaining -fcf-protection and I indeed receive the warning except
for -fcf-protection=none which seems strange.

Reproducible: Always

Steps to Reproduce:
$ cat files/main.cc
#include <iostream>
using namespace std;

int main(void) {
    cout << "hello world" << endl;
    return 0;
}

# not actually overriding -> no warning as expected
$ g++ -fhardened -fcf-protection=full -Whardened -O2 -o cxx_hello.exe main.cc

# overriding to branch-only -> warning as expected
$ g++ -fhardened -fcf-protection=branch -Whardened -O2 -o cxx_hello.exe main.cc
cc1plus: warning: ‘-fcf-protection=full’ is not enabled by ‘-fhardened’ because it was specified on the command line [-Whardened]

# overriding to none (disabling it altogether) -> no warning???
$ g++ -fhardened -fcf-protection=none -Whardened -O2 -o cxx_hello.exe main.cc

Comment 1 Marek Polacek 2024-04-05 16:12:48 UTC
Good catch, thanks Vaclav.

Comment 2 Marek Polacek 2024-04-12 14:26:43 UTC
Fixed upstream.