xref: /titanic_51/usr/src/cmd/sgs/liblddbg/common/unused.c (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	"msg.h"
28 #include	"_debug.h"
29 #include	"libld.h"
30 
31 void
32 Dbg_unused_unref(Rt_map *lmp, const char *depend)
33 {
34 	if (DBG_NOTCLASS(DBG_C_UNUSED))
35 		return;
36 	if (DBG_NOTDETAIL())
37 		return;
38 
39 	dbg_print(LIST(lmp), MSG_INTL(MSG_USD_UNREF), NAME(lmp), depend);
40 }
41 
42 void
43 Dbg_unused_sec(Lm_list *lml, Is_desc *isp)
44 {
45 	dbg_isec_name_buf_t	buf;
46 	char			*alloc_mem;
47 	const char		*str;
48 
49 	if (DBG_NOTCLASS(DBG_C_UNUSED))
50 		return;
51 	if (DBG_NOTDETAIL())
52 		return;
53 
54 	/*
55 	 * If the file from which this section originates hasn't been referenced
56 	 * at all, skip this diagnostic, as it would have been covered under
57 	 * Dbg_unused_file() called from ignore_section_processing().
58 	 */
59 	if (isp->is_file &&
60 	    ((isp->is_file->ifl_flags & FLG_IF_FILEREF) == 0))
61 		return;
62 
63 	if (isp->is_flags & FLG_IS_DISCARD)
64 		str = MSG_INTL(MSG_USD_SECDISCARD);
65 	else
66 		str = MSG_ORIG(MSG_STR_EMPTY);
67 
68 	dbg_print(lml, MSG_INTL(MSG_USD_SEC),
69 	    dbg_fmt_isec_name(isp, buf, &alloc_mem),
70 	    EC_XWORD(isp->is_shdr->sh_size), isp->is_file->ifl_name, str);
71 	if (alloc_mem != NULL)
72 		free(alloc_mem);
73 }
74 
75 void
76 Dbg_unused_file(Lm_list *lml, const char *name, int needstr, uint_t cycle)
77 {
78 	if (DBG_NOTCLASS(DBG_C_UNUSED))
79 		return;
80 
81 	if (needstr)
82 		dbg_print(lml, MSG_INTL(MSG_USD_NEEDSTR), name);
83 	else if (cycle)
84 		dbg_print(lml, MSG_INTL(MSG_USD_FILECYCLIC), name, cycle);
85 	else
86 		dbg_print(lml, MSG_INTL(MSG_USD_FILE), name);
87 }
88 
89 void
90 Dbg_unused_path(Lm_list *lml, const char *path, uint_t orig, uint_t dup,
91     const char *obj)
92 {
93 	const char	*fmt;
94 
95 	if (DBG_NOTCLASS(DBG_C_UNUSED))
96 		return;
97 	if (DBG_NOTDETAIL())
98 		return;
99 
100 	if (orig & LA_SER_LIBPATH) {
101 		if (orig & LA_SER_CONFIG) {
102 			if (dup)
103 				fmt = MSG_INTL(MSG_DUP_LDLIBPATHC);
104 			else
105 				fmt = MSG_INTL(MSG_USD_LDLIBPATHC);
106 		} else {
107 			if (dup)
108 				fmt = MSG_INTL(MSG_DUP_LDLIBPATH);
109 			else
110 				fmt = MSG_INTL(MSG_USD_LDLIBPATH);
111 		}
112 	} else if (orig & LA_SER_RUNPATH) {
113 		fmt = MSG_INTL(MSG_USD_RUNPATH);
114 	} else
115 		return;
116 
117 	dbg_print(lml, fmt, path, obj);
118 }
119