https://gcc.gnu.org/g:9a4b6b004f1b277ebf698686dd35517eecdde36d
commit 9a4b6b004f1b277ebf698686dd35517eecdde36d Author: Richard Ball <richard.b...@arm.com> Date: Mon Sep 16 14:50:47 2024 +0100 aarch64: Add tests and docs for indirect_return attribute This patch adds a new testcase and docs for the indirect_return attribute. gcc/ChangeLog: * doc/extend.texi: Add AArch64 docs for indirect_return attribute. gcc/testsuite/ChangeLog: * gcc.target/aarch64/indirect_return.c: New test. Co-authored-by: Yury Khrustalev <yury.khrusta...@arm.com> Diff: --- gcc/doc/extend.texi | 5 +++++ gcc/testsuite/gcc.target/aarch64/indirect_return.c | 25 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 42bd567119de..45e2b3ec5699 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4760,6 +4760,11 @@ Enable or disable calls to out-of-line helpers to implement atomic operations. This corresponds to the behavior of the command-line options @option{-moutline-atomics} and @option{-mno-outline-atomics}. +@cindex @code{indirect_return} function attribute, AArch64 +@item indirect_return +Used to inform the compiler that a function may return via +an indirect return. Adds a BTI J instruction under @option{mbranch-protection=} bti. + @end table The above target attributes can be specified as follows: diff --git a/gcc/testsuite/gcc.target/aarch64/indirect_return.c b/gcc/testsuite/gcc.target/aarch64/indirect_return.c new file mode 100644 index 000000000000..f1ef56d5557b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/indirect_return.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-mbranch-protection=bti" } */ + +int __attribute((indirect_return)) +foo (int a) +{ + return a; +} + +/* +**func1: +** hint 34 // bti c +** ... +** bl foo +** hint 36 // bti j +** ... +** ret +*/ +int +func1 (int a, int b) +{ + return foo (a + b); +} + +/* { dg-final { check-function-bodies "**" "" "" } } */