[pushed] i386: Do not define __CET__ for -fcf-protection=check [PR128373]
Checks
Commit Message
-fcf-protection=check is ignored at compile time, but it sets
flag_cf_protection to CF_CHECK | CF_SET, so ix86_target_macros defined
__CET__=8 even though neither IBT nor SHSTK is enabled. Assembly files
including <cet.h> then emitted a GNU_PROPERTY_X86_FEATURE_1_AND note
with a zero value.
Define __CET__ only when CF_BRANCH or CF_RETURN is set, and expose
only those bits in its value.
Assisted-by: Claude Sonnet 5.5
PR target/128373
gcc/ChangeLog:
* config/i386/i386-c.cc (ix86_target_macros):
Define __CET__ only when CF_BRANCH or CF_RETURN is set.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr128373-1.c: New test.
* gcc.target/i386/pr128373-2.c: Ditto.
Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.
Uros.
Comments
On Tue, Nov 3, 2026 at 6:45 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> -fcf-protection=check is ignored at compile time, but it sets
> flag_cf_protection to CF_CHECK | CF_SET, so ix86_target_macros defined
> __CET__=8 even though neither IBT nor SHSTK is enabled. Assembly files
> including <cet.h> then emitted a GNU_PROPERTY_X86_FEATURE_1_AND note
> with a zero value.
>
> Define __CET__ only when CF_BRANCH or CF_RETURN is set, and expose
> only those bits in its value.
LGTM.
> Assisted-by: Claude Sonnet 5.5
>
> PR target/128373
>
> gcc/ChangeLog:
>
> * config/i386/i386-c.cc (ix86_target_macros):
> Define __CET__ only when CF_BRANCH or CF_RETURN is set.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr128373-1.c: New test.
> * gcc.target/i386/pr128373-2.c: Ditto.
>
> Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.
>
> Uros.
@@ -977,8 +977,9 @@ ix86_target_macros (void)
cpp_define (parse_in, "__SEG_FS");
cpp_define (parse_in, "__SEG_GS");
- if (flag_cf_protection != CF_NONE)
- cpp_define_formatted (parse_in, "__CET__=%d", flag_cf_protection & ~CF_SET);
+ if (flag_cf_protection & (CF_BRANCH | CF_RETURN))
+ cpp_define_formatted (parse_in, "__CET__=%d",
+ flag_cf_protection & (CF_BRANCH | CF_RETURN));
}
new file mode 100644
@@ -0,0 +1,7 @@
+/* PR target/128373 */
+/* { dg-do preprocess { target *-*-linux* } } */
+/* { dg-options "-fcf-protection=check -march=x86-64" } */
+
+#ifdef __CET__
+# error "__CET__ must not be defined with -fcf-protection=check"
+#endif
new file mode 100644
@@ -0,0 +1,7 @@
+/* PR target/128373 */
+/* { dg-do preprocess { target *-*-linux* } } */
+/* { dg-options "-fcf-protection=full -fcf-protection=check -march=x86-64" } */
+
+#if __CET__ != 3
+# error "__CET__ must be 3 with -fcf-protection=full"
+#endif