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