xref: /onnv-gate/usr/src/cmd/sgs/rtld/sparc/sparc_a.out.c (revision 12449:a87750d92895)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
231618Srie  *	Copyright (c) 1988 AT&T
241618Srie  *	All Rights Reserved
25*12449SRod.Evans@Sun.COM  *
26*12449SRod.Evans@Sun.COM  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * SPARC machine dependent and a.out format file class dependent functions.
310Sstevel@tonic-gate  * Contains routines for performing function binding and symbol relocations.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include	<stdio.h>
350Sstevel@tonic-gate #include	<sys/types.h>
360Sstevel@tonic-gate #include	<sys/mman.h>
370Sstevel@tonic-gate #include	<synch.h>
380Sstevel@tonic-gate #include	<dlfcn.h>
391618Srie #include	<debug.h>
400Sstevel@tonic-gate #include	"_a.out.h"
410Sstevel@tonic-gate #include	"_rtld.h"
420Sstevel@tonic-gate #include	"_audit.h"
43*12449SRod.Evans@Sun.COM #include	"_inline_gen.h"
440Sstevel@tonic-gate #include	"msg.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate extern void	iflush_range(caddr_t, size_t);
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * Function binding routine - invoked on the first call to a function through
500Sstevel@tonic-gate  * the procedure linkage table;
510Sstevel@tonic-gate  * passes first through an assembly language interface.
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * Takes the address of the PLT entry where the call originated,
540Sstevel@tonic-gate  * the offset into the relocation table of the associated
550Sstevel@tonic-gate  * relocation entry and the address of the link map (rt_private_map struct)
560Sstevel@tonic-gate  * for the entry.
570Sstevel@tonic-gate  *
580Sstevel@tonic-gate  * Returns the address of the function referenced after re-writing the PLT
590Sstevel@tonic-gate  * entry to invoke the function directly.
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  * On error, causes process to terminate with a signal.
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate ulong_t
aout_bndr(caddr_t pc)640Sstevel@tonic-gate aout_bndr(caddr_t pc)
650Sstevel@tonic-gate {
661618Srie 	Rt_map		*lmp, *nlmp, *llmp;
670Sstevel@tonic-gate 	struct relocation_info *rp;
680Sstevel@tonic-gate 	struct nlist	*sp;
691618Srie 	Sym		*sym;
700Sstevel@tonic-gate 	char		*name;
710Sstevel@tonic-gate 	int 		rndx, entry;
720Sstevel@tonic-gate 	ulong_t		symval;
730Sstevel@tonic-gate 	Slookup		sl;
7411827SRod.Evans@Sun.COM 	Sresult		sr;
750Sstevel@tonic-gate 	uint_t		binfo;
761618Srie 	Lm_list		*lml;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	/*
790Sstevel@tonic-gate 	 * For compatibility with libthread (TI_VERSION 1) we track the entry
800Sstevel@tonic-gate 	 * value.  A zero value indicates we have recursed into ld.so.1 to
810Sstevel@tonic-gate 	 * further process a locking request (see comments in completion()).
820Sstevel@tonic-gate 	 * Under this recursion we disable tsort and cleanup activities.
830Sstevel@tonic-gate 	 */
846515Sraf 	entry = enter(0);
850Sstevel@tonic-gate 
868394SAli.Bahrami@Sun.COM 	for (lmp = lml_main.lm_head; lmp; lmp = NEXT_RT_MAP(lmp)) {
878598SRod.Evans@Sun.COM 		if (THIS_IS_AOUT(lmp)) {
880Sstevel@tonic-gate 			if (pc > (caddr_t)(LM2LP(lmp)->lp_plt) &&
890Sstevel@tonic-gate 			    pc < (caddr_t)((int)LM2LP(lmp)->lp_plt +
900Sstevel@tonic-gate 			    AOUTDYN(lmp)->v2->ld_plt_sz))  {
910Sstevel@tonic-gate 				break;
920Sstevel@tonic-gate 			}
930Sstevel@tonic-gate 		}
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate #define	LAST22BITS	0x3fffff
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	/* LINTED */
990Sstevel@tonic-gate 	rndx = *(int *)(pc + (sizeof (ulong_t *) * 2)) & LAST22BITS;
1000Sstevel@tonic-gate 	rp = &LM2LP(lmp)->lp_rp[rndx];
1010Sstevel@tonic-gate 	sp = &LM2LP(lmp)->lp_symtab[rp->r_symbolnum];
1020Sstevel@tonic-gate 	name = &LM2LP(lmp)->lp_symstr[sp->n_un.n_strx];
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	/*
1050Sstevel@tonic-gate 	 * Determine the last link-map of this list, this'll be the starting
1060Sstevel@tonic-gate 	 * point for any tsort() processing.
1070Sstevel@tonic-gate 	 */
1081618Srie 	lml = LIST(lmp);
1091618Srie 	llmp = lml->lm_tail;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/*
1125950Srie 	 * Find definition for symbol.  Initialize the symbol lookup data
1135950Srie 	 * structure.
1140Sstevel@tonic-gate 	 */
1155950Srie 	SLOOKUP_INIT(sl, name, lmp, lml->lm_head, ld_entry_cnt, 0, 0, 0, 0,
1165950Srie 	    LKUP_DEFT);
11711827SRod.Evans@Sun.COM 	SRESULT_INIT(sr, name);
1180Sstevel@tonic-gate 
11911827SRod.Evans@Sun.COM 	if (aout_lookup_sym(&sl, &sr, &binfo, NULL) == 0) {
1201618Srie 		eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_NOSYM), NAME(lmp),
1210Sstevel@tonic-gate 		    demangle(name));
1221618Srie 		rtldexit(lml, 1);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 
12511827SRod.Evans@Sun.COM 	name = (char *)sr.sr_name;
12611827SRod.Evans@Sun.COM 	nlmp = sr.sr_dmap;
12711827SRod.Evans@Sun.COM 	sym = sr.sr_sym;
12811827SRod.Evans@Sun.COM 
1290Sstevel@tonic-gate 	symval = sym->st_value;
13011827SRod.Evans@Sun.COM 
1310Sstevel@tonic-gate 	if (!(FLAGS(nlmp) & FLG_RT_FIXED) &&
1320Sstevel@tonic-gate 	    (sym->st_shndx != SHN_ABS))
1330Sstevel@tonic-gate 		symval += (int)(ADDR(nlmp));
1340Sstevel@tonic-gate 	if ((lmp != nlmp) && ((FLAGS1(nlmp) & FL1_RT_NOINIFIN) == 0)) {
1350Sstevel@tonic-gate 		/*
1360Sstevel@tonic-gate 		 * Record that this new link map is now bound to the caller.
1370Sstevel@tonic-gate 		 */
1380Sstevel@tonic-gate 		if (bind_one(lmp, nlmp, BND_REFER) == 0)
1391618Srie 			rtldexit(lml, 1);
1400Sstevel@tonic-gate 	}
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * Print binding information and rebuild PLT entry.
1440Sstevel@tonic-gate 	 */
1451618Srie 	DBG_CALL(Dbg_bind_global(lmp, (Addr)(ADDR(lmp) + rp->r_address),
1461618Srie 	    (Off)rp->r_address, (Xword)(-1), PLT_T_NONE, nlmp,
1471618Srie 	    (Addr)symval, sym->st_value, name, binfo));
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	if (!(rtld_flags & RT_FL_NOBIND))
1500Sstevel@tonic-gate 		aout_plt_write((caddr_t)(ADDR(lmp) + rp->r_address), symval);
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	/*
1530Sstevel@tonic-gate 	 * Complete any processing for newly loaded objects.  Note we don't
1540Sstevel@tonic-gate 	 * know exactly where any new objects are loaded (we know the object
1550Sstevel@tonic-gate 	 * that supplied the symbol, but others may have been loaded lazily as
1560Sstevel@tonic-gate 	 * we searched for the symbol), so sorting starts from the last
1570Sstevel@tonic-gate 	 * link-map know on entry to this routine.
1580Sstevel@tonic-gate 	 */
1590Sstevel@tonic-gate 	if (entry)
1604679Srie 		load_completion(llmp);
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	/*
1630Sstevel@tonic-gate 	 * Make sure the object to which we've bound has had it's .init fired.
1640Sstevel@tonic-gate 	 * Cleanup before return to user code.
1650Sstevel@tonic-gate 	 */
1660Sstevel@tonic-gate 	if (entry) {
1670Sstevel@tonic-gate 		is_dep_init(nlmp, lmp);
1686515Sraf 		leave(lml, 0);
1690Sstevel@tonic-gate 	}
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	return (symval);
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #define	IS_PC_RELATIVE(X) (pc_rel_type[(X)] == 1)
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate static const uchar_t pc_rel_type[] = {
1780Sstevel@tonic-gate 	0,				/* RELOC_8 */
1790Sstevel@tonic-gate 	0,				/* RELOC_16 */
1800Sstevel@tonic-gate 	0,				/* RELOC_32 */
1810Sstevel@tonic-gate 	1,				/* RELOC_DISP8 */
1820Sstevel@tonic-gate 	1,				/* RELOC_DISP16 */
1830Sstevel@tonic-gate 	1,				/* RELOC_DISP32 */
1840Sstevel@tonic-gate 	1,				/* RELOC_WDISP30 */
1850Sstevel@tonic-gate 	1,				/* RELOC_WDISP22 */
1860Sstevel@tonic-gate 	0,				/* RELOC_HI22 */
1870Sstevel@tonic-gate 	0,				/* RELOC_22 */
1880Sstevel@tonic-gate 	0,				/* RELOC_13 */
1890Sstevel@tonic-gate 	0,				/* RELOC_LO10 */
1900Sstevel@tonic-gate 	0,				/* RELOC_SFA_BASE */
1910Sstevel@tonic-gate 	0,				/* RELOC_SFA_OFF13 */
1920Sstevel@tonic-gate 	0,				/* RELOC_BASE10 */
1930Sstevel@tonic-gate 	0,				/* RELOC_BASE13 */
1940Sstevel@tonic-gate 	0,				/* RELOC_BASE22 */
1950Sstevel@tonic-gate 	0,				/* RELOC_PC10 */
1960Sstevel@tonic-gate 	0,				/* RELOC_PC22 */
1970Sstevel@tonic-gate 	0,				/* RELOC_JMP_TBL */
1980Sstevel@tonic-gate 	0,				/* RELOC_SEGOFF16 */
1990Sstevel@tonic-gate 	0,				/* RELOC_GLOB_DAT */
2000Sstevel@tonic-gate 	0,				/* RELOC_JMP_SLOT */
2010Sstevel@tonic-gate 	0				/* RELOC_RELATIVE */
2020Sstevel@tonic-gate };
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate int
aout_reloc(Rt_map * lmp,uint_t plt,int * in_nfavl,APlist ** textrel)2058598SRod.Evans@Sun.COM aout_reloc(Rt_map *lmp, uint_t plt, int *in_nfavl, APlist **textrel)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate 	int		k;		/* loop temporary */
2080Sstevel@tonic-gate 	int		nr;		/* number of relocations */
2090Sstevel@tonic-gate 	char		*name;		/* symbol being searched for */
2100Sstevel@tonic-gate 	long		value;		/* relocation temporary */
2110Sstevel@tonic-gate 	long		*ra;		/* cached relocation address */
2120Sstevel@tonic-gate 	struct relocation_info *rp;	/* current relocation */
2130Sstevel@tonic-gate 	struct nlist	*sp;		/* symbol table of "symbol" */
2140Sstevel@tonic-gate 	Rt_map *	_lmp;		/* lm which holds symbol definition */
2150Sstevel@tonic-gate 	Sym *		sym;		/* symbol definition */
2168598SRod.Evans@Sun.COM 	int		ret = 1;
2175892Sab196087 	APlist		*bound = NULL;
2181618Srie 	Lm_list		*lml = LIST(lmp);
2190Sstevel@tonic-gate 
2201618Srie 	DBG_CALL(Dbg_reloc_run(lmp, SHT_RELA, plt, DBG_REL_START));
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	/*
2230Sstevel@tonic-gate 	 * If we've been called upon to promote an RTLD_LAZY object to an
2240Sstevel@tonic-gate 	 * RTLD_NOW don't bother to do anything - a.out's are bound as if
2250Sstevel@tonic-gate 	 * RTLD_NOW regardless.
2260Sstevel@tonic-gate 	 */
2270Sstevel@tonic-gate 	if (plt)
2280Sstevel@tonic-gate 		return (1);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	rp = LM2LP(lmp)->lp_rp;
2310Sstevel@tonic-gate 	nr = GETRELSZ(AOUTDYN(lmp)) / sizeof (struct relocation_info);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	/*
2340Sstevel@tonic-gate 	 * Initialize _PLT_, if any.
2350Sstevel@tonic-gate 	 */
2360Sstevel@tonic-gate 	if (AOUTDYN(lmp)->v2->ld_plt_sz)
2370Sstevel@tonic-gate 		aout_plt_write((caddr_t)LM2LP(lmp)->lp_plt->jb_inst,
2380Sstevel@tonic-gate 		    (ulong_t)aout_rtbndr);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	/*
2410Sstevel@tonic-gate 	 * Loop through relocations.
2420Sstevel@tonic-gate 	 */
2430Sstevel@tonic-gate 	for (k = 0; k < nr; k++, rp++) {
2448598SRod.Evans@Sun.COM 		mmapobj_result_t	*mpp;
2458598SRod.Evans@Sun.COM 
2460Sstevel@tonic-gate 		/* LINTED */
2470Sstevel@tonic-gate 		ra = (long *)&((char *)ADDR(lmp))[rp->r_address];
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 		/*
2508598SRod.Evans@Sun.COM 		 * Make sure the segment is writable.
2510Sstevel@tonic-gate 		 */
2528598SRod.Evans@Sun.COM 		if (((mpp = find_segment((caddr_t)ra, lmp)) != NULL) &&
2538598SRod.Evans@Sun.COM 		    ((mpp->mr_prot & PROT_WRITE) == 0)) {
2548598SRod.Evans@Sun.COM 			if ((set_prot(lmp, mpp, 1) == 0) ||
2558598SRod.Evans@Sun.COM 			    (aplist_append(textrel, mpp,
2568598SRod.Evans@Sun.COM 			    AL_CNT_TEXTREL) == NULL)) {
2570Sstevel@tonic-gate 				ret = 0;
2580Sstevel@tonic-gate 				break;
2590Sstevel@tonic-gate 			}
2600Sstevel@tonic-gate 		}
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 		/*
2630Sstevel@tonic-gate 		 * Perform the relocation.
2640Sstevel@tonic-gate 		 */
2650Sstevel@tonic-gate 		if (rp->r_extern == 0) {
26611827SRod.Evans@Sun.COM 			name = NULL;
2670Sstevel@tonic-gate 			value = ADDR(lmp);
2680Sstevel@tonic-gate 		} else {
2690Sstevel@tonic-gate 			Slookup		sl;
27011827SRod.Evans@Sun.COM 			Sresult		sr;
2710Sstevel@tonic-gate 			uint_t		binfo;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 			if (rp->r_type == RELOC_JMP_SLOT)
2740Sstevel@tonic-gate 				continue;
2750Sstevel@tonic-gate 			sp = &LM2LP(lmp)->lp_symtab[rp->r_symbolnum];
2760Sstevel@tonic-gate 			name = &LM2LP(lmp)->lp_symstr[sp->n_un.n_strx];
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 			/*
2795950Srie 			 * Locate symbol.  Initialize the symbol lookup data
2805950Srie 			 * structure.
2810Sstevel@tonic-gate 			 */
2828598SRod.Evans@Sun.COM 			SLOOKUP_INIT(sl, name, lmp, 0, ld_entry_cnt,
2838598SRod.Evans@Sun.COM 			    0, 0, 0, 0, LKUP_STDRELOC);
28411827SRod.Evans@Sun.COM 			SRESULT_INIT(sr, name);
2850Sstevel@tonic-gate 
28611827SRod.Evans@Sun.COM 			if (aout_lookup_sym(&sl, &sr, &binfo, in_nfavl) == 0) {
2871618Srie 				if (lml->lm_flags & LML_FLG_TRC_WARN) {
2880Sstevel@tonic-gate 					(void)
2890Sstevel@tonic-gate 					    printf(MSG_INTL(MSG_LDD_SYM_NFOUND),
2900Sstevel@tonic-gate 					    demangle(name), NAME(lmp));
2910Sstevel@tonic-gate 					continue;
2920Sstevel@tonic-gate 				} else {
2931618Srie 					eprintf(lml, ERR_FATAL,
2940Sstevel@tonic-gate 					    MSG_INTL(MSG_REL_NOSYM), NAME(lmp),
2950Sstevel@tonic-gate 					    demangle(name));
2960Sstevel@tonic-gate 					ret = 0;
2970Sstevel@tonic-gate 					break;
2980Sstevel@tonic-gate 				}
2990Sstevel@tonic-gate 			}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 			/*
3020Sstevel@tonic-gate 			 * If symbol was found in an object other than the
3030Sstevel@tonic-gate 			 * referencing object then record the binding.
3040Sstevel@tonic-gate 			 */
30511827SRod.Evans@Sun.COM 			name = (char *)sr.sr_name;
30611827SRod.Evans@Sun.COM 			_lmp = sr.sr_dmap;
30711827SRod.Evans@Sun.COM 			sym = sr.sr_sym;
30811827SRod.Evans@Sun.COM 
3090Sstevel@tonic-gate 			if ((lmp != _lmp) &&
3100Sstevel@tonic-gate 			    ((FLAGS1(_lmp) & FL1_RT_NOINIFIN) == 0)) {
3115892Sab196087 				if (aplist_test(&bound, _lmp,
3120Sstevel@tonic-gate 				    AL_CNT_RELBIND) == 0) {
3130Sstevel@tonic-gate 					ret = 0;
3140Sstevel@tonic-gate 					break;
3150Sstevel@tonic-gate 				}
3160Sstevel@tonic-gate 			}
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 			value = sym->st_value + rp->r_addend;
3190Sstevel@tonic-gate 			if (!(FLAGS(_lmp) & FLG_RT_FIXED) &&
3200Sstevel@tonic-gate 			    (sym->st_shndx != SHN_COMMON) &&
3210Sstevel@tonic-gate 			    (sym->st_shndx != SHN_ABS))
3220Sstevel@tonic-gate 				value += ADDR(_lmp);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 			if (IS_PC_RELATIVE(rp->r_type))
3250Sstevel@tonic-gate 				value -= (long)ADDR(lmp);
3260Sstevel@tonic-gate 
3271618Srie 			DBG_CALL(Dbg_bind_global(lmp, (Addr)ra,
3281618Srie 			    (Off)(ra - ADDR(lmp)), (Xword)(-1), PLT_T_NONE,
3291618Srie 			    _lmp, (Addr)value, sym->st_value, name, binfo));
3300Sstevel@tonic-gate 		}
3310Sstevel@tonic-gate 
3320Sstevel@tonic-gate 		/*
3330Sstevel@tonic-gate 		 * Perform a specific relocation operation.
3340Sstevel@tonic-gate 		 */
3350Sstevel@tonic-gate 		switch (rp->r_type) {
3360Sstevel@tonic-gate 		case RELOC_RELATIVE:
3370Sstevel@tonic-gate 			value += *ra << (32-22);
3380Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
3394679Srie 			    ((value >> (32 - 22)) & S_MASK(22));
3400Sstevel@tonic-gate 			ra++;
3410Sstevel@tonic-gate 			value += (*ra & S_MASK(10));
3420Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(10)) |
3434679Srie 			    (value & S_MASK(10));
3440Sstevel@tonic-gate 			break;
3450Sstevel@tonic-gate 		case RELOC_8:
3460Sstevel@tonic-gate 		case RELOC_DISP8:
3470Sstevel@tonic-gate 			value += *ra & S_MASK(8);
3484679Srie 			if (!S_INRANGE(value, 8)) {
3494679Srie 				eprintf(lml, ERR_FATAL,
3504679Srie 				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3514679Srie 				    (name ? demangle(name) :
3524679Srie 				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 8,
3534679Srie 				    (uint_t)ra);
3544679Srie 			}
3550Sstevel@tonic-gate 			*ra = value;
3560Sstevel@tonic-gate 			break;
3570Sstevel@tonic-gate 		case RELOC_LO10:
3580Sstevel@tonic-gate 		case RELOC_BASE10:
3590Sstevel@tonic-gate 			value += *ra & S_MASK(10);
3600Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(10)) |
3614679Srie 			    (value & S_MASK(10));
3620Sstevel@tonic-gate 			break;
3630Sstevel@tonic-gate 		case RELOC_BASE13:
3640Sstevel@tonic-gate 		case RELOC_13:
3650Sstevel@tonic-gate 			value += *ra & S_MASK(13);
3660Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(13)) |
3674679Srie 			    (value & S_MASK(13));
3680Sstevel@tonic-gate 			break;
3690Sstevel@tonic-gate 		case RELOC_16:
3700Sstevel@tonic-gate 		case RELOC_DISP16:
3710Sstevel@tonic-gate 			value += *ra & S_MASK(16);
3724679Srie 			if (!S_INRANGE(value, 16)) {
3734679Srie 				eprintf(lml, ERR_FATAL,
3744679Srie 				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3754679Srie 				    (name ? demangle(name) :
3764679Srie 				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 16,
3774679Srie 				    (uint_t)ra);
3784679Srie 			}
3790Sstevel@tonic-gate 			*(short *)ra = value;
3800Sstevel@tonic-gate 			break;
3810Sstevel@tonic-gate 		case RELOC_22:
3820Sstevel@tonic-gate 		case RELOC_BASE22:
3830Sstevel@tonic-gate 			value += *ra & S_MASK(22);
3844679Srie 			if (!S_INRANGE(value, 22)) {
3854679Srie 				eprintf(lml, ERR_FATAL,
3864679Srie 				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3874679Srie 				    (name ? demangle(name) :
3884679Srie 				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 22,
3894679Srie 				    (uint_t)ra);
3904679Srie 			}
3910Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
3924679Srie 			    (value & S_MASK(22));
3930Sstevel@tonic-gate 			break;
3940Sstevel@tonic-gate 		case RELOC_HI22:
3950Sstevel@tonic-gate 			value += (*ra & S_MASK(22)) << (32 - 22);
3960Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
3974679Srie 			    ((value >> (32 - 22)) & S_MASK(22));
3980Sstevel@tonic-gate 			break;
3990Sstevel@tonic-gate 		case RELOC_WDISP22:
4000Sstevel@tonic-gate 			value += *ra & S_MASK(22);
4010Sstevel@tonic-gate 			value >>= 2;
4024679Srie 			if (!S_INRANGE(value, 22)) {
4034679Srie 				eprintf(lml, ERR_FATAL,
4044679Srie 				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
4054679Srie 				    (name ? demangle(name) :
4064679Srie 				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 22,
4074679Srie 				    (uint_t)ra);
4084679Srie 			}
4090Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
4104679Srie 			    (value & S_MASK(22));
4110Sstevel@tonic-gate 			break;
4120Sstevel@tonic-gate 		case RELOC_WDISP30:
4130Sstevel@tonic-gate 			value += *ra & S_MASK(30);
4140Sstevel@tonic-gate 			value >>= 2;
4150Sstevel@tonic-gate 			*(long *)ra = (*(long *)ra & ~S_MASK(30)) |
4164679Srie 			    (value & S_MASK(30));
4170Sstevel@tonic-gate 			break;
4180Sstevel@tonic-gate 		case RELOC_32:
4190Sstevel@tonic-gate 		case RELOC_GLOB_DAT:
4200Sstevel@tonic-gate 		case RELOC_DISP32:
4210Sstevel@tonic-gate 			value += *ra;
4220Sstevel@tonic-gate 			*(long *)ra = value;
4230Sstevel@tonic-gate 			break;
4240Sstevel@tonic-gate 		default:
4251618Srie 			eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_UNIMPL),
4261618Srie 			    NAME(lmp), (name ? demangle(name) :
4271618Srie 			    MSG_INTL(MSG_STR_UNKNOWN)), rp->r_type);
4280Sstevel@tonic-gate 			ret = 0;
4290Sstevel@tonic-gate 			break;
4300Sstevel@tonic-gate 		}
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 		/*
4330Sstevel@tonic-gate 		 * If this relocation is against a text segment we must make
4340Sstevel@tonic-gate 		 * sure that the instruction cache is flushed.
4350Sstevel@tonic-gate 		 */
4360Sstevel@tonic-gate 		if (textrel) {
4370Sstevel@tonic-gate 			if (rp->r_type == RELOC_RELATIVE)
4380Sstevel@tonic-gate 				iflush_range((caddr_t)(ra - 1), 0x8);
4390Sstevel@tonic-gate 			else
4400Sstevel@tonic-gate 				iflush_range((caddr_t)ra, 0x4);
4410Sstevel@tonic-gate 		}
4420Sstevel@tonic-gate 	}
4430Sstevel@tonic-gate 
4448598SRod.Evans@Sun.COM 	return (relocate_finish(lmp, bound, ret));
4450Sstevel@tonic-gate }
446