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 c/102953] New: Improvements to CET-IBT and ENDBR generation
Date: Tue, 26 Oct 2021 17:01:20 +0000	[thread overview]
Message-ID: <bug-102953-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102953
           Summary: Improvements to CET-IBT and ENDBR generation
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew.cooper3 at citrix dot com
  Target Milestone: ---

Hello,

With CET-IBT, ENDBR{32,64} instructions are used to mark legitimate forward
edges for indirect branches.

GCC can generate a CET-IBT binary with -fcf-protection, but the default
behaviour is to generate ENDBR instructions for every function.  This creates
more "legal" forward edges than necessary in the eyes of CET-IBT.

https://godbolt.org/z/M15rjMb4G is almost excellent, but it would be far more
helpful if all functions were implicitly nocf_check, so this example produces a
diagnostic.  That way, GCC can point out all functions used by function
pointers, rather than the result compiling and failing to be CET-IBT
compatible.

This on its own would be enough to let embedded projects minimise their ENDBR*
count while having some compiler assistance while doing so.


More generally, a lot of common cases (e.g. Linux) could be computed
automatically.  Drivers filling in ops structures typically refer to local
symbols, so these defaulting to cf_check would be an improvement still.  This
would leave only global symbols needing explicit cf_check.  (Maybe LTO could
even figure out the global symbols cases correctly?)

Finally, one minor code generation improvement.  When GCC emits a direct
call/jmp to an ENDBR'd symbol, it can actually use sym+4 as an optimisation to
skip the ENDBR instruction (not needed for direct call/jmp's) and save on
decode bandwidth.

             reply	other threads:[~2021-10-26 17:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 17:01 andrew.cooper3 at citrix dot com [this message]
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
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@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).