Date: Tue, 17 Nov 1998 09:38:37 -0700 From: Nate Williams <nate@mt.sri.com> To: Thomas David Rivers <rivers@dignus.com> Cc: hackers@FreeBSD.ORG, nate@mt.sri.com Subject: Re: Wrapping a function Message-ID: <199811171638.JAA24053@mt.sri.com> In-Reply-To: <199811171348.IAA11670@lakes.dignus.com> References: <199811170517.WAA22627@mt.sri.com> <199811171348.IAA11670@lakes.dignus.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> > Does anyone have an easy way of 'wrapping' an already existing library > > function so that any programs linked against your .o will call your > > function, but so your function can call the 'real' library function? > > > > Example: > > > > my_malloc.c: > > > > void *malloc(size_t size) > > { > > void *ret; > > > > printf("Calling malloc\n"); > > ret = REALMALLOC(size); > > printf("Leaving malloc\n"); > > return ret; > > } > > > > I don't know about our linker (gnu-ld) - but many UNIX linkers (and other > systems as well) have a way to re-name identifiers. > > The standard trick would be to pre-link the malloc code from the library; > renaming the malloc entry there - to say, MALLOC. (ld -r is how you > prelink.) > > Then, you can link your code with that. Unfortunately, the symbol exists in a shlib, so it must use the same symbol name as the library since sometimes the shlib exists, and other times it doesn't. :( (Don't ask, it's not my code but the JDK. They get around this problem in Solaris by being aware that dlsym happens to be a simple C function that calls _dlsym, so in the JDK they call _dlsym directly and hope no-one else is aware of this feature.) Sounds like I'll just not be able to wrap those functions. :( Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811171638.JAA24053>