]>
Commit | Line | Data |
---|---|---|
e156dabc | 1 | /* Test that variant PCS calls don't clobber registers with lazy binding. |
581c785b | 2 | Copyright (C) 2020-2022 Free Software Foundation, Inc. |
e156dabc SN |
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 <stdint.h> | |
20 | #include <stdio.h> | |
21 | #include <support/check.h> | |
22 | ||
23 | struct regs | |
24 | { | |
25 | uint64_t x[32]; | |
26 | union { | |
27 | long double q[32]; | |
28 | uint64_t u[64]; | |
29 | } v; | |
30 | }; | |
31 | ||
32 | /* Gives the registers in the caller and callee around a variant PCS call. | |
33 | Most registers are initialized from BEFORE in the caller so they can | |
34 | have values that likely show clobbers. Register state extensions such | |
35 | as SVE is not covered here, only the base registers. */ | |
36 | void vpcs_call_regs (struct regs *after, struct regs *before); | |
37 | ||
38 | static int | |
39 | do_test (void) | |
40 | { | |
41 | struct regs before, after; | |
42 | int err = 0; | |
43 | ||
44 | unsigned char *p = (unsigned char *)&before; | |
45 | for (int i = 0; i < sizeof before; i++) | |
46 | p[i] = i & 0xff; | |
47 | ||
48 | vpcs_call_regs (&after, &before); | |
49 | ||
50 | for (int i = 0; i < 32; i++) | |
51 | if (before.x[i] != after.x[i]) | |
52 | { | |
53 | if (i == 16 || i == 17) | |
54 | /* Variant PCS allows clobbering x16 and x17. */ | |
55 | continue; | |
56 | err++; | |
57 | printf ("x%d: before: 0x%016llx after: 0x%016llx\n", | |
58 | i, | |
59 | (unsigned long long)before.x[i], | |
60 | (unsigned long long)after.x[i]); | |
61 | } | |
62 | for (int i = 0; i < 64; i++) | |
63 | if (before.v.u[i] != after.v.u[i]) | |
64 | { | |
65 | err++; | |
66 | printf ("v%d: before: 0x%016llx %016llx after: 0x%016llx %016llx\n", | |
67 | i/2, | |
68 | (unsigned long long)before.v.u[2*(i/2)+1], | |
69 | (unsigned long long)before.v.u[2*(i/2)], | |
70 | (unsigned long long)after.v.u[2*(i/2)+1], | |
71 | (unsigned long long)after.v.u[2*(i/2)]); | |
72 | } | |
73 | if (err) | |
74 | FAIL_EXIT1 ("The variant PCS call clobbered %d registers.\n", err); | |
75 | return 0; | |
76 | } | |
77 | ||
78 | #include <support/test-driver.c> |