mirrored from git://gcc.gnu.org/git/gcc.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AArch64][1/4] Support Return address protection on AArch64
gcc/ * config/aarch64/aarch64-opts.h (aarch64_function_type): New enum. * config/aarch64/aarch64-protos.h (aarch64_return_address_signing_enabled): New declaration. * config/aarch64/aarch64.c (aarch64_return_address_signing_enabled): New function. (aarch64_expand_prologue): Sign return address before it's pushed onto stack. (aarch64_expand_epilogue): Authenticate return address fetched from stack. (aarch64_override_options): Sanity check for ILP32 and ISA level. (aarch64_attributes): New function attributes for "sign-return-address". * config/aarch64/aarch64.md (UNSPEC_AUTI1716, UNSPEC_AUTISP, UNSPEC_PACI1716, UNSPEC_PACISP, UNSPEC_XPACLRI): New unspecs. ("*do_return"): Generate combined instructions according to key index. ("<pauth_mnem_prefix>sp", "<pauth_mnem_prefix1716", "xpaclri"): New. * config/aarch64/iterators.md (PAUTH_LR_SP, PAUTH_17_16): New integer iterators. (pauth_mnem_prefix, pauth_hint_num_a): New integer attributes. * config/aarch64/aarch64.opt (msign-return-address=): New. * doc/extend.texi (AArch64 Function Attributes): Documents "sign-return-address=". * doc/invoke.texi (AArch64 Options): Documents "-msign-return-address=". gcc/testsuite/ * gcc.target/aarch64/return_address_sign_1.c: New testcase for no combined instructions. * gcc.target/aarch64/return_address_sign_2.c: New testcase for combined instructions. * gcc.target/aarch64/return_address_sign_3.c: New testcase for disable of pointer authentication. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244666 138bc75d-0d04-0410-961f-82ee72b054a4
- Loading branch information
jiwang
committed
Jan 20, 2017
1 parent
f36ff00
commit 06f29de
Showing
13 changed files
with
271 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* Testing return address signing where no combined instructions used. */ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-O2 -msign-return-address=all" } */ | ||
|
||
int foo (int); | ||
|
||
/* sibcall only. */ | ||
int __attribute__ ((target ("arch=armv8.3-a"))) | ||
func1 (int a, int b) | ||
{ | ||
/* paciasp */ | ||
return foo (a + b); | ||
/* autiasp */ | ||
} | ||
|
||
/* non-leaf function with sibcall. */ | ||
int __attribute__ ((target ("arch=armv8.3-a"))) | ||
func2 (int a, int b) | ||
{ | ||
/* paciasp */ | ||
if (a < b) | ||
return b; | ||
|
||
a = foo (b); | ||
|
||
return foo (a); | ||
/* autiasp */ | ||
} | ||
|
||
/* non-leaf function, legacy arch. */ | ||
int __attribute__ ((target ("arch=armv8.2-a"))) | ||
func3 (int a, int b, int c) | ||
{ | ||
/* paciasp */ | ||
return a + foo (b) + c; | ||
/* autiasp */ | ||
} | ||
|
||
/* eh_return. */ | ||
void __attribute__ ((target ("arch=armv8.3-a"))) | ||
func4 (long offset, void *handler, int *ptr, int imm1, int imm2) | ||
{ | ||
/* paciasp */ | ||
*ptr = imm1 + foo (imm1) + imm2; | ||
__builtin_eh_return (offset, handler); | ||
/* autiasp */ | ||
return; | ||
} | ||
|
||
/* { dg-final { scan-assembler-times "autiasp" 4 } } */ | ||
/* { dg-final { scan-assembler-times "paciasp" 4 } } */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Testing return address signing where combined instructions used. */ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-O2 -msign-return-address=all" } */ | ||
|
||
int foo (int); | ||
int bar (int, int); | ||
|
||
int __attribute__ ((target ("arch=armv8.3-a"))) | ||
func1 (int a, int b, int c) | ||
{ | ||
/* paciasp */ | ||
return a + foo (b) + c; | ||
/* retaa */ | ||
} | ||
|
||
/* { dg-final { scan-assembler-times "paciasp" 1 } } */ | ||
/* { dg-final { scan-assembler-times "retaa" 1 } } */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Testing the disable of return address signing. */ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-O2 -msign-return-address=all" } */ | ||
|
||
int bar (int, int); | ||
|
||
int __attribute__ ((target ("arch=armv8.3-a, sign-return-address=non-leaf"))) | ||
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"))) | ||
func2_none (int a, int b, int c, int d) | ||
{ | ||
return c + bar (a, b) + d; | ||
} | ||
|
||
/* { dg-final { scan-assembler-not "paciasp" } } */ | ||
/* { dg-final { scan-assembler-not "autiasp" } } */ | ||
/* { dg-final { scan-assembler-not "retaa" } } */ |