xref: /titanic_51/usr/src/cmd/sgs/link_audit/common/symbindrep.c (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <link.h>
33 
34 #include "env.h"
35 
36 static Elist	*bindto_list = 0;
37 static Elist	*bindfrom_list = 0;
38 static FILE	*output = stdout;
39 
40 
41 uint_t
42 la_version(uint_t version)
43 {
44 	if (version < LAV_CURRENT) {
45 		(void) fprintf(stderr,
46 			"symbindrep.so: unexpected version: %d\n",
47 			version);
48 		return (0);
49 	}
50 
51 	build_env_list(&bindto_list, (const char *)"SYMBINDREP_BINDTO");
52 	build_env_list(&bindfrom_list, (const char *)"SYMBINDREP_BINDFROM");
53 
54 	(void) fprintf(output,
55 #ifdef _LP64
56 	"                            Symbol Bindings\n\n"
57 	"Referencing                  Defining\n"
58 	"Object                       Object                       Symbol\n"
59 	/* CSTYLED */
60 	"----------------------------------------------------------------------------------\n");
61 #else
62 	"                    Symbol Bindings\n\n"
63 	"Referencing          Defining\n"
64 	"Object               Object               Symbol\n"
65 	"------------------------------------------------------------------\n");
66 #endif
67 	return (LAV_CURRENT);
68 }
69 
70 
71 /* ARGSUSED1 */
72 uint_t
73 la_objopen(Link_map *lmp, Lmid_t lmid, uintptr_t *cookie)
74 {
75 	uint_t		flags;
76 
77 	if ((bindto_list == 0) ||
78 	    (check_list(bindto_list, lmp->l_name)))
79 		flags = LA_FLG_BINDTO;
80 	else
81 		flags = 0;
82 
83 	if ((bindfrom_list == 0) ||
84 	    (check_list(bindfrom_list, lmp->l_name)))
85 		flags |= LA_FLG_BINDFROM;
86 
87 	*cookie = (uintptr_t)lmp->l_name;
88 	return (flags);
89 }
90 
91 
92 /* ARGSUSED1 */
93 #if	defined(_LP64)
94 uintptr_t
95 la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook,
96 	uintptr_t *defcook, uint_t *sb_flags, const char *sym_name)
97 #else
98 uintptr_t
99 la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook,
100 	uintptr_t *defcook, uint_t *sb_flags)
101 #endif
102 {
103 #if	!defined(_LP64)
104 	const char	*sym_name = (const char *)symp->st_name;
105 #endif
106 
107 	(void) fprintf(output, "%-28s %-28s %s\n", (char *)(*refcook),
108 		(char *)(*defcook), sym_name);
109 
110 	return (symp->st_value);
111 }
112 
113 /*
114  * Since we only want to report on the symbol bindings for this
115  * process and we *do not* want the actual program to run we exit
116  * at this point.
117  */
118 /* ARGSUSED0 */
119 void
120 la_preinit(uintptr_t *cookie)
121 {
122 	(void) fflush(output);
123 	exit(0);
124 }
125