21 May 2013 14:06
why the DSO was loaded at address 0
There is a simple test program,it dlopen()s a DSO "/lib/libc.so.6" and
then prints the address of symbol "printf".
#include <dlfcn.h>
#include <stdio.h>
int main() {
void* handle;
void (*func)();
char* error_test;
if (handle = dlopen("/lib/libc.so.6", RTLD_NOW)) {
func = dlsym(handle, "printf");
(*func)("address:%p\n",func);
sleep(-1);
dlclose(handle);
return 0;
}
return -1;
}
When I debug it with "LD_DEBUG=all",it shows that:
[root <at> localhost glibc_test]# LD_DEBUG=all LD_DEBUG_OUTPUT=error ./test &
[18] 14690
[root <at> localhost glibc_test]# address:0x2f87b0
But the file "error" shows that "/lib/libc.so.6" was loaded to address
0! That`s why?
14690: initialize program: ./test
14690:
(Continue reading)
RSS Feed