xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/bindings.c (revision c94146ce6d2a316eca6450a8cd77d8dee993f233)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 
29 #include	<sys/types.h>
30 #include	<string.h>
31 #include	<debug.h>
32 #include	<conv.h>
33 #include	"_debug.h"
34 #include	"msg.h"
35 
36 void
37 Dbg_bind_plt_summary(Lm_list *lml, Half mach, Word pltcnt21d, Word pltcnt24d,
38     Word pltcntu32, Word pltcntu44, Word pltcntfull, Word pltcntfar)
39 {
40 	Word plttotal = pltcnt21d + pltcnt24d + pltcntu32 +
41 	    pltcntu44 + pltcntfull + pltcntfar;
42 
43 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
44 		return;
45 
46 	switch (mach) {
47 	case EM_SPARC:
48 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARC), EC_WORD(pltcnt21d),
49 		    EC_WORD(pltcnt24d), EC_WORD(pltcntfull), EC_WORD(plttotal));
50 		break;
51 	case EM_SPARCV9:
52 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARCV9),
53 		    EC_WORD(pltcnt21d), EC_WORD(pltcnt24d), EC_WORD(pltcntu32),
54 		    EC_WORD(pltcntu44), EC_WORD(pltcntfull), EC_WORD(pltcntfar),
55 		    EC_WORD(plttotal));
56 		break;
57 	default:
58 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_DEFAULT),
59 		    EC_WORD(plttotal));
60 		break;
61 	};
62 }
63 
64 static const char	*pltbindtypes[PLT_T_NUM] = {
65 	MSG_ORIG(MSG_STR_EMPTY),	/* PLT_T_NONE */
66 	MSG_ORIG(MSG_PLT_21D),		/* PLT_T_21D */
67 	MSG_ORIG(MSG_PLT_24D),		/* PLT_T_24D */
68 	MSG_ORIG(MSG_PLT_U32),		/* PLT_T_U32 */
69 	MSG_ORIG(MSG_PLT_U44),		/* PLT_T_U44 */
70 	MSG_ORIG(MSG_PLT_FULL),		/* PLT_T_FULL */
71 	MSG_ORIG(MSG_PLT_FAR)		/* PLT_T_FAR */
72 };
73 
74 #define	BINFOSZ	MSG_BINFO_START_SIZE + \
75 		MSG_BINFO_DIRECT_SIZE +		MSG_BINFO_SEP_SIZE + \
76 		MSG_BINFO_INTERPOSE_SIZE +	MSG_BINFO_SEP_SIZE + \
77 		MSG_BINFO_COPYREF_SIZE +	MSG_BINFO_SEP_SIZE + \
78 		MSG_BINFO_FILTEE_SIZE +		MSG_BINFO_SEP_SIZE + \
79 		MSG_BINFO_PLTADDR_SIZE + \
80 		CONV_INV_BUFSIZE + MSG_BINFO_END_SIZE
81 
82 
83 void
84 Dbg_bind_global(Rt_map *flmp, Addr fabs, Off foff, Xword pltndx,
85     Pltbindtype pbtype, Rt_map *tlmp, Addr tabs, Off toff,
86     const char *sym, uint_t binfo)
87 {
88 	static char binfostr[BINFOSZ];
89 	static Val_desc vda[] = {
90 		{ DBG_BINFO_DIRECT,	MSG_ORIG(MSG_BINFO_DIRECT) },
91 		{ DBG_BINFO_INTERPOSE,	MSG_ORIG(MSG_BINFO_INTERPOSE) },
92 		{ DBG_BINFO_COPYREF,	MSG_ORIG(MSG_BINFO_COPYREF) },
93 		{ DBG_BINFO_FILTEE,	MSG_ORIG(MSG_BINFO_FILTEE) },
94 		{ DBG_BINFO_PLTADDR,	MSG_ORIG(MSG_BINFO_PLTADDR) },
95 		{ 0,			0 }
96 	};
97 	static CONV_EXPN_FIELD_ARG conv_arg = { binfostr, sizeof (binfostr),
98 		vda, NULL, 0, 0, MSG_ORIG(MSG_BINFO_START),
99 		MSG_ORIG(MSG_BINFO_SEP), MSG_ORIG(MSG_BINFO_END) };
100 
101 	const char	*ffile = NAME(flmp);
102 	const char	*tfile = NAME(tlmp);
103 	Lm_list		*lml = LIST(flmp);
104 
105 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
106 		return;
107 
108 	if (DBG_NOTDETAIL()) {
109 		dbg_print(lml, MSG_INTL(MSG_BND_BASIC), ffile, tfile,
110 		    Dbg_demangle_name(sym));
111 		return;
112 	}
113 
114 	/*
115 	 * Determine if this binding has any associated information, such as
116 	 * interposition, direct binding, copy-relocations, etc.
117 	 */
118 	binfo &= ~DBG_BINFO_FOUND;
119 	binfo &= DBG_BINFO_MSK;
120 	if (binfo) {
121 		conv_arg.oflags = conv_arg.rflags = binfo;
122 		(void) conv_expn_field(&conv_arg, 0);
123 	} else {
124 		binfostr[0] = '\0';
125 	}
126 
127 	if (pltndx != (Xword)-1) {
128 		const char	*pltstring;
129 
130 		if (pbtype < PLT_T_NUM)
131 			pltstring = pltbindtypes[pbtype];
132 		else
133 			pltstring = pltbindtypes[PLT_T_NONE];
134 
135 		/*
136 		 * Called from a plt offset.
137 		 */
138 		dbg_print(lml, MSG_INTL(MSG_BND_PLT), ffile, EC_ADDR(fabs),
139 		    EC_OFF(foff), EC_XWORD(pltndx), pltstring, tfile,
140 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
141 		    binfostr);
142 
143 	} else if ((fabs == 0) && (foff == 0)) {
144 		/*
145 		 * Called from a dlsym().  We're not performing a relocation,
146 		 * but are handing the address of the symbol back to the user.
147 		 */
148 		dbg_print(lml, MSG_INTL(MSG_BND_DLSYM), ffile, tfile,
149 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
150 		    binfostr);
151 	} else {
152 		/*
153 		 * Standard relocation.
154 		 */
155 		dbg_print(lml, MSG_INTL(MSG_BND_DEFAULT), ffile, EC_ADDR(fabs),
156 		    EC_OFF(foff), tfile, EC_ADDR(tabs), EC_OFF(toff),
157 		    Dbg_demangle_name(sym), binfostr);
158 	}
159 }
160 
161 void
162 Dbg_bind_reject(Rt_map *flmp, Rt_map *tlmp, const char *sym, int why)
163 {
164 	static Msg reason[DBG_BNDREJ_NUM + 1] = {
165 		MSG_BNDREJ_NODIR,	/* MSG_INTL(MSG_BNDREJ_NODIR) */
166 		MSG_BNDREJ_SINGLE	/* MSG_INTL(MSG_BNDREJ_SINGLE) */
167 	};
168 
169 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
170 		return;
171 
172 	dbg_print(LIST(flmp), MSG_INTL(MSG_BND_REJECT), NAME(flmp), NAME(tlmp),
173 	    sym, MSG_INTL(reason[why]));
174 }
175 
176 void
177 Dbg_bind_weak(Rt_map *flmp, Addr fabs, Addr frel, const char *sym)
178 {
179 	Lm_list		*lml = LIST(flmp);
180 	const char	*ffile = NAME(flmp);
181 
182 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
183 		return;
184 
185 	if (DBG_NOTDETAIL())
186 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_1), ffile,
187 		    Dbg_demangle_name(sym));
188 	else
189 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_2), ffile, EC_ADDR(fabs),
190 		    EC_ADDR(frel), Dbg_demangle_name(sym));
191 }
192 
193 #if	defined(_ELF64)
194 
195 void
196 Dbg_bind_pltpad_to(Rt_map *lmp, Addr pltpad, const char *dfile,
197     const char *sname)
198 {
199 	if (DBG_NOTCLASS(DBG_C_RELOC))
200 		return;
201 	if (DBG_NOTDETAIL())
202 		return;
203 
204 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_TO), EC_ADDR(pltpad),
205 	    NAME(lmp), dfile, sname);
206 }
207 
208 void
209 Dbg_bind_pltpad_from(Rt_map *lmp, Addr pltpad, const char *sname)
210 {
211 	if (DBG_NOTCLASS(DBG_C_RELOC))
212 		return;
213 	if (DBG_NOTDETAIL())
214 		return;
215 
216 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_FROM), EC_ADDR(pltpad),
217 	    NAME(lmp), sname);
218 }
219 
220 #endif
221