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,19 @@
#include <assert.h>
#include <dlfcn.h>
#ifdef USE_HOST_LIBC
#define LIBFOO "libnative-foo.so"
#else
#define LIBFOO "libfoo.so"
#endif
int foo(void);
int bar(void) {
return foo();
}
[[gnu::constructor]] void init(void) {
void *libfoo = dlopen(LIBFOO, RTLD_LOCAL | RTLD_NOW);
assert(libfoo);
}
@@ -0,0 +1,3 @@
int foo(void) {
return 0xCAFEBABE;
}
@@ -0,0 +1,32 @@
# meson does not have native custom_target, so when cross compiling it gets
# unhappy that we're trying to link a "host" library (which is actually built
# for the build machine) to a build executable. This means we can't patchelf
# native libraries if we want cross compilation to work.
patchelf = find_program('patchelf', required: false)
if patchelf.found()
# Overwrite LD_LIBRARY_PATH to make meson not fix our shenanigans
# Otherwise, meson's LD_LIBRARY_PATH makes this test useless because libfoo
# will be found through it instead of failing when libfoo is not found
test_env += ['LD_LIBRARY_PATH=']
test_native_env += ['LD_LIBRARY_PATH=']
libfoo = shared_library('foo', 'libfoo.c', link_args: test_additional_link_args)
libbar_unpatched = shared_library('bar-unpatched', 'libbar.c',
link_args: test_additional_link_args,
override_options: 'b_sanitize=none',
dependencies: libc_dep,
link_with: libfoo)
libbar = custom_target('patch-libbar',
command: [patchelf,
'--remove-rpath',
'--set-soname', 'libbar.so',
libbar_unpatched,
'--output', '@OUTPUT0@'],
output: ['libbar.so'],
)
test_link_with = [libbar, libfoo]
else
test_skipped = true
endif
@@ -0,0 +1,21 @@
#include <assert.h>
#include <dlfcn.h>
#ifdef USE_HOST_LIBC
#define LIBBAR "libnative-bar.so"
#else
#define LIBBAR "libbar.so"
#endif
int foo();
int bar();
int main() {
void *libbar = dlopen(LIBBAR, RTLD_LOCAL | RTLD_NOW);
assert(libbar);
assert(foo() == (int) 0xCAFEBABE);
assert(bar() == (int) 0xCAFEBABE);
return 0;
}