Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are __stat & __fstat linked statically?

Tags:

glibc

I'm monkeying around with LD_PRELOAD to wrap libc functions for call tracking purposes. Everything has been going swell until I attempted to wrap __stat and __fstat. It appears these two functions are statically linked, unlike open, fdopen, etc which are dynamically linked (and thus wrap able).

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

Bonus points if you can answer: How can I wrap __stat & __fstat calls?

Thanks!

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.
like image 566
Matt McCann Avatar asked Nov 07 '22 18:11

Matt McCann


1 Answers

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

This answer explains why that is the case.

You'll need to wrap __xstat instead.

like image 60
Employed Russian Avatar answered Dec 09 '22 09:12

Employed Russian