|
楼主 |
发表于 2009-6-3 23:28:46
|
显示全部楼层
一些资料
http://en.wikipedia.org/wiki/Dynamic_linkerUnix and Unix-likes
On Unix and Unix-like operating systems, the dynamic linker shared libraries vary. Two common ones are ld.so on BSD and ld-linux.so on Linux. These typically change their behaviour based on a common set of environment variables, including LD_LIBRARY_PATH and LD_PRELOAD.
LD_PRELOAD
LD_PRELOAD instructs the loader to load additional libraries into a program, beyond what was specified when it was compiled. It allows users to add or replace functionality when they run a program and can be used for beneficial purposes, such as implementing userspace virtual file systems or debuggers, or malicious purposes, to run code the program authors didn't intend. For this reason, LD_PRELOAD is often ignored when a program is running setuid and under a few other circumstances. More generally, this technique is called DLL injection.
Examples of programs using LD_PRELOAD: authbind, IPv6 CARE, fakeroot.
http://www.linuxsir.cn/bbs/post264482-16.html 7.为应用程序提供动态转载服务。
环境变量LD_PRELOAD设置共享库名或者用":"把文件名隔开。动态连接器在
任何那些请求的共享库之前把环境变量LD_PRELOAD的共享库装载到进程地址
空间去。例如:
# LD_PRELOAD=./mylibc.so myprog
这里./mylibc.so将第一时间map到程序myprog的空间。因为动态连接器在找
寻标号的时候总是使用第一次碰到的标号,所以我们可以使用LD_PRELOAD来
覆盖标准共享库中的函数。这个特性对程序员来说是很有用的,可用来在还
没有建好整个共享库的时候对单个函数功能先做调试实验。
我们可以这样:
#gcc -c -fPIC -O3 print.c
#gcc -shared print.o -o print.so.1.0
创建自己的共享连接库 |
|