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,5 @@
|
||||
char *foo_baz_conflict(void);
|
||||
|
||||
char *bar_calls_foo_baz_conflict(void) {
|
||||
return foo_baz_conflict();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
char *foo_baz_conflict() {
|
||||
return "resolved to baz";
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
char *foo_baz_conflict() {
|
||||
return "resolved to foo";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
libfoo = shared_library('foo', 'libfoo.c')
|
||||
libbar = shared_library('bar', 'libbar.c', build_rpath: test_rpath, link_with: libfoo)
|
||||
libbaz = shared_library('baz', 'libbaz.c')
|
||||
test_depends = [libfoo, libbar, libbaz]
|
||||
|
||||
libfoo_native = shared_library('native-foo', 'libfoo.c', native: true)
|
||||
libbar_native = shared_library('native-bar', 'libbar.c', build_rpath: test_rpath, link_with: libfoo_native, native: true)
|
||||
libbaz_native = shared_library('native-baz', 'libbaz.c', native: true)
|
||||
test_native_depends = [libfoo_native, libbar_native, libbaz_native]
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <stddef.h>
|
||||
#include <dlfcn.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef USE_HOST_LIBC
|
||||
#define LIBBAR "libnative-bar.so"
|
||||
#define LIBBAZ "libnative-baz.so"
|
||||
#else
|
||||
#define LIBBAR "libbar.so"
|
||||
#define LIBBAZ "libbaz.so"
|
||||
#endif
|
||||
|
||||
typedef char *strfn(void);
|
||||
|
||||
int main() {
|
||||
void *baz = dlopen(LIBBAZ, RTLD_LAZY | RTLD_GLOBAL);
|
||||
assert(baz);
|
||||
|
||||
// At this point, baz is loaded in the global scope. When we load bar locally,
|
||||
// there is a relocation to `foo_baz_conflict` which is defined in both
|
||||
// foo (which is a dependency of bar), and baz. In this case baz should win
|
||||
// since we search the global scope first.
|
||||
|
||||
void *bar = dlopen(LIBBAR, RTLD_LAZY | RTLD_LOCAL);
|
||||
assert(bar);
|
||||
|
||||
strfn *bfn = dlsym(bar, "bar_calls_foo_baz_conflict");
|
||||
assert(!strcmp(bfn(), "resolved to baz"));
|
||||
|
||||
// TODO: Test RTLD_DEEPBIND and DT_SYMBOLIC once we implement it.
|
||||
|
||||
dlclose(bar);
|
||||
dlclose(baz);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user