xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/dynamic.c (revision 29e362da24db33a6650152985ef5626b4e6a810f)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * String conversion routine for .dynamic tag entries.
30  */
31 #include	<stdio.h>
32 #include	<string.h>
33 #include	<sys/elf_SPARC.h>
34 #include	"rtld.h"
35 #include	"_conv.h"
36 #include	"dynamic_msg.h"
37 
38 #define	POSSZ	MSG_GBL_OSQBRKT_SIZE + \
39 		MSG_DFP_LAZYLOAD_SIZE + \
40 		MSG_DFP_GROUPPERM_SIZE + \
41 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
42 
43 const char *
44 conv_dyn_posflag1(Xword flags)
45 {
46 	static char	string[POSSZ];
47 	static Val_desc vda[] = {
48 		{ DF_P1_LAZYLOAD,	MSG_ORIG(MSG_DFP_LAZYLOAD) },
49 		{ DF_P1_GROUPPERM,	MSG_ORIG(MSG_DFP_GROUPPERM) },
50 		{ 0,			0 }
51 	};
52 
53 	if (flags == 0)
54 		return (MSG_ORIG(MSG_GBL_ZERO));
55 
56 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), POSSZ);
57 	if (conv_expn_field(string, POSSZ, vda, flags, flags, 0, 0))
58 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), POSSZ);
59 
60 	return ((const char *)string);
61 }
62 
63 #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
64 		MSG_DF_ORIGIN_SIZE + \
65 		MSG_DF_SYMBOLIC_SIZE + \
66 		MSG_DF_TEXTREL_SIZE + \
67 		MSG_DF_BIND_NOW_SIZE + \
68 		MSG_DF_STATIC_TLS_SIZE + \
69 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
70 
71 const char *
72 conv_dyn_flag(Xword flags)
73 {
74 	static char	string[FLAGSZ];
75 	static Val_desc vda[] = {
76 		{ DF_ORIGIN,		MSG_ORIG(MSG_DF_ORIGIN) },
77 		{ DF_SYMBOLIC,		MSG_ORIG(MSG_DF_SYMBOLIC) },
78 		{ DF_TEXTREL,		MSG_ORIG(MSG_DF_TEXTREL) },
79 		{ DF_BIND_NOW,		MSG_ORIG(MSG_DF_BIND_NOW) },
80 		{ DF_STATIC_TLS,	MSG_ORIG(MSG_DF_STATIC_TLS) },
81 		{ 0,			0 }
82 	};
83 
84 	if (flags == 0)
85 		return (MSG_ORIG(MSG_GBL_ZERO));
86 
87 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ);
88 	if (conv_expn_field(string, FLAGSZ, vda, flags, flags, 0, 0))
89 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
90 
91 	return ((const char *)string);
92 }
93 
94 #define	FLAG1SZ	MSG_GBL_OSQBRKT_SIZE + \
95 		MSG_DF1_NOW_SIZE + \
96 		MSG_DF1_GLOBAL_SIZE + \
97 		MSG_DF1_GROUP_SIZE + \
98 		MSG_DF1_NODELETE_SIZE + \
99 		MSG_DF1_LOADFLTR_SIZE + \
100 		MSG_DF1_INITFIRST_SIZE + \
101 		MSG_DF1_NOOPEN_SIZE + \
102 		MSG_DF1_ORIGIN_SIZE + \
103 		MSG_DF1_DIRECT_SIZE + \
104 		MSG_DF1_TRANS_SIZE + \
105 		MSG_DF1_INTERPOSE_SIZE + \
106 		MSG_DF1_NODEFLIB_SIZE + \
107 		MSG_DF1_NODUMP_SIZE + \
108 		MSG_DF1_CONFALT_SIZE + \
109 		MSG_DF1_ENDFILTEE_SIZE + \
110 		MSG_DF1_DISPRELPND_SIZE + \
111 		MSG_DF1_DISPRELDNE_SIZE + \
112 		MSG_DF1_NODIRECT_SIZE + \
113 		MSG_DF1_IGNMULDEF_SIZE + \
114 		MSG_DF1_NOKSYMS_SIZE + \
115 		MSG_DF1_NORELOC_SIZE + \
116 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
117 
118 const char *
119 conv_dyn_flag1(Xword flags)
120 {
121 	static char	string[FLAG1SZ];
122 	static Val_desc vda[] = {
123 		{ DF_1_NOW,		MSG_ORIG(MSG_DF_ORIGIN) },
124 		{ DF_1_GLOBAL,		MSG_ORIG(MSG_DF1_GLOBAL) },
125 		{ DF_1_GROUP,		MSG_ORIG(MSG_DF1_GROUP) },
126 		{ DF_1_NODELETE,	MSG_ORIG(MSG_DF1_NODELETE) },
127 		{ DF_1_LOADFLTR,	MSG_ORIG(MSG_DF1_LOADFLTR) },
128 		{ DF_1_INITFIRST,	MSG_ORIG(MSG_DF1_INITFIRST) },
129 		{ DF_1_NOOPEN,		MSG_ORIG(MSG_DF1_NOOPEN) },
130 		{ DF_1_ORIGIN,		MSG_ORIG(MSG_DF1_ORIGIN) },
131 		{ DF_1_DIRECT,		MSG_ORIG(MSG_DF1_DIRECT) },
132 		{ DF_1_TRANS,		MSG_ORIG(MSG_DF1_TRANS) },
133 		{ DF_1_INTERPOSE,	MSG_ORIG(MSG_DF1_INTERPOSE) },
134 		{ DF_1_NODEFLIB,	MSG_ORIG(MSG_DF1_NODEFLIB) },
135 		{ DF_1_NODUMP,		MSG_ORIG(MSG_DF1_NODUMP) },
136 		{ DF_1_CONFALT,		MSG_ORIG(MSG_DF1_CONFALT) },
137 		{ DF_1_ENDFILTEE,	MSG_ORIG(MSG_DF1_ENDFILTEE) },
138 		{ DF_1_DISPRELPND,	MSG_ORIG(MSG_DF1_DISPRELPND) },
139 		{ DF_1_DISPRELDNE,	MSG_ORIG(MSG_DF1_DISPRELDNE) },
140 		{ DF_1_NODIRECT,	MSG_ORIG(MSG_DF1_NODIRECT) },
141 		{ DF_1_IGNMULDEF,	MSG_ORIG(MSG_DF1_IGNMULDEF) },
142 		{ DF_1_NOKSYMS,		MSG_ORIG(MSG_DF1_NOKSYMS) },
143 		{ DF_1_NORELOC,		MSG_ORIG(MSG_DF1_NORELOC) },
144 		{ 0,			0 }
145 	};
146 
147 	if (flags == 0)
148 		return (MSG_ORIG(MSG_GBL_ZERO));
149 
150 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FLAG1SZ);
151 	if (conv_expn_field(string, FLAG1SZ, vda, flags, flags, 0, 0))
152 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAG1SZ);
153 
154 	return ((const char *)string);
155 }
156 
157 #define	FEATSZ	MSG_GBL_OSQBRKT_SIZE + \
158 		MSG_DTF_PARINIT_SIZE + \
159 		MSG_DTF_CONFEXP_SIZE + \
160 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
161 
162 const char *
163 conv_dyn_feature1(Xword flags)
164 {
165 	static char	string[FEATSZ];
166 	static Val_desc vda[] = {
167 		{ DTF_1_PARINIT,	MSG_ORIG(MSG_DTF_PARINIT) },
168 		{ DTF_1_CONFEXP,	MSG_ORIG(MSG_DTF_CONFEXP) },
169 		{ 0,			0 }
170 	};
171 
172 	if (flags == 0)
173 		return (MSG_ORIG(MSG_GBL_ZERO));
174 
175 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FEATSZ);
176 	if (conv_expn_field(string, FEATSZ, vda, flags, flags, 0, 0))
177 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FEATSZ);
178 
179 	return ((const char *)string);
180 }
181 
182 const char *
183 conv_dyn_tag(Xword tag, Half mach)
184 {
185 	static char		string[CONV_INV_STRSIZE];
186 	static const Msg	tags[DT_MAXPOSTAGS] = {
187 		MSG_DYN_NULL,		MSG_DYN_NEEDED,
188 		MSG_DYN_PLTRELSZ,	MSG_DYN_PLTGOT,
189 		MSG_DYN_HASH,		MSG_DYN_STRTAB,
190 		MSG_DYN_SYMTAB,		MSG_DYN_RELA,
191 		MSG_DYN_RELASZ,		MSG_DYN_RELAENT,
192 		MSG_DYN_STRSZ,		MSG_DYN_SYMENT,
193 		MSG_DYN_INIT,		MSG_DYN_FINI,
194 		MSG_DYN_SONAME,		MSG_DYN_RPATH,
195 		MSG_DYN_SYMBOLIC,	MSG_DYN_REL,
196 		MSG_DYN_RELSZ,		MSG_DYN_RELENT,
197 		MSG_DYN_PLTREL,		MSG_DYN_DEBUG,
198 		MSG_DYN_TEXTREL,	MSG_DYN_JMPREL,
199 		MSG_DYN_BIND_NOW,	MSG_DYN_INIT_ARRAY,
200 		MSG_DYN_FINI_ARRAY,	MSG_DYN_INIT_ARRAYSZ,
201 		MSG_DYN_FINI_ARRAYSZ,	MSG_DYN_RUNPATH,
202 		MSG_DYN_FLAGS,		MSG_DYN_NULL,
203 		MSG_DYN_PREINIT_ARRAY,	MSG_DYN_PREINIT_ARRAYSZ
204 	};
205 
206 	if (tag < DT_MAXPOSTAGS) {
207 		/*
208 		 * Generic dynamic tags.
209 		 */
210 		return (MSG_ORIG(tags[tag]));
211 	} else {
212 		/*
213 		 * SUNW: DT_LOOS -> DT_HIOS range.
214 		 */
215 		if (tag == DT_SUNW_AUXILIARY)
216 			return (MSG_ORIG(MSG_DYN_SUNW_AUXILIARY));
217 		else if (tag == DT_SUNW_RTLDINF)
218 			return (MSG_ORIG(MSG_DYN_SUNW_RTLDINF));
219 		else if (tag == DT_SUNW_FILTER)
220 			return (MSG_ORIG(MSG_DYN_SUNW_FILTER));
221 		else if (tag == DT_SUNW_CAP)
222 			return (MSG_ORIG(MSG_DYN_SUNW_CAP));
223 
224 		/*
225 		 * SUNW: DT_VALRNGLO - DT_VALRNGHI range.
226 		 */
227 		else if (tag == DT_CHECKSUM)
228 			return (MSG_ORIG(MSG_DYN_CHECKSUM));
229 		else if (tag == DT_PLTPADSZ)
230 			return (MSG_ORIG(MSG_DYN_PLTPADSZ));
231 		else if (tag == DT_MOVEENT)
232 			return (MSG_ORIG(MSG_DYN_MOVEENT));
233 		else if (tag == DT_MOVESZ)
234 			return (MSG_ORIG(MSG_DYN_MOVESZ));
235 		else if (tag == DT_FEATURE_1)
236 			return (MSG_ORIG(MSG_DYN_FEATURE_1));
237 		else if (tag == DT_POSFLAG_1)
238 			return (MSG_ORIG(MSG_DYN_POSFLAG_1));
239 		else if (tag == DT_SYMINSZ)
240 			return (MSG_ORIG(MSG_DYN_SYMINSZ));
241 		else if (tag == DT_SYMINENT)
242 			return (MSG_ORIG(MSG_DYN_SYMINENT));
243 
244 		/*
245 		 * SUNW: DT_ADDRRNGLO - DT_ADDRRNGHI range.
246 		 */
247 		else if (tag == DT_CONFIG)
248 			return (MSG_ORIG(MSG_DYN_CONFIG));
249 		else if (tag == DT_DEPAUDIT)
250 			return (MSG_ORIG(MSG_DYN_DEPAUDIT));
251 		else if (tag == DT_AUDIT)
252 			return (MSG_ORIG(MSG_DYN_AUDIT));
253 		else if (tag == DT_PLTPAD)
254 			return (MSG_ORIG(MSG_DYN_PLTPAD));
255 		else if (tag == DT_MOVETAB)
256 			return (MSG_ORIG(MSG_DYN_MOVETAB));
257 		else if (tag == DT_SYMINFO)
258 			return (MSG_ORIG(MSG_DYN_SYMINFO));
259 
260 		/*
261 		 * SUNW: generic range.
262 		 */
263 		else if (tag == DT_VERSYM)
264 			return (MSG_ORIG(MSG_DYN_VERSYM));
265 		else if (tag == DT_RELACOUNT)
266 			return (MSG_ORIG(MSG_DYN_RELACOUNT));
267 		else if (tag == DT_RELCOUNT)
268 			return (MSG_ORIG(MSG_DYN_RELCOUNT));
269 		else if (tag == DT_FLAGS_1)
270 			return (MSG_ORIG(MSG_DYN_FLAGS_1));
271 		else if (tag == DT_VERDEF)
272 			return (MSG_ORIG(MSG_DYN_VERDEF));
273 		else if (tag == DT_VERDEFNUM)
274 			return (MSG_ORIG(MSG_DYN_VERDEFNUM));
275 		else if (tag == DT_VERNEED)
276 			return (MSG_ORIG(MSG_DYN_VERNEED));
277 		else if (tag == DT_VERNEEDNUM)
278 			return (MSG_ORIG(MSG_DYN_VERNEEDNUM));
279 		else if (tag == DT_AUXILIARY)
280 			return (MSG_ORIG(MSG_DYN_AUXILIARY));
281 		else if (tag == DT_USED)
282 			return (MSG_ORIG(MSG_DYN_USED));
283 		else if (tag == DT_FILTER)
284 			return (MSG_ORIG(MSG_DYN_FILTER));
285 
286 		/*
287 		 * SUNW: machine specific range.
288 		 */
289 		else if (((mach == EM_SPARC) || (mach == EM_SPARCV9) ||
290 		    (mach == EM_SPARC32PLUS)) && (tag == DT_SPARC_REGISTER))
291 			/* this is so x86 can display a sparc binary */
292 			return (MSG_ORIG(MSG_DYN_REGISTER));
293 		else if (tag == DT_DEPRECATED_SPARC_REGISTER)
294 			return (MSG_ORIG(MSG_DYN_REGISTER));
295 		else
296 			return (conv_invalid_val(string, CONV_INV_STRSIZE,
297 			    tag, 0));
298 	}
299 }
300 
301 #define	BINDTSZ	MSG_GBL_OSQBRKT_SIZE + \
302 		MSG_BND_NEEDED_SIZE + \
303 		MSG_BND_REFER_SIZE + \
304 		MSG_BND_FILTER_SIZE + \
305 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
306 
307 const char *
308 conv_bnd_type(uint_t flags)
309 {
310 	static char	string[BINDTSZ];
311 	static Val_desc vda[] = {
312 		{ BND_NEEDED,		MSG_ORIG(MSG_BND_NEEDED) },
313 		{ BND_REFER,		MSG_ORIG(MSG_BND_REFER) },
314 		{ BND_FILTER,		MSG_ORIG(MSG_BND_FILTER) },
315 		{ 0,			0 }
316 	};
317 
318 	if (flags == 0)
319 		return (MSG_ORIG(MSG_STR_EMPTY));
320 
321 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), BINDTSZ);
322 	if (conv_expn_field(string, BINDTSZ, vda, flags, flags, 0, 0))
323 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), BINDTSZ);
324 
325 	return ((const char *)string);
326 }
327 
328 #define	BINDOSZ	MSG_GBL_OSQBRKT_SIZE + \
329 		MSG_BND_ADDED_SIZE + \
330 		MSG_BND_REEVAL_SIZE + \
331 		MSG_GBL_CSQBRKT_SIZE
332 
333 const char *
334 conv_bnd_obj(uint_t flags)
335 {
336 	static char	string[BINDOSZ];
337 	static Val_desc vda[] = {
338 		{ LML_FLG_OBJADDED,	MSG_ORIG(MSG_BND_ADDED) },
339 		{ LML_FLG_OBJREEVAL,	MSG_ORIG(MSG_BND_REEVAL) },
340 		{ LML_FLG_OBJDELETED,	MSG_ORIG(MSG_BND_DELETED) },
341 		{ LML_FLG_ATEXIT,	MSG_ORIG(MSG_BND_ATEXIT) },
342 		{ 0,			0 }
343 	};
344 
345 	if (flags == 0)
346 		return (MSG_ORIG(MSG_STR_EMPTY));
347 
348 	/*
349 	 * Note, we're not worried about unknown flags for this family, only
350 	 * the selected flags are of interest.
351 	 */
352 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), BINDOSZ);
353 	if (conv_expn_field(string, BINDOSZ, vda, flags, 0, 0, 0))
354 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), BINDOSZ);
355 
356 	return ((const char *)string);
357 }
358