1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _STATIC_PROF_H 28*7c478bd9Sstevel@tonic-gate #define _STATIC_PROF_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * include headers 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include <stdio.h> 41*7c478bd9Sstevel@tonic-gate #include <string.h> 42*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 43*7c478bd9Sstevel@tonic-gate #include <unistd.h> 44*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 45*7c478bd9Sstevel@tonic-gate #include <libelf.h> 46*7c478bd9Sstevel@tonic-gate #include <link.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 49*7c478bd9Sstevel@tonic-gate #include <errno.h> 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * Declaration of global variables 53*7c478bd9Sstevel@tonic-gate */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #define DEFBKTS 24997 /* 3571 nice big prime number */ 56*7c478bd9Sstevel@tonic-gate #define MASK (~(unsigned long)0<<28) 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * bucket struct of hash table 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate typedef struct binding_bucket 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate char *sym; 64*7c478bd9Sstevel@tonic-gate char *ref_lib; 65*7c478bd9Sstevel@tonic-gate char *def_lib; 66*7c478bd9Sstevel@tonic-gate char *obj; 67*7c478bd9Sstevel@tonic-gate char *section; 68*7c478bd9Sstevel@tonic-gate char *sttype; 69*7c478bd9Sstevel@tonic-gate char *stbind; 70*7c478bd9Sstevel@tonic-gate } binding_bucket; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate static binding_bucket bkts[DEFBKTS]; 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate /* 75*7c478bd9Sstevel@tonic-gate * data structure for linked list of DT_NEEDED entries 76*7c478bd9Sstevel@tonic-gate */ 77*7c478bd9Sstevel@tonic-gate typedef struct dt_list_tag 78*7c478bd9Sstevel@tonic-gate { 79*7c478bd9Sstevel@tonic-gate char *libname; 80*7c478bd9Sstevel@tonic-gate #if defined(_LP64) 81*7c478bd9Sstevel@tonic-gate Elf64_Sword d_tag; 82*7c478bd9Sstevel@tonic-gate #else 83*7c478bd9Sstevel@tonic-gate Elf32_Sword d_tag; 84*7c478bd9Sstevel@tonic-gate #endif 85*7c478bd9Sstevel@tonic-gate struct dt_list_tag *next; 86*7c478bd9Sstevel@tonic-gate } dt_list; 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate static dt_list *dt_needed = NULL; /* ptr to link list of dtneeded */ 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* 91*7c478bd9Sstevel@tonic-gate * struct for the binary object under test 92*7c478bd9Sstevel@tonic-gate */ 93*7c478bd9Sstevel@tonic-gate typedef struct obj_com 94*7c478bd9Sstevel@tonic-gate { 95*7c478bd9Sstevel@tonic-gate char **filenames; /* name of application file */ 96*7c478bd9Sstevel@tonic-gate char *filename; 97*7c478bd9Sstevel@tonic-gate int numfiles; /* number of applications to check */ 98*7c478bd9Sstevel@tonic-gate /* ---Current application ELF file information--- */ 99*7c478bd9Sstevel@tonic-gate char *ename; /* name of current ELF file */ 100*7c478bd9Sstevel@tonic-gate int fd; /* file descriptor for current file */ 101*7c478bd9Sstevel@tonic-gate Elf *elf; /* elf descriptor for current file */ 102*7c478bd9Sstevel@tonic-gate #if defined(_LP64) 103*7c478bd9Sstevel@tonic-gate Elf64_Ehdr *ehdr; /* 64 bit elf header for current file */ 104*7c478bd9Sstevel@tonic-gate Elf64_Phdr *phdr; /* 64 bit prog header for current file */ 105*7c478bd9Sstevel@tonic-gate Elf64_Dyn *dynsect; /* pointer to 64 bit dynamic section */ 106*7c478bd9Sstevel@tonic-gate #else 107*7c478bd9Sstevel@tonic-gate Elf32_Ehdr *ehdr; /* 32 bit elf header for current file */ 108*7c478bd9Sstevel@tonic-gate Elf32_Phdr *phdr; /* 32 bit prog header for current file */ 109*7c478bd9Sstevel@tonic-gate Elf32_Dyn *dynsect; /* ptr to 64 bit dynamic section */ 110*7c478bd9Sstevel@tonic-gate #endif 111*7c478bd9Sstevel@tonic-gate Elf_Data *ddata; /* ptr to dstring table data descriptor */ 112*7c478bd9Sstevel@tonic-gate char *dynnames; /* pointer to dynamic string table */ 113*7c478bd9Sstevel@tonic-gate /* ---ELF file symbol table information--- */ 114*7c478bd9Sstevel@tonic-gate /* dynamic symbol table */ 115*7c478bd9Sstevel@tonic-gate #if defined(_LP64) 116*7c478bd9Sstevel@tonic-gate Elf64_Sym *dsym_tab; 117*7c478bd9Sstevel@tonic-gate #else 118*7c478bd9Sstevel@tonic-gate Elf32_Sym *dsym_tab; 119*7c478bd9Sstevel@tonic-gate #endif 120*7c478bd9Sstevel@tonic-gate Elf_Data *dsym_data; 121*7c478bd9Sstevel@tonic-gate int dsym_num; 122*7c478bd9Sstevel@tonic-gate char *dsym_names; 123*7c478bd9Sstevel@tonic-gate /* regular symbol table */ 124*7c478bd9Sstevel@tonic-gate #if defined(_LP64) 125*7c478bd9Sstevel@tonic-gate Elf64_Sym *sym_tab; 126*7c478bd9Sstevel@tonic-gate #else 127*7c478bd9Sstevel@tonic-gate Elf32_Sym *sym_tab; 128*7c478bd9Sstevel@tonic-gate #endif 129*7c478bd9Sstevel@tonic-gate Elf_Data *sym_data; 130*7c478bd9Sstevel@tonic-gate int sym_num; 131*7c478bd9Sstevel@tonic-gate char *sym_names; 132*7c478bd9Sstevel@tonic-gate } obj_com; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * struct of the linked list of object files 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate typedef struct obj_list_tag 138*7c478bd9Sstevel@tonic-gate { 139*7c478bd9Sstevel@tonic-gate obj_com *obj; 140*7c478bd9Sstevel@tonic-gate struct obj_list_tag *next; 141*7c478bd9Sstevel@tonic-gate } obj_list; 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate static int oflag = 0; /* flag for redirecting output */ 144*7c478bd9Sstevel@tonic-gate static int pflag = 0; /* flag for profiling to stdout */ 145*7c478bd9Sstevel@tonic-gate static int sflag = 1; /* flag for silent mode */ 146*7c478bd9Sstevel@tonic-gate static int aflag = 1; /* flag for read input as archive */ 147*7c478bd9Sstevel@tonic-gate extern int errno; /* file opening error return code */ 148*7c478bd9Sstevel@tonic-gate static FILE *OUTPUT_FD = stdout; /* output fd: default as stdout */ 149*7c478bd9Sstevel@tonic-gate static char *outputfile; /* full pathname of output file */ 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate #define SUCCEED 0 152*7c478bd9Sstevel@tonic-gate #define FAIL 1 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate #define TRUE 1 155*7c478bd9Sstevel@tonic-gate #define FALSE 0 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate #endif 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate #endif /* _STATIC_PROF_H */ 162