Fix CFE handling of `-fcf-protection=check` for CET.
Ensures CFE correctly reports CET status, not misinterpreting `-fcf-protection=check`.
This commit corrects how the D language front-end (CFE) interprets the -fcf-protection=check compiler flag regarding Control-flow Enforcement Technology (CET). Previously, this flag, which is ignored at compile time but sets internal flags, caused the D front-end to incorrectly report CET as enabled. The fix ensures that CET-related version identifiers and features (GNU_CET and __traits(getTargetInfo, "CET")) are only defined and reported when actual CET protection mechanisms like IBT or SHSTK are enabled, aligning D’s behavior with C family front-ends.
In Details
In gcc/config/i386/i386-d.cc, the commit refines the ix86_d_target_versions and ix86_d_handle_target_cf_protection functions. Previously, flag_cf_protection being set to CF_CHECK | CF_SET by -fcf-protection=check incorrectly triggered the definition of GNU_CET and returned a CET version of 8 from __traits(getTargetInfo, "CET"). This patch ensures GNU_CET is only defined when CF_BRANCH or CF_RETURN is set, and __traits(getTargetInfo, "CET") only returns the bits corresponding to these actual protections, aligning with C/C++ front-ends and fixing PR target/128373.
- i386
- Refers to the 32-bit Intel architecture instruction set and its subsequent extensions. In this context, it relates to compiler support and specific behaviors for this processor family.
- CET
- Control-flow Enforcement Technology. A hardware security feature on modern processors designed to mitigate control-flow hijacking attacks, such as return-oriented programming (ROP) and jump-oriented programming (JOP).
- -fcf-protection=check
- A GCC compiler flag that enables runtime checks for control-flow integrity. When set to 'check', it instruments code to detect potential control-flow violations, but unlike 'branch' or 'return', it does not enable hardware enforcement mechanisms directly.
- D front end
- The part of the GCC compiler responsible for parsing and processing source code written in the D programming language.
- GNU_CET
- A version identifier related to Control-flow Enforcement Technology, likely used within GCC to signal support or features related to CET.
- IBT
- Indirect Branch Tracking. A component of Intel's CET that provides hardware protection against attacks that hijack indirect branches.
- SHSTK
- Shadow Stack. A component of Intel's CET that provides hardware protection against attacks targeting the call stack, such as stack smashing.