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