Re: LD_PRELOAD odd woes

From: Drago (Drago_at_mailinator.com)
Date: 11/11/04


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, ...).
>
> Cheers,

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.

Much oblidged,
Drago



Relevant Pages

  • Re: Calling free() from libc library
    ... Paul Pluzhnikov wrote: ... >>Now how could I call the version provided in the libc that came with the OS? ... This returned pointer to my overridden free:^) ... extern "C" { ...
    (comp.os.linux.development.apps)
  • Re: Using dlsym for symbols contained in the executable itself
    ... Paul Pluzhnikov wrote: ... dlsym() finds symbols that are in the "dynamic ... You'll find out that PrintAnInt() is not in the dynamic symbol table. ... This is because main executables symbols are not ...
    (comp.unix.programmer)
  • dlsym() in libc vs libdl
    ... On my S10 U-something system, dlsymis defined in both libc and ... say anything about linking with libdl, and on my system it works ... But my software has a reported bug whose symptom indicates that dlsym() ...
    (comp.unix.solaris)
  • Re: relocation error: undefined symbol: stat
    ... Paul Pluzhnikov wrote: ... >> I do not for one moment believe your libc doesn't provide stat. ... But that should still show up in the grep, ...
    (comp.os.linux.development.apps)