Home | History | Annotate | Line # | Download | only in sparc64
mdreloc.c revision 1.5.2.1
      1  1.5.2.1  tron /*	$NetBSD: mdreloc.c,v 1.5.2.1 2004/05/28 08:31:22 tron Exp $	*/
      2      1.1   eeh 
      3      1.1   eeh /*-
      4      1.1   eeh  * Copyright (c) 2000 Eduardo Horvath.
      5  1.5.2.1  tron  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      6      1.1   eeh  * All rights reserved.
      7      1.1   eeh  *
      8      1.1   eeh  * This code is derived from software contributed to The NetBSD Foundation
      9  1.5.2.1  tron  * by Paul Kranenburg and by Charles M. Hannum.
     10      1.1   eeh  *
     11      1.1   eeh  * Redistribution and use in source and binary forms, with or without
     12      1.1   eeh  * modification, are permitted provided that the following conditions
     13      1.1   eeh  * are met:
     14      1.1   eeh  * 1. Redistributions of source code must retain the above copyright
     15      1.1   eeh  *    notice, this list of conditions and the following disclaimer.
     16      1.1   eeh  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.1   eeh  *    notice, this list of conditions and the following disclaimer in the
     18      1.1   eeh  *    documentation and/or other materials provided with the distribution.
     19      1.1   eeh  * 3. All advertising materials mentioning features or use of this software
     20      1.1   eeh  *    must display the following acknowledgement:
     21      1.1   eeh  *        This product includes software developed by the NetBSD
     22      1.1   eeh  *        Foundation, Inc. and its contributors.
     23      1.1   eeh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.1   eeh  *    contributors may be used to endorse or promote products derived
     25      1.1   eeh  *    from this software without specific prior written permission.
     26      1.1   eeh  *
     27      1.1   eeh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.1   eeh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.1   eeh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.1   eeh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.1   eeh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.1   eeh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.1   eeh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.1   eeh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.1   eeh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.1   eeh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.1   eeh  * POSSIBILITY OF SUCH DAMAGE.
     38      1.1   eeh  */
     39      1.1   eeh 
     40      1.1   eeh #include <errno.h>
     41      1.1   eeh #include <stdio.h>
     42      1.1   eeh #include <stdlib.h>
     43      1.1   eeh #include <string.h>
     44      1.1   eeh #include <unistd.h>
     45      1.1   eeh #include <sys/stat.h>
     46      1.1   eeh 
     47      1.1   eeh #include "rtldenv.h"
     48      1.1   eeh #include "debug.h"
     49      1.1   eeh #include "rtld.h"
     50      1.1   eeh 
     51      1.1   eeh /*
     52      1.1   eeh  * The following table holds for each relocation type:
     53      1.1   eeh  *	- the width in bits of the memory location the relocation
     54      1.1   eeh  *	  applies to (not currently used)
     55      1.1   eeh  *	- the number of bits the relocation value must be shifted to the
     56      1.1   eeh  *	  right (i.e. discard least significant bits) to fit into
     57      1.1   eeh  *	  the appropriate field in the instruction word.
     58      1.1   eeh  *	- flags indicating whether
     59      1.1   eeh  *		* the relocation involves a symbol
     60      1.1   eeh  *		* the relocation is relative to the current position
     61      1.1   eeh  *		* the relocation is for a GOT entry
     62      1.1   eeh  *		* the relocation is relative to the load address
     63      1.1   eeh  *
     64      1.1   eeh  */
     65      1.1   eeh #define _RF_S		0x80000000		/* Resolve symbol */
     66      1.1   eeh #define _RF_A		0x40000000		/* Use addend */
     67      1.1   eeh #define _RF_P		0x20000000		/* Location relative */
     68      1.1   eeh #define _RF_G		0x10000000		/* GOT offset */
     69      1.1   eeh #define _RF_B		0x08000000		/* Load address relative */
     70      1.2   eeh #define _RF_U		0x04000000		/* Unaligned */
     71      1.1   eeh #define _RF_SZ(s)	(((s) & 0xff) << 8)	/* memory target size */
     72      1.1   eeh #define _RF_RS(s)	( (s) & 0xff)		/* right shift */
     73  1.5.2.1  tron static const int reloc_target_flags[] = {
     74      1.1   eeh 	0,							/* NONE */
     75      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(8)  | _RF_RS(0),		/* RELOC_8 */
     76      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(16) | _RF_RS(0),		/* RELOC_16 */
     77      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* RELOC_32 */
     78      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(8)  | _RF_RS(0),		/* DISP_8 */
     79      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(16) | _RF_RS(0),		/* DISP_16 */
     80      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* DISP_32 */
     81      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP_30 */
     82      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP_22 */
     83      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(10),	/* HI22 */
     84      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 22 */
     85      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 13 */
     86      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* LO10 */
     87      1.1   eeh 	_RF_G|			_RF_SZ(32) | _RF_RS(0),		/* GOT10 */
     88      1.1   eeh 	_RF_G|			_RF_SZ(32) | _RF_RS(0),		/* GOT13 */
     89      1.1   eeh 	_RF_G|			_RF_SZ(32) | _RF_RS(10),	/* GOT22 */
     90      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* PC10 */
     91      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(10),	/* PC22 */
     92      1.1   eeh 	      _RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WPLT30 */
     93      1.1   eeh 				_RF_SZ(32) | _RF_RS(0),		/* COPY */
     94      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(64) | _RF_RS(0),		/* GLOB_DAT */
     95      1.1   eeh 				_RF_SZ(32) | _RF_RS(0),		/* JMP_SLOT */
     96      1.1   eeh 	      _RF_A|	_RF_B|	_RF_SZ(64) | _RF_RS(0),		/* RELATIVE */
     97      1.2   eeh 	_RF_S|_RF_A|	_RF_U|	_RF_SZ(32) | _RF_RS(0),		/* UA_32 */
     98      1.1   eeh 
     99      1.1   eeh 	      _RF_A|		_RF_SZ(32) | _RF_RS(0),		/* PLT32 */
    100      1.1   eeh 	      _RF_A|		_RF_SZ(32) | _RF_RS(10),	/* HIPLT22 */
    101      1.1   eeh 	      _RF_A|		_RF_SZ(32) | _RF_RS(0),		/* LOPLT10 */
    102      1.1   eeh 	      _RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* PCPLT32 */
    103      1.1   eeh 	      _RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(10),	/* PCPLT22 */
    104      1.1   eeh 	      _RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* PCPLT10 */
    105      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 10 */
    106      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 11 */
    107      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(64) | _RF_RS(0),		/* 64 */
    108      1.1   eeh 	_RF_S|_RF_A|/*extra*/	_RF_SZ(32) | _RF_RS(0),		/* OLO10 */
    109      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(42),	/* HH22 */
    110      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(32),	/* HM10 */
    111      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(10),	/* LM22 */
    112      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(42),	/* PC_HH22 */
    113      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(32),	/* PC_HM10 */
    114      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(10),	/* PC_LM22 */
    115      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP16 */
    116      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP19 */
    117      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* GLOB_JMP */
    118      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 7 */
    119      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 5 */
    120      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 6 */
    121      1.1   eeh 	_RF_S|_RF_A|_RF_P|	_RF_SZ(64) | _RF_RS(0),		/* DISP64 */
    122      1.1   eeh 	      _RF_A|		_RF_SZ(64) | _RF_RS(0),		/* PLT64 */
    123      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(10),	/* HIX22 */
    124      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* LOX10 */
    125      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(22),	/* H44 */
    126      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(12),	/* M44 */
    127      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* L44 */
    128      1.1   eeh 	_RF_S|_RF_A|		_RF_SZ(64) | _RF_RS(0),		/* REGISTER */
    129      1.2   eeh 	_RF_S|_RF_A|	_RF_U|	_RF_SZ(64) | _RF_RS(0),		/* UA64 */
    130      1.2   eeh 	_RF_S|_RF_A|	_RF_U|	_RF_SZ(16) | _RF_RS(0),		/* UA16 */
    131      1.1   eeh };
    132      1.1   eeh 
    133      1.1   eeh #ifdef RTLD_DEBUG_RELOC
    134      1.1   eeh static const char *reloc_names[] = {
    135      1.1   eeh 	"NONE", "RELOC_8", "RELOC_16", "RELOC_32", "DISP_8",
    136      1.1   eeh 	"DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22",
    137      1.1   eeh 	"22", "13", "LO10", "GOT10", "GOT13",
    138      1.1   eeh 	"GOT22", "PC10", "PC22", "WPLT30", "COPY",
    139      1.1   eeh 	"GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32", "PLT32",
    140      1.1   eeh 	"HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", "PCPLT32",
    141      1.1   eeh 	"10", "11", "64", "OLO10", "HH22",
    142      1.1   eeh 	"HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22",
    143      1.1   eeh 	"WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6",
    144      1.1   eeh 	"DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44",
    145      1.1   eeh 	"L44", "REGISTER", "UA64", "UA16"
    146      1.1   eeh };
    147      1.1   eeh #endif
    148      1.1   eeh 
    149      1.1   eeh #define RELOC_RESOLVE_SYMBOL(t)		((reloc_target_flags[t] & _RF_S) != 0)
    150      1.1   eeh #define RELOC_PC_RELATIVE(t)		((reloc_target_flags[t] & _RF_P) != 0)
    151      1.1   eeh #define RELOC_BASE_RELATIVE(t)		((reloc_target_flags[t] & _RF_B) != 0)
    152      1.2   eeh #define RELOC_UNALIGNED(t)		((reloc_target_flags[t] & _RF_U) != 0)
    153      1.2   eeh #define RELOC_USE_ADDEND(t)		((reloc_target_flags[t] & _RF_A) != 0)
    154      1.1   eeh #define RELOC_TARGET_SIZE(t)		((reloc_target_flags[t] >> 8) & 0xff)
    155      1.1   eeh #define RELOC_VALUE_RIGHTSHIFT(t)	(reloc_target_flags[t] & 0xff)
    156      1.1   eeh 
    157  1.5.2.1  tron static const long reloc_target_bitmask[] = {
    158      1.1   eeh #define _BM(x)	(~(-(1ULL << (x))))
    159      1.1   eeh 	0,				/* NONE */
    160      1.1   eeh 	_BM(8), _BM(16), _BM(32),	/* RELOC_8, _16, _32 */
    161      1.1   eeh 	_BM(8), _BM(16), _BM(32),	/* DISP8, DISP16, DISP32 */
    162      1.1   eeh 	_BM(30), _BM(22),		/* WDISP30, WDISP22 */
    163      1.1   eeh 	_BM(22), _BM(22),		/* HI22, _22 */
    164      1.1   eeh 	_BM(13), _BM(10),		/* RELOC_13, _LO10 */
    165      1.1   eeh 	_BM(10), _BM(13), _BM(22),	/* GOT10, GOT13, GOT22 */
    166      1.1   eeh 	_BM(10), _BM(22),		/* _PC10, _PC22 */
    167      1.1   eeh 	_BM(30), 0,			/* _WPLT30, _COPY */
    168      1.1   eeh 	_BM(32), _BM(32), _BM(32),	/* _GLOB_DAT, JMP_SLOT, _RELATIVE */
    169      1.1   eeh 	_BM(32), _BM(32),		/* _UA32, PLT32 */
    170      1.1   eeh 	_BM(22), _BM(10),		/* _HIPLT22, LOPLT10 */
    171      1.1   eeh 	_BM(32), _BM(22), _BM(10),	/* _PCPLT32, _PCPLT22, _PCPLT10 */
    172      1.1   eeh 	_BM(10), _BM(11), -1,		/* _10, _11, _64 */
    173      1.1   eeh 	_BM(10), _BM(22),		/* _OLO10, _HH22 */
    174      1.1   eeh 	_BM(10), _BM(22),		/* _HM10, _LM22 */
    175      1.1   eeh 	_BM(22), _BM(10), _BM(22),	/* _PC_HH22, _PC_HM10, _PC_LM22 */
    176      1.1   eeh 	_BM(16), _BM(19),		/* _WDISP16, _WDISP19 */
    177      1.1   eeh 	-1,				/* GLOB_JMP */
    178      1.1   eeh 	_BM(7), _BM(5), _BM(6)		/* _7, _5, _6 */
    179      1.1   eeh 	-1, -1,				/* DISP64, PLT64 */
    180      1.1   eeh 	_BM(22), _BM(13),		/* HIX22, LOX10 */
    181      1.1   eeh 	_BM(22), _BM(10), _BM(13),	/* H44, M44, L44 */
    182      1.1   eeh 	-1, -1, _BM(16),		/* REGISTER, UA64, UA16 */
    183      1.1   eeh #undef _BM
    184      1.1   eeh };
    185      1.1   eeh #define RELOC_VALUE_BITMASK(t)	(reloc_target_bitmask[t])
    186      1.1   eeh 
    187  1.5.2.1  tron /*
    188  1.5.2.1  tron  * Instruction templates:
    189  1.5.2.1  tron  */
    190  1.5.2.1  tron #define	BAA	0x10400000	/*	ba,a	%xcc, 0 */
    191  1.5.2.1  tron #define	SETHI	0x03000000	/*	sethi	%hi(0), %g1 */
    192  1.5.2.1  tron #define	JMP	0x81c06000	/*	jmpl	%g1+%lo(0), %g0 */
    193  1.5.2.1  tron #define	NOP	0x01000000	/*	sethi	%hi(0), %g0 */
    194  1.5.2.1  tron #define	OR	0x82806000	/*	or	%g1, 0, %g1 */
    195  1.5.2.1  tron #define	XOR	0x82c06000	/*	xor	%g1, 0, %g1 */
    196  1.5.2.1  tron #define	MOV71	0x8283a000	/*	or	%o7, 0, %g1 */
    197  1.5.2.1  tron #define	MOV17	0x9c806000	/*	or	%g1, 0, %o7 */
    198  1.5.2.1  tron #define	CALL	0x40000000	/*	call	0 */
    199  1.5.2.1  tron #define	SLLX	0x8b407000	/*	sllx	%g1, 0, %g1 */
    200  1.5.2.1  tron #define	SETHIG5	0x0b000000	/*	sethi	%hi(0), %g5 */
    201  1.5.2.1  tron #define	ORG5	0x82804005	/*	or	%g1, %g5, %g1 */
    202      1.1   eeh 
    203  1.5.2.1  tron 
    204  1.5.2.1  tron /* %hi(v)/%lo(v) with variable shift */
    205  1.5.2.1  tron #define	HIVAL(v, s)	(((v) >> (s)) & 0x003fffff)
    206  1.5.2.1  tron #define LOVAL(v, s)	(((v) >> (s)) & 0x000003ff)
    207  1.5.2.1  tron 
    208  1.5.2.1  tron void _rtld_bind_start_0(long, long);
    209  1.5.2.1  tron void _rtld_bind_start_1(long, long);
    210  1.5.2.1  tron void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
    211  1.5.2.1  tron caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
    212  1.5.2.1  tron 
    213  1.5.2.1  tron /*
    214  1.5.2.1  tron  * Install rtld function call into this PLT slot.
    215  1.5.2.1  tron  */
    216  1.5.2.1  tron #define	SAVE		0x9de3bf50	/* i.e. `save %sp,-176,%sp' */
    217  1.5.2.1  tron #define	SETHI_l0	0x21000000
    218  1.5.2.1  tron #define	SETHI_l1	0x23000000
    219  1.5.2.1  tron #define	OR_l0_l0	0xa0142000
    220  1.5.2.1  tron #define	SLLX_l0_32_l0	0xa12c3020
    221  1.5.2.1  tron #define	OR_l0_l1_l0	0xa0140011
    222  1.5.2.1  tron #define	JMPL_l0_o0	0x91c42000
    223  1.5.2.1  tron #define	MOV_g1_o1	0x92100001
    224  1.5.2.1  tron 
    225  1.5.2.1  tron void _rtld_install_plt(Elf_Word *pltgot, Elf_Addr proc);
    226  1.5.2.1  tron 
    227  1.5.2.1  tron void
    228  1.5.2.1  tron _rtld_install_plt(Elf_Word *pltgot, Elf_Addr proc)
    229      1.1   eeh {
    230  1.5.2.1  tron 	pltgot[0] = SAVE;
    231  1.5.2.1  tron 	pltgot[1] = SETHI_l0  | HIVAL(proc, 42);
    232  1.5.2.1  tron 	pltgot[2] = SETHI_l1  | HIVAL(proc, 10);
    233  1.5.2.1  tron 	pltgot[3] = OR_l0_l0  | LOVAL(proc, 32);
    234  1.5.2.1  tron 	pltgot[4] = SLLX_l0_32_l0;
    235  1.5.2.1  tron 	pltgot[5] = OR_l0_l1_l0;
    236  1.5.2.1  tron 	pltgot[6] = JMPL_l0_o0 | LOVAL(proc, 0);
    237  1.5.2.1  tron 	pltgot[7] = MOV_g1_o1;
    238  1.5.2.1  tron }
    239      1.1   eeh 
    240  1.5.2.1  tron void
    241  1.5.2.1  tron _rtld_setup_pltgot(const Obj_Entry *obj)
    242  1.5.2.1  tron {
    243      1.1   eeh 	/*
    244  1.5.2.1  tron 	 * On sparc64 we got troubles.
    245  1.5.2.1  tron 	 *
    246  1.5.2.1  tron 	 * Instructions are 4 bytes long.
    247  1.5.2.1  tron 	 * Elf[64]_Addr is 8 bytes long, so are our pltglot[]
    248  1.5.2.1  tron 	 * array entries.
    249  1.5.2.1  tron 	 * Each PLT entry jumps to PLT0 to enter the dynamic
    250  1.5.2.1  tron 	 * linker.
    251  1.5.2.1  tron 	 * Loading an arbitrary 64-bit pointer takes 6
    252  1.5.2.1  tron 	 * instructions and 2 registers.
    253  1.5.2.1  tron 	 *
    254  1.5.2.1  tron 	 * Somehow we need to issue a save to get a new stack
    255  1.5.2.1  tron 	 * frame, load the address of the dynamic linker, and
    256  1.5.2.1  tron 	 * jump there, in 8 instructions or less.
    257  1.5.2.1  tron 	 *
    258  1.5.2.1  tron 	 * Oh, we need to fill out both PLT0 and PLT1.
    259      1.1   eeh 	 */
    260  1.5.2.1  tron 	{
    261  1.5.2.1  tron 		Elf_Word *entry = (Elf_Word *)obj->pltgot;
    262      1.1   eeh 
    263  1.5.2.1  tron 		/* Install in entries 0 and 1 */
    264  1.5.2.1  tron 		_rtld_install_plt(&entry[0], (Elf_Addr) &_rtld_bind_start_0);
    265  1.5.2.1  tron 		_rtld_install_plt(&entry[8], (Elf_Addr) &_rtld_bind_start_1);
    266      1.1   eeh 
    267  1.5.2.1  tron 		/*
    268  1.5.2.1  tron 		 * Install the object reference in first slot
    269  1.5.2.1  tron 		 * of entry 2.
    270  1.5.2.1  tron 		 */
    271  1.5.2.1  tron 		obj->pltgot[8] = (Elf_Addr) obj;
    272  1.5.2.1  tron 	}
    273  1.5.2.1  tron }
    274  1.5.2.1  tron 
    275  1.5.2.1  tron void
    276  1.5.2.1  tron _rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
    277  1.5.2.1  tron {
    278  1.5.2.1  tron 	const Elf_Rela *rela = 0, *relalim;
    279  1.5.2.1  tron 	Elf_Addr relasz = 0;
    280  1.5.2.1  tron 	Elf_Addr *where;
    281  1.5.2.1  tron 
    282  1.5.2.1  tron 	for (; dynp->d_tag != DT_NULL; dynp++) {
    283  1.5.2.1  tron 		switch (dynp->d_tag) {
    284  1.5.2.1  tron 		case DT_RELA:
    285  1.5.2.1  tron 			rela = (const Elf_Rela *)(relocbase + dynp->d_un.d_ptr);
    286  1.5.2.1  tron 			break;
    287  1.5.2.1  tron 		case DT_RELASZ:
    288  1.5.2.1  tron 			relasz = dynp->d_un.d_val;
    289  1.5.2.1  tron 			break;
    290  1.5.2.1  tron 		}
    291  1.5.2.1  tron 	}
    292  1.5.2.1  tron 	relalim = (const Elf_Rela *)((caddr_t)rela + relasz);
    293  1.5.2.1  tron 	for (; rela < relalim; rela++) {
    294  1.5.2.1  tron 		where = (Elf_Addr *)(relocbase + rela->r_offset);
    295  1.5.2.1  tron 		*where = (Elf_Addr)(relocbase + rela->r_addend);
    296      1.1   eeh 	}
    297  1.5.2.1  tron }
    298  1.5.2.1  tron 
    299  1.5.2.1  tron int
    300  1.5.2.1  tron _rtld_relocate_nonplt_objects(const Obj_Entry *obj)
    301  1.5.2.1  tron {
    302  1.5.2.1  tron 	const Elf_Rela *rela;
    303      1.1   eeh 
    304  1.5.2.1  tron 	for (rela = obj->rela; rela < obj->relalim; rela++) {
    305  1.5.2.1  tron 		Elf_Addr *where;
    306  1.5.2.1  tron 		Elf_Word type;
    307  1.5.2.1  tron 		Elf_Addr value = 0, mask;
    308  1.5.2.1  tron 		const Elf_Sym *def = NULL;
    309  1.5.2.1  tron 		const Obj_Entry *defobj = NULL;
    310  1.5.2.1  tron 		unsigned long	 symnum;
    311  1.5.2.1  tron 
    312  1.5.2.1  tron 		where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
    313  1.5.2.1  tron 		symnum = ELF_R_SYM(rela->r_info);
    314  1.5.2.1  tron 
    315  1.5.2.1  tron 		type = ELF_R_TYPE(rela->r_info);
    316  1.5.2.1  tron 		if (type == R_TYPE(NONE))
    317  1.5.2.1  tron 			continue;
    318  1.5.2.1  tron 
    319  1.5.2.1  tron 		/* We do JMP_SLOTs in _rtld_bind() below */
    320  1.5.2.1  tron 		if (type == R_TYPE(JMP_SLOT))
    321  1.5.2.1  tron 			continue;
    322  1.5.2.1  tron 
    323  1.5.2.1  tron 		/* COPY relocs are also handled elsewhere */
    324  1.5.2.1  tron 		if (type == R_TYPE(COPY))
    325  1.5.2.1  tron 			continue;
    326      1.1   eeh 
    327  1.5.2.1  tron 		/*
    328  1.5.2.1  tron 		 * We use the fact that relocation types are an `enum'
    329  1.5.2.1  tron 		 * Note: R_SPARC_UA16 is currently numerically largest.
    330  1.5.2.1  tron 		 */
    331  1.5.2.1  tron 		if (type > R_TYPE(UA16))
    332      1.1   eeh 			return (-1);
    333      1.1   eeh 
    334  1.5.2.1  tron 		value = rela->r_addend;
    335      1.1   eeh 
    336      1.1   eeh 		/*
    337  1.5.2.1  tron 		 * Handle relative relocs here, as an optimization.
    338      1.1   eeh 		 */
    339  1.5.2.1  tron 		if (type == R_TYPE(RELATIVE)) {
    340  1.5.2.1  tron 			*where = (Elf_Addr)(obj->relocbase + value);
    341  1.5.2.1  tron 			rdbg(("RELATIVE in %s --> %p", obj->path,
    342  1.5.2.1  tron 			    (void *)*where));
    343  1.5.2.1  tron 			continue;
    344  1.5.2.1  tron 		}
    345  1.5.2.1  tron 
    346  1.5.2.1  tron 		if (RELOC_RESOLVE_SYMBOL(type)) {
    347  1.5.2.1  tron 
    348  1.5.2.1  tron 			/* Find the symbol */
    349  1.5.2.1  tron 			def = _rtld_find_symdef(symnum, obj, &defobj, false);
    350  1.5.2.1  tron 			if (def == NULL)
    351  1.5.2.1  tron 				return (-1);
    352  1.5.2.1  tron 
    353  1.5.2.1  tron 			/* Add in the symbol's absolute address */
    354  1.5.2.1  tron 			value += (Elf_Addr)(defobj->relocbase + def->st_value);
    355      1.1   eeh 		}
    356  1.5.2.1  tron 
    357  1.5.2.1  tron 		if (RELOC_PC_RELATIVE(type)) {
    358  1.5.2.1  tron 			value -= (Elf_Addr)where;
    359  1.5.2.1  tron 		}
    360  1.5.2.1  tron 
    361  1.5.2.1  tron 		if (RELOC_BASE_RELATIVE(type)) {
    362  1.5.2.1  tron 			/*
    363  1.5.2.1  tron 			 * Note that even though sparcs use `Elf_rela'
    364  1.5.2.1  tron 			 * exclusively we still need the implicit memory addend
    365  1.5.2.1  tron 			 * in relocations referring to GOT entries.
    366  1.5.2.1  tron 			 * Undoubtedly, someone f*cked this up in the distant
    367  1.5.2.1  tron 			 * past, and now we're stuck with it in the name of
    368  1.5.2.1  tron 			 * compatibility for all eternity..
    369  1.5.2.1  tron 			 *
    370  1.5.2.1  tron 			 * In any case, the implicit and explicit should be
    371  1.5.2.1  tron 			 * mutually exclusive. We provide a check for that
    372  1.5.2.1  tron 			 * here.
    373  1.5.2.1  tron 			 */
    374  1.5.2.1  tron #ifdef DIAGNOSTIC
    375  1.5.2.1  tron 			if (value != 0 && *where != 0) {
    376  1.5.2.1  tron 				xprintf("BASE_REL(%s): where=%p, *where 0x%lx, "
    377  1.5.2.1  tron 					"addend=0x%lx, base %p\n",
    378  1.5.2.1  tron 					obj->path, where, *where,
    379  1.5.2.1  tron 					rela->r_addend, obj->relocbase);
    380  1.5.2.1  tron 			}
    381      1.1   eeh #endif
    382  1.5.2.1  tron 			/* XXXX -- apparently we ignore the preexisting value */
    383  1.5.2.1  tron 			value += (Elf_Addr)(obj->relocbase);
    384  1.5.2.1  tron 		}
    385      1.1   eeh 
    386  1.5.2.1  tron 		mask = RELOC_VALUE_BITMASK(type);
    387  1.5.2.1  tron 		value >>= RELOC_VALUE_RIGHTSHIFT(type);
    388  1.5.2.1  tron 		value &= mask;
    389  1.5.2.1  tron 
    390  1.5.2.1  tron 		if (RELOC_UNALIGNED(type)) {
    391  1.5.2.1  tron 			/* Handle unaligned relocations. */
    392  1.5.2.1  tron 			Elf_Addr tmp = 0;
    393  1.5.2.1  tron 			char *ptr = (char *)where;
    394  1.5.2.1  tron 			int i, size = RELOC_TARGET_SIZE(type)/8;
    395  1.5.2.1  tron 
    396  1.5.2.1  tron 			/* Read it in one byte at a time. */
    397  1.5.2.1  tron 			for (i=0; i<size; i++)
    398  1.5.2.1  tron 				tmp = (tmp << 8) | ptr[i];
    399  1.5.2.1  tron 
    400  1.5.2.1  tron 			tmp &= ~mask;
    401  1.5.2.1  tron 			tmp |= value;
    402  1.5.2.1  tron 
    403  1.5.2.1  tron 			/* Write it back out. */
    404  1.5.2.1  tron 			for (i=0; i<size; i++)
    405  1.5.2.1  tron 				ptr[i] = ((tmp >> (8*i)) & 0xff);
    406      1.2   eeh #ifdef RTLD_DEBUG_RELOC
    407  1.5.2.1  tron 			value = (Elf_Addr)tmp;
    408      1.2   eeh #endif
    409      1.2   eeh 
    410  1.5.2.1  tron 		} else if (RELOC_TARGET_SIZE(type) > 32) {
    411  1.5.2.1  tron 			*where &= ~mask;
    412  1.5.2.1  tron 			*where |= value;
    413      1.1   eeh #ifdef RTLD_DEBUG_RELOC
    414  1.5.2.1  tron 			value = (Elf_Addr)*where;
    415      1.1   eeh #endif
    416  1.5.2.1  tron 		} else {
    417  1.5.2.1  tron 			Elf32_Addr *where32 = (Elf32_Addr *)where;
    418      1.1   eeh 
    419  1.5.2.1  tron 			*where32 &= ~mask;
    420  1.5.2.1  tron 			*where32 |= value;
    421      1.1   eeh #ifdef RTLD_DEBUG_RELOC
    422  1.5.2.1  tron 			value = (Elf_Addr)*where32;
    423      1.1   eeh #endif
    424  1.5.2.1  tron 		}
    425      1.1   eeh 
    426      1.1   eeh #ifdef RTLD_DEBUG_RELOC
    427  1.5.2.1  tron 		if (RELOC_RESOLVE_SYMBOL(type)) {
    428  1.5.2.1  tron 			rdbg(("%s %s in %s --> %p in %s", reloc_names[type],
    429  1.5.2.1  tron 			    obj->strtab + obj->symtab[symnum].st_name,
    430  1.5.2.1  tron 			    obj->path, (void *)value, defobj->path));
    431  1.5.2.1  tron 		} else {
    432  1.5.2.1  tron 			rdbg(("%s in %s --> %p", reloc_names[type],
    433  1.5.2.1  tron 			    obj->path, (void *)value));
    434  1.5.2.1  tron 		}
    435      1.1   eeh #endif
    436  1.5.2.1  tron 	}
    437      1.1   eeh 	return (0);
    438      1.1   eeh }
    439      1.1   eeh 
    440      1.1   eeh int
    441  1.5.2.1  tron _rtld_relocate_plt_lazy(const Obj_Entry *obj)
    442  1.5.2.1  tron {
    443  1.5.2.1  tron 	return (0);
    444  1.5.2.1  tron }
    445  1.5.2.1  tron 
    446  1.5.2.1  tron caddr_t
    447  1.5.2.1  tron _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
    448      1.1   eeh {
    449  1.5.2.1  tron 	const Elf_Rela *rela = obj->pltrela + reloff;
    450      1.1   eeh 	const Elf_Sym *def;
    451      1.1   eeh 	const Obj_Entry *defobj;
    452  1.5.2.1  tron 	Elf_Word *where;
    453      1.1   eeh 	Elf_Addr value, offset;
    454      1.1   eeh 
    455  1.5.2.1  tron 	if (ELF_R_TYPE(obj->pltrela->r_info) == R_TYPE(JMP_SLOT)) {
    456  1.5.2.1  tron 		/*
    457  1.5.2.1  tron 		 * XXXX
    458  1.5.2.1  tron 		 *
    459  1.5.2.1  tron 		 * The first four PLT entries are reserved.  There is some
    460  1.5.2.1  tron 		 * disagreement whether they should have associated relocation
    461  1.5.2.1  tron 		 * entries.  Both the SPARC 32-bit and 64-bit ELF
    462  1.5.2.1  tron 		 * specifications say that they should have relocation entries,
    463  1.5.2.1  tron 		 * but the 32-bit SPARC binutils do not generate them, and now
    464  1.5.2.1  tron 		 * the 64-bit SPARC binutils have stopped generating them too.
    465  1.5.2.1  tron 		 *
    466  1.5.2.1  tron 		 * So, to provide binary compatibility, we will check the first
    467  1.5.2.1  tron 		 * entry, if it is reserved it should not be of the type
    468  1.5.2.1  tron 		 * JMP_SLOT.  If it is JMP_SLOT, then the 4 reserved entries
    469  1.5.2.1  tron 		 * were not generated and our index is 4 entries too far.
    470  1.5.2.1  tron 		 */
    471  1.5.2.1  tron 		rela -= 4;
    472  1.5.2.1  tron 	}
    473  1.5.2.1  tron 
    474  1.5.2.1  tron 	where = (Elf_Word *)(obj->relocbase + rela->r_offset);
    475      1.1   eeh 
    476      1.1   eeh 	/* Fully resolve procedure addresses now */
    477      1.1   eeh 
    478      1.1   eeh 	assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JMP_SLOT));
    479      1.1   eeh 
    480  1.5.2.1  tron 	def = _rtld_find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, true);
    481      1.1   eeh 	if (def == NULL)
    482  1.5.2.1  tron 		_rtld_die();
    483      1.1   eeh 
    484  1.5.2.1  tron 	value = (Elf_Addr)(defobj->relocbase + def->st_value);
    485  1.5.2.1  tron 	rdbg(("bind now/fixup in %s --> new=%p",
    486  1.5.2.1  tron 	    defobj->strtab + def->st_name, (void *)value));
    487      1.1   eeh 
    488      1.1   eeh 	/*
    489      1.1   eeh 	 * At the PLT entry pointed at by `where', we now construct
    490      1.1   eeh 	 * a direct transfer to the now fully resolved function
    491      1.1   eeh 	 * address.
    492      1.1   eeh 	 *
    493      1.1   eeh 	 * A PLT entry is supposed to start by looking like this:
    494      1.1   eeh 	 *
    495      1.1   eeh 	 *	sethi	%hi(. - .PLT0), %g1
    496      1.1   eeh 	 *	ba,a	%xcc, .PLT1
    497      1.1   eeh 	 *	nop
    498      1.1   eeh 	 *	nop
    499      1.1   eeh 	 *	nop
    500      1.1   eeh 	 *	nop
    501      1.1   eeh 	 *	nop
    502      1.1   eeh 	 *	nop
    503      1.1   eeh 	 *
    504      1.1   eeh 	 * When we replace these entries we start from the second
    505      1.1   eeh 	 * entry and do it in reverse order so the last thing we
    506      1.1   eeh 	 * do is replace the branch.  That allows us to change this
    507      1.1   eeh 	 * atomically.
    508      1.1   eeh 	 *
    509      1.1   eeh 	 * We now need to find out how far we need to jump.  We
    510      1.1   eeh 	 * have a choice of several different relocation techniques
    511      1.1   eeh 	 * which are increasingly expensive.
    512      1.1   eeh 	 */
    513      1.1   eeh 
    514      1.1   eeh 	offset = ((Elf_Addr)where) - value;
    515      1.1   eeh 	if (rela->r_addend) {
    516      1.1   eeh 		Elf_Addr *ptr = (Elf_Addr *)where;
    517      1.1   eeh 		/*
    518  1.5.2.1  tron 		 * This entry is >=32768.  The relocations points to a
    519  1.5.2.1  tron 		 * PC-relative pointer to the bind_0 stub at the top of the
    520  1.5.2.1  tron 		 * PLT section.  Update it to point to the target function.
    521      1.1   eeh 		 */
    522  1.5.2.1  tron 		ptr[0] += value - (Elf_Addr)obj->pltgot;
    523      1.1   eeh 
    524      1.1   eeh 	} else if (offset <= (1L<<20) && offset >= -(1L<<20)) {
    525      1.1   eeh 		/*
    526      1.1   eeh 		 * We're within 1MB -- we can use a direct branch insn.
    527      1.1   eeh 		 *
    528      1.1   eeh 		 * We can generate this pattern:
    529      1.1   eeh 		 *
    530      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    531      1.1   eeh 		 *	ba,a	%xcc, addr
    532      1.1   eeh 		 *	nop
    533      1.1   eeh 		 *	nop
    534      1.1   eeh 		 *	nop
    535      1.1   eeh 		 *	nop
    536      1.1   eeh 		 *	nop
    537      1.1   eeh 		 *	nop
    538      1.1   eeh 		 *
    539      1.1   eeh 		 */
    540      1.1   eeh 		where[1] = BAA | ((offset >> 2) &0x3fffff);
    541      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    542      1.1   eeh 	} else if (value >= 0 && value < (1L<<32)) {
    543      1.1   eeh 		/*
    544  1.5.2.1  tron 		 * We're within 32-bits of address zero.
    545      1.1   eeh 		 *
    546      1.1   eeh 		 * The resulting code in the jump slot is:
    547      1.1   eeh 		 *
    548      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    549      1.1   eeh 		 *	sethi	%hi(addr), %g1
    550      1.1   eeh 		 *	jmp	%g1+%lo(addr)
    551      1.1   eeh 		 *	nop
    552      1.1   eeh 		 *	nop
    553      1.1   eeh 		 *	nop
    554      1.1   eeh 		 *	nop
    555      1.1   eeh 		 *	nop
    556      1.1   eeh 		 *
    557      1.1   eeh 		 */
    558  1.5.2.1  tron 		where[2] = JMP   | LOVAL(value, 0);
    559      1.1   eeh 		where[1] = SETHI | HIVAL(value, 10);
    560      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    561      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    562      1.1   eeh 
    563      1.1   eeh 	} else if (value <= 0 && value > -(1L<<32)) {
    564      1.1   eeh 		/*
    565  1.5.2.1  tron 		 * We're within 32-bits of address -1.
    566      1.1   eeh 		 *
    567      1.1   eeh 		 * The resulting code in the jump slot is:
    568      1.1   eeh 		 *
    569      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    570      1.1   eeh 		 *	sethi	%hix(addr), %g1
    571      1.1   eeh 		 *	xor	%g1, %lox(addr), %g1
    572      1.1   eeh 		 *	jmp	%g1
    573      1.1   eeh 		 *	nop
    574      1.1   eeh 		 *	nop
    575      1.1   eeh 		 *	nop
    576      1.1   eeh 		 *	nop
    577      1.1   eeh 		 *
    578      1.1   eeh 		 */
    579      1.1   eeh 		where[3] = JMP;
    580      1.1   eeh 		where[2] = XOR | ((~value) & 0x00001fff);
    581      1.1   eeh 		where[1] = SETHI | HIVAL(~value, 10);
    582      1.1   eeh 		__asm __volatile("iflush %0+12" : : "r" (where));
    583      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    584      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    585      1.1   eeh 
    586      1.1   eeh 	} else if (offset <= (1L<<32) && offset >= -((1L<<32) - 4)) {
    587      1.1   eeh 		/*
    588  1.5.2.1  tron 		 * We're within 32-bits -- we can use a direct call insn
    589      1.1   eeh 		 *
    590      1.1   eeh 		 * The resulting code in the jump slot is:
    591      1.1   eeh 		 *
    592      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    593      1.1   eeh 		 *	mov	%o7, %g1
    594      1.1   eeh 		 *	call	(.+offset)
    595      1.1   eeh 		 *	 mov	%g1, %o7
    596      1.1   eeh 		 *	nop
    597      1.1   eeh 		 *	nop
    598      1.1   eeh 		 *	nop
    599      1.1   eeh 		 *	nop
    600      1.1   eeh 		 *
    601      1.1   eeh 		 */
    602      1.1   eeh 		where[3] = MOV17;
    603      1.1   eeh 		where[2] = CALL	  | ((offset >> 4) & 0x3fffffff);
    604      1.1   eeh 		where[1] = MOV71;
    605      1.1   eeh 		__asm __volatile("iflush %0+12" : : "r" (where));
    606      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    607      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    608      1.1   eeh 
    609      1.1   eeh 	} else if (offset >= 0 && offset < (1L<<44)) {
    610      1.1   eeh 		/*
    611  1.5.2.1  tron 		 * We're within 44 bits.  We can generate this pattern:
    612      1.1   eeh 		 *
    613      1.1   eeh 		 * The resulting code in the jump slot is:
    614      1.1   eeh 		 *
    615      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    616      1.1   eeh 		 *	sethi	%h44(addr), %g1
    617      1.1   eeh 		 *	or	%g1, %m44(addr), %g1
    618      1.1   eeh 		 *	sllx	%g1, 12, %g1
    619      1.1   eeh 		 *	jmp	%g1+%l44(addr)
    620      1.1   eeh 		 *	nop
    621      1.1   eeh 		 *	nop
    622      1.1   eeh 		 *	nop
    623      1.1   eeh 		 *
    624      1.1   eeh 		 */
    625  1.5.2.1  tron 		where[4] = JMP   | LOVAL(offset, 0);
    626      1.1   eeh 		where[3] = SLLX  | 12;
    627      1.1   eeh 		where[2] = OR    | (((offset) >> 12) & 0x00001fff);
    628      1.1   eeh 		where[1] = SETHI | HIVAL(offset, 22);
    629      1.1   eeh 		__asm __volatile("iflush %0+16" : : "r" (where));
    630      1.1   eeh 		__asm __volatile("iflush %0+12" : : "r" (where));
    631      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    632      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    633      1.1   eeh 
    634      1.1   eeh 	} else if (offset < 0 && offset > -(1L<<44)) {
    635      1.1   eeh 		/*
    636  1.5.2.1  tron 		 * We're within 44 bits.  We can generate this pattern:
    637      1.1   eeh 		 *
    638      1.1   eeh 		 * The resulting code in the jump slot is:
    639      1.1   eeh 		 *
    640      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    641      1.1   eeh 		 *	sethi	%h44(-addr), %g1
    642      1.1   eeh 		 *	xor	%g1, %m44(-addr), %g1
    643      1.1   eeh 		 *	sllx	%g1, 12, %g1
    644      1.1   eeh 		 *	jmp	%g1+%l44(addr)
    645      1.1   eeh 		 *	nop
    646      1.1   eeh 		 *	nop
    647      1.1   eeh 		 *	nop
    648      1.1   eeh 		 *
    649      1.1   eeh 		 */
    650  1.5.2.1  tron 		where[4] = JMP   | LOVAL(offset, 0);
    651      1.1   eeh 		where[3] = SLLX  | 12;
    652      1.1   eeh 		where[2] = XOR   | (((~offset) >> 12) & 0x00001fff);
    653      1.1   eeh 		where[1] = SETHI | HIVAL(~offset, 22);
    654      1.1   eeh 		__asm __volatile("iflush %0+16" : : "r" (where));
    655      1.1   eeh 		__asm __volatile("iflush %0+12" : : "r" (where));
    656      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    657      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    658      1.1   eeh 
    659      1.1   eeh 	} else {
    660      1.1   eeh 		/*
    661      1.1   eeh 		 * We need to load all 64-bits
    662      1.1   eeh 		 *
    663      1.1   eeh 		 * The resulting code in the jump slot is:
    664      1.1   eeh 		 *
    665      1.1   eeh 		 *	sethi	%hi(. - .PLT0), %g1
    666      1.1   eeh 		 *	sethi	%hh(addr), %g1
    667      1.1   eeh 		 *	sethi	%lm(addr), %g5
    668      1.1   eeh 		 *	or	%g1, %hm(addr), %g1
    669      1.1   eeh 		 *	sllx	%g1, 32, %g1
    670      1.1   eeh 		 *	or	%g1, %g5, %g1
    671      1.1   eeh 		 *	jmp	%g1+%lo(addr)
    672      1.1   eeh 		 *	nop
    673      1.1   eeh 		 *
    674      1.1   eeh 		 */
    675  1.5.2.1  tron 		where[6] = JMP     | LOVAL(value, 0);
    676      1.1   eeh 		where[5] = ORG5;
    677  1.5.2.1  tron 		where[4] = SLLX    | 32;
    678  1.5.2.1  tron 		where[3] = OR      | LOVAL(value, 32);
    679      1.1   eeh 		where[2] = SETHIG5 | HIVAL(value, 10);
    680      1.1   eeh 		where[1] = SETHI   | HIVAL(value, 42);
    681  1.5.2.1  tron 		__asm __volatile("iflush %0+24" : : "r" (where));
    682      1.1   eeh 		__asm __volatile("iflush %0+20" : : "r" (where));
    683      1.1   eeh 		__asm __volatile("iflush %0+16" : : "r" (where));
    684      1.1   eeh 		__asm __volatile("iflush %0+12" : : "r" (where));
    685      1.1   eeh 		__asm __volatile("iflush %0+8" : : "r" (where));
    686      1.1   eeh 		__asm __volatile("iflush %0+4" : : "r" (where));
    687      1.1   eeh 
    688      1.1   eeh 	}
    689      1.1   eeh 
    690  1.5.2.1  tron 	return (caddr_t)value;
    691      1.2   eeh }
    692