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
24static int
25one (void)
26{
27 return 1;
28}
29
30static uint64_t saved_arg1;
31static __ifunc_arg_t saved_arg2;
32
33/* local ifunc symbol. */
34int
35__attribute__ ((visibility ("hidden")))
36foo (void);
37
38static void *
39__attribute__ ((used))
40foo_ifunc (uint64_t, const __ifunc_arg_t *) __asm__ ("foo");
41__asm__(".type foo, %gnu_indirect_function");
42
43static void *
44__attribute__ ((used))
45inhibit_stack_protector
46foo_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
54static int
55do_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

source code of glibc/sysdeps/aarch64/tst-ifunc-arg-2.c