xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/sections.c (revision 685:39399075b8e6)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*685Srie 
230Sstevel@tonic-gate /*
24574Sseizo  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * String conversion routines for section attributes.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate #include	<string.h>
330Sstevel@tonic-gate #include	<sys/param.h>
340Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
350Sstevel@tonic-gate #include	<sys/elf_amd64.h>
360Sstevel@tonic-gate #include	<_conv.h>
370Sstevel@tonic-gate #include	<sections_msg.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate static const Msg secs[SHT_NUM] = {
400Sstevel@tonic-gate 	MSG_SHT_NULL,		MSG_SHT_PROGBITS,	MSG_SHT_SYMTAB,
410Sstevel@tonic-gate 	MSG_SHT_STRTAB,		MSG_SHT_RELA,		MSG_SHT_HASH,
420Sstevel@tonic-gate 	MSG_SHT_DYNAMIC,	MSG_SHT_NOTE,		MSG_SHT_NOBITS,
430Sstevel@tonic-gate 	MSG_SHT_REL,		MSG_SHT_SHLIB,		MSG_SHT_DYNSYM,
440Sstevel@tonic-gate 	MSG_SHT_UNKNOWN12,	MSG_SHT_UNKNOWN13,	MSG_SHT_INIT_ARRAY,
450Sstevel@tonic-gate 	MSG_SHT_FINI_ARRAY,	MSG_SHT_PREINIT_ARRAY,	MSG_SHT_GROUP,
460Sstevel@tonic-gate 	MSG_SHT_SYMTAB_SHNDX
470Sstevel@tonic-gate };
480Sstevel@tonic-gate #if	(SHT_NUM != (SHT_SYMTAB_SHNDX + 1))
490Sstevel@tonic-gate #error	"SHT_NUM has grown"
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static const Msg usecs[SHT_HISUNW - SHT_LOSUNW + 1] = {
530Sstevel@tonic-gate 	MSG_SHT_SUNW_dof,	MSG_SHT_SUNW_cap,	MSG_SHT_SUNW_SIGNATURE,
540Sstevel@tonic-gate 	MSG_SHT_SUNW_ANNOTATE,	MSG_SHT_SUNW_DEBUGSTR,	MSG_SHT_SUNW_DEBUG,
550Sstevel@tonic-gate 	MSG_SHT_SUNW_move,	MSG_SHT_SUNW_COMDAT,	MSG_SHT_SUNW_syminfo,
560Sstevel@tonic-gate 	MSG_SHT_SUNW_verdef,	MSG_SHT_SUNW_verneed,	MSG_SHT_SUNW_versym
570Sstevel@tonic-gate };
580Sstevel@tonic-gate #if	(SHT_LOSUNW != SHT_SUNW_dof)
590Sstevel@tonic-gate #error	"SHT_LOSUNW has moved"
600Sstevel@tonic-gate #endif
610Sstevel@tonic-gate 
620Sstevel@tonic-gate const char *
630Sstevel@tonic-gate /* ARGSUSED 1 */
640Sstevel@tonic-gate conv_sectyp_str(ushort_t mach, uint_t sec)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	static char	string[STRSIZE] = { '\0' };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	if (sec < SHT_NUM)
690Sstevel@tonic-gate 		return (MSG_ORIG(secs[sec]));
700Sstevel@tonic-gate 	else if ((sec >= SHT_LOSUNW) && (sec <= SHT_HISUNW))
710Sstevel@tonic-gate 		return (MSG_ORIG(usecs[sec - SHT_LOSUNW]));
720Sstevel@tonic-gate 	else if ((sec >= SHT_LOPROC) && (sec <= SHT_HIPROC)) {
730Sstevel@tonic-gate 		if ((sec == (uint_t)SHT_SPARC_GOTDATA) &&
740Sstevel@tonic-gate 		    ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
750Sstevel@tonic-gate 		    (mach == EM_SPARCV9)))
760Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHT_SPARC_GOTDATA));
770Sstevel@tonic-gate 		else if ((sec == (uint_t)SHT_AMD64_UNWIND) &&
780Sstevel@tonic-gate 		    (mach == EM_AMD64))
790Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHT_AMD64_UNWIND));
800Sstevel@tonic-gate 		else
810Sstevel@tonic-gate 			return (conv_invalid_str(string, STRSIZE, sec, 0));
820Sstevel@tonic-gate 	} else
830Sstevel@tonic-gate 		return (conv_invalid_str(string, STRSIZE, sec, 0));
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
870Sstevel@tonic-gate 		MSG_SHF_WRITE_SIZE + \
880Sstevel@tonic-gate 		MSG_SHF_ALLOC_SIZE + \
890Sstevel@tonic-gate 		MSG_SHF_EXECINSTR_SIZE + \
900Sstevel@tonic-gate 		MSG_SHF_MERGE_SIZE + \
910Sstevel@tonic-gate 		MSG_SHF_STRINGS_SIZE + \
920Sstevel@tonic-gate 		MSG_SHF_INFO_LINK_SIZE + \
930Sstevel@tonic-gate 		MSG_SHF_LINK_ORDER_SIZE + \
940Sstevel@tonic-gate 		MSG_SHF_OS_NONCONFORMING_SIZE + \
950Sstevel@tonic-gate 		MSG_SHF_GROUP_SIZE + \
960Sstevel@tonic-gate 		MSG_SHF_TLS_SIZE + \
970Sstevel@tonic-gate 		MSG_SHF_EXCLUDE_SIZE + \
980Sstevel@tonic-gate 		MSG_SHF_ORDERED_SIZE + \
99*685Srie 		MSG_SHF_AMD64_LARGE_SIZE + \
1000Sstevel@tonic-gate 		MSG_GBL_CSQBRKT_SIZE
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate const char *
1030Sstevel@tonic-gate /* ARGSUSED 1 */
1040Sstevel@tonic-gate conv_secflg_str(ushort_t mach, uint_t flags)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	static	char	string[FLAGSZ] = { '\0' };
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	if (flags == 0)
1090Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
1100Sstevel@tonic-gate 	else {
1110Sstevel@tonic-gate 		uint_t	flags_handled = 0;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 		(void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT));
1140Sstevel@tonic-gate 		if (flags & SHF_WRITE) {
1150Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_WRITE));
1160Sstevel@tonic-gate 			flags_handled |= SHF_WRITE;
1170Sstevel@tonic-gate 		}
1180Sstevel@tonic-gate 		if (flags & SHF_ALLOC) {
1190Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_ALLOC));
1200Sstevel@tonic-gate 			flags_handled |= SHF_ALLOC;
1210Sstevel@tonic-gate 		}
1220Sstevel@tonic-gate 		if (flags & SHF_EXECINSTR) {
1230Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_EXECINSTR));
1240Sstevel@tonic-gate 			flags_handled |= SHF_EXECINSTR;
1250Sstevel@tonic-gate 		}
1260Sstevel@tonic-gate 		if (flags & SHF_MERGE) {
1270Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_MERGE));
1280Sstevel@tonic-gate 			flags_handled |= SHF_MERGE;
1290Sstevel@tonic-gate 		}
1300Sstevel@tonic-gate 		if (flags & SHF_STRINGS) {
1310Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_STRINGS));
1320Sstevel@tonic-gate 			flags_handled |= SHF_STRINGS;
1330Sstevel@tonic-gate 		}
1340Sstevel@tonic-gate 		if (flags & SHF_INFO_LINK) {
1350Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_INFO_LINK));
1360Sstevel@tonic-gate 			flags_handled |= SHF_INFO_LINK;
1370Sstevel@tonic-gate 		}
1380Sstevel@tonic-gate 		if (flags & SHF_LINK_ORDER) {
1390Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_LINK_ORDER));
1400Sstevel@tonic-gate 			flags_handled |= SHF_LINK_ORDER;
1410Sstevel@tonic-gate 		}
1420Sstevel@tonic-gate 		if (flags & SHF_OS_NONCONFORMING) {
1430Sstevel@tonic-gate 			(void) strcat(string,
1440Sstevel@tonic-gate 				MSG_ORIG(MSG_SHF_OS_NONCONFORMING));
1450Sstevel@tonic-gate 			flags_handled |= SHF_OS_NONCONFORMING;
1460Sstevel@tonic-gate 		}
1470Sstevel@tonic-gate 		if (flags & SHF_GROUP) {
1480Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_GROUP));
1490Sstevel@tonic-gate 			flags_handled |= SHF_GROUP;
1500Sstevel@tonic-gate 		}
1510Sstevel@tonic-gate 		if (flags & SHF_TLS) {
1520Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_TLS));
1530Sstevel@tonic-gate 			flags_handled |= SHF_TLS;
1540Sstevel@tonic-gate 		}
1550Sstevel@tonic-gate 		if (flags & SHF_EXCLUDE) {
1560Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_EXCLUDE));
1570Sstevel@tonic-gate 			flags_handled |= SHF_EXCLUDE;
1580Sstevel@tonic-gate 		}
1590Sstevel@tonic-gate 		if (flags & SHF_ORDERED) {
1600Sstevel@tonic-gate 			(void) strcat(string, MSG_ORIG(MSG_SHF_ORDERED));
1610Sstevel@tonic-gate 			flags_handled |= SHF_ORDERED;
1620Sstevel@tonic-gate 		}
163574Sseizo 		if (flags & SHF_AMD64_LARGE) {
164574Sseizo 			(void) strcat(string, MSG_ORIG(MSG_SHF_AMD64_LARGE));
165574Sseizo 			flags_handled |= SHF_AMD64_LARGE;
166574Sseizo 		}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 		/*
1690Sstevel@tonic-gate 		 * Are there any flags that haven't been handled.
1700Sstevel@tonic-gate 		 */
1710Sstevel@tonic-gate 		if ((flags & flags_handled) != flags) {
1720Sstevel@tonic-gate 			char	*str;
1730Sstevel@tonic-gate 			size_t	len;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 			len = strlen(string);
1760Sstevel@tonic-gate 			str = string + len;
1770Sstevel@tonic-gate 			(void) conv_invalid_str(str, FLAGSZ - len,
1780Sstevel@tonic-gate 			    (flags & (~flags_handled)), 0);
1790Sstevel@tonic-gate 		}
1800Sstevel@tonic-gate 		(void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT));
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 		return ((const char *)string);
1830Sstevel@tonic-gate 	}
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate  * Need to be able to hold a 32bit signed integer.
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate #define	INFOSZ	128
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate const char *
1920Sstevel@tonic-gate conv_secinfo_str(uint_t info, uint_t flags)
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate 	static	char	string[INFOSZ] = { '\0' };
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	if (flags & SHF_ORDERED) {
1970Sstevel@tonic-gate 		if (info == SHN_BEFORE)
1980Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHN_BEFORE));
1990Sstevel@tonic-gate 		else if (info == SHN_AFTER)
2000Sstevel@tonic-gate 			return (MSG_ORIG(MSG_SHN_AFTER));
2010Sstevel@tonic-gate 	}
2020Sstevel@tonic-gate 	(void) conv_invalid_str(string, INFOSZ, info, 1);
2030Sstevel@tonic-gate 	return ((const char *)string);
2040Sstevel@tonic-gate }
205