Home | History | Annotate | Line # | Download | only in sparc
mdreloc.c revision 1.45
      1  1.45     joerg /*	$NetBSD: mdreloc.c,v 1.45 2011/03/25 18:07:06 joerg Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*-
      4  1.27   mycroft  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5   1.1  christos  * All rights reserved.
      6   1.1  christos  *
      7   1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.29   mycroft  * by Paul Kranenburg and by Charles M. Hannum.
      9   1.1  christos  *
     10   1.1  christos  * Redistribution and use in source and binary forms, with or without
     11   1.1  christos  * modification, are permitted provided that the following conditions
     12   1.1  christos  * are met:
     13   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  christos  *    documentation and/or other materials provided with the distribution.
     18   1.1  christos  *
     19   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  christos  */
     31   1.1  christos 
     32  1.37     skrll #include <sys/cdefs.h>
     33  1.37     skrll #ifndef lint
     34  1.45     joerg __RCSID("$NetBSD: mdreloc.c,v 1.45 2011/03/25 18:07:06 joerg Exp $");
     35  1.37     skrll #endif /* not lint */
     36  1.37     skrll 
     37   1.1  christos #include <errno.h>
     38   1.1  christos #include <stdio.h>
     39   1.1  christos #include <stdlib.h>
     40   1.1  christos #include <string.h>
     41   1.1  christos #include <unistd.h>
     42   1.1  christos 
     43   1.1  christos #include "rtldenv.h"
     44   1.1  christos #include "debug.h"
     45   1.1  christos #include "rtld.h"
     46   1.1  christos 
     47   1.1  christos /*
     48   1.1  christos  * The following table holds for each relocation type:
     49   1.1  christos  *	- the width in bits of the memory location the relocation
     50   1.1  christos  *	  applies to (not currently used)
     51   1.1  christos  *	- the number of bits the relocation value must be shifted to the
     52   1.1  christos  *	  right (i.e. discard least significant bits) to fit into
     53   1.1  christos  *	  the appropriate field in the instruction word.
     54   1.1  christos  *	- flags indicating whether
     55   1.1  christos  *		* the relocation involves a symbol
     56   1.1  christos  *		* the relocation is relative to the current position
     57   1.1  christos  *		* the relocation is for a GOT entry
     58   1.1  christos  *		* the relocation is relative to the load address
     59   1.1  christos  *
     60   1.1  christos  */
     61   1.1  christos #define _RF_S		0x80000000		/* Resolve symbol */
     62   1.1  christos #define _RF_A		0x40000000		/* Use addend */
     63   1.1  christos #define _RF_P		0x20000000		/* Location relative */
     64   1.1  christos #define _RF_G		0x10000000		/* GOT offset */
     65   1.1  christos #define _RF_B		0x08000000		/* Load address relative */
     66  1.34    martin #define _RF_U		0x04000000		/* Unaligned */
     67   1.1  christos #define _RF_SZ(s)	(((s) & 0xff) << 8)	/* memory target size */
     68   1.1  christos #define _RF_RS(s)	( (s) & 0xff)		/* right shift */
     69  1.21   mycroft static const int reloc_target_flags[] = {
     70   1.1  christos 	0,							/* NONE */
     71   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(8)  | _RF_RS(0),		/* RELOC_8 */
     72   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(16) | _RF_RS(0),		/* RELOC_16 */
     73   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* RELOC_32 */
     74   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(8)  | _RF_RS(0),		/* DISP_8 */
     75   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(16) | _RF_RS(0),		/* DISP_16 */
     76   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* DISP_32 */
     77   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP_30 */
     78   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WDISP_22 */
     79   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(10),	/* HI22 */
     80   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 22 */
     81   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* 13 */
     82   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* LO10 */
     83   1.1  christos 	_RF_G|			_RF_SZ(32) | _RF_RS(0),		/* GOT10 */
     84   1.1  christos 	_RF_G|			_RF_SZ(32) | _RF_RS(0),		/* GOT13 */
     85   1.1  christos 	_RF_G|			_RF_SZ(32) | _RF_RS(10),	/* GOT22 */
     86   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(0),		/* PC10 */
     87   1.1  christos 	_RF_S|_RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(10),	/* PC22 */
     88   1.1  christos 	      _RF_A|_RF_P|	_RF_SZ(32) | _RF_RS(2),		/* WPLT30 */
     89   1.1  christos 				_RF_SZ(32) | _RF_RS(0),		/* COPY */
     90   1.1  christos 	_RF_S|_RF_A|		_RF_SZ(32) | _RF_RS(0),		/* GLOB_DAT */
     91   1.1  christos 				_RF_SZ(32) | _RF_RS(0),		/* JMP_SLOT */
     92   1.2        pk 	      _RF_A|	_RF_B|	_RF_SZ(32) | _RF_RS(0),		/* RELATIVE */
     93  1.34    martin 	_RF_S|_RF_A|	_RF_U|	_RF_SZ(32) | _RF_RS(0),		/* UA_32 */
     94   1.1  christos };
     95   1.1  christos 
     96   1.1  christos #ifdef RTLD_DEBUG_RELOC
     97   1.1  christos static const char *reloc_names[] = {
     98   1.1  christos 	"NONE", "RELOC_8", "RELOC_16", "RELOC_32", "DISP_8",
     99   1.1  christos 	"DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22",
    100   1.1  christos 	"22", "13", "LO10", "GOT10", "GOT13",
    101   1.1  christos 	"GOT22", "PC10", "PC22", "WPLT30", "COPY",
    102  1.35    martin 	"GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32"
    103   1.1  christos };
    104   1.1  christos #endif
    105   1.1  christos 
    106   1.1  christos #define RELOC_RESOLVE_SYMBOL(t)		((reloc_target_flags[t] & _RF_S) != 0)
    107   1.1  christos #define RELOC_PC_RELATIVE(t)		((reloc_target_flags[t] & _RF_P) != 0)
    108   1.2        pk #define RELOC_BASE_RELATIVE(t)		((reloc_target_flags[t] & _RF_B) != 0)
    109  1.34    martin #define RELOC_UNALIGNED(t)		((reloc_target_flags[t] & _RF_U) != 0)
    110  1.34    martin #define RELOC_USE_ADDEND(t)		((reloc_target_flags[t] & _RF_A) != 0)
    111   1.1  christos #define RELOC_TARGET_SIZE(t)		((reloc_target_flags[t] >> 8) & 0xff)
    112   1.1  christos #define RELOC_VALUE_RIGHTSHIFT(t)	(reloc_target_flags[t] & 0xff)
    113   1.1  christos 
    114  1.21   mycroft static const int reloc_target_bitmask[] = {
    115   1.1  christos #define _BM(x)	(~(-(1ULL << (x))))
    116   1.1  christos 	0,				/* NONE */
    117   1.1  christos 	_BM(8), _BM(16), _BM(32),	/* RELOC_8, _16, _32 */
    118   1.1  christos 	_BM(8), _BM(16), _BM(32),	/* DISP8, DISP16, DISP32 */
    119   1.1  christos 	_BM(30), _BM(22),		/* WDISP30, WDISP22 */
    120   1.1  christos 	_BM(22), _BM(22),		/* HI22, _22 */
    121   1.1  christos 	_BM(13), _BM(10),		/* RELOC_13, _LO10 */
    122   1.1  christos 	_BM(10), _BM(13), _BM(22),	/* GOT10, GOT13, GOT22 */
    123   1.1  christos 	_BM(10), _BM(22),		/* _PC10, _PC22 */
    124   1.1  christos 	_BM(30), 0,			/* _WPLT30, _COPY */
    125   1.4        pk 	-1, -1, -1,			/* _GLOB_DAT, JMP_SLOT, _RELATIVE */
    126  1.35    martin 	_BM(32)				/* _UA32 */
    127   1.1  christos #undef _BM
    128   1.1  christos };
    129   1.1  christos #define RELOC_VALUE_BITMASK(t)	(reloc_target_bitmask[t])
    130   1.1  christos 
    131  1.25   mycroft void _rtld_bind_start(void);
    132  1.24   mycroft void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
    133  1.33     skrll caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
    134  1.36     skrll static inline int _rtld_relocate_plt_object(const Obj_Entry *,
    135  1.36     skrll     const Elf_Rela *, Elf_Addr *);
    136  1.13   mycroft 
    137  1.13   mycroft void
    138  1.13   mycroft _rtld_setup_pltgot(const Obj_Entry *obj)
    139  1.13   mycroft {
    140  1.13   mycroft 	/*
    141  1.13   mycroft 	 * PLTGOT is the PLT on the sparc.
    142  1.13   mycroft 	 * The first entry holds the call the dynamic linker.
    143  1.13   mycroft 	 * We construct a `call' sequence that transfers
    144  1.13   mycroft 	 * to `_rtld_bind_start()'.
    145  1.13   mycroft 	 * The second entry holds the object identification.
    146  1.13   mycroft 	 * Note: each PLT entry is three words long.
    147  1.13   mycroft 	 */
    148  1.30   mycroft #define SAVE	0x9de3bfa0	/* i.e. `save %sp,-96,%sp' */
    149  1.13   mycroft #define CALL	0x40000000
    150  1.13   mycroft #define NOP	0x01000000
    151  1.13   mycroft 	obj->pltgot[0] = SAVE;
    152  1.13   mycroft 	obj->pltgot[1] = CALL |
    153  1.13   mycroft 	    ((Elf_Addr) &_rtld_bind_start - (Elf_Addr) &obj->pltgot[1]) >> 2;
    154  1.13   mycroft 	obj->pltgot[2] = NOP;
    155  1.13   mycroft 	obj->pltgot[3] = (Elf_Addr) obj;
    156  1.13   mycroft }
    157  1.13   mycroft 
    158  1.24   mycroft void
    159  1.33     skrll _rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
    160  1.24   mycroft {
    161  1.24   mycroft 	const Elf_Rela *rela = 0, *relalim;
    162  1.24   mycroft 	Elf_Addr relasz = 0;
    163  1.24   mycroft 	Elf_Addr *where;
    164  1.24   mycroft 
    165  1.24   mycroft 	for (; dynp->d_tag != DT_NULL; dynp++) {
    166  1.24   mycroft 		switch (dynp->d_tag) {
    167  1.24   mycroft 		case DT_RELA:
    168  1.24   mycroft 			rela = (const Elf_Rela *)(relocbase + dynp->d_un.d_ptr);
    169  1.24   mycroft 			break;
    170  1.24   mycroft 		case DT_RELASZ:
    171  1.24   mycroft 			relasz = dynp->d_un.d_val;
    172  1.24   mycroft 			break;
    173  1.24   mycroft 		}
    174  1.24   mycroft 	}
    175  1.42     lukem 	relalim = (const Elf_Rela *)((const uint8_t *)rela + relasz);
    176  1.24   mycroft 	for (; rela < relalim; rela++) {
    177  1.24   mycroft 		where = (Elf_Addr *)(relocbase + rela->r_offset);
    178  1.24   mycroft 		*where += (Elf_Addr)(relocbase + rela->r_addend);
    179  1.24   mycroft 	}
    180  1.24   mycroft }
    181  1.24   mycroft 
    182  1.13   mycroft int
    183  1.44     joerg _rtld_relocate_nonplt_objects(Obj_Entry *obj)
    184   1.1  christos {
    185  1.14   mycroft 	const Elf_Rela *rela;
    186  1.24   mycroft 
    187  1.14   mycroft 	for (rela = obj->rela; rela < obj->relalim; rela++) {
    188  1.14   mycroft 		Elf_Addr *where;
    189  1.14   mycroft 		Elf_Word type, value, mask;
    190  1.14   mycroft 		const Elf_Sym *def = NULL;
    191  1.14   mycroft 		const Obj_Entry *defobj = NULL;
    192  1.15   mycroft 		unsigned long	 symnum;
    193  1.14   mycroft 
    194  1.14   mycroft 		where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
    195  1.15   mycroft 		symnum = ELF_R_SYM(rela->r_info);
    196  1.14   mycroft 
    197  1.14   mycroft 		type = ELF_R_TYPE(rela->r_info);
    198  1.14   mycroft 		if (type == R_TYPE(NONE))
    199  1.17   mycroft 			continue;
    200  1.14   mycroft 
    201  1.27   mycroft 		/* We do JMP_SLOTs in _rtld_bind() below */
    202  1.14   mycroft 		if (type == R_TYPE(JMP_SLOT))
    203  1.17   mycroft 			continue;
    204  1.14   mycroft 
    205  1.14   mycroft 		/* COPY relocs are also handled elsewhere */
    206  1.14   mycroft 		if (type == R_TYPE(COPY))
    207  1.17   mycroft 			continue;
    208   1.1  christos 
    209  1.14   mycroft 		/*
    210  1.14   mycroft 		 * We use the fact that relocation types are an `enum'
    211  1.14   mycroft 		 * Note: R_SPARC_6 is currently numerically largest.
    212  1.14   mycroft 		 */
    213  1.14   mycroft 		if (type > R_TYPE(6))
    214  1.14   mycroft 			return (-1);
    215   1.4        pk 
    216  1.14   mycroft 		value = rela->r_addend;
    217   1.1  christos 
    218  1.14   mycroft 		/*
    219  1.24   mycroft 		 * Handle relative relocs here, as an optimization.
    220  1.14   mycroft 		 */
    221  1.22   mycroft 		if (type == R_TYPE(RELATIVE)) {
    222  1.24   mycroft 			*where += (Elf_Addr)(obj->relocbase + value);
    223  1.26   mycroft 			rdbg(("RELATIVE in %s --> %p", obj->path,
    224  1.24   mycroft 			    (void *)*where));
    225  1.17   mycroft 			continue;
    226  1.14   mycroft 		}
    227   1.1  christos 
    228  1.14   mycroft 		if (RELOC_RESOLVE_SYMBOL(type)) {
    229   1.1  christos 
    230  1.14   mycroft 			/* Find the symbol */
    231  1.15   mycroft 			def = _rtld_find_symdef(symnum, obj, &defobj, false);
    232  1.14   mycroft 			if (def == NULL)
    233  1.14   mycroft 				return (-1);
    234   1.1  christos 
    235  1.14   mycroft 			/* Add in the symbol's absolute address */
    236  1.14   mycroft 			value += (Elf_Word)(defobj->relocbase + def->st_value);
    237  1.14   mycroft 		}
    238   1.1  christos 
    239  1.14   mycroft 		if (RELOC_PC_RELATIVE(type)) {
    240  1.14   mycroft 			value -= (Elf_Word)where;
    241  1.14   mycroft 		}
    242   1.2        pk 
    243  1.14   mycroft 		if (RELOC_BASE_RELATIVE(type)) {
    244  1.14   mycroft 			/*
    245  1.14   mycroft 			 * Note that even though sparcs use `Elf_rela'
    246  1.14   mycroft 			 * exclusively we still need the implicit memory addend
    247  1.14   mycroft 			 * in relocations referring to GOT entries.
    248  1.14   mycroft 			 * Undoubtedly, someone f*cked this up in the distant
    249  1.14   mycroft 			 * past, and now we're stuck with it in the name of
    250  1.14   mycroft 			 * compatibility for all eternity..
    251  1.14   mycroft 			 *
    252  1.14   mycroft 			 * In any case, the implicit and explicit should be
    253  1.14   mycroft 			 * mutually exclusive. We provide a check for that
    254  1.14   mycroft 			 * here.
    255  1.14   mycroft 			 */
    256   1.5        pk #define DIAGNOSTIC
    257   1.5        pk #ifdef DIAGNOSTIC
    258  1.14   mycroft 			if (value != 0 && *where != 0) {
    259  1.14   mycroft 				xprintf("BASE_REL(%s): where=%p, *where 0x%x, "
    260  1.14   mycroft 					"addend=0x%x, base %p\n",
    261  1.14   mycroft 					obj->path, where, *where,
    262  1.14   mycroft 					rela->r_addend, obj->relocbase);
    263  1.14   mycroft 			}
    264  1.14   mycroft #endif
    265  1.14   mycroft 			value += (Elf_Word)(obj->relocbase + *where);
    266   1.5        pk 		}
    267   1.1  christos 
    268  1.14   mycroft 		mask = RELOC_VALUE_BITMASK(type);
    269  1.14   mycroft 		value >>= RELOC_VALUE_RIGHTSHIFT(type);
    270  1.14   mycroft 		value &= mask;
    271  1.14   mycroft 
    272  1.34    martin 		if (RELOC_UNALIGNED(type)) {
    273  1.34    martin 			/* Handle unaligned relocations. */
    274  1.34    martin 			Elf_Addr tmp = 0;
    275  1.34    martin 			char *ptr = (char *)where;
    276  1.34    martin 			int i, size = RELOC_TARGET_SIZE(type)/8;
    277  1.34    martin 
    278  1.34    martin 			/* Read it in one byte at a time. */
    279  1.34    martin 			for (i=0; i<size; i++)
    280  1.34    martin 				tmp = (tmp << 8) | ptr[i];
    281  1.34    martin 
    282  1.34    martin 			tmp &= ~mask;
    283  1.34    martin 			tmp |= value;
    284  1.34    martin 
    285  1.34    martin 			/* Write it back out. */
    286  1.34    martin 			for (i=0; i<size; i++)
    287  1.34    martin 				ptr[i] = ((tmp >> (8*i)) & 0xff);
    288  1.34    martin #ifdef RTLD_DEBUG_RELOC
    289  1.34    martin 			value = (Elf_Word)tmp;
    290  1.34    martin #endif
    291  1.34    martin 
    292  1.34    martin 		} else {
    293  1.34    martin 			*where &= ~mask;
    294  1.34    martin 			*where |= value;
    295  1.34    martin #ifdef RTLD_DEBUG_RELOC
    296  1.34    martin 			value = (Elf_Word)*where;
    297  1.34    martin #endif
    298  1.34    martin 		}
    299   1.1  christos #ifdef RTLD_DEBUG_RELOC
    300  1.14   mycroft 		if (RELOC_RESOLVE_SYMBOL(type)) {
    301  1.26   mycroft 			rdbg(("%s %s in %s --> %p in %s", reloc_names[type],
    302  1.16   mycroft 			    obj->strtab + obj->symtab[symnum].st_name,
    303  1.34    martin 			    obj->path, (void *)value, defobj->path));
    304  1.16   mycroft 		} else {
    305  1.26   mycroft 			rdbg(("%s in %s --> %p", reloc_names[type],
    306  1.34    martin 			    obj->path, (void *)value));
    307  1.14   mycroft 		}
    308  1.14   mycroft #endif
    309   1.1  christos 	}
    310  1.18   mycroft 	return (0);
    311  1.18   mycroft }
    312  1.18   mycroft 
    313  1.18   mycroft int
    314  1.33     skrll _rtld_relocate_plt_lazy(const Obj_Entry *obj)
    315  1.18   mycroft {
    316   1.1  christos 	return (0);
    317  1.27   mycroft }
    318  1.27   mycroft 
    319  1.27   mycroft caddr_t
    320  1.33     skrll _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
    321  1.27   mycroft {
    322  1.42     lukem 	const Elf_Rela *rela = (const Elf_Rela *)((const uint8_t *)obj->pltrela + reloff);
    323  1.35    martin 	Elf_Addr value;
    324  1.35    martin 	int err;
    325  1.35    martin 
    326  1.39       mrg 	value = 0;	/* XXX gcc */
    327  1.39       mrg 
    328  1.45     joerg 	_rtld_shared_enter();
    329  1.35    martin 	err = _rtld_relocate_plt_object(obj, rela, &value);
    330  1.43  christos 	if (err)
    331  1.35    martin 		_rtld_die();
    332  1.45     joerg 	_rtld_shared_exit();
    333  1.35    martin 
    334  1.35    martin 	return (caddr_t)value;
    335  1.35    martin }
    336  1.35    martin 
    337  1.35    martin int
    338  1.35    martin _rtld_relocate_plt_objects(const Obj_Entry *obj)
    339  1.35    martin {
    340  1.35    martin 	const Elf_Rela *rela = obj->pltrela;
    341  1.35    martin 
    342  1.35    martin 	for (; rela < obj->pltrelalim; rela++)
    343  1.35    martin 		if (_rtld_relocate_plt_object(obj, rela, NULL) < 0)
    344  1.35    martin 			return -1;
    345  1.35    martin 
    346  1.35    martin 	return 0;
    347  1.35    martin }
    348  1.35    martin 
    349  1.35    martin static inline int
    350  1.35    martin _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *tp)
    351  1.35    martin {
    352  1.27   mycroft 	const Elf_Sym *def;
    353  1.27   mycroft 	const Obj_Entry *defobj;
    354  1.28   mycroft 	Elf_Word *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
    355  1.27   mycroft 	Elf_Addr value;
    356  1.43  christos 	unsigned long info = rela->r_info;
    357  1.27   mycroft 
    358  1.43  christos 	assert(ELF_R_TYPE(info) == R_TYPE(JMP_SLOT));
    359  1.27   mycroft 
    360  1.43  christos 	def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
    361  1.43  christos 	if (__predict_false(def == NULL))
    362  1.35    martin 		return -1;
    363  1.43  christos 	if (__predict_false(def == &_rtld_sym_zero))
    364  1.43  christos 		return 0;
    365  1.27   mycroft 
    366  1.27   mycroft 	value = (Elf_Addr)(defobj->relocbase + def->st_value);
    367  1.31   mycroft 	rdbg(("bind now/fixup in %s --> new=%p",
    368  1.31   mycroft 	    defobj->strtab + def->st_name, (void *)value));
    369  1.27   mycroft 
    370  1.27   mycroft 	/*
    371  1.27   mycroft 	 * At the PLT entry pointed at by `where', we now construct
    372  1.27   mycroft 	 * a direct transfer to the now fully resolved function
    373  1.27   mycroft 	 * address.  The resulting code in the jump slot is:
    374  1.27   mycroft 	 *
    375  1.27   mycroft 	 *	sethi	%hi(roffset), %g1
    376  1.27   mycroft 	 *	sethi	%hi(addr), %g1
    377  1.27   mycroft 	 *	jmp	%g1+%lo(addr)
    378  1.27   mycroft 	 *
    379  1.27   mycroft 	 * We write the third instruction first, since that leaves the
    380  1.27   mycroft 	 * previous `b,a' at the second word in place. Hence the whole
    381  1.27   mycroft 	 * PLT slot can be atomically change to the new sequence by
    382  1.27   mycroft 	 * writing the `sethi' instruction at word 2.
    383  1.27   mycroft 	 */
    384  1.27   mycroft #define SETHI	0x03000000
    385  1.27   mycroft #define JMP	0x81c06000
    386  1.27   mycroft #define NOP	0x01000000
    387  1.27   mycroft 	where[2] = JMP   | (value & 0x000003ff);
    388  1.27   mycroft 	where[1] = SETHI | ((value >> 10) & 0x003fffff);
    389  1.38     perry 	__asm volatile("iflush %0+8" : : "r" (where));
    390  1.38     perry 	__asm volatile("iflush %0+4" : : "r" (where));
    391  1.27   mycroft 
    392  1.35    martin 	if (tp)
    393  1.35    martin 		*tp = value;
    394  1.35    martin 
    395  1.35    martin 	return 0;
    396   1.1  christos }
    397