diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/test-dladdr.c | 23 |
2 files changed, 15 insertions, 15 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 00b6647..47fef38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -25,6 +25,13 @@ target_link_libraries(test-dladdr dl) | |||
25 | if(UNIX) | 25 | if(UNIX) |
26 | set_target_properties(test-dladdr PROPERTIES COMPILE_FLAGS "-Wl,--export-dynamic -fpie") | 26 | set_target_properties(test-dladdr PROPERTIES COMPILE_FLAGS "-Wl,--export-dynamic -fpie") |
27 | endif() | 27 | endif() |
28 | if(WIN32 AND NOT BUILD_SHARED_LIBS) | ||
29 | if(MSVC) | ||
30 | set_property(TARGET test-dladdr APPEND_STRING PROPERTY LINK_FLAGS "/EXPORT:dlopen /EXPORT:dladdr") | ||
31 | else() | ||
32 | set_property(TARGET test-dladdr APPEND_STRING PROPERTY LINK_FLAGS "-Wl,--export-all-symbols") | ||
33 | endif() | ||
34 | endif() | ||
28 | 35 | ||
29 | install(TARGETS test-dladdr EXPORT dlfcn-win32-targets RUNTIME DESTINATION bin) | 36 | install(TARGETS test-dladdr EXPORT dlfcn-win32-targets RUNTIME DESTINATION bin) |
30 | 37 | ||
diff --git a/tests/test-dladdr.c b/tests/test-dladdr.c index 57914cb..e2f6c01 100644 --- a/tests/test-dladdr.c +++ b/tests/test-dladdr.c | |||
@@ -1,4 +1,6 @@ | |||
1 | /* On Unix like os compile with "-Wl,--export-dynamic -fpie" (default with cmake) */ | 1 | /* On Unix like os compile with "-Wl,--export-dynamic -fpie" (default with cmake) */ |
2 | /* On Windows gcc compile with "-Wl,--export-all-symbols" (default with cmake) */ | ||
3 | /* On Windows msvc compile with "/EXPORT:dlopen /EXPORT:dladdr" (default with cmake) */ | ||
2 | 4 | ||
3 | /* required for non Windows builds, must be set in front of the first system include */ | 5 | /* required for non Windows builds, must be set in front of the first system include */ |
4 | #define _GNU_SOURCE | 6 | #define _GNU_SOURCE |
@@ -131,20 +133,11 @@ __declspec(dllimport) int __cdecl atoi(const char *_Str); | |||
131 | #endif | 133 | #endif |
132 | #endif | 134 | #endif |
133 | 135 | ||
134 | #ifdef _WIN32 | ||
135 | #define FailOnWin Fail | ||
136 | #else | ||
137 | #define FailOnWin Pass | ||
138 | #endif | ||
139 | |||
140 | #if defined(_WIN32) && !defined(DLFCN_WIN32_SHARED) | ||
141 | #define PassOnSharedBuild Fail | ||
142 | #else | ||
143 | #define PassOnSharedBuild Pass | ||
144 | #endif | ||
145 | |||
146 | #define UNUSED(x) (void)x | 136 | #define UNUSED(x) (void)x |
147 | 137 | ||
138 | #ifdef _WIN32 | ||
139 | __declspec(dllexport) | ||
140 | #endif | ||
148 | int main(int argc, char **argv) | 141 | int main(int argc, char **argv) |
149 | { | 142 | { |
150 | /* points to non reachable address */ | 143 | /* points to non reachable address */ |
@@ -161,10 +154,10 @@ int main(int argc, char **argv) | |||
161 | 154 | ||
162 | result = check_dladdr( "null pointer", (void*)0, NULL , NoInfo); | 155 | result = check_dladdr( "null pointer", (void*)0, NULL , NoInfo); |
163 | result |= check_dladdr( "invalid pointer", (void*)0x125, NULL , NoInfo); | 156 | result |= check_dladdr( "invalid pointer", (void*)0x125, NULL , NoInfo); |
164 | result |= check_dladdr( "function from dl library", (void*)dladdr, "dladdr" , PassOnSharedBuild ); | 157 | result |= check_dladdr( "function from dl library", (void*)dladdr, "dladdr" , Pass ); |
165 | result |= check_dladdr( "function from dl library", (void*)dlopen, "dlopen", PassOnSharedBuild ); | 158 | result |= check_dladdr( "function from dl library", (void*)dlopen, "dlopen", Pass ); |
166 | result |= check_dladdr( "function from glibc/msvcrt library", (void*)atoi, "atoi", Pass ); | 159 | result |= check_dladdr( "function from glibc/msvcrt library", (void*)atoi, "atoi", Pass ); |
167 | result |= check_dladdr( "function from executable", (void*)main, "main", FailOnWin ); | 160 | result |= check_dladdr( "function from executable", (void*)main, "main", Pass ); |
168 | result |= check_dladdr( "static function from executable", (void*)print_dl_info, "print_dl_info", Fail ); | 161 | result |= check_dladdr( "static function from executable", (void*)print_dl_info, "print_dl_info", Fail ); |
169 | result |= check_dladdr( "address with positive offset", ((char*)atoi)+1, "atoi", PassWithDifferentAddress ); | 162 | result |= check_dladdr( "address with positive offset", ((char*)atoi)+1, "atoi", PassWithDifferentAddress ); |
170 | result |= check_dladdr( "zero address from import thunk", zero_thunk_address, "", NoInfo ); | 163 | result |= check_dladdr( "zero address from import thunk", zero_thunk_address, "", NoInfo ); |