-
-
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: Add test for symbol versioning
- Loading branch information
Showing
5 changed files
with
80 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ rtld_test_cases = [ | |
'scope5', | ||
'tls_align', | ||
'relr', | ||
'symver', | ||
] | ||
|
||
host_libc_rtld_nosan_test_cases = [ | ||
|
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,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 @) |
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,14 @@ | ||
FOO_1 { | ||
global: foo; | ||
local: *; | ||
}; | ||
|
||
FOO_2 { | ||
global: foo; | ||
local: *; | ||
}; | ||
|
||
FOO_3 { | ||
global: foo; | ||
local: *; | ||
}; |
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,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] |
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,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; | ||
} |