loader - why the DSO was loaded at address 0 -
there simple test program,it dlopen()s dso "/lib/libc.so.6" , print 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 debug "ld_debug=all",it shows that:
[root@localhost glibc_test]# ld_debug=all ld_debug_output=error ./test & [18] 14690 [root@localhost glibc_test]# address:0x2f87b0
but file "error" shows "/lib/libc.so.6" loaded address 0! that`s why?
14690: initialize program: ./test 14690: 14690: 14690: transferring control: ./test 14690: 14690: symbol=dlopen; lookup in file=./test [0] 14690: symbol=dlopen; lookup in file=/changed_glibc/lib/libdl.so.2 [0] 14690: binding file ./test [0] /changed_glibc/lib/libdl.so.2 [0]: normal symbol `dlopen' [glibc_2.1] 14690: 14690: file=/lib/libc.so.6 [0]; needed ./test [0] 14690: file=/lib/libc.so.6 [0]; generating link map 14690: dynamic: 0x0043cd7c base: 0x00000000 size: 0x00191988 14690: entry: 0x002c5e40 phdr: 0x002af034 phnum: 10
what`s more,the "/proc/14270/maps" file perform normal,and address of symbol "func"(0x2f87b0) in test program lies in right range(002af000-0043b000).
[root@localhost ~]# cat /proc/14690/maps 002af000-0043b000 r-xp 00000000 fd:00 1714117 /lib/libc-2.12.so 0043b000-0043d000 r--p 0018c000 fd:00 1714117 /lib/libc-2.12.so 0043d000-0043e000 rw-p 0018e000 fd:00 1714117 /lib/libc-2.12.so 0043e000-00441000 rw-p 00000000 00:00 0
the issue related "prelink",when dso loading, has been prelinked address.
Comments
Post a Comment