xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/libs.c (revision d67944fbe3fa0b31893a7116a09b0718eecf6078)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #include	"msg.h"
27 #include	"_debug.h"
28 #include	"libld.h"
29 
30 void
31 Dbg_libs_audit(Lm_list *lml, const char *opath, const char *npath)
32 {
33 	if (DBG_NOTCLASS(DBG_C_LIBS | DBG_C_AUDITING))
34 		return;
35 
36 	if (npath == opath)
37 		return;
38 	else if (npath == 0)
39 		dbg_print(lml, MSG_INTL(MSG_LIB_SKIP), opath);
40 	else
41 		dbg_print(lml, MSG_INTL(MSG_LIB_ALTER), npath);
42 }
43 
44 void
45 Dbg_libs_find(Lm_list *lml, const char *name)
46 {
47 	if (DBG_NOTCLASS(DBG_C_LIBS))
48 		return;
49 
50 	Dbg_util_nl(lml, DBG_NL_STD);
51 	dbg_print(lml, MSG_INTL(MSG_LIB_FIND), name);
52 }
53 
54 void
55 Dbg_libs_found(Lm_list *lml, const char *path, int alter)
56 {
57 	if (DBG_NOTCLASS(DBG_C_LIBS))
58 		return;
59 
60 	dbg_print(lml, MSG_INTL(MSG_LIB_TRYING), path, alter ?
61 	    MSG_INTL(MSG_STR_ALTER) : MSG_ORIG(MSG_STR_EMPTY));
62 }
63 
64 void
65 Dbg_libs_insecure(Lm_list *lml, const char *path, int usable)
66 {
67 	if (DBG_NOTCLASS(DBG_C_LIBS))
68 		return;
69 
70 	if (usable)
71 		dbg_print(lml, MSG_INTL(MSG_LIB_INUSE), path);
72 	else
73 		dbg_print(lml, MSG_INTL(MSG_LIB_IGNORE), path);
74 }
75 
76 static void
77 Dbg_lib_dir_print(Lm_list *lml, APlist *libdir)
78 {
79 	Aliste	idx;
80 	char	*cp;
81 
82 	for (APLIST_TRAVERSE(libdir, idx, cp))
83 		dbg_print(lml, MSG_ORIG(MSG_LIB_FILE), cp);
84 }
85 
86 void
87 Dbg_libs_init(Lm_list *lml, APlist *ulibdir, APlist *dlibdir)
88 {
89 	if (DBG_NOTCLASS(DBG_C_LIBS))
90 		return;
91 
92 	dbg_print(lml, MSG_INTL(MSG_LIB_INITPATH));
93 	Dbg_lib_dir_print(lml, ulibdir);
94 	Dbg_lib_dir_print(lml, dlibdir);
95 }
96 
97 void
98 Dbg_libs_l(Lm_list *lml, const char *name, const char *path)
99 {
100 	if (DBG_NOTCLASS(DBG_C_LIBS))
101 		return;
102 	if (DBG_NOTDETAIL())
103 		return;
104 
105 	dbg_print(lml, MSG_INTL(MSG_LIB_LOPT), name, path);
106 }
107 
108 void
109 Dbg_libs_path(Lm_list *lml, const char *path, uint_t orig, const char *obj)
110 {
111 	const char	*fmt;
112 	uint_t		search;
113 
114 	if (path == NULL)
115 		return;
116 	if (DBG_NOTCLASS(DBG_C_LIBS))
117 		return;
118 
119 	search = orig &
120 	    (LA_SER_LIBPATH | LA_SER_RUNPATH | LA_SER_DEFAULT | LA_SER_SECURE);
121 
122 	switch (search) {
123 	case LA_SER_LIBPATH:
124 		if (orig & LA_SER_CONFIG)
125 			fmt = MSG_INTL(MSG_LIB_LDLIBPATHC);
126 		else
127 			fmt = MSG_INTL(MSG_LIB_LDLIBPATH);
128 		break;
129 
130 	case LA_SER_RUNPATH:
131 		fmt = MSG_INTL(MSG_LIB_RUNPATH);
132 		break;
133 
134 	case LA_SER_DEFAULT:
135 		if (orig & LA_SER_CONFIG)
136 			fmt = MSG_INTL(MSG_LIB_DEFAULTC);
137 		else
138 			fmt = MSG_INTL(MSG_LIB_DEFAULT);
139 		break;
140 
141 	case LA_SER_SECURE:
142 		if (orig & LA_SER_CONFIG)
143 			fmt = MSG_INTL(MSG_LIB_TDEFAULTC);
144 		else
145 			fmt = MSG_INTL(MSG_LIB_TDEFAULT);
146 		break;
147 
148 	default:
149 		return;
150 	}
151 
152 	dbg_print(lml, fmt, path, obj);
153 }
154 
155 void
156 Dbg_libs_req(Lm_list *lml, const char *so_name, const char *ref_file,
157     const char *name)
158 {
159 	if (DBG_NOTCLASS(DBG_C_LIBS))
160 		return;
161 	if (DBG_NOTDETAIL())
162 		return;
163 
164 	dbg_print(lml, MSG_INTL(MSG_LIB_REQUIRED), so_name, name, ref_file);
165 }
166 
167 void
168 Dbg_libs_update(Lm_list *lml, APlist *ulibdir, APlist *dlibdir)
169 {
170 	if (DBG_NOTCLASS(DBG_C_LIBS))
171 		return;
172 
173 	dbg_print(lml, MSG_INTL(MSG_LIB_UPPATH));
174 	Dbg_lib_dir_print(lml, ulibdir);
175 	Dbg_lib_dir_print(lml, dlibdir);
176 }
177 
178 void
179 Dbg_libs_yp(Lm_list *lml, const char *path)
180 {
181 	if (DBG_NOTCLASS(DBG_C_LIBS))
182 		return;
183 
184 	dbg_print(lml, MSG_INTL(MSG_LIB_LIBPATH), path);
185 }
186 
187 void
188 Dbg_libs_ylu(Lm_list *lml, const char *path, const char *orig, int index)
189 {
190 	if (DBG_NOTCLASS(DBG_C_LIBS))
191 		return;
192 
193 	dbg_print(lml, MSG_INTL(MSG_LIB_YPATH), path, orig,
194 	    (index == YLDIR) ? 'L' : 'U');
195 }
196