【发布时间】:2017-08-10 19:28:44
【问题描述】:
我正在使用 LD_PRELOAD 来包装 libc 函数以进行呼叫跟踪。在我尝试包装 __stat 和 __fstat 之前,一切都很顺利。看起来这两个函数是静态链接的,不像 open、fdopen 等是动态链接的(因此可以包装)。
我很想了解:为什么会这样?
如果你能回答,加分:如何包装 __stat 和 __fstat 调用?
谢谢!
matt@matt-laptop:~/code/test$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/libc_wrapper_lib/libc_wrapper.os -c -D_GNU_SOURCE -D_REENTRANT -std=gnu++11 -g -fPIC build/libc_wrapper_lib/libc_wrapper.cpp
g++ -o lib/libc_wrapper.so -nostartfiles -fPIC -pthread -shared build/libc_wrapper_lib/libc_wrapper.os -ldl
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(stat.oS): In function `__stat':
(.text+0x0): multiple definition of `__stat'
build/libc_wrapper_lib/libc_wrapper.os:/home/matt/code/test/build/libc_wrapper_lib/libc_wrapper.cpp:252: first defined here
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(fstat.oS): In function `__fstat':
(.text+0x0): multiple definition of `__fstat'
build/libc_wrapper_lib/libc_wrapper.os:/home/matt/code/test/build/libc_wrapper_lib/libc_wrapper.cpp:283: first defined here
collect2: error: ld returned 1 exit status
scons: *** [lib/libc_wrapper.so] Error 1
scons: building terminated because of errors.
【问题讨论】:
标签: glibc