public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "andrew.cooper3 at citrix dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/102953] Improvements to CET-IBT and ENDBR generation
Date: Fri, 29 Oct 2021 22:57:28 +0000	[thread overview]
Message-ID: <bug-102953-4-LdYXVm5dI2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102953-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102953

--- Comment #17 from Andrew Cooper <andrew.cooper3 at citrix dot com> ---
I think I've found a bug in the -fcf-check-attribute implementation.

  $ cat fnptr-array-arg.c
  static int __attribute__((cf_check)) foo(char a[], int b)
  {
      return 0;
  }
  int (*ptr)(char[], int) = foo;

  $ gcc -Wall -fcf-protection=branch -mmanual-endbr -fcf-check-attribute=no -c
fnptr-array-arg.c -o tmp.o && objdump -d tmp.o
  fnptr-array-arg.c:5:27: warning: initialization of 'int (*)(char *, int)'
from incompatible pointer type 'int (__attribute__((nocf_check)) *)(char *,
int)' [-Wincompatible-pointer-types]
      5 | int (*ptr)(char[], int) = foo;
        |                           ^~~

  tmp.o:     file format elf64-x86-64


  Disassembly of section .text:

  0000000000000000 <foo>:
     0: 31 c0                   xor    %eax,%eax
     2: c3                      retq   


Despite the explicit cf_check, a diagnostic is raised complaining about
cf_check-ness of the pointer, and the generated code has no `endbr64`
instruction.

This issue only manifests when using array arguments in the function.  When
switching `char[]` for `char*`, everything works as expected.  Also, dropping
-fcf-check-attribute=no also causes things to work.

  $ gcc -Wall -fcf-protection=branch -mmanual-endbr -c fnptr-array-arg.c -o
tmp.o && objdump -d tmp.o

  tmp.o:     file format elf64-x86-64


  Disassembly of section .text:

  0000000000000000 <foo>:
     0: f3 0f 1e fa             endbr64 
     4: 31 c0                   xor    %eax,%eax
     6: c3                      retq   


Something about the array type seems to cause the explicit cf_check attribute
to be lost.

  parent reply	other threads:[~2021-10-29 22:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 17:01 [Bug c/102953] New: " andrew.cooper3 at citrix dot com
2021-10-26 20:45 ` [Bug target/102953] " hjl.tools at gmail dot com
2021-10-26 21:31 ` hjl.tools at gmail dot com
2021-10-26 22:48 ` hjl.tools at gmail dot com
2021-10-26 22:49 ` hjl.tools at gmail dot com
2021-10-27  8:38 ` peterz at infradead dot org
2021-10-27 13:40 ` hjl.tools at gmail dot com
2021-10-27 18:50 ` andrew.cooper3 at citrix dot com
2021-10-27 23:48 ` andrew.cooper3 at citrix dot com
2021-10-28  1:53 ` hjl.tools at gmail dot com
2021-10-28  1:53 ` hjl.tools at gmail dot com
2021-10-28 10:40 ` andrew.cooper3 at citrix dot com
2021-10-28 13:17 ` hjl.tools at gmail dot com
2021-10-28 13:17 ` hjl.tools at gmail dot com
2021-10-28 17:36 ` andrew.cooper3 at citrix dot com
2021-10-28 19:11 ` hjl.tools at gmail dot com
2021-10-28 19:12 ` hjl.tools at gmail dot com
2021-10-29 22:57 ` andrew.cooper3 at citrix dot com [this message]
2021-10-30  0:03 ` hjl.tools at gmail dot com
2021-10-30  0:04 ` hjl.tools at gmail dot com
2021-10-30  0:51 ` andrew.cooper3 at citrix dot com
2021-10-30  4:03 ` andrew.cooper3 at citrix dot com
2021-10-30 12:22 ` hjl.tools at gmail dot com
2021-11-05 11:11 ` andrew.cooper3 at citrix dot com
2021-11-05 14:29 ` hjl.tools at gmail dot com
2022-02-23 20:34 ` andrew.cooper3 at citrix dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102953-4-LdYXVm5dI2@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).