Mercurial > pub > dyncall > dyncall
comparison test/dynload_plain/dynload_plain.c @ 272:a94a9a83dae6
- dynload_plain test handling symbol aliases, now
- removed some hardcoded libc.so paths in dynload_plain, and pushed deduction logic to build instead
author | Tassilo Philipp |
---|---|
date | Fri, 29 Dec 2017 21:19:07 +0100 |
parents | 9d70178c1ded |
children | f5577f6bf97a |
comparison
equal
deleted
inserted
replaced
271:aa0d2536a4eb | 272:a94a9a83dae6 |
---|---|
41 int r = 0, i; | 41 int r = 0, i; |
42 void* p; | 42 void* p; |
43 DLLib* pLib; | 43 DLLib* pLib; |
44 DLSyms* pSyms; | 44 DLSyms* pSyms; |
45 const char* path = NULL; | 45 const char* path = NULL; |
46 const char* clibs[] = { /* hacky/lazy list of some clib paths per platform */ | 46 /* hacky/lazy list of some clib paths per platform - more/others, like version-suffixed ones */ |
47 /* can be specified in Makefile; this avoids trying to write portable directory traversal stuff */ | |
48 const char* clibs[] = { | |
49 #if defined(DEF_C_DYLIB) | |
50 DEF_C_DYLIB, | |
51 #endif | |
47 "/lib/libc.so", | 52 "/lib/libc.so", |
48 "/lib/libc.so.0.1", | 53 "/lib32/libc.so", |
49 "/lib/libc.so.6", | |
50 "/lib/libc.so.7", | |
51 "/lib64/libc.so", | 54 "/lib64/libc.so", |
52 "/lib64/libc.so.6", | |
53 "/lib64/libc.so.7", | |
54 "/lib32/libc.so", | |
55 "/lib32/libc.so.6", | |
56 "/lib32/libc.so.7", | |
57 "/usr/lib/libc.so", | 55 "/usr/lib/libc.so", |
58 "/usr/lib/libc.so.6", | 56 "/usr/lib/system/libsystem_c.dylib", /* macos */ |
59 "/usr/lib/libc.so.7", | |
60 "/usr/lib/libc.so.39.3", /* hack: for OpenBSD used in dyncall test env */ | |
61 "/usr/lib/system/libsystem_c.dylib", | |
62 "/usr/lib/libc.dylib", | 57 "/usr/lib/libc.dylib", |
63 "/boot/system/lib/libroot.so", /* Haiku */ | 58 "/boot/system/lib/libroot.so", /* Haiku */ |
64 "\\ReactOS\\system32\\msvcrt.dll", | 59 "\\ReactOS\\system32\\msvcrt.dll", /* ReactOS */ |
65 "C:\\ReactOS\\system32\\msvcrt.dll", | 60 "C:\\ReactOS\\system32\\msvcrt.dll", |
66 "\\Windows\\system32\\msvcrt.dll", | 61 "\\Windows\\system32\\msvcrt.dll", /* Windows */ |
67 "C:\\Windows\\system32\\msvcrt.dll" | 62 "C:\\Windows\\system32\\msvcrt.dll" |
68 }; | 63 }; |
69 | 64 |
70 | 65 /* use first matching path of hacky hardcoded list, above */ |
71 for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) { | 66 for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) { |
72 if(access(clibs[i], F_OK) != -1) { | 67 if(access(clibs[i], F_OK) != -1) { |
73 path = clibs[i]; | 68 path = clibs[i]; |
74 break; | 69 break; |
75 } | 70 } |
99 int b; | 94 int b; |
100 printf("path of lib looked up via handle: %s\n", queriedPath); | 95 printf("path of lib looked up via handle: %s\n", queriedPath); |
101 b = (stat(path, &st0) != -1) && (stat(queriedPath, &st1) != -1); | 96 b = (stat(path, &st0) != -1) && (stat(queriedPath, &st1) != -1); |
102 printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?st0.st_ino:-1, b?st1.st_ino:-1, b && (st0.st_ino == st1.st_ino)); //@@@ on windows, inode numbers returned here are always 0 | 97 printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?st0.st_ino:-1, b?st1.st_ino:-1, b && (st0.st_ino == st1.st_ino)); //@@@ on windows, inode numbers returned here are always 0 |
103 r += b && (st0.st_ino == st1.st_ino); /* compare if same lib using inode */ | 98 r += b && (st0.st_ino == st1.st_ino); /* compare if same lib using inode */ |
104 /*@@@ check of resolved path is absolute*/ | 99 /*@@@ check if resolved path is absolute*/ |
105 | 100 |
106 /* check correct bufsize retval */ | 101 /* check correct bufsize retval */ |
107 b = (bs == strlen(queriedPath) + 1); | 102 b = (bs == strlen(queriedPath) + 1); |
108 printf("looked up path's needed buffer size (%d) computed correctly: %d\n", bs, b); | 103 printf("looked up path's needed buffer size (%d) computed correctly: %d\n", bs, b); |
109 r += b; | 104 r += b; |
147 pLib = dlLoadLibrary(path); /* check if we can resolve ptr -> name, */ | 142 pLib = dlLoadLibrary(path); /* check if we can resolve ptr -> name, */ |
148 if(pLib) { /* need to lookup by name again, first */ | 143 if(pLib) { /* need to lookup by name again, first */ |
149 p = dlFindSymbol(pLib, "printf"); | 144 p = dlFindSymbol(pLib, "printf"); |
150 name = dlSymsNameFromValue(pSyms, p); | 145 name = dlSymsNameFromValue(pSyms, p); |
151 printf("printf symbol name by its own address (%p): %s\n", p, name?name:""); | 146 printf("printf symbol name by its own address (%p): %s\n", p, name?name:""); |
152 r += (name && strcmp(name, "printf") == 0); | 147 if(name) { |
148 if(strcmp(name, "printf") == 0) | |
149 ++r; | |
150 else { | |
151 /* Symbol name returned might be an "alias". In that case, check address again (full lookup to be sure). */ | |
152 void* p0 = dlFindSymbol(pLib, name); | |
153 printf("lookup by address returned different name (%s), which is alias of printf: %d\n", name, (p==p0)); | |
154 r += (p == p0); | |
155 } | |
156 } | |
153 dlFreeLibrary(pLib); | 157 dlFreeLibrary(pLib); |
154 } | 158 } |
155 | 159 |
156 dlSymsCleanup(pSyms); | 160 dlSymsCleanup(pSyms); |
157 } | 161 } |