aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dladdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-dladdr.c')
-rw-r--r--tests/test-dladdr.c23
1 files changed, 8 insertions, 15 deletions
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
148int main(int argc, char **argv) 141int 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 );