x86; Add -mmanual-endbr and cf_check function attribute
authorH.J. Lu <hongjiu.lu@intel.com>
Fri, 14 Dec 2018 21:35:36 +0000 (21:35 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Fri, 14 Dec 2018 21:35:36 +0000 (13:35 -0800)
commit06553c89f521477d6c3ec4023d5162f90c57111d
treec6d500a4d04a1fcee026fc1b5125e4a7a2b05a31
parentc759830b29fff2288bc0cebfb4b2c479f0b5b30e
x86; Add -mmanual-endbr and cf_check function attribute

Currently GCC inserts ENDBR instruction at entries of all non-static
functions, unless LTO compilation is used.  Marking all functions,
which are not called indirectly with nocf_check attribute, is not
ideal since 99% of functions in a program may be of this kind.

This patch adds -mmanual-endbr and cf_check function attribute.  They
can be used together with -fcf-protection such that ENDBR instruction
is inserted only at entries of functions with cf_check attribute.  It
can limit number of ENDBR instructions to reduce program size.

gcc/

* config/i386/i386.c (rest_of_insert_endbranch): Insert ENDBR
at the function entry only when -mmanual-endbr isn't used or
there is cf_check function attribute.
(ix86_attribute_table): Add cf_check.
* config/i386/i386.opt: Add -mmanual-endbr.
* doc/extend.texi: Document cf_check attribute.
* doc/invoke.texi: Document -mmanual-endbr.

gcc/testsuite/

* gcc.target/i386/cf_check-1.c: New test.
* gcc.target/i386/cf_check-2.c: Likewise.
* gcc.target/i386/cf_check-3.c: Likewise.
* gcc.target/i386/cf_check-4.c: Likewise.
* gcc.target/i386/cf_check-5.c: Likewise.

From-SVN: r267154
gcc/ChangeLog
gcc/config/i386/i386.c
gcc/config/i386/i386.opt
gcc/doc/extend.texi
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/cf_check-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-5.c [new file with mode: 0644]