1/* Check LD_AUDIT for aarch64 specific ABI.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <assert.h>
20#include <link.h>
21#include <string.h>
22#include <stddef.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include "tst-audit27mod.h"
26
27#define TEST_NAME "tst-audit27"
28
29#define AUDIT27_COOKIE 0
30
31unsigned int
32la_version (unsigned int v)
33{
34 return v;
35}
36
37unsigned int
38la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
39{
40 const char *p = strrchr (map->l_name, '/');
41 const char *l_name = p == NULL ? map->l_name : p + 1;
42 uintptr_t ck = -1;
43 if (strncmp (l_name, TEST_NAME, strlen (TEST_NAME)) == 0)
44 ck = AUDIT27_COOKIE;
45 *cookie = ck;
46 printf (format: "objopen: %ld, %s [%ld]\n", lmid, l_name, ck);
47 return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO;
48}
49
50ElfW(Addr)
51la_aarch64_gnu_pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
52 uintptr_t *defcook, La_aarch64_regs *regs,
53 unsigned int *flags, const char *symname,
54 long int *framesizep)
55{
56 printf (format: "pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
57 symname, (long int) sym->st_value, ndx, *flags);
58
59 if (strcmp (symname, "tst_audit27_func_float") == 0)
60 {
61 assert (regs->lr_vreg[0].s == FUNC_FLOAT_ARG0);
62 assert (regs->lr_vreg[1].s == FUNC_FLOAT_ARG1);
63 assert (regs->lr_vreg[2].s == FUNC_FLOAT_ARG2);
64 assert (regs->lr_vreg[3].s == FUNC_FLOAT_ARG3);
65 assert (regs->lr_vreg[4].s == FUNC_FLOAT_ARG4);
66 assert (regs->lr_vreg[5].s == FUNC_FLOAT_ARG5);
67 assert (regs->lr_vreg[6].s == FUNC_FLOAT_ARG6);
68 assert (regs->lr_vreg[7].s == FUNC_FLOAT_ARG7);
69 }
70 else if (strcmp (symname, "tst_audit27_func_double") == 0)
71 {
72 assert (regs->lr_vreg[0].d == FUNC_DOUBLE_ARG0);
73 assert (regs->lr_vreg[1].d == FUNC_DOUBLE_ARG1);
74 assert (regs->lr_vreg[2].d == FUNC_DOUBLE_ARG2);
75 assert (regs->lr_vreg[3].d == FUNC_DOUBLE_ARG3);
76 assert (regs->lr_vreg[4].d == FUNC_DOUBLE_ARG4);
77 assert (regs->lr_vreg[5].d == FUNC_DOUBLE_ARG5);
78 assert (regs->lr_vreg[6].d == FUNC_DOUBLE_ARG6);
79 assert (regs->lr_vreg[7].d == FUNC_DOUBLE_ARG7);
80 }
81 else if (strcmp (symname, "tst_audit27_func_ldouble") == 0)
82 {
83 assert (regs->lr_vreg[0].q == FUNC_LDOUBLE_ARG0);
84 assert (regs->lr_vreg[1].q == FUNC_LDOUBLE_ARG1);
85 assert (regs->lr_vreg[2].q == FUNC_LDOUBLE_ARG2);
86 assert (regs->lr_vreg[3].q == FUNC_LDOUBLE_ARG3);
87 assert (regs->lr_vreg[4].q == FUNC_LDOUBLE_ARG4);
88 assert (regs->lr_vreg[5].q == FUNC_LDOUBLE_ARG5);
89 assert (regs->lr_vreg[6].q == FUNC_LDOUBLE_ARG6);
90 assert (regs->lr_vreg[7].q == FUNC_LDOUBLE_ARG7);
91 }
92 else
93 abort ();
94
95 assert (regs->lr_vpcs == 0);
96
97 /* Clobber the q registers on exit. */
98 uint8_t v = 0xff;
99 asm volatile ("dup v0.8b, %w0" : : "r" (v) : "v0");
100 asm volatile ("dup v1.8b, %w0" : : "r" (v) : "v1");
101 asm volatile ("dup v2.8b, %w0" : : "r" (v) : "v2");
102 asm volatile ("dup v3.8b, %w0" : : "r" (v) : "v3");
103 asm volatile ("dup v4.8b, %w0" : : "r" (v) : "v4");
104 asm volatile ("dup v5.8b, %w0" : : "r" (v) : "v5");
105 asm volatile ("dup v6.8b, %w0" : : "r" (v) : "v6");
106 asm volatile ("dup v7.8b, %w0" : : "r" (v) : "v7");
107
108 *framesizep = 1024;
109
110 return sym->st_value;
111}
112
113unsigned int
114la_aarch64_gnu_pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
115 uintptr_t *defcook,
116 const struct La_aarch64_regs *inregs,
117 struct La_aarch64_retval *outregs,
118 const char *symname)
119{
120 printf (format: "pltexit: symname=%s, st_value=%#lx, ndx=%u\n",
121 symname, (long int) sym->st_value, ndx);
122
123 if (strcmp (symname, "tst_audit27_func_float") == 0)
124 {
125 assert (inregs->lr_vreg[0].s == FUNC_FLOAT_ARG0);
126 assert (inregs->lr_vreg[1].s == FUNC_FLOAT_ARG1);
127 assert (inregs->lr_vreg[2].s == FUNC_FLOAT_ARG2);
128 assert (inregs->lr_vreg[3].s == FUNC_FLOAT_ARG3);
129 assert (inregs->lr_vreg[4].s == FUNC_FLOAT_ARG4);
130 assert (inregs->lr_vreg[5].s == FUNC_FLOAT_ARG5);
131 assert (inregs->lr_vreg[6].s == FUNC_FLOAT_ARG6);
132 assert (inregs->lr_vreg[7].s == FUNC_FLOAT_ARG7);
133
134 assert (outregs->lrv_vreg[0].s == FUNC_FLOAT_RET);
135 }
136 else if (strcmp (symname, "tst_audit27_func_double") == 0)
137 {
138 assert (inregs->lr_vreg[0].d == FUNC_DOUBLE_ARG0);
139 assert (inregs->lr_vreg[1].d == FUNC_DOUBLE_ARG1);
140 assert (inregs->lr_vreg[2].d == FUNC_DOUBLE_ARG2);
141 assert (inregs->lr_vreg[3].d == FUNC_DOUBLE_ARG3);
142 assert (inregs->lr_vreg[4].d == FUNC_DOUBLE_ARG4);
143 assert (inregs->lr_vreg[5].d == FUNC_DOUBLE_ARG5);
144 assert (inregs->lr_vreg[6].d == FUNC_DOUBLE_ARG6);
145 assert (inregs->lr_vreg[7].d == FUNC_DOUBLE_ARG7);
146
147 assert (outregs->lrv_vreg[0].d == FUNC_DOUBLE_RET);
148 }
149 else if (strcmp (symname, "tst_audit27_func_ldouble") == 0)
150 {
151 assert (inregs->lr_vreg[0].q == FUNC_LDOUBLE_ARG0);
152 assert (inregs->lr_vreg[1].q == FUNC_LDOUBLE_ARG1);
153 assert (inregs->lr_vreg[2].q == FUNC_LDOUBLE_ARG2);
154 assert (inregs->lr_vreg[3].q == FUNC_LDOUBLE_ARG3);
155 assert (inregs->lr_vreg[4].q == FUNC_LDOUBLE_ARG4);
156 assert (inregs->lr_vreg[5].q == FUNC_LDOUBLE_ARG5);
157 assert (inregs->lr_vreg[6].q == FUNC_LDOUBLE_ARG6);
158 assert (inregs->lr_vreg[7].q == FUNC_LDOUBLE_ARG7);
159
160 assert (outregs->lrv_vreg[0].q == FUNC_LDOUBLE_RET);
161 }
162 else
163 abort ();
164
165 assert (inregs->lr_vpcs == 0);
166 assert (outregs->lrv_vpcs == 0);
167
168 /* Clobber the q registers on exit. */
169 uint8_t v = 0xff;
170 asm volatile ("dup v0.8b, %w0" : : "r" (v) : "v0");
171 asm volatile ("dup v1.8b, %w0" : : "r" (v) : "v1");
172 asm volatile ("dup v2.8b, %w0" : : "r" (v) : "v2");
173 asm volatile ("dup v3.8b, %w0" : : "r" (v) : "v3");
174 asm volatile ("dup v4.8b, %w0" : : "r" (v) : "v4");
175 asm volatile ("dup v5.8b, %w0" : : "r" (v) : "v5");
176 asm volatile ("dup v6.8b, %w0" : : "r" (v) : "v6");
177 asm volatile ("dup v7.8b, %w0" : : "r" (v) : "v7");
178
179 return 0;
180}
181

source code of glibc/sysdeps/aarch64/tst-auditmod27.c