profile.c revision 02ca3e029e37aa98ac6717698bfdac6afe960932
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Routines to provide profiling of shared libraries required by the called
* executable.
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <synch.h>
#include <signal.h>
#include <synch.h>
#include <link.h>
#include <procfs.h>
#include "msg.h"
#include "sgs.h"
#include "profile.h"
#include "_rtld.h"
static char *pname = 0; /* name of object to profile */
uintptr_t profcookie = 0;
/*
* When handling mutex's locally we need to mask signals. The signal
* mask is for everything except SIGWAITING.
*/
static int
{
return (0);
}
static int
{
if (oset)
(void) _lwp_mutex_lock(mp);
return (0);
}
static int
{
(void) _lwp_mutex_unlock(mp);
if (oset)
return (0);
}
extern char *_dgettext(const char *, const char *);
const char *
{
}
/*
* Determine whether a set (of arbitrary size) is in use - used to analyze proc
* status information.
*/
static int
{
while (n--)
if (*sp++)
return (1);
return (0);
}
{
int fd;
if (version < LAV_CURRENT) {
return (LAV_CURRENT);
}
/*
* To reduce the potential for deadlock conditions that can arise from
* being monitored (say by truss(1)) while setting a lock in the profile
* buffer, determine if someone is monitoring us. If so silently
* disable profiling.
*/
return (LAV_CURRENT);
return (LAV_CURRENT);
}
/*
* We're presently not being monitored (although there's no control of
* someone attaching to us later), so retrieve the profile target name.
*/
return (LAV_CURRENT);
}
int
{
int new_buffer = 0;
int err;
if (*Profile == '\0') {
char *tmp;
/*
* From the basename of the specified filename generate the
* appropriate profile buffer name. The profile file is created
* if it does not already exist.
*/
#if defined(_ELF64)
#else
#endif
}
return (0);
}
/*
* Now we determine the valid pc range for this object. The lpc is easy
* (lmp->l_addr), to determine the hpc we must examine the Phdrs.
*/
/* LINTED */
return (0);
}
fixed = 1;
/* LINTED */
if (fixed == 0) {
(unsigned long)lpc);
}
continue;
}
continue;
if (fixed == 0) {
(unsigned long)lpc);
}
}
return (0);
}
/*
* In order to determine the number of symbols in the object scan the
* dynamic section until we find the DT_HASH entry (hash[1] == symcnt).
*/
if (dynp) {
unsigned int *hashp;
continue;
if (fixed == 0) {
(unsigned long)lpc);
}
break;
}
}
/*
* Determine the (minimum) size of the buffer to allocate
*/
/*
* If the file size is zero (ie. we just created it), truncate it
* to the minimum size.
*/
return (0);
}
new_buffer++;
} else
/*
* Map the file in.
*/
return (0);
}
/*
* Initialize the remaining elements of the header. All pc addresses
* that are recorded are relative to zero thus allowing the recorded
* entries to be correlated with the symbols in the original file,
* and to compensate for any differences in where the file is mapped.
* If the high pc address has been initialized from a previous run,
* and the new entry is different from the original then a new library
* must have been installed. In this case bale out.
*/
/* LINTED */
if (new_buffer)
Profile);
return (0);
}
} else {
/*
* Initialize the header information as we must have just
* created the output file.
*/
#if defined(_ELF64)
#else
#endif
/* LINTED */
/* LINTED */
}
/* LINTED */
/*
* Turn on profiling
*/
/* LINTED */
return (1);
}
/* ARGSUSED1 */
{
char *objname;
/*
* This would only occur if the getenv() in la_version() failed.
* at this point there is nothing for us to do.
*/
if (pname == 0)
return (0);
/*
* Just grab the 'basename' of the object current object for
* comparing against the 'profiled object name'
*/
(*(++objname) == 0))
/*
* Is this the object we are going to profile. If not
* just set the 'BINDFROM' flag for this object.
*/
return (LA_FLG_BINDFROM);
/*
* Don't even try to profile an object that does not have
* auditing enabled on it's link-map. This catches 'ld.so.1'.
*/
return (LA_FLG_BINDFROM);
return (0);
profcookie = *cookie;
return (LA_FLG_BINDFROM | LA_FLG_BINDTO);
}
{
if (*cookie != profcookie)
return (0);
profcookie = 0;
/*
* Turn profil() off.
*/
profil(0, 0, 0, 0);
return (0);
}
static int
remap_profile(int fd)
{
return (0);
}
/* LINTED */
/* LINTED */
return (1);
}
/*
* Update a call graph arc entry. This routine can be called three ways;
* o On initialization from one of the bndr() functions.
* In this case the `to' address is known, and may be used to
* initialize the call graph entry if this function has not
* been entered before.
* o On initial relocation (ie. LD_BIND_NOW). In this case the `to'
* address is known but the `from' isn't. The call graph entry
* is initialized to hold this dummy `to' address, but will be
* re-initialized later when a function is first called.
* o From an initialized plt entry. When profiling, the plt entries
* are filled in with the calling functions symbol index and
* the plt_cg_elf interface function. This interface function
* calls here to determine the `to' functions address, and in so
* doing increments the call count.
*/
{
/*
* If the from address is outside of the address range being profiled,
* simply assign it to the `outside' address.
*/
if (from != PRF_UNKNOWN) {
from = PRF_OUTADDR;
else
}
/*
* Has the buffer grown since last we looked at it (another processes
* could have grown it...).
*/
/* LINTED */
int fd;
if (remap_profile(fd) == 0) {
&mask);
exit(1);
}
}
/*
* If this is the first time this function has been called we
* got here from one of the binders or an initial relocation
* (ie. LD_BIND_NOW). In this case the `to' address is
* provided. Initialize this functions call graph entry with
* the functions address (retained as a relative offset).
* If we know where the function call originated from
* initialize the count field.
*/
if (from != PRF_UNKNOWN)
} else {
/*
* If a function has been called from a previous run, but we
* don't know where we came from (ie. LD_BIND_NOW), then later
* calls through the plt will be able to obtain the required
* functions address, thus there is no need to proceed further.
*/
if (from != PRF_UNKNOWN) {
/*
* If the from addresses match simply bump the count.
* If not scan the link list to find a match for this
* `from' address. If one doesn't exit create a new
* entry and link it in.
*/
else {
/*
* If we've run out of file, extend it.
*/
int fd;
/* LINTED */
sizeof (L_cgarc);
}
/*
* Since the buffer will be
* remapped, we need to be
* prepared to adjust cptr.
*/
if (remap_profile(fd) == 0) {
(void) prof_mutex_unlock(
exit(1);
}
}
}
}
/*
* If we're updating an entry from an unknown call
* address initialize this element, otherwise
* increment the call count.
*/
} else
}
}
/*
* Return the real address of the function.
*/
}
/* ARGSUSED2 */
#if defined(__sparcv9)
const char *sym_name)
const char *sym_name)
#else
#endif
{
/*
* profiling has been disabled.
*/
if (profcookie == 0)
#if defined(__sparc)
/*
* The callers return address is currently stored in O7 (which
* will become I7 when the window shift occurs).
*/
/*
* The callers return address is on the top of the stack for amd64
*/
/*
* The callers return address is on the top of the stack for i386
*/
#else
#endif
}