Mail Archives: cygwin/2010/02/04/03:29:50
--------------030309040508080500070806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Per POSIX:
"""The dlsym() function shall search for the named symbol in all objects
loaded automatically as a result of loading the object referenced by
handle (see dlopen )."""
With the relevant part of dlopen() saying:
"""Note that some implementations permit the construction of
dependencies between such objects that are embedded within files. In
such cases, a dlopen() operation shall load such dependencies in
addition to the object referenced by file."""
IOW, when the target of dlopen() has linked dependencies, not only shall
those dependencies must also be loaded by dlopen() but the symbols
therein found by dlsym(). On Cygwin, by the nature of PE/COFF the
dependencies are loaded, but dlsym() does not search their symbols.
Attached is a STC:
# on Cygwin:
$ gcc -Wl,--export-all-symbols -o dlsym-test.exe dlsym-test.c
$ ./dlsym-test.exe
I can dlopen() myself...
and I can dlsym() myself...
but I can't dlsym() my deps.
# on Linux:
$ gcc -Wl,--export-dynamic -o dlsym-test dlsym-test.c -ldl
$ ./dlsym-test
I can dlopen() myself...
and I can dlsym() myself...
but I can dlsym() my deps!
I have encountered several real-world cases which depends on this behaviour.
TIA,
Yaakov
--------------030309040508080500070806
Content-Type: text/plain;
name="dlsym-test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="dlsym-test.c"
/*
* dlsym() dependencies test
*
* On Cygwin, compile with:
* gcc -Wl,--export-all-symbols -o dlsym-test.exe dlsym-test.c
*
* On Linux, compile with:
* gcc -Wl,--export-dynamic -o dlsym-test dlsym-test.c -ldl
*
*/
#include <dlfcn.h>
#include <stdio.h>
void
foo() {
printf("foo\n");
}
int
main() {
void *self;
self = dlopen(NULL, RTLD_LAZY);
if (self) {
printf("I can dlopen() myself...\n");
} else {
printf("Sorry, I can't dlopen() myself.\n");
return 2;
}
if (dlsym(self, "foo")) {
printf("and I can dlsym() myself...\n");
} else {
printf("but I can't dlsym() myself.\n");
return 1;
}
if (dlsym(self, "dlclose")) {
printf("and I can dlsym() my deps!\n");
} else {
printf("but I can't dlsym() my deps.\n");
}
return 0;
}
--------------030309040508080500070806
Content-Type: text/plain; charset=us-ascii
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
--------------030309040508080500070806--
- Raw text -