Commit efac62a3 by Sam Tebbs Committed by Sam Tebbs

[PATCH 2/3][GCC][AARCH64] Add new -mbranch-protection option to combine pointer signing and BTI

gcc/ChangeLog:

2019-01-08  Sam Tebbs  <sam.tebbs@arm.com>

	* config/aarch64/aarch64.c (BRANCH_PROTECT_STR_MAX,
	aarch64_parse_branch_protection,
	struct aarch64_branch_protect_type,
	aarch64_handle_no_branch_protection,
	aarch64_handle_standard_branch_protection,
	aarch64_validate_mbranch_protection,
	aarch64_handle_pac_ret_protection,
	aarch64_handle_attr_branch_protection,
	accepted_branch_protection_string,
	aarch64_pac_ret_subtypes,
	aarch64_branch_protect_types,
	aarch64_handle_pac_ret_leaf): Define.
	(aarch64_override_options_after_change_1, aarch64_override_options):
	Add check for accepted_branch_protection_string.
	(aarch64_option_save): Save accepted_branch_protection_string.
	(aarch64_option_restore): Save accepted_branch_protection_string.
	* config/aarch64/aarch64.c (aarch64_attributes): Add branch-protection.
	* config/aarch64/aarch64.opt: Add mbranch-protection. Deprecate
	msign-return-address.
	* doc/invoke.texi: Add mbranch-protection.

gcc/testsuite/Changelog:

2019-01-08  Sam Tebbs  <sam.tebbs@arm.com>

	* gcc.target/aarch64/(return_address_sign_1.c,
	return_address_sign_2.c, return_address_sign_3.c (__attribute__)):
	Change option to -mbranch-protection.
	* gcc.target/aarch64/(branch-protection-option.c,
	branch-protection-option-2.c, branch-protection-attr.c,
	branch-protection-attr-2.c): New file.

From-SVN: r267717
parent 35724e51
2019-01-08 Sam Tebbs <sam.tebbs@arm.com>
* config/aarch64/aarch64.c (BRANCH_PROTECT_STR_MAX,
aarch64_parse_branch_protection,
struct aarch64_branch_protect_type,
aarch64_handle_no_branch_protection,
aarch64_handle_standard_branch_protection,
aarch64_validate_mbranch_protection,
aarch64_handle_pac_ret_protection,
aarch64_handle_attr_branch_protection,
accepted_branch_protection_string,
aarch64_pac_ret_subtypes,
aarch64_branch_protect_types,
aarch64_handle_pac_ret_leaf): Define.
(aarch64_override_options_after_change_1, aarch64_override_options):
Add check for accepted_branch_protection_string.
(aarch64_option_save): Save accepted_branch_protection_string.
(aarch64_option_restore): Save accepted_branch_protection_string.
* config/aarch64/aarch64.c (aarch64_attributes): Add branch-protection.
* config/aarch64/aarch64.opt: Add mbranch-protection. Deprecate
msign-return-address.
* doc/invoke.texi: Add mbranch-protection.
2019-01-08 Alan Modra <amodra@gmail.com>
PR target/88614
......
......@@ -149,8 +149,12 @@ mpc-relative-literal-loads
Target Report Save Var(pcrelative_literal_loads) Init(2) Save
PC relative literal loads.
mbranch-protection=
Target RejectNegative Joined Var(aarch64_branch_protection_string) Save
Use branch-protection features.
msign-return-address=
Target RejectNegative Report Joined Enum(aarch64_ra_sign_scope_t) Var(aarch64_ra_sign_scope) Init(AARCH64_FUNCTION_NONE) Save
Target Deprecated RejectNegative Joined Enum(aarch64_ra_sign_scope_t) Var(aarch64_ra_sign_scope) Init(AARCH64_FUNCTION_NONE) Save
Select return address signing scope.
Enum
......
......@@ -631,6 +631,7 @@ Objective-C and Objective-C++ Dialects}.
-mlow-precision-recip-sqrt -mlow-precision-sqrt -mlow-precision-div @gol
-mpc-relative-literal-loads @gol
-msign-return-address=@var{scope} @gol
-mbranch-protection=@var{none}|@var{standard}|@var{pac-ret}[+@var{leaf}] @gol
-march=@var{name} -mcpu=@var{name} -mtune=@var{name} @gol
-moverride=@var{string} -mverbose-cost-dump -mtrack-speculation}
......@@ -15738,7 +15739,21 @@ Select the function scope on which return address signing will be applied.
Permissible values are @samp{none}, which disables return address signing,
@samp{non-leaf}, which enables pointer signing for functions which are not leaf
functions, and @samp{all}, which enables pointer signing for all functions. The
default value is @samp{none}.
default value is @samp{none}. This option has been deprecated by
-mbranch-protection.
@item -mbranch-protection=@var{none}|@var{standard}|@var{pac-ret}[+@var{leaf}]
@opindex mbranch-protection
Select the branch protection features to use.
@samp{none} is the default and turns off all types of branch protection.
@samp{standard} turns on all types of branch protection features. If a feature
has additional tuning options, then @samp{standard} sets it to its standard
level.
@samp{pac-ret[+@var{leaf}]} turns on return address signing to its standard
level: signing functions that save the return address to memory (non-leaf
functions will practically always do this) using the a-key. The optional
argument @samp{leaf} can be used to extend the signing to include leaf
functions.
@item -msve-vector-bits=@var{bits}
@opindex msve-vector-bits
2019-01-08 Sam Tebbs <sam.tebbs@arm.com>
* gcc.target/aarch64/(return_address_sign_1.c,
return_address_sign_2.c, return_address_sign_3.c (__attribute__)):
Change option to -mbranch-protection.
* gcc.target/aarch64/(branch-protection-option.c,
branch-protection-option-2.c, branch-protection-attr.c,
branch-protection-attr-2.c): New file.
2019-01-08 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/diagnostic/out-of-class-redeclaration.C: New.
......
/* { dg-do "compile" } */
void __attribute__ ((target("branch-protection=pac-ret+leaf,branch-protection=none")))
foo ()
{
}
void __attribute__ ((target("branch-protection=pac-ret,branch-protection=none")))
foo2 ()
{
/* Function call here to make this a non-leaf function, so that it is covered by pac-ret. */
foo ();
}
/* { dg-final { scan-assembler-not "\tautiasp\t" } } */
/* { dg-final { scan-assembler-not "\tpaciasp\t" } } */
/* { dg-do "compile" } */
void __attribute__ ((target("branch-protection=leaf")))
foo1 ()
{
}
/* { dg-error {invalid protection type \("leaf"\) in 'target\("branch-protection="\)' pragma or attribute} "" { target *-*-* } 5 } */
/* { dg-error {pragma or attribute 'target\("branch-protection=leaf"\)' is not valid} "" { target *-*-* } 5 } */
void __attribute__ ((target("branch-protection=none+pac-ret")))
foo2 ()
{
}
/* { dg-error "unexpected 'pac-ret' after 'none'" "" { target *-*-* } 12 } */
/* { dg-error {pragma or attribute 'target\("branch-protection=none\+pac-ret"\)' is not valid} "" { target *-*-* } 12 } */
void __attribute__ ((target("branch-protection=")))
foo3 ()
{
}
/* { dg-error {missing argument to 'target\("branch-protection="\)' pragma or attribute} "" { target *-*-* } 19 } */
/* { dg-error {pragma or attribute 'target\("branch-protection="\)' is not valid} "" { target *-*-* } 19 } */
/* { dg-do "compile" } */
/* { dg-options "-mbranch-protection=pac-ret+leaf -mbranch-protection=none" } */
void foo2 ()
{
}
/* { dg-final { scan-assembler-not "\tautiasp\t" } } */
/* { dg-final { scan-assembler-not "\tpaciasp\t" } } */
/* { dg-do "compile" } */
/* { dg-options "-mbranch-protection=leaf -mbranch-protection=none+pac-ret" } */
/* { dg-error "unexpected 'pac-ret' after 'none'" "" { target *-*-* } 0 } */
/* Testing return address signing where no combined instructions used. */
/* { dg-do compile } */
/* { dg-options "-O2 -msign-return-address=all" } */
/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf" } */
/* { dg-require-effective-target lp64 } */
int foo (int);
......
/* Testing return address signing where combined instructions used. */
/* { dg-do compile } */
/* { dg-options "-O2 -msign-return-address=all" } */
/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf" } */
/* { dg-require-effective-target lp64 } */
int foo (int);
......
/* Testing the disable of return address signing. */
/* { dg-do compile } */
/* { dg-options "-O2 -msign-return-address=all" } */
/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf" } */
/* { dg-require-effective-target lp64 } */
int bar (int, int);
int __attribute__ ((target ("arch=armv8.3-a, sign-return-address=non-leaf")))
int __attribute__ ((target ("arch=armv8.3-a, branch-protection=pac-ret")))
func1_leaf (int a, int b, int c, int d)
{
return a + b + c + d;
}
int __attribute__ ((target ("arch=armv8.3-a, sign-return-address=none")))
int __attribute__ ((target ("arch=armv8.3-a, branch-protection=none")))
func2_none (int a, int b, int c, int d)
{
return c + bar (a, b) + d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment