Re: LD_PRELOAD odd woes
From: Drago (Drago_at_mailinator.com)
Date: Wed, 10 Nov 2004 20:51:27 -0600
Paul Pluzhnikov wrote:
> One problem is that you are probably getting the "wrong" fopen().
> There are at least 2 fopen()s in libc:
> $ nm -n /lib/libc.so.6 | grep ' fopen[^a-z0-9]'
> 00052820 T fopen@@GLIBC_2.1
> 00054da0 T fopen@GLIBC_2.0
> There is a high chance that 'dlsym(..., "fopen")' returns you the "old"
> fopen(), when your program needs the "new" one (to match e.g. fclose(),
> which also has 2 different versions).
> Which version you actually get from dlsym() depends on your version
> of glibc :-( You can work around this problem by using dlvsym() instead.
> The second problem with your approach is that /lib/libc.so.6 may
> not be the right libc. On modern systems, /usr/tls/libc.so.6 or
> /usr/i686/libc.so.6 may be more correct. You can fix this problem
> by using dlsym(RTLD_NEXT, ...).
Thanks, that worked like a champ. Appears RTLD_NEXT is a more portable
approach. I didn't like hardwiring the shared library, but that was an
example I saw. Also, on my system, dlvsym is not even in the man pages,
although nm says it's there.