Unlike solaris, this program demonstrates that glibc has issues resolving symbols to data elements. I've tried it with glibc 2.0.7 and 2.1.2, both with and without x being initialized: #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int x=1; int main() { void *handle = dlopen(NULL, RTLD_NOW); int *symbol = (int*)dlsym(handle, "x"); char *errmsg = dlerror(); printf("%d\n", x); if (symbol) printf("%d\n", *symbol); else printf("error: %s\n", errmsg); return 0; }
Actually, it seems unable to locate any local symbols.. main, or if I add another function it can't look up that one either. It seems that dlopen(NULL,blah) is what's broken possibly.
change the sort desc to match the actual bug report
Yepp, this is a bug.
Oops, not really a bug. You need to pass -rdynamic at the link time to have this fucntionality (you need to be able to access your own proram space like a shared object)