-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/rtld: Add test for breadth-first search order
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ rtld_test_cases = [ | |
'scope3', | ||
'scope4', | ||
'scope5', | ||
'search-order', | ||
'tls_align', | ||
'relr', | ||
'symver', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() + 0xBABE; | ||
} | ||
|
||
[[constructor]] void init(void) { | ||
void *libfoo = dlopen(LIBFOO, RTLD_LOCAL | RTLD_NOW); | ||
assert(libfoo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int foo(void) { | ||
return 0xCAFE0000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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') | ||
libbar_unpatched = shared_library('bar-unpatched', 'libbar.c', | ||
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] | ||
|
||
libfoo_native = shared_library('native-foo', 'libfoo.c', native: true) | ||
libbar_native_unpatched = shared_library('native-bar-unpatched', 'libbar.c', | ||
dependencies: rtlib_deps, link_with: libfoo_native, native: true) | ||
libbar_native = custom_target('patch-libnative-bar', | ||
command: [patchelf, | ||
'--remove-rpath', | ||
'--set-soname', 'libnative-bar.so', | ||
libbar_native_unpatched, | ||
'--output', '@OUTPUT0@'], | ||
output: ['libnative-bar.so'], | ||
) | ||
test_native_link_with = [libbar_native, libfoo_native] | ||
else | ||
test_skipped = true | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) 0xCAFE0000); | ||
assert(bar() == (int) 0xCAFEBABE); | ||
|
||
return 0; | ||
} |