public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [AARCH64]: Pointer mangling support for Aarch64
@ 2013-12-26 12:25 Venkataramanan Kumar
  2013-12-26 19:33 ` Richard Henderson
  2014-01-06 18:11 ` Tom Tromey
  0 siblings, 2 replies; 20+ messages in thread
From: Venkataramanan Kumar @ 2013-12-26 12:25 UTC (permalink / raw)
  To: libc-ports
  Cc: Marcus Shawcroft, Marcus Shawcroft, Carlos O'Donell, Patch Tracking

[-- Attachment #1: Type: text/plain, Size: 914 bytes --]

Hi Maintainers,

This patch adds pointer mangling support for Aarch64.
Regressed by cross testing glibc tests on V8 Foundation model running
a linaro open embedded image.

Ok for trunk? Please provide your feedback.

ChangeLog.aarch64:
-----------------------------
2013-12-26  Venkataramanan Kumar  <venkataramanan.kumar@linaro.org>

* sysdeps/aarch64/__longjmp.S (__longjmp): Demangle sp
        and lr when restoring register values.
* sysdeps/aarch64/setjmp.S (__sigsetjmp): Mangle sp and lr
before storing register values.
* sysdeps/arm/jmpbuf-unwind.h (_jmpbuf_sp): Remove.
* sysdeps/aarch64/jmpbuf-offsets.h (_jmpbuf_sp): Add.
(JB_FRAME_ADDRESS): call  _jmpbuf_sp.
* sysdeps/aarch64/sysdep.h (LDST_PCREL) : New macros.
(LDST_GLOBAL): Likewise.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (PTR_MANGLE): New macro.
(PTR_DEMANGLE): Likewise.
(PTR_MANGLE2): Likewise.
(PTR_DEMANGLE2): Likewise.

regards
Venkat.

[-- Attachment #2: aarch64.glibc.pointer.mangle.txt --]
[-- Type: text/plain, Size: 6063 bytes --]

diff --git a/ports/sysdeps/aarch64/__longjmp.S b/ports/sysdeps/aarch64/__longjmp.S
index ffd30a2..fcff7eb 100644
--- a/ports/sysdeps/aarch64/__longjmp.S
+++ b/ports/sysdeps/aarch64/__longjmp.S
@@ -50,8 +50,13 @@ ENTRY (__longjmp)
 	ldp	x23, x24, [x0, #JB_X23<<3]
 	ldp	x25, x26, [x0, #JB_X25<<3]
 	ldp	x27, x28, [x0, #JB_X27<<3]
+#ifdef PTR_DEMANGLE
 	ldp	x29, x30, [x0, #JB_X29<<3]
-
+	PTR_DEMANGLE (x4, x30, x3, x2)
+	mov	x30, x4	
+#else
+	ldp	x29, x30, [x0, #JB_X29<<3]
+#endif
 	ldp	 d8,  d9, [x0, #JB_D8<<3]
 	ldp	d10, d11, [x0, #JB_D10<<3]
 	ldp	d12, d13, [x0, #JB_D12<<3]
@@ -87,8 +92,12 @@ ENTRY (__longjmp)
 	cfi_same_value(d13)
 	cfi_same_value(d14)
 	cfi_same_value(d15)
-
-	ldr	x5,  [x0, #JB_SP<<3]
+#ifdef PTR_DEMANGLE
+	ldr	x4, [x0, #JB_SP<<3]
+        PTR_DEMANGLE (x5, x4, x3, x2)
+#else
+	ldr	x5, [x0, #JB_SP<<3]
+#endif
 	mov	sp, x5
 	cmp	x1, #0
 	mov	x0, #1
diff --git a/ports/sysdeps/aarch64/jmpbuf-offsets.h b/ports/sysdeps/aarch64/jmpbuf-offsets.h
index ed5f42a..1392c41 100644
--- a/ports/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/ports/sysdeps/aarch64/jmpbuf-offsets.h
@@ -39,6 +39,22 @@
 #define JB_D14		 20
 #define JB_D15		 21
 
+#ifndef  __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+  uintptr_t sp = jmpbuf[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+#endif
+
 /* Helper for generic ____longjmp_chk(). */
 #define JB_FRAME_ADDRESS(buf) \
-  ((void *) (buf[JB_SP]))
+  ((void *) _jmpbuf_sp (buf))
diff --git a/ports/sysdeps/aarch64/jmpbuf-unwind.h b/ports/sysdeps/aarch64/jmpbuf-unwind.h
index 087e1b6..375decb 100644
--- a/ports/sysdeps/aarch64/jmpbuf-unwind.h
+++ b/ports/sysdeps/aarch64/jmpbuf-unwind.h
@@ -29,16 +29,6 @@
 #define _JMPBUF_CFA_UNWINDS_ADJ(jmpbuf, context, adj) \
   _JMPBUF_UNWINDS_ADJ (jmpbuf, (void *) _Unwind_GetCFA (context), adj)
 
-static inline uintptr_t __attribute__ ((unused))
-_jmpbuf_sp (__jmp_buf jmpbuf)
-{
-  uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
-  PTR_DEMANGLE (sp);
-#endif
-  return sp;
-}
-
 #define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
   ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
 
diff --git a/ports/sysdeps/aarch64/setjmp.S b/ports/sysdeps/aarch64/setjmp.S
index 10e0709..b90a79e 100644
--- a/ports/sysdeps/aarch64/setjmp.S
+++ b/ports/sysdeps/aarch64/setjmp.S
@@ -39,13 +39,27 @@ ENTRY (__sigsetjmp)
 	stp	x23, x24, [x0, #JB_X23<<3]
 	stp	x25, x26, [x0, #JB_X25<<3]
 	stp	x27, x28, [x0, #JB_X27<<3]
+
+#ifdef PTR_MANGLE
+	PTR_MANGLE (x4, x30, x3, x2)
+	str	x29, [x0, #JB_X29<<3]
+	str	x4,  [x0, #JB_LR<<3]
+
+#else
 	stp	x29, x30, [x0, #JB_X29<<3]
+#endif
 	stp	 d8,  d9, [x0, #JB_D8<<3]
 	stp	d10, d11, [x0, #JB_D10<<3]
 	stp	d12, d13, [x0, #JB_D12<<3]
 	stp	d14, d15, [x0, #JB_D14<<3]
+#ifdef PTR_MANGLE
+	mov	x4, sp
+	PTR_MANGLE (x5, x4, x3, x2)
+	str	x5, [x0, #JB_SP<<3]
+#else
 	mov	x2,  sp
 	str	x2,  [x0, #JB_SP<<3]
+#endif
 #if defined NOT_IN_libc && defined IS_IN_rtld
 	/* In ld.so we never save the signal mask */
 	mov	w0, #0
diff --git a/ports/sysdeps/aarch64/sysdep.h b/ports/sysdeps/aarch64/sysdep.h
index 9349471..520d1fc 100644
--- a/ports/sysdeps/aarch64/sysdep.h
+++ b/ports/sysdeps/aarch64/sysdep.h
@@ -78,6 +78,18 @@
 # define L(name)         .L##name
 #endif
 
+/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
+#define LDST_PCREL(OP, R, T, EXPR)\
+	adrp	T, EXPR;	  \
+	add	T, T, #:lo12:EXPR;\
+	OP	R, [T];
+
+/* Load or store to/from a got-relative EXPR into/from R, using T.  */
+#define LDST_GLOBAL(OP, R, T, EXPR)     \
+	adrp	T, :got:EXPR;		\
+	ldr	T, [T, #:got_lo12:EXPR];\
+	OP	R, [T];
+
 /* Since C identifiers are not normally prefixed with an underscore
    on this system, the asm identifier `syscall_error' intrudes on the
    C name space.  Make sure we use an innocuous name.  */
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 9a7b167..a96b69b 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -371,8 +371,45 @@ __local_syscall_error:						\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for AArch64.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
+/* Pointer mangling is support for AArch64.  */
+#if (defined NOT_IN_libc && defined IS_IN_rtld) || \
+  (!defined SHARED && (!defined NOT_IN_libc || defined IS_IN_libpthread))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_PCREL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+
+# else
 
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_GLOBAL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));     \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+#endif
+#endif
 #endif /* linux/aarch64/sysdep.h */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-26 12:25 [PATCH] [AARCH64]: Pointer mangling support for Aarch64 Venkataramanan Kumar
@ 2013-12-26 19:33 ` Richard Henderson
  2013-12-27  7:48   ` Venkataramanan Kumar
  2014-01-06 18:11 ` Tom Tromey
  1 sibling, 1 reply; 20+ messages in thread
From: Richard Henderson @ 2013-12-26 19:33 UTC (permalink / raw)
  To: Venkataramanan Kumar, libc-ports
  Cc: Marcus Shawcroft, Marcus Shawcroft, Carlos O'Donell, Patch Tracking

On 12/26/2013 04:25 AM, Venkataramanan Kumar wrote:
> +#ifdef PTR_DEMANGLE
>  	ldp	x29, x30, [x0, #JB_X29<<3]
> -
> +	PTR_DEMANGLE (x4, x30, x3, x2)
> +	mov	x30, x4	
> +#else

Why not load into x4 and then demangle into x30 directly?  I.e.

	ldp	x29, x4, [x0, #JB_X29<<3]
	PTR_DEMANGLE (x30, x4, x3, x2)


r~

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-26 19:33 ` Richard Henderson
@ 2013-12-27  7:48   ` Venkataramanan Kumar
  2013-12-27 15:09     ` Richard Henderson
  0 siblings, 1 reply; 20+ messages in thread
From: Venkataramanan Kumar @ 2013-12-27  7:48 UTC (permalink / raw)
  To: Richard Henderson
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]

Hi Richard,

On 27 December 2013 01:03, Richard Henderson <rth@twiddle.net> wrote:
> On 12/26/2013 04:25 AM, Venkataramanan Kumar wrote:
>> +#ifdef PTR_DEMANGLE
>>       ldp     x29, x30, [x0, #JB_X29<<3]
>> -
>> +     PTR_DEMANGLE (x4, x30, x3, x2)
>> +     mov     x30, x4
>> +#else
>
> Why not load into x4 and then demangle into x30 directly?  I.e.
>
>         ldp     x29, x4, [x0, #JB_X29<<3]
>         PTR_DEMANGLE (x30, x4, x3, x2)
>
>
> r~

Yes this can be done. Also I changed the mangling code to use store
pair instruction.
Attached is the revised patch. I will do a cross test on V8 foundation
model again.

ChangeLog.aarch64:
-----------------------------
2013-12-26  Venkataramanan Kumar  <venkataramanan.kumar@linaro.org>

* sysdeps/aarch64/__longjmp.S (__longjmp): Demangle sp
        and lr when restoring register values.
* sysdeps/aarch64/setjmp.S (__sigsetjmp): Mangle sp and lr
before storing register values.
* sysdeps/arm/jmpbuf-unwind.h (_jmpbuf_sp): Remove.
* sysdeps/aarch64/jmpbuf-offsets.h (_jmpbuf_sp): Add.
(JB_FRAME_ADDRESS): call  _jmpbuf_sp.
* sysdeps/aarch64/sysdep.h (LDST_PCREL) : New macros.
(LDST_GLOBAL): Likewise.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (PTR_MANGLE): New macro.
(PTR_DEMANGLE): Likewise.
(PTR_MANGLE2): Likewise.
(PTR_DEMANGLE2): Likewise.

regards
Venkat.

[-- Attachment #2: aarch64.glibc.pointer.mangle.txt --]
[-- Type: text/plain, Size: 6017 bytes --]

diff --git a/ports/sysdeps/aarch64/__longjmp.S b/ports/sysdeps/aarch64/__longjmp.S
index ffd30a2..426edc0 100644
--- a/ports/sysdeps/aarch64/__longjmp.S
+++ b/ports/sysdeps/aarch64/__longjmp.S
@@ -50,8 +50,12 @@ ENTRY (__longjmp)
 	ldp	x23, x24, [x0, #JB_X23<<3]
 	ldp	x25, x26, [x0, #JB_X25<<3]
 	ldp	x27, x28, [x0, #JB_X27<<3]
+#ifdef PTR_DEMANGLE
+	ldp	x29,  x4, [x0, #JB_X29<<3]
+	PTR_DEMANGLE (x30, x4, x3, x2)
+#else
 	ldp	x29, x30, [x0, #JB_X29<<3]
-
+#endif
 	ldp	 d8,  d9, [x0, #JB_D8<<3]
 	ldp	d10, d11, [x0, #JB_D10<<3]
 	ldp	d12, d13, [x0, #JB_D12<<3]
@@ -87,8 +91,12 @@ ENTRY (__longjmp)
 	cfi_same_value(d13)
 	cfi_same_value(d14)
 	cfi_same_value(d15)
-
-	ldr	x5,  [x0, #JB_SP<<3]
+#ifdef PTR_DEMANGLE
+	ldr	x4, [x0, #JB_SP<<3]
+	PTR_DEMANGLE (x5, x4, x3, x2)
+#else
+	ldr	x5, [x0, #JB_SP<<3]
+#endif
 	mov	sp, x5
 	cmp	x1, #0
 	mov	x0, #1
diff --git a/ports/sysdeps/aarch64/jmpbuf-offsets.h b/ports/sysdeps/aarch64/jmpbuf-offsets.h
index ed5f42a..1392c41 100644
--- a/ports/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/ports/sysdeps/aarch64/jmpbuf-offsets.h
@@ -39,6 +39,22 @@
 #define JB_D14		 20
 #define JB_D15		 21
 
+#ifndef  __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+  uintptr_t sp = jmpbuf[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+#endif
+
 /* Helper for generic ____longjmp_chk(). */
 #define JB_FRAME_ADDRESS(buf) \
-  ((void *) (buf[JB_SP]))
+  ((void *) _jmpbuf_sp (buf))
diff --git a/ports/sysdeps/aarch64/jmpbuf-unwind.h b/ports/sysdeps/aarch64/jmpbuf-unwind.h
index 087e1b6..375decb 100644
--- a/ports/sysdeps/aarch64/jmpbuf-unwind.h
+++ b/ports/sysdeps/aarch64/jmpbuf-unwind.h
@@ -29,16 +29,6 @@
 #define _JMPBUF_CFA_UNWINDS_ADJ(jmpbuf, context, adj) \
   _JMPBUF_UNWINDS_ADJ (jmpbuf, (void *) _Unwind_GetCFA (context), adj)
 
-static inline uintptr_t __attribute__ ((unused))
-_jmpbuf_sp (__jmp_buf jmpbuf)
-{
-  uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
-  PTR_DEMANGLE (sp);
-#endif
-  return sp;
-}
-
 #define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
   ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
 
diff --git a/ports/sysdeps/aarch64/setjmp.S b/ports/sysdeps/aarch64/setjmp.S
index 10e0709..fb90cf2 100644
--- a/ports/sysdeps/aarch64/setjmp.S
+++ b/ports/sysdeps/aarch64/setjmp.S
@@ -39,13 +39,25 @@ ENTRY (__sigsetjmp)
 	stp	x23, x24, [x0, #JB_X23<<3]
 	stp	x25, x26, [x0, #JB_X25<<3]
 	stp	x27, x28, [x0, #JB_X27<<3]
+
+#ifdef PTR_MANGLE
+	PTR_MANGLE (x4, x30, x3, x2)
+	stp	x29,  x4, [x0, #JB_X29<<3]
+#else
 	stp	x29, x30, [x0, #JB_X29<<3]
+#endif
 	stp	 d8,  d9, [x0, #JB_D8<<3]
 	stp	d10, d11, [x0, #JB_D10<<3]
 	stp	d12, d13, [x0, #JB_D12<<3]
 	stp	d14, d15, [x0, #JB_D14<<3]
+#ifdef PTR_MANGLE
+	mov	x4, sp
+	PTR_MANGLE (x5, x4, x3, x2)
+	str	x5, [x0, #JB_SP<<3]
+#else
 	mov	x2,  sp
 	str	x2,  [x0, #JB_SP<<3]
+#endif
 #if defined NOT_IN_libc && defined IS_IN_rtld
 	/* In ld.so we never save the signal mask */
 	mov	w0, #0
diff --git a/ports/sysdeps/aarch64/sysdep.h b/ports/sysdeps/aarch64/sysdep.h
index 9349471..520d1fc 100644
--- a/ports/sysdeps/aarch64/sysdep.h
+++ b/ports/sysdeps/aarch64/sysdep.h
@@ -78,6 +78,18 @@
 # define L(name)         .L##name
 #endif
 
+/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
+#define LDST_PCREL(OP, R, T, EXPR)\
+	adrp	T, EXPR;	  \
+	add	T, T, #:lo12:EXPR;\
+	OP	R, [T];
+
+/* Load or store to/from a got-relative EXPR into/from R, using T.  */
+#define LDST_GLOBAL(OP, R, T, EXPR)     \
+	adrp	T, :got:EXPR;		\
+	ldr	T, [T, #:got_lo12:EXPR];\
+	OP	R, [T];
+
 /* Since C identifiers are not normally prefixed with an underscore
    on this system, the asm identifier `syscall_error' intrudes on the
    C name space.  Make sure we use an innocuous name.  */
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 9a7b167..a96b69b 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -371,8 +371,45 @@ __local_syscall_error:						\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for AArch64.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
+/* Pointer mangling is support for AArch64.  */
+#if (defined NOT_IN_libc && defined IS_IN_rtld) || \
+  (!defined SHARED && (!defined NOT_IN_libc || defined IS_IN_libpthread))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_PCREL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+
+# else
 
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_GLOBAL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));     \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+#endif
+#endif
 #endif /* linux/aarch64/sysdep.h */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-27  7:48   ` Venkataramanan Kumar
@ 2013-12-27 15:09     ` Richard Henderson
  2013-12-30  5:00       ` Venkataramanan Kumar
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Henderson @ 2013-12-27 15:09 UTC (permalink / raw)
  To: Venkataramanan Kumar
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

On 12/26/2013 11:48 PM, Venkataramanan Kumar wrote:
> +/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
> +#define LDST_PCREL(OP, R, T, EXPR)\
> +	adrp	T, EXPR;	  \
> +	add	T, T, #:lo12:EXPR;\
> +	OP	R, [T];

Is T supposed to be live after the macro?  Otherwise the whole point of the
12-bit offset is that it can be used inside the memory operation offset.

As you in fact do with the LDST_GLOBAL macro just below.


r~

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-27 15:09     ` Richard Henderson
@ 2013-12-30  5:00       ` Venkataramanan Kumar
  2013-12-30 14:45         ` Richard Henderson
  2013-12-30 22:20         ` Marcus Shawcroft
  0 siblings, 2 replies; 20+ messages in thread
From: Venkataramanan Kumar @ 2013-12-30  5:00 UTC (permalink / raw)
  To: Richard Henderson
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

Hi Richard,

Attached is the revised patch with the changes you suggested.
Regressed with glibc tests on ARMV8 Foundation model running open
embedded image.

 ChangeLog.aarch64:
-----------------------------
2013-12-26  Venkataramanan Kumar  <venkataramanan.kumar@linaro.org>

* sysdeps/aarch64/__longjmp.S (__longjmp): Demangle sp
        and lr when restoring register values.
* sysdeps/aarch64/setjmp.S (__sigsetjmp): Mangle sp and lr
before storing register values.
* sysdeps/arm/jmpbuf-unwind.h (_jmpbuf_sp): Remove.
* sysdeps/aarch64/jmpbuf-
offsets.h (_jmpbuf_sp): Add.
(JB_FRAME_ADDRESS): call  _jmpbuf_sp.
* sysdeps/aarch64/sysdep.h (LDST_PCREL) : New macros.
(LDST_GLOBAL): Likewise.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (PTR_MANGLE): New macro.
(PTR_DEMANGLE): Likewise.
(PTR_MANGLE2): Likewise.
(PTR_DEMANGLE2): Likewise.

On 27 December 2013 20:39, Richard Henderson <rth@twiddle.net> wrote:
> On 12/26/2013 11:48 PM, Venkataramanan Kumar wrote:
>> +/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
>> +#define LDST_PCREL(OP, R, T, EXPR)\
>> +     adrp    T, EXPR;          \
>> +     add     T, T, #:lo12:EXPR;\
>> +     OP      R, [T];
>
> Is T supposed to be live after the macro?  Otherwise the whole point of the
> 12-bit offset is that it can be used inside the memory operation offset.
>
> As you in fact do with the LDST_GLOBAL macro just below.
>
>
> r~


regards,
Venkat.

[-- Attachment #2: aarch64.glibc.pointer.mangle.txt --]
[-- Type: text/plain, Size: 6009 bytes --]

diff --git a/ports/sysdeps/aarch64/__longjmp.S b/ports/sysdeps/aarch64/__longjmp.S
index ffd30a2..426edc0 100644
--- a/ports/sysdeps/aarch64/__longjmp.S
+++ b/ports/sysdeps/aarch64/__longjmp.S
@@ -50,8 +50,12 @@ ENTRY (__longjmp)
 	ldp	x23, x24, [x0, #JB_X23<<3]
 	ldp	x25, x26, [x0, #JB_X25<<3]
 	ldp	x27, x28, [x0, #JB_X27<<3]
+#ifdef PTR_DEMANGLE
+	ldp	x29,  x4, [x0, #JB_X29<<3]
+	PTR_DEMANGLE (x30, x4, x3, x2)
+#else
 	ldp	x29, x30, [x0, #JB_X29<<3]
-
+#endif
 	ldp	 d8,  d9, [x0, #JB_D8<<3]
 	ldp	d10, d11, [x0, #JB_D10<<3]
 	ldp	d12, d13, [x0, #JB_D12<<3]
@@ -87,8 +91,12 @@ ENTRY (__longjmp)
 	cfi_same_value(d13)
 	cfi_same_value(d14)
 	cfi_same_value(d15)
-
-	ldr	x5,  [x0, #JB_SP<<3]
+#ifdef PTR_DEMANGLE
+	ldr	x4, [x0, #JB_SP<<3]
+	PTR_DEMANGLE (x5, x4, x3, x2)
+#else
+	ldr	x5, [x0, #JB_SP<<3]
+#endif
 	mov	sp, x5
 	cmp	x1, #0
 	mov	x0, #1
diff --git a/ports/sysdeps/aarch64/jmpbuf-offsets.h b/ports/sysdeps/aarch64/jmpbuf-offsets.h
index ed5f42a..1392c41 100644
--- a/ports/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/ports/sysdeps/aarch64/jmpbuf-offsets.h
@@ -39,6 +39,22 @@
 #define JB_D14		 20
 #define JB_D15		 21
 
+#ifndef  __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+  uintptr_t sp = jmpbuf[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+#endif
+
 /* Helper for generic ____longjmp_chk(). */
 #define JB_FRAME_ADDRESS(buf) \
-  ((void *) (buf[JB_SP]))
+  ((void *) _jmpbuf_sp (buf))
diff --git a/ports/sysdeps/aarch64/jmpbuf-unwind.h b/ports/sysdeps/aarch64/jmpbuf-unwind.h
index 087e1b6..375decb 100644
--- a/ports/sysdeps/aarch64/jmpbuf-unwind.h
+++ b/ports/sysdeps/aarch64/jmpbuf-unwind.h
@@ -29,16 +29,6 @@
 #define _JMPBUF_CFA_UNWINDS_ADJ(jmpbuf, context, adj) \
   _JMPBUF_UNWINDS_ADJ (jmpbuf, (void *) _Unwind_GetCFA (context), adj)
 
-static inline uintptr_t __attribute__ ((unused))
-_jmpbuf_sp (__jmp_buf jmpbuf)
-{
-  uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
-  PTR_DEMANGLE (sp);
-#endif
-  return sp;
-}
-
 #define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
   ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
 
diff --git a/ports/sysdeps/aarch64/setjmp.S b/ports/sysdeps/aarch64/setjmp.S
index 10e0709..fb90cf2 100644
--- a/ports/sysdeps/aarch64/setjmp.S
+++ b/ports/sysdeps/aarch64/setjmp.S
@@ -39,13 +39,25 @@ ENTRY (__sigsetjmp)
 	stp	x23, x24, [x0, #JB_X23<<3]
 	stp	x25, x26, [x0, #JB_X25<<3]
 	stp	x27, x28, [x0, #JB_X27<<3]
+
+#ifdef PTR_MANGLE
+	PTR_MANGLE (x4, x30, x3, x2)
+	stp	x29,  x4, [x0, #JB_X29<<3]
+#else
 	stp	x29, x30, [x0, #JB_X29<<3]
+#endif
 	stp	 d8,  d9, [x0, #JB_D8<<3]
 	stp	d10, d11, [x0, #JB_D10<<3]
 	stp	d12, d13, [x0, #JB_D12<<3]
 	stp	d14, d15, [x0, #JB_D14<<3]
+#ifdef PTR_MANGLE
+	mov	x4, sp
+	PTR_MANGLE (x5, x4, x3, x2)
+	str	x5, [x0, #JB_SP<<3]
+#else
 	mov	x2,  sp
 	str	x2,  [x0, #JB_SP<<3]
+#endif
 #if defined NOT_IN_libc && defined IS_IN_rtld
 	/* In ld.so we never save the signal mask */
 	mov	w0, #0
diff --git a/ports/sysdeps/aarch64/sysdep.h b/ports/sysdeps/aarch64/sysdep.h
index 9349471..5fb7173 100644
--- a/ports/sysdeps/aarch64/sysdep.h
+++ b/ports/sysdeps/aarch64/sysdep.h
@@ -78,6 +78,17 @@
 # define L(name)         .L##name
 #endif
 
+/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
+#define LDST_PCREL(OP, R, T, EXPR)  \
+	adrp	T, EXPR;	    \
+	OP	R, [T, #:lo12:EXPR];\
+
+/* Load or store to/from a got-relative EXPR into/from R, using T.  */
+#define LDST_GLOBAL(OP, R, T, EXPR)     \
+	adrp	T, :got:EXPR;		\
+	ldr	T, [T, #:got_lo12:EXPR];\
+	OP	R, [T];
+
 /* Since C identifiers are not normally prefixed with an underscore
    on this system, the asm identifier `syscall_error' intrudes on the
    C name space.  Make sure we use an innocuous name.  */
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 9a7b167..a96b69b 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -371,8 +371,45 @@ __local_syscall_error:						\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for AArch64.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
+/* Pointer mangling is support for AArch64.  */
+#if (defined NOT_IN_libc && defined IS_IN_rtld) || \
+  (!defined SHARED && (!defined NOT_IN_libc || defined IS_IN_libpthread))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_PCREL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+
+# else
 
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_GLOBAL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));     \
+  PTR_MANGLE2(dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+#endif
+#endif
 #endif /* linux/aarch64/sysdep.h */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-30  5:00       ` Venkataramanan Kumar
@ 2013-12-30 14:45         ` Richard Henderson
  2013-12-30 15:36           ` Venkataramanan Kumar
  2013-12-30 22:20         ` Marcus Shawcroft
  1 sibling, 1 reply; 20+ messages in thread
From: Richard Henderson @ 2013-12-30 14:45 UTC (permalink / raw)
  To: Venkataramanan Kumar
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

Looks fine to me.


r~

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-30 14:45         ` Richard Henderson
@ 2013-12-30 15:36           ` Venkataramanan Kumar
  0 siblings, 0 replies; 20+ messages in thread
From: Venkataramanan Kumar @ 2013-12-30 15:36 UTC (permalink / raw)
  To: Richard Henderson
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

Hi Richard,

Thank you for reviewing the patch .

I don't have write access. So I will wait for someone to commit on my behalf.

regards,
Venkat.





On 30 December 2013 20:14, Richard Henderson <rth@twiddle.net> wrote:
> Looks fine to me.
>
>
> r~

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-30  5:00       ` Venkataramanan Kumar
  2013-12-30 14:45         ` Richard Henderson
@ 2013-12-30 22:20         ` Marcus Shawcroft
  2013-12-31  5:15           ` Venkataramanan Kumar
  1 sibling, 1 reply; 20+ messages in thread
From: Marcus Shawcroft @ 2013-12-30 22:20 UTC (permalink / raw)
  To: Venkataramanan Kumar; +Cc: libc-ports, Patch Tracking

Hi, Couple of nits:

On 30 December 2013 05:00, Venkataramanan Kumar
<venkataramanan.kumar@linaro.org> wrote:

+#  define PTR_MANGLE(dst, src, guard, tmp)                              \
+  LDST_PCREL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2(dst, src, guard)

Space before ( in macro invocations.

+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif

Nested #if should have indentation between # and if.

+/* Pointer mangling is support for AArch64.  */

support -> supported

Otherwise OK
/Marcus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-30 22:20         ` Marcus Shawcroft
@ 2013-12-31  5:15           ` Venkataramanan Kumar
  2014-01-01 17:42             ` Marcus Shawcroft
  0 siblings, 1 reply; 20+ messages in thread
From: Venkataramanan Kumar @ 2013-12-31  5:15 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: libc-ports, Patch Tracking

[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]

Hi Marcus,

Thank you for reviewing the patch.
I have incorporated your review comments.

(Snip)
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
Nested #if should have indentation between # and if.
(Snip)

In ports/sysdeps/aarch64/jmpbuf-offsets.h, should I need to add space
between # and if?
Reading the glibc coding style,  I understood it as outer #ifndef
__ASSEMBLER__ will not increase indentation level.

if it is Ok, can you please commit on my behalf since I don't have write access.

ChangeLog.aarch64:
-----------------------------
2013-12-31  Venkataramanan Kumar  <venkataramanan.kumar@linaro.org>

* sysdeps/aarch64/__longjmp.S (__longjmp): Demangle sp
        and lr when restoring register values.
* sysdeps/aarch64/setjmp.S (__sigsetjmp): Mangle sp and lr
before storing register values.
* sysdeps/arm/jmpbuf-unwind.h (_jmpbuf_sp): Remove.
* sysdeps/aarch64/jmpbuf-offsets.h (_jmpbuf_sp): Add.
(JB_FRAME_ADDRESS): call  _jmpbuf_sp.
* sysdeps/aarch64/sysdep.h (LDST_PCREL) : New macros.
(LDST_GLOBAL): Likewise.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (PTR_MANGLE): New macro.
(PTR_DEMANGLE): Likewise.
(PTR_MANGLE2): Likewise.
(PTR_DEMANGLE2): Likewise.

regards,
Venkat.


On 31 December 2013 03:50, Marcus Shawcroft <marcus.shawcroft@gmail.com> wrote:
> Hi, Couple of nits:
>
> On 30 December 2013 05:00, Venkataramanan Kumar
> <venkataramanan.kumar@linaro.org> wrote:
>
> +#  define PTR_MANGLE(dst, src, guard, tmp)                              \
> +  LDST_PCREL(ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
> +  PTR_MANGLE2(dst, src, guard)
>
> Space before ( in macro invocations.
>
> +#ifdef PTR_DEMANGLE
> +  PTR_DEMANGLE (sp);
> +#endif
>
> Nested #if should have indentation between # and if.
>
> +/* Pointer mangling is support for AArch64.  */
>
> support -> supported
>
> Otherwise OK
> /Marcus

[-- Attachment #2: aarch64.glibc.pointer.mangle.txt --]
[-- Type: text/plain, Size: 6012 bytes --]

diff --git a/ports/sysdeps/aarch64/__longjmp.S b/ports/sysdeps/aarch64/__longjmp.S
index ffd30a2..426edc0 100644
--- a/ports/sysdeps/aarch64/__longjmp.S
+++ b/ports/sysdeps/aarch64/__longjmp.S
@@ -50,8 +50,12 @@ ENTRY (__longjmp)
 	ldp	x23, x24, [x0, #JB_X23<<3]
 	ldp	x25, x26, [x0, #JB_X25<<3]
 	ldp	x27, x28, [x0, #JB_X27<<3]
+#ifdef PTR_DEMANGLE
+	ldp	x29,  x4, [x0, #JB_X29<<3]
+	PTR_DEMANGLE (x30, x4, x3, x2)
+#else
 	ldp	x29, x30, [x0, #JB_X29<<3]
-
+#endif
 	ldp	 d8,  d9, [x0, #JB_D8<<3]
 	ldp	d10, d11, [x0, #JB_D10<<3]
 	ldp	d12, d13, [x0, #JB_D12<<3]
@@ -87,8 +91,12 @@ ENTRY (__longjmp)
 	cfi_same_value(d13)
 	cfi_same_value(d14)
 	cfi_same_value(d15)
-
-	ldr	x5,  [x0, #JB_SP<<3]
+#ifdef PTR_DEMANGLE
+	ldr	x4, [x0, #JB_SP<<3]
+	PTR_DEMANGLE (x5, x4, x3, x2)
+#else
+	ldr	x5, [x0, #JB_SP<<3]
+#endif
 	mov	sp, x5
 	cmp	x1, #0
 	mov	x0, #1
diff --git a/ports/sysdeps/aarch64/jmpbuf-offsets.h b/ports/sysdeps/aarch64/jmpbuf-offsets.h
index ed5f42a..1392c41 100644
--- a/ports/sysdeps/aarch64/jmpbuf-offsets.h
+++ b/ports/sysdeps/aarch64/jmpbuf-offsets.h
@@ -39,6 +39,22 @@
 #define JB_D14		 20
 #define JB_D15		 21
 
+#ifndef  __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+  uintptr_t sp = jmpbuf[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+#endif
+
 /* Helper for generic ____longjmp_chk(). */
 #define JB_FRAME_ADDRESS(buf) \
-  ((void *) (buf[JB_SP]))
+  ((void *) _jmpbuf_sp (buf))
diff --git a/ports/sysdeps/aarch64/jmpbuf-unwind.h b/ports/sysdeps/aarch64/jmpbuf-unwind.h
index 087e1b6..375decb 100644
--- a/ports/sysdeps/aarch64/jmpbuf-unwind.h
+++ b/ports/sysdeps/aarch64/jmpbuf-unwind.h
@@ -29,16 +29,6 @@
 #define _JMPBUF_CFA_UNWINDS_ADJ(jmpbuf, context, adj) \
   _JMPBUF_UNWINDS_ADJ (jmpbuf, (void *) _Unwind_GetCFA (context), adj)
 
-static inline uintptr_t __attribute__ ((unused))
-_jmpbuf_sp (__jmp_buf jmpbuf)
-{
-  uintptr_t sp = jmpbuf[JB_SP];
-#ifdef PTR_DEMANGLE
-  PTR_DEMANGLE (sp);
-#endif
-  return sp;
-}
-
 #define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
   ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
 
diff --git a/ports/sysdeps/aarch64/setjmp.S b/ports/sysdeps/aarch64/setjmp.S
index 10e0709..fb90cf2 100644
--- a/ports/sysdeps/aarch64/setjmp.S
+++ b/ports/sysdeps/aarch64/setjmp.S
@@ -39,13 +39,25 @@ ENTRY (__sigsetjmp)
 	stp	x23, x24, [x0, #JB_X23<<3]
 	stp	x25, x26, [x0, #JB_X25<<3]
 	stp	x27, x28, [x0, #JB_X27<<3]
+
+#ifdef PTR_MANGLE
+	PTR_MANGLE (x4, x30, x3, x2)
+	stp	x29,  x4, [x0, #JB_X29<<3]
+#else
 	stp	x29, x30, [x0, #JB_X29<<3]
+#endif
 	stp	 d8,  d9, [x0, #JB_D8<<3]
 	stp	d10, d11, [x0, #JB_D10<<3]
 	stp	d12, d13, [x0, #JB_D12<<3]
 	stp	d14, d15, [x0, #JB_D14<<3]
+#ifdef PTR_MANGLE
+	mov	x4, sp
+	PTR_MANGLE (x5, x4, x3, x2)
+	str	x5, [x0, #JB_SP<<3]
+#else
 	mov	x2,  sp
 	str	x2,  [x0, #JB_SP<<3]
+#endif
 #if defined NOT_IN_libc && defined IS_IN_rtld
 	/* In ld.so we never save the signal mask */
 	mov	w0, #0
diff --git a/ports/sysdeps/aarch64/sysdep.h b/ports/sysdeps/aarch64/sysdep.h
index 9349471..5fb7173 100644
--- a/ports/sysdeps/aarch64/sysdep.h
+++ b/ports/sysdeps/aarch64/sysdep.h
@@ -78,6 +78,17 @@
 # define L(name)         .L##name
 #endif
 
+/* Load or store to/from a pc-relative EXPR into/from R, using T.  */
+#define LDST_PCREL(OP, R, T, EXPR)  \
+	adrp	T, EXPR;	    \
+	OP	R, [T, #:lo12:EXPR];\
+
+/* Load or store to/from a got-relative EXPR into/from R, using T.  */
+#define LDST_GLOBAL(OP, R, T, EXPR)     \
+	adrp	T, :got:EXPR;		\
+	ldr	T, [T, #:got_lo12:EXPR];\
+	OP	R, [T];
+
 /* Since C identifiers are not normally prefixed with an underscore
    on this system, the asm identifier `syscall_error' intrudes on the
    C name space.  Make sure we use an innocuous name.  */
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 9a7b167..c596055 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -371,8 +371,44 @@ __local_syscall_error:						\
 
 #endif	/* __ASSEMBLER__ */
 
-/* Pointer mangling is not yet supported for AArch64.  */
-#define PTR_MANGLE(var) (void) (var)
-#define PTR_DEMANGLE(var) (void) (var)
+/* Pointer mangling is supported for AArch64.  */
+#if (defined NOT_IN_libc && defined IS_IN_rtld) || \
+  (!defined SHARED && (!defined NOT_IN_libc || defined IS_IN_libpthread))
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                                \
+  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
+  PTR_MANGLE2 (dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#else
+# ifdef __ASSEMBLER__
+#  define PTR_MANGLE(dst, src, guard, tmp)                             \
+  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
+  PTR_MANGLE2 (dst, src, guard)
+/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
+#  define PTR_MANGLE2(dst, src, guard)\
+  eor dst, src, guard
+#  define PTR_DEMANGLE(dst, src, guard, tmp)\
+  PTR_MANGLE (dst, src, guard, tmp)
+#  define PTR_DEMANGLE2(dst, src, guard)\
+  PTR_MANGLE2 (dst, src, guard)
+# else
+extern uintptr_t __pointer_chk_guard attribute_relro;
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
+#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
+# endif
+#endif
 
 #endif /* linux/aarch64/sysdep.h */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-31  5:15           ` Venkataramanan Kumar
@ 2014-01-01 17:42             ` Marcus Shawcroft
  0 siblings, 0 replies; 20+ messages in thread
From: Marcus Shawcroft @ 2014-01-01 17:42 UTC (permalink / raw)
  To: Venkataramanan Kumar; +Cc: libc-ports, Patch Tracking

On 31 December 2013 05:15, Venkataramanan Kumar
<venkataramanan.kumar@linaro.org> wrote:
> Hi Marcus,
>
> Thank you for reviewing the patch.
> I have incorporated your review comments.
>
> (Snip)
> +#ifdef PTR_DEMANGLE
> +  PTR_DEMANGLE (sp);
> +#endif
> Nested #if should have indentation between # and if.
> (Snip)
>
> In ports/sysdeps/aarch64/jmpbuf-offsets.h, should I need to add space
> between # and if?
> Reading the glibc coding style,  I understood it as outer #ifndef
> __ASSEMBLER__ will not increase indentation level.
>
> if it is Ok, can you please commit on my behalf since I don't have write access.

You are right. I'll commit this for you shortly.
/Marcus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2013-12-26 12:25 [PATCH] [AARCH64]: Pointer mangling support for Aarch64 Venkataramanan Kumar
  2013-12-26 19:33 ` Richard Henderson
@ 2014-01-06 18:11 ` Tom Tromey
  2014-01-07 11:05   ` Venkataramanan Kumar
  1 sibling, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2014-01-06 18:11 UTC (permalink / raw)
  To: Venkataramanan Kumar
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

>>>>> ">" == Venkataramanan Kumar <venkataramanan.kumar@linaro.org> writes:

>> This patch adds pointer mangling support for Aarch64.

IIRC the Aarch64 longjmp code doesn't have the sdt.h probes in place.
If you add pointer mangling without also adding the sdt.h probes, then
gdb's longjmp support will break.  You should be able to see this easily
in the gdb test suite.

Adding the probes is quite easy to do, so I encourage you to add that
to the patch.

thanks,
Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-06 18:11 ` Tom Tromey
@ 2014-01-07 11:05   ` Venkataramanan Kumar
  2014-01-07 12:17     ` Marcus Shawcroft
  0 siblings, 1 reply; 20+ messages in thread
From: Venkataramanan Kumar @ 2014-01-07 11:05 UTC (permalink / raw)
  To: Tom Tromey
  Cc: libc-ports, Marcus Shawcroft, Marcus Shawcroft,
	Carlos O'Donell, Patch Tracking

Hi,

The mangling patch is already up streamed. So I will include this
addition as a separate patch.

I looked at x86 and powerpc ports. So for Aarch64
longjmp/longjmp_target probe expects
   *  first argument 8@address of jmpbuf in x0.
   *  second argument -4@return val in x1.
   *  third argument 8@ address of target in LR/X30.

The patch below does that.

(--snip--)
--- a/ports/sysdeps/aarch64/__longjmp.S
+++ b/ports/sysdeps/aarch64/__longjmp.S
@@ -18,6 +18,7 @@

 #include <sysdep.h>
 #include <jmpbuf-offsets.h>
+#include <stap-probe.h>

 /* __longjmp(jmpbuf, val) */

@@ -56,6 +57,7 @@ ENTRY (__longjmp)
 #else
        ldp     x29, x30, [x0, #JB_X29<<3]
 #endif
+       LIBC_PROBE (longjmp, 3, 8@x0, -4@x1, 8@x30)
        ldp      d8,  d9, [x0, #JB_D8<<3]
        ldp     d10, d11, [x0, #JB_D10<<3]
        ldp     d12, d13, [x0, #JB_D12<<3]
@@ -97,6 +99,7 @@ ENTRY (__longjmp)
 #else
        ldr     x5, [x0, #JB_SP<<3]
 #endif
+       LIBC_PROBE (longjmp_target, 3, 8@x0, -4@x1, 8@x30)
        mov     sp, x5
        cmp     x1, #0
        mov     x0, #1
(--snip--)

Please let me know if this is fine,  I will start doing the testing.

regards,
Venkat.

On 6 January 2014 23:40, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> ">" == Venkataramanan Kumar <venkataramanan.kumar@linaro.org> writes:
>
>>> This patch adds pointer mangling support for Aarch64.
>
> IIRC the Aarch64 longjmp code doesn't have the sdt.h probes in place.
> If you add pointer mangling without also adding the sdt.h probes, then
> gdb's longjmp support will break.  You should be able to see this easily
> in the gdb test suite.
>
> Adding the probes is quite easy to do, so I encourage you to add that
> to the patch.
>
> thanks,
> Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-07 11:05   ` Venkataramanan Kumar
@ 2014-01-07 12:17     ` Marcus Shawcroft
  2014-01-07 18:10       ` Tom Tromey
  2014-01-08 10:32       ` Venkataramanan Kumar
  0 siblings, 2 replies; 20+ messages in thread
From: Marcus Shawcroft @ 2014-01-07 12:17 UTC (permalink / raw)
  To: Venkataramanan Kumar; +Cc: libc-ports, Patch Tracking

On 7 January 2014 11:05, Venkataramanan Kumar
<venkataramanan.kumar@linaro.org> wrote:

> I looked at x86 and powerpc ports. So for Aarch64
> longjmp/longjmp_target probe expects
>    *  first argument 8@address of jmpbuf in x0.
>    *  second argument -4@return val in x1.
>    *  third argument 8@ address of target in LR/X30.

Hi, I'm not familiar with the inner workings of STAP probes, can you
explain what the arguments of longjmp_target should be at a semantic
level rather than the proposed location to get the values from?

Do we need probes in setjmp aswell?

Cheers
/Marcus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-07 12:17     ` Marcus Shawcroft
@ 2014-01-07 18:10       ` Tom Tromey
  2014-01-10  9:54         ` Will Newton
  2014-01-20  9:01         ` Will Newton
  2014-01-08 10:32       ` Venkataramanan Kumar
  1 sibling, 2 replies; 20+ messages in thread
From: Tom Tromey @ 2014-01-07 18:10 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: Venkataramanan Kumar, libc-ports, Patch Tracking

>>>>> "Marcus" == Marcus Shawcroft <marcus.shawcroft@gmail.com> writes:

Marcus> Hi, I'm not familiar with the inner workings of STAP probes, can you
Marcus> explain what the arguments of longjmp_target should be at a semantic
Marcus> level rather than the proposed location to get the values from?

I was going to say manual/probes.texi but I see the longjmp probes
aren't documented.

Currently gdb only uses the third argument, which is the target PC.

Marcus> Do we need probes in setjmp aswell?

I think it's nice for users if the probes are the same across ports.

That said, gdb itself only uses the longjmp and rtld probes from glibc.
gdb users (or SystemTap users) can refer to the other probes though.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-07 12:17     ` Marcus Shawcroft
  2014-01-07 18:10       ` Tom Tromey
@ 2014-01-08 10:32       ` Venkataramanan Kumar
  2014-01-10 10:40         ` Marcus Shawcroft
  1 sibling, 1 reply; 20+ messages in thread
From: Venkataramanan Kumar @ 2014-01-08 10:32 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: libc-ports, Patch Tracking

Hi Marcus,

On 7 January 2014 17:47, Marcus Shawcroft <marcus.shawcroft@gmail.com> wrote:
> On 7 January 2014 11:05, Venkataramanan Kumar
> <venkataramanan.kumar@linaro.org> wrote:
>
>> I looked at x86 and powerpc ports. So for Aarch64
>> longjmp/longjmp_target probe expects
>>    *  first argument 8@address of jmpbuf in x0.
>>    *  second argument -4@return val in x1.
>>    *  third argument 8@ address of target in LR/X30.
>
> Hi, I'm not familiar with the inner workings of STAP probes, can you
> explain what the arguments of longjmp_target should be at a semantic
> level rather than the proposed location to get the values from?

I checked below link and found the argument format.
https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation

(Snip)
For compiler-generated code, each argument will be of the form N@OP.
For hand-written assembly, or for inline assembly in C or C++, the
initial N@ may be missing.
If N is present, it describes the size of the argument. It will be one of:

1  8 bits unsigned
-1 8 bits signed
2 16 bits unsigned
-2 16 bits signed
4 32 bits unsigned
-4 32 bits signed
8 64 bits unsigned
-8 64 bits signed
(Snip)

Also looking at x86 and powerpc ports.
They pass argument 1 - the address of jump buffer
                argument 2 - return value of __longjmp
                argument 3 - PC address or the jump target

For Aarch64, the longjmp/longjmp_target probe passed as below.
   *  first argument -  8@address of jmpbuf in x0.
   *  second argument-  -4@return val in x1.
   *  third argument-  8@ PC address or jump target target in LR/X30.

is that fine?

>
> Do we need probes in setjmp aswell?

Ok, I will add that as well.
I have not yet tested, the patch by enabling --enable-systemtap as it
needs std.h. This is missing in my cross build system.

>
> Cheers
> /Marcus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-07 18:10       ` Tom Tromey
@ 2014-01-10  9:54         ` Will Newton
  2014-01-20  9:01         ` Will Newton
  1 sibling, 0 replies; 20+ messages in thread
From: Will Newton @ 2014-01-10  9:54 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Marcus Shawcroft, Venkataramanan Kumar, libc-ports, Patch Tracking

On 7 January 2014 18:10, Tom Tromey <tromey@redhat.com> wrote:

Hi Tom,

> Marcus> Hi, I'm not familiar with the inner workings of STAP probes, can you
> Marcus> explain what the arguments of longjmp_target should be at a semantic
> Marcus> level rather than the proposed location to get the values from?
>
> I was going to say manual/probes.texi but I see the longjmp probes
> aren't documented.
>
> Currently gdb only uses the third argument, which is the target PC.
>
> Marcus> Do we need probes in setjmp aswell?
>
> I think it's nice for users if the probes are the same across ports.
>
> That said, gdb itself only uses the longjmp and rtld probes from glibc.
> gdb users (or SystemTap users) can refer to the other probes though.

Do you know if it is documented anywhere what the difference is
between the longjmp and longjmp_target probes?

It looks like on i386 the registers are restored in between
longjmp/longjmp_target but on powerpc half the registers seem to have
been restored by the time the longjmp probe is executed. AFAICT gdb
does not use the longjmp_target probe either...

Thanks,

-- 
Will Newton
Toolchain Working Group, Linaro

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-08 10:32       ` Venkataramanan Kumar
@ 2014-01-10 10:40         ` Marcus Shawcroft
  0 siblings, 0 replies; 20+ messages in thread
From: Marcus Shawcroft @ 2014-01-10 10:40 UTC (permalink / raw)
  To: Venkataramanan Kumar; +Cc: libc-ports, Patch Tracking

On 8 January 2014 10:32, Venkataramanan Kumar
<venkataramanan.kumar@linaro.org> wrote:

> Also looking at x86 and powerpc ports.
> They pass argument 1 - the address of jump buffer
>                 argument 2 - return value of __longjmp
>                 argument 3 - PC address or the jump target

> For Aarch64, the longjmp/longjmp_target probe passed as below.
>    *  first argument -  8@address of jmpbuf in x0.
>    *  second argument-  -4@return val in x1.
>    *  third argument-  8@ PC address or jump target target in LR/X30.

OK, so the arguments to the LIBC_PROBES in your patch look sensible.

> is that fine?

I'd like to see follow up to Will's question regarding placement of
the two probes.

>
>>
>> Do we need probes in setjmp aswell?
>
> Ok, I will add that as well.
> I have not yet tested, the patch by enabling --enable-systemtap as it

The patch needs to be tested ;-)

Cheers
/Marcus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-07 18:10       ` Tom Tromey
  2014-01-10  9:54         ` Will Newton
@ 2014-01-20  9:01         ` Will Newton
  2014-01-20 16:45           ` Tom Tromey
  1 sibling, 1 reply; 20+ messages in thread
From: Will Newton @ 2014-01-20  9:01 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Marcus Shawcroft, Venkataramanan Kumar, libc-ports, Patch Tracking

On 7 January 2014 18:10, Tom Tromey <tromey@redhat.com> wrote:

Hi Tom,

> Marcus> Hi, I'm not familiar with the inner workings of STAP probes, can you
> Marcus> explain what the arguments of longjmp_target should be at a semantic
> Marcus> level rather than the proposed location to get the values from?
>
> I was going to say manual/probes.texi but I see the longjmp probes
> aren't documented.
>
> Currently gdb only uses the third argument, which is the target PC.
>
> Marcus> Do we need probes in setjmp aswell?
>
> I think it's nice for users if the probes are the same across ports.
>
> That said, gdb itself only uses the longjmp and rtld probes from glibc.
> gdb users (or SystemTap users) can refer to the other probes though.

Can you confirm that gdb does not use the longjmp_target probe? It
doesn't appear to use it as far as I can tell. Are you aware of what
consumers there are for this probe point?

Thanks,

-- 
Will Newton
Toolchain Working Group, Linaro

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-20  9:01         ` Will Newton
@ 2014-01-20 16:45           ` Tom Tromey
  2014-01-20 17:02             ` Will Newton
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2014-01-20 16:45 UTC (permalink / raw)
  To: Will Newton
  Cc: Marcus Shawcroft, Venkataramanan Kumar, libc-ports, Patch Tracking

>>>>> "Will" == Will Newton <will.newton@linaro.org> writes:

Will> Can you confirm that gdb does not use the longjmp_target probe? It
Will> doesn't appear to use it as far as I can tell. Are you aware of what
Will> consumers there are for this probe point?

Yeah, gdb uses the "longjmp" probe, not "longjmp_target".
I don't know what uses the latter; though it's worth noting that all
probes are available to gdb and systemtap users, so I wouldn't
necessarily know whether someone is using it.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] [AARCH64]: Pointer mangling support for Aarch64
  2014-01-20 16:45           ` Tom Tromey
@ 2014-01-20 17:02             ` Will Newton
  0 siblings, 0 replies; 20+ messages in thread
From: Will Newton @ 2014-01-20 17:02 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Marcus Shawcroft, Venkataramanan Kumar, libc-ports, Patch Tracking

On 20 January 2014 16:44, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Will" == Will Newton <will.newton@linaro.org> writes:
>
> Will> Can you confirm that gdb does not use the longjmp_target probe? It
> Will> doesn't appear to use it as far as I can tell. Are you aware of what
> Will> consumers there are for this probe point?
>
> Yeah, gdb uses the "longjmp" probe, not "longjmp_target".
> I don't know what uses the latter; though it's worth noting that all
> probes are available to gdb and systemtap users, so I wouldn't
> necessarily know whether someone is using it.

It's not clear to me the difference between the two - they take the
same arguments as far as I can tell (longjmp arguments 1 and 2, and
the target PC) but longjmp_target occurs at some later point which
seems implementation dependant. For that reason I would propose new
ports (or ports lacking these probes entirely such as ARM) not
implement longjmp_target unless there is a compelling reason to do so.

-- 
Will Newton
Toolchain Working Group, Linaro

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2014-01-20 17:02 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-26 12:25 [PATCH] [AARCH64]: Pointer mangling support for Aarch64 Venkataramanan Kumar
2013-12-26 19:33 ` Richard Henderson
2013-12-27  7:48   ` Venkataramanan Kumar
2013-12-27 15:09     ` Richard Henderson
2013-12-30  5:00       ` Venkataramanan Kumar
2013-12-30 14:45         ` Richard Henderson
2013-12-30 15:36           ` Venkataramanan Kumar
2013-12-30 22:20         ` Marcus Shawcroft
2013-12-31  5:15           ` Venkataramanan Kumar
2014-01-01 17:42             ` Marcus Shawcroft
2014-01-06 18:11 ` Tom Tromey
2014-01-07 11:05   ` Venkataramanan Kumar
2014-01-07 12:17     ` Marcus Shawcroft
2014-01-07 18:10       ` Tom Tromey
2014-01-10  9:54         ` Will Newton
2014-01-20  9:01         ` Will Newton
2014-01-20 16:45           ` Tom Tromey
2014-01-20 17:02             ` Will Newton
2014-01-08 10:32       ` Venkataramanan Kumar
2014-01-10 10:40         ` Marcus Shawcroft

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).