0
有一个简单的测试程序,它将dlopen()作为DSO“/lib/libc.so.6”,然后打印符号“printf”的地址。为什么DSO被加载到地址0
#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;
}
当我与 “LD_DEBUG =所有” 调试它,它表明:
[[email protected] glibc_test]# LD_DEBUG=all LD_DEBUG_OUTPUT=error ./test &
[18] 14690
[[email protected] glibc_test]# address:0x2f87b0
但文件 “错误” 显示, “/lib/libc.so.6” 被加载到地址0!那是为什么?
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] to /changed_glibc/lib/libdl.so.2 [0]: normal symbol `dlopen' [GLIBC_2.1]
14690:
14690: file=/lib/libc.so.6 [0]; needed by ./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
什么`以上,则 “/ PROC/14270 /地图” 的文件进行正常的,而符号 “FUNC” 的地址(0x2f87b0)在测试程序中位于右范围(002af000-0043b000)。
[[email protected] ~]# 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