17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb65rie * Common Development and Distribution License (the "License").
65aefb65rie * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
215aefb65rie
227c478bdstevel@tonic-gate/*
234f680ccAli Bahrami * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#include	<sys/types.h>
287c478bdstevel@tonic-gate#include	<string.h>
295aefb65rie#include	<debug.h>
305aefb65rie#include	<conv.h>
317c478bdstevel@tonic-gate#include	"_debug.h"
325aefb65rie#include	"msg.h"
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gatevoid
355aefb65rieDbg_bind_plt_summary(Lm_list *lml, Half mach, Word pltcnt21d, Word pltcnt24d,
365aefb65rie    Word pltcntu32, Word pltcntu44, Word pltcntfull, Word pltcntfar)
377c478bdstevel@tonic-gate{
387c478bdstevel@tonic-gate	Word plttotal = pltcnt21d + pltcnt24d + pltcntu32 +
39de777a6ab	    pltcntu44 + pltcntfull + pltcntfar;
407c478bdstevel@tonic-gate
415aefb65rie	if (DBG_NOTCLASS(DBG_C_BINDINGS))
427c478bdstevel@tonic-gate		return;
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate	switch (mach) {
457c478bdstevel@tonic-gate	case EM_SPARC:
465aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARC), EC_WORD(pltcnt21d),
477c478bdstevel@tonic-gate		    EC_WORD(pltcnt24d), EC_WORD(pltcntfull), EC_WORD(plttotal));
487c478bdstevel@tonic-gate		break;
497c478bdstevel@tonic-gate	case EM_SPARCV9:
505aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_SPARCV9),
515aefb65rie		    EC_WORD(pltcnt21d), EC_WORD(pltcnt24d), EC_WORD(pltcntu32),
525aefb65rie		    EC_WORD(pltcntu44), EC_WORD(pltcntfull), EC_WORD(pltcntfar),
535aefb65rie		    EC_WORD(plttotal));
547c478bdstevel@tonic-gate		break;
557c478bdstevel@tonic-gate	default:
565aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_PSUM_DEFAULT),
575aefb65rie		    EC_WORD(plttotal));
587c478bdstevel@tonic-gate		break;
597c478bdstevel@tonic-gate	};
607c478bdstevel@tonic-gate}
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gatestatic const char	*pltbindtypes[PLT_T_NUM] = {
637c478bdstevel@tonic-gate	MSG_ORIG(MSG_STR_EMPTY),	/* PLT_T_NONE */
647c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_21D),		/* PLT_T_21D */
657c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_24D),		/* PLT_T_24D */
667c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_U32),		/* PLT_T_U32 */
677c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_U44),		/* PLT_T_U44 */
687c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_FULL),		/* PLT_T_FULL */
697c478bdstevel@tonic-gate	MSG_ORIG(MSG_PLT_FAR)		/* PLT_T_FAR */
707c478bdstevel@tonic-gate};
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#define	BINFOSZ	MSG_BINFO_START_SIZE + \
735aefb65rie		MSG_BINFO_DIRECT_SIZE +		MSG_BINFO_SEP_SIZE + \
745aefb65rie		MSG_BINFO_INTERPOSE_SIZE +	MSG_BINFO_SEP_SIZE + \
755aefb65rie		MSG_BINFO_COPYREF_SIZE +	MSG_BINFO_SEP_SIZE + \
765aefb65rie		MSG_BINFO_FILTEE_SIZE +		MSG_BINFO_SEP_SIZE + \
777c478bdstevel@tonic-gate		MSG_BINFO_PLTADDR_SIZE + \
78de777a6ab		CONV_INV_BUFSIZE + MSG_BINFO_END_SIZE
795aefb65rie
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gatevoid
825aefb65rieDbg_bind_global(Rt_map *flmp, Addr fabs, Off foff, Xword pltndx,
835aefb65rie    Pltbindtype pbtype, Rt_map *tlmp, Addr tabs, Off toff,
847c478bdstevel@tonic-gate    const char *sym, uint_t binfo)
857c478bdstevel@tonic-gate{
864f680ccAli Bahrami	/*
874f680ccAli Bahrami	 * MSG_ORIG(MSG_BINFO_DIRECT)
884f680ccAli Bahrami	 * MSG_ORIG(MSG_BINFO_INTERPOSE)
894f680ccAli Bahrami	 * MSG_ORIG(MSG_BINFO_COPYREF)
904f680ccAli Bahrami	 * MSG_ORIG(MSG_BINFO_FILTEE)
914f680ccAli Bahrami	 * MSG_ORIG(MSG_BINFO_PLTADDR)
924f680ccAli Bahrami	 */
93ba4e3c8ab	static char binfostr[BINFOSZ];
945aefb65rie	static Val_desc vda[] = {
954f680ccAli Bahrami		{ DBG_BINFO_DIRECT,	MSG_BINFO_DIRECT },
964f680ccAli Bahrami		{ DBG_BINFO_INTERPOSE,	MSG_BINFO_INTERPOSE },
974f680ccAli Bahrami		{ DBG_BINFO_COPYREF,	MSG_BINFO_COPYREF },
984f680ccAli Bahrami		{ DBG_BINFO_FILTEE,	MSG_BINFO_FILTEE },
994f680ccAli Bahrami		{ DBG_BINFO_PLTADDR,	MSG_BINFO_PLTADDR },
1005aefb65rie		{ 0,			0 }
1015aefb65rie	};
102ba4e3c8ab	static CONV_EXPN_FIELD_ARG conv_arg = { binfostr, sizeof (binfostr),
1034f680ccAli Bahrami		NULL, 0, 0, MSG_ORIG(MSG_BINFO_START),
104ba4e3c8ab		MSG_ORIG(MSG_BINFO_SEP), MSG_ORIG(MSG_BINFO_END) };
105ba4e3c8ab
1065aefb65rie	const char	*ffile = NAME(flmp);
1075aefb65rie	const char	*tfile = NAME(tlmp);
1085aefb65rie	Lm_list		*lml = LIST(flmp);
1097c478bdstevel@tonic-gate
1105aefb65rie	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1117c478bdstevel@tonic-gate		return;
1127c478bdstevel@tonic-gate
1137c478bdstevel@tonic-gate	if (DBG_NOTDETAIL()) {
1145aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_BASIC), ffile, tfile,
1155aefb65rie		    Dbg_demangle_name(sym));
1167c478bdstevel@tonic-gate		return;
1177c478bdstevel@tonic-gate	}
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gate	/*
1207c478bdstevel@tonic-gate	 * Determine if this binding has any associated information, such as
1215aefb65rie	 * interposition, direct binding, copy-relocations, etc.
1227c478bdstevel@tonic-gate	 */
1237c478bdstevel@tonic-gate	binfo &= ~DBG_BINFO_FOUND;
1247c478bdstevel@tonic-gate	binfo &= DBG_BINFO_MSK;
1257c478bdstevel@tonic-gate	if (binfo) {
126ba4e3c8ab		conv_arg.oflags = conv_arg.rflags = binfo;
1274f680ccAli Bahrami		(void) conv_expn_field(&conv_arg, vda, 0);
128ba4e3c8ab	} else {
1297c478bdstevel@tonic-gate		binfostr[0] = '\0';
130ba4e3c8ab	}
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate	if (pltndx != (Xword)-1) {
1337c478bdstevel@tonic-gate		const char	*pltstring;
1347c478bdstevel@tonic-gate
1357c478bdstevel@tonic-gate		if (pbtype < PLT_T_NUM)
1367c478bdstevel@tonic-gate			pltstring = pltbindtypes[pbtype];
1377c478bdstevel@tonic-gate		else
1387c478bdstevel@tonic-gate			pltstring = pltbindtypes[PLT_T_NONE];
1397c478bdstevel@tonic-gate
1407c478bdstevel@tonic-gate		/*
1417c478bdstevel@tonic-gate		 * Called from a plt offset.
1427c478bdstevel@tonic-gate		 */
1435aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_PLT), ffile, EC_ADDR(fabs),
1445aefb65rie		    EC_OFF(foff), EC_XWORD(pltndx), pltstring, tfile,
1455aefb65rie		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1465aefb65rie		    binfostr);
1477c478bdstevel@tonic-gate
1485aefb65rie	} else if ((fabs == 0) && (foff == 0)) {
1497c478bdstevel@tonic-gate		/*
1507c478bdstevel@tonic-gate		 * Called from a dlsym().  We're not performing a relocation,
1517c478bdstevel@tonic-gate		 * but are handing the address of the symbol back to the user.
1527c478bdstevel@tonic-gate		 */
1535aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_DLSYM), ffile, tfile,
1545aefb65rie		    EC_ADDR(tabs), EC_OFF(toff), Dbg_demangle_name(sym),
1555aefb65rie		    binfostr);
1567c478bdstevel@tonic-gate	} else {
1577c478bdstevel@tonic-gate		/*
1587c478bdstevel@tonic-gate		 * Standard relocation.
1597c478bdstevel@tonic-gate		 */
1605aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_DEFAULT), ffile, EC_ADDR(fabs),
1615aefb65rie		    EC_OFF(foff), tfile, EC_ADDR(tabs), EC_OFF(toff),
1625aefb65rie		    Dbg_demangle_name(sym), binfostr);
1637c478bdstevel@tonic-gate	}
1647c478bdstevel@tonic-gate}
1657c478bdstevel@tonic-gate
1667c478bdstevel@tonic-gatevoid
1676075882rieDbg_bind_reject(Rt_map *flmp, Rt_map *tlmp, const char *sym, int why)
1686075882rie{
1696075882rie	static Msg reason[DBG_BNDREJ_NUM + 1] = {
17037ffaf8Rod Evans		MSG_BNDREJ_DIRECT,	/* MSG_INTL(MSG_BNDREJ_DIRECT) */
17137ffaf8Rod Evans		MSG_BNDREJ_GROUP,	/* MSG_INTL(MSG_BNDREJ_GROUP) */
1726075882rie		MSG_BNDREJ_SINGLE	/* MSG_INTL(MSG_BNDREJ_SINGLE) */
1736075882rie	};
1746075882rie
1756075882rie	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1766075882rie		return;
1776075882rie
1786075882rie	dbg_print(LIST(flmp), MSG_INTL(MSG_BND_REJECT), NAME(flmp), NAME(tlmp),
1796075882rie	    sym, MSG_INTL(reason[why]));
1806075882rie}
1816075882rie
1826075882rievoid
1835aefb65rieDbg_bind_weak(Rt_map *flmp, Addr fabs, Addr frel, const char *sym)
1847c478bdstevel@tonic-gate{
1855aefb65rie	Lm_list		*lml = LIST(flmp);
1865aefb65rie	const char	*ffile = NAME(flmp);
1875aefb65rie
1885aefb65rie	if (DBG_NOTCLASS(DBG_C_BINDINGS))
1897c478bdstevel@tonic-gate		return;
1907c478bdstevel@tonic-gate
1917c478bdstevel@tonic-gate	if (DBG_NOTDETAIL())
1925aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_1), ffile,
1935aefb65rie		    Dbg_demangle_name(sym));
1947c478bdstevel@tonic-gate	else
1955aefb65rie		dbg_print(lml, MSG_INTL(MSG_BND_WEAK_2), ffile, EC_ADDR(fabs),
1965aefb65rie		    EC_ADDR(frel), Dbg_demangle_name(sym));
1975aefb65rie}
1985aefb65rie
1995aefb65rie#if	defined(_ELF64)
2005aefb65rie
2015aefb65rievoid
2025aefb65rieDbg_bind_pltpad_to(Rt_map *lmp, Addr pltpad, const char *dfile,
2035aefb65rie    const char *sname)
2045aefb65rie{
2055aefb65rie	if (DBG_NOTCLASS(DBG_C_RELOC))
2065aefb65rie		return;
2075aefb65rie	if (DBG_NOTDETAIL())
2085aefb65rie		return;
2095aefb65rie
2105aefb65rie	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_TO), EC_ADDR(pltpad),
2115aefb65rie	    NAME(lmp), dfile, sname);
2127c478bdstevel@tonic-gate}
2137c478bdstevel@tonic-gate
2147c478bdstevel@tonic-gatevoid
2155aefb65rieDbg_bind_pltpad_from(Rt_map *lmp, Addr pltpad, const char *sname)
2167c478bdstevel@tonic-gate{
2175aefb65rie	if (DBG_NOTCLASS(DBG_C_RELOC))
2187c478bdstevel@tonic-gate		return;
2197c478bdstevel@tonic-gate	if (DBG_NOTDETAIL())
2207c478bdstevel@tonic-gate		return;
2217c478bdstevel@tonic-gate
2225aefb65rie	dbg_print(LIST(lmp), MSG_INTL(MSG_BND_PLTPAD_FROM), EC_ADDR(pltpad),
2235aefb65rie	    NAME(lmp), sname);
2247c478bdstevel@tonic-gate}
2255aefb65rie
2265aefb65rie#endif
227