xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/bindings.c (revision 37ffaf8335982d89ab569e9a1020419e32003404)
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  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*37ffaf83SRod Evans  * Copyright 2008 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	<sys/types.h>
287c478bd9Sstevel@tonic-gate #include	<string.h>
295aefb655Srie #include	<debug.h>
305aefb655Srie #include	<conv.h>
317c478bd9Sstevel@tonic-gate #include	"_debug.h"
325aefb655Srie #include	"msg.h"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate void
355aefb655Srie Dbg_bind_plt_summary(Lm_list *lml, Half mach, Word pltcnt21d, Word pltcnt24d,
365aefb655Srie     Word pltcntu32, Word pltcntu44, Word pltcntfull, Word pltcntfar)
377c478bd9Sstevel@tonic-gate {
387c478bd9Sstevel@tonic-gate 	Word plttotal = pltcnt21d + pltcnt24d + pltcntu32 +
39de777a60Sab 	    pltcntu44 + pltcntfull + pltcntfar;
407c478bd9Sstevel@tonic-gate 
415aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
427c478bd9Sstevel@tonic-gate 		return;
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 	switch (mach) {
457c478bd9Sstevel@tonic-gate 	case EM_SPARC:
465aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARC), EC_WORD(pltcnt21d),
477c478bd9Sstevel@tonic-gate 		    EC_WORD(pltcnt24d), EC_WORD(pltcntfull), EC_WORD(plttotal));
487c478bd9Sstevel@tonic-gate 		break;
497c478bd9Sstevel@tonic-gate 	case EM_SPARCV9:
505aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARCV9),
515aefb655Srie 		    EC_WORD(pltcnt21d), EC_WORD(pltcnt24d), EC_WORD(pltcntu32),
525aefb655Srie 		    EC_WORD(pltcntu44), EC_WORD(pltcntfull), EC_WORD(pltcntfar),
535aefb655Srie 		    EC_WORD(plttotal));
547c478bd9Sstevel@tonic-gate 		break;
557c478bd9Sstevel@tonic-gate 	default:
565aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_DEFAULT),
575aefb655Srie 		    EC_WORD(plttotal));
587c478bd9Sstevel@tonic-gate 		break;
597c478bd9Sstevel@tonic-gate 	};
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate static const char	*pltbindtypes[PLT_T_NUM] = {
637c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_STR_EMPTY),	/* PLT_T_NONE */
647c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_21D),		/* PLT_T_21D */
657c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_24D),		/* PLT_T_24D */
667c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U32),		/* PLT_T_U32 */
677c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U44),		/* PLT_T_U44 */
687c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FULL),		/* PLT_T_FULL */
697c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FAR)		/* PLT_T_FAR */
707c478bd9Sstevel@tonic-gate };
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	BINFOSZ	MSG_BINFO_START_SIZE + \
735aefb655Srie 		MSG_BINFO_DIRECT_SIZE +		MSG_BINFO_SEP_SIZE + \
745aefb655Srie 		MSG_BINFO_INTERPOSE_SIZE +	MSG_BINFO_SEP_SIZE + \
755aefb655Srie 		MSG_BINFO_COPYREF_SIZE +	MSG_BINFO_SEP_SIZE + \
765aefb655Srie 		MSG_BINFO_FILTEE_SIZE +		MSG_BINFO_SEP_SIZE + \
777c478bd9Sstevel@tonic-gate 		MSG_BINFO_PLTADDR_SIZE + \
78de777a60Sab 		CONV_INV_BUFSIZE + MSG_BINFO_END_SIZE
795aefb655Srie 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate void
825aefb655Srie Dbg_bind_global(Rt_map *flmp, Addr fabs, Off foff, Xword pltndx,
835aefb655Srie     Pltbindtype pbtype, Rt_map *tlmp, Addr tabs, Off toff,
847c478bd9Sstevel@tonic-gate     const char *sym, uint_t binfo)
857c478bd9Sstevel@tonic-gate {
86ba4e3c84Sab 	static char binfostr[BINFOSZ];
875aefb655Srie 	static Val_desc vda[] = {
885aefb655Srie 		{ DBG_BINFO_DIRECT,	MSG_ORIG(MSG_BINFO_DIRECT) },
895aefb655Srie 		{ DBG_BINFO_INTERPOSE,	MSG_ORIG(MSG_BINFO_INTERPOSE) },
905aefb655Srie 		{ DBG_BINFO_COPYREF,	MSG_ORIG(MSG_BINFO_COPYREF) },
915aefb655Srie 		{ DBG_BINFO_FILTEE,	MSG_ORIG(MSG_BINFO_FILTEE) },
925aefb655Srie 		{ DBG_BINFO_PLTADDR,	MSG_ORIG(MSG_BINFO_PLTADDR) },
935aefb655Srie 		{ 0,			0 }
945aefb655Srie 	};
95ba4e3c84Sab 	static CONV_EXPN_FIELD_ARG conv_arg = { binfostr, sizeof (binfostr),
96ba4e3c84Sab 		vda, NULL, 0, 0, MSG_ORIG(MSG_BINFO_START),
97ba4e3c84Sab 		MSG_ORIG(MSG_BINFO_SEP), MSG_ORIG(MSG_BINFO_END) };
98ba4e3c84Sab 
995aefb655Srie 	const char	*ffile = NAME(flmp);
1005aefb655Srie 	const char	*tfile = NAME(tlmp);
1015aefb655Srie 	Lm_list		*lml = LIST(flmp);
1027c478bd9Sstevel@tonic-gate 
1035aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1047c478bd9Sstevel@tonic-gate 		return;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL()) {
1075aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_BASIC), ffile, tfile,
1085aefb655Srie 		    Dbg_demangle_name(sym));
1097c478bd9Sstevel@tonic-gate 		return;
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	/*
1137c478bd9Sstevel@tonic-gate 	 * Determine if this binding has any associated information, such as
1145aefb655Srie 	 * interposition, direct binding, copy-relocations, etc.
1157c478bd9Sstevel@tonic-gate 	 */
1167c478bd9Sstevel@tonic-gate 	binfo &= ~DBG_BINFO_FOUND;
1177c478bd9Sstevel@tonic-gate 	binfo &= DBG_BINFO_MSK;
1187c478bd9Sstevel@tonic-gate 	if (binfo) {
119ba4e3c84Sab 		conv_arg.oflags = conv_arg.rflags = binfo;
120d29b2c44Sab 		(void) conv_expn_field(&conv_arg, 0);
121ba4e3c84Sab 	} else {
1227c478bd9Sstevel@tonic-gate 		binfostr[0] = '\0';
123ba4e3c84Sab 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	if (pltndx != (Xword)-1) {
1267c478bd9Sstevel@tonic-gate 		const char	*pltstring;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 		if (pbtype < PLT_T_NUM)
1297c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[pbtype];
1307c478bd9Sstevel@tonic-gate 		else
1317c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[PLT_T_NONE];
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 		/*
1347c478bd9Sstevel@tonic-gate 		 * Called from a plt offset.
1357c478bd9Sstevel@tonic-gate 		 */
1365aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PLT), ffile, EC_ADDR(fabs),
1375aefb655Srie 		    EC_OFF(foff), EC_XWORD(pltndx), pltstring, tfile,
1385aefb655Srie 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1395aefb655Srie 		    binfostr);
1407c478bd9Sstevel@tonic-gate 
1415aefb655Srie 	} else if ((fabs == 0) && (foff == 0)) {
1427c478bd9Sstevel@tonic-gate 		/*
1437c478bd9Sstevel@tonic-gate 		 * Called from a dlsym().  We're not performing a relocation,
1447c478bd9Sstevel@tonic-gate 		 * but are handing the address of the symbol back to the user.
1457c478bd9Sstevel@tonic-gate 		 */
1465aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_DLSYM), ffile, tfile,
1475aefb655Srie 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1485aefb655Srie 		    binfostr);
1497c478bd9Sstevel@tonic-gate 	} else {
1507c478bd9Sstevel@tonic-gate 		/*
1517c478bd9Sstevel@tonic-gate 		 * Standard relocation.
1527c478bd9Sstevel@tonic-gate 		 */
1535aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_DEFAULT), ffile, EC_ADDR(fabs),
1545aefb655Srie 		    EC_OFF(foff), tfile, EC_ADDR(tabs), EC_OFF(toff),
1555aefb655Srie 		    Dbg_demangle_name(sym), binfostr);
1567c478bd9Sstevel@tonic-gate 	}
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate 
15960758829Srie void
16060758829Srie Dbg_bind_reject(Rt_map *flmp, Rt_map *tlmp, const char *sym, int why)
16160758829Srie {
16260758829Srie 	static Msg reason[DBG_BNDREJ_NUM + 1] = {
163*37ffaf83SRod Evans 		MSG_BNDREJ_DIRECT,	/* MSG_INTL(MSG_BNDREJ_DIRECT) */
164*37ffaf83SRod Evans 		MSG_BNDREJ_GROUP,	/* MSG_INTL(MSG_BNDREJ_GROUP) */
16560758829Srie 		MSG_BNDREJ_SINGLE	/* MSG_INTL(MSG_BNDREJ_SINGLE) */
16660758829Srie 	};
16760758829Srie 
16860758829Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
16960758829Srie 		return;
17060758829Srie 
17160758829Srie 	dbg_print(LIST(flmp), MSG_INTL(MSG_BND_REJECT), NAME(flmp), NAME(tlmp),
17260758829Srie 	    sym, MSG_INTL(reason[why]));
17360758829Srie }
17460758829Srie 
1757c478bd9Sstevel@tonic-gate void
1765aefb655Srie Dbg_bind_weak(Rt_map *flmp, Addr fabs, Addr frel, const char *sym)
1777c478bd9Sstevel@tonic-gate {
1785aefb655Srie 	Lm_list		*lml = LIST(flmp);
1795aefb655Srie 	const char	*ffile = NAME(flmp);
1805aefb655Srie 
1815aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1827c478bd9Sstevel@tonic-gate 		return;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1855aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_1), ffile,
1865aefb655Srie 		    Dbg_demangle_name(sym));
1877c478bd9Sstevel@tonic-gate 	else
1885aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_2), ffile, EC_ADDR(fabs),
1895aefb655Srie 		    EC_ADDR(frel), Dbg_demangle_name(sym));
1905aefb655Srie }
1915aefb655Srie 
1925aefb655Srie #if	defined(_ELF64)
1935aefb655Srie 
1945aefb655Srie void
1955aefb655Srie Dbg_bind_pltpad_to(Rt_map *lmp, Addr pltpad, const char *dfile,
1965aefb655Srie     const char *sname)
1975aefb655Srie {
1985aefb655Srie 	if (DBG_NOTCLASS(DBG_C_RELOC))
1995aefb655Srie 		return;
2005aefb655Srie 	if (DBG_NOTDETAIL())
2015aefb655Srie 		return;
2025aefb655Srie 
2035aefb655Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_TO), EC_ADDR(pltpad),
2045aefb655Srie 	    NAME(lmp), dfile, sname);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate void
2085aefb655Srie Dbg_bind_pltpad_from(Rt_map *lmp, Addr pltpad, const char *sname)
2097c478bd9Sstevel@tonic-gate {
2105aefb655Srie 	if (DBG_NOTCLASS(DBG_C_RELOC))
2117c478bd9Sstevel@tonic-gate 		return;
2127c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2137c478bd9Sstevel@tonic-gate 		return;
2147c478bd9Sstevel@tonic-gate 
2155aefb655Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_FROM), EC_ADDR(pltpad),
2165aefb655Srie 	    NAME(lmp), sname);
2177c478bd9Sstevel@tonic-gate }
2185aefb655Srie 
2195aefb655Srie #endif
220