xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/bindings.c (revision ba4e3c84e6b9390bbf7df80b5f1d11dec34cc525)
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 /*
235aefb655Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include	<sys/types.h>
307c478bd9Sstevel@tonic-gate #include	<string.h>
315aefb655Srie #include	<debug.h>
325aefb655Srie #include	<conv.h>
337c478bd9Sstevel@tonic-gate #include	"_debug.h"
345aefb655Srie #include	"msg.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate void
375aefb655Srie Dbg_bind_plt_summary(Lm_list *lml, Half mach, Word pltcnt21d, Word pltcnt24d,
385aefb655Srie     Word pltcntu32, Word pltcntu44, Word pltcntfull, Word pltcntfar)
397c478bd9Sstevel@tonic-gate {
407c478bd9Sstevel@tonic-gate 	Word plttotal = pltcnt21d + pltcnt24d + pltcntu32 +
417c478bd9Sstevel@tonic-gate 		pltcntu44 + pltcntfull + pltcntfar;
427c478bd9Sstevel@tonic-gate 
435aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
447c478bd9Sstevel@tonic-gate 		return;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 	switch (mach) {
477c478bd9Sstevel@tonic-gate 	case EM_SPARC:
485aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARC), EC_WORD(pltcnt21d),
497c478bd9Sstevel@tonic-gate 		    EC_WORD(pltcnt24d), EC_WORD(pltcntfull), EC_WORD(plttotal));
507c478bd9Sstevel@tonic-gate 		break;
517c478bd9Sstevel@tonic-gate 	case EM_SPARCV9:
525aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARCV9),
535aefb655Srie 		    EC_WORD(pltcnt21d), EC_WORD(pltcnt24d), EC_WORD(pltcntu32),
545aefb655Srie 		    EC_WORD(pltcntu44), EC_WORD(pltcntfull), EC_WORD(pltcntfar),
555aefb655Srie 		    EC_WORD(plttotal));
567c478bd9Sstevel@tonic-gate 		break;
577c478bd9Sstevel@tonic-gate 	default:
585aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_DEFAULT),
595aefb655Srie 		    EC_WORD(plttotal));
607c478bd9Sstevel@tonic-gate 		break;
617c478bd9Sstevel@tonic-gate 	};
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate static const char	*pltbindtypes[PLT_T_NUM] = {
657c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_STR_EMPTY),	/* PLT_T_NONE */
667c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_21D),		/* PLT_T_21D */
677c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_24D),		/* PLT_T_24D */
687c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U32),		/* PLT_T_U32 */
697c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_U44),		/* PLT_T_U44 */
707c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FULL),		/* PLT_T_FULL */
717c478bd9Sstevel@tonic-gate 	MSG_ORIG(MSG_PLT_FAR)		/* PLT_T_FAR */
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	BINFOSZ	MSG_BINFO_START_SIZE + \
755aefb655Srie 		MSG_BINFO_DIRECT_SIZE +		MSG_BINFO_SEP_SIZE + \
765aefb655Srie 		MSG_BINFO_INTERPOSE_SIZE +	MSG_BINFO_SEP_SIZE + \
775aefb655Srie 		MSG_BINFO_COPYREF_SIZE +	MSG_BINFO_SEP_SIZE + \
785aefb655Srie 		MSG_BINFO_FILTEE_SIZE +		MSG_BINFO_SEP_SIZE + \
797c478bd9Sstevel@tonic-gate 		MSG_BINFO_PLTADDR_SIZE + \
805aefb655Srie 		CONV_INV_STRSIZE + MSG_BINFO_END_SIZE
815aefb655Srie 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate void
845aefb655Srie Dbg_bind_global(Rt_map *flmp, Addr fabs, Off foff, Xword pltndx,
855aefb655Srie     Pltbindtype pbtype, Rt_map *tlmp, Addr tabs, Off toff,
867c478bd9Sstevel@tonic-gate     const char *sym, uint_t binfo)
877c478bd9Sstevel@tonic-gate {
88*ba4e3c84Sab 	static char binfostr[BINFOSZ];
895aefb655Srie 	static Val_desc vda[] = {
905aefb655Srie 		{ DBG_BINFO_DIRECT,	MSG_ORIG(MSG_BINFO_DIRECT) },
915aefb655Srie 		{ DBG_BINFO_INTERPOSE,	MSG_ORIG(MSG_BINFO_INTERPOSE) },
925aefb655Srie 		{ DBG_BINFO_COPYREF,	MSG_ORIG(MSG_BINFO_COPYREF) },
935aefb655Srie 		{ DBG_BINFO_FILTEE,	MSG_ORIG(MSG_BINFO_FILTEE) },
945aefb655Srie 		{ DBG_BINFO_PLTADDR,	MSG_ORIG(MSG_BINFO_PLTADDR) },
955aefb655Srie 		{ 0,			0 }
965aefb655Srie 	};
97*ba4e3c84Sab 	static CONV_EXPN_FIELD_ARG conv_arg = { binfostr, sizeof (binfostr),
98*ba4e3c84Sab 		vda, NULL, 0, 0, MSG_ORIG(MSG_BINFO_START),
99*ba4e3c84Sab 		MSG_ORIG(MSG_BINFO_SEP), MSG_ORIG(MSG_BINFO_END) };
100*ba4e3c84Sab 
1015aefb655Srie 	const char	*ffile = NAME(flmp);
1025aefb655Srie 	const char	*tfile = NAME(tlmp);
1035aefb655Srie 	Lm_list		*lml = LIST(flmp);
1047c478bd9Sstevel@tonic-gate 
1055aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1067c478bd9Sstevel@tonic-gate 		return;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL()) {
1095aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_BASIC), ffile, tfile,
1105aefb655Srie 		    Dbg_demangle_name(sym));
1117c478bd9Sstevel@tonic-gate 		return;
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	/*
1157c478bd9Sstevel@tonic-gate 	 * Determine if this binding has any associated information, such as
1165aefb655Srie 	 * interposition, direct binding, copy-relocations, etc.
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	binfo &= ~DBG_BINFO_FOUND;
1197c478bd9Sstevel@tonic-gate 	binfo &= DBG_BINFO_MSK;
1207c478bd9Sstevel@tonic-gate 	if (binfo) {
121*ba4e3c84Sab 		conv_arg.oflags = conv_arg.rflags = binfo;
122*ba4e3c84Sab 		(void) conv_expn_field(&conv_arg);
123*ba4e3c84Sab 	} else {
1247c478bd9Sstevel@tonic-gate 		binfostr[0] = '\0';
125*ba4e3c84Sab 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	if (pltndx != (Xword)-1) {
1287c478bd9Sstevel@tonic-gate 		const char	*pltstring;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 		if (pbtype < PLT_T_NUM)
1317c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[pbtype];
1327c478bd9Sstevel@tonic-gate 		else
1337c478bd9Sstevel@tonic-gate 			pltstring = pltbindtypes[PLT_T_NONE];
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 		/*
1367c478bd9Sstevel@tonic-gate 		 * Called from a plt offset.
1377c478bd9Sstevel@tonic-gate 		 */
1385aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_PLT), ffile, EC_ADDR(fabs),
1395aefb655Srie 		    EC_OFF(foff), EC_XWORD(pltndx), pltstring, tfile,
1405aefb655Srie 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1415aefb655Srie 		    binfostr);
1427c478bd9Sstevel@tonic-gate 
1435aefb655Srie 	} else if ((fabs == 0) && (foff == 0)) {
1447c478bd9Sstevel@tonic-gate 		/*
1457c478bd9Sstevel@tonic-gate 		 * Called from a dlsym().  We're not performing a relocation,
1467c478bd9Sstevel@tonic-gate 		 * but are handing the address of the symbol back to the user.
1477c478bd9Sstevel@tonic-gate 		 */
1485aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_DLSYM), ffile, tfile,
1495aefb655Srie 		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1505aefb655Srie 		    binfostr);
1517c478bd9Sstevel@tonic-gate 	} else {
1527c478bd9Sstevel@tonic-gate 		/*
1537c478bd9Sstevel@tonic-gate 		 * Standard relocation.
1547c478bd9Sstevel@tonic-gate 		 */
1555aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_DEFAULT), ffile, EC_ADDR(fabs),
1565aefb655Srie 		    EC_OFF(foff), tfile, EC_ADDR(tabs), EC_OFF(toff),
1575aefb655Srie 		    Dbg_demangle_name(sym), binfostr);
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate void
1625aefb655Srie Dbg_bind_weak(Rt_map *flmp, Addr fabs, Addr frel, const char *sym)
1637c478bd9Sstevel@tonic-gate {
1645aefb655Srie 	Lm_list		*lml = LIST(flmp);
1655aefb655Srie 	const char	*ffile = NAME(flmp);
1665aefb655Srie 
1675aefb655Srie 	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1687c478bd9Sstevel@tonic-gate 		return;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1715aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_1), ffile,
1725aefb655Srie 		    Dbg_demangle_name(sym));
1737c478bd9Sstevel@tonic-gate 	else
1745aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_2), ffile, EC_ADDR(fabs),
1755aefb655Srie 		    EC_ADDR(frel), Dbg_demangle_name(sym));
1765aefb655Srie }
1775aefb655Srie 
1785aefb655Srie #if	defined(_ELF64)
1795aefb655Srie 
1805aefb655Srie void
1815aefb655Srie Dbg_bind_pltpad_to(Rt_map *lmp, Addr pltpad, const char *dfile,
1825aefb655Srie     const char *sname)
1835aefb655Srie {
1845aefb655Srie 	if (DBG_NOTCLASS(DBG_C_RELOC))
1855aefb655Srie 		return;
1865aefb655Srie 	if (DBG_NOTDETAIL())
1875aefb655Srie 		return;
1885aefb655Srie 
1895aefb655Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_TO), EC_ADDR(pltpad),
1905aefb655Srie 	    NAME(lmp), dfile, sname);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate void
1945aefb655Srie Dbg_bind_pltpad_from(Rt_map *lmp, Addr pltpad, const char *sname)
1957c478bd9Sstevel@tonic-gate {
1965aefb655Srie 	if (DBG_NOTCLASS(DBG_C_RELOC))
1977c478bd9Sstevel@tonic-gate 		return;
1987c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1997c478bd9Sstevel@tonic-gate 		return;
2007c478bd9Sstevel@tonic-gate 
2015aefb655Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_FROM), EC_ADDR(pltpad),
2025aefb655Srie 	    NAME(lmp), sname);
2037c478bd9Sstevel@tonic-gate }
2045aefb655Srie 
2055aefb655Srie #endif
206