user: implement mlibc as the libc, finally.

It's finally done..

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
kaguya
2026-05-02 03:31:49 -04:00
parent 2fa39ad85a
commit 9a9b91c940
2387 changed files with 152741 additions and 315 deletions
@@ -0,0 +1,15 @@
int foo_v1(void) {
return 1;
}
int foo_v2(void) {
return 2;
}
int foo_v3(void) {
return 3;
}
asm(".symver foo_v1, foo@FOO_1");
asm(".symver foo_v2, foo@FOO_2");
asm(".symver foo_v3, foo@@FOO_3"); // default version (due to @@ vs @)
@@ -0,0 +1,14 @@
FOO_1 {
global: foo;
local: *;
};
FOO_2 {
global: foo;
local: *;
};
FOO_3 {
global: foo;
local: *;
};
@@ -0,0 +1,11 @@
version_script = meson.current_source_dir() / 'libfoo.ver'
libfoo = shared_library('foo', 'libfoo.c',
link_args : ['-Wl,--version-script', version_script])
test_depends = [libfoo]
test_link_with = [libfoo]
libfoo_native = shared_library('native-foo', 'libfoo.c', native: true,
link_args : ['-Wl,--version-script', version_script])
test_native_depends = [libfoo_native]
test_native_link_with = [libfoo_native]
@@ -0,0 +1,39 @@
#include <assert.h>
#include <stdio.h>
#include <dlfcn.h>
#ifdef USE_HOST_LIBC
#define LIBFOO "libnative-foo.so"
#else
#define LIBFOO "libfoo.so"
#endif
int foo(void);
int main() {
int ver = foo();
fprintf(stderr, "called foo version %d\n", ver);
assert(ver == 3); // version 3 is the default for libfoo.so
void *libfoo_h = dlopen(LIBFOO, RTLD_GLOBAL | RTLD_NOW);
assert(libfoo_h);
int (*foo1)(void) = dlvsym(libfoo_h, "foo", "FOO_1");
assert(foo1);
int (*foo2)(void) = dlvsym(libfoo_h, "foo", "FOO_2");
assert(foo2);
int (*foo3)(void) = dlvsym(libfoo_h, "foo", "FOO_3");
assert(foo3);
int (*foo_def)(void) = dlsym(libfoo_h, "foo");
assert(foo_def);
assert(foo1() == 1);
assert(foo2() == 2);
assert(foo3() == 3);
assert(foo3 == foo_def);
return 0;
}