Merge "riscv64: pass a pointer to __riscv_hwprobe() to ifunc resolvers." into main am: 75539ab928
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2860689 Change-Id: I08da51a32b58320f62a2b6fbb09187e8049f243d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
aecaca71a4
3 changed files with 22 additions and 9 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "private/bionic_call_ifunc_resolver.h"
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/hwprobe.h>
|
||||
#include <sys/ifunc.h>
|
||||
|
||||
#include "bionic/macros.h"
|
||||
|
@ -54,12 +55,12 @@ ElfW(Addr) __bionic_call_ifunc_resolver(ElfW(Addr) resolver_addr) {
|
|||
static unsigned long hwcap = getauxval(AT_HWCAP);
|
||||
return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(hwcap);
|
||||
#elif defined(__riscv)
|
||||
// The pointer argument is currently unused, but reserved for future
|
||||
// The third argument is currently unused, but reserved for future
|
||||
// expansion. If we pass nullptr from the beginning, it'll be easier
|
||||
// to recognize if/when we pass actual data (and matches glibc).
|
||||
typedef ElfW(Addr) (*ifunc_resolver_t)(uint64_t, void*);
|
||||
typedef ElfW(Addr) (*ifunc_resolver_t)(uint64_t, __riscv_hwprobe_t, void*);
|
||||
static uint64_t hwcap = getauxval(AT_HWCAP);
|
||||
return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(hwcap, nullptr);
|
||||
return reinterpret_cast<ifunc_resolver_t>(resolver_addr)(hwcap, __riscv_hwprobe, nullptr);
|
||||
#else
|
||||
typedef ElfW(Addr) (*ifunc_resolver_t)(void);
|
||||
return reinterpret_cast<ifunc_resolver_t>(resolver_addr)();
|
||||
|
|
|
@ -53,6 +53,14 @@ __BEGIN_DECLS
|
|||
*/
|
||||
int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_count, unsigned long* _Nullable __cpus, unsigned __flags);
|
||||
|
||||
/**
|
||||
* The type of the second argument passed to riscv64 ifunc resolvers.
|
||||
* This argument allows riscv64 ifunc resolvers to call __riscv_hwprobe()
|
||||
* without worrying about whether that relocation is resolved before
|
||||
* the ifunc resolver is called.
|
||||
*/
|
||||
typedef int (*__riscv_hwprobe_t)(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_count, unsigned long* _Nullable __cpus, unsigned __flags);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,18 +65,18 @@ extern "C" fn_ptr_t hwcap_resolver(unsigned long hwcap) {
|
|||
#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 @@ TEST(ifunc, hwcap) {
|
|||
#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));
|
||||
|
|
Loading…
Reference in a new issue