This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

overloading symbols in glibc-2.2.3


A year ago I wrote a small wrapper for gettimeofday() to add a
constant time offset.  I did this as follows

    int gettimeofday(struct timeval *tv, struct timezone *tz)
    {
    	if (__gettimeofday(tv, tz) < 0)
    	    return -1;
    	tv->tv_sec += warp;
    	return 0;
    }

This works, because

    $ nm /lib/libc.so.6 |grep gettimeofday  
    0009b170 T __gettimeofday
    0009b170 W gettimeofday

Now I wanted to do the same with uname() but there seems not to be an
__uname() I can call, since that is not a global symbol:

    $ nm /lib/libc.so.6 |grep uname
    000a6330 t __uname
    000a6330 W uname

And there are other syscalls, where both symbols (with and without the
__) are weak and global and where there is an additional symbol
prefixed by __libc_:

    $ nm /lib/libc.so.6 |egrep -w "(__|__libc_)?(open|read|close)"|sort
    000c3ea0 T __libc_open
    000c3ea0 W __open
    000c3ea0 W open
    000c3f20 T __libc_close
    000c3f20 W __close
    000c3f20 W close
    000c3f60 T __libc_read
    000c3f60 W __read
    000c3f60 W read

For time() and stime() however there is only one strong and global
symbol:

    $ nm /lib/libc.so.6 |egrep -w "stime|time"
    0009d2c0 T stime
    0009b120 T time

What is the reason for these differences?  Is that intended?  I
thought the main purpose of a weak symbols is that they can be
overridden in my application without the linker generating an
"multiple defined symbol" error message.  And the purpose of having
the __ prefixed symbols is that I can access the original function
that I have overridden, like I have done with gettimeofday() above.
But what is then the purpose of a local symbol like __uname() which I
can't access?

Another question: I have tried to override time() as I have done with
gettimeofday() in the example above.  To my surprise it works, even
from a shared object loaded with LD_PRELOAD, although the time() in
glibc is not weak.  Why are weak symbols then needed?


urs


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]