user: implement mlibc as the libc, finally.
It's finally done.. Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include <stdint.h>
|
||||
|
||||
static uint64_t foo_impl(void) {
|
||||
return 420;
|
||||
}
|
||||
|
||||
#if defined(__riscv) && !defined(USE_HOST_LIBC)
|
||||
#include <sys/hwprobe.h>
|
||||
#elif defined(__riscv)
|
||||
int __riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count, size_t cpusetsize, cpu_set_t *cpus,
|
||||
unsigned int flags) __attribute__((access(read_write, 1, 2)));
|
||||
|
||||
typedef int (*__riscv_hwprobe_t)(struct riscv_hwprobe *pairs, size_t pair_count,
|
||||
size_t cpusetsize, cpu_set_t *cpus, unsigned int flags) __attribute__((access(read_write, 1, 2)));
|
||||
#endif
|
||||
|
||||
#if defined(__riscv)
|
||||
#include <stdlib.h>
|
||||
|
||||
static uint64_t (*foo_resolver(long long, __riscv_hwprobe_t hwprobe, void *))(void) {
|
||||
if (!hwprobe)
|
||||
return NULL;
|
||||
struct riscv_hwprobe pairs[1] = {
|
||||
{ .key = 4, .value = 0 }
|
||||
};
|
||||
hwprobe(pairs, 1, 0, 0, 0);
|
||||
return foo_impl;
|
||||
}
|
||||
#else
|
||||
static uint64_t (*foo_resolver(void))(void) {
|
||||
return foo_impl;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t foo(void) __attribute__((ifunc("foo_resolver")));
|
||||
@@ -0,0 +1,5 @@
|
||||
libifunc_test = shared_library('ifunc-test', 'lib.c', dependencies: libc_dep)
|
||||
test_link_with = [libifunc_test]
|
||||
|
||||
libifunc_test_native = shared_library('native-ifunc-test', 'lib.c', native: true)
|
||||
test_native_link_with = [libifunc_test_native]
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
int foo(void);
|
||||
|
||||
int main(void) {
|
||||
int res = foo();
|
||||
assert(res == 420);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user