Article View: gnu.utils.bug
Article #72Re: ld question
From: sac
Date: Tue, 03 Nov 1992 06:40
Date: Tue, 03 Nov 1992 06:40
66 lines
1970 bytes
1970 bytes
>
>I have been looking at the documentation for ld 2.0 and it would appear
>that a fairly powerful command language comes with this linker. This has me
>to wondering whether the question of remapping (not an accurate term, but
>it will do for now) of library/system calls in a fairly portable manner is
>possible using gld.
>
>Basically what I want to do is create and link in a routine called, say,
>my_read() which would be called in place of *any and all* calls (including
>libc calls!) to the real read(). The tricky part is that my_read() will
>at some point be calling the real read().
>
>Any info/tips/advice greatly appreciated.
Ok, no problem:
Just link thus:
ld -defsym _real_read=_read -defsym _read=_my_read ...
Here's an example on the sparc:
sac@thepub$ cat e.c
read()
{
printf("read called\n");
}
sac@thepub$ cat r.c
my_read ()
{
printf("my read called\n");
real_read ();
printf("my read done\n");
}
sac@thepub$ cat t.c
main ()
{
printf("calling read\n");
read ();
printf("done\n");
return 0;
}
sac@thepub$ cc -c t.c r.c e.c
t.c:
r.c:
e.c:
sac@thepub$ ld -o foo -defsym _real_read=_read -defsym _read=_my_read /lib/crt0.o e.o r.o t.o -lc
ld -o foo -defsym _real_read=_read -defsym _read=_my_read /lib/crt0.o e.o r.o t.o -lc
sac@thepub$ ./foo
calling read
my read called
read called
my read done
done
Steve
Technical Details
Message-ID:
<9211032240.AA19461@thepub.cygnus.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!sacReferences:
<9211032219.AA13597@cygnus.com>Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!sac From: sac@cygnus.com Subject: Re: ld question Message-ID: <9211032240.AA19461@thepub.cygnus.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet References: <9211032219.AA13597@cygnus.com> Distribution: gnu Date: Tue, 3 Nov 1992 06:40:24 GMT Approved: bug-gnu-utils@prep.ai.mit.edu Lines: 68