bug-hurd
[Top][All Lists]
Advanced

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

Help with weak symbols needed (gcc question).


From: Farid Hajji
Subject: Help with weak symbols needed (gcc question).
Date: Mon, 23 Jul 2001 04:07:57 +0200

[Sorry, this is not _directly_ a Hurd-related question, but you may
already know the answer. If it's a FAQ, I've missed it. This question
is however related to hacking on the Hurd, so it's not completely
off-topic. ;)]

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.

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;
}

There is probably some gcc macro or hook to do it, but I couldn't find
any hint in the docs. Simply renaming the wrappers or changing glibc
would _not_ be a solution neither is copy-and-pasting the glibc code
of the wrapped functions in the new wrapping functions (too many of
them would need to be intercepted). If at all possible, the solution
should work with gcc, but not be tied to glibc too much (i.e. general
ELF libraries with weak symbols should work as well).

Any ideas?

Thanks,

-Farid.

-- 
Farid Hajji -- Unix Systems and Network Admin | Phone: +49-2131-67-555
Broicherdorfstr. 83, D-41564 Kaarst, Germany  | farid.hajji@ob.kamp.net
- - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - -
One OS To Rule Them All And In The Darkness Bind Them... --Bill Gates.




reply via email to

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