abe59f
commit ce9a68c57c260c8417afc93972849ac9ad243ec4
abe59f
Author: Ben Woodard <woodard@redhat.com>
abe59f
Date:   Mon Jan 24 10:46:18 2022 -0300
abe59f
abe59f
    elf: Fix runtime linker auditing on aarch64 (BZ #26643)
abe59f
    
abe59f
    The rtld audit support show two problems on aarch64:
abe59f
    
abe59f
      1. _dl_runtime_resolve does not preserve x8, the indirect result
abe59f
          location register, which might generate wrong result calls
abe59f
          depending of the function signature.
abe59f
    
abe59f
      2. The NEON Q registers pushed onto the stack by _dl_runtime_resolve
abe59f
         were twice the size of D registers extracted from the stack frame by
abe59f
         _dl_runtime_profile.
abe59f
    
abe59f
    While 2. might result in wrong information passed on the PLT tracing,
abe59f
    1. generates wrong runtime behaviour.
abe59f
    
abe59f
    The aarch64 rtld audit support is changed to:
abe59f
    
abe59f
      * Both La_aarch64_regs and La_aarch64_retval are expanded to include
abe59f
        both x8 and the full sized NEON V registers, as defined by the
abe59f
        ABI.
abe59f
    
abe59f
      * dl_runtime_profile needed to extract registers saved by
abe59f
        _dl_runtime_resolve and put them into the new correctly sized
abe59f
        La_aarch64_regs structure.
abe59f
    
abe59f
      * The LAV_CURRENT check is change to only accept new audit modules
abe59f
        to avoid the undefined behavior of not save/restore x8.
abe59f
    
abe59f
      * Different than other architectures, audit modules older than
abe59f
        LAV_CURRENT are rejected (both La_aarch64_regs and La_aarch64_retval
abe59f
        changed their layout and there are no requirements to support multiple
abe59f
        audit interface with the inherent aarch64 issues).
abe59f
    
abe59f
      * A new field is also reserved on both La_aarch64_regs and
abe59f
        La_aarch64_retval to support variant pcs symbols.
abe59f
    
abe59f
    Similar to x86, a new La_aarch64_vector type to represent the NEON
abe59f
    register is added on the La_aarch64_regs (so each type can be accessed
abe59f
    directly).
abe59f
    
abe59f
    Since LAV_CURRENT was already bumped to support bind-now, there is
abe59f
    no need to increase it again.
abe59f
    
abe59f
    Checked on aarch64-linux-gnu.
abe59f
    
abe59f
    Co-authored-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
abe59f
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
abe59f
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
abe59f
    Tested-by: Carlos O'Donell <carlos@redhat.com>
abe59f
abe59f
Conflicts:
abe59f
	elf/rtld.c
abe59f
	sysdeps/aarch64/Makefile
abe59f
		Rewrite slightly for inclusion in elf/ testing.
abe59f
abe59f
diff --git a/elf/rtld.c b/elf/rtld.c
abe59f
index caa980dbda3d1a72..aee5ca357f66121e 100644
abe59f
--- a/elf/rtld.c
abe59f
+++ b/elf/rtld.c
abe59f
@@ -49,6 +49,7 @@
abe59f
 #include <gnu/lib-names.h>
abe59f
 #include <dl-tunables.h>
abe59f
 #include <dl-execve.h>
abe59f
+#include <dl-audit-check.h>
abe59f
 
abe59f
 #include <assert.h>
abe59f
 
abe59f
@@ -1002,7 +1003,7 @@ file=%s [%lu]; audit interface function la_version returned zero; ignored.\n",
abe59f
       return;
abe59f
     }
abe59f
 
abe59f
-  if (lav > LAV_CURRENT)
abe59f
+  if (!_dl_audit_check_version (lav))
abe59f
     {
abe59f
       _dl_debug_printf ("\
abe59f
 ERROR: audit interface '%s' requires version %d (maximum supported version %d); ignored.\n",
abe59f
diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile
abe59f
index 3ec78fefc6dd5797..794ea7d13ae2737f 100644
abe59f
--- a/sysdeps/aarch64/Makefile
abe59f
+++ b/sysdeps/aarch64/Makefile
abe59f
@@ -4,6 +4,26 @@ ifeq ($(subdir),elf)
abe59f
 sysdep-dl-routines += tlsdesc dl-tlsdesc
abe59f
 gen-as-const-headers += dl-link.sym
abe59f
 
abe59f
+tests += tst-audit26 \
abe59f
+	 tst-audit27
abe59f
+
abe59f
+modules-names += \
abe59f
+    tst-audit26mod \
abe59f
+    tst-auditmod26 \
abe59f
+    tst-audit27mod \
abe59f
+    tst-auditmod27
abe59f
+
abe59f
+$(objpfx)tst-audit26: $(objpfx)tst-audit26mod.so \
abe59f
+		      $(objpfx)tst-auditmod26.so
abe59f
+LDFLAGS-tst-audit26 += -Wl,-z,lazy
abe59f
+tst-audit26-ENV = LD_AUDIT=$(objpfx)tst-auditmod26.so
abe59f
+
abe59f
+$(objpfx)tst-audit27: $(objpfx)tst-audit27mod.so \
abe59f
+		      $(objpfx)tst-auditmod27.so
abe59f
+$(objpfx)tst-audit27mod.so: $(libsupport)
abe59f
+LDFLAGS-tst-audit27 += -Wl,-z,lazy
abe59f
+tst-audit27-ENV = LD_AUDIT=$(objpfx)tst-auditmod27.so
abe59f
+
abe59f
 ifeq (yes,$(aarch64-variant-pcs))
abe59f
 tests += tst-vpcs
abe59f
 modules-names += tst-vpcs-mod
abe59f
diff --git a/sysdeps/aarch64/bits/link.h b/sysdeps/aarch64/bits/link.h
abe59f
index 5a7fc1ccd494b2a7..f4f844bfefdaf2f5 100644
abe59f
--- a/sysdeps/aarch64/bits/link.h
abe59f
+++ b/sysdeps/aarch64/bits/link.h
abe59f
@@ -20,23 +20,31 @@
abe59f
 # error "Never include <bits/link.h> directly; use <link.h> instead."
abe59f
 #endif
abe59f
 
abe59f
+typedef union
abe59f
+{
abe59f
+  float s;
abe59f
+  double d;
abe59f
+  long double q;
abe59f
+} La_aarch64_vector;
abe59f
+
abe59f
 /* Registers for entry into PLT on AArch64.  */
abe59f
 typedef struct La_aarch64_regs
abe59f
 {
abe59f
-  uint64_t lr_xreg[8];
abe59f
-  uint64_t lr_dreg[8];
abe59f
-  uint64_t lr_sp;
abe59f
-  uint64_t lr_lr;
abe59f
+  uint64_t          lr_xreg[9];
abe59f
+  La_aarch64_vector lr_vreg[8];
abe59f
+  uint64_t          lr_sp;
abe59f
+  uint64_t          lr_lr;
abe59f
+  void              *lr_vpcs;
abe59f
 } La_aarch64_regs;
abe59f
 
abe59f
 /* Return values for calls from PLT on AArch64.  */
abe59f
 typedef struct La_aarch64_retval
abe59f
 {
abe59f
-  /* Up to two integer registers can be used for a return value.  */
abe59f
-  uint64_t lrv_xreg[2];
abe59f
-  /* Up to four D registers can be used for a return value.  */
abe59f
-  uint64_t lrv_dreg[4];
abe59f
-
abe59f
+  /* Up to eight integer registers can be used for a return value.  */
abe59f
+  uint64_t          lrv_xreg[8];
abe59f
+  /* Up to eight V registers can be used for a return value.  */
abe59f
+  La_aarch64_vector lrv_vreg[8];
abe59f
+  void              *lrv_vpcs;
abe59f
 } La_aarch64_retval;
abe59f
 __BEGIN_DECLS
abe59f
 
abe59f
diff --git a/sysdeps/aarch64/dl-audit-check.h b/sysdeps/aarch64/dl-audit-check.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..e324339a1d4abec3
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/dl-audit-check.h
abe59f
@@ -0,0 +1,28 @@
abe59f
+/* rtld-audit version check.  AArch64 version.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+static inline bool
abe59f
+_dl_audit_check_version (unsigned int lav)
abe59f
+{
abe59f
+  /* Audit version 1 do not save x8 or NEON registers, which required
abe59f
+     changing La_aarch64_regs and La_aarch64_retval layout (BZ#26643).  The
abe59f
+     missing indirect result save/restore makes _dl_runtime_profile
abe59f
+     potentially trigger undefined behavior if the function returns a large
abe59f
+     struct (even when PLT trace is not requested).  */
abe59f
+  return lav == LAV_CURRENT;
abe59f
+}
abe59f
diff --git a/sysdeps/aarch64/dl-link.sym b/sysdeps/aarch64/dl-link.sym
abe59f
index d67d28b40ce7d4ff..cb4dcdcbed0db492 100644
abe59f
--- a/sysdeps/aarch64/dl-link.sym
abe59f
+++ b/sysdeps/aarch64/dl-link.sym
abe59f
@@ -7,9 +7,11 @@ DL_SIZEOF_RG		sizeof(struct La_aarch64_regs)
abe59f
 DL_SIZEOF_RV		sizeof(struct La_aarch64_retval)
abe59f
 
abe59f
 DL_OFFSET_RG_X0		offsetof(struct La_aarch64_regs, lr_xreg)
abe59f
-DL_OFFSET_RG_D0		offsetof(struct La_aarch64_regs, lr_dreg)
abe59f
+DL_OFFSET_RG_V0		offsetof(struct La_aarch64_regs, lr_vreg)
abe59f
 DL_OFFSET_RG_SP		offsetof(struct La_aarch64_regs, lr_sp)
abe59f
 DL_OFFSET_RG_LR		offsetof(struct La_aarch64_regs, lr_lr)
abe59f
+DL_OFFSET_RG_VPCS       offsetof(struct La_aarch64_regs, lr_vpcs)
abe59f
 
abe59f
 DL_OFFSET_RV_X0		offsetof(struct La_aarch64_retval, lrv_xreg)
abe59f
-DL_OFFSET_RV_D0		offsetof(struct La_aarch64_retval, lrv_dreg)
abe59f
+DL_OFFSET_RV_V0		offsetof(struct La_aarch64_retval, lrv_vreg)
abe59f
+DL_OFFSET_RV_VPCS       offsetof(struct La_aarch64_retval, lrv_vpcs)
abe59f
diff --git a/sysdeps/aarch64/dl-trampoline.S b/sysdeps/aarch64/dl-trampoline.S
abe59f
index 18740398e63fdf97..a83e7fc5f97047e2 100644
abe59f
--- a/sysdeps/aarch64/dl-trampoline.S
abe59f
+++ b/sysdeps/aarch64/dl-trampoline.S
abe59f
@@ -44,7 +44,8 @@ _dl_runtime_resolve:
abe59f
 
abe59f
 	cfi_rel_offset (lr, 8)
abe59f
 
abe59f
-	/* Save arguments.  */
abe59f
+	/* Note: Saving x9 is not required by the ABI but the assembler requires
abe59f
+	   the immediate values of operand 3 to be a multiple of 16 */
abe59f
 	stp	x8, x9, [sp, #-(80+8*16)]!
abe59f
 	cfi_adjust_cfa_offset (80+8*16)
abe59f
 	cfi_rel_offset (x8, 0)
abe59f
@@ -135,7 +136,7 @@ _dl_runtime_profile:
abe59f
 	   Stack frame layout:
abe59f
 	   [sp,   #...] lr
abe59f
 	   [sp,   #...] &PLTGOT[n]
abe59f
-	   [sp,    #96] La_aarch64_regs
abe59f
+	   [sp,   #256] La_aarch64_regs
abe59f
 	   [sp,    #48] La_aarch64_retval
abe59f
 	   [sp,    #40] frame size return from pltenter
abe59f
 	   [sp,    #32] dl_profile_call saved x1
abe59f
@@ -176,19 +177,25 @@ _dl_runtime_profile:
abe59f
 	stp	x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
abe59f
 	cfi_rel_offset (x6, OFFSET_RG + DL_OFFSET_RG_X0 + 16*3 + 0)
abe59f
 	cfi_rel_offset (x7, OFFSET_RG + DL_OFFSET_RG_X0 + 16*3 + 8)
abe59f
-
abe59f
-	stp	d0, d1, [X29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*0]
abe59f
-	cfi_rel_offset (d0, OFFSET_RG + DL_OFFSET_RG_D0 + 16*0)
abe59f
-	cfi_rel_offset (d1, OFFSET_RG + DL_OFFSET_RG_D0 + 16*0 + 8)
abe59f
-	stp	d2, d3, [X29, #OFFSET_RG+ DL_OFFSET_RG_D0 + 16*1]
abe59f
-	cfi_rel_offset (d2, OFFSET_RG + DL_OFFSET_RG_D0 + 16*1 + 0)
abe59f
-	cfi_rel_offset (d3, OFFSET_RG + DL_OFFSET_RG_D0 + 16*1 + 8)
abe59f
-	stp	d4, d5, [X29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*2]
abe59f
-	cfi_rel_offset (d4, OFFSET_RG + DL_OFFSET_RG_D0 + 16*2 + 0)
abe59f
-	cfi_rel_offset (d5, OFFSET_RG + DL_OFFSET_RG_D0 + 16*2 + 8)
abe59f
-	stp	d6, d7, [X29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*3]
abe59f
-	cfi_rel_offset (d6, OFFSET_RG + DL_OFFSET_RG_D0 + 16*3 + 0)
abe59f
-	cfi_rel_offset (d7, OFFSET_RG + DL_OFFSET_RG_D0 + 16*3 + 8)
abe59f
+	str	x8, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4 + 0]
abe59f
+	cfi_rel_offset (x8, OFFSET_RG + DL_OFFSET_RG_X0 + 16*4 + 0)
abe59f
+	/* Note 8 bytes of padding is in the stack frame for alignment */
abe59f
+
abe59f
+	stp	q0, q1, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
abe59f
+	cfi_rel_offset (q0, OFFSET_RG + DL_OFFSET_RG_V0 + 32*0)
abe59f
+	cfi_rel_offset (q1, OFFSET_RG + DL_OFFSET_RG_V0 + 32*0 + 16)
abe59f
+	stp	q2, q3, [X29, #OFFSET_RG+ DL_OFFSET_RG_V0 + 32*1]
abe59f
+	cfi_rel_offset (q2, OFFSET_RG + DL_OFFSET_RG_V0 + 32*1 + 0)
abe59f
+	cfi_rel_offset (q3, OFFSET_RG + DL_OFFSET_RG_V0 + 32*1 + 16)
abe59f
+	stp	q4, q5, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
abe59f
+	cfi_rel_offset (q4, OFFSET_RG + DL_OFFSET_RG_V0 + 32*2 + 0)
abe59f
+	cfi_rel_offset (q5, OFFSET_RG + DL_OFFSET_RG_V0 + 32*2 + 16)
abe59f
+	stp	q6, q7, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
abe59f
+	cfi_rel_offset (q6, OFFSET_RG + DL_OFFSET_RG_V0 + 32*3 + 0)
abe59f
+	cfi_rel_offset (q7, OFFSET_RG + DL_OFFSET_RG_V0 + 32*3 + 16)
abe59f
+
abe59f
+	/* No APCS extension supported.  */
abe59f
+	str	xzr,    [X29, #OFFSET_RG + DL_OFFSET_RG_VPCS]
abe59f
 
abe59f
 	add     x0, x29, #SF_SIZE + 16
abe59f
 	ldr	x1, [x29, #OFFSET_LR]
abe59f
@@ -227,10 +234,11 @@ _dl_runtime_profile:
abe59f
 	ldp	x2, x3, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*1]
abe59f
 	ldp	x4, x5, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*2]
abe59f
 	ldp	x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
abe59f
-	ldp	d0, d1, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*0]
abe59f
-	ldp	d2, d3, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*1]
abe59f
-	ldp	d4, d5, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*2]
abe59f
-	ldp	d6, d7, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*3]
abe59f
+	ldr	x8,     [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4]
abe59f
+	ldp	q0, q1, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
abe59f
+	ldp	q2, q3, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*1]
abe59f
+	ldp	q4, q5, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
abe59f
+	ldp	q6, q7, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
abe59f
 
abe59f
 	cfi_def_cfa_register (sp)
abe59f
 	ldp	x29, x30, [x29, #0]
abe59f
@@ -264,14 +272,22 @@ _dl_runtime_profile:
abe59f
 	ldp	x2, x3, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*1]
abe59f
 	ldp	x4, x5, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*2]
abe59f
 	ldp	x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
abe59f
-	ldp	d0, d1, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*0]
abe59f
-	ldp	d2, d3, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*1]
abe59f
-	ldp	d4, d5, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*2]
abe59f
-	ldp	d6, d7, [x29, #OFFSET_RG + DL_OFFSET_RG_D0 + 16*3]
abe59f
+	ldr	x8,     [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4]
abe59f
+	ldp	q0, q1, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
abe59f
+	ldp	q2, q3, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*1]
abe59f
+	ldp	q4, q5, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
abe59f
+	ldp	q6, q7, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
abe59f
 	blr	ip0
abe59f
-	stp	x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0]
abe59f
-	stp	d0, d1, [x29, #OFFSET_RV + DL_OFFSET_RV_D0 + 16*0]
abe59f
-	stp	d2, d3, [x29, #OFFSET_RV + DL_OFFSET_RV_D0 + 16*1]
abe59f
+	stp	x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*0]
abe59f
+	stp	x2, x3, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*1]
abe59f
+	stp	x4, x5, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*2]
abe59f
+	stp	x6, x7, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*3]
abe59f
+	str	x8,     [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4]
abe59f
+	stp	q0, q1, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*0]
abe59f
+	stp	q2, q3, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*1]
abe59f
+	stp	q4, q5, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*2]
abe59f
+	stp	q6, q7, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*3]
abe59f
+	str	xzr,    [X29, #OFFSET_RV + DL_OFFSET_RG_VPCS]
abe59f
 
abe59f
 	/* Setup call to pltexit  */
abe59f
 	ldp	x0, x1, [x29, #OFFSET_SAVED_CALL_X0]
abe59f
@@ -279,9 +295,16 @@ _dl_runtime_profile:
abe59f
 	add	x3, x29, #OFFSET_RV
abe59f
 	bl	_dl_audit_pltexit
abe59f
 
abe59f
-	ldp	x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0]
abe59f
-	ldp	d0, d1, [x29, #OFFSET_RV + DL_OFFSET_RV_D0 + 16*0]
abe59f
-	ldp	d2, d3, [x29, #OFFSET_RV + DL_OFFSET_RV_D0 + 16*1]
abe59f
+	ldp	x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*0]
abe59f
+	ldp	x2, x3, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*1]
abe59f
+	ldp	x4, x5, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*2]
abe59f
+	ldp	x6, x7, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*3]
abe59f
+	ldr	x8,     [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*4]
abe59f
+	ldp	q0, q1, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*0]
abe59f
+	ldp	q2, q3, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*1]
abe59f
+	ldp	q4, q5, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*2]
abe59f
+	ldp	q6, q7, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*3]
abe59f
+
abe59f
 	/* LR from within La_aarch64_reg */
abe59f
 	ldr	lr, [x29, #OFFSET_RG + DL_OFFSET_RG_LR]
abe59f
 	cfi_restore(lr)
abe59f
diff --git a/sysdeps/aarch64/tst-audit26.c b/sysdeps/aarch64/tst-audit26.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..46de8acd219cb8bc
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit26.c
abe59f
@@ -0,0 +1,37 @@
abe59f
+/* Check LD_AUDIT for aarch64 ABI specifics.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <array_length.h>
abe59f
+#include <string.h>
abe59f
+#include <support/check.h>
abe59f
+#include "tst-audit26mod.h"
abe59f
+
abe59f
+int
abe59f
+do_test (void)
abe59f
+{
abe59f
+  /* Returning a large struct uses 'x8' as indirect result location.  */
abe59f
+  struct large_struct r = tst_audit26_func (ARG1, ARG2, ARG3);
abe59f
+
abe59f
+  struct large_struct e = set_large_struct (ARG1, ARG2, ARG3);
abe59f
+
abe59f
+  TEST_COMPARE_BLOB (r.a, sizeof (r.a), e.a, sizeof (e.a));
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/sysdeps/aarch64/tst-audit26mod.c b/sysdeps/aarch64/tst-audit26mod.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..67d5ffce7288b34c
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit26mod.c
abe59f
@@ -0,0 +1,33 @@
abe59f
+/* Check LD_AUDIT for aarch64 ABI specifics.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <stdlib.h>
abe59f
+#include "tst-audit26mod.h"
abe59f
+
abe59f
+struct large_struct
abe59f
+tst_audit26_func (char a, short b, long int c)
abe59f
+{
abe59f
+  if (a != ARG1)
abe59f
+    abort ();
abe59f
+  if (b != ARG2)
abe59f
+    abort ();
abe59f
+  if (c != ARG3)
abe59f
+    abort ();
abe59f
+
abe59f
+  return set_large_struct (a, b, c);
abe59f
+}
abe59f
diff --git a/sysdeps/aarch64/tst-audit26mod.h b/sysdeps/aarch64/tst-audit26mod.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..f80409f96bae6c82
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit26mod.h
abe59f
@@ -0,0 +1,50 @@
abe59f
+/* Check LD_AUDIT for aarch64 specific ABI.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#ifndef _TST_AUDIT27MOD_H
abe59f
+#define _TST_AUDIT27MOD_H 1
abe59f
+
abe59f
+#include <array_length.h>
abe59f
+
abe59f
+struct large_struct
abe59f
+{
abe59f
+  char a[16];
abe59f
+  short b[8];
abe59f
+  long int c[4];
abe59f
+};
abe59f
+
abe59f
+static inline struct large_struct
abe59f
+set_large_struct (char a, short b, long int c)
abe59f
+{
abe59f
+  struct large_struct r;
abe59f
+  for (int i = 0; i < array_length (r.a); i++)
abe59f
+    r.a[i] = a;
abe59f
+  for (int i = 0; i < array_length (r.b); i++)
abe59f
+    r.b[i] = b;
abe59f
+  for (int i = 0; i < array_length (r.c); i++)
abe59f
+    r.c[i] = c;
abe59f
+  return r;
abe59f
+}
abe59f
+
abe59f
+#define ARG1 0x12
abe59f
+#define ARG2 0x1234
abe59f
+#define ARG3 0x12345678
abe59f
+
abe59f
+struct large_struct tst_audit26_func (char a, short b, long int c);
abe59f
+
abe59f
+#endif
abe59f
diff --git a/sysdeps/aarch64/tst-audit27.c b/sysdeps/aarch64/tst-audit27.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..5ebc09771f845af0
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit27.c
abe59f
@@ -0,0 +1,64 @@
abe59f
+/* Check LD_AUDIT for aarch64 ABI specifics.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <array_length.h>
abe59f
+#include <string.h>
abe59f
+#include <support/check.h>
abe59f
+#include "tst-audit27mod.h"
abe59f
+
abe59f
+int
abe59f
+do_test (void)
abe59f
+{
abe59f
+  {
abe59f
+    float r = tst_audit27_func_float (FUNC_FLOAT_ARG0, FUNC_FLOAT_ARG1,
abe59f
+				      FUNC_FLOAT_ARG2, FUNC_FLOAT_ARG3,
abe59f
+				      FUNC_FLOAT_ARG4, FUNC_FLOAT_ARG5,
abe59f
+				      FUNC_FLOAT_ARG6, FUNC_FLOAT_ARG7);
abe59f
+    if (r != FUNC_FLOAT_RET)
abe59f
+      FAIL_EXIT1 ("tst_audit27_func_float() returned %a, expected %a",
abe59f
+		  r, FUNC_FLOAT_RET);
abe59f
+  }
abe59f
+
abe59f
+  {
abe59f
+    double r = tst_audit27_func_double (FUNC_DOUBLE_ARG0, FUNC_DOUBLE_ARG1,
abe59f
+					FUNC_DOUBLE_ARG2, FUNC_DOUBLE_ARG3,
abe59f
+					FUNC_DOUBLE_ARG4, FUNC_DOUBLE_ARG5,
abe59f
+					FUNC_DOUBLE_ARG6, FUNC_DOUBLE_ARG7);
abe59f
+    if (r != FUNC_DOUBLE_RET)
abe59f
+      FAIL_EXIT1 ("tst_audit27_func_double() returned %la, expected %la",
abe59f
+		  r, FUNC_DOUBLE_RET);
abe59f
+  }
abe59f
+
abe59f
+  {
abe59f
+    long double r = tst_audit27_func_ldouble (FUNC_LDOUBLE_ARG0,
abe59f
+					      FUNC_LDOUBLE_ARG1,
abe59f
+					      FUNC_LDOUBLE_ARG2,
abe59f
+					      FUNC_LDOUBLE_ARG3,
abe59f
+					      FUNC_LDOUBLE_ARG4,
abe59f
+					      FUNC_LDOUBLE_ARG5,
abe59f
+					      FUNC_LDOUBLE_ARG6,
abe59f
+					      FUNC_LDOUBLE_ARG7);
abe59f
+    if (r != FUNC_LDOUBLE_RET)
abe59f
+      FAIL_EXIT1 ("tst_audit27_func_ldouble() returned %La, expected %La",
abe59f
+		  r, FUNC_LDOUBLE_RET);
abe59f
+  }
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
+
abe59f
+#include <support/test-driver.c>
abe59f
diff --git a/sysdeps/aarch64/tst-audit27mod.c b/sysdeps/aarch64/tst-audit27mod.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..922b518f0af4b97b
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit27mod.c
abe59f
@@ -0,0 +1,95 @@
abe59f
+/* Check LD_AUDIT for aarch64 ABI specifics.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <array_length.h>
abe59f
+#include <stdlib.h>
abe59f
+#include <support/check.h>
abe59f
+#include "tst-audit27mod.h"
abe59f
+
abe59f
+float
abe59f
+tst_audit27_func_float (float a0, float a1, float a2, float a3, float a4,
abe59f
+			float a5, float a6, float a7)
abe59f
+{
abe59f
+  if (a0 != FUNC_FLOAT_ARG0)
abe59f
+    FAIL_EXIT1 ("a0: %a != %a", a0, FUNC_FLOAT_ARG0);
abe59f
+  if (a1 != FUNC_FLOAT_ARG1)
abe59f
+    FAIL_EXIT1 ("a1: %a != %a", a1, FUNC_FLOAT_ARG1);
abe59f
+  if (a2 != FUNC_FLOAT_ARG2)
abe59f
+    FAIL_EXIT1 ("a2: %a != %a", a2, FUNC_FLOAT_ARG2);
abe59f
+  if (a3 != FUNC_FLOAT_ARG3)
abe59f
+    FAIL_EXIT1 ("a3: %a != %a", a3, FUNC_FLOAT_ARG3);
abe59f
+  if (a4 != FUNC_FLOAT_ARG4)
abe59f
+    FAIL_EXIT1 ("a4: %a != %a", a4, FUNC_FLOAT_ARG4);
abe59f
+  if (a5 != FUNC_FLOAT_ARG5)
abe59f
+    FAIL_EXIT1 ("a5: %a != %a", a5, FUNC_FLOAT_ARG5);
abe59f
+  if (a6 != FUNC_FLOAT_ARG6)
abe59f
+    FAIL_EXIT1 ("a6: %a != %a", a6, FUNC_FLOAT_ARG6);
abe59f
+  if (a7 != FUNC_FLOAT_ARG7)
abe59f
+    FAIL_EXIT1 ("a7: %a != %a", a7, FUNC_FLOAT_ARG7);
abe59f
+
abe59f
+  return FUNC_FLOAT_RET;
abe59f
+}
abe59f
+
abe59f
+double
abe59f
+tst_audit27_func_double (double a0, double a1, double a2, double a3, double a4,
abe59f
+			 double a5, double a6, double a7)
abe59f
+{
abe59f
+  if (a0 != FUNC_DOUBLE_ARG0)
abe59f
+    FAIL_EXIT1 ("a0: %la != %la", a0, FUNC_DOUBLE_ARG0);
abe59f
+  if (a1 != FUNC_DOUBLE_ARG1)
abe59f
+    FAIL_EXIT1 ("a1: %la != %la", a1, FUNC_DOUBLE_ARG1);
abe59f
+  if (a2 != FUNC_DOUBLE_ARG2)
abe59f
+    FAIL_EXIT1 ("a2: %la != %la", a2, FUNC_DOUBLE_ARG2);
abe59f
+  if (a3 != FUNC_DOUBLE_ARG3)
abe59f
+    FAIL_EXIT1 ("a3: %la != %la", a3, FUNC_DOUBLE_ARG3);
abe59f
+  if (a4 != FUNC_DOUBLE_ARG4)
abe59f
+    FAIL_EXIT1 ("a4: %la != %la", a4, FUNC_DOUBLE_ARG4);
abe59f
+  if (a5 != FUNC_DOUBLE_ARG5)
abe59f
+    FAIL_EXIT1 ("a5: %la != %la", a5, FUNC_DOUBLE_ARG5);
abe59f
+  if (a6 != FUNC_DOUBLE_ARG6)
abe59f
+    FAIL_EXIT1 ("a6: %la != %la", a6, FUNC_DOUBLE_ARG6);
abe59f
+  if (a7 != FUNC_DOUBLE_ARG7)
abe59f
+    FAIL_EXIT1 ("a7: %la != %la", a7, FUNC_DOUBLE_ARG7);
abe59f
+
abe59f
+  return FUNC_DOUBLE_RET;
abe59f
+}
abe59f
+
abe59f
+long double
abe59f
+tst_audit27_func_ldouble (long double a0, long double a1, long double a2,
abe59f
+			  long double a3, long double a4, long double a5,
abe59f
+			  long double a6, long double a7)
abe59f
+{
abe59f
+  if (a0 != FUNC_LDOUBLE_ARG0)
abe59f
+    FAIL_EXIT1 ("a0: %La != %La", a0, FUNC_LDOUBLE_ARG0);
abe59f
+  if (a1 != FUNC_LDOUBLE_ARG1)
abe59f
+    FAIL_EXIT1 ("a1: %La != %La", a1, FUNC_LDOUBLE_ARG1);
abe59f
+  if (a2 != FUNC_LDOUBLE_ARG2)
abe59f
+    FAIL_EXIT1 ("a2: %La != %La", a2, FUNC_LDOUBLE_ARG2);
abe59f
+  if (a3 != FUNC_LDOUBLE_ARG3)
abe59f
+    FAIL_EXIT1 ("a3: %La != %La", a3, FUNC_LDOUBLE_ARG3);
abe59f
+  if (a4 != FUNC_LDOUBLE_ARG4)
abe59f
+    FAIL_EXIT1 ("a4: %La != %La", a4, FUNC_LDOUBLE_ARG4);
abe59f
+  if (a5 != FUNC_LDOUBLE_ARG5)
abe59f
+    FAIL_EXIT1 ("a5: %La != %La", a5, FUNC_LDOUBLE_ARG5);
abe59f
+  if (a6 != FUNC_LDOUBLE_ARG6)
abe59f
+    FAIL_EXIT1 ("a6: %La != %La", a6, FUNC_LDOUBLE_ARG6);
abe59f
+  if (a7 != FUNC_LDOUBLE_ARG7)
abe59f
+    FAIL_EXIT1 ("a7: %La != %La", a7, FUNC_LDOUBLE_ARG7);
abe59f
+
abe59f
+  return FUNC_LDOUBLE_RET;
abe59f
+}
abe59f
diff --git a/sysdeps/aarch64/tst-audit27mod.h b/sysdeps/aarch64/tst-audit27mod.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..1709d222ca251e3b
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-audit27mod.h
abe59f
@@ -0,0 +1,67 @@
abe59f
+/* Check LD_AUDIT for aarch64 specific ABI.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#ifndef _TST_AUDIT27MOD_H
abe59f
+#define _TST_AUDIT27MOD_H 1
abe59f
+
abe59f
+#include <float.h>
abe59f
+
abe59f
+#define FUNC_FLOAT_ARG0 FLT_MIN
abe59f
+#define FUNC_FLOAT_ARG1 FLT_MAX
abe59f
+#define FUNC_FLOAT_ARG2 FLT_EPSILON
abe59f
+#define FUNC_FLOAT_ARG3 FLT_TRUE_MIN
abe59f
+#define FUNC_FLOAT_ARG4 0.0f
abe59f
+#define FUNC_FLOAT_ARG5 1.0f
abe59f
+#define FUNC_FLOAT_ARG6 2.0f
abe59f
+#define FUNC_FLOAT_ARG7 3.0f
abe59f
+#define FUNC_FLOAT_RET  4.0f
abe59f
+
abe59f
+float
abe59f
+tst_audit27_func_float (float a0, float a1, float a2, float a3, float a4,
abe59f
+			float a5, float a6, float a7);
abe59f
+
abe59f
+#define FUNC_DOUBLE_ARG0 DBL_MIN
abe59f
+#define FUNC_DOUBLE_ARG1 DBL_MAX
abe59f
+#define FUNC_DOUBLE_ARG2 DBL_EPSILON
abe59f
+#define FUNC_DOUBLE_ARG3 DBL_TRUE_MIN
abe59f
+#define FUNC_DOUBLE_ARG4 0.0
abe59f
+#define FUNC_DOUBLE_ARG5 1.0
abe59f
+#define FUNC_DOUBLE_ARG6 2.0
abe59f
+#define FUNC_DOUBLE_ARG7 3.0
abe59f
+#define FUNC_DOUBLE_RET  0x1.fffffe0000001p+127
abe59f
+
abe59f
+double
abe59f
+tst_audit27_func_double (double a0, double a1, double a2, double a3, double a4,
abe59f
+			 double a5, double a6, double a7);
abe59f
+
abe59f
+#define FUNC_LDOUBLE_ARG0 DBL_MAX + 1.0L
abe59f
+#define FUNC_LDOUBLE_ARG1 DBL_MAX + 2.0L
abe59f
+#define FUNC_LDOUBLE_ARG2 DBL_MAX + 3.0L
abe59f
+#define FUNC_LDOUBLE_ARG3 DBL_MAX + 4.0L
abe59f
+#define FUNC_LDOUBLE_ARG4 DBL_MAX + 5.0L
abe59f
+#define FUNC_LDOUBLE_ARG5 DBL_MAX + 6.0L
abe59f
+#define FUNC_LDOUBLE_ARG6 DBL_MAX + 7.0L
abe59f
+#define FUNC_LDOUBLE_ARG7 DBL_MAX + 8.0L
abe59f
+#define FUNC_LDOUBLE_RET  0x1.fffffffffffff000000000000001p+1023L
abe59f
+
abe59f
+long double
abe59f
+tst_audit27_func_ldouble (long double a0, long double a1, long double a2,
abe59f
+			  long double a3, long double a4, long double a5,
abe59f
+			  long double a6, long double a7);
abe59f
+
abe59f
+#endif
abe59f
diff --git a/sysdeps/aarch64/tst-auditmod26.c b/sysdeps/aarch64/tst-auditmod26.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..b03b6baed9aeb528
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-auditmod26.c
abe59f
@@ -0,0 +1,103 @@
abe59f
+/* Check LD_AUDIT for aarch64 specific ABI.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <assert.h>
abe59f
+#include <link.h>
abe59f
+#include <string.h>
abe59f
+#include <stdio.h>
abe59f
+#include <stdlib.h>
abe59f
+#include "tst-audit26mod.h"
abe59f
+
abe59f
+#define TEST_NAME  "tst-audit26"
abe59f
+
abe59f
+#define AUDIT26_COOKIE 0
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int v)
abe59f
+{
abe59f
+  return v;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? map->l_name : p + 1;
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strncmp (l_name, TEST_NAME, strlen (TEST_NAME)) == 0)
abe59f
+    ck = AUDIT26_COOKIE;
abe59f
+  *cookie = ck;
abe59f
+  printf ("objopen: %ld, %s [cookie=%ld]\n", lmid, l_name, ck);
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+ElfW(Addr)
abe59f
+la_aarch64_gnu_pltenter (ElfW(Sym) *sym __attribute__ ((unused)),
abe59f
+                         unsigned int ndx __attribute__ ((unused)),
abe59f
+                         uintptr_t *refcook, uintptr_t *defcook,
abe59f
+                         La_aarch64_regs *regs, unsigned int *flags,
abe59f
+                         const char *symname, long int *framesizep)
abe59f
+{
abe59f
+  printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
abe59f
+	  symname, (long int) sym->st_value, ndx, *flags);
abe59f
+
abe59f
+  if (strcmp (symname, "tst_audit26_func") == 0)
abe59f
+    {
abe59f
+      assert (regs->lr_xreg[0] == ARG1);
abe59f
+      assert (regs->lr_xreg[1] == ARG2);
abe59f
+      assert (regs->lr_xreg[2] == ARG3);
abe59f
+    }
abe59f
+  else
abe59f
+    abort ();
abe59f
+
abe59f
+  assert (regs->lr_vpcs == 0);
abe59f
+
abe59f
+  /* Clobber 'x8'.  */
abe59f
+  asm volatile ("mov x8, -1" : : : "x8");
abe59f
+
abe59f
+  *framesizep = 1024;
abe59f
+
abe59f
+  return sym->st_value;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_aarch64_gnu_pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
abe59f
+                        uintptr_t *defcook,
abe59f
+                        const struct La_aarch64_regs *inregs,
abe59f
+                        struct La_aarch64_retval *outregs, const char *symname)
abe59f
+{
abe59f
+  printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u\n",
abe59f
+	  symname, (long int) sym->st_value, ndx);
abe59f
+
abe59f
+  if (strcmp (symname, "tst_audit26_func") == 0)
abe59f
+    {
abe59f
+      assert (inregs->lr_xreg[0] == ARG1);
abe59f
+      assert (inregs->lr_xreg[1] == ARG2);
abe59f
+      assert (inregs->lr_xreg[2] == ARG3);
abe59f
+    }
abe59f
+  else
abe59f
+    abort ();
abe59f
+
abe59f
+  assert (inregs->lr_vpcs == 0);
abe59f
+  assert (outregs->lrv_vpcs == 0);
abe59f
+
abe59f
+  /* Clobber 'x8'.  */
abe59f
+  asm volatile ("mov x8, -1" : : : "x8");
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
diff --git a/sysdeps/aarch64/tst-auditmod27.c b/sysdeps/aarch64/tst-auditmod27.c
abe59f
new file mode 100644
abe59f
index 0000000000000000..21132c2985dab7b2
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/aarch64/tst-auditmod27.c
abe59f
@@ -0,0 +1,180 @@
abe59f
+/* Check LD_AUDIT for aarch64 specific ABI.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+#include <assert.h>
abe59f
+#include <link.h>
abe59f
+#include <string.h>
abe59f
+#include <stddef.h>
abe59f
+#include <stdio.h>
abe59f
+#include <stdlib.h>
abe59f
+#include "tst-audit27mod.h"
abe59f
+
abe59f
+#define TEST_NAME  "tst-audit27"
abe59f
+
abe59f
+#define AUDIT27_COOKIE 0
abe59f
+
abe59f
+unsigned int
abe59f
+la_version (unsigned int v)
abe59f
+{
abe59f
+  return v;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
abe59f
+{
abe59f
+  const char *p = strrchr (map->l_name, '/');
abe59f
+  const char *l_name = p == NULL ? map->l_name : p + 1;
abe59f
+  uintptr_t ck = -1;
abe59f
+  if (strncmp (l_name, TEST_NAME, strlen (TEST_NAME)) == 0)
abe59f
+    ck = AUDIT27_COOKIE;
abe59f
+  *cookie = ck;
abe59f
+  printf ("objopen: %ld, %s [%ld]\n", lmid, l_name, ck);
abe59f
+  return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
abe59f
+}
abe59f
+
abe59f
+ElfW(Addr)
abe59f
+la_aarch64_gnu_pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
abe59f
+			 uintptr_t *defcook, La_aarch64_regs *regs,
abe59f
+			 unsigned int *flags, const char *symname,
abe59f
+			 long int *framesizep)
abe59f
+{
abe59f
+  printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
abe59f
+	  symname, (long int) sym->st_value, ndx, *flags);
abe59f
+
abe59f
+  if (strcmp (symname, "tst_audit27_func_float") == 0)
abe59f
+    {
abe59f
+      assert (regs->lr_vreg[0].s == FUNC_FLOAT_ARG0);
abe59f
+      assert (regs->lr_vreg[1].s == FUNC_FLOAT_ARG1);
abe59f
+      assert (regs->lr_vreg[2].s == FUNC_FLOAT_ARG2);
abe59f
+      assert (regs->lr_vreg[3].s == FUNC_FLOAT_ARG3);
abe59f
+      assert (regs->lr_vreg[4].s == FUNC_FLOAT_ARG4);
abe59f
+      assert (regs->lr_vreg[5].s == FUNC_FLOAT_ARG5);
abe59f
+      assert (regs->lr_vreg[6].s == FUNC_FLOAT_ARG6);
abe59f
+      assert (regs->lr_vreg[7].s == FUNC_FLOAT_ARG7);
abe59f
+    }
abe59f
+  else if (strcmp (symname, "tst_audit27_func_double") == 0)
abe59f
+    {
abe59f
+      assert (regs->lr_vreg[0].d == FUNC_DOUBLE_ARG0);
abe59f
+      assert (regs->lr_vreg[1].d == FUNC_DOUBLE_ARG1);
abe59f
+      assert (regs->lr_vreg[2].d == FUNC_DOUBLE_ARG2);
abe59f
+      assert (regs->lr_vreg[3].d == FUNC_DOUBLE_ARG3);
abe59f
+      assert (regs->lr_vreg[4].d == FUNC_DOUBLE_ARG4);
abe59f
+      assert (regs->lr_vreg[5].d == FUNC_DOUBLE_ARG5);
abe59f
+      assert (regs->lr_vreg[6].d == FUNC_DOUBLE_ARG6);
abe59f
+      assert (regs->lr_vreg[7].d == FUNC_DOUBLE_ARG7);
abe59f
+    }
abe59f
+  else if (strcmp (symname, "tst_audit27_func_ldouble") == 0)
abe59f
+    {
abe59f
+      assert (regs->lr_vreg[0].q == FUNC_LDOUBLE_ARG0);
abe59f
+      assert (regs->lr_vreg[1].q == FUNC_LDOUBLE_ARG1);
abe59f
+      assert (regs->lr_vreg[2].q == FUNC_LDOUBLE_ARG2);
abe59f
+      assert (regs->lr_vreg[3].q == FUNC_LDOUBLE_ARG3);
abe59f
+      assert (regs->lr_vreg[4].q == FUNC_LDOUBLE_ARG4);
abe59f
+      assert (regs->lr_vreg[5].q == FUNC_LDOUBLE_ARG5);
abe59f
+      assert (regs->lr_vreg[6].q == FUNC_LDOUBLE_ARG6);
abe59f
+      assert (regs->lr_vreg[7].q == FUNC_LDOUBLE_ARG7);
abe59f
+    }
abe59f
+  else
abe59f
+    abort ();
abe59f
+
abe59f
+  assert (regs->lr_vpcs == 0);
abe59f
+
abe59f
+  /* Clobber the q registers on exit.  */
abe59f
+  uint8_t v = 0xff;
abe59f
+  asm volatile ("dup v0.8b, %w0" : : "r" (v) : "v0");
abe59f
+  asm volatile ("dup v1.8b, %w0" : : "r" (v) : "v1");
abe59f
+  asm volatile ("dup v2.8b, %w0" : : "r" (v) : "v2");
abe59f
+  asm volatile ("dup v3.8b, %w0" : : "r" (v) : "v3");
abe59f
+  asm volatile ("dup v4.8b, %w0" : : "r" (v) : "v4");
abe59f
+  asm volatile ("dup v5.8b, %w0" : : "r" (v) : "v5");
abe59f
+  asm volatile ("dup v6.8b, %w0" : : "r" (v) : "v6");
abe59f
+  asm volatile ("dup v7.8b, %w0" : : "r" (v) : "v7");
abe59f
+
abe59f
+  *framesizep = 1024;
abe59f
+
abe59f
+  return sym->st_value;
abe59f
+}
abe59f
+
abe59f
+unsigned int
abe59f
+la_aarch64_gnu_pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
abe59f
+                        uintptr_t *defcook,
abe59f
+			const struct La_aarch64_regs *inregs,
abe59f
+                        struct La_aarch64_retval *outregs,
abe59f
+			const char *symname)
abe59f
+{
abe59f
+  printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u\n",
abe59f
+	  symname, (long int) sym->st_value, ndx);
abe59f
+
abe59f
+  if (strcmp (symname, "tst_audit27_func_float") == 0)
abe59f
+    {
abe59f
+      assert (inregs->lr_vreg[0].s == FUNC_FLOAT_ARG0);
abe59f
+      assert (inregs->lr_vreg[1].s == FUNC_FLOAT_ARG1);
abe59f
+      assert (inregs->lr_vreg[2].s == FUNC_FLOAT_ARG2);
abe59f
+      assert (inregs->lr_vreg[3].s == FUNC_FLOAT_ARG3);
abe59f
+      assert (inregs->lr_vreg[4].s == FUNC_FLOAT_ARG4);
abe59f
+      assert (inregs->lr_vreg[5].s == FUNC_FLOAT_ARG5);
abe59f
+      assert (inregs->lr_vreg[6].s == FUNC_FLOAT_ARG6);
abe59f
+      assert (inregs->lr_vreg[7].s == FUNC_FLOAT_ARG7);
abe59f
+
abe59f
+      assert (outregs->lrv_vreg[0].s == FUNC_FLOAT_RET);
abe59f
+    }
abe59f
+  else if (strcmp (symname, "tst_audit27_func_double") == 0)
abe59f
+    {
abe59f
+      assert (inregs->lr_vreg[0].d == FUNC_DOUBLE_ARG0);
abe59f
+      assert (inregs->lr_vreg[1].d == FUNC_DOUBLE_ARG1);
abe59f
+      assert (inregs->lr_vreg[2].d == FUNC_DOUBLE_ARG2);
abe59f
+      assert (inregs->lr_vreg[3].d == FUNC_DOUBLE_ARG3);
abe59f
+      assert (inregs->lr_vreg[4].d == FUNC_DOUBLE_ARG4);
abe59f
+      assert (inregs->lr_vreg[5].d == FUNC_DOUBLE_ARG5);
abe59f
+      assert (inregs->lr_vreg[6].d == FUNC_DOUBLE_ARG6);
abe59f
+      assert (inregs->lr_vreg[7].d == FUNC_DOUBLE_ARG7);
abe59f
+
abe59f
+      assert (outregs->lrv_vreg[0].d == FUNC_DOUBLE_RET);
abe59f
+    }
abe59f
+  else if (strcmp (symname, "tst_audit27_func_ldouble") == 0)
abe59f
+    {
abe59f
+      assert (inregs->lr_vreg[0].q == FUNC_LDOUBLE_ARG0);
abe59f
+      assert (inregs->lr_vreg[1].q == FUNC_LDOUBLE_ARG1);
abe59f
+      assert (inregs->lr_vreg[2].q == FUNC_LDOUBLE_ARG2);
abe59f
+      assert (inregs->lr_vreg[3].q == FUNC_LDOUBLE_ARG3);
abe59f
+      assert (inregs->lr_vreg[4].q == FUNC_LDOUBLE_ARG4);
abe59f
+      assert (inregs->lr_vreg[5].q == FUNC_LDOUBLE_ARG5);
abe59f
+      assert (inregs->lr_vreg[6].q == FUNC_LDOUBLE_ARG6);
abe59f
+      assert (inregs->lr_vreg[7].q == FUNC_LDOUBLE_ARG7);
abe59f
+
abe59f
+      assert (outregs->lrv_vreg[0].q == FUNC_LDOUBLE_RET);
abe59f
+    }
abe59f
+  else
abe59f
+    abort ();
abe59f
+
abe59f
+  assert (inregs->lr_vpcs == 0);
abe59f
+  assert (outregs->lrv_vpcs == 0);
abe59f
+
abe59f
+  /* Clobber the q registers on exit.  */
abe59f
+  uint8_t v = 0xff;
abe59f
+  asm volatile ("dup v0.8b, %w0" : : "r" (v) : "v0");
abe59f
+  asm volatile ("dup v1.8b, %w0" : : "r" (v) : "v1");
abe59f
+  asm volatile ("dup v2.8b, %w0" : : "r" (v) : "v2");
abe59f
+  asm volatile ("dup v3.8b, %w0" : : "r" (v) : "v3");
abe59f
+  asm volatile ("dup v4.8b, %w0" : : "r" (v) : "v4");
abe59f
+  asm volatile ("dup v5.8b, %w0" : : "r" (v) : "v5");
abe59f
+  asm volatile ("dup v6.8b, %w0" : : "r" (v) : "v6");
abe59f
+  asm volatile ("dup v7.8b, %w0" : : "r" (v) : "v7");
abe59f
+
abe59f
+  return 0;
abe59f
+}
abe59f
diff --git a/sysdeps/generic/dl-audit-check.h b/sysdeps/generic/dl-audit-check.h
abe59f
new file mode 100644
abe59f
index 0000000000000000..3ab76532868b5895
abe59f
--- /dev/null
abe59f
+++ b/sysdeps/generic/dl-audit-check.h
abe59f
@@ -0,0 +1,23 @@
abe59f
+/* rtld-audit version check.  Generic version.
abe59f
+   Copyright (C) 2022 Free Software Foundation, Inc.
abe59f
+   This file is part of the GNU C Library.
abe59f
+
abe59f
+   The GNU C Library is free software; you can redistribute it and/or
abe59f
+   modify it under the terms of the GNU Lesser General Public
abe59f
+   License as published by the Free Software Foundation; either
abe59f
+   version 2.1 of the License, or (at your option) any later version.
abe59f
+
abe59f
+   The GNU C Library is distributed in the hope that it will be useful,
abe59f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
abe59f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
abe59f
+   Lesser General Public License for more details.
abe59f
+
abe59f
+   You should have received a copy of the GNU Lesser General Public
abe59f
+   License along with the GNU C Library; if not, see
abe59f
+   <https://www.gnu.org/licenses/>.  */
abe59f
+
abe59f
+static inline bool
abe59f
+_dl_audit_check_version (unsigned int lav)
abe59f
+{
abe59f
+  return lav <= LAV_CURRENT;
abe59f
+}