(root)/
glibc-2.38/
sysdeps/
aarch64/
tst-ifunc-arg-1.c
       1  /* Test STT_GNU_IFUNC resolver with second argument.
       2     Copyright (C) 2019-2023 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  /* extern visible ifunc symbol.  */
      34  int
      35  foo (void);
      36  
      37  void *
      38  foo_ifunc (uint64_t, const __ifunc_arg_t *) __asm__ ("foo");
      39  __asm__(".type foo, %gnu_indirect_function");
      40  
      41  void *
      42  inhibit_stack_protector
      43  foo_ifunc (uint64_t arg1, const __ifunc_arg_t *arg2)
      44  {
      45    saved_arg1 = arg1;
      46    if (arg1 & _IFUNC_ARG_HWCAP)
      47        saved_arg2 = *arg2;
      48    return (void *) one;
      49  }
      50  
      51  static int
      52  do_test (void)
      53  {
      54    TEST_VERIFY (foo () == 1);
      55    TEST_VERIFY (saved_arg1 & _IFUNC_ARG_HWCAP);
      56    TEST_COMPARE ((uint32_t)saved_arg1, (uint32_t)getauxval (AT_HWCAP));
      57    TEST_COMPARE (saved_arg2._size, sizeof (__ifunc_arg_t));
      58    TEST_COMPARE (saved_arg2._hwcap, getauxval (AT_HWCAP));
      59    TEST_COMPARE (saved_arg2._hwcap2, getauxval (AT_HWCAP2));
      60    return 0;
      61  }
      62  
      63  #include <support/test-driver.c>