[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with weak symbols needed (gcc question).

From: Igor Khavkine
Subject: Re: Help with weak symbols needed (gcc question).
Date: Sun, 22 Jul 2001 23:19:19 -0400
User-agent: Mutt/1.3.18i

On Mon, Jul 23, 2001 at 04:07:57AM +0200, Farid Hajji wrote:
> What is the "official" way to wrap library (e.g. glibc) functions with
> user-defined code, without fiddling in the glibc sources themselves?
> As far as I understand it, (most) glibc functions are declared to be
> "weak symbols", so that they can be overridden by simply redefining
> them in user-code. gcc would be so smart as to reference the
> user-defined code instead of the weak symbol.

I'm not sure there is an automatic way of doing this. But practical
experience suggests that most of these "weak symbols" are declared
in the following way:
weak_alias (__foo, foo)
So all you need to do is call __foo() from your user defined foo()
function and that should work (in most cases). I think that's the
simplest solution you can come up with.

> So far, so good. Now, I want to call the original glibc function inside
> the wrapper. How do I get to the old symbol, if I used the same name
> for the wrapper function?
> Here's an example:
> /* somewhere in the code... */
> time_t now = time(NULL);
> /* somewhere else, in the same or in a different file... */
> #include <time.h>
> time_t
> time(time_t *t)
> {
>   time_t realtime;
>   do_preprocessing();
>   realtime = <????>(t); /* wanting to call original/weak time() here... */
>   do_postprocessing();
>   return realtime;
> }

So just replace <????>(t) by __time(t) here.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]