From owner-freebsd-hackers Tue Nov 17 08:39:04 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA02737 for freebsd-hackers-outgoing; Tue, 17 Nov 1998 08:39:04 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ns.mt.sri.com (sri-gw.MT.net [206.127.105.141]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA02732 for ; Tue, 17 Nov 1998 08:39:03 -0800 (PST) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id JAA22434; Tue, 17 Nov 1998 09:38:38 -0700 (MST) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id JAA24053; Tue, 17 Nov 1998 09:38:37 -0700 Date: Tue, 17 Nov 1998 09:38:37 -0700 Message-Id: <199811171638.JAA24053@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Thomas David Rivers Cc: hackers@FreeBSD.ORG, nate@mt.sri.com Subject: Re: Wrapping a function In-Reply-To: <199811171348.IAA11670@lakes.dignus.com> References: <199811170517.WAA22627@mt.sri.com> <199811171348.IAA11670@lakes.dignus.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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