xref: /titanic_44/usr/src/cmd/sgs/libconv/common/dynamic.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2005 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	"_conv.h"
35 #include	"dynamic_msg.h"
36 
37 #define	POSSZ	MSG_GBL_OSQBRKT_SIZE + \
38 		MSG_DFP_LAZYLOAD_SIZE + \
39 		MSG_DFP_GROUPPERM_SIZE + \
40 		MSG_GBL_CSQBRKT_SIZE
41 
42 const char *
43 conv_dynposflag_1_str(uint_t flags)
44 {
45 	static char	string[POSSZ] = { '\0' };
46 	if (flags == 0)
47 		return (MSG_ORIG(MSG_GBL_ZERO));
48 
49 	(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
50 
51 	if (flags & DF_P1_LAZYLOAD)
52 		(void) strcat(string, MSG_ORIG(MSG_DFP_LAZYLOAD));
53 	if (flags & DF_P1_GROUPPERM)
54 		(void) strcat(string, MSG_ORIG(MSG_DFP_GROUPPERM));
55 
56 	(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
57 
58 	return ((const char *)string);
59 }
60 
61 #define	FLAGSZ	MSG_DF_ORIGIN_SIZE + \
62 		MSG_DF_SYMBOLIC_SIZE + \
63 		MSG_DF_TEXTREL_SIZE + \
64 		MSG_DF_BIND_NOW_SIZE + \
65 		MSG_DF_STATIC_TLS_SIZE
66 
67 const char *
68 conv_dynflag_str(uint_t flags)
69 {
70 	static char	string[FLAGSZ] = { '\0' };
71 	if (flags == 0)
72 		return (MSG_ORIG(MSG_GBL_ZERO));
73 	else {
74 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
75 		if (flags & DF_ORIGIN)
76 			(void) strcat(string, MSG_ORIG(MSG_DF_ORIGIN));
77 		if (flags & DF_SYMBOLIC)
78 			(void) strcat(string, MSG_ORIG(MSG_DF_SYMBOLIC));
79 		if (flags & DF_TEXTREL)
80 			(void) strcat(string, MSG_ORIG(MSG_DF_TEXTREL));
81 		if (flags & DF_BIND_NOW)
82 			(void) strcat(string, MSG_ORIG(MSG_DF_BIND_NOW));
83 		if (flags & DF_STATIC_TLS)
84 			(void) strcat(string, MSG_ORIG(MSG_DF_STATIC_TLS));
85 
86 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
87 
88 		return ((const char *)string);
89 	}
90 }
91 
92 #define	FLAG1SZ	MSG_GBL_OSQBRKT_SIZE + \
93 		MSG_DF1_NOW_SIZE + \
94 		MSG_DF1_GROUP_SIZE + \
95 		MSG_DF1_NODELETE_SIZE + \
96 		MSG_DF1_LOADFLTR_SIZE + \
97 		MSG_DF1_INITFIRST_SIZE + \
98 		MSG_DF1_NOOPEN_SIZE + \
99 		MSG_DF1_ORIGIN_SIZE + \
100 		MSG_DF1_DIRECT_SIZE + \
101 		MSG_DF1_TRANS_SIZE + \
102 		MSG_DF1_INTERPOSE_SIZE + \
103 		MSG_DF1_NODEFLIB_SIZE + \
104 		MSG_DF1_NODUMP_SIZE + \
105 		MSG_DF1_CONFALT_SIZE + \
106 		MSG_DF1_ENDFILTEE_SIZE + \
107 		MSG_DF1_DISPRELPND_SIZE + \
108 		MSG_DF1_DISPRELDNE_SIZE + \
109 		MSG_DF1_NODIRECT_SIZE + \
110 		MSG_DF1_IGNMULDEF_SIZE + \
111 		MSG_DF1_NOKSYMS_SIZE + \
112 		MSG_DF1_NORELOC_SIZE + \
113 		MSG_GBL_CSQBRKT_SIZE
114 
115 const char *
116 conv_dynflag_1_str(uint_t flags)
117 {
118 	static char	string[FLAG1SZ] = { '\0' };
119 
120 	if (flags == 0)
121 		return (MSG_ORIG(MSG_GBL_ZERO));
122 	else {
123 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
124 
125 		if (flags & DF_1_NOW)
126 			(void) strcat(string, MSG_ORIG(MSG_DF1_NOW));
127 		if (flags & DF_1_GROUP)
128 			(void) strcat(string, MSG_ORIG(MSG_DF1_GROUP));
129 		if (flags & DF_1_NODELETE)
130 			(void) strcat(string, MSG_ORIG(MSG_DF1_NODELETE));
131 		if (flags & DF_1_LOADFLTR)
132 			(void) strcat(string, MSG_ORIG(MSG_DF1_LOADFLTR));
133 		if (flags & DF_1_INITFIRST)
134 			(void) strcat(string, MSG_ORIG(MSG_DF1_INITFIRST));
135 		if (flags & DF_1_NOOPEN)
136 			(void) strcat(string, MSG_ORIG(MSG_DF1_NOOPEN));
137 		if (flags & DF_1_ORIGIN)
138 			(void) strcat(string, MSG_ORIG(MSG_DF1_ORIGIN));
139 		if (flags & DF_1_DIRECT)
140 			(void) strcat(string, MSG_ORIG(MSG_DF1_DIRECT));
141 		if (flags & DF_1_TRANS)
142 			(void) strcat(string, MSG_ORIG(MSG_DF1_TRANS));
143 		if (flags & DF_1_INTERPOSE)
144 			(void) strcat(string, MSG_ORIG(MSG_DF1_INTERPOSE));
145 		if (flags & DF_1_NODEFLIB)
146 			(void) strcat(string, MSG_ORIG(MSG_DF1_NODEFLIB));
147 		if (flags & DF_1_NODUMP)
148 			(void) strcat(string, MSG_ORIG(MSG_DF1_NODUMP));
149 		if (flags & DF_1_CONFALT)
150 			(void) strcat(string, MSG_ORIG(MSG_DF1_CONFALT));
151 		if (flags & DF_1_ENDFILTEE)
152 			(void) strcat(string, MSG_ORIG(MSG_DF1_ENDFILTEE));
153 		if (flags & DF_1_DISPRELPND)
154 			(void) strcat(string, MSG_ORIG(MSG_DF1_DISPRELPND));
155 		if (flags & DF_1_DISPRELDNE)
156 			(void) strcat(string, MSG_ORIG(MSG_DF1_DISPRELDNE));
157 		if (flags & DF_1_NODIRECT)
158 			(void) strcat(string, MSG_ORIG(MSG_DF1_NODIRECT));
159 		if (flags & DF_1_IGNMULDEF)
160 			(void) strcat(string, MSG_ORIG(MSG_DF1_IGNMULDEF));
161 		if (flags & DF_1_NOKSYMS)
162 			(void) strcat(string, MSG_ORIG(MSG_DF1_NOKSYMS));
163 		if (flags & DF_1_NORELOC)
164 			(void) strcat(string, MSG_ORIG(MSG_DF1_NORELOC));
165 
166 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
167 
168 		return ((const char *)string);
169 	}
170 }
171 
172 #define	FEATSZ	MSG_GBL_OSQBRKT_SIZE + \
173 		MSG_DTF_PARINIT_SIZE + \
174 		MSG_DTF_CONFEXP_SIZE + \
175 		MSG_GBL_CSQBRKT_SIZE
176 
177 const char *
178 conv_dynfeature_1_str(uint_t flags)
179 {
180 	static char	string[FEATSZ] = { '\0' };
181 
182 	if (flags == 0)
183 		return (MSG_ORIG(MSG_GBL_ZERO));
184 	else {
185 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
186 
187 		if (flags & DTF_1_PARINIT)
188 			(void) strcat(string, MSG_ORIG(MSG_DTF_PARINIT));
189 		if (flags & DTF_1_CONFEXP)
190 			(void) strcat(string, MSG_ORIG(MSG_DTF_CONFEXP));
191 
192 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
193 
194 		return ((const char *)string);
195 	}
196 }
197 
198 const Msg _dyntag_tags[DT_MAXPOSTAGS] = {
199 	MSG_DYN_NULL,		MSG_DYN_NEEDED,		MSG_DYN_PLTRELSZ,
200 	MSG_DYN_PLTGOT,		MSG_DYN_HASH,		MSG_DYN_STRTAB,
201 	MSG_DYN_SYMTAB,		MSG_DYN_RELA,		MSG_DYN_RELASZ,
202 	MSG_DYN_RELAENT,	MSG_DYN_STRSZ,		MSG_DYN_SYMENT,
203 	MSG_DYN_INIT,		MSG_DYN_FINI,		MSG_DYN_SONAME,
204 	MSG_DYN_RPATH,		MSG_DYN_SYMBOLIC,	MSG_DYN_REL,
205 	MSG_DYN_RELSZ,		MSG_DYN_RELENT,		MSG_DYN_PLTREL,
206 	MSG_DYN_DEBUG,		MSG_DYN_TEXTREL,	MSG_DYN_JMPREL,
207 	MSG_DYN_BIND_NOW,	MSG_DYN_INIT_ARRAY,	MSG_DYN_FINI_ARRAY,
208 	MSG_DYN_INIT_ARRAYSZ,	MSG_DYN_FINI_ARRAYSZ,	MSG_DYN_RUNPATH,
209 	MSG_DYN_FLAGS,		MSG_DYN_NULL,		MSG_DYN_PREINIT_ARRAY,
210 	MSG_DYN_PREINIT_ARRAYSZ
211 };
212 
213 const char *
214 conv_dyntag_str(uint64_t tag, ushort_t mach)
215 {
216 	static char	string[STRSIZE] = { '\0' };
217 
218 	if (tag < DT_MAXPOSTAGS) {
219 		/*
220 		 * Generic dynamic tags.
221 		 */
222 		return (MSG_ORIG(_dyntag_tags[tag]));
223 	} else {
224 		/*
225 		 * SUNW: DT_LOOS -> DT_HIOS range.
226 		 */
227 		if (tag == DT_SUNW_AUXILIARY)
228 			return (MSG_ORIG(MSG_DYN_SUNW_AUXILIARY));
229 		else if (tag == DT_SUNW_RTLDINF)
230 			return (MSG_ORIG(MSG_DYN_SUNW_RTLDINF));
231 		else if (tag == DT_SUNW_FILTER)
232 			return (MSG_ORIG(MSG_DYN_SUNW_FILTER));
233 		else if (tag == DT_SUNW_CAP)
234 			return (MSG_ORIG(MSG_DYN_SUNW_CAP));
235 
236 		/*
237 		 * SUNW: DT_VALRNGLO - DT_VALRNGHI range.
238 		 */
239 		else if (tag == DT_CHECKSUM)
240 			return (MSG_ORIG(MSG_DYN_CHECKSUM));
241 		else if (tag == DT_PLTPADSZ)
242 			return (MSG_ORIG(MSG_DYN_PLTPADSZ));
243 		else if (tag == DT_MOVEENT)
244 			return (MSG_ORIG(MSG_DYN_MOVEENT));
245 		else if (tag == DT_MOVESZ)
246 			return (MSG_ORIG(MSG_DYN_MOVESZ));
247 		else if (tag == DT_FEATURE_1)
248 			return (MSG_ORIG(MSG_DYN_FEATURE_1));
249 		else if (tag == DT_POSFLAG_1)
250 			return (MSG_ORIG(MSG_DYN_POSFLAG_1));
251 		else if (tag == DT_SYMINSZ)
252 			return (MSG_ORIG(MSG_DYN_SYMINSZ));
253 		else if (tag == DT_SYMINENT)
254 			return (MSG_ORIG(MSG_DYN_SYMINENT));
255 
256 		/*
257 		 * SUNW: DT_ADDRRNGLO - DT_ADDRRNGHI range.
258 		 */
259 		else if (tag == DT_CONFIG)
260 			return (MSG_ORIG(MSG_DYN_CONFIG));
261 		else if (tag == DT_DEPAUDIT)
262 			return (MSG_ORIG(MSG_DYN_DEPAUDIT));
263 		else if (tag == DT_AUDIT)
264 			return (MSG_ORIG(MSG_DYN_AUDIT));
265 		else if (tag == DT_PLTPAD)
266 			return (MSG_ORIG(MSG_DYN_PLTPAD));
267 		else if (tag == DT_MOVETAB)
268 			return (MSG_ORIG(MSG_DYN_MOVETAB));
269 		else if (tag == DT_SYMINFO)
270 			return (MSG_ORIG(MSG_DYN_SYMINFO));
271 
272 		/*
273 		 * SUNW: generic range.
274 		 */
275 		else if (tag == DT_VERSYM)
276 			return (MSG_ORIG(MSG_DYN_VERSYM));
277 		else if (tag == DT_RELACOUNT)
278 			return (MSG_ORIG(MSG_DYN_RELACOUNT));
279 		else if (tag == DT_RELCOUNT)
280 			return (MSG_ORIG(MSG_DYN_RELCOUNT));
281 		else if (tag == DT_FLAGS_1)
282 			return (MSG_ORIG(MSG_DYN_FLAGS_1));
283 		else if (tag == DT_VERDEF)
284 			return (MSG_ORIG(MSG_DYN_VERDEF));
285 		else if (tag == DT_VERDEFNUM)
286 			return (MSG_ORIG(MSG_DYN_VERDEFNUM));
287 		else if (tag == DT_VERNEED)
288 			return (MSG_ORIG(MSG_DYN_VERNEED));
289 		else if (tag == DT_VERNEEDNUM)
290 			return (MSG_ORIG(MSG_DYN_VERNEEDNUM));
291 		else if (tag == DT_AUXILIARY)
292 			return (MSG_ORIG(MSG_DYN_AUXILIARY));
293 		else if (tag == DT_USED)
294 			return (MSG_ORIG(MSG_DYN_USED));
295 		else if (tag == DT_FILTER)
296 			return (MSG_ORIG(MSG_DYN_FILTER));
297 
298 		/*
299 		 * SUNW: machine specific range.
300 		 */
301 		else if (((mach == EM_SPARC) || (mach == EM_SPARCV9) ||
302 		    (mach == EM_SPARC32PLUS)) && (tag == DT_SPARC_REGISTER))
303 			/* this is so x86 can display a sparc binary */
304 			return (MSG_ORIG(MSG_DYN_REGISTER));
305 		else if (tag == DT_DEPRECATED_SPARC_REGISTER)
306 			return (MSG_ORIG(MSG_DYN_REGISTER));
307 		else
308 			return (conv_invalid_str(string, STRSIZE, tag, 0));
309 	}
310 }
311