xref: /onnv-gate/usr/src/cmd/sgs/liblddbg/common/sections.c (revision 11734:d29dc9c2b6c5)
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
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * 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  */
211618Srie 
220Sstevel@tonic-gate /*
23*11734SAli.Bahrami@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2433Srie  * Use is subject to license terms.
250Sstevel@tonic-gate  */
269406SAli.Bahrami@Sun.COM #include	<stdio.h>
270Sstevel@tonic-gate #include	"msg.h"
280Sstevel@tonic-gate #include	"_debug.h"
290Sstevel@tonic-gate #include	"libld.h"
305549Srie #include	"_string_table.h"
310Sstevel@tonic-gate 
329406SAli.Bahrami@Sun.COM /*
339406SAli.Bahrami@Sun.COM  * Format an input section descriptor name for output, in the format
349406SAli.Bahrami@Sun.COM  *	[ndx]name
359406SAli.Bahrami@Sun.COM  * If possible, a user supplied fixed size buffer is used. Failing that,
369406SAli.Bahrami@Sun.COM  * dynamic memory is allocated, which must be freed by the caller.
379406SAli.Bahrami@Sun.COM  *
389406SAli.Bahrami@Sun.COM  * entry:
399406SAli.Bahrami@Sun.COM  *	[dbg_fmt_isec_name2]: name, scnndx  - Name and section index
409406SAli.Bahrami@Sun.COM  *	[dbg_fmt_isec_name]: isp - Input section descriptor giving name
419406SAli.Bahrami@Sun.COM  *		and index.
429406SAli.Bahrami@Sun.COM  *
439406SAli.Bahrami@Sun.COM  *	buf - Caller supplied buffer
449406SAli.Bahrami@Sun.COM  *	alloc_mem - Address of pointer to be set to address of allocated
459406SAli.Bahrami@Sun.COM  *		memory, or NULL if no memory is allocated.
469406SAli.Bahrami@Sun.COM  *
479406SAli.Bahrami@Sun.COM  * exit:
489406SAli.Bahrami@Sun.COM  *	A pointer to the formatted string is returned. If the supplied buffer
499406SAli.Bahrami@Sun.COM  *	was sufficient, *alloc_mem is set to NULL. If memory was allocated,
509406SAli.Bahrami@Sun.COM  *	*alloc_mem references it. The caller must free this memory after use.
519406SAli.Bahrami@Sun.COM  */
529406SAli.Bahrami@Sun.COM const char *
dbg_fmt_isec_name2(const char * name,Word scnndx,dbg_isec_name_buf_t buf,char ** alloc_mem)539406SAli.Bahrami@Sun.COM dbg_fmt_isec_name2(const char *name, Word scnndx, dbg_isec_name_buf_t buf,
549406SAli.Bahrami@Sun.COM     char **alloc_mem)
559406SAli.Bahrami@Sun.COM {
569406SAli.Bahrami@Sun.COM 	int	cnt;
579406SAli.Bahrami@Sun.COM 
589406SAli.Bahrami@Sun.COM 	/*
599406SAli.Bahrami@Sun.COM 	 * If the section index is 0, it's not a real section.
609406SAli.Bahrami@Sun.COM 	 * Just use the name as is.
619406SAli.Bahrami@Sun.COM 	 */
629406SAli.Bahrami@Sun.COM 	if (scnndx == 0) {
639406SAli.Bahrami@Sun.COM 		*alloc_mem = NULL;
649406SAli.Bahrami@Sun.COM 		return (name);
659406SAli.Bahrami@Sun.COM 	}
669406SAli.Bahrami@Sun.COM 
679406SAli.Bahrami@Sun.COM 	/* Format into the fixed buffer */
689406SAli.Bahrami@Sun.COM 	cnt = snprintf(buf, sizeof (dbg_isec_name_buf_t),
699406SAli.Bahrami@Sun.COM 	    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
709406SAli.Bahrami@Sun.COM 
719406SAli.Bahrami@Sun.COM 	/*
729406SAli.Bahrami@Sun.COM 	 * If the name was too long, try to allocate a dynamic buffer.
739406SAli.Bahrami@Sun.COM 	 * Failing that, fall through and use the clipped one already
749406SAli.Bahrami@Sun.COM 	 * formatted into buf, as that's better than nothing.
759406SAli.Bahrami@Sun.COM 	 */
769406SAli.Bahrami@Sun.COM 	if ((cnt >= sizeof (dbg_isec_name_buf_t)) &&
779406SAli.Bahrami@Sun.COM 	    ((*alloc_mem = malloc(cnt + 1)) != NULL)) {
789406SAli.Bahrami@Sun.COM 		(void) snprintf(*alloc_mem, cnt + 1,
799406SAli.Bahrami@Sun.COM 		    MSG_ORIG(MSG_FMT_ISEC_NAME), EC_WORD(scnndx), name);
809406SAli.Bahrami@Sun.COM 		return (*alloc_mem);
819406SAli.Bahrami@Sun.COM 	}
829406SAli.Bahrami@Sun.COM 
839406SAli.Bahrami@Sun.COM 	/* Return the caller supplied buffer */
849406SAli.Bahrami@Sun.COM 	*alloc_mem = NULL;
859406SAli.Bahrami@Sun.COM 	return (buf);
869406SAli.Bahrami@Sun.COM }
879406SAli.Bahrami@Sun.COM const char *
dbg_fmt_isec_name(Is_desc * isp,dbg_isec_name_buf_t buf,char ** alloc_mem)889406SAli.Bahrami@Sun.COM dbg_fmt_isec_name(Is_desc *isp, dbg_isec_name_buf_t buf, char **alloc_mem)
899406SAli.Bahrami@Sun.COM {
909406SAli.Bahrami@Sun.COM 	return (dbg_fmt_isec_name2(isp->is_name, isp->is_scnndx, buf,
919406SAli.Bahrami@Sun.COM 	    alloc_mem));
929406SAli.Bahrami@Sun.COM }
939406SAli.Bahrami@Sun.COM 
940Sstevel@tonic-gate void
Dbg_sec_strtab(Lm_list * lml,Os_desc * osp,Str_tbl * stp)951618Srie Dbg_sec_strtab(Lm_list *lml, Os_desc *osp, Str_tbl *stp)
960Sstevel@tonic-gate {
975549Srie 	uint_t	cnt;
980Sstevel@tonic-gate 
991618Srie 	if (DBG_NOTCLASS(DBG_C_STRTAB))
1000Sstevel@tonic-gate 		return;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	if (!osp)
1030Sstevel@tonic-gate 		return;
1040Sstevel@tonic-gate 
1052647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1060Sstevel@tonic-gate 	if (stp->st_flags & FLG_STTAB_COMPRESS)
1071618Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_COMP), osp->os_name,
1085892Sab196087 		    EC_XWORD(stp->st_fullstrsize), EC_XWORD(stp->st_strsize));
1090Sstevel@tonic-gate 	else
1101618Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_STND), osp->os_name,
1115892Sab196087 		    EC_XWORD(stp->st_fullstrsize));
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	if ((DBG_NOTDETAIL()) ||
1140Sstevel@tonic-gate 	    ((stp->st_flags & FLG_STTAB_COMPRESS) == 0))
1150Sstevel@tonic-gate 		return;
1160Sstevel@tonic-gate 
1171618Srie 	dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
1181618Srie 	dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_HD), osp->os_name,
1191618Srie 	    stp->st_hbckcnt);
1201618Srie 
1215549Srie 	for (cnt = 0; cnt < stp->st_hbckcnt; cnt++) {
1225549Srie 		Str_hash	*strhash = stp->st_hashbcks[cnt];
1231618Srie 
1249406SAli.Bahrami@Sun.COM 		if (strhash == NULL)
1255549Srie 			continue;
1261618Srie 
1275549Srie 		dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_BCKT), cnt);
1285549Srie 
1295549Srie 		while (strhash) {
1305892Sab196087 			size_t	stroff = strhash->hi_mstr->sm_strlen -
1315549Srie 			    strhash->hi_strlen;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 			if (stroff == 0) {
1341618Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_MSTR),
1355892Sab196087 				    EC_XWORD(strhash->hi_refcnt),
1365549Srie 				    strhash->hi_mstr->sm_str);
1370Sstevel@tonic-gate 			} else {
1381618Srie 				dbg_print(lml, MSG_INTL(MSG_SEC_STRTAB_SUFSTR),
1395892Sab196087 				    EC_XWORD(strhash->hi_refcnt),
1405549Srie 				    &strhash->hi_mstr->sm_str[stroff],
1415549Srie 				    strhash->hi_mstr->sm_str);
1420Sstevel@tonic-gate 			}
1435549Srie 
1445549Srie 			strhash = strhash->hi_next;
1450Sstevel@tonic-gate 		}
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate void
Dbg_sec_genstr_compress(Lm_list * lml,const char * os_name,Xword raw_size,Xword merge_size)1505892Sab196087 Dbg_sec_genstr_compress(Lm_list *lml, const char *os_name,
1515892Sab196087     Xword raw_size, Xword merge_size)
1525892Sab196087 {
1535892Sab196087 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1545892Sab196087 		return;
1555892Sab196087 
1565892Sab196087 	dbg_print(lml, MSG_INTL(MSG_SEC_GENSTR_COMP), os_name,
1575892Sab196087 	    EC_XWORD(raw_size), EC_XWORD(merge_size));
1585892Sab196087 }
1595892Sab196087 
1605892Sab196087 void
Dbg_sec_unsup_strmerge(Lm_list * lml,Is_desc * isp)1615892Sab196087 Dbg_sec_unsup_strmerge(Lm_list *lml, Is_desc *isp)
1625892Sab196087 {
1639406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
1649406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
1659406SAli.Bahrami@Sun.COM 	const char		*str;
1665892Sab196087 
1675892Sab196087 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1685892Sab196087 		return;
1695892Sab196087 
1705892Sab196087 	/*
1715892Sab196087 	 * We can only merge string table sections with single byte
1725892Sab196087 	 * (char) characters. For any other (wide) character types,
1735892Sab196087 	 * issue a message so the user will understand why these
1745892Sab196087 	 * sections are not being picked up.
1755892Sab196087 	 */
1765892Sab196087 	if ((isp->is_shdr->sh_entsize > 1) ||
1775892Sab196087 	    (isp->is_shdr->sh_addralign > 1)) {
1785892Sab196087 		str = (isp->is_file != NULL) ? isp->is_file->ifl_name :
1795892Sab196087 		    MSG_INTL(MSG_STR_NULL);
1805892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_UNSUP),
1819406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem), str,
1829406SAli.Bahrami@Sun.COM 		    EC_XWORD(isp->is_shdr->sh_addralign),
1835892Sab196087 		    EC_XWORD(isp->is_shdr->sh_entsize));
1849406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
1859406SAli.Bahrami@Sun.COM 			free(alloc_mem);
1865892Sab196087 	}
1875892Sab196087 }
1885892Sab196087 
1895892Sab196087 void
Dbg_sec_backing(Lm_list * lml)1909131SRod.Evans@Sun.COM Dbg_sec_backing(Lm_list *lml)
1919131SRod.Evans@Sun.COM {
1929131SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
1939131SRod.Evans@Sun.COM 		return;
1949131SRod.Evans@Sun.COM 
1959131SRod.Evans@Sun.COM 	Dbg_util_nl(lml, DBG_NL_STD);
1969131SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_BACKING));
1979131SRod.Evans@Sun.COM }
1989131SRod.Evans@Sun.COM 
1999131SRod.Evans@Sun.COM void
Dbg_sec_in(Lm_list * lml,Is_desc * isp)2001618Srie Dbg_sec_in(Lm_list *lml, Is_desc *isp)
2010Sstevel@tonic-gate {
2021618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2030Sstevel@tonic-gate 		return;
2040Sstevel@tonic-gate 
2055892Sab196087 	if (isp->is_flags & FLG_IS_GNSTRMRG) {
2065892Sab196087 		/*
2075892Sab196087 		 * This section was generated because we have 1 or
2085892Sab196087 		 * more SHF_MERGE|SHF_STRINGS input sections that we
2095892Sab196087 		 * wish to merge. This new section will ultimately
2105892Sab196087 		 * end up replacing those sections once it has been filled
2115892Sab196087 		 * with their strings (merged and compressed) and relocations
2125892Sab196087 		 * have been redirected.
2135892Sab196087 		 */
2145892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GENSTR), isp->is_name);
2159406SAli.Bahrami@Sun.COM 	} else if (isp->is_file == NULL) {
2169406SAli.Bahrami@Sun.COM 		/* Generated input section */
2179406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT_GEN), isp->is_name);
2185892Sab196087 	} else {
2195892Sab196087 		/* Standard input section */
2209406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf;
2219406SAli.Bahrami@Sun.COM 		char			*alloc_mem;
2229406SAli.Bahrami@Sun.COM 
2239406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_INPUT),
2249406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
2259406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name);
2269406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
2279406SAli.Bahrami@Sun.COM 			free(alloc_mem);
2285892Sab196087 	}
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate void
Dbg_sec_added(Lm_list * lml,Os_desc * osp,Sg_desc * sgp)2321618Srie Dbg_sec_added(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2330Sstevel@tonic-gate {
2341618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2350Sstevel@tonic-gate 		return;
2360Sstevel@tonic-gate 
237*11734SAli.Bahrami@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_ADDED), osp->os_name,
238*11734SAli.Bahrami@Sun.COM 	    (sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL)));
2390Sstevel@tonic-gate }
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate void
Dbg_sec_created(Lm_list * lml,Os_desc * osp,Sg_desc * sgp)2421618Srie Dbg_sec_created(Lm_list *lml, Os_desc *osp, Sg_desc *sgp)
2430Sstevel@tonic-gate {
2441618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2450Sstevel@tonic-gate 		return;
2460Sstevel@tonic-gate 
247*11734SAli.Bahrami@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_CREATED), osp->os_name,
248*11734SAli.Bahrami@Sun.COM 	    (sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL)));
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate void
Dbg_sec_discarded(Lm_list * lml,Is_desc * isp,Is_desc * disp)2521618Srie Dbg_sec_discarded(Lm_list *lml, Is_desc *isp, Is_desc *disp)
2530Sstevel@tonic-gate {
2545549Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS | DBG_C_UNUSED))
2550Sstevel@tonic-gate 		return;
2560Sstevel@tonic-gate 
2575892Sab196087 	if ((isp->is_flags & FLG_IS_INSTRMRG) &&
2585892Sab196087 	    (disp->is_flags & FLG_IS_GNSTRMRG)) {
2595892Sab196087 		/*
2605892Sab196087 		 * This SHF_MERGE|SHF_STRINGS input section is being
2615892Sab196087 		 * discarded in favor of the generated merged string section.
2625892Sab196087 		 */
2639406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf;
2649406SAli.Bahrami@Sun.COM 		char			*alloc_mem;
2659406SAli.Bahrami@Sun.COM 
2665892Sab196087 		dbg_print(lml, MSG_INTL(MSG_SEC_STRMERGE_DISCARDED),
2679406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf, &alloc_mem),
2689406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name);
2699406SAli.Bahrami@Sun.COM 		if (alloc_mem != NULL)
2709406SAli.Bahrami@Sun.COM 			free(alloc_mem);
2715892Sab196087 	} else {
2725892Sab196087 		/* Generic section discard */
2739406SAli.Bahrami@Sun.COM 		dbg_isec_name_buf_t	buf1, buf2;
2749406SAli.Bahrami@Sun.COM 		char			*alloc_mem1, *alloc_mem2;
2759406SAli.Bahrami@Sun.COM 
2769406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_DISCARDED),
2779406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(isp, buf1, &alloc_mem1),
2789406SAli.Bahrami@Sun.COM 		    isp->is_file->ifl_name,
2799406SAli.Bahrami@Sun.COM 		    dbg_fmt_isec_name(disp, buf2, &alloc_mem2),
2805892Sab196087 		    disp->is_file->ifl_name);
2819406SAli.Bahrami@Sun.COM 		if (alloc_mem1 != NULL)
2829406SAli.Bahrami@Sun.COM 			free(alloc_mem1);
2839406SAli.Bahrami@Sun.COM 		if (alloc_mem2 != NULL)
2849406SAli.Bahrami@Sun.COM 			free(alloc_mem2);
2855892Sab196087 	}
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate void
Dbg_sec_group(Lm_list * lml,Is_desc * isp,Group_desc * gdp)2891618Srie Dbg_sec_group(Lm_list *lml, Is_desc *isp, Group_desc *gdp)
2900Sstevel@tonic-gate {
2919406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
2929406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
2939406SAli.Bahrami@Sun.COM 	const char		*comdat, *isp_str;
29433Srie 
2951618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
2960Sstevel@tonic-gate 		return;
2970Sstevel@tonic-gate 
2987463SRod.Evans@Sun.COM 	if (gdp->gd_data[0] & GRP_COMDAT)
2997463SRod.Evans@Sun.COM 		comdat = MSG_ORIG(MSG_STR_COMDAT);
30033Srie 	else
3017463SRod.Evans@Sun.COM 		comdat = MSG_ORIG(MSG_STR_EMPTY);
30233Srie 
3039406SAli.Bahrami@Sun.COM 	isp_str = dbg_fmt_isec_name(isp, buf, &alloc_mem);
3049406SAli.Bahrami@Sun.COM 
3057463SRod.Evans@Sun.COM 	if (isp->is_shdr->sh_type == SHT_GROUP) {
3069406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DEFINE), isp_str,
3077463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3087463SRod.Evans@Sun.COM 	} else {
3099406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_MEMBER), isp_str,
3107463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, comdat, gdp->gd_name);
3117463SRod.Evans@Sun.COM 	}
3127463SRod.Evans@Sun.COM 
3137463SRod.Evans@Sun.COM 	if (gdp->gd_oisc) {
3149406SAli.Bahrami@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_SEC_GRP_DISCARDED), isp_str,
3157463SRod.Evans@Sun.COM 		    isp->is_file->ifl_name, gdp->gd_name,
3167463SRod.Evans@Sun.COM 		    gdp->gd_oisc->is_file->ifl_name);
3177463SRod.Evans@Sun.COM 	}
3189406SAli.Bahrami@Sun.COM 
3199406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
3209406SAli.Bahrami@Sun.COM 		free(alloc_mem);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate void
Dbg_sec_order_list(Ofl_desc * ofl,int flag)3240Sstevel@tonic-gate Dbg_sec_order_list(Ofl_desc *ofl, int flag)
3250Sstevel@tonic-gate {
3260Sstevel@tonic-gate 	Os_desc		*osp;
3270Sstevel@tonic-gate 	Is_desc		*isp1;
3289131SRod.Evans@Sun.COM 	Aliste		idx1;
3291618Srie 	Lm_list		*lml = ofl->ofl_lml;
3300Sstevel@tonic-gate 	const char	*str;
3310Sstevel@tonic-gate 
3321618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
3330Sstevel@tonic-gate 		return;
3340Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
3350Sstevel@tonic-gate 		return;
3360Sstevel@tonic-gate 
3372647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3382647Srie 
3390Sstevel@tonic-gate 	/*
3400Sstevel@tonic-gate 	 * If the flag == 0, then the routine is called before sorting.
3410Sstevel@tonic-gate 	 */
3420Sstevel@tonic-gate 	if (flag == 0)
3430Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_BEFORE);
3440Sstevel@tonic-gate 	else
3450Sstevel@tonic-gate 		str = MSG_INTL(MSG_ORD_SORT_AFTER);
3460Sstevel@tonic-gate 
3479131SRod.Evans@Sun.COM 	for (APLIST_TRAVERSE(ofl->ofl_ordered, idx1, osp)) {
3489615SAli.Bahrami@Sun.COM 		int		os_isdescs_idx;
3499131SRod.Evans@Sun.COM 		Aliste		idx2;
3500Sstevel@tonic-gate 
3519406SAli.Bahrami@Sun.COM 		Dbg_util_nl(lml, DBG_NL_STD);
3521618Srie 		dbg_print(lml, str, osp->os_name);
3531618Srie 		dbg_print(lml, MSG_INTL(MSG_ORD_HDR_1),
3549615SAli.Bahrami@Sun.COM 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_BEFORE])),
3559615SAli.Bahrami@Sun.COM 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_ORDERED])),
3569615SAli.Bahrami@Sun.COM 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_DEFAULT])),
3579615SAli.Bahrami@Sun.COM 		    EC_WORD(aplist_nitems(osp->os_isdescs[OS_ISD_AFTER])));
3580Sstevel@tonic-gate 
3599615SAli.Bahrami@Sun.COM 		OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx2, isp1) {
3609406SAli.Bahrami@Sun.COM 			dbg_isec_name_buf_t	buf;
3619406SAli.Bahrami@Sun.COM 			char			*alloc_mem;
3629406SAli.Bahrami@Sun.COM 			const char		*isp1_str;
3639406SAli.Bahrami@Sun.COM 			Word			link;
3649406SAli.Bahrami@Sun.COM 			Ifl_desc		*ifl = isp1->is_file;
3659406SAli.Bahrami@Sun.COM 			Is_desc			*isp2;
3669406SAli.Bahrami@Sun.COM 			const char		*msg;
3670Sstevel@tonic-gate 
3689406SAli.Bahrami@Sun.COM 			/*
36910436SRod.Evans@Sun.COM 			 * An output segment that requires ordering might have
37010436SRod.Evans@Sun.COM 			 * as little as two sorted input sections.  For example,
37110436SRod.Evans@Sun.COM 			 * the crt's can provide a SHN_BEGIN and SHN_AFTER, and
37210436SRod.Evans@Sun.COM 			 * only these two sections must be processed.  Thus, if
37310436SRod.Evans@Sun.COM 			 * a input section is unordered, move on.  Diagnosing
37410436SRod.Evans@Sun.COM 			 * any unsorted section can produce way too much noise.
3759406SAli.Bahrami@Sun.COM 			 */
37610436SRod.Evans@Sun.COM 			if ((isp1->is_flags & FLG_IS_ORDERED) == 0)
3770Sstevel@tonic-gate 				continue;
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 			if (isp1->is_shdr->sh_flags & SHF_ORDERED) {
3800Sstevel@tonic-gate 				link = isp1->is_shdr->sh_info;
3812647Srie 				msg = MSG_ORIG(MSG_SH_INFO);
3829406SAli.Bahrami@Sun.COM 			} else {	/* SHF_LINK_ORDER */
3830Sstevel@tonic-gate 				link = isp1->is_shdr->sh_link;
3842647Srie 				msg = MSG_ORIG(MSG_SH_LINK);
3850Sstevel@tonic-gate 			}
3860Sstevel@tonic-gate 
3879406SAli.Bahrami@Sun.COM 			isp1_str = dbg_fmt_isec_name(isp1, buf, &alloc_mem);
3880Sstevel@tonic-gate 
3899406SAli.Bahrami@Sun.COM 			if (link == SHN_BEFORE) {
3909406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_1), msg,
3919406SAli.Bahrami@Sun.COM 				    isp1_str, isp1->is_file->ifl_name);
3929406SAli.Bahrami@Sun.COM 			} else if (link == SHN_AFTER) {
3939406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_2), msg,
3949406SAli.Bahrami@Sun.COM 				    isp1_str, isp1->is_file->ifl_name);
3959406SAli.Bahrami@Sun.COM 			} else {
3969406SAli.Bahrami@Sun.COM 				isp2 = ifl->ifl_isdesc[link];
3979406SAli.Bahrami@Sun.COM 				dbg_print(lml, MSG_INTL(MSG_ORD_TITLE_3),
3989406SAli.Bahrami@Sun.COM 				    EC_WORD(isp2->is_keyident), isp1_str,
3999406SAli.Bahrami@Sun.COM 				    ifl->ifl_name, msg, isp2->is_name);
4000Sstevel@tonic-gate 			}
4019406SAli.Bahrami@Sun.COM 			if (alloc_mem != NULL)
4029406SAli.Bahrami@Sun.COM 				free(alloc_mem);
4030Sstevel@tonic-gate 		}
4040Sstevel@tonic-gate 	}
4052647Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate 
4085549Srie /*
4095549Srie  * Error message string table.
4105549Srie  */
4115549Srie static const Msg order_errors[] = {
4125549Srie 	MSG_ORD_ERR_INFORANGE,		/* MSG_INTL(MSG_ORD_ERR_INFORANGE) */
4135549Srie 	MSG_ORD_ERR_ORDER,		/* MSG_INTL(MSG_ORD_ERR_ORDER) */
4145549Srie 	MSG_ORD_ERR_LINKRANGE,		/* MSG_INTL(MSG_ORD_ERR_LINKRANGE) */
4155549Srie 	MSG_ORD_ERR_FLAGS,		/* MSG_INTL(MSG_ORD_ERR_FLAGS) */
4165549Srie 	MSG_ORD_ERR_CYCLIC,		/* MSG_INTL(MSG_ORD_ERR_CYCLIC) */
4175549Srie 	MSG_ORD_ERR_LINKINV		/* MSG_INTL(MSG_ORD_ERR_LINKINV) */
4185549Srie };
4195549Srie 
4200Sstevel@tonic-gate void
Dbg_sec_order_error(Lm_list * lml,Ifl_desc * ifl,Word ndx,int error)4211618Srie Dbg_sec_order_error(Lm_list *lml, Ifl_desc *ifl, Word ndx, int error)
4220Sstevel@tonic-gate {
4239406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
4249406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
4259406SAli.Bahrami@Sun.COM 
4261618Srie 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4270Sstevel@tonic-gate 		return;
4280Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4290Sstevel@tonic-gate 		return;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	if (error == 0)
4320Sstevel@tonic-gate 		return;
4330Sstevel@tonic-gate 
4341618Srie 	dbg_print(lml, MSG_INTL(MSG_ORD_ERR_TITLE),
4359406SAli.Bahrami@Sun.COM 	    dbg_fmt_isec_name(ifl->ifl_isdesc[ndx], buf, &alloc_mem),
4369406SAli.Bahrami@Sun.COM 	    ifl->ifl_name);
4379406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
4389406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 	if (error)
4411618Srie 		dbg_print(lml, MSG_INTL(order_errors[error - 1]));
4420Sstevel@tonic-gate }
4437463SRod.Evans@Sun.COM 
4447463SRod.Evans@Sun.COM void
Dbg_sec_redirected(Lm_list * lml,Is_desc * isp,const char * nname)4459406SAli.Bahrami@Sun.COM Dbg_sec_redirected(Lm_list *lml, Is_desc *isp, const char *nname)
4467463SRod.Evans@Sun.COM {
4479406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
4489406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
4499406SAli.Bahrami@Sun.COM 
4507463SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4517463SRod.Evans@Sun.COM 		return;
4527463SRod.Evans@Sun.COM 
4539406SAli.Bahrami@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_SEC_REDIRECTED),
4549406SAli.Bahrami@Sun.COM 	    dbg_fmt_isec_name(isp, buf, &alloc_mem), nname);
4559406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
4569406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4577463SRod.Evans@Sun.COM }
4587463SRod.Evans@Sun.COM 
4597463SRod.Evans@Sun.COM void
Dbg_sec_gnu_comdat(Lm_list * lml,Is_desc * isp,Boolean comdat,Boolean relax)46011227SAli.Bahrami@Sun.COM Dbg_sec_gnu_comdat(Lm_list *lml, Is_desc *isp, Boolean comdat, Boolean relax)
4617463SRod.Evans@Sun.COM {
4629406SAli.Bahrami@Sun.COM 	dbg_isec_name_buf_t	buf;
4639406SAli.Bahrami@Sun.COM 	char			*alloc_mem;
4649406SAli.Bahrami@Sun.COM 	const char		*fmt;
4657463SRod.Evans@Sun.COM 
4667463SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_SECTIONS))
4677463SRod.Evans@Sun.COM 		return;
4687463SRod.Evans@Sun.COM 
4697463SRod.Evans@Sun.COM 	if (comdat && relax)
4707463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_1);
4717463SRod.Evans@Sun.COM 	else if (comdat)
4727463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_2);
4737463SRod.Evans@Sun.COM 	else
4747463SRod.Evans@Sun.COM 		fmt = MSG_INTL(MSG_SEC_GNU_COMDAT_3);
4757463SRod.Evans@Sun.COM 
4769406SAli.Bahrami@Sun.COM 	dbg_print(lml, fmt, dbg_fmt_isec_name(isp, buf, &alloc_mem));
4779406SAli.Bahrami@Sun.COM 	if (alloc_mem != NULL)
4789406SAli.Bahrami@Sun.COM 		free(alloc_mem);
4797463SRod.Evans@Sun.COM }
480