glibc/elf/sotruss-lib.c

394 lines
11 KiB
C
Raw Normal View History

2011-05-28 17:20:12 +00:00
/* Trace calls through PLTs and show caller, callee, and parameters.
Copyright (C) 2011-2021 Free Software Foundation, Inc.
2011-05-28 17:20:12 +00:00
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
Prefer https to http for gnu.org and fsf.org URLs Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
<https://www.gnu.org/licenses/>. */
2011-05-28 17:20:12 +00:00
#include <err.h>
2011-05-28 17:20:12 +00:00
#include <error.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <ldsodefs.h>
extern const char *__progname;
extern const char *__progname_full;
/* List of objects to trace calls from. */
static const char *fromlist;
/* List of objects to trace calls to. */
static const char *tolist;
/* If non-zero, also trace returns of the calls. */
static int do_exit;
/* If non-zero print PID for each line. */
static int print_pid;
/* The output stream to use. */
static FILE *out_file;
static int
match_pid (pid_t pid, const char *which)
{
if (which == NULL || which[0] == '\0')
{
print_pid = 1;
return 1;
}
char *endp;
unsigned long n = strtoul (which, &endp, 0);
return *endp == '\0' && n == pid;
}
static void
init (void)
{
fromlist = getenv ("SOTRUSS_FROMLIST");
if (fromlist != NULL && fromlist[0] == '\0')
fromlist = NULL;
tolist = getenv ("SOTRUSS_TOLIST");
if (tolist != NULL && tolist[0] == '\0')
tolist = NULL;
do_exit = (getenv ("SOTRUSS_EXIT") ?: "")[0] != '\0';
/* Determine whether this process is supposed to be traced and if
yes, whether we should print into a file. */
const char *which_process = getenv ("SOTRUSS_WHICH");
pid_t pid = getpid ();
int out_fd = -1;
if (match_pid (pid, which_process))
{
const char *out_filename = getenv ("SOTRUSS_OUTNAME");
if (out_filename != NULL && out_filename[0] != 0)
{
size_t out_filename_len = strlen (out_filename) + 13;
2011-05-28 17:20:12 +00:00
char fullname[out_filename_len];
char *endp = stpcpy (fullname, out_filename);
if (which_process == NULL || which_process[0] == '\0')
snprintf (endp, 13, ".%ld", (long int) pid);
2011-05-28 17:20:12 +00:00
Use LFS and 64 bit time for installed programs (BZ #15333) The installed programs are built with a combination of different values for MODULE_NAME, as below. To enable both Long File Support and 64 bt time, -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 is added for nonlibi, nscd, lddlibc4, libresolv, ldconfig, locale_programs, iconvprogs, libnss_files, libnss_compat, libnss_db, libnss_hesiod, libutil, libpcprofile, and libSegFault. nscd/nscd nscd/nscd.o MODULE_NAME=nscd nscd/connections.o MODULE_NAME=nscd nscd/pwdcache.o MODULE_NAME=nscd nscd/getpwnam_r.o MODULE_NAME=nscd nscd/getpwuid_r.o MODULE_NAME=nscd nscd/grpcache.o MODULE_NAME=nscd nscd/getgrnam_r.o MODULE_NAME=nscd nscd/getgrgid_r.o MODULE_NAME=nscd nscd/hstcache.o MODULE_NAME=nscd nscd/gethstbyad_r.o MODULE_NAME=nscd nscd/gethstbynm3_r.o MODULE_NAME=nscd nscd/getsrvbynm_r.o MODULE_NAME=nscd nscd/getsrvbypt_r.o MODULE_NAME=nscd nscd/servicescache.o MODULE_NAME=nscd nscd/dbg_log.o MODULE_NAME=nscd nscd/nscd_conf.o MODULE_NAME=nscd nscd/nscd_stat.o MODULE_NAME=nscd nscd/cache.o MODULE_NAME=nscd nscd/mem.o MODULE_NAME=nscd nscd/nscd_setup_thread.o MODULE_NAME=nscd nscd/xmalloc.o MODULE_NAME=nscd nscd/xstrdup.o MODULE_NAME=nscd nscd/aicache.o MODULE_NAME=nscd nscd/initgrcache.o MODULE_NAME=nscd nscd/gai.o MODULE_NAME=nscd nscd/res_hconf.o MODULE_NAME=nscd nscd/netgroupcache.o MODULE_NAME=nscd nscd/cachedumper.o MODULE_NAME=nscd elf/lddlibc4 elf/lddlibc4 MODULE_NAME=lddlibc4 elf/pldd elf/pldd.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/sln elf/sln.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/sprof MODULE_NAME=nonlib elf/ldconfig elf/ldconfig.o MODULE_NAME=ldconfig elf/cache.o MODULE_NAME=nonlib elf/readlib.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/xstrdup.o MODULE_NAME=nonlib elf/chroot_canon.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/stringtable.o MODULE_NAME=nonlib io/pwd io/pwd.o MODULE_NAME=nonlib locale/locale locale/locale.o MODULE_NAME=locale_programs locale/locale-spec.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs locale/localedef locale/localedef.o MODULE_NAME=locale_programs locale/ld-ctype.o MODULE_NAME=locale_programs locale/ld-messages.o MODULE_NAME=locale_programs locale/ld-monetary.o MODULE_NAME=locale_programs locale/ld-numeric.o MODULE_NAME=locale_programs locale/ld-time.o MODULE_NAME=locale_programs locale/ld-paper.o MODULE_NAME=locale_programs locale/ld-name.o MODULE_NAME=locale_programs locale/ld-address.o MODULE_NAME=locale_programs locale/ld-telephone.o MODULE_NAME=locale_programs locale/ld-measurement.o MODULE_NAME=locale_programs locale/ld-identification.o MODULE_NAME=locale_programs locale/ld-collate.o MODULE_NAME=locale_programs locale/charmap.o MODULE_NAME=locale_programs locale/linereader.o MODULE_NAME=locale_programs locale/locfile.o MODULE_NAME=locale_programs locale/repertoire.o MODULE_NAME=locale_programs locale/locarchive.o MODULE_NAME=locale_programs locale/md5.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs catgets/gencat catgets/gencat.o MODULE_NAME=nonlib catgets/xmalloc.o MODULE_NAME=nonlib nss/makedb nss/makedb.o MODULE_NAME=nonlib nss/xmalloc.o MODULE_NAME=nonlib nss/hash-string.o MODULE_NAME=nonlib nss/getent nss/getent.o MODULE_NAME=nonlib posix/getconf posix/getconf.o MODULE_NAME=nonlib login/utmpdump login/utmpdump.o MODULE_NAME=nonlib debug/pcprofiledump debug/pcprofiledump.o MODULE_NAME=nonlib timezone/zic timezone/zic.o MODULE_NAME=nonlib timezone/zdump timezone/zdump.o MODULE_NAME=nonlib iconv/iconv_prog iconv/iconv_prog.o MODULE_NAME=nonlib iconv/iconv_charmap.o MODULE_NAME=iconvprogs iconv/charmap.o MODULE_NAME=iconvprogs iconv/charmap-dir.o MODULE_NAME=iconvprogs iconv/linereader.o MODULE_NAME=iconvprogs iconv/dummy-repertoire.o MODULE_NAME=iconvprogs iconv/simple-hash.o MODULE_NAME=iconvprogs iconv/xstrdup.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/record-status.o MODULE_NAME=iconvprogs iconv/iconvconfig iconv/iconvconfig.o MODULE_NAME=nonlib iconv/strtab.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/hash-string.o MODULE_NAME=iconvprogs nss/libnss_files.so MODULE_NAME=libnss_files nss/libnss_compat.so.2 MODULE_NAME=libnss_compat nss/libnss_db.so MODULE_NAME=libnss_db hesiod/libnss_hesiod.so MODULE_NAME=libnss_hesiod login/libutil.so MODULE_NAME=libutil debug/libpcprofile.so MODULE_NAME=libpcprofile debug/libSegFault.so MODULE_NAME=libSegFault Also, to avoid adding both LFS and 64 bit time support on internal tests they are moved to a newer 'testsuite-internal' module. It should be similar to 'nonlib' regarding internal definition and linking namespace. This patch also enables LFS and 64 bit support of libsupport container programs (echo-container, test-container, shell-container, and true-container). Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: DJ Delorie <dj@redhat.com> (cherry picked from commit a6d2f948b71adcb5ea395cb04833bc645eab45e6)
2021-05-20 17:20:18 +00:00
out_fd = open64 (fullname, O_RDWR | O_CREAT | O_TRUNC, 0666);
2011-05-28 17:20:12 +00:00
if (out_fd != -1)
print_pid = 0;
}
}
/* If we do not write into a file write to stderr. Duplicate the
descriptor so that we can keep printing in case the program
closes stderr. Try first to allocate a descriptor with a value
usually not used as to minimize interference with the
program. */
if (out_fd == -1)
{
Use LFS and 64 bit time for installed programs (BZ #15333) The installed programs are built with a combination of different values for MODULE_NAME, as below. To enable both Long File Support and 64 bt time, -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 is added for nonlibi, nscd, lddlibc4, libresolv, ldconfig, locale_programs, iconvprogs, libnss_files, libnss_compat, libnss_db, libnss_hesiod, libutil, libpcprofile, and libSegFault. nscd/nscd nscd/nscd.o MODULE_NAME=nscd nscd/connections.o MODULE_NAME=nscd nscd/pwdcache.o MODULE_NAME=nscd nscd/getpwnam_r.o MODULE_NAME=nscd nscd/getpwuid_r.o MODULE_NAME=nscd nscd/grpcache.o MODULE_NAME=nscd nscd/getgrnam_r.o MODULE_NAME=nscd nscd/getgrgid_r.o MODULE_NAME=nscd nscd/hstcache.o MODULE_NAME=nscd nscd/gethstbyad_r.o MODULE_NAME=nscd nscd/gethstbynm3_r.o MODULE_NAME=nscd nscd/getsrvbynm_r.o MODULE_NAME=nscd nscd/getsrvbypt_r.o MODULE_NAME=nscd nscd/servicescache.o MODULE_NAME=nscd nscd/dbg_log.o MODULE_NAME=nscd nscd/nscd_conf.o MODULE_NAME=nscd nscd/nscd_stat.o MODULE_NAME=nscd nscd/cache.o MODULE_NAME=nscd nscd/mem.o MODULE_NAME=nscd nscd/nscd_setup_thread.o MODULE_NAME=nscd nscd/xmalloc.o MODULE_NAME=nscd nscd/xstrdup.o MODULE_NAME=nscd nscd/aicache.o MODULE_NAME=nscd nscd/initgrcache.o MODULE_NAME=nscd nscd/gai.o MODULE_NAME=nscd nscd/res_hconf.o MODULE_NAME=nscd nscd/netgroupcache.o MODULE_NAME=nscd nscd/cachedumper.o MODULE_NAME=nscd elf/lddlibc4 elf/lddlibc4 MODULE_NAME=lddlibc4 elf/pldd elf/pldd.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/sln elf/sln.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/sprof MODULE_NAME=nonlib elf/ldconfig elf/ldconfig.o MODULE_NAME=ldconfig elf/cache.o MODULE_NAME=nonlib elf/readlib.o MODULE_NAME=nonlib elf/xmalloc.o MODULE_NAME=nonlib elf/xstrdup.o MODULE_NAME=nonlib elf/chroot_canon.o MODULE_NAME=nonlib elf/static-stubs.o MODULE_NAME=nonlib elf/stringtable.o MODULE_NAME=nonlib io/pwd io/pwd.o MODULE_NAME=nonlib locale/locale locale/locale.o MODULE_NAME=locale_programs locale/locale-spec.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs locale/localedef locale/localedef.o MODULE_NAME=locale_programs locale/ld-ctype.o MODULE_NAME=locale_programs locale/ld-messages.o MODULE_NAME=locale_programs locale/ld-monetary.o MODULE_NAME=locale_programs locale/ld-numeric.o MODULE_NAME=locale_programs locale/ld-time.o MODULE_NAME=locale_programs locale/ld-paper.o MODULE_NAME=locale_programs locale/ld-name.o MODULE_NAME=locale_programs locale/ld-address.o MODULE_NAME=locale_programs locale/ld-telephone.o MODULE_NAME=locale_programs locale/ld-measurement.o MODULE_NAME=locale_programs locale/ld-identification.o MODULE_NAME=locale_programs locale/ld-collate.o MODULE_NAME=locale_programs locale/charmap.o MODULE_NAME=locale_programs locale/linereader.o MODULE_NAME=locale_programs locale/locfile.o MODULE_NAME=locale_programs locale/repertoire.o MODULE_NAME=locale_programs locale/locarchive.o MODULE_NAME=locale_programs locale/md5.o MODULE_NAME=locale_programs locale/charmap-dir.o MODULE_NAME=locale_programs locale/simple-hash.o MODULE_NAME=locale_programs locale/xmalloc.o MODULE_NAME=locale_programs locale/xstrdup.o MODULE_NAME=locale_programs locale/record-status.o MODULE_NAME=locale_programs locale/xasprintf.o MODULE_NAME=locale_programs catgets/gencat catgets/gencat.o MODULE_NAME=nonlib catgets/xmalloc.o MODULE_NAME=nonlib nss/makedb nss/makedb.o MODULE_NAME=nonlib nss/xmalloc.o MODULE_NAME=nonlib nss/hash-string.o MODULE_NAME=nonlib nss/getent nss/getent.o MODULE_NAME=nonlib posix/getconf posix/getconf.o MODULE_NAME=nonlib login/utmpdump login/utmpdump.o MODULE_NAME=nonlib debug/pcprofiledump debug/pcprofiledump.o MODULE_NAME=nonlib timezone/zic timezone/zic.o MODULE_NAME=nonlib timezone/zdump timezone/zdump.o MODULE_NAME=nonlib iconv/iconv_prog iconv/iconv_prog.o MODULE_NAME=nonlib iconv/iconv_charmap.o MODULE_NAME=iconvprogs iconv/charmap.o MODULE_NAME=iconvprogs iconv/charmap-dir.o MODULE_NAME=iconvprogs iconv/linereader.o MODULE_NAME=iconvprogs iconv/dummy-repertoire.o MODULE_NAME=iconvprogs iconv/simple-hash.o MODULE_NAME=iconvprogs iconv/xstrdup.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/record-status.o MODULE_NAME=iconvprogs iconv/iconvconfig iconv/iconvconfig.o MODULE_NAME=nonlib iconv/strtab.o MODULE_NAME=iconvprogs iconv/xmalloc.o MODULE_NAME=iconvprogs iconv/hash-string.o MODULE_NAME=iconvprogs nss/libnss_files.so MODULE_NAME=libnss_files nss/libnss_compat.so.2 MODULE_NAME=libnss_compat nss/libnss_db.so MODULE_NAME=libnss_db hesiod/libnss_hesiod.so MODULE_NAME=libnss_hesiod login/libutil.so MODULE_NAME=libutil debug/libpcprofile.so MODULE_NAME=libpcprofile debug/libSegFault.so MODULE_NAME=libSegFault Also, to avoid adding both LFS and 64 bit time support on internal tests they are moved to a newer 'testsuite-internal' module. It should be similar to 'nonlib' regarding internal definition and linking namespace. This patch also enables LFS and 64 bit support of libsupport container programs (echo-container, test-container, shell-container, and true-container). Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: DJ Delorie <dj@redhat.com> (cherry picked from commit a6d2f948b71adcb5ea395cb04833bc645eab45e6)
2021-05-20 17:20:18 +00:00
out_fd = fcntl64 (STDERR_FILENO, F_DUPFD, 1000);
2011-05-28 17:20:12 +00:00
if (out_fd == -1)
out_fd = dup (STDERR_FILENO);
}
if (out_fd != -1)
{
/* Convert file descriptor into a stream. */
out_file = fdopen (out_fd, "w");
if (out_file != NULL)
setlinebuf (out_file);
}
}
/* Audit interface verification. We also initialize everything if
everything checks out OK. */
unsigned int
la_version (unsigned int v)
{
if (v != LAV_CURRENT)
error (1, 0, "cannot handle interface version %u", v);
init ();
return v;
}
/* Check whether a file name is on the colon-separated list of file
names. */
static unsigned int
match_file (const char *list, const char *name, size_t name_len,
unsigned int mask)
{
if (list[0] == '\0')
return 0;
const char *cp = list;
while (1)
{
if (strncmp (cp, name, name_len) == 0
&& (cp[name_len] == ':' || cp[name_len] == '\0'))
return mask;
cp = strchr (cp, ':');
if (cp == NULL)
return 0;
++cp;
}
}
unsigned int
la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
{
if (out_file == NULL)
return 0;
const char *full_name = map->l_name ?: "";
if (full_name[0] == '\0')
full_name = __progname_full;
size_t full_name_len = strlen (full_name);
const char *base_name = basename (full_name);
if (base_name[0] == '\0')
base_name = __progname;
size_t base_name_len = strlen (base_name);
int result = 0;
const char *print_name = NULL;
for (struct libname_list *l = map->l_libname; l != NULL; l = l->next)
{
if (print_name == NULL || (print_name[0] == '/' && l->name[0] != '/'))
print_name = l->name;
if (fromlist != NULL)
result |= match_file (fromlist, l->name, strlen (l->name),
LA_FLG_BINDFROM);
if (tolist != NULL)
result |= match_file (tolist, l->name, strlen (l->name),LA_FLG_BINDTO);
}
if (print_name == NULL)
print_name = base_name;
if (print_name[0] == '\0')
print_name = __progname;
/* We cannot easily get to the object name in the PLT handling
functions. Use the cookie to get the string pointer passed back
to us. */
*cookie = (uintptr_t) print_name;
/* The object name has to be on the list of objects to trace calls
from or that list must be empty. In the latter case we trace
only calls from the main binary. */
if (fromlist == NULL)
result |= map->l_name[0] == '\0' ? LA_FLG_BINDFROM : 0;
else
result |= (match_file (fromlist, full_name, full_name_len,
LA_FLG_BINDFROM)
| match_file (fromlist, base_name, base_name_len,
LA_FLG_BINDFROM));
/* The object name has to be on the list of objects to trace calls
to or that list must be empty. In the latter case we trace
calls toall objects. */
if (tolist == NULL)
result |= LA_FLG_BINDTO;
else
result |= (match_file (tolist, full_name, full_name_len, LA_FLG_BINDTO)
| match_file (tolist, base_name, base_name_len, LA_FLG_BINDTO));
return result;
}
#if __ELF_NATIVE_CLASS == 32
# define la_symbind la_symbind32
typedef Elf32_Sym Elf_Sym;
#else
# define la_symbind la_symbind64
typedef Elf64_Sym Elf_Sym;
#endif
uintptr_t
la_symbind (Elf_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, unsigned int *flags, const char *symname)
{
if (*flags & LA_SYMB_NOPLTENTER)
warnx ("cannot trace PLT enter (bind-now enabled)");
if (do_exit && *flags & LA_SYMB_NOPLTEXIT)
warnx ("cannot trace PLT exit (bind-now enabled)");
2011-05-28 17:20:12 +00:00
if (!do_exit)
*flags = LA_SYMB_NOPLTEXIT;
return sym->st_value;
}
static void
print_enter (uintptr_t *refcook, uintptr_t *defcook, const char *symname,
unsigned long int reg1, unsigned long int reg2,
unsigned long int reg3, unsigned int flags)
{
char buf[3 * sizeof (pid_t) + 3];
buf[0] = '\0';
if (print_pid)
snprintf (buf, sizeof (buf), "%5ld: ", (long int) getpid ());
fprintf (out_file, "%s%15s -> %-15s:%s%s(0x%lx, 0x%lx, 0x%lx)\n",
buf, (char *) *refcook, (char *) *defcook,
(flags & LA_SYMB_NOPLTEXIT) ? "*" : " ", symname, reg1, reg2, reg3);
}
#ifdef __i386__
Elf32_Addr
la_i86_gnu_pltenter (Elf32_Sym *sym __attribute__ ((unused)),
unsigned int ndx __attribute__ ((unused)),
uintptr_t *refcook, uintptr_t *defcook,
La_i86_regs *regs, unsigned int *flags,
const char *symname, long int *framesizep)
{
unsigned long int *sp = (unsigned long int *) regs->lr_esp;
print_enter (refcook, defcook, symname, sp[1], sp[2], sp[3], *flags);
/* No need to copy anything, we will not need the parameters in any case. */
*framesizep = 0;
return sym->st_value;
}
#elif defined __x86_64__
Elf64_Addr
la_x86_64_gnu_pltenter (Elf64_Sym *sym __attribute__ ((unused)),
unsigned int ndx __attribute__ ((unused)),
uintptr_t *refcook, uintptr_t *defcook,
La_x86_64_regs *regs, unsigned int *flags,
const char *symname, long int *framesizep)
{
print_enter (refcook, defcook, symname,
regs->lr_rdi, regs->lr_rsi, regs->lr_rdx, *flags);
/* No need to copy anything, we will not need the parameters in any case. */
*framesizep = 0;
return sym->st_value;
}
#elif defined __sparc__ && !defined __arch64__
Elf32_Addr
la_sparc32_gnu_pltenter (Elf32_Sym *sym __attribute__ ((unused)),
unsigned int ndx __attribute__ ((unused)),
uintptr_t *refcook, uintptr_t *defcook,
La_sparc32_regs *regs, unsigned int *flags,
const char *symname, long int *framesizep)
{
print_enter (refcook, defcook, symname,
regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2],
*flags);
/* No need to copy anything, we will not need the parameters in any case. */
*framesizep = 0;
return sym->st_value;
}
#elif defined __sparc__ && defined __arch64__
Elf64_Addr
la_sparc64_gnu_pltenter (Elf64_Sym *sym __attribute__ ((unused)),
unsigned int ndx __attribute__ ((unused)),
uintptr_t *refcook, uintptr_t *defcook,
La_sparc64_regs *regs, unsigned int *flags,
const char *symname, long int *framesizep)
{
print_enter (refcook, defcook, symname,
regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2],
*flags);
/* No need to copy anything, we will not need the parameters in any case. */
*framesizep = 0;
return sym->st_value;
}
2011-05-28 17:20:12 +00:00
#elif !defined HAVE_ARCH_PLTENTER
# warning "pltenter for architecture not supported"
#endif
static void
print_exit (uintptr_t *refcook, uintptr_t *defcook, const char *symname,
unsigned long int reg)
{
char buf[3 * sizeof (pid_t) + 3];
buf[0] = '\0';
if (print_pid)
snprintf (buf, sizeof (buf), "%5ld: ", (long int) getpid ());
fprintf (out_file, "%s%15s -> %-15s:%s%s - 0x%lx\n",
2011-05-28 17:20:12 +00:00
buf, (char *) *refcook, (char *) *defcook, " ", symname, reg);
}
#ifdef __i386__
unsigned int
la_i86_gnu_pltexit (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, const struct La_i86_regs *inregs,
struct La_i86_retval *outregs, const char *symname)
{
print_exit (refcook, defcook, symname, outregs->lrv_eax);
return 0;
}
#elif defined __x86_64__
unsigned int
la_x86_64_gnu_pltexit (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, const struct La_x86_64_regs *inregs,
struct La_x86_64_retval *outregs, const char *symname)
{
print_exit (refcook, defcook, symname, outregs->lrv_rax);
return 0;
}
#elif defined __sparc__ && !defined __arch64__
unsigned int
la_sparc32_gnu_pltexit (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, const struct La_sparc32_regs *inregs,
struct La_sparc32_retval *outregs, const char *symname)
{
print_exit (refcook, defcook, symname, outregs->lrv_reg[0]);
return 0;
}
#elif defined __sparc__ && defined __arch64__
unsigned int
la_sparc64_gnu_pltexit (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
uintptr_t *defcook, const struct La_sparc64_regs *inregs,
struct La_sparc64_retval *outregs, const char *symname)
{
print_exit (refcook, defcook, symname, outregs->lrv_reg[0]);
return 0;
}
2011-05-28 17:20:12 +00:00
#elif !defined HAVE_ARCH_PLTEXIT
# warning "pltexit for architecture not supported"
#endif