xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/sections.c (revision 1618:8c9a4f31d225)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1618Srie  * Common Development and Distribution License (the "License").
6*1618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21685Srie 
220Sstevel@tonic-gate /*
23*1618Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * String conversion routines for section attributes.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate #include	<string.h>
320Sstevel@tonic-gate #include	<sys/param.h>
330Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
340Sstevel@tonic-gate #include	<sys/elf_amd64.h>
350Sstevel@tonic-gate #include	<_conv.h>
360Sstevel@tonic-gate #include	<sections_msg.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate static const Msg secs[SHT_NUM] = {
390Sstevel@tonic-gate 	MSG_SHT_NULL,		MSG_SHT_PROGBITS,	MSG_SHT_SYMTAB,
400Sstevel@tonic-gate 	MSG_SHT_STRTAB,		MSG_SHT_RELA,		MSG_SHT_HASH,
410Sstevel@tonic-gate 	MSG_SHT_DYNAMIC,	MSG_SHT_NOTE,		MSG_SHT_NOBITS,
420Sstevel@tonic-gate 	MSG_SHT_REL,		MSG_SHT_SHLIB,		MSG_SHT_DYNSYM,
430Sstevel@tonic-gate 	MSG_SHT_UNKNOWN12,	MSG_SHT_UNKNOWN13,	MSG_SHT_INIT_ARRAY,
440Sstevel@tonic-gate 	MSG_SHT_FINI_ARRAY,	MSG_SHT_PREINIT_ARRAY,	MSG_SHT_GROUP,
450Sstevel@tonic-gate 	MSG_SHT_SYMTAB_SHNDX
460Sstevel@tonic-gate };
470Sstevel@tonic-gate #if	(SHT_NUM != (SHT_SYMTAB_SHNDX + 1))
480Sstevel@tonic-gate #error	"SHT_NUM has grown"
490Sstevel@tonic-gate #endif
500Sstevel@tonic-gate 
510Sstevel@tonic-gate static const Msg usecs[SHT_HISUNW - SHT_LOSUNW + 1] = {
520Sstevel@tonic-gate 	MSG_SHT_SUNW_dof,	MSG_SHT_SUNW_cap,	MSG_SHT_SUNW_SIGNATURE,
530Sstevel@tonic-gate 	MSG_SHT_SUNW_ANNOTATE,	MSG_SHT_SUNW_DEBUGSTR,	MSG_SHT_SUNW_DEBUG,
540Sstevel@tonic-gate 	MSG_SHT_SUNW_move,	MSG_SHT_SUNW_COMDAT,	MSG_SHT_SUNW_syminfo,
550Sstevel@tonic-gate 	MSG_SHT_SUNW_verdef,	MSG_SHT_SUNW_verneed,	MSG_SHT_SUNW_versym
560Sstevel@tonic-gate };
570Sstevel@tonic-gate #if	(SHT_LOSUNW != SHT_SUNW_dof)
580Sstevel@tonic-gate #error	"SHT_LOSUNW has moved"
590Sstevel@tonic-gate #endif
600Sstevel@tonic-gate 
610Sstevel@tonic-gate const char *
62*1618Srie conv_sec_type(Half mach, Word sec)
630Sstevel@tonic-gate {
64*1618Srie 	static char	string[CONV_INV_STRSIZE];
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	if (sec < SHT_NUM)
670Sstevel@tonic-gate 		return (MSG_ORIG(secs[sec]));
680Sstevel@tonic-gate 	else if ((sec >= SHT_LOSUNW) && (sec <= SHT_HISUNW))
690Sstevel@tonic-gate 		return (MSG_ORIG(usecs[sec - SHT_LOSUNW]));
700Sstevel@tonic-gate 	else if ((sec >= SHT_LOPROC) && (sec <= SHT_HIPROC)) {
71*1618Srie 		if ((sec == SHT_SPARC_GOTDATA) && ((mach == EM_SPARC) ||
72*1618Srie 		    (mach == EM_SPARC32PLUS) || (mach == EM_SPARCV9)))
730Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHT_SPARC_GOTDATA));
74*1618Srie 		else if ((sec == SHT_AMD64_UNWIND) && (mach == EM_AMD64))
750Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHT_AMD64_UNWIND));
760Sstevel@tonic-gate 		else
77*1618Srie 			return (conv_invalid_val(string, CONV_INV_STRSIZE,
78*1618Srie 			    sec, 0));
790Sstevel@tonic-gate 	} else
80*1618Srie 		return (conv_invalid_val(string, CONV_INV_STRSIZE, sec, 0));
810Sstevel@tonic-gate }
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
840Sstevel@tonic-gate 		MSG_SHF_WRITE_SIZE + \
850Sstevel@tonic-gate 		MSG_SHF_ALLOC_SIZE + \
860Sstevel@tonic-gate 		MSG_SHF_EXECINSTR_SIZE + \
870Sstevel@tonic-gate 		MSG_SHF_MERGE_SIZE + \
880Sstevel@tonic-gate 		MSG_SHF_STRINGS_SIZE + \
890Sstevel@tonic-gate 		MSG_SHF_INFO_LINK_SIZE + \
900Sstevel@tonic-gate 		MSG_SHF_LINK_ORDER_SIZE + \
910Sstevel@tonic-gate 		MSG_SHF_OS_NONCONFORMING_SIZE + \
920Sstevel@tonic-gate 		MSG_SHF_GROUP_SIZE + \
930Sstevel@tonic-gate 		MSG_SHF_TLS_SIZE + \
940Sstevel@tonic-gate 		MSG_SHF_EXCLUDE_SIZE + \
950Sstevel@tonic-gate 		MSG_SHF_ORDERED_SIZE + \
96685Srie 		MSG_SHF_AMD64_LARGE_SIZE + \
97*1618Srie 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
980Sstevel@tonic-gate 
990Sstevel@tonic-gate const char *
100*1618Srie conv_sec_flags(Xword flags)
1010Sstevel@tonic-gate {
102*1618Srie 	static	char	string[FLAGSZ];
103*1618Srie 	static Val_desc vda[] = {
104*1618Srie 		{ SHF_WRITE,		MSG_ORIG(MSG_SHF_WRITE) },
105*1618Srie 		{ SHF_ALLOC,		MSG_ORIG(MSG_SHF_ALLOC) },
106*1618Srie 		{ SHF_EXECINSTR,	MSG_ORIG(MSG_SHF_EXECINSTR) },
107*1618Srie 		{ SHF_MERGE,		MSG_ORIG(MSG_SHF_MERGE) },
108*1618Srie 		{ SHF_STRINGS,		MSG_ORIG(MSG_SHF_STRINGS) },
109*1618Srie 		{ SHF_INFO_LINK,	MSG_ORIG(MSG_SHF_INFO_LINK) },
110*1618Srie 		{ SHF_LINK_ORDER,	MSG_ORIG(MSG_SHF_LINK_ORDER) },
111*1618Srie 		{ SHF_OS_NONCONFORMING,	MSG_ORIG(MSG_SHF_OS_NONCONFORMING) },
112*1618Srie 		{ SHF_GROUP,		MSG_ORIG(MSG_SHF_GROUP) },
113*1618Srie 		{ SHF_TLS,		MSG_ORIG(MSG_SHF_TLS) },
114*1618Srie 		{ SHF_EXCLUDE,		MSG_ORIG(MSG_SHF_EXCLUDE) },
115*1618Srie 		{ SHF_ORDERED,		MSG_ORIG(MSG_SHF_ORDERED) },
116*1618Srie 		{ SHF_AMD64_LARGE,	MSG_ORIG(MSG_SHF_AMD64_LARGE) },
117*1618Srie 		{ 0,			0 }
118*1618Srie 	};
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	if (flags == 0)
1210Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1220Sstevel@tonic-gate 
123*1618Srie 	(void) strlcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ);
124*1618Srie 	if (conv_expn_field(string, FLAGSZ, vda, flags, flags, 0, 0))
125*1618Srie 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
1260Sstevel@tonic-gate 
127*1618Srie 	return ((const char *)string);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate const char *
131*1618Srie conv_sec_info(Word info, Xword flags)
1320Sstevel@tonic-gate {
133*1618Srie 	static	char	string[CONV_INV_STRSIZE];
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	if (flags & SHF_ORDERED) {
1360Sstevel@tonic-gate 		if (info == SHN_BEFORE)
1370Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHN_BEFORE));
1380Sstevel@tonic-gate 		else if (info == SHN_AFTER)
1390Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHN_AFTER));
1400Sstevel@tonic-gate 	}
141*1618Srie 	(void) conv_invalid_val(string, CONV_INV_STRSIZE, info, 1);
1420Sstevel@tonic-gate 	return ((const char *)string);
1430Sstevel@tonic-gate }
144