1 | /* Test R_*_IRELATIVE resolver with second argument. |
2 | Copyright (C) 2019-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 <stdint.h> |
20 | #include <sys/auxv.h> |
21 | #include <sys/ifunc.h> |
22 | #include <support/check.h> |
23 | |
24 | static int |
25 | one (void) |
26 | { |
27 | return 1; |
28 | } |
29 | |
30 | static uint64_t saved_arg1; |
31 | static __ifunc_arg_t saved_arg2; |
32 | |
33 | /* local ifunc symbol. */ |
34 | int |
35 | __attribute__ ((visibility ("hidden" ))) |
36 | foo (void); |
37 | |
38 | static void * |
39 | __attribute__ ((used)) |
40 | foo_ifunc (uint64_t, const __ifunc_arg_t *) __asm__ ("foo" ); |
41 | __asm__(".type foo, %gnu_indirect_function" ); |
42 | |
43 | static void * |
44 | __attribute__ ((used)) |
45 | inhibit_stack_protector |
46 | foo_ifunc (uint64_t arg1, const __ifunc_arg_t *arg2) |
47 | { |
48 | saved_arg1 = arg1; |
49 | if (arg1 & _IFUNC_ARG_HWCAP) |
50 | saved_arg2 = *arg2; |
51 | return (void *) one; |
52 | } |
53 | |
54 | static int |
55 | do_test (void) |
56 | { |
57 | TEST_VERIFY (foo () == 1); |
58 | TEST_VERIFY (saved_arg1 & _IFUNC_ARG_HWCAP); |
59 | TEST_COMPARE ((uint32_t)saved_arg1, (uint32_t)getauxval (AT_HWCAP)); |
60 | TEST_COMPARE (saved_arg2._size, sizeof (__ifunc_arg_t)); |
61 | TEST_COMPARE (saved_arg2._hwcap, getauxval (AT_HWCAP)); |
62 | TEST_COMPARE (saved_arg2._hwcap2, getauxval (AT_HWCAP2)); |
63 | return 0; |
64 | } |
65 | |
66 | #include <support/test-driver.c> |
67 | |