about summary refs log tree commit diff
path: root/sysdeps/aarch64/sysdep.h
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-05-13 12:10:13 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-07-08 15:02:38 +0100
commitc94767712b06fd37e82d23f86d4d6e1c93948d8a (patch)
tree73b1fac75a8b862f14ceaceee7c0f2f3ccf8b908 /sysdeps/aarch64/sysdep.h
parent1be3d6eb823d8b952fa54b7bbc90cbecb8981380 (diff)
downloadglibc-c94767712b06fd37e82d23f86d4d6e1c93948d8a.tar.gz
glibc-c94767712b06fd37e82d23f86d4d6e1c93948d8a.tar.xz
glibc-c94767712b06fd37e82d23f86d4d6e1c93948d8a.zip
aarch64: fix pac-ret support in _mcount
Currently gcc -pg -mbranch-protection=pac-ret passes signed return
address to _mcount, so _mcount now has to always strip pac from the
frompc since that's from user code that may be built with pac-ret.

This is gcc PR target/94791: signed pointers should not escape and get
passed across extern call boundaries, since that's an ABI break, but
because existing gcc has this issue we work it around in glibc until
that is resolved. This is compatible with a fixed gcc and it is a nop
on systems without PAuth support. The bug was introduced in gcc-7 with
-msign-return-address=non-leaf|all support which in gcc-9 got renamed
to -mbranch-protection=pac-ret|pac-ret+leaf|standard.

strip_pac uses inline asm instead of __builtin_aarch64_xpaclri since
that is not a documented api and not available in all supported gccs.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/aarch64/sysdep.h')
-rw-r--r--sysdeps/aarch64/sysdep.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index cd88023163..f442506952 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -35,6 +35,17 @@
 
 #define PTR_SIZE	(1<<PTR_LOG_SIZE)
 
+#ifndef __ASSEMBLER__
+/* Strip pointer authentication code from pointer p.  */
+static inline void *
+strip_pac (void *p)
+{
+  register void *ra asm ("x30") = (p);
+  asm ("hint 7 // xpaclri" : "+r"(ra));
+  return ra;
+}
+#endif
+
 #ifdef	__ASSEMBLER__
 
 /* Syntactic details of assembler.  */