之前文章讲过 使用 ld_preload 来实现函数替换
$ arm--linux-gnu-ar x libc.a malloc.o
$ arm-linux-gnu-objcopy -W malloc malloc.o
$ arm--linux-gnu-objcopy -W realloc malloc.o
$ arm--linux-gnu-objcopy -W free malloc.o
$ arm--linux-gnu-ar r libc.a malloc.o
这样的代码里malloc 同名函数就会被使用, libc 原生malloc 就被替换了
objcopy --redefine-sym test1=test2 test.o new_test.o
--redefine-sym old=new Change the name of a symbol old, to new. This can be useful when one is trying link two things together for which you have no source, and there are name collisions. --redefine-syms=filename Apply --redefine-sym to each symbol pair "old new" listed in the file filename. filename is simply a flat file, with one symbol pair per line. Line comments may be introduced by the hash character. This option may be given more than once. |