gcc main.c -o main ldd main
让
linux-gate.so.1 => (0x00f67000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00b7d000) /lib/ld-linux.so.2 (0x00ae5000)
是否可以更改libc.so.6将在内存中映射的地址?例如,将libc.so.6映射到,例如0xb0000000.
我正在运行Xubuntu 32bit:Linux 3.2.0-23-generic i686 i686 i386 GNU / Linux
解决方法
有关prelink如何工作的一些信息:http://www.acsu.buffalo.edu/~charngda/elf.html
What does this prelink do? It changes the base address of a dynamic library to the actual address in the user program’s address space when it is loaded into memory. Of course,ld.so recognizes GNU_PRELINKED tag and will load a dynamic library to its this base address (recall the first argument of mmap is the preferred address; of course,this is subject to the operating system.)
Normally,a dynamic library is built as position independent code,i.e. the -fPIC compiler command-line option,and thus the base address is 0. For example,a normal libc.so has ELF program header as follows (
readelf -l
command)…
根据man prelink
,有一个prelink实用程序选项可以将给定库重新定位(重定位)到指定的地址:
-r --reloc-only=ADDRESS
Instead of prelinking,just relink given shared libraries to the specified base address.
预链接–reloc-only = 0x7896000 libc.so.6应足以实现您想要的更改.
PS:您可以在本地libc副本上执行此重定位,然后通过export LD_LIBRARY_PATH = / path / to / your / rebased / copy:$LD_LIBRARY_PATH给出它的路径