Home | History | Annotate | Line # | Download | only in ld.elf_so
      1  1.120  riastrad /*	$NetBSD: reloc.c,v 1.120 2025/05/02 23:03:16 riastradh Exp $	 */
      2    1.1       cgd 
      3    1.1       cgd /*
      4    1.1       cgd  * Copyright 1996 John D. Polstra.
      5    1.1       cgd  * Copyright 1996 Matt Thomas <matt (at) 3am-software.com>
      6    1.1       cgd  * All rights reserved.
      7    1.1       cgd  *
      8    1.1       cgd  * Redistribution and use in source and binary forms, with or without
      9    1.1       cgd  * modification, are permitted provided that the following conditions
     10    1.1       cgd  * are met:
     11    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     12    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     13    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     15    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     16    1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     17    1.1       cgd  *    must display the following acknowledgement:
     18    1.1       cgd  *      This product includes software developed by John Polstra.
     19    1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     20    1.1       cgd  *    derived from this software without specific prior written permission.
     21    1.1       cgd  *
     22    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23    1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24    1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25    1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26    1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27    1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28    1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29    1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30    1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31    1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32    1.1       cgd  */
     33    1.1       cgd 
     34    1.1       cgd /*
     35    1.1       cgd  * Dynamic linker for ELF.
     36    1.1       cgd  *
     37    1.1       cgd  * John Polstra <jdp (at) polstra.com>.
     38    1.1       cgd  */
     39    1.1       cgd 
     40   1.85     skrll #include <sys/cdefs.h>
     41   1.85     skrll #ifndef lint
     42  1.120  riastrad __RCSID("$NetBSD: reloc.c,v 1.120 2025/05/02 23:03:16 riastradh Exp $");
     43   1.85     skrll #endif /* not lint */
     44   1.85     skrll 
     45    1.1       cgd #include <err.h>
     46    1.1       cgd #include <errno.h>
     47    1.1       cgd #include <fcntl.h>
     48    1.1       cgd #include <stdarg.h>
     49    1.1       cgd #include <stdio.h>
     50    1.1       cgd #include <stdlib.h>
     51    1.1       cgd #include <string.h>
     52    1.1       cgd #include <unistd.h>
     53    1.1       cgd #include <sys/types.h>
     54    1.1       cgd #include <sys/mman.h>
     55  1.102     joerg #include <sys/bitops.h>
     56    1.1       cgd #include <dirent.h>
     57    1.1       cgd 
     58    1.1       cgd #include "debug.h"
     59  1.118  riastrad #include "hash.h"
     60    1.1       cgd #include "rtld.h"
     61    1.1       cgd 
     62   1.14        pk #ifndef RTLD_INHIBIT_COPY_RELOCS
     63   1.80     skrll static int _rtld_do_copy_relocation(const Obj_Entry *, const Elf_Rela *);
     64   1.16  christos 
     65    1.1       cgd static int
     66   1.80     skrll _rtld_do_copy_relocation(const Obj_Entry *dstobj, const Elf_Rela *rela)
     67    1.1       cgd {
     68   1.11  christos 	void           *dstaddr = (void *)(dstobj->relocbase + rela->r_offset);
     69   1.11  christos 	const Elf_Sym  *dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
     70   1.11  christos 	const char     *name = dstobj->strtab + dstsym->st_name;
     71  1.115     kamil 	Elf_Hash        hash;
     72   1.11  christos 	size_t          size = dstsym->st_size;
     73   1.11  christos 	const void     *srcaddr;
     74   1.37      matt 	const Elf_Sym  *srcsym = NULL;
     75   1.11  christos 	Obj_Entry      *srcobj;
     76   1.11  christos 
     77  1.115     kamil 	hash.sysv = _rtld_sysv_hash(name);
     78  1.115     kamil 	hash.gnu = _rtld_gnu_hash(name);
     79  1.115     kamil 
     80  1.110       uwe 	if (__predict_false(size == 0)) {
     81  1.110       uwe #if defined(__powerpc__) && !defined(__LP64) /* PR port-macppc/47464 */
     82  1.110       uwe 		if (strcmp(name, "_SDA_BASE_") == 0
     83  1.110       uwe 		    || strcmp(name, "_SDA2_BASE_") == 0)
     84  1.110       uwe 		{
     85  1.110       uwe 			rdbg(("COPY %s %s --> ignoring old binutils bug",
     86  1.110       uwe 			      dstobj->path, name));
     87  1.110       uwe 			return 0;
     88  1.110       uwe 		}
     89  1.110       uwe #endif
     90  1.110       uwe #if 0 /* shall we warn? */
     91  1.110       uwe 		xwarnx("%s: zero size COPY relocation for \"%s\"",
     92  1.110       uwe 		       dstobj->path, name);
     93  1.110       uwe #endif
     94  1.110       uwe 	}
     95  1.110       uwe 
     96  1.104    nonaka 	for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next) {
     97  1.115     kamil 		srcsym = _rtld_symlook_obj(name, &hash, srcobj, 0,
     98  1.104    nonaka 		    _rtld_fetch_ventry(dstobj, ELF_R_SYM(rela->r_info)));
     99  1.104    nonaka 		if (srcsym != NULL)
    100   1.11  christos 			break;
    101  1.104    nonaka 	}
    102   1.11  christos 
    103   1.11  christos 	if (srcobj == NULL) {
    104   1.11  christos 		_rtld_error("Undefined symbol \"%s\" referenced from COPY"
    105   1.11  christos 		    " relocation in %s", name, dstobj->path);
    106   1.14        pk 		return (-1);
    107   1.11  christos 	}
    108   1.11  christos 	srcaddr = (const void *)(srcobj->relocbase + srcsym->st_value);
    109   1.84    petrov 	rdbg(("COPY %s %s %s --> src=%p dst=%p size %ld",
    110   1.98  christos 	    dstobj->path, srcobj->path, name, srcaddr,
    111   1.84    petrov 	    (void *)dstaddr, (long)size));
    112  1.114  christos 	(void)memcpy(dstaddr, srcaddr, size);
    113   1.14        pk 	return (0);
    114    1.1       cgd }
    115   1.14        pk #endif /* RTLD_INHIBIT_COPY_RELOCS */
    116   1.11  christos 
    117   1.11  christos 
    118    1.1       cgd /*
    119    1.1       cgd  * Process the special R_xxx_COPY relocations in the main program.  These
    120    1.1       cgd  * copy data from a shared object into a region in the main program's BSS
    121    1.1       cgd  * segment.
    122    1.1       cgd  *
    123    1.1       cgd  * Returns 0 on success, -1 on failure.
    124    1.1       cgd  */
    125    1.1       cgd int
    126   1.80     skrll _rtld_do_copy_relocations(const Obj_Entry *dstobj)
    127    1.1       cgd {
    128   1.14        pk #ifndef RTLD_INHIBIT_COPY_RELOCS
    129   1.14        pk 
    130   1.14        pk 	/* COPY relocations are invalid elsewhere */
    131   1.64   mycroft 	assert(!dstobj->isdynamic);
    132    1.1       cgd 
    133   1.11  christos 	if (dstobj->rel != NULL) {
    134   1.11  christos 		const Elf_Rel  *rel;
    135   1.11  christos 		for (rel = dstobj->rel; rel < dstobj->rellim; ++rel) {
    136   1.11  christos 			if (ELF_R_TYPE(rel->r_info) == R_TYPE(COPY)) {
    137   1.35    kleink 				Elf_Rela        ourrela;
    138   1.11  christos 				ourrela.r_info = rel->r_info;
    139   1.11  christos 				ourrela.r_offset = rel->r_offset;
    140   1.11  christos 				ourrela.r_addend = 0;
    141   1.11  christos 				if (_rtld_do_copy_relocation(dstobj,
    142   1.66   mycroft 				    &ourrela) < 0)
    143   1.14        pk 					return (-1);
    144   1.11  christos 			}
    145   1.11  christos 		}
    146   1.11  christos 	}
    147   1.11  christos 	if (dstobj->rela != NULL) {
    148   1.35    kleink 		const Elf_Rela *rela;
    149   1.11  christos 		for (rela = dstobj->rela; rela < dstobj->relalim; ++rela) {
    150   1.11  christos 			if (ELF_R_TYPE(rela->r_info) == R_TYPE(COPY)) {
    151   1.66   mycroft 				if (_rtld_do_copy_relocation(dstobj, rela) < 0)
    152   1.14        pk 					return (-1);
    153   1.11  christos 			}
    154   1.11  christos 		}
    155    1.1       cgd 	}
    156  1.114  christos #ifdef GNU_RELRO
    157  1.119  riastrad 	/*
    158  1.119  riastrad 	 * If the main program is lazily bound (default -- whether or
    159  1.119  riastrad 	 * not LD_BINDNOW is set in the calling environment), we are
    160  1.119  riastrad 	 * now done writing to anything covered by RELRO and we can
    161  1.119  riastrad 	 * safely make it read-only.  There may still be ifunc
    162  1.119  riastrad 	 * resolution to do later; it will happen in a read/write
    163  1.119  riastrad 	 * segment and will not be made read-only.
    164  1.119  riastrad 	 *
    165  1.119  riastrad 	 * But if the main program is eagerly bound (i.e., the object
    166  1.119  riastrad 	 * has DF_1_NOW set in DT_FLAGS_1, whether or not LD_BIND_NOW
    167  1.119  riastrad 	 * is set in the calling environment), we delay protecting the
    168  1.119  riastrad 	 * RELRO region as read-only until we have resolved ifuncs --
    169  1.119  riastrad 	 * at which point we will make the ifunc resolution read-only
    170  1.119  riastrad 	 * too.
    171  1.119  riastrad 	 */
    172  1.119  riastrad 	if (!dstobj->z_now && _rtld_relro(dstobj, true) == -1)
    173  1.114  christos 		return -1;
    174  1.114  christos #endif
    175   1.14        pk #endif /* RTLD_INHIBIT_COPY_RELOCS */
    176    1.1       cgd 
    177   1.14        pk 	return (0);
    178    1.1       cgd }
    179    1.9        pk 
    180    1.1       cgd /*
    181  1.120  riastrad  * _rtld_relocate_relr(obj)
    182  1.120  riastrad  *
    183  1.120  riastrad  *	Relocate the RELR entries of obj.  The RELR table is encoded as
    184  1.120  riastrad  *	a sequence of alternating addresses and bitmaps.  Each address
    185  1.120  riastrad  *	entry has the low-order bit clear, and each bitmap has the
    186  1.120  riastrad  *	low-order bit set:
    187  1.120  riastrad  *
    188  1.120  riastrad  *		AAAAAAA0
    189  1.120  riastrad  *		BBBBBBB1
    190  1.120  riastrad  *		BBBBBBB1
    191  1.120  riastrad  *		BBBBBBB1
    192  1.120  riastrad  *		AAAAAAA0
    193  1.120  riastrad  *		BBBBBBB1
    194  1.120  riastrad  *		...
    195  1.120  riastrad  *
    196  1.120  riastrad  *	Each address A is taken relative to obj->relocbase, and has
    197  1.120  riastrad  *	obj->relocbase added to the Elf_Addr it points at.  For each
    198  1.120  riastrad  *	bit i in the following bitmaps concatenated starting at 1,
    199  1.120  riastrad  *	excluding the low-order bit used to distinguish bitmaps from
    200  1.120  riastrad  *	addresses, the Elf_Addr at the address
    201  1.120  riastrad  *
    202  1.120  riastrad  *		A + sizeof(Elf_Addr)*i
    203  1.120  riastrad  *
    204  1.120  riastrad  *	(again, relative to obj->relocbase) has obj->relocbase added
    205  1.120  riastrad  *	too.
    206  1.120  riastrad  *
    207  1.120  riastrad  *	DT_RELR relocations are processed before any DT_REL or DT_RELA
    208  1.120  riastrad  *	relocations.
    209  1.120  riastrad  *
    210  1.120  riastrad  *	References:
    211  1.120  riastrad  *
    212  1.120  riastrad  *	Rahul Chaudhry, `Re: Proposal for a new section type SHT_RELR',
    213  1.120  riastrad  *	generic-abi mailing list, 2018-02-07.
    214  1.120  riastrad  *
    215  1.120  riastrad  *	https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/Jnz1lgLJAgAJ
    216  1.120  riastrad  *	https://web.archive.org/web/20241213012330/https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/Jnz1lgLJAgAJ
    217  1.120  riastrad  */
    218  1.120  riastrad static void
    219  1.120  riastrad _rtld_relocate_relr(Obj_Entry *obj)
    220  1.120  riastrad {
    221  1.120  riastrad 	const Elf_Relr *relr;
    222  1.120  riastrad 
    223  1.120  riastrad 	if (obj->relr == obj->relrlim)
    224  1.120  riastrad 		return;
    225  1.120  riastrad 
    226  1.120  riastrad 	for (relr = obj->relr; relr < obj->relrlim;) {
    227  1.120  riastrad 		Elf_Addr *where;
    228  1.120  riastrad 
    229  1.120  riastrad 		/*
    230  1.120  riastrad 		 * At an address entry.  Relocate the address.
    231  1.120  riastrad 		 */
    232  1.120  riastrad 		assert((*relr & 1) == 0);
    233  1.120  riastrad 		where = (Elf_Addr *)(obj->relocbase + *relr);
    234  1.120  riastrad 		*where++ += (Elf_Addr)obj->relocbase;
    235  1.120  riastrad 
    236  1.120  riastrad 		/*
    237  1.120  riastrad 		 * Process every bitmap entry after the address.
    238  1.120  riastrad 		 */
    239  1.120  riastrad 		while (++relr < obj->relrlim && *relr & 1) {
    240  1.120  riastrad 			unsigned i;
    241  1.120  riastrad 
    242  1.120  riastrad 			/*
    243  1.120  riastrad 			 * Process every set bit in the bitmap.  Note
    244  1.120  riastrad 			 * that the first bit (i=0) is not processed
    245  1.120  riastrad 			 * here -- it's just metadata to mark a bitmap
    246  1.120  riastrad 			 * entry.
    247  1.120  riastrad 			 */
    248  1.120  riastrad 			for (i = 1; i < CHAR_BIT*sizeof(*relr); i++, where++) {
    249  1.120  riastrad 				if (*relr & ((Elf_Relr)1 << i))
    250  1.120  riastrad 					*where += (Elf_Addr)obj->relocbase;
    251  1.120  riastrad 			}
    252  1.120  riastrad 		}
    253  1.120  riastrad 	}
    254  1.120  riastrad }
    255  1.120  riastrad 
    256  1.120  riastrad /*
    257    1.1       cgd  * Relocate newly-loaded shared objects.  The argument is a pointer to
    258    1.1       cgd  * the Obj_Entry for the first such object.  All objects from the first
    259    1.1       cgd  * to the end of the list of objects are relocated.  Returns 0 on success,
    260    1.1       cgd  * or -1 on failure.
    261    1.1       cgd  */
    262    1.1       cgd int
    263   1.80     skrll _rtld_relocate_objects(Obj_Entry *first, bool bind_now)
    264    1.1       cgd {
    265   1.16  christos 	Obj_Entry *obj;
    266   1.77   mycroft 	int ok = 1;
    267    1.1       cgd 
    268   1.11  christos 	for (obj = first; obj != NULL; obj = obj->next) {
    269  1.116     kamil 		if ((!obj->sysv_hash && !obj->gnu_hash) ||
    270  1.116     kamil 		    obj->symtab == NULL || obj->strtab == NULL) {
    271   1.11  christos 			_rtld_error("%s: Shared object has no run-time"
    272   1.11  christos 			    " symbol table", obj->path);
    273   1.11  christos 			return -1;
    274   1.11  christos 		}
    275  1.102     joerg 		if (obj->nbuckets == UINT32_MAX) {
    276  1.102     joerg 			_rtld_error("%s: Symbol table too large", obj->path);
    277  1.102     joerg 			return -1;
    278  1.102     joerg 		}
    279   1.66   mycroft 		rdbg((" relocating %s (%ld/%ld rel/rela, %ld/%ld plt rel/rela)",
    280   1.11  christos 		    obj->path,
    281   1.11  christos 		    (long)(obj->rellim - obj->rel),
    282   1.11  christos 		    (long)(obj->relalim - obj->rela),
    283   1.11  christos 		    (long)(obj->pltrellim - obj->pltrel),
    284   1.16  christos 		    (long)(obj->pltrelalim - obj->pltrela)));
    285   1.11  christos 
    286   1.11  christos 		if (obj->textrel) {
    287  1.108  christos 			xwarnx("%s: text relocations", obj->path);
    288   1.11  christos 			/*
    289   1.11  christos 			 * There are relocations to the write-protected text
    290   1.11  christos 			 * segment.
    291   1.11  christos 			 */
    292   1.11  christos 			if (mprotect(obj->mapbase, obj->textsize,
    293  1.108  christos 				PROT_READ | PROT_WRITE) == -1) {
    294   1.11  christos 				_rtld_error("%s: Cannot write-enable text "
    295   1.11  christos 				    "segment: %s", obj->path, xstrerror(errno));
    296   1.11  christos 				return -1;
    297   1.11  christos 			}
    298   1.11  christos 		}
    299  1.120  riastrad 		dbg(("doing relative relocations"));
    300  1.120  riastrad 		_rtld_relocate_relr(obj);
    301   1.71   mycroft 		dbg(("doing non-PLT relocations"));
    302   1.76  junyoung 		if (_rtld_relocate_nonplt_objects(obj) < 0)
    303   1.77   mycroft 			ok = 0;
    304   1.11  christos 		if (obj->textrel) {	/* Re-protected the text segment. */
    305   1.11  christos 			if (mprotect(obj->mapbase, obj->textsize,
    306   1.11  christos 				     PROT_READ | PROT_EXEC) == -1) {
    307   1.11  christos 				_rtld_error("%s: Cannot write-protect text "
    308   1.11  christos 				    "segment: %s", obj->path, xstrerror(errno));
    309   1.11  christos 				return -1;
    310   1.11  christos 			}
    311   1.11  christos 		}
    312   1.71   mycroft 		dbg(("doing lazy PLT binding"));
    313   1.76  junyoung 		if (_rtld_relocate_plt_lazy(obj) < 0)
    314   1.77   mycroft 			ok = 0;
    315  1.103     skrll 		if (obj->z_now || bind_now) {
    316   1.82     skrll 			dbg(("doing immediate PLT binding"));
    317   1.76  junyoung 			if (_rtld_relocate_plt_objects(obj) < 0)
    318   1.77   mycroft 				ok = 0;
    319   1.82     skrll 		}
    320   1.77   mycroft 		if (!ok)
    321   1.77   mycroft 			return -1;
    322   1.77   mycroft 
    323   1.71   mycroft 		dbg(("fixing up PLTGOT"));
    324   1.11  christos 		/* Set the special PLTGOT entries. */
    325   1.53   mycroft 		if (obj->pltgot != NULL)
    326   1.53   mycroft 			_rtld_setup_pltgot(obj);
    327  1.109  christos #ifdef GNU_RELRO
    328  1.114  christos 		if (_rtld_relro(obj, false) == -1)
    329  1.114  christos 			return -1;
    330  1.109  christos #endif
    331    1.1       cgd 	}
    332   1.11  christos 	return 0;
    333    1.1       cgd }
    334  1.107     joerg 
    335  1.107     joerg Elf_Addr
    336  1.107     joerg _rtld_resolve_ifunc(const Obj_Entry *obj, const Elf_Sym *def)
    337  1.107     joerg {
    338  1.107     joerg 	Elf_Addr target;
    339  1.107     joerg 
    340  1.107     joerg 	_rtld_shared_exit();
    341  1.111     joerg 	target = _rtld_resolve_ifunc2(obj,
    342  1.107     joerg 	    (Elf_Addr)obj->relocbase + def->st_value);
    343  1.107     joerg 	_rtld_shared_enter();
    344  1.111     joerg 	return target;
    345  1.111     joerg }
    346  1.111     joerg 
    347  1.111     joerg Elf_Addr
    348  1.111     joerg _rtld_resolve_ifunc2(const Obj_Entry *obj, Elf_Addr addr)
    349  1.111     joerg {
    350  1.111     joerg 	Elf_Addr target;
    351  1.111     joerg 
    352  1.111     joerg 	target = _rtld_call_function_addr(obj, addr);
    353  1.107     joerg 
    354  1.107     joerg 	return target;
    355  1.107     joerg }
    356  1.112     joerg 
    357  1.117     skrll #if \
    358  1.117     skrll     !defined(RTLD_COMMON_CALL_IFUNC_RELA) && \
    359  1.117     skrll     !defined(RTLD_COMMON_CALL_IFUNC_REL) && \
    360  1.117     skrll     !defined(RTLD_ARCH_CALL_IFUNC)
    361  1.117     skrll void
    362  1.117     skrll _rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
    363  1.117     skrll {
    364  1.117     skrll }
    365  1.117     skrll #endif
    366  1.117     skrll 
    367  1.112     joerg #ifdef RTLD_COMMON_CALL_IFUNC_RELA
    368  1.112     joerg #  ifdef __sparc__
    369  1.112     joerg #  include <machine/elf_support.h>
    370  1.112     joerg #  endif
    371  1.112     joerg 
    372  1.112     joerg void
    373  1.112     joerg _rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
    374  1.112     joerg {
    375  1.112     joerg 	const Elf_Rela *rela;
    376  1.112     joerg 	Elf_Addr *where;
    377  1.112     joerg #ifdef __sparc__
    378  1.112     joerg 	Elf_Word *where2;
    379  1.112     joerg #endif
    380  1.112     joerg 	Elf_Addr target;
    381  1.112     joerg 
    382  1.112     joerg 	while (obj->ifunc_remaining > 0 && _rtld_objgen == cur_objgen) {
    383  1.112     joerg 		rela = obj->pltrelalim - obj->ifunc_remaining--;
    384  1.112     joerg #ifdef __sparc__
    385  1.112     joerg #define PLT_IRELATIVE R_TYPE(JMP_IREL)
    386  1.112     joerg #else
    387  1.112     joerg #define PLT_IRELATIVE R_TYPE(IRELATIVE)
    388  1.112     joerg #endif
    389  1.112     joerg 		if (ELF_R_TYPE(rela->r_info) != PLT_IRELATIVE)
    390  1.112     joerg 			continue;
    391  1.112     joerg #ifdef __sparc__
    392  1.112     joerg 		where2 = (Elf_Word *)(obj->relocbase + rela->r_offset);
    393  1.112     joerg #else
    394  1.112     joerg 		where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
    395  1.112     joerg #endif
    396  1.112     joerg 		target = (Elf_Addr)(obj->relocbase + rela->r_addend);
    397  1.112     joerg 		_rtld_exclusive_exit(mask);
    398  1.112     joerg 		target = _rtld_resolve_ifunc2(obj, target);
    399  1.112     joerg 		_rtld_exclusive_enter(mask);
    400  1.112     joerg #ifdef __sparc__
    401  1.112     joerg 		sparc_write_branch(where2 + 1, (void *)target);
    402  1.112     joerg #else
    403  1.112     joerg 		if (*where != target)
    404  1.112     joerg 			*where = target;
    405  1.112     joerg #endif
    406  1.112     joerg 	}
    407  1.112     joerg 
    408  1.112     joerg 	while (obj->ifunc_remaining_nonplt > 0 && _rtld_objgen == cur_objgen) {
    409  1.112     joerg 		rela = obj->relalim - obj->ifunc_remaining_nonplt--;
    410  1.112     joerg 		if (ELF_R_TYPE(rela->r_info) != R_TYPE(IRELATIVE))
    411  1.112     joerg 			continue;
    412  1.112     joerg 		where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
    413  1.112     joerg 		target = (Elf_Addr)(obj->relocbase + rela->r_addend);
    414  1.112     joerg 		_rtld_exclusive_exit(mask);
    415  1.112     joerg 		target = _rtld_resolve_ifunc2(obj, target);
    416  1.112     joerg 		_rtld_exclusive_enter(mask);
    417  1.112     joerg 		if (*where != target)
    418  1.112     joerg 			*where = target;
    419  1.112     joerg 	}
    420  1.112     joerg }
    421  1.112     joerg #endif
    422  1.112     joerg 
    423  1.112     joerg #ifdef RTLD_COMMON_CALL_IFUNC_REL
    424  1.112     joerg void
    425  1.112     joerg _rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
    426  1.112     joerg {
    427  1.112     joerg 	const Elf_Rel *rel;
    428  1.112     joerg 	Elf_Addr *where, target;
    429  1.112     joerg 
    430  1.112     joerg 	while (obj->ifunc_remaining > 0 && _rtld_objgen == cur_objgen) {
    431  1.112     joerg 		rel = obj->pltrellim - obj->ifunc_remaining;
    432  1.112     joerg 		--obj->ifunc_remaining;
    433  1.112     joerg 		if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE)) {
    434  1.112     joerg 			where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
    435  1.112     joerg 			_rtld_exclusive_exit(mask);
    436  1.112     joerg 			target = _rtld_resolve_ifunc2(obj, *where);
    437  1.112     joerg 			_rtld_exclusive_enter(mask);
    438  1.112     joerg 			if (*where != target)
    439  1.112     joerg 				*where = target;
    440  1.112     joerg 		}
    441  1.112     joerg 	}
    442  1.112     joerg 
    443  1.112     joerg 	while (obj->ifunc_remaining_nonplt > 0 && _rtld_objgen == cur_objgen) {
    444  1.112     joerg 		rel = obj->rellim - obj->ifunc_remaining_nonplt--;
    445  1.112     joerg 		if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE)) {
    446  1.112     joerg 			where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
    447  1.112     joerg 			_rtld_exclusive_exit(mask);
    448  1.112     joerg 			target = _rtld_resolve_ifunc2(obj, *where);
    449  1.112     joerg 			_rtld_exclusive_enter(mask);
    450  1.112     joerg 			if (*where != target)
    451  1.112     joerg 				*where = target;
    452  1.112     joerg 		}
    453  1.112     joerg 	}
    454  1.112     joerg }
    455  1.112     joerg #endif
    456