Why are __stat & __fstat linked statically?

I am wrapping up with LD_PRELOAD to wrap libc functions for call tracking purposes. Everything was coming until I tried to wrap __stat and __fstat. It seems that these two functions are statically connected, unlike open, fdopen, etc., which are dynamically connected (and thus are wrapped).

I would like to understand: why is this so?

Bonus points if you can answer: how can I wrap __stat and __fstat calls?

Thank!

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.
+4
source share
1 answer

I would like to understand: why is this so?

This answer explains why this is so.

Instead, you need to wrap __xstat.

+1
source

Source: https://habr.com/ru/post/1683467/


All Articles