xref: /titanic_41/usr/src/cmd/sgs/ldprof/common/profile.c (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
502ca3e02Srie  * Common Development and Distribution License (the "License").
602ca3e02Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*2020b2b6SRod Evans  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257257d1b4Sraf 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Routines to provide profiling of shared libraries required by the called
287c478bd9Sstevel@tonic-gate  * executable.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <fcntl.h>
327c478bd9Sstevel@tonic-gate #include <sys/mman.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/stat.h>
387c478bd9Sstevel@tonic-gate #include <synch.h>
397c478bd9Sstevel@tonic-gate #include <signal.h>
407c478bd9Sstevel@tonic-gate #include <synch.h>
417c478bd9Sstevel@tonic-gate #include <link.h>
427257d1b4Sraf #include <libintl.h>
437c478bd9Sstevel@tonic-gate #include <sys/param.h>
447c478bd9Sstevel@tonic-gate #include <procfs.h>
457c478bd9Sstevel@tonic-gate #include "msg.h"
467c478bd9Sstevel@tonic-gate #include "sgs.h"
477c478bd9Sstevel@tonic-gate #include "profile.h"
487c478bd9Sstevel@tonic-gate #include "_rtld.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate static char	Profile[MAXPATHLEN];	/* Profile buffer pathname */
527c478bd9Sstevel@tonic-gate static char	*pname = 0;		/* name of object to profile */
537c478bd9Sstevel@tonic-gate static L_hdr	*Hptr;			/* profile buffer header pointer */
547c478bd9Sstevel@tonic-gate static L_cgarc	*Cptr;			/* profile buffer call graph pointer */
557c478bd9Sstevel@tonic-gate static caddr_t	Hpc, Lpc;		/* Range of addresses being monitored */
567c478bd9Sstevel@tonic-gate static size_t	Fsize;			/* Size of mapped in profile buffer */
577c478bd9Sstevel@tonic-gate uintptr_t	profcookie = 0;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * When handling mutex's locally we need to mask signals.  The signal
617c478bd9Sstevel@tonic-gate  * mask is for everything except SIGWAITING.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate static const sigset_t	iset = { ~0U, ~0U, ~0U, ~0U };
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static lwp_mutex_t sharedmutex = SHAREDMUTEX;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static int
prof_mutex_init(lwp_mutex_t * mp)687c478bd9Sstevel@tonic-gate prof_mutex_init(lwp_mutex_t *mp)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	(void) memcpy(mp, &sharedmutex, sizeof (lwp_mutex_t));
717c478bd9Sstevel@tonic-gate 	return (0);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate static int
prof_mutex_lock(lwp_mutex_t * mp,sigset_t * oset)757c478bd9Sstevel@tonic-gate prof_mutex_lock(lwp_mutex_t *mp, sigset_t *oset)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	if (oset)
787c478bd9Sstevel@tonic-gate 		(void) sigprocmask(SIG_BLOCK, &iset, oset);
797c478bd9Sstevel@tonic-gate 	(void) _lwp_mutex_lock(mp);
807c478bd9Sstevel@tonic-gate 	return (0);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static int
prof_mutex_unlock(mutex_t * mp,sigset_t * oset)847c478bd9Sstevel@tonic-gate prof_mutex_unlock(mutex_t *mp, sigset_t *oset)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	(void) _lwp_mutex_unlock(mp);
877c478bd9Sstevel@tonic-gate 	if (oset)
887c478bd9Sstevel@tonic-gate 		(void) sigprocmask(SIG_SETMASK, oset, NULL);
897c478bd9Sstevel@tonic-gate 	return (0);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate const char *
_ldprof_msg(Msg mid)937c478bd9Sstevel@tonic-gate _ldprof_msg(Msg mid)
947c478bd9Sstevel@tonic-gate {
957257d1b4Sraf 	return (dgettext(MSG_ORIG(MSG_SUNW_OST_SGS), MSG_ORIG(mid)));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * Determine whether a set (of arbitrary size) is in use - used to analyze proc
1007c478bd9Sstevel@tonic-gate  * status information.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate static int
setisinuse(uint32_t * sp,uint_t n)1037c478bd9Sstevel@tonic-gate setisinuse(uint32_t *sp, uint_t n)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	while (n--)
1067c478bd9Sstevel@tonic-gate 		if (*sp++)
1077c478bd9Sstevel@tonic-gate 			return (1);
1087c478bd9Sstevel@tonic-gate 	return (0);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #define	prisinuse(sp) \
1127c478bd9Sstevel@tonic-gate 		setisinuse((uint32_t *)(sp), \
1137c478bd9Sstevel@tonic-gate 		    (uint_t)(sizeof (*(sp)) / sizeof (uint32_t)))
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate uint_t
la_version(uint_t version)1167c478bd9Sstevel@tonic-gate la_version(uint_t version)
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate 	int		fd;
1197c478bd9Sstevel@tonic-gate 	ssize_t		num;
1207c478bd9Sstevel@tonic-gate 	pstatus_t	status;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	if (version < LAV_CURRENT) {
1237c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_GEN_AUDITVERSION),
1247c478bd9Sstevel@tonic-gate 		    LAV_CURRENT, version);
1257c478bd9Sstevel@tonic-gate 		return (LAV_CURRENT);
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	/*
1297c478bd9Sstevel@tonic-gate 	 * To reduce the potential for deadlock conditions that can arise from
1307c478bd9Sstevel@tonic-gate 	 * being monitored (say by truss(1)) while setting a lock in the profile
1317c478bd9Sstevel@tonic-gate 	 * buffer, determine if someone is monitoring us.  If so silently
1327c478bd9Sstevel@tonic-gate 	 * disable profiling.
1337c478bd9Sstevel@tonic-gate 	 */
1347c478bd9Sstevel@tonic-gate 	if ((fd = open(MSG_ORIG(MSG_FMT_PROCSELF), O_RDONLY)) < 0)
1357c478bd9Sstevel@tonic-gate 		return (LAV_CURRENT);
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	num = read(fd, &status, sizeof (status));
1387c478bd9Sstevel@tonic-gate 	(void) close(fd);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if ((num != sizeof (status)) ||
1417c478bd9Sstevel@tonic-gate 	    prisinuse(&status.pr_sigtrace) || prisinuse(&status.pr_flttrace) ||
1427c478bd9Sstevel@tonic-gate 	    prisinuse(&status.pr_sysentry) || prisinuse(&status.pr_sysexit)) {
1437c478bd9Sstevel@tonic-gate 		return (LAV_CURRENT);
1447c478bd9Sstevel@tonic-gate 	}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	/*
1477c478bd9Sstevel@tonic-gate 	 * We're presently not being monitored (although there's no control of
1487c478bd9Sstevel@tonic-gate 	 * someone attaching to us later), so retrieve the profile target name.
1497c478bd9Sstevel@tonic-gate 	 */
1507c478bd9Sstevel@tonic-gate 	if (dlinfo((void *)NULL, RTLD_DI_PROFILENAME, &pname) == -1)
1517c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,  MSG_INTL(MSG_GEN_PROFNOTSET));
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	return (LAV_CURRENT);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate int
profile_open(const char * fname,Link_map * lmp)1587c478bd9Sstevel@tonic-gate profile_open(const char *fname, Link_map *lmp)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	size_t		hsize;		/* struct hdr size */
1617c478bd9Sstevel@tonic-gate 	size_t		psize;		/* profile histogram size */
1627c478bd9Sstevel@tonic-gate 	size_t		csize;		/* call graph array size */
1637c478bd9Sstevel@tonic-gate 	size_t		msize;		/* size of memory being profiled */
1647c478bd9Sstevel@tonic-gate 	int		i, fd, fixed = 0;
1657c478bd9Sstevel@tonic-gate 	caddr_t		lpc;
1667c478bd9Sstevel@tonic-gate 	caddr_t		hpc;
1677c478bd9Sstevel@tonic-gate 	caddr_t		addr;
1687c478bd9Sstevel@tonic-gate 	struct stat	status;
1697c478bd9Sstevel@tonic-gate 	int		new_buffer = 0;
1707c478bd9Sstevel@tonic-gate 	sigset_t	mask;
1717c478bd9Sstevel@tonic-gate 	int		err;
1727c478bd9Sstevel@tonic-gate 	Ehdr *		ehdr;		/* ELF header for file */
1737c478bd9Sstevel@tonic-gate 	Phdr *		phdr;		/* program headers for file */
1747c478bd9Sstevel@tonic-gate 	Dyn *		dynp = 0;	/* Dynamic section */
1757c478bd9Sstevel@tonic-gate 	Word		nsym = 0;	/* no. of symtab ntries */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (*Profile == '\0') {
1787c478bd9Sstevel@tonic-gate 		const char	*dir, *suf;
1797c478bd9Sstevel@tonic-gate 		char		*tmp;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 		/*
1827c478bd9Sstevel@tonic-gate 		 * From the basename of the specified filename generate the
1837c478bd9Sstevel@tonic-gate 		 * appropriate profile buffer name.  The profile file is created
1847c478bd9Sstevel@tonic-gate 		 * if it does not already exist.
1857c478bd9Sstevel@tonic-gate 		 */
1867c478bd9Sstevel@tonic-gate 		if (((tmp = strrchr(fname, '/')) != 0) && (*(++tmp)))
1877c478bd9Sstevel@tonic-gate 			fname = tmp;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #if	defined(_ELF64)
1907c478bd9Sstevel@tonic-gate 		suf = MSG_ORIG(MSG_SUF_PROFILE_64);
1917c478bd9Sstevel@tonic-gate #else
1927c478bd9Sstevel@tonic-gate 		suf = MSG_ORIG(MSG_SUF_PROFILE);
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate 		if (dlinfo((void *)NULL, RTLD_DI_PROFILEOUT, &dir) == -1)
1957c478bd9Sstevel@tonic-gate 			dir = MSG_ORIG(MSG_PTH_VARTMP);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 		(void) snprintf(Profile, MAXPATHLEN, MSG_ORIG(MSG_FMT_PROFILE),
1987c478bd9Sstevel@tonic-gate 		    dir, fname, suf);
1997c478bd9Sstevel@tonic-gate 	}
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	if ((fd = open(Profile, (O_RDWR | O_CREAT), 0666)) == -1) {
2027c478bd9Sstevel@tonic-gate 		err = errno;
2037c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), Profile,
2047c478bd9Sstevel@tonic-gate 		    strerror(err));
2057c478bd9Sstevel@tonic-gate 		return (0);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * Now we determine the valid pc range for this object.  The lpc is easy
2107c478bd9Sstevel@tonic-gate 	 * (lmp->l_addr), to determine the hpc we must examine the Phdrs.
2117c478bd9Sstevel@tonic-gate 	 */
2127c478bd9Sstevel@tonic-gate 	lpc = hpc = (caddr_t)lmp->l_addr;
2137c478bd9Sstevel@tonic-gate 	/* LINTED */
2147c478bd9Sstevel@tonic-gate 	ehdr = (Ehdr *)lpc;
2157c478bd9Sstevel@tonic-gate 	if (ehdr->e_phnum == 0) {
2167c478bd9Sstevel@tonic-gate 		(void) close(fd);
2177c478bd9Sstevel@tonic-gate 		return (0);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 	if (ehdr->e_type == ET_EXEC)
2207c478bd9Sstevel@tonic-gate 		fixed = 1;
2217c478bd9Sstevel@tonic-gate 	/* LINTED */
2227c478bd9Sstevel@tonic-gate 	phdr = (Phdr *)(ehdr->e_phoff + lpc);
2237c478bd9Sstevel@tonic-gate 	for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
2247c478bd9Sstevel@tonic-gate 		caddr_t	_hpc;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_DYNAMIC) {
2277c478bd9Sstevel@tonic-gate 			dynp = (Dyn *)phdr->p_vaddr;
2287c478bd9Sstevel@tonic-gate 			if (fixed == 0) {
2297c478bd9Sstevel@tonic-gate 				dynp = (Dyn *)((unsigned long)dynp +
2307c478bd9Sstevel@tonic-gate 				    (unsigned long)lpc);
2317c478bd9Sstevel@tonic-gate 			}
2327c478bd9Sstevel@tonic-gate 			continue;
2337c478bd9Sstevel@tonic-gate 		}
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 		if (phdr->p_type != PT_LOAD)
2367c478bd9Sstevel@tonic-gate 			continue;
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 		_hpc = (caddr_t)(phdr->p_vaddr + phdr->p_memsz);
2397c478bd9Sstevel@tonic-gate 		if (fixed == 0) {
2407c478bd9Sstevel@tonic-gate 			_hpc = (caddr_t)((unsigned long)_hpc +
2417c478bd9Sstevel@tonic-gate 			    (unsigned long)lpc);
2427c478bd9Sstevel@tonic-gate 		}
2437c478bd9Sstevel@tonic-gate 		if (_hpc > hpc)
2447c478bd9Sstevel@tonic-gate 			hpc = _hpc;
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate 	if (lpc == hpc) {
2477c478bd9Sstevel@tonic-gate 		(void) close(fd);
2487c478bd9Sstevel@tonic-gate 		return (0);
2497c478bd9Sstevel@tonic-gate 	}
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	/*
2527c478bd9Sstevel@tonic-gate 	 * In order to determine the number of symbols in the object scan the
2537c478bd9Sstevel@tonic-gate 	 * dynamic section until we find the DT_HASH entry (hash[1] == symcnt).
2547c478bd9Sstevel@tonic-gate 	 */
2557c478bd9Sstevel@tonic-gate 	if (dynp) {
2567c478bd9Sstevel@tonic-gate 		for (; dynp->d_tag != DT_NULL; dynp++) {
2577c478bd9Sstevel@tonic-gate 			unsigned int	*hashp;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 			if (dynp->d_tag != DT_HASH)
2607c478bd9Sstevel@tonic-gate 				continue;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 			hashp = (unsigned int *)dynp->d_un.d_ptr;
2637c478bd9Sstevel@tonic-gate 			if (fixed == 0) {
2647c478bd9Sstevel@tonic-gate 				hashp = (unsigned int *)((unsigned long)hashp +
2657c478bd9Sstevel@tonic-gate 				    (unsigned long)lpc);
2667c478bd9Sstevel@tonic-gate 			}
2677c478bd9Sstevel@tonic-gate 			nsym = hashp[1];
2687c478bd9Sstevel@tonic-gate 			break;
2697c478bd9Sstevel@tonic-gate 		}
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Determine the (minimum) size of the buffer to allocate
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	Lpc = lpc = (caddr_t)PRF_ROUNDWN((long)lpc, sizeof (long));
2767c478bd9Sstevel@tonic-gate 	Hpc = hpc = (caddr_t)PRF_ROUNDUP((long)hpc, sizeof (long));
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	hsize = sizeof (L_hdr);
2797c478bd9Sstevel@tonic-gate 	msize = (size_t)(hpc - lpc);
2807c478bd9Sstevel@tonic-gate 	psize = (size_t)PRF_ROUNDUP((msize / PRF_BARSIZE), sizeof (long));
2817c478bd9Sstevel@tonic-gate 	csize = (nsym + 1) * PRF_CGINIT * sizeof (L_cgarc);
2827c478bd9Sstevel@tonic-gate 	Fsize = (hsize + psize + csize);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/*
2857c478bd9Sstevel@tonic-gate 	 * If the file size is zero (ie. we just created it), truncate it
2867c478bd9Sstevel@tonic-gate 	 * to the minimum size.
2877c478bd9Sstevel@tonic-gate 	 */
2887c478bd9Sstevel@tonic-gate 	(void) fstat(fd, &status);
2897c478bd9Sstevel@tonic-gate 	if (status.st_size == 0) {
2907c478bd9Sstevel@tonic-gate 		if (ftruncate(fd, Fsize) == -1) {
2917c478bd9Sstevel@tonic-gate 			err = errno;
2927c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_SYS_FTRUNC),
2937c478bd9Sstevel@tonic-gate 			    Profile, strerror(err));
2947c478bd9Sstevel@tonic-gate 			(void) close(fd);
2957c478bd9Sstevel@tonic-gate 			return (0);
2967c478bd9Sstevel@tonic-gate 		}
2977c478bd9Sstevel@tonic-gate 		new_buffer++;
2987c478bd9Sstevel@tonic-gate 	} else
2997c478bd9Sstevel@tonic-gate 		Fsize = status.st_size;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	/*
3027c478bd9Sstevel@tonic-gate 	 * Map the file in.
3037c478bd9Sstevel@tonic-gate 	 */
3047c478bd9Sstevel@tonic-gate 	if ((addr = (caddr_t)mmap(0, Fsize, (PROT_READ | PROT_WRITE),
3057c478bd9Sstevel@tonic-gate 	    MAP_SHARED, fd, 0)) == (char *)-1) {
3067c478bd9Sstevel@tonic-gate 		err = errno;
3077c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), Profile,
3087c478bd9Sstevel@tonic-gate 		    strerror(err));
3097c478bd9Sstevel@tonic-gate 		(void) close(fd);
3107c478bd9Sstevel@tonic-gate 		return (0);
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate 	(void) close(fd);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	/*
3157c478bd9Sstevel@tonic-gate 	 * Initialize the remaining elements of the header.  All pc addresses
3167c478bd9Sstevel@tonic-gate 	 * that are recorded are relative to zero thus allowing the recorded
3177c478bd9Sstevel@tonic-gate 	 * entries to be correlated with the symbols in the original file,
3187c478bd9Sstevel@tonic-gate 	 * and to compensate for any differences in where the file is mapped.
3197c478bd9Sstevel@tonic-gate 	 * If the high pc address has been initialized from a previous run,
3207c478bd9Sstevel@tonic-gate 	 * and the new entry is different from the original then a new library
3217c478bd9Sstevel@tonic-gate 	 * must have been installed.  In this case bale out.
3227c478bd9Sstevel@tonic-gate 	 */
3237c478bd9Sstevel@tonic-gate 	/* LINTED */
3247c478bd9Sstevel@tonic-gate 	Hptr = (L_hdr *)addr;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	if (new_buffer)
3277c478bd9Sstevel@tonic-gate 		(void) prof_mutex_init((lwp_mutex_t *)&Hptr->hd_mutex);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	(void) prof_mutex_lock((mutex_t *)&Hptr->hd_mutex, &mask);
3307c478bd9Sstevel@tonic-gate 	if (Hptr->hd_hpc) {
3317c478bd9Sstevel@tonic-gate 		if (Hptr->hd_hpc != (caddr_t)(hpc - lpc)) {
3327c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_GEN_PROFSZCHG),
3337c478bd9Sstevel@tonic-gate 			    Profile);
3347c478bd9Sstevel@tonic-gate 			(void) prof_mutex_unlock((mutex_t *)&Hptr->
3357c478bd9Sstevel@tonic-gate 			    hd_mutex, &mask);
3367c478bd9Sstevel@tonic-gate 			(void) munmap((caddr_t)Hptr, Fsize);
3377c478bd9Sstevel@tonic-gate 			return (0);
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 	} else {
3407c478bd9Sstevel@tonic-gate 		/*
3417c478bd9Sstevel@tonic-gate 		 * Initialize the header information as we must have just
3427c478bd9Sstevel@tonic-gate 		 * created the output file.
3437c478bd9Sstevel@tonic-gate 		 */
3447c478bd9Sstevel@tonic-gate 		Hptr->hd_magic = (unsigned int)PRF_MAGIC;
3457c478bd9Sstevel@tonic-gate #if	defined(_ELF64)
3467c478bd9Sstevel@tonic-gate 		Hptr->hd_version = (unsigned int)PRF_VERSION_64;
3477c478bd9Sstevel@tonic-gate #else
3487c478bd9Sstevel@tonic-gate 		Hptr->hd_version = (unsigned int)PRF_VERSION;
3497c478bd9Sstevel@tonic-gate #endif
3507c478bd9Sstevel@tonic-gate 		Hptr->hd_hpc = (caddr_t)(hpc - lpc);
3517c478bd9Sstevel@tonic-gate 		/* LINTED */
3527c478bd9Sstevel@tonic-gate 		Hptr->hd_psize = (unsigned int)psize;
3537c478bd9Sstevel@tonic-gate 		/* LINTED */
3547c478bd9Sstevel@tonic-gate 		Hptr->hd_fsize = (unsigned int)Fsize;
3557c478bd9Sstevel@tonic-gate 		Hptr->hd_ncndx = nsym;
3567c478bd9Sstevel@tonic-gate 		Hptr->hd_lcndx = (nsym + 1) * PRF_CGINIT;
3577c478bd9Sstevel@tonic-gate 	}
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	(void) prof_mutex_unlock((mutex_t *)&Hptr->hd_mutex, &mask);
3607c478bd9Sstevel@tonic-gate 	/* LINTED */
3617c478bd9Sstevel@tonic-gate 	Cptr = (L_cgarc *)(addr + hsize + psize);
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	/*
3647c478bd9Sstevel@tonic-gate 	 * Turn on profiling
3657c478bd9Sstevel@tonic-gate 	 */
3667c478bd9Sstevel@tonic-gate 	/* LINTED */
3677c478bd9Sstevel@tonic-gate 	profil((unsigned short *)(addr + hsize),
3687c478bd9Sstevel@tonic-gate 	    psize, (unsigned long)lpc, (unsigned int) PRF_SCALE);
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	return (1);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate uint_t
3757c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
la_objopen(Link_map * lmp,Lmid_t lmid,uintptr_t * cookie)3767c478bd9Sstevel@tonic-gate la_objopen(Link_map *lmp, Lmid_t lmid, uintptr_t *cookie)
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate 	char	*objname;
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	/*
3817c478bd9Sstevel@tonic-gate 	 * This would only occur if the getenv() in la_version() failed.
3827c478bd9Sstevel@tonic-gate 	 * at this point there is nothing for us to do.
3837c478bd9Sstevel@tonic-gate 	 */
3847c478bd9Sstevel@tonic-gate 	if (pname == 0)
3857c478bd9Sstevel@tonic-gate 		return (0);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	/*
3887c478bd9Sstevel@tonic-gate 	 * Just grab the 'basename' of the object current object for
3897c478bd9Sstevel@tonic-gate 	 * comparing against the 'profiled object name'
3907c478bd9Sstevel@tonic-gate 	 */
3917c478bd9Sstevel@tonic-gate 	if (((objname = strrchr(lmp->l_name, '/')) == 0) ||
3927c478bd9Sstevel@tonic-gate 	    (*(++objname) == 0))
3937c478bd9Sstevel@tonic-gate 		objname = lmp->l_name;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	/*
3967c478bd9Sstevel@tonic-gate 	 * Is this the object we are going to profile.  If not
3977c478bd9Sstevel@tonic-gate 	 * just set the 'BINDFROM' flag for this object.
3987c478bd9Sstevel@tonic-gate 	 */
3997c478bd9Sstevel@tonic-gate 	if ((strcmp(pname, objname) != 0) &&
4007c478bd9Sstevel@tonic-gate 	    (strcmp(pname, lmp->l_name) != 0))
4017c478bd9Sstevel@tonic-gate 		return (LA_FLG_BINDFROM);
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	/*
4047c478bd9Sstevel@tonic-gate 	 * Don't even try to profile an object that does not have
4057c478bd9Sstevel@tonic-gate 	 * auditing enabled on it's link-map.  This catches 'ld.so.1'.
4067c478bd9Sstevel@tonic-gate 	 */
407*2020b2b6SRod Evans 	if (LIST(LINKMAP_TO_RTMAP(lmp))->lm_tflags & LML_TFLG_NOAUDIT)
4087c478bd9Sstevel@tonic-gate 		return (LA_FLG_BINDFROM);
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	if (profile_open(pname, lmp) == 0)
4117c478bd9Sstevel@tonic-gate 		return (0);
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	profcookie = *cookie;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	return (LA_FLG_BINDFROM | LA_FLG_BINDTO);
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate uint_t
la_objclose(uintptr_t * cookie)4217c478bd9Sstevel@tonic-gate la_objclose(uintptr_t *cookie)
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate 	if (*cookie != profcookie)
4247c478bd9Sstevel@tonic-gate 		return (0);
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	profcookie = 0;
4277c478bd9Sstevel@tonic-gate 	/*
4287c478bd9Sstevel@tonic-gate 	 * Turn profil() off.
4297c478bd9Sstevel@tonic-gate 	 */
4307c478bd9Sstevel@tonic-gate 	profil(0, 0, 0, 0);
4317c478bd9Sstevel@tonic-gate 	(void) munmap((caddr_t)Hptr, Fsize);
4327c478bd9Sstevel@tonic-gate 	return (0);
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate static int
remap_profile(int fd)4377c478bd9Sstevel@tonic-gate remap_profile(int fd)
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate 	caddr_t		addr;
4407c478bd9Sstevel@tonic-gate 	size_t		l_fsize;
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 	l_fsize = Hptr->hd_fsize;
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	if ((addr = (caddr_t)mmap(0, l_fsize, (PROT_READ | PROT_WRITE),
4457c478bd9Sstevel@tonic-gate 	    MAP_SHARED, fd, 0)) == (char *)-1) {
4467c478bd9Sstevel@tonic-gate 		int	err = errno;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), Profile,
4497c478bd9Sstevel@tonic-gate 		    strerror(err));
4507c478bd9Sstevel@tonic-gate 		return (0);
4517c478bd9Sstevel@tonic-gate 	}
4527c478bd9Sstevel@tonic-gate 	(void) munmap((caddr_t)Hptr, Fsize);
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	Fsize = l_fsize;
4557c478bd9Sstevel@tonic-gate 	/* LINTED */
4567c478bd9Sstevel@tonic-gate 	Hptr = (L_hdr*) addr;
4577c478bd9Sstevel@tonic-gate 	/* LINTED */
4587c478bd9Sstevel@tonic-gate 	Cptr = (L_cgarc *)(addr + sizeof (L_hdr) + Hptr->hd_psize);
4597c478bd9Sstevel@tonic-gate 	return (1);
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate /*
4647c478bd9Sstevel@tonic-gate  * Update a call graph arc entry.  This routine can be called three ways;
4657c478bd9Sstevel@tonic-gate  * 	o	On initialization from one of the bndr() functions.
4667c478bd9Sstevel@tonic-gate  *		In this case the `to' address is known, and may be used to
4677c478bd9Sstevel@tonic-gate  *		initialize the call graph entry if this function has not
4687c478bd9Sstevel@tonic-gate  *		been entered before.
4697c478bd9Sstevel@tonic-gate  *	o	On initial relocation (ie. LD_BIND_NOW). In this case the `to'
4707c478bd9Sstevel@tonic-gate  *		address is known but the `from' isn't.  The call graph entry
4717c478bd9Sstevel@tonic-gate  *		is initialized to hold this dummy `to' address, but will be
4727c478bd9Sstevel@tonic-gate  *		re-initialized later when a function is first called.
4737c478bd9Sstevel@tonic-gate  *	o	From an initialized plt entry.  When profiling, the plt entries
4747c478bd9Sstevel@tonic-gate  *		are filled in with the calling functions symbol index and
4757c478bd9Sstevel@tonic-gate  *		the plt_cg_elf interface function.  This interface function
4767c478bd9Sstevel@tonic-gate  *		calls here to determine the `to' functions address, and in so
4777c478bd9Sstevel@tonic-gate  *		doing increments the call count.
4787c478bd9Sstevel@tonic-gate  */
4797c478bd9Sstevel@tonic-gate uintptr_t
plt_cg_interp(uint_t ndx,caddr_t from,caddr_t to)4807c478bd9Sstevel@tonic-gate plt_cg_interp(uint_t ndx, caddr_t from, caddr_t to)
4817c478bd9Sstevel@tonic-gate {
4827c478bd9Sstevel@tonic-gate 	L_cgarc *	cptr, cbucket;
4837c478bd9Sstevel@tonic-gate 	sigset_t	mask;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	/*
4867c478bd9Sstevel@tonic-gate 	 * If the from address is outside of the address range being profiled,
4877c478bd9Sstevel@tonic-gate 	 * simply assign it to the `outside' address.
4887c478bd9Sstevel@tonic-gate 	 */
4897c478bd9Sstevel@tonic-gate 	if (from != PRF_UNKNOWN) {
4907c478bd9Sstevel@tonic-gate 		if ((from > Hpc) || (from < Lpc))
4917c478bd9Sstevel@tonic-gate 			from = PRF_OUTADDR;
4927c478bd9Sstevel@tonic-gate 		else
4937c478bd9Sstevel@tonic-gate 			from = (caddr_t)(from - Lpc);
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	(void) prof_mutex_lock((mutex_t *)&Hptr->hd_mutex, &mask);
4977c478bd9Sstevel@tonic-gate 	/*
4987c478bd9Sstevel@tonic-gate 	 * Has the buffer grown since last we looked at it (another processes
4997c478bd9Sstevel@tonic-gate 	 * could have grown it...).
5007c478bd9Sstevel@tonic-gate 	 */
5017c478bd9Sstevel@tonic-gate 	/* LINTED */
5027c478bd9Sstevel@tonic-gate 	if (Hptr->hd_fsize != (unsigned int)Fsize) {
5037c478bd9Sstevel@tonic-gate 		int fd;
5047c478bd9Sstevel@tonic-gate 		fd = open(Profile, O_RDWR, 0);
5057c478bd9Sstevel@tonic-gate 		if (remap_profile(fd) == 0) {
5067c478bd9Sstevel@tonic-gate 			(void) prof_mutex_unlock((mutex_t *)&Hptr->hd_mutex,
5077c478bd9Sstevel@tonic-gate 			    &mask);
5087c478bd9Sstevel@tonic-gate 			exit(1);
5097c478bd9Sstevel@tonic-gate 		}
5107c478bd9Sstevel@tonic-gate 		(void) close(fd);
5117c478bd9Sstevel@tonic-gate 	}
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	cptr = &Cptr[ndx];
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	if (cptr->cg_to == 0) {
5167c478bd9Sstevel@tonic-gate 		/*
5177c478bd9Sstevel@tonic-gate 		 * If this is the first time this function has been called we
5187c478bd9Sstevel@tonic-gate 		 * got here from one of the binders or an initial relocation
5197c478bd9Sstevel@tonic-gate 		 * (ie. LD_BIND_NOW).  In this case the `to' address is
5207c478bd9Sstevel@tonic-gate 		 * provided.  Initialize this functions call graph entry with
5217c478bd9Sstevel@tonic-gate 		 * the functions address (retained as a relative offset).
5227c478bd9Sstevel@tonic-gate 		 * If we know where the function call originated from
5237c478bd9Sstevel@tonic-gate 		 * initialize the count field.
5247c478bd9Sstevel@tonic-gate 		 */
5257c478bd9Sstevel@tonic-gate 		cptr->cg_to = (caddr_t)(to - Lpc);
5267c478bd9Sstevel@tonic-gate 		cptr->cg_from = from;
5277c478bd9Sstevel@tonic-gate 		if (from != PRF_UNKNOWN)
5287c478bd9Sstevel@tonic-gate 			cptr->cg_count = 1;
5297c478bd9Sstevel@tonic-gate 	} else {
5307c478bd9Sstevel@tonic-gate 		/*
5317c478bd9Sstevel@tonic-gate 		 * If a function has been called from a previous run, but we
5327c478bd9Sstevel@tonic-gate 		 * don't know where we came from (ie. LD_BIND_NOW), then later
5337c478bd9Sstevel@tonic-gate 		 * calls through the plt will be able to obtain the required
5347c478bd9Sstevel@tonic-gate 		 * functions address, thus there is no need to proceed further.
5357c478bd9Sstevel@tonic-gate 		 */
5367c478bd9Sstevel@tonic-gate 		if (from != PRF_UNKNOWN) {
5377c478bd9Sstevel@tonic-gate 			/*
5387c478bd9Sstevel@tonic-gate 			 * If the from addresses match simply bump the count.
5397c478bd9Sstevel@tonic-gate 			 * If not scan the link list to find a match for this
5407c478bd9Sstevel@tonic-gate 			 * `from' address.  If one doesn't exit create a new
5417c478bd9Sstevel@tonic-gate 			 * entry and link it in.
5427c478bd9Sstevel@tonic-gate 			 */
5437c478bd9Sstevel@tonic-gate 			while ((cptr->cg_from != from) &&
5447c478bd9Sstevel@tonic-gate 			    (cptr->cg_from != PRF_UNKNOWN)) {
5457c478bd9Sstevel@tonic-gate 				if (cptr->cg_next != 0)
5467c478bd9Sstevel@tonic-gate 					cptr = &Cptr[cptr->cg_next];
5477c478bd9Sstevel@tonic-gate 				else {
5487c478bd9Sstevel@tonic-gate 					to = cptr->cg_to;
5497c478bd9Sstevel@tonic-gate 					cptr->cg_next = Hptr->hd_ncndx++;
5507c478bd9Sstevel@tonic-gate 					cptr = &Cptr[cptr->cg_next];
5517c478bd9Sstevel@tonic-gate 					/*
5527c478bd9Sstevel@tonic-gate 					 * If we've run out of file, extend it.
5537c478bd9Sstevel@tonic-gate 					 */
5547c478bd9Sstevel@tonic-gate 					if (Hptr->hd_ncndx == Hptr->hd_lcndx) {
5557c478bd9Sstevel@tonic-gate 						caddr_t	addr;
5567c478bd9Sstevel@tonic-gate 						int	fd;
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 						/* LINTED */
5597c478bd9Sstevel@tonic-gate 						Hptr->hd_fsize += (unsigned int)
5607c478bd9Sstevel@tonic-gate 						    PRF_CGNUMB *
5617c478bd9Sstevel@tonic-gate 						    sizeof (L_cgarc);
5627c478bd9Sstevel@tonic-gate 						fd = open(Profile, O_RDWR, 0);
5637c478bd9Sstevel@tonic-gate 						if (ftruncate(fd,
5647c478bd9Sstevel@tonic-gate 						    Hptr->hd_fsize) == -1) {
5657c478bd9Sstevel@tonic-gate 							int	err = errno;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 							(void) fprintf(stderr,
5687c478bd9Sstevel@tonic-gate 							    MSG_INTL(
5697c478bd9Sstevel@tonic-gate 							    MSG_SYS_FTRUNC),
5707c478bd9Sstevel@tonic-gate 							    Profile,
5717c478bd9Sstevel@tonic-gate 							    strerror(err));
5727c478bd9Sstevel@tonic-gate 							(void) close(fd);
5737c478bd9Sstevel@tonic-gate 							cptr = &cbucket;
5747c478bd9Sstevel@tonic-gate 						}
5757c478bd9Sstevel@tonic-gate 						/*
5767c478bd9Sstevel@tonic-gate 						 * Since the buffer will be
5777c478bd9Sstevel@tonic-gate 						 * remapped, we need to be
5787c478bd9Sstevel@tonic-gate 						 * prepared to adjust cptr.
5797c478bd9Sstevel@tonic-gate 						 */
5807c478bd9Sstevel@tonic-gate 						addr = (caddr_t)((Addr)cptr -
5817c478bd9Sstevel@tonic-gate 						    (Addr)Cptr);
5827c478bd9Sstevel@tonic-gate 						if (remap_profile(fd) == 0) {
5837257d1b4Sraf 						    /* CSTYLED */
5847c478bd9Sstevel@tonic-gate 						    (void) prof_mutex_unlock(
5857c478bd9Sstevel@tonic-gate 							(mutex_t *)&Hptr->
5867c478bd9Sstevel@tonic-gate 							hd_mutex, &mask);
5877c478bd9Sstevel@tonic-gate 							exit(1);
5887c478bd9Sstevel@tonic-gate 						}
5897c478bd9Sstevel@tonic-gate 						cptr = (L_cgarc *)((Addr)addr +
5907c478bd9Sstevel@tonic-gate 						    (Addr)Cptr);
5917c478bd9Sstevel@tonic-gate 						(void) close(fd);
5927c478bd9Sstevel@tonic-gate 						Hptr->hd_lcndx += PRF_CGNUMB;
5937c478bd9Sstevel@tonic-gate 					}
5947c478bd9Sstevel@tonic-gate 					cptr->cg_from = from;
5957c478bd9Sstevel@tonic-gate 					cptr->cg_to = to;
5967c478bd9Sstevel@tonic-gate 				}
5977c478bd9Sstevel@tonic-gate 			}
5987c478bd9Sstevel@tonic-gate 			/*
5997c478bd9Sstevel@tonic-gate 			 * If we're updating an entry from an unknown call
6007c478bd9Sstevel@tonic-gate 			 * address initialize this element, otherwise
6017c478bd9Sstevel@tonic-gate 			 * increment the call count.
6027c478bd9Sstevel@tonic-gate 			 */
6037c478bd9Sstevel@tonic-gate 			if (cptr->cg_from == PRF_UNKNOWN) {
6047c478bd9Sstevel@tonic-gate 				cptr->cg_from = from;
6057c478bd9Sstevel@tonic-gate 				cptr->cg_count = 1;
6067c478bd9Sstevel@tonic-gate 			} else
6077c478bd9Sstevel@tonic-gate 				cptr->cg_count++;
6087c478bd9Sstevel@tonic-gate 		}
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 	/*
6117c478bd9Sstevel@tonic-gate 	 * Return the real address of the function.
6127c478bd9Sstevel@tonic-gate 	 */
6137c478bd9Sstevel@tonic-gate 	(void) prof_mutex_unlock((mutex_t *)&Hptr->hd_mutex, &mask);
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	return ((uintptr_t)((Addr)cptr->cg_to + (Addr)Lpc));
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
6197c478bd9Sstevel@tonic-gate #if	defined(__sparcv9)
6207c478bd9Sstevel@tonic-gate uintptr_t
la_sparcv9_pltenter(Elf64_Sym * symp,uint_t symndx,uintptr_t * refcookie,uintptr_t * defcookie,La_sparcv9_regs * regset,uint_t * sbflags,const char * sym_name)6217c478bd9Sstevel@tonic-gate la_sparcv9_pltenter(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcookie,
6227c478bd9Sstevel@tonic-gate 	uintptr_t *defcookie, La_sparcv9_regs *regset, uint_t *sbflags,
6237c478bd9Sstevel@tonic-gate 	const char *sym_name)
6247c478bd9Sstevel@tonic-gate #elif	defined(__sparc)
6257c478bd9Sstevel@tonic-gate uintptr_t
6267c478bd9Sstevel@tonic-gate la_sparcv8_pltenter(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcookie,
6277c478bd9Sstevel@tonic-gate 	uintptr_t *defcookie, La_sparcv8_regs *regset, uint_t *sbflags)
6287c478bd9Sstevel@tonic-gate #elif	defined(__amd64)
6297c478bd9Sstevel@tonic-gate uintptr_t
6307c478bd9Sstevel@tonic-gate la_amd64_pltenter(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcookie,
6317c478bd9Sstevel@tonic-gate 	uintptr_t *defcookie, La_amd64_regs *regset, uint_t *sbflags,
6327c478bd9Sstevel@tonic-gate 	const char *sym_name)
6337c478bd9Sstevel@tonic-gate #elif	defined(__i386)
6347c478bd9Sstevel@tonic-gate uintptr_t
6357c478bd9Sstevel@tonic-gate la_i86_pltenter(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcookie,
6367c478bd9Sstevel@tonic-gate 	uintptr_t *defcookie, La_i86_regs *regset, uint_t *sbflags)
6377c478bd9Sstevel@tonic-gate #else
6387c478bd9Sstevel@tonic-gate #error unexpected architecture!
6397c478bd9Sstevel@tonic-gate #endif
6407c478bd9Sstevel@tonic-gate {
6417c478bd9Sstevel@tonic-gate 	caddr_t		from;
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	/*
6447c478bd9Sstevel@tonic-gate 	 * profiling has been disabled.
6457c478bd9Sstevel@tonic-gate 	 */
6467c478bd9Sstevel@tonic-gate 	if (profcookie == 0)
6477c478bd9Sstevel@tonic-gate 		return (symp->st_value);
64802ca3e02Srie #if defined(__sparc)
6497c478bd9Sstevel@tonic-gate 	/*
6507c478bd9Sstevel@tonic-gate 	 * The callers return address is currently stored in O7 (which
6517c478bd9Sstevel@tonic-gate 	 * will become I7 when the window shift occurs).
6527c478bd9Sstevel@tonic-gate 	 */
6537c478bd9Sstevel@tonic-gate 	from = (caddr_t)regset->lr_rego7;
6547c478bd9Sstevel@tonic-gate #elif defined(__amd64)
6557c478bd9Sstevel@tonic-gate 	/*
6567c478bd9Sstevel@tonic-gate 	 * The callers return address is on the top of the stack for amd64
6577c478bd9Sstevel@tonic-gate 	 */
6587c478bd9Sstevel@tonic-gate 	from = *(caddr_t *)(regset->lr_rsp);
6597c478bd9Sstevel@tonic-gate #elif defined(__i386)
6607c478bd9Sstevel@tonic-gate 	/*
6617c478bd9Sstevel@tonic-gate 	 * The callers return address is on the top of the stack for i386
6627c478bd9Sstevel@tonic-gate 	 */
6637c478bd9Sstevel@tonic-gate 	from = *(caddr_t *)(regset->lr_esp);
6647c478bd9Sstevel@tonic-gate #else
6657c478bd9Sstevel@tonic-gate #error unexpected architecture!
6667c478bd9Sstevel@tonic-gate #endif
6677c478bd9Sstevel@tonic-gate 	return (plt_cg_interp(symndx, (caddr_t)from, (caddr_t)symp->st_value));
6687c478bd9Sstevel@tonic-gate }
669