riscv64: pass a pointer to __riscv_hwprobe() to ifunc resolvers.

This way, callees don't need to worry about whether or not their
reference to __riscv_hwprobe() has been resolved before their ifunc
resolver is called.

This matches the current glibc proposal from rivos.

Test: treehugger
Change-Id: I0d5244aa837d0d1f0e6bd7d22091dfedb8a55bdb
diff --git a/tests/ifunc_test.cpp b/tests/ifunc_test.cpp
index 1fdbf1a..09d987d 100644
--- a/tests/ifunc_test.cpp
+++ b/tests/ifunc_test.cpp
@@ -65,18 +65,18 @@
 #include <sys/hwprobe.h>
 
 static uint64_t g_hwcap;
+static __riscv_hwprobe_t g_hwprobe_ptr;
+static void* g_null;
 
 static riscv_hwprobe g_hwprobes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0}};
 
-extern "C" fn_ptr_t hwcap_resolver(uint64_t hwcap, void* null) {
-  // Check hwcap like arm32/arm64.
+extern "C" fn_ptr_t hwcap_resolver(uint64_t hwcap, __riscv_hwprobe_t hwprobe_ptr, void* null) {
   g_hwcap = hwcap;
-
-  // For now, the pointer argument is reserved for future expansion.
-  if (null != NULL) abort();
+  g_hwprobe_ptr = hwprobe_ptr;
+  g_null = null;
 
   // Ensure that __riscv_hwprobe() can be called from an ifunc.
-  if (__riscv_hwprobe(g_hwprobes, 1, 0, nullptr, 0) != 0) return nullptr;
+  if ((*hwprobe_ptr)(g_hwprobes, 1, 0, nullptr, 0) != 0) return nullptr;
   return ret42;
 }
 
@@ -102,7 +102,11 @@
 #elif defined(__arm__)
   EXPECT_EQ(getauxval(AT_HWCAP), g_hwcap);
 #elif defined(__riscv)
+  printf("hwcap=%lx hwprobe_ptr=%p (__riscv_hwprobe=%p) null=%p\n", g_hwcap, g_hwprobe_ptr,
+         __riscv_hwprobe, g_null);
+
   EXPECT_EQ(getauxval(AT_HWCAP), g_hwcap);
+  EXPECT_EQ(nullptr, g_null);
 
   riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0}};
   ASSERT_EQ(0, __riscv_hwprobe(probes, 1, 0, nullptr, 0));