5

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.
Matt McCann
  • 315
  • 3
  • 8
  • Possible duplicate of [Moving to different Linux build system, getting error: undefined symbol: stat](https://stackoverflow.com/questions/44294173/moving-to-different-linux-build-system-getting-error-undefined-symbol-stat) – user207421 Aug 12 '17 at 02:58

1 Answers1

1

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362