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