xref: /titanic_51/usr/src/cmd/sgs/liblddbg/common/unused.c (revision 60c45ed01d4f99571d468c42f609d11a099fab1e)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	"msg.h"
29 #include	"_debug.h"
30 #include	"libld.h"
31 
32 void
33 Dbg_unused_unref(Rt_map *lmp, const char *depend)
34 {
35 	if (DBG_NOTCLASS(DBG_C_UNUSED))
36 		return;
37 	if (DBG_NOTDETAIL())
38 		return;
39 
40 	dbg_print(LIST(lmp), MSG_INTL(MSG_USD_UNREF), NAME(lmp), depend);
41 }
42 
43 void
44 Dbg_unused_sec(Lm_list *lml, Is_desc *isp)
45 {
46 	const char	*str;
47 
48 	if (DBG_NOTCLASS(DBG_C_UNUSED))
49 		return;
50 	if (DBG_NOTDETAIL())
51 		return;
52 
53 	/*
54 	 * If the file from which this section originates hasn't been referenced
55 	 * at all, skip this diagnostic, as it would have been covered under
56 	 * Dbg_unused_file() called from ignore_section_processing().
57 	 */
58 	if (isp->is_file &&
59 	    ((isp->is_file->ifl_flags & FLG_IF_FILEREF) == 0))
60 		return;
61 
62 	if (isp->is_flags & FLG_IS_DISCARD)
63 		str = MSG_INTL(MSG_USD_SECDISCARD);
64 	else
65 		str = MSG_ORIG(MSG_STR_EMPTY);
66 
67 	dbg_print(lml, MSG_INTL(MSG_USD_SEC), isp->is_basename,
68 	    EC_XWORD(isp->is_shdr->sh_size), isp->is_file->ifl_name, str);
69 }
70 
71 void
72 Dbg_unused_file(Lm_list *lml, const char *name, int needstr, uint_t cycle)
73 {
74 	if (DBG_NOTCLASS(DBG_C_UNUSED))
75 		return;
76 
77 	if (needstr)
78 		dbg_print(lml, MSG_INTL(MSG_USD_NEEDSTR), name);
79 	else if (cycle)
80 		dbg_print(lml, MSG_INTL(MSG_USD_FILECYCLIC), name, cycle);
81 	else
82 		dbg_print(lml, MSG_INTL(MSG_USD_FILE), name);
83 }
84 
85 void
86 Dbg_unused_path(Lm_list *lml, const char *path, uint_t orig, uint_t dup,
87     const char *obj)
88 {
89 	const char	*fmt;
90 
91 	if (DBG_NOTCLASS(DBG_C_UNUSED))
92 		return;
93 	if (DBG_NOTDETAIL())
94 		return;
95 
96 	if (orig & LA_SER_LIBPATH) {
97 		if (orig & LA_SER_CONFIG) {
98 			if (dup)
99 				fmt = MSG_INTL(MSG_DUP_LDLIBPATHC);
100 			else
101 				fmt = MSG_INTL(MSG_USD_LDLIBPATHC);
102 		} else {
103 			if (dup)
104 				fmt = MSG_INTL(MSG_DUP_LDLIBPATH);
105 			else
106 				fmt = MSG_INTL(MSG_USD_LDLIBPATH);
107 		}
108 	} else if (orig & LA_SER_RUNPATH) {
109 		fmt = MSG_INTL(MSG_USD_RUNPATH);
110 	} else
111 		return;
112 
113 	dbg_print(lml, fmt, path, obj);
114 }
115