Home | History | Annotate | Line # | Download | only in ld.elf_so
reloc.c revision 1.11
      1 /*	$NetBSD: reloc.c,v 1.11 1999/02/24 18:31:00 christos Exp $	 */
      2 
      3 /*
      4  * Copyright 1996 John D. Polstra.
      5  * Copyright 1996 Matt Thomas <matt (at) 3am-software.com>
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by John Polstra.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 /*
     35  * Dynamic linker for ELF.
     36  *
     37  * John Polstra <jdp (at) polstra.com>.
     38  */
     39 
     40 #include <err.h>
     41 #include <errno.h>
     42 #include <fcntl.h>
     43 #include <stdarg.h>
     44 #include <stdio.h>
     45 #include <stdlib.h>
     46 #include <string.h>
     47 #include <unistd.h>
     48 #include <sys/types.h>
     49 #include <sys/mman.h>
     50 #include <dirent.h>
     51 
     52 #include "debug.h"
     53 #include "rtld.h"
     54 
     55 #if defined(__alpha__) || defined(__powerpc__) || defined(__i386__)
     56 /*
     57  * XXX: These don't work for the alpha and i386; don't know about powerpc
     58  *	The alpha and the i386 avoid the problem by compiling everything PIC.
     59  *	These relocation are supposed to be writing the address of the
     60  *	function to be called on the bss.rel or bss.rela segment, but:
     61  *		- st_size == 0
     62  *		- on the i386 at least the call instruction is a direct call
     63  *		  not an indirect call.
     64  */
     65 static int
     66 _rtld_do_copy_relocation(
     67 	const Obj_Entry *dstobj,
     68 	const Elf_RelA *rela,
     69 	bool dodebug)
     70 {
     71 	void           *dstaddr = (void *)(dstobj->relocbase + rela->r_offset);
     72 	const Elf_Sym  *dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
     73 	const char     *name = dstobj->strtab + dstsym->st_name;
     74 	unsigned long   hash = _rtld_elf_hash(name);
     75 	size_t          size = dstsym->st_size;
     76 	const void     *srcaddr;
     77 	const Elf_Sym  *srcsym;
     78 	Obj_Entry      *srcobj;
     79 
     80 	for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next)
     81 		if ((srcsym = _rtld_symlook_obj(name, hash, srcobj,
     82 		    false)) != NULL)
     83 			break;
     84 
     85 	if (srcobj == NULL) {
     86 		_rtld_error("Undefined symbol \"%s\" referenced from COPY"
     87 		    " relocation in %s", name, dstobj->path);
     88 		return -1;
     89 	}
     90 	srcaddr = (const void *)(srcobj->relocbase + srcsym->st_value);
     91 	(void)memcpy(dstaddr, srcaddr, size);
     92 	rdbg(dodebug, "COPY %s %s %s --> src=%p dst=%p *dst= %p size %d",
     93 	    dstobj->path, srcobj->path, name, (void *)srcaddr,
     94 	    (void *)dstaddr, (void *)*(long *)dstaddr, size);
     95 	return 0;
     96 }
     97 #endif /* __alpha__ || __powerpc__ || __i386__ */
     98 
     99 
    100 /*
    101  * Process the special R_xxx_COPY relocations in the main program.  These
    102  * copy data from a shared object into a region in the main program's BSS
    103  * segment.
    104  *
    105  * Returns 0 on success, -1 on failure.
    106  */
    107 int
    108 _rtld_do_copy_relocations(
    109 	const Obj_Entry *dstobj,
    110 	bool dodebug)
    111 {
    112 	assert(dstobj->mainprog);	/* COPY relocations are invalid
    113 					 * elsewhere */
    114 
    115 #if defined(__alpha__) || defined(__powerpc__) || defined(__i386__)
    116 	if (dstobj->rel != NULL) {
    117 		const Elf_Rel  *rel;
    118 		for (rel = dstobj->rel; rel < dstobj->rellim; ++rel) {
    119 			if (ELF_R_TYPE(rel->r_info) == R_TYPE(COPY)) {
    120 				Elf_RelA        ourrela;
    121 				ourrela.r_info = rel->r_info;
    122 				ourrela.r_offset = rel->r_offset;
    123 				ourrela.r_addend = 0;
    124 				if (_rtld_do_copy_relocation(dstobj,
    125 				    &ourrela, dodebug) < 0)
    126 					return -1;
    127 			}
    128 		}
    129 	}
    130 	if (dstobj->rela != NULL) {
    131 		const Elf_RelA *rela;
    132 		for (rela = dstobj->rela; rela < dstobj->relalim; ++rela) {
    133 			if (ELF_R_TYPE(rela->r_info) == R_TYPE(COPY)) {
    134 				if (_rtld_do_copy_relocation(dstobj, rela,
    135 				    dodebug) < 0)
    136 					return -1;
    137 			}
    138 		}
    139 	}
    140 #endif /* __alpha__ || __powerpc__ || __i386__ */
    141 
    142 	return 0;
    143 }
    144 
    145 
    146 #ifndef __sparc__
    147 int
    148 _rtld_relocate_nonplt_object(
    149 	const Obj_Entry * obj,
    150 	const Elf_RelA * rela,
    151 	bool dodebug)
    152 {
    153 	Elf_Addr        *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
    154 	const Elf_Sym   *def;
    155 	const Obj_Entry *defobj;
    156 	extern Elf_Addr  _GLOBAL_OFFSET_TABLE_[];
    157 	extern Elf_Dyn   _DYNAMIC;
    158 	Elf_Addr         tmp;
    159 
    160 	switch (ELF_R_TYPE(rela->r_info)) {
    161 
    162 	case R_TYPE(NONE):
    163 		break;
    164 
    165 #ifdef __i386__
    166 	case R_TYPE(GOT32):
    167 
    168 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    169 		    &defobj, false);
    170 		if (def == NULL)
    171 			return -1;
    172 
    173 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value);
    174 		if (*where != tmp)
    175 			*where = tmp;
    176 		rdbg(dodebug, "GOT32 %s in %s --> %p in %s",
    177 		    defobj->strtab + def->st_name, obj->path,
    178 		    (void *)*where, defobj->path);
    179 		break;
    180 
    181 	case R_TYPE(PC32):
    182 		/*
    183 		 * I don't think the dynamic linker should ever see this
    184 		 * type of relocation.  But the binutils-2.6 tools sometimes
    185 		 * generate it.
    186 		 */
    187 
    188 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    189 		    &defobj, false);
    190 		if (def == NULL)
    191 			return -1;
    192 
    193 		*where += (Elf_Addr)(defobj->relocbase + def->st_value) -
    194 		    (Elf_Addr)where;
    195 		rdbg(dodebug, "PC32 %s in %s --> %p in %s",
    196 		    defobj->strtab + def->st_name, obj->path,
    197 		    (void *)*where, defobj->path);
    198 		break;
    199 
    200 	case R_TYPE(32):
    201 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    202 		    &defobj, false);
    203 		if (def == NULL)
    204 			return -1;
    205 
    206 		*where += (Elf_Addr)(defobj->relocbase + def->st_value);
    207 		rdbg(dodebug, "32 %s in %s --> %p in %s",
    208 		    defobj->strtab + def->st_name, obj->path,
    209 		    (void *)*where, defobj->path);
    210 		break;
    211 #endif /* __i386__ */
    212 
    213 #ifdef __alpha__
    214 	case R_TYPE(REFQUAD):
    215 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    216 		    &defobj, false);
    217 		if (def == NULL)
    218 			return -1;
    219 
    220 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value) +
    221 		    *where + rela->r_addend;
    222 		if (*where != tmp_value)
    223 			*where = tmp_value;
    224 		rdbg(dodebug, "REFQUAD %s in %s --> %p in %s",
    225 		    defobj->strtab + def->st_name, obj->path,
    226 		    (void *)*where, defobj->path);
    227 		break;
    228 #endif /* __alpha__ */
    229 
    230 #if defined(__i386__) || defined(__alpha__)
    231 	case R_TYPE(GLOB_DAT):
    232 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    233 		    &defobj, false);
    234 		if (def == NULL)
    235 			return -1;
    236 
    237 		if (*where != (Elf_Addr)(defobj->relocbase + def->st_value))
    238 			*where = (Elf_Addr)(defobj->relocbase + def->st_value);
    239 		rdbg(dodebug, "GLOB_DAT %s in %s --> %p in %s",
    240 		    defobj->strtab + def->st_name, obj->path,
    241 		    (void *)*where, defobj->path);
    242 		break;
    243 
    244 	case R_TYPE(RELATIVE):
    245 		if (obj != &_rtld_objself ||
    246 		    (caddr_t)where < (caddr_t)_GLOBAL_OFFSET_TABLE_ ||
    247 		    (caddr_t)where >= (caddr_t)&_DYNAMIC) {
    248 			*where += (Elf_Addr)obj->relocbase;
    249 			rdbg(dodebug, "RELATIVE in %s --> %p", obj->path,
    250 			    (void *)*where);
    251 		}
    252 		else
    253 			rdbg(dodebug, "RELATIVE in %s stays at %p",
    254 			    obj->path, (void *)*where);
    255 		break;
    256 
    257 	case R_TYPE(COPY):
    258 		/*
    259 		 * These are deferred until all other relocations have
    260 		 * been done.  All we do here is make sure that the COPY
    261 		 * relocation is not in a shared library.  They are allowed
    262 		 * only in executable files.
    263 		 */
    264 		if (!obj->mainprog) {
    265 			_rtld_error(
    266 			"%s: Unexpected R_COPY relocation in shared library",
    267 			    obj->path);
    268 			return -1;
    269 		}
    270 		rdbg(dodebug, "COPY (avoid in main)");
    271 		break;
    272 #endif /* __i386__ || __alpha__ */
    273 
    274 #ifdef __mips__
    275 	case R_TYPE(REL32):
    276 		/* 32-bit PC-relative reference */
    277 		def = obj->symtab + ELF_R_SYM(rela->r_info);
    278 
    279 		if (ELF_SYM_BIND(def->st_info) == Elf_estb_local &&
    280 		  (ELF_SYM_TYPE(def->st_info) == Elf_estt_section ||
    281 		   ELF_SYM_TYPE(def->st_info) == Elf_estt_notype)) {
    282 			*where += (Elf_Addr)obj->relocbase;
    283 			rdbg(dodebug, "REL32 in %s --> %p", obj->path,
    284 			    (void *)*where);
    285 		} else {
    286 			/* XXX maybe do something re: bootstrapping? */
    287 			def = _rtld_find_symdef(_rtld_objlist, rela->r_info,
    288 			    NULL, obj, &defobj, false);
    289 			if (def == NULL)
    290 				return -1;
    291 			*where += (Elf_Addr)(defobj->relocbase + def->st_value);
    292 			rdbg(dodebug, "REL32 %s in %s --> %p in %s",
    293 			    defobj->strtab + def->st_name, obj->path,
    294 			    (void *)*where, defobj->path);
    295 		}
    296 		break;
    297 
    298 #endif /* __mips__ */
    299 
    300 #ifdef __powerpc__
    301 	case R_TYPE(32):	/* word32 S + A */
    302 	case R_TYPE(GLOB_DAT):	/* word32 S + A */
    303 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    304 		    &defobj, false);
    305 		if (def == NULL)
    306 			return -1;
    307 
    308 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
    309 		    rela->r_addend);
    310 
    311 		if (*where != tmp)
    312 			*where = tmp;
    313 		rdbg(dodebug, "32/GLOB_DAT %s in %s --> %p in %s",
    314 		    defobj->strtab + def->st_name, obj->path,
    315 		    (void *)*where, defobj->path);
    316 		break;
    317 
    318 	case R_TYPE(COPY):
    319 		rdbg(dodebug, "COPY");
    320 		break;
    321 
    322 	case R_TYPE(JMP_SLOT):
    323 		rdbg(dodebug, "JMP_SLOT");
    324 		break;
    325 
    326 	case R_TYPE(RELATIVE):	/* word32 B + A */
    327 		tmp = (Elf_Addr)(obj->relocbase + rela->r_addend);
    328 		if (obj == &_rtld_objself && *where == tmp;
    329 			break;	/* GOT - already done */
    330 
    331 		*where = tmp;
    332 		rdbg(dodebug, "RELATIVE in %s --> %p", obj->path,
    333 		    (void *)*where);
    334 		break;
    335 #endif /* __powerpc__ */
    336 
    337 	default:
    338 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    339 		    &defobj, true);
    340 		rdbg(dodebug, "sym = %lu, type = %lu, offset = %p, "
    341 		    "addend = %p, contents = %p, symbol = %s",
    342 		    (u_long)ELF_R_SYM(rela->r_info),
    343 		    (u_long)ELF_R_TYPE(rela->r_info),
    344 		    (void *)rela->r_offset, (void *)rela->r_addend,
    345 		    (void *)*where,
    346 		    def ? defobj->strtab + def->st_name : "??");
    347 		_rtld_error("%s: Unsupported relocation type %d"
    348 		    "in non-PLT relocations\n",
    349 		    obj->path, ELF_R_TYPE(rela->r_info));
    350 		return -1;
    351 	}
    352 	return 0;
    353 }
    354 
    355 
    356 
    357 int
    358 _rtld_relocate_plt_object(
    359 	const Obj_Entry * obj,
    360 	const Elf_RelA * rela,
    361 	caddr_t *addrp,
    362 	bool bind_now,
    363 	bool dodebug)
    364 {
    365 	Elf_Addr       *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
    366 	Elf_Addr        new_value;
    367 
    368 	/* Fully resolve procedure addresses now */
    369 
    370 #if defined(__powerpc__)
    371 	return _rtld_reloc_powerpc_plt(obj, rela, bind_now);
    372 #endif
    373 
    374 #if defined(__alpha__)	|| defined(__i386__)
    375 	if (bind_now || obj->pltgot == NULL) {
    376 		const Elf_Sym  *def;
    377 		const Obj_Entry *defobj;
    378 
    379 		assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JMP_SLOT));
    380 
    381 		def = _rtld_find_symdef(_rtld_objlist, rela->r_info, NULL, obj,
    382 		    &defobj, true);
    383 		if (def == NULL)
    384 			return -1;
    385 
    386 		new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
    387 		rdbg(dodebug, "bind now %d/fixup in %s --> old=%p new=%p",
    388 		    (int)bind_now,
    389 		    defobj->strtab + def->st_name,
    390 		    (void *)*where, (void *)new_value);
    391 	} else
    392 #endif /* __alpha__ || __i386__ */
    393 	if (!obj->mainprog) {
    394 		/* Just relocate the GOT slots pointing into the PLT */
    395 		new_value = *where + (Elf_Addr)(obj->relocbase);
    396 		rdbg(dodebug, "fixup !main in %s --> %p", obj->path,
    397 		    (void *)*where);
    398 	} else {
    399 		return 0;
    400 	}
    401 	/*
    402          * Since this page is probably copy-on-write, let's not write
    403          * it unless we really really have to.
    404          */
    405 	if (*where != new_value)
    406 		*where = new_value;
    407 	if (addrp != NULL)
    408 		*addrp = *(caddr_t *)(obj->relocbase + rela->r_offset);
    409 	return 0;
    410 }
    411 #endif /* __sparc__ */
    412 
    413 caddr_t
    414 _rtld_bind(
    415 	const Obj_Entry *obj,
    416 	Elf_Word reloff)
    417 {
    418 	const Elf_RelA *rela;
    419 	Elf_RelA        ourrela;
    420 	caddr_t		addr;
    421 
    422 	if (obj->pltrel != NULL) {
    423 		const Elf_Rel *rel;
    424 
    425 		rel = (const Elf_Rel *)((caddr_t) obj->pltrel + reloff);
    426 		ourrela.r_info = rel->r_info;
    427 		ourrela.r_offset = rel->r_offset;
    428 		rela = &ourrela;
    429 	} else {
    430 		rela = (const Elf_RelA *)((caddr_t) obj->pltrela + reloff);
    431 	}
    432 
    433 	if (_rtld_relocate_plt_object(obj, rela, &addr, true, true) < 0)
    434 		_rtld_die();
    435 
    436 	return addr;
    437 }
    438 
    439 /*
    440  * Relocate newly-loaded shared objects.  The argument is a pointer to
    441  * the Obj_Entry for the first such object.  All objects from the first
    442  * to the end of the list of objects are relocated.  Returns 0 on success,
    443  * or -1 on failure.
    444  */
    445 int
    446 _rtld_relocate_objects(
    447 	Obj_Entry * first,
    448 	bool bind_now,
    449 	bool dodebug)
    450 {
    451 	Obj_Entry      *obj;
    452 	int             ok = 1;
    453 
    454 	for (obj = first; obj != NULL; obj = obj->next) {
    455 		if (obj->nbuckets == 0 || obj->nchains == 0
    456 		    || obj->buckets == NULL || obj->symtab == NULL
    457 		    || obj->strtab == NULL) {
    458 			_rtld_error("%s: Shared object has no run-time"
    459 			    " symbol table", obj->path);
    460 			return -1;
    461 		}
    462 		rdbg(dodebug, " relocating %s (%ld/%ld rel/rela, "
    463 		    "%ld/%ld plt rel/rela)",
    464 		    obj->path,
    465 		    (long)(obj->rellim - obj->rel),
    466 		    (long)(obj->relalim - obj->rela),
    467 		    (long)(obj->pltrellim - obj->pltrel),
    468 		    (long)(obj->pltrelalim - obj->pltrela));
    469 
    470 		if (obj->textrel) {
    471 			/*
    472 			 * There are relocations to the write-protected text
    473 			 * segment.
    474 			 */
    475 			if (mprotect(obj->mapbase, obj->textsize,
    476 				PROT_READ | PROT_WRITE | PROT_EXEC) == -1) {
    477 				_rtld_error("%s: Cannot write-enable text "
    478 				    "segment: %s", obj->path, xstrerror(errno));
    479 				return -1;
    480 			}
    481 		}
    482 		if (obj->rel != NULL) {
    483 			/* Process the non-PLT relocations. */
    484 			const Elf_Rel  *rel;
    485 			for (rel = obj->rel; rel < obj->rellim; ++rel) {
    486 				Elf_RelA        ourrela;
    487 				ourrela.r_info = rel->r_info;
    488 				ourrela.r_offset = rel->r_offset;
    489 #if defined(__mips__)
    490 				/* rel->r_offset is not valid on mips? */
    491 				if (ELF_R_TYPE(ourrela.r_info) == R_TYPE(NONE))
    492 					ourrela.r_addend = 0;
    493 				else
    494 #endif
    495 					ourrela.r_addend =
    496 					    *(Elf_Word *)(obj->relocbase +
    497 					    rel->r_offset);
    498 
    499 				if (_rtld_relocate_nonplt_object(obj, &ourrela,
    500 				    dodebug) < 0)
    501 					ok = 0;
    502 			}
    503 		}
    504 		if (obj->rela != NULL) {
    505 			/* Process the non-PLT relocations. */
    506 			const Elf_RelA *rela;
    507 			for (rela = obj->rela; rela < obj->relalim; ++rela) {
    508 				if (_rtld_relocate_nonplt_object(obj, rela,
    509 				    dodebug) < 0)
    510 					ok = 0;
    511 			}
    512 		}
    513 		if (obj->textrel) {	/* Re-protected the text segment. */
    514 			if (mprotect(obj->mapbase, obj->textsize,
    515 				     PROT_READ | PROT_EXEC) == -1) {
    516 				_rtld_error("%s: Cannot write-protect text "
    517 				    "segment: %s", obj->path, xstrerror(errno));
    518 				return -1;
    519 			}
    520 		}
    521 		/* Process the PLT relocations. */
    522 		if (obj->pltrel != NULL) {
    523 			const Elf_Rel  *rel;
    524 			for (rel = obj->pltrel; rel < obj->pltrellim; ++rel) {
    525 				Elf_RelA        ourrela;
    526 				ourrela.r_info = rel->r_info;
    527 				ourrela.r_offset = rel->r_offset;
    528 				ourrela.r_addend =
    529 				    *(Elf_Word *)(obj->relocbase +
    530 				    rel->r_offset);
    531 				if (_rtld_relocate_plt_object(obj, &ourrela,
    532 				    NULL, bind_now, dodebug) < 0)
    533 					ok = 0;
    534 			}
    535 		}
    536 		if (obj->pltrela != NULL) {
    537 			const Elf_RelA *rela;
    538 			for (rela = obj->pltrela; rela < obj->pltrelalim;
    539 			    ++rela) {
    540 				if (_rtld_relocate_plt_object(obj, rela,
    541 				    NULL, bind_now, dodebug) < 0)
    542 					ok = 0;
    543 			}
    544 		}
    545 		if (!ok)
    546 			return -1;
    547 
    548 
    549 		/* Set some sanity-checking numbers in the Obj_Entry. */
    550 		obj->magic = RTLD_MAGIC;
    551 		obj->version = RTLD_VERSION;
    552 
    553 		/* Fill in the dynamic linker entry points. */
    554 		obj->dlopen = _rtld_dlopen;
    555 		obj->dlsym = _rtld_dlsym;
    556 		obj->dlerror = _rtld_dlerror;
    557 		obj->dlclose = _rtld_dlclose;
    558 
    559 		/* Set the special PLTGOT entries. */
    560 		if (obj->pltgot != NULL) {
    561 #if defined(__i386__)
    562 			obj->pltgot[1] = (Elf_Addr) obj;
    563 			obj->pltgot[2] = (Elf_Addr) & _rtld_bind_start;
    564 #endif
    565 #if defined(__alpha__)
    566 			/*
    567 			 * This function will be called to perform the
    568 			 * relocation.
    569 			 */
    570 			obj->pltgot[2] = (Elf_Addr) & _rtld_bind_start;
    571 			/* Identify this shared object */
    572 			obj->pltgot[3] = (Elf_Addr) obj;
    573 #endif
    574 #if defined(__mips__)
    575 			_rtld_relocate_mips_got(obj);
    576 
    577 			obj->pltgot[0] = (Elf_Addr) & _rtld_bind_start;
    578 			/* XXX only if obj->pltgot[1] & 0x80000000 ?? */
    579 			obj->pltgot[1] |= (Elf_Addr) obj;
    580 #endif
    581 #if defined(__powerpc__)
    582 			_rtld_setup_powerpc_plt(obj);
    583 #endif
    584 #if defined(__sparc__)
    585 			/*
    586 			 * PLTGOT is the PLT on the sparc.
    587 			 * The first entry holds the call the dynamic linker.
    588 			 * We construct a `call' instruction that transfers
    589 			 * to `_rtld_bind_start()'.
    590 			 * The second entry holds the object identification.
    591 			 * Note: each PLT entry is three words long.
    592 			 */
    593 			obj->pltgot[1] = 0x40000000 |
    594 			    ((Elf_Addr)&_rtld_bind_start -
    595 			    (Elf_Addr)&obj->pltgot[1]);
    596 			obj->pltgot[3] = (Elf_Addr) obj;
    597 #endif
    598 		}
    599 	}
    600 
    601 	return 0;
    602 }
    603