2017-08-10 24 views
4

私は、LD_PRELOADを使用してコールトラッキングの目的でlibc関数をラッピングすることに夢中になっています。 __statと__fstatをラップしようとするまで、すべてが盛り上がりました。これらの2つの関数は、open、fdopenなどとは異なり、静的にリンクされており、動的にリンクされている(したがってラッピング可能である)ようです。__statと__fstatは静的にリンクされているのはなぜですか?

私は理解したいと思う:これはなぜですか?

あなたが答えることができる場合のボーナスポイント:__statを__statにするにはどうすればいいですか?& __fstatコール?

ありがとうございます!それが事実である理由

[email protected]:~/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. 
+0

[別のLinuxビルドシステムに移動すると、エラーが発生する:undefined symbol:stat](https://stackoverflow.com/questions/44294173/moving-to-different-linux-build-system-getting-error)の可能な複製-undefined-symbol-stat) – EJP

答えて

1

I would love to understand: Why this is the case?

このanswerは説明しています。

代わりに__xstatをラップする必要があります。

関連する問題