xref: /onnv-gate/usr/src/cmd/sgs/link_audit/common/symbindrep.c (revision 12927:a27c46eb192b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*12927SRod.Evans@Sun.COM  * Common Development and Distribution License (the "License").
6*12927SRod.Evans@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*12927SRod.Evans@Sun.COM 
220Sstevel@tonic-gate /*
23*12927SRod.Evans@Sun.COM  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate #include <stdio.h>
260Sstevel@tonic-gate #include <stdlib.h>
270Sstevel@tonic-gate #include <link.h>
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include "env.h"
300Sstevel@tonic-gate 
31*12927SRod.Evans@Sun.COM static Elist	*bindto_list = NULL;
32*12927SRod.Evans@Sun.COM static Elist	*bindfrom_list = NULL;
330Sstevel@tonic-gate static FILE	*output = stdout;
340Sstevel@tonic-gate 
350Sstevel@tonic-gate 
360Sstevel@tonic-gate uint_t
la_version(uint_t version)370Sstevel@tonic-gate la_version(uint_t version)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	if (version < LAV_CURRENT) {
400Sstevel@tonic-gate 		(void) fprintf(stderr,
41*12927SRod.Evans@Sun.COM 		    "symbindrep.so: unexpected version: %d\n", version);
420Sstevel@tonic-gate 		return (0);
430Sstevel@tonic-gate 	}
440Sstevel@tonic-gate 
450Sstevel@tonic-gate 	build_env_list(&bindto_list, (const char *)"SYMBINDREP_BINDTO");
460Sstevel@tonic-gate 	build_env_list(&bindfrom_list, (const char *)"SYMBINDREP_BINDFROM");
470Sstevel@tonic-gate 
48*12927SRod.Evans@Sun.COM #ifdef _LP64
490Sstevel@tonic-gate 	(void) fprintf(output,
50*12927SRod.Evans@Sun.COM 	    "                            Symbol Bindings\n\n"
51*12927SRod.Evans@Sun.COM 	    "Referencing                  Defining\n"
52*12927SRod.Evans@Sun.COM 	    "Object                       Object                       Symbol\n"
53*12927SRod.Evans@Sun.COM 	    "---------------------------------------------------------------"
54*12927SRod.Evans@Sun.COM 	    "-------------------\n");
550Sstevel@tonic-gate #else
56*12927SRod.Evans@Sun.COM 	(void) fprintf(output,
57*12927SRod.Evans@Sun.COM 	    "                    Symbol Bindings\n\n"
58*12927SRod.Evans@Sun.COM 	    "Referencing          Defining\n"
59*12927SRod.Evans@Sun.COM 	    "Object               Object               Symbol\n"
60*12927SRod.Evans@Sun.COM 	    "---------------------------------------------------------------"
61*12927SRod.Evans@Sun.COM 	    "---\n");
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate 	return (LAV_CURRENT);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /* ARGSUSED1 */
670Sstevel@tonic-gate uint_t
la_objopen(Link_map * lmp,Lmid_t lmid,uintptr_t * cookie)680Sstevel@tonic-gate la_objopen(Link_map *lmp, Lmid_t lmid, uintptr_t *cookie)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate 	uint_t		flags;
710Sstevel@tonic-gate 
72*12927SRod.Evans@Sun.COM 	if ((bindto_list == NULL) ||
730Sstevel@tonic-gate 	    (check_list(bindto_list, lmp->l_name)))
740Sstevel@tonic-gate 		flags = LA_FLG_BINDTO;
750Sstevel@tonic-gate 	else
760Sstevel@tonic-gate 		flags = 0;
770Sstevel@tonic-gate 
78*12927SRod.Evans@Sun.COM 	if ((bindfrom_list == NULL) ||
790Sstevel@tonic-gate 	    (check_list(bindfrom_list, lmp->l_name)))
800Sstevel@tonic-gate 		flags |= LA_FLG_BINDFROM;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	*cookie = (uintptr_t)lmp->l_name;
830Sstevel@tonic-gate 	return (flags);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /* ARGSUSED1 */
880Sstevel@tonic-gate #if	defined(_LP64)
890Sstevel@tonic-gate uintptr_t
la_symbind64(Elf64_Sym * symp,uint_t symndx,uintptr_t * refcook,uintptr_t * defcook,uint_t * sb_flags,const char * sym_name)900Sstevel@tonic-gate la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook,
910Sstevel@tonic-gate 	uintptr_t *defcook, uint_t *sb_flags, const char *sym_name)
920Sstevel@tonic-gate #else
930Sstevel@tonic-gate uintptr_t
940Sstevel@tonic-gate la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook,
950Sstevel@tonic-gate 	uintptr_t *defcook, uint_t *sb_flags)
960Sstevel@tonic-gate #endif
970Sstevel@tonic-gate {
980Sstevel@tonic-gate #if	!defined(_LP64)
990Sstevel@tonic-gate 	const char	*sym_name = (const char *)symp->st_name;
1000Sstevel@tonic-gate #endif
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	(void) fprintf(output, "%-28s %-28s %s\n", (char *)(*refcook),
1030Sstevel@tonic-gate 		(char *)(*defcook), sym_name);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	return (symp->st_value);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * Since we only want to report on the symbol bindings for this
1100Sstevel@tonic-gate  * process and we *do not* want the actual program to run we exit
1110Sstevel@tonic-gate  * at this point.
1120Sstevel@tonic-gate  */
1130Sstevel@tonic-gate /* ARGSUSED0 */
1140Sstevel@tonic-gate void
la_preinit(uintptr_t * cookie)1150Sstevel@tonic-gate la_preinit(uintptr_t *cookie)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	(void) fflush(output);
1180Sstevel@tonic-gate 	exit(0);
1190Sstevel@tonic-gate }
120