xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/unused.c (revision e23c41c9edb2294649cde3d370ae755701f3f140)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21fb1354edSrie 
227c478bd9Sstevel@tonic-gate /*
23*e23c41c9SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include	"msg.h"
287c478bd9Sstevel@tonic-gate #include	"_debug.h"
297c478bd9Sstevel@tonic-gate #include	"libld.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate void
Dbg_unused_unref(Rt_map * lmp,const char * depend)325aefb655Srie Dbg_unused_unref(Rt_map *lmp, const char *depend)
335aefb655Srie {
345aefb655Srie 	if (DBG_NOTCLASS(DBG_C_UNUSED))
355aefb655Srie 		return;
365aefb655Srie 	if (DBG_NOTDETAIL())
375aefb655Srie 		return;
385aefb655Srie 
395aefb655Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_USD_UNREF), NAME(lmp), depend);
405aefb655Srie }
415aefb655Srie 
425aefb655Srie void
Dbg_unused_sec(Lm_list * lml,Is_desc * isp)435aefb655Srie Dbg_unused_sec(Lm_list *lml, Is_desc *isp)
447c478bd9Sstevel@tonic-gate {
45*e23c41c9SAli Bahrami 	dbg_isec_name_buf_t	buf;
46*e23c41c9SAli Bahrami 	char			*alloc_mem;
477c478bd9Sstevel@tonic-gate 	const char		*str;
487c478bd9Sstevel@tonic-gate 
495aefb655Srie 	if (DBG_NOTCLASS(DBG_C_UNUSED))
507c478bd9Sstevel@tonic-gate 		return;
517c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
527c478bd9Sstevel@tonic-gate 		return;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	/*
557c478bd9Sstevel@tonic-gate 	 * If the file from which this section originates hasn't been referenced
567c478bd9Sstevel@tonic-gate 	 * at all, skip this diagnostic, as it would have been covered under
577c478bd9Sstevel@tonic-gate 	 * Dbg_unused_file() called from ignore_section_processing().
587c478bd9Sstevel@tonic-gate 	 */
597c478bd9Sstevel@tonic-gate 	if (isp->is_file &&
607c478bd9Sstevel@tonic-gate 	    ((isp->is_file->ifl_flags & FLG_IF_FILEREF) == 0))
617c478bd9Sstevel@tonic-gate 		return;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	if (isp->is_flags & FLG_IS_DISCARD)
647c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_USD_SECDISCARD);
657c478bd9Sstevel@tonic-gate 	else
667c478bd9Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
677c478bd9Sstevel@tonic-gate 
68*e23c41c9SAli Bahrami 	dbg_print(lml, MSG_INTL(MSG_USD_SEC),
69*e23c41c9SAli Bahrami 	    dbg_fmt_isec_name(isp, buf, &alloc_mem),
707c478bd9Sstevel@tonic-gate 	    EC_XWORD(isp->is_shdr->sh_size), isp->is_file->ifl_name, str);
71*e23c41c9SAli Bahrami 	if (alloc_mem != NULL)
72*e23c41c9SAli Bahrami 		free(alloc_mem);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate void
Dbg_unused_file(Lm_list * lml,const char * name,int needstr,uint_t cycle)765aefb655Srie Dbg_unused_file(Lm_list *lml, const char *name, int needstr, uint_t cycle)
777c478bd9Sstevel@tonic-gate {
785aefb655Srie 	if (DBG_NOTCLASS(DBG_C_UNUSED))
797c478bd9Sstevel@tonic-gate 		return;
807c478bd9Sstevel@tonic-gate 
81fb1354edSrie 	if (needstr)
825aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_USD_NEEDSTR), name);
83fb1354edSrie 	else if (cycle)
845aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_USD_FILECYCLIC), name, cycle);
857c478bd9Sstevel@tonic-gate 	else
865aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_USD_FILE), name);
877c478bd9Sstevel@tonic-gate }
889aa23310Srie 
899aa23310Srie void
Dbg_unused_path(Lm_list * lml,const char * path,uint_t orig,uint_t dup,const char * obj)909aa23310Srie Dbg_unused_path(Lm_list *lml, const char *path, uint_t orig, uint_t dup,
919aa23310Srie     const char *obj)
929aa23310Srie {
939aa23310Srie 	const char	*fmt;
949aa23310Srie 
959aa23310Srie 	if (DBG_NOTCLASS(DBG_C_UNUSED))
969aa23310Srie 		return;
979aa23310Srie 	if (DBG_NOTDETAIL())
989aa23310Srie 		return;
999aa23310Srie 
1009aa23310Srie 	if (orig & LA_SER_LIBPATH) {
1019aa23310Srie 		if (orig & LA_SER_CONFIG) {
1029aa23310Srie 			if (dup)
1039aa23310Srie 				fmt = MSG_INTL(MSG_DUP_LDLIBPATHC);
1049aa23310Srie 			else
1059aa23310Srie 				fmt = MSG_INTL(MSG_USD_LDLIBPATHC);
1069aa23310Srie 		} else {
1079aa23310Srie 			if (dup)
1089aa23310Srie 				fmt = MSG_INTL(MSG_DUP_LDLIBPATH);
1099aa23310Srie 			else
1109aa23310Srie 				fmt = MSG_INTL(MSG_USD_LDLIBPATH);
1119aa23310Srie 		}
1129aa23310Srie 	} else if (orig & LA_SER_RUNPATH) {
1139aa23310Srie 		fmt = MSG_INTL(MSG_USD_RUNPATH);
1149aa23310Srie 	} else
1159aa23310Srie 		return;
1169aa23310Srie 
1179aa23310Srie 	dbg_print(lml, fmt, path, obj);
1189aa23310Srie }
119