xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/bindings.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include	<string.h>
31*7c478bd9Sstevel@tonic-gate #include	"msg.h"
32*7c478bd9Sstevel@tonic-gate #include	"_debug.h"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate void
35*7c478bd9Sstevel@tonic-gate Dbg_bind_plt_summary(Half mach, Word pltcnt21d, Word pltcnt24d, Word pltcntu32,
36*7c478bd9Sstevel@tonic-gate     Word pltcntu44, Word pltcntfull, Word pltcntfar)
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	Word plttotal = pltcnt21d + pltcnt24d + pltcntu32 +
39*7c478bd9Sstevel@tonic-gate 		pltcntu44 + pltcntfull + pltcntfar;
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_BINDINGS))
42*7c478bd9Sstevel@tonic-gate 		return;
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 	switch (mach) {
45*7c478bd9Sstevel@tonic-gate 	case EM_SPARC:
46*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_PSUM_SPARC), EC_WORD(pltcnt21d),
47*7c478bd9Sstevel@tonic-gate 		    EC_WORD(pltcnt24d), EC_WORD(pltcntfull), EC_WORD(plttotal));
48*7c478bd9Sstevel@tonic-gate 		break;
49*7c478bd9Sstevel@tonic-gate 	case EM_SPARCV9:
50*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_PSUM_SPARCV9), EC_WORD(pltcnt21d),
51*7c478bd9Sstevel@tonic-gate 		    EC_WORD(pltcnt24d), EC_WORD(pltcntu32), EC_WORD(pltcntu44),
52*7c478bd9Sstevel@tonic-gate 		    EC_WORD(pltcntfull), EC_WORD(pltcntfar), EC_WORD(plttotal));
53*7c478bd9Sstevel@tonic-gate 		break;
54*7c478bd9Sstevel@tonic-gate 	default:
55*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_PSUM_DEFAULT), EC_WORD(plttotal));
56*7c478bd9Sstevel@tonic-gate 		break;
57*7c478bd9Sstevel@tonic-gate 	};
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate static const char	*pltbindtypes[PLT_T_NUM] = {
61*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_STR_EMPTY),	/* PLT_T_NONE */
62*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_21D),		/* PLT_T_21D */
63*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_24D),		/* PLT_T_24D */
64*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U32),		/* PLT_T_U32 */
65*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U44),		/* PLT_T_U44 */
66*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FULL),		/* PLT_T_FULL */
67*7c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FAR)		/* PLT_T_FAR */
68*7c478bd9Sstevel@tonic-gate };
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate #define	BINFOSZ	MSG_BINFO_START_SIZE + \
71*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_DIRECT_SIZE + \
72*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_SEP_SIZE + \
73*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_COPYREF_SIZE + \
74*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_SEP_SIZE + \
75*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_FILTEE_SIZE + \
76*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_SEP_SIZE + \
77*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_PLTADDR_SIZE + \
78*7c478bd9Sstevel@tonic-gate 		MSG_BINFO_END_SIZE + 1
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate  * Normally we don't want to display any ld.so.1 bindings (i.e. the bindings
82*7c478bd9Sstevel@tonic-gate  * to these calls themselves). So, if a Dbg_bind_global() originates from
83*7c478bd9Sstevel@tonic-gate  * ld.so.1 don't print anything.  If we really want to see the ld.so.1 bindings,
84*7c478bd9Sstevel@tonic-gate  * simply give the run-time linker a different SONAME.
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate void
87*7c478bd9Sstevel@tonic-gate Dbg_bind_global(const char *ffile, caddr_t fabs, caddr_t frel, Xword pltndx,
88*7c478bd9Sstevel@tonic-gate     Pltbindtype pbtype, const char *tfile, caddr_t tabs, caddr_t trel,
89*7c478bd9Sstevel@tonic-gate     const char *sym, uint_t binfo)
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 	const char	*rfile;
92*7c478bd9Sstevel@tonic-gate 	char		binfostr[BINFOSZ];
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_BINDINGS))
95*7c478bd9Sstevel@tonic-gate 		return;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	if ((rfile = strrchr(ffile, '/')) == NULL)
98*7c478bd9Sstevel@tonic-gate 		rfile = ffile;
99*7c478bd9Sstevel@tonic-gate 	else
100*7c478bd9Sstevel@tonic-gate 		rfile++;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	if (strcmp(rfile, MSG_ORIG(MSG_FIL_RTLD)) == 0)
103*7c478bd9Sstevel@tonic-gate 		return;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL()) {
106*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_BASIC), ffile, tfile,
107*7c478bd9Sstevel@tonic-gate 		    _Dbg_sym_dem(sym));
108*7c478bd9Sstevel@tonic-gate 		return;
109*7c478bd9Sstevel@tonic-gate 	}
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	/*
112*7c478bd9Sstevel@tonic-gate 	 * Determine if this binding has any associated information, such as
113*7c478bd9Sstevel@tonic-gate 	 * and interposition, direct binding, copy-relocations, etc.
114*7c478bd9Sstevel@tonic-gate 	 */
115*7c478bd9Sstevel@tonic-gate 	binfo &= ~DBG_BINFO_FOUND;
116*7c478bd9Sstevel@tonic-gate 	binfo &= DBG_BINFO_MSK;
117*7c478bd9Sstevel@tonic-gate 	if (binfo) {
118*7c478bd9Sstevel@tonic-gate 		int	_binfo = 0;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 		(void) strcpy(binfostr, MSG_ORIG(MSG_BINFO_START));
121*7c478bd9Sstevel@tonic-gate 		if (binfo & DBG_BINFO_DIRECT) {
122*7c478bd9Sstevel@tonic-gate 			_binfo |= DBG_BINFO_DIRECT;
123*7c478bd9Sstevel@tonic-gate 			(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_DIRECT));
124*7c478bd9Sstevel@tonic-gate 		}
125*7c478bd9Sstevel@tonic-gate 		if (binfo & DBG_BINFO_INTERPOSE) {
126*7c478bd9Sstevel@tonic-gate 			if (_binfo)
127*7c478bd9Sstevel@tonic-gate 			    (void) strcat(binfostr, MSG_ORIG(MSG_BINFO_SEP));
128*7c478bd9Sstevel@tonic-gate 			_binfo |= DBG_BINFO_INTERPOSE;
129*7c478bd9Sstevel@tonic-gate 			(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_INTERPOSE));
130*7c478bd9Sstevel@tonic-gate 		}
131*7c478bd9Sstevel@tonic-gate 		if (binfo & DBG_BINFO_COPYREF) {
132*7c478bd9Sstevel@tonic-gate 			if (_binfo)
133*7c478bd9Sstevel@tonic-gate 			    (void) strcat(binfostr, MSG_ORIG(MSG_BINFO_SEP));
134*7c478bd9Sstevel@tonic-gate 			_binfo |= DBG_BINFO_COPYREF;
135*7c478bd9Sstevel@tonic-gate 			(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_COPYREF));
136*7c478bd9Sstevel@tonic-gate 		}
137*7c478bd9Sstevel@tonic-gate 		if (binfo & DBG_BINFO_FILTEE) {
138*7c478bd9Sstevel@tonic-gate 			if (_binfo)
139*7c478bd9Sstevel@tonic-gate 			    (void) strcat(binfostr, MSG_ORIG(MSG_BINFO_SEP));
140*7c478bd9Sstevel@tonic-gate 			_binfo |= DBG_BINFO_FILTEE;
141*7c478bd9Sstevel@tonic-gate 			(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_FILTEE));
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 		if (binfo & DBG_BINFO_PLTADDR) {
144*7c478bd9Sstevel@tonic-gate 			if (_binfo)
145*7c478bd9Sstevel@tonic-gate 			    (void) strcat(binfostr, MSG_ORIG(MSG_BINFO_SEP));
146*7c478bd9Sstevel@tonic-gate 			_binfo |= DBG_BINFO_PLTADDR;
147*7c478bd9Sstevel@tonic-gate 			(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_PLTADDR));
148*7c478bd9Sstevel@tonic-gate 		}
149*7c478bd9Sstevel@tonic-gate 		if (binfo & ~_binfo) {
150*7c478bd9Sstevel@tonic-gate 			size_t	len;
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 			if (_binfo)
153*7c478bd9Sstevel@tonic-gate 			    (void) strcat(binfostr, MSG_ORIG(MSG_BINFO_SEP));
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 			len = strlen(binfostr);
156*7c478bd9Sstevel@tonic-gate 			conv_invalid_str(&binfostr[len], (BINFOSZ - len),
157*7c478bd9Sstevel@tonic-gate 			    (Lword)(binfo & ~_binfo), 0);
158*7c478bd9Sstevel@tonic-gate 		}
159*7c478bd9Sstevel@tonic-gate 		(void) strcat(binfostr, MSG_ORIG(MSG_BINFO_END));
160*7c478bd9Sstevel@tonic-gate 	} else
161*7c478bd9Sstevel@tonic-gate 		binfostr[0] = '\0';
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	if (pltndx != (Xword)-1) {
165*7c478bd9Sstevel@tonic-gate 		const char	*pltstring;
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 		if (pbtype < PLT_T_NUM)
168*7c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[pbtype];
169*7c478bd9Sstevel@tonic-gate 		else
170*7c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[PLT_T_NONE];
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 		/*
173*7c478bd9Sstevel@tonic-gate 		 * Called from a plt offset.
174*7c478bd9Sstevel@tonic-gate 		 */
175*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_PLT), ffile, EC_ADDR(fabs),
176*7c478bd9Sstevel@tonic-gate 		    EC_ADDR(frel), EC_WORD(pltndx), pltstring, tfile,
177*7c478bd9Sstevel@tonic-gate 		    EC_ADDR(tabs), EC_ADDR(trel), _Dbg_sym_dem(sym), binfostr);
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	} else if ((fabs == 0) && (frel == 0)) {
180*7c478bd9Sstevel@tonic-gate 		/*
181*7c478bd9Sstevel@tonic-gate 		 * Called from a dlsym().  We're not performing a relocation,
182*7c478bd9Sstevel@tonic-gate 		 * but are handing the address of the symbol back to the user.
183*7c478bd9Sstevel@tonic-gate 		 */
184*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_DLSYM), ffile, tfile, EC_ADDR(tabs),
185*7c478bd9Sstevel@tonic-gate 		    EC_ADDR(trel), _Dbg_sym_dem(sym), binfostr);
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 	} else {
188*7c478bd9Sstevel@tonic-gate 		/*
189*7c478bd9Sstevel@tonic-gate 		 * Standard relocation.
190*7c478bd9Sstevel@tonic-gate 		 */
191*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_DEFAULT), ffile, EC_ADDR(fabs),
192*7c478bd9Sstevel@tonic-gate 		    EC_ADDR(frel), tfile, EC_ADDR(tabs), EC_ADDR(trel),
193*7c478bd9Sstevel@tonic-gate 		    _Dbg_sym_dem(sym), binfostr);
194*7c478bd9Sstevel@tonic-gate 	}
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate void
198*7c478bd9Sstevel@tonic-gate Dbg_bind_weak(const char *ffile, caddr_t fabs, caddr_t frel, const char *sym)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_BINDINGS))
201*7c478bd9Sstevel@tonic-gate 		return;
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
204*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_WEAK_1), ffile, _Dbg_sym_dem(sym));
205*7c478bd9Sstevel@tonic-gate 	else
206*7c478bd9Sstevel@tonic-gate 		dbg_print(MSG_INTL(MSG_BND_WEAK_2), ffile, EC_ADDR(fabs),
207*7c478bd9Sstevel@tonic-gate 		    EC_ADDR(frel), _Dbg_sym_dem(sym));
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate void
211*7c478bd9Sstevel@tonic-gate Dbg_bind_profile(uint_t ndx, uint_t count)
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTCLASS(DBG_BINDINGS))
214*7c478bd9Sstevel@tonic-gate 		return;
215*7c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
216*7c478bd9Sstevel@tonic-gate 		return;
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	dbg_print(MSG_INTL(MSG_BND_PROFILE), EC_WORD(ndx), EC_WORD(count));
219*7c478bd9Sstevel@tonic-gate }
220