xref: /onnv-gate/usr/src/cmd/sgs/rtld/i386/i386_elf.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
24*0Sstevel@tonic-gate  *	  All Rights Reserved
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  *
27*0Sstevel@tonic-gate  *	Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  *	Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * x86 machine dependent and ELF file class dependent functions.
34*0Sstevel@tonic-gate  * Contains routines for performing function binding and symbol relocations.
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate #include	"_synonyms.h"
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include	<stdio.h>
39*0Sstevel@tonic-gate #include	<sys/elf.h>
40*0Sstevel@tonic-gate #include	<sys/elf_386.h>
41*0Sstevel@tonic-gate #include	<sys/mman.h>
42*0Sstevel@tonic-gate #include	<dlfcn.h>
43*0Sstevel@tonic-gate #include	<synch.h>
44*0Sstevel@tonic-gate #include	<string.h>
45*0Sstevel@tonic-gate #include	"_rtld.h"
46*0Sstevel@tonic-gate #include	"_audit.h"
47*0Sstevel@tonic-gate #include	"_elf.h"
48*0Sstevel@tonic-gate #include	"msg.h"
49*0Sstevel@tonic-gate #include	"debug.h"
50*0Sstevel@tonic-gate #include	"reloc.h"
51*0Sstevel@tonic-gate #include	"conv.h"
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate extern void	elf_rtbndr(Rt_map *, ulong_t, caddr_t);
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate int
57*0Sstevel@tonic-gate elf_mach_flags_check(Rej_desc *rej, Ehdr *ehdr)
58*0Sstevel@tonic-gate {
59*0Sstevel@tonic-gate 	/*
60*0Sstevel@tonic-gate 	 * Check machine type and flags.
61*0Sstevel@tonic-gate 	 */
62*0Sstevel@tonic-gate 	if (ehdr->e_flags != 0) {
63*0Sstevel@tonic-gate 		rej->rej_type = SGS_REJ_BADFLAG;
64*0Sstevel@tonic-gate 		rej->rej_info = (uint_t)ehdr->e_flags;
65*0Sstevel@tonic-gate 		return (0);
66*0Sstevel@tonic-gate 	}
67*0Sstevel@tonic-gate 	return (1);
68*0Sstevel@tonic-gate }
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate void
71*0Sstevel@tonic-gate ldso_plt_init(Rt_map * lmp)
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate 	/*
74*0Sstevel@tonic-gate 	 * There is no need to analyze ld.so because we don't map in any of
75*0Sstevel@tonic-gate 	 * its dependencies.  However we may map these dependencies in later
76*0Sstevel@tonic-gate 	 * (as if ld.so had dlopened them), so initialize the plt and the
77*0Sstevel@tonic-gate 	 * permission information.
78*0Sstevel@tonic-gate 	 */
79*0Sstevel@tonic-gate 	if (PLTGOT(lmp))
80*0Sstevel@tonic-gate 		elf_plt_init((PLTGOT(lmp)), (caddr_t)lmp);
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate static const uchar_t dyn_plt_template[] = {
84*0Sstevel@tonic-gate /* 0x00 */  0x55,				/* pushl %ebp */
85*0Sstevel@tonic-gate /* 0x01 */  0x8b, 0xec,				/* movl %esp, %ebp */
86*0Sstevel@tonic-gate /* 0x03 */  0x68, 0x00, 0x00, 0x00, 0x00,	/* pushl trace_fields */
87*0Sstevel@tonic-gate /* 0x08 */  0xe9, 0xfc, 0xff, 0xff, 0xff, 0xff	/* jmp  elf_plt_trace */
88*0Sstevel@tonic-gate };
89*0Sstevel@tonic-gate int	dyn_plt_ent_size = sizeof (dyn_plt_template);
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate /*
92*0Sstevel@tonic-gate  * the dynamic plt entry is:
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  *	pushl	%ebp
95*0Sstevel@tonic-gate  *	movl	%esp, %ebp
96*0Sstevel@tonic-gate  *	pushl	tfp
97*0Sstevel@tonic-gate  *	jmp	elf_plt_trace
98*0Sstevel@tonic-gate  * dyn_data:
99*0Sstevel@tonic-gate  *	.align  4
100*0Sstevel@tonic-gate  *	uintptr_t	reflmp
101*0Sstevel@tonic-gate  *	uintptr_t	deflmp
102*0Sstevel@tonic-gate  *	uint_t		symndx
103*0Sstevel@tonic-gate  *	uint_t		sb_flags
104*0Sstevel@tonic-gate  *	Sym		symdef
105*0Sstevel@tonic-gate  */
106*0Sstevel@tonic-gate static caddr_t
107*0Sstevel@tonic-gate elf_plt_trace_write(uint_t roffset, Rt_map *rlmp, Rt_map *dlmp, Sym *sym,
108*0Sstevel@tonic-gate     uint_t symndx, uint_t pltndx, caddr_t to, uint_t sb_flags, int *fail)
109*0Sstevel@tonic-gate {
110*0Sstevel@tonic-gate 	extern int	elf_plt_trace();
111*0Sstevel@tonic-gate 	ulong_t		got_entry;
112*0Sstevel@tonic-gate 	uchar_t		*dyn_plt;
113*0Sstevel@tonic-gate 	uintptr_t	*dyndata;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	/*
116*0Sstevel@tonic-gate 	 * We only need to add the glue code if there is an auditing
117*0Sstevel@tonic-gate 	 * library that is interested in this binding.
118*0Sstevel@tonic-gate 	 */
119*0Sstevel@tonic-gate 	dyn_plt = (uchar_t *)((uintptr_t)AUDINFO(rlmp)->ai_dynplts +
120*0Sstevel@tonic-gate 		(pltndx * dyn_plt_ent_size));
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 	/*
123*0Sstevel@tonic-gate 	 * Have we initialized this dynamic plt entry yet?  If we haven't do it
124*0Sstevel@tonic-gate 	 * now.  Otherwise this function has been called before, but from a
125*0Sstevel@tonic-gate 	 * different plt (ie. from another shared object).  In that case
126*0Sstevel@tonic-gate 	 * we just set the plt to point to the new dyn_plt.
127*0Sstevel@tonic-gate 	 */
128*0Sstevel@tonic-gate 	if (*dyn_plt == 0) {
129*0Sstevel@tonic-gate 		Sym *	symp;
130*0Sstevel@tonic-gate 		Word	symvalue;
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 		(void) memcpy((void *)dyn_plt, dyn_plt_template,
133*0Sstevel@tonic-gate 		    sizeof (dyn_plt_template));
134*0Sstevel@tonic-gate 		dyndata = (uintptr_t *)((uintptr_t)dyn_plt +
135*0Sstevel@tonic-gate 		    ROUND(sizeof (dyn_plt_template), M_WORD_ALIGN));
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 		/*
138*0Sstevel@tonic-gate 		 * relocate:
139*0Sstevel@tonic-gate 		 *	pushl	dyn_data
140*0Sstevel@tonic-gate 		 */
141*0Sstevel@tonic-gate 		symvalue = (Word)dyndata;
142*0Sstevel@tonic-gate 		if (do_reloc(R_386_32, &dyn_plt[4], &symvalue,
143*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_SYM_LADYNDATA),
144*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_SPECFIL_DYNPLT)) == 0) {
145*0Sstevel@tonic-gate 			*fail = 1;
146*0Sstevel@tonic-gate 			return (0);
147*0Sstevel@tonic-gate 		}
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 		/*
150*0Sstevel@tonic-gate 		 * jmps are relative, so I need to figure out the relative
151*0Sstevel@tonic-gate 		 * address to elf_plt_trace.
152*0Sstevel@tonic-gate 		 *
153*0Sstevel@tonic-gate 		 * relocating:
154*0Sstevel@tonic-gate 		 *	jmp	elf_plt_trace
155*0Sstevel@tonic-gate 		 */
156*0Sstevel@tonic-gate 		symvalue = (ulong_t)(elf_plt_trace) - (ulong_t)(dyn_plt + 9);
157*0Sstevel@tonic-gate 		if (do_reloc(R_386_PC32, &dyn_plt[9], &symvalue,
158*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_SYM_ELFPLTTRACE),
159*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_SPECFIL_DYNPLT)) == 0) {
160*0Sstevel@tonic-gate 			*fail = 1;
161*0Sstevel@tonic-gate 			return (0);
162*0Sstevel@tonic-gate 		}
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate 		*dyndata++ = (uintptr_t)rlmp;
165*0Sstevel@tonic-gate 		*dyndata++ = (uintptr_t)dlmp;
166*0Sstevel@tonic-gate 		*dyndata++ = (uint_t)symndx;
167*0Sstevel@tonic-gate 		*dyndata++ = (uint_t)sb_flags;
168*0Sstevel@tonic-gate 		symp = (Sym *)dyndata;
169*0Sstevel@tonic-gate 		*symp = *sym;
170*0Sstevel@tonic-gate 		symp->st_name += (Word)STRTAB(dlmp);
171*0Sstevel@tonic-gate 		symp->st_value = (Addr)to;
172*0Sstevel@tonic-gate 	}
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	got_entry = (ulong_t)roffset;
175*0Sstevel@tonic-gate 	*(ulong_t *)got_entry = (ulong_t)dyn_plt;
176*0Sstevel@tonic-gate 	return ((caddr_t)dyn_plt);
177*0Sstevel@tonic-gate }
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate /*
181*0Sstevel@tonic-gate  * Function binding routine - invoked on the first call to a function through
182*0Sstevel@tonic-gate  * the procedure linkage table;
183*0Sstevel@tonic-gate  * passes first through an assembly language interface.
184*0Sstevel@tonic-gate  *
185*0Sstevel@tonic-gate  * Takes the offset into the relocation table of the associated
186*0Sstevel@tonic-gate  * relocation entry and the address of the link map (rt_private_map struct)
187*0Sstevel@tonic-gate  * for the entry.
188*0Sstevel@tonic-gate  *
189*0Sstevel@tonic-gate  * Returns the address of the function referenced after re-writing the PLT
190*0Sstevel@tonic-gate  * entry to invoke the function directly.
191*0Sstevel@tonic-gate  *
192*0Sstevel@tonic-gate  * On error, causes process to terminate with a signal.
193*0Sstevel@tonic-gate  */
194*0Sstevel@tonic-gate ulong_t
195*0Sstevel@tonic-gate elf_bndr(Rt_map *lmp, ulong_t reloff, caddr_t from)
196*0Sstevel@tonic-gate {
197*0Sstevel@tonic-gate 	Rt_map		*nlmp, * llmp;
198*0Sstevel@tonic-gate 	ulong_t		addr, symval, rsymndx;
199*0Sstevel@tonic-gate 	char		*name;
200*0Sstevel@tonic-gate 	Rel		*rptr;
201*0Sstevel@tonic-gate 	Sym		*sym, *nsym;
202*0Sstevel@tonic-gate 	uint_t		binfo, sb_flags = 0;
203*0Sstevel@tonic-gate 	Slookup		sl;
204*0Sstevel@tonic-gate 	int		entry, dbg_save, lmflags;
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	/*
207*0Sstevel@tonic-gate 	 * For compatibility with libthread (TI_VERSION 1) we track the entry
208*0Sstevel@tonic-gate 	 * value.  A zero value indicates we have recursed into ld.so.1 to
209*0Sstevel@tonic-gate 	 * further process a locking request.  Under this recursion we disable
210*0Sstevel@tonic-gate 	 * tsort and cleanup activities.
211*0Sstevel@tonic-gate 	 */
212*0Sstevel@tonic-gate 	entry = enter();
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 	if ((lmflags = LIST(lmp)->lm_flags) & LML_FLG_RTLDLM) {
215*0Sstevel@tonic-gate 		dbg_save = dbg_mask;
216*0Sstevel@tonic-gate 		dbg_mask = 0;
217*0Sstevel@tonic-gate 	}
218*0Sstevel@tonic-gate 
219*0Sstevel@tonic-gate 	/*
220*0Sstevel@tonic-gate 	 * Perform some basic sanity checks.  If we didn't get a load map or
221*0Sstevel@tonic-gate 	 * the relocation offset is invalid then its possible someone has walked
222*0Sstevel@tonic-gate 	 * over the .got entries or jumped to plt0 out of the blue.
223*0Sstevel@tonic-gate 	 */
224*0Sstevel@tonic-gate 	if (!lmp || ((reloff % sizeof (Rel)) != 0)) {
225*0Sstevel@tonic-gate 		eprintf(ERR_FATAL, MSG_INTL(MSG_REL_PLTREF),
226*0Sstevel@tonic-gate 		    conv_reloc_386_type_str(R_386_JMP_SLOT),
227*0Sstevel@tonic-gate 		    EC_XWORD(lmp), EC_XWORD(reloff), EC_ADDR(from));
228*0Sstevel@tonic-gate 		rtldexit(LIST(lmp), 1);
229*0Sstevel@tonic-gate 	}
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 	/*
232*0Sstevel@tonic-gate 	 * Use relocation entry to get symbol table entry and symbol name.
233*0Sstevel@tonic-gate 	 */
234*0Sstevel@tonic-gate 	addr = (ulong_t)JMPREL(lmp);
235*0Sstevel@tonic-gate 	rptr = (Rel *)(addr + reloff);
236*0Sstevel@tonic-gate 	rsymndx = ELF_R_SYM(rptr->r_info);
237*0Sstevel@tonic-gate 	sym = (Sym *)((ulong_t)SYMTAB(lmp) + (rsymndx * SYMENT(lmp)));
238*0Sstevel@tonic-gate 	name = (char *)(STRTAB(lmp) + sym->st_name);
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	/*
241*0Sstevel@tonic-gate 	 * Determine the last link-map of this list, this'll be the starting
242*0Sstevel@tonic-gate 	 * point for any tsort() processing.
243*0Sstevel@tonic-gate 	 */
244*0Sstevel@tonic-gate 	llmp = LIST(lmp)->lm_tail;
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	/*
247*0Sstevel@tonic-gate 	 * Find definition for symbol.
248*0Sstevel@tonic-gate 	 */
249*0Sstevel@tonic-gate 	sl.sl_name = name;
250*0Sstevel@tonic-gate 	sl.sl_cmap = lmp;
251*0Sstevel@tonic-gate 	sl.sl_imap = LIST(lmp)->lm_head;
252*0Sstevel@tonic-gate 	sl.sl_hash = 0;
253*0Sstevel@tonic-gate 	sl.sl_rsymndx = rsymndx;
254*0Sstevel@tonic-gate 	sl.sl_flags = LKUP_DEFT;
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate 	if ((nsym = lookup_sym(&sl, &nlmp, &binfo)) == 0) {
257*0Sstevel@tonic-gate 		eprintf(ERR_FATAL, MSG_INTL(MSG_REL_NOSYM), NAME(lmp),
258*0Sstevel@tonic-gate 		    demangle(name));
259*0Sstevel@tonic-gate 		rtldexit(LIST(lmp), 1);
260*0Sstevel@tonic-gate 	}
261*0Sstevel@tonic-gate 
262*0Sstevel@tonic-gate 	symval = nsym->st_value;
263*0Sstevel@tonic-gate 	if (!(FLAGS(nlmp) & FLG_RT_FIXED) &&
264*0Sstevel@tonic-gate 	    (nsym->st_shndx != SHN_ABS))
265*0Sstevel@tonic-gate 		symval += ADDR(nlmp);
266*0Sstevel@tonic-gate 	if ((lmp != nlmp) && ((FLAGS1(nlmp) & FL1_RT_NOINIFIN) == 0)) {
267*0Sstevel@tonic-gate 		/*
268*0Sstevel@tonic-gate 		 * Record that this new link map is now bound to the caller.
269*0Sstevel@tonic-gate 		 */
270*0Sstevel@tonic-gate 		if (bind_one(lmp, nlmp, BND_REFER) == 0)
271*0Sstevel@tonic-gate 			rtldexit(LIST(lmp), 1);
272*0Sstevel@tonic-gate 	}
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate 	if ((LIST(lmp)->lm_tflags | FLAGS1(lmp)) & LML_TFLG_AUD_SYMBIND) {
275*0Sstevel@tonic-gate 		uint_t	symndx = (((uintptr_t)nsym -
276*0Sstevel@tonic-gate 			(uintptr_t)SYMTAB(nlmp)) / SYMENT(nlmp));
277*0Sstevel@tonic-gate 		symval = audit_symbind(lmp, nlmp, nsym, symndx, symval,
278*0Sstevel@tonic-gate 			&sb_flags);
279*0Sstevel@tonic-gate 	}
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 	if (!(rtld_flags & RT_FL_NOBIND)) {
282*0Sstevel@tonic-gate 		addr = rptr->r_offset;
283*0Sstevel@tonic-gate 		if (!(FLAGS(lmp) & FLG_RT_FIXED))
284*0Sstevel@tonic-gate 			addr += ADDR(lmp);
285*0Sstevel@tonic-gate 		if (((LIST(lmp)->lm_tflags | FLAGS1(lmp)) &
286*0Sstevel@tonic-gate 		    (LML_TFLG_AUD_PLTENTER | LML_TFLG_AUD_PLTEXIT)) &&
287*0Sstevel@tonic-gate 		    AUDINFO(lmp)->ai_dynplts) {
288*0Sstevel@tonic-gate 			int	fail = 0;
289*0Sstevel@tonic-gate 			uint_t	pltndx = reloff / sizeof (Rel);
290*0Sstevel@tonic-gate 			uint_t	symndx = (((uintptr_t)nsym -
291*0Sstevel@tonic-gate 						(uintptr_t)SYMTAB(nlmp)) /
292*0Sstevel@tonic-gate 						SYMENT(nlmp));
293*0Sstevel@tonic-gate 
294*0Sstevel@tonic-gate 			symval = (ulong_t)elf_plt_trace_write(addr, lmp, nlmp,
295*0Sstevel@tonic-gate 			    nsym, symndx, pltndx, (caddr_t)symval, sb_flags,
296*0Sstevel@tonic-gate 			    &fail);
297*0Sstevel@tonic-gate 			if (fail)
298*0Sstevel@tonic-gate 				rtldexit(LIST(lmp), 1);
299*0Sstevel@tonic-gate 		} else {
300*0Sstevel@tonic-gate 			/*
301*0Sstevel@tonic-gate 			 * Write standard PLT entry to jump directly
302*0Sstevel@tonic-gate 			 * to newly bound function.
303*0Sstevel@tonic-gate 			 */
304*0Sstevel@tonic-gate 			*(ulong_t *)addr = symval;
305*0Sstevel@tonic-gate 		}
306*0Sstevel@tonic-gate 	}
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 	/*
309*0Sstevel@tonic-gate 	 * Print binding information and rebuild PLT entry.
310*0Sstevel@tonic-gate 	 */
311*0Sstevel@tonic-gate 	DBG_CALL(Dbg_bind_global(NAME(lmp), from, from - ADDR(lmp),
312*0Sstevel@tonic-gate 	    (Xword)(reloff / sizeof (Rel)), PLT_T_FULL, NAME(nlmp),
313*0Sstevel@tonic-gate 	    (caddr_t)symval, (caddr_t)nsym->st_value, name, binfo));
314*0Sstevel@tonic-gate 
315*0Sstevel@tonic-gate 	/*
316*0Sstevel@tonic-gate 	 * Complete any processing for newly loaded objects.  Note we don't
317*0Sstevel@tonic-gate 	 * know exactly where any new objects are loaded (we know the object
318*0Sstevel@tonic-gate 	 * that supplied the symbol, but others may have been loaded lazily as
319*0Sstevel@tonic-gate 	 * we searched for the symbol), so sorting starts from the last
320*0Sstevel@tonic-gate 	 * link-map know on entry to this routine.
321*0Sstevel@tonic-gate 	 */
322*0Sstevel@tonic-gate 	if (entry)
323*0Sstevel@tonic-gate 		load_completion(llmp, lmp);
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate 	/*
326*0Sstevel@tonic-gate 	 * Some operations like dldump() or dlopen()'ing a relocatable object
327*0Sstevel@tonic-gate 	 * result in objects being loaded on rtld's link-map, make sure these
328*0Sstevel@tonic-gate 	 * objects are initialized also.
329*0Sstevel@tonic-gate 	 */
330*0Sstevel@tonic-gate 	if ((LIST(nlmp)->lm_flags & LML_FLG_RTLDLM) && LIST(nlmp)->lm_init)
331*0Sstevel@tonic-gate 		load_completion(nlmp, 0);
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate 	/*
334*0Sstevel@tonic-gate 	 * If the object we've bound to is in the process of being initialized
335*0Sstevel@tonic-gate 	 * by another thread, determine whether we should block.
336*0Sstevel@tonic-gate 	 */
337*0Sstevel@tonic-gate 	is_dep_ready(nlmp, lmp, DBG_WAIT_SYMBOL);
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	/*
340*0Sstevel@tonic-gate 	 * Make sure the object to which we've bound has had it's .init fired.
341*0Sstevel@tonic-gate 	 * Cleanup before return to user code.
342*0Sstevel@tonic-gate 	 */
343*0Sstevel@tonic-gate 	if (entry) {
344*0Sstevel@tonic-gate 		is_dep_init(nlmp, lmp);
345*0Sstevel@tonic-gate 		leave(LIST(lmp));
346*0Sstevel@tonic-gate 	}
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 	if (lmflags & LML_FLG_RTLDLM)
349*0Sstevel@tonic-gate 		dbg_mask = dbg_save;
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 	return (symval);
352*0Sstevel@tonic-gate }
353*0Sstevel@tonic-gate 
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate /*
356*0Sstevel@tonic-gate  * When the relocation loop realizes that it's dealing with relative
357*0Sstevel@tonic-gate  * relocations in a shared object, it breaks into this tighter loop
358*0Sstevel@tonic-gate  * as an optimization.
359*0Sstevel@tonic-gate  */
360*0Sstevel@tonic-gate ulong_t
361*0Sstevel@tonic-gate elf_reloc_relative(ulong_t relbgn, ulong_t relend, ulong_t relsiz,
362*0Sstevel@tonic-gate     ulong_t basebgn, ulong_t etext, ulong_t emap)
363*0Sstevel@tonic-gate {
364*0Sstevel@tonic-gate 	ulong_t roffset = ((Rel *)relbgn)->r_offset;
365*0Sstevel@tonic-gate 	char rtype;
366*0Sstevel@tonic-gate 
367*0Sstevel@tonic-gate 	do {
368*0Sstevel@tonic-gate 		roffset += basebgn;
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate 		/*
371*0Sstevel@tonic-gate 		 * If this relocation is against an address not mapped in,
372*0Sstevel@tonic-gate 		 * then break out of the relative relocation loop, falling
373*0Sstevel@tonic-gate 		 * back on the main relocation loop.
374*0Sstevel@tonic-gate 		 */
375*0Sstevel@tonic-gate 		if (roffset < etext || roffset > emap)
376*0Sstevel@tonic-gate 			break;
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate 		/*
379*0Sstevel@tonic-gate 		 * Perform the actual relocation.
380*0Sstevel@tonic-gate 		 */
381*0Sstevel@tonic-gate 		*((ulong_t *)roffset) += basebgn;
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate 		relbgn += relsiz;
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 		if (relbgn >= relend)
386*0Sstevel@tonic-gate 			break;
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate 		rtype = ELF_R_TYPE(((Rel *)relbgn)->r_info);
389*0Sstevel@tonic-gate 		roffset = ((Rel *)relbgn)->r_offset;
390*0Sstevel@tonic-gate 
391*0Sstevel@tonic-gate 	} while (rtype == R_386_RELATIVE);
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate 	return (relbgn);
394*0Sstevel@tonic-gate }
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate /*
397*0Sstevel@tonic-gate  * This is the tightest loop for RELATIVE relocations for those
398*0Sstevel@tonic-gate  * objects built with the DT_RELACOUNT .dynamic entry.
399*0Sstevel@tonic-gate  */
400*0Sstevel@tonic-gate ulong_t
401*0Sstevel@tonic-gate elf_reloc_relacount(ulong_t relbgn, ulong_t relacount, ulong_t relsiz,
402*0Sstevel@tonic-gate     ulong_t basebgn)
403*0Sstevel@tonic-gate {
404*0Sstevel@tonic-gate 	ulong_t roffset = ((Rel *) relbgn)->r_offset;
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate 	for (; relacount; relacount--) {
407*0Sstevel@tonic-gate 		roffset += basebgn;
408*0Sstevel@tonic-gate 
409*0Sstevel@tonic-gate 		/*
410*0Sstevel@tonic-gate 		 * Perform the actual relocation.
411*0Sstevel@tonic-gate 		 */
412*0Sstevel@tonic-gate 		*((ulong_t *)roffset) += basebgn;
413*0Sstevel@tonic-gate 
414*0Sstevel@tonic-gate 		relbgn += relsiz;
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate 		roffset = ((Rel *)relbgn)->r_offset;
417*0Sstevel@tonic-gate 
418*0Sstevel@tonic-gate 	}
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 	return (relbgn);
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate /*
424*0Sstevel@tonic-gate  * Read and process the relocations for one link object, we assume all
425*0Sstevel@tonic-gate  * relocation sections for loadable segments are stored contiguously in
426*0Sstevel@tonic-gate  * the file.
427*0Sstevel@tonic-gate  */
428*0Sstevel@tonic-gate int
429*0Sstevel@tonic-gate elf_reloc(Rt_map *lmp, uint_t plt)
430*0Sstevel@tonic-gate {
431*0Sstevel@tonic-gate 	ulong_t		relbgn, relend, relsiz, basebgn;
432*0Sstevel@tonic-gate 	ulong_t		pltbgn, pltend, _pltbgn, _pltend;
433*0Sstevel@tonic-gate 	ulong_t		roffset, rsymndx, psymndx = 0, etext  = ETEXT(lmp);
434*0Sstevel@tonic-gate 	ulong_t		emap, dsymndx;
435*0Sstevel@tonic-gate 	uchar_t		rtype;
436*0Sstevel@tonic-gate 	long		value, pvalue;
437*0Sstevel@tonic-gate 	Sym		*symref, *psymref, *symdef, *psymdef;
438*0Sstevel@tonic-gate 	char		*name, *pname;
439*0Sstevel@tonic-gate 	Rt_map		*_lmp, *plmp;
440*0Sstevel@tonic-gate 	int		textrel = 0, ret = 1, noplt = 0;
441*0Sstevel@tonic-gate 	int		relacount = RELACOUNT(lmp), plthint = 0;
442*0Sstevel@tonic-gate 	Rel		*rel;
443*0Sstevel@tonic-gate 	uint_t		binfo, pbinfo;
444*0Sstevel@tonic-gate 	Alist		*bound = 0;
445*0Sstevel@tonic-gate 
446*0Sstevel@tonic-gate 	/*
447*0Sstevel@tonic-gate 	 * Although only necessary for lazy binding, initialize the first
448*0Sstevel@tonic-gate 	 * global offset entry to go to elf_rtbndr().  dbx(1) seems
449*0Sstevel@tonic-gate 	 * to find this useful.
450*0Sstevel@tonic-gate 	 */
451*0Sstevel@tonic-gate 	if ((plt == 0) && PLTGOT(lmp)) {
452*0Sstevel@tonic-gate 		if ((ulong_t)PLTGOT(lmp) < etext) {
453*0Sstevel@tonic-gate 			if (elf_set_prot(lmp, PROT_WRITE) == 0)
454*0Sstevel@tonic-gate 				return (0);
455*0Sstevel@tonic-gate 			textrel = 1;
456*0Sstevel@tonic-gate 		}
457*0Sstevel@tonic-gate 		elf_plt_init(PLTGOT(lmp), (caddr_t)lmp);
458*0Sstevel@tonic-gate 	}
459*0Sstevel@tonic-gate 
460*0Sstevel@tonic-gate 	/*
461*0Sstevel@tonic-gate 	 * Initialize the plt start and end addresses.
462*0Sstevel@tonic-gate 	 */
463*0Sstevel@tonic-gate 	if ((pltbgn = (ulong_t)JMPREL(lmp)) != 0)
464*0Sstevel@tonic-gate 		pltend = pltbgn + (ulong_t)(PLTRELSZ(lmp));
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	relsiz = (ulong_t)(RELENT(lmp));
468*0Sstevel@tonic-gate 	basebgn = ADDR(lmp);
469*0Sstevel@tonic-gate 	emap = ADDR(lmp) + MSIZE(lmp);
470*0Sstevel@tonic-gate 
471*0Sstevel@tonic-gate 	if (PLTRELSZ(lmp))
472*0Sstevel@tonic-gate 		plthint = PLTRELSZ(lmp) / relsiz;
473*0Sstevel@tonic-gate 
474*0Sstevel@tonic-gate 	/*
475*0Sstevel@tonic-gate 	 * If we've been called upon to promote an RTLD_LAZY object to an
476*0Sstevel@tonic-gate 	 * RTLD_NOW then we're only interested in scaning the .plt table.
477*0Sstevel@tonic-gate 	 * An uninitialized .plt is the case where the associated got entry
478*0Sstevel@tonic-gate 	 * points back to the plt itself.  Determine the range of the real .plt
479*0Sstevel@tonic-gate 	 * entries using the _PROCEDURE_LINKAGE_TABLE_ symbol.
480*0Sstevel@tonic-gate 	 */
481*0Sstevel@tonic-gate 	if (plt) {
482*0Sstevel@tonic-gate 		Slookup	sl;
483*0Sstevel@tonic-gate 
484*0Sstevel@tonic-gate 		relbgn = pltbgn;
485*0Sstevel@tonic-gate 		relend = pltend;
486*0Sstevel@tonic-gate 		if (!relbgn || (relbgn == relend))
487*0Sstevel@tonic-gate 			return (1);
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate 		sl.sl_name = MSG_ORIG(MSG_SYM_PLT);
490*0Sstevel@tonic-gate 		sl.sl_cmap = lmp;
491*0Sstevel@tonic-gate 		sl.sl_imap = lmp;
492*0Sstevel@tonic-gate 		sl.sl_hash = 0;
493*0Sstevel@tonic-gate 		sl.sl_rsymndx = 0;
494*0Sstevel@tonic-gate 		sl.sl_flags = LKUP_DEFT;
495*0Sstevel@tonic-gate 
496*0Sstevel@tonic-gate 		if ((symdef = elf_find_sym(&sl, &_lmp, &binfo)) == 0)
497*0Sstevel@tonic-gate 			return (1);
498*0Sstevel@tonic-gate 
499*0Sstevel@tonic-gate 		_pltbgn = symdef->st_value;
500*0Sstevel@tonic-gate 		if (!(FLAGS(lmp) & FLG_RT_FIXED) &&
501*0Sstevel@tonic-gate 		    (symdef->st_shndx != SHN_ABS))
502*0Sstevel@tonic-gate 			_pltbgn += basebgn;
503*0Sstevel@tonic-gate 		_pltend = _pltbgn + (((PLTRELSZ(lmp) / relsiz)) *
504*0Sstevel@tonic-gate 			M_PLT_ENTSIZE) + M_PLT_RESERVSZ;
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate 	} else {
507*0Sstevel@tonic-gate 		/*
508*0Sstevel@tonic-gate 		 * The relocation sections appear to the run-time linker as a
509*0Sstevel@tonic-gate 		 * single table.  Determine the address of the beginning and end
510*0Sstevel@tonic-gate 		 * of this table.  There are two different interpretations of
511*0Sstevel@tonic-gate 		 * the ABI at this point:
512*0Sstevel@tonic-gate 		 *
513*0Sstevel@tonic-gate 		 *   o	The REL table and its associated RELSZ indicate the
514*0Sstevel@tonic-gate 		 *	concatenation of *all* relocation sections (this is the
515*0Sstevel@tonic-gate 		 *	model our link-editor constructs).
516*0Sstevel@tonic-gate 		 *
517*0Sstevel@tonic-gate 		 *   o	The REL table and its associated RELSZ indicate the
518*0Sstevel@tonic-gate 		 *	concatenation of all *but* the .plt relocations.  These
519*0Sstevel@tonic-gate 		 *	relocations are specified individually by the JMPREL and
520*0Sstevel@tonic-gate 		 *	PLTRELSZ entries.
521*0Sstevel@tonic-gate 		 *
522*0Sstevel@tonic-gate 		 * Determine from our knowledege of the relocation range and
523*0Sstevel@tonic-gate 		 * .plt range, the range of the total relocation table.  Note
524*0Sstevel@tonic-gate 		 * that one other ABI assumption seems to be that the .plt
525*0Sstevel@tonic-gate 		 * relocations always follow any other relocations, the
526*0Sstevel@tonic-gate 		 * following range checking drops that assumption.
527*0Sstevel@tonic-gate 		 */
528*0Sstevel@tonic-gate 		relbgn = (ulong_t)(REL(lmp));
529*0Sstevel@tonic-gate 		relend = relbgn + (ulong_t)(RELSZ(lmp));
530*0Sstevel@tonic-gate 		if (pltbgn) {
531*0Sstevel@tonic-gate 			if (!relbgn || (relbgn > pltbgn))
532*0Sstevel@tonic-gate 				relbgn = pltbgn;
533*0Sstevel@tonic-gate 			if (!relbgn || (relend < pltend))
534*0Sstevel@tonic-gate 				relend = pltend;
535*0Sstevel@tonic-gate 		}
536*0Sstevel@tonic-gate 	}
537*0Sstevel@tonic-gate 	if (!relbgn || (relbgn == relend)) {
538*0Sstevel@tonic-gate 		DBG_CALL(Dbg_reloc_run(NAME(lmp), 0, plt, DBG_REL_NONE));
539*0Sstevel@tonic-gate 		return (1);
540*0Sstevel@tonic-gate 	}
541*0Sstevel@tonic-gate 	DBG_CALL(Dbg_reloc_run(NAME(lmp), M_REL_SHT_TYPE, plt, DBG_REL_START));
542*0Sstevel@tonic-gate 
543*0Sstevel@tonic-gate 	/*
544*0Sstevel@tonic-gate 	 * If we're processing a dynamic executable in lazy mode there is no
545*0Sstevel@tonic-gate 	 * need to scan the .rel.plt table, however if we're processing a shared
546*0Sstevel@tonic-gate 	 * object in lazy mode the .got addresses associated to each .plt must
547*0Sstevel@tonic-gate 	 * be relocated to reflect the location of the shared object.
548*0Sstevel@tonic-gate 	 */
549*0Sstevel@tonic-gate 	if (pltbgn && ((MODE(lmp) & RTLD_NOW) == 0) &&
550*0Sstevel@tonic-gate 	    (FLAGS(lmp) & FLG_RT_FIXED))
551*0Sstevel@tonic-gate 		noplt = 1;
552*0Sstevel@tonic-gate 
553*0Sstevel@tonic-gate 	/*
554*0Sstevel@tonic-gate 	 * Loop through relocations.
555*0Sstevel@tonic-gate 	 */
556*0Sstevel@tonic-gate 	while (relbgn < relend) {
557*0Sstevel@tonic-gate 		uint_t	sb_flags = 0;
558*0Sstevel@tonic-gate 
559*0Sstevel@tonic-gate 		rtype = ELF_R_TYPE(((Rel *)relbgn)->r_info);
560*0Sstevel@tonic-gate 
561*0Sstevel@tonic-gate 		/*
562*0Sstevel@tonic-gate 		 * If this is a RELATIVE relocation in a shared object (the
563*0Sstevel@tonic-gate 		 * common case), and if we are not debugging, then jump into a
564*0Sstevel@tonic-gate 		 * tighter relocation loop (elf_reloc_relative).  Only make the
565*0Sstevel@tonic-gate 		 * jump if we've been given a hint on the number of relocations.
566*0Sstevel@tonic-gate 		 */
567*0Sstevel@tonic-gate 		if ((rtype == R_386_RELATIVE) &&
568*0Sstevel@tonic-gate 		    !(FLAGS(lmp) & FLG_RT_FIXED) && !dbg_mask) {
569*0Sstevel@tonic-gate 			/*
570*0Sstevel@tonic-gate 			 * It's possible that the relative relocation block
571*0Sstevel@tonic-gate 			 * has relocations against the text segment as well
572*0Sstevel@tonic-gate 			 * as the data segment.  Since our optimized relocation
573*0Sstevel@tonic-gate 			 * engine does not check which segment the relocation
574*0Sstevel@tonic-gate 			 * is against - just mprotect it now if it's been
575*0Sstevel@tonic-gate 			 * marked as containing TEXTREL's.
576*0Sstevel@tonic-gate 			 */
577*0Sstevel@tonic-gate 			if ((textrel == 0) && (FLAGS1(lmp) & FL1_RT_TEXTREL)) {
578*0Sstevel@tonic-gate 				if (elf_set_prot(lmp, PROT_WRITE) == 0) {
579*0Sstevel@tonic-gate 					ret = 0;
580*0Sstevel@tonic-gate 					break;
581*0Sstevel@tonic-gate 				}
582*0Sstevel@tonic-gate 				textrel = 1;
583*0Sstevel@tonic-gate 			}
584*0Sstevel@tonic-gate 			if (relacount) {
585*0Sstevel@tonic-gate 				relbgn = elf_reloc_relacount(relbgn, relacount,
586*0Sstevel@tonic-gate 				    relsiz, basebgn);
587*0Sstevel@tonic-gate 				relacount = 0;
588*0Sstevel@tonic-gate 			} else {
589*0Sstevel@tonic-gate 				relbgn = elf_reloc_relative(relbgn, relend,
590*0Sstevel@tonic-gate 				    relsiz, basebgn, etext, emap);
591*0Sstevel@tonic-gate 			}
592*0Sstevel@tonic-gate 			if (relbgn >= relend)
593*0Sstevel@tonic-gate 				break;
594*0Sstevel@tonic-gate 			rtype = ELF_R_TYPE(((Rel *)relbgn)->r_info);
595*0Sstevel@tonic-gate 		}
596*0Sstevel@tonic-gate 
597*0Sstevel@tonic-gate 		roffset = ((Rel *)relbgn)->r_offset;
598*0Sstevel@tonic-gate 
599*0Sstevel@tonic-gate 		/*
600*0Sstevel@tonic-gate 		 * If this is a shared object, add the base address to offset.
601*0Sstevel@tonic-gate 		 */
602*0Sstevel@tonic-gate 		if (!(FLAGS(lmp) & FLG_RT_FIXED)) {
603*0Sstevel@tonic-gate 
604*0Sstevel@tonic-gate 			/*
605*0Sstevel@tonic-gate 			 * If we're processing lazy bindings, we have to step
606*0Sstevel@tonic-gate 			 * through the plt entries and add the base address
607*0Sstevel@tonic-gate 			 * to the corresponding got entry.
608*0Sstevel@tonic-gate 			 */
609*0Sstevel@tonic-gate 			if (plthint && (plt == 0) &&
610*0Sstevel@tonic-gate 			    (rtype == R_386_JMP_SLOT) &&
611*0Sstevel@tonic-gate 			    ((MODE(lmp) & RTLD_NOW) == 0)) {
612*0Sstevel@tonic-gate 				relbgn = elf_reloc_relacount(relbgn,
613*0Sstevel@tonic-gate 				    plthint, relsiz, basebgn);
614*0Sstevel@tonic-gate 				plthint = 0;
615*0Sstevel@tonic-gate 				continue;
616*0Sstevel@tonic-gate 			}
617*0Sstevel@tonic-gate 			roffset += basebgn;
618*0Sstevel@tonic-gate 		}
619*0Sstevel@tonic-gate 
620*0Sstevel@tonic-gate 		rsymndx = ELF_R_SYM(((Rel *)relbgn)->r_info);
621*0Sstevel@tonic-gate 		rel = (Rel *)relbgn;
622*0Sstevel@tonic-gate 		relbgn += relsiz;
623*0Sstevel@tonic-gate 
624*0Sstevel@tonic-gate 		/*
625*0Sstevel@tonic-gate 		 * Optimizations.
626*0Sstevel@tonic-gate 		 */
627*0Sstevel@tonic-gate 		if (rtype == R_386_NONE)
628*0Sstevel@tonic-gate 			continue;
629*0Sstevel@tonic-gate 		if (noplt && ((ulong_t)rel >= pltbgn) &&
630*0Sstevel@tonic-gate 		    ((ulong_t)rel < pltend)) {
631*0Sstevel@tonic-gate 			relbgn = pltend;
632*0Sstevel@tonic-gate 			continue;
633*0Sstevel@tonic-gate 		}
634*0Sstevel@tonic-gate 
635*0Sstevel@tonic-gate 		/*
636*0Sstevel@tonic-gate 		 * If we're promoting plts determine if this one has already
637*0Sstevel@tonic-gate 		 * been written.
638*0Sstevel@tonic-gate 		 */
639*0Sstevel@tonic-gate 		if (plt) {
640*0Sstevel@tonic-gate 			if ((*(ulong_t *)roffset < _pltbgn) ||
641*0Sstevel@tonic-gate 			    (*(ulong_t *)roffset > _pltend))
642*0Sstevel@tonic-gate 				continue;
643*0Sstevel@tonic-gate 		}
644*0Sstevel@tonic-gate 
645*0Sstevel@tonic-gate 		/*
646*0Sstevel@tonic-gate 		 * If this relocation is not against part of the image
647*0Sstevel@tonic-gate 		 * mapped into memory we skip it.
648*0Sstevel@tonic-gate 		 */
649*0Sstevel@tonic-gate 		if ((roffset < ADDR(lmp)) || (roffset > (ADDR(lmp) +
650*0Sstevel@tonic-gate 		    MSIZE(lmp)))) {
651*0Sstevel@tonic-gate 			elf_reloc_bad(lmp, (void *)rel,
652*0Sstevel@tonic-gate 				rtype, roffset, rsymndx);
653*0Sstevel@tonic-gate 			continue;
654*0Sstevel@tonic-gate 		}
655*0Sstevel@tonic-gate 
656*0Sstevel@tonic-gate 		binfo = 0;
657*0Sstevel@tonic-gate 		/*
658*0Sstevel@tonic-gate 		 * If a symbol index is specified then get the symbol table
659*0Sstevel@tonic-gate 		 * entry, locate the symbol definition, and determine its
660*0Sstevel@tonic-gate 		 * address.
661*0Sstevel@tonic-gate 		 */
662*0Sstevel@tonic-gate 		if (rsymndx) {
663*0Sstevel@tonic-gate 			/*
664*0Sstevel@tonic-gate 			 * Get the local symbol table entry.
665*0Sstevel@tonic-gate 			 */
666*0Sstevel@tonic-gate 			symref = (Sym *)((ulong_t)SYMTAB(lmp) +
667*0Sstevel@tonic-gate 			    (rsymndx * SYMENT(lmp)));
668*0Sstevel@tonic-gate 
669*0Sstevel@tonic-gate 			/*
670*0Sstevel@tonic-gate 			 * If this is a local symbol, just use the base address.
671*0Sstevel@tonic-gate 			 * (we should have no local relocations in the
672*0Sstevel@tonic-gate 			 * executable).
673*0Sstevel@tonic-gate 			 */
674*0Sstevel@tonic-gate 			if (ELF_ST_BIND(symref->st_info) == STB_LOCAL) {
675*0Sstevel@tonic-gate 				value = basebgn;
676*0Sstevel@tonic-gate 				name = (char *)0;
677*0Sstevel@tonic-gate 
678*0Sstevel@tonic-gate 				/*
679*0Sstevel@tonic-gate 				 * TLS relocation - value for DTPMOD32
680*0Sstevel@tonic-gate 				 * relocation is the TLS modid.
681*0Sstevel@tonic-gate 				 */
682*0Sstevel@tonic-gate 				if (rtype == R_386_TLS_DTPMOD32)
683*0Sstevel@tonic-gate 					value = TLSMODID(lmp);
684*0Sstevel@tonic-gate 			} else {
685*0Sstevel@tonic-gate 				/*
686*0Sstevel@tonic-gate 				 * If the symbol index is equal to the previous
687*0Sstevel@tonic-gate 				 * symbol index relocation we processed then
688*0Sstevel@tonic-gate 				 * reuse the previous values. (Note that there
689*0Sstevel@tonic-gate 				 * have been cases where a relocation exists
690*0Sstevel@tonic-gate 				 * against a copy relocation symbol, our ld(1)
691*0Sstevel@tonic-gate 				 * should optimize this away, but make sure we
692*0Sstevel@tonic-gate 				 * don't use the same symbol information should
693*0Sstevel@tonic-gate 				 * this case exist).
694*0Sstevel@tonic-gate 				 */
695*0Sstevel@tonic-gate 				if ((rsymndx == psymndx) &&
696*0Sstevel@tonic-gate 				    (rtype != R_386_COPY)) {
697*0Sstevel@tonic-gate 					/* LINTED */
698*0Sstevel@tonic-gate 					if (psymdef == 0) {
699*0Sstevel@tonic-gate 						DBG_CALL(Dbg_bind_weak(
700*0Sstevel@tonic-gate 						    NAME(lmp), (caddr_t)roffset,
701*0Sstevel@tonic-gate 						    (caddr_t)
702*0Sstevel@tonic-gate 						    (roffset - basebgn), name));
703*0Sstevel@tonic-gate 						continue;
704*0Sstevel@tonic-gate 					}
705*0Sstevel@tonic-gate 					/* LINTED */
706*0Sstevel@tonic-gate 					value = pvalue;
707*0Sstevel@tonic-gate 					/* LINTED */
708*0Sstevel@tonic-gate 					name = pname;
709*0Sstevel@tonic-gate 					/* LINTED */
710*0Sstevel@tonic-gate 					symdef = psymdef;
711*0Sstevel@tonic-gate 					/* LINTED */
712*0Sstevel@tonic-gate 					symref = psymref;
713*0Sstevel@tonic-gate 					/* LINTED */
714*0Sstevel@tonic-gate 					_lmp = plmp;
715*0Sstevel@tonic-gate 					/* LINTED */
716*0Sstevel@tonic-gate 					binfo = pbinfo;
717*0Sstevel@tonic-gate 
718*0Sstevel@tonic-gate 					if ((LIST(_lmp)->lm_tflags |
719*0Sstevel@tonic-gate 					    FLAGS1(_lmp)) &
720*0Sstevel@tonic-gate 					    LML_TFLG_AUD_SYMBIND) {
721*0Sstevel@tonic-gate 						value = audit_symbind(lmp, _lmp,
722*0Sstevel@tonic-gate 						    /* LINTED */
723*0Sstevel@tonic-gate 						    symdef, dsymndx, value,
724*0Sstevel@tonic-gate 						    &sb_flags);
725*0Sstevel@tonic-gate 					}
726*0Sstevel@tonic-gate 				} else {
727*0Sstevel@tonic-gate 					Slookup		sl;
728*0Sstevel@tonic-gate 					uchar_t		bind;
729*0Sstevel@tonic-gate 
730*0Sstevel@tonic-gate 					/*
731*0Sstevel@tonic-gate 					 * Lookup the symbol definition.
732*0Sstevel@tonic-gate 					 */
733*0Sstevel@tonic-gate 					name = (char *)(STRTAB(lmp) +
734*0Sstevel@tonic-gate 					    symref->st_name);
735*0Sstevel@tonic-gate 
736*0Sstevel@tonic-gate 					sl.sl_name = name;
737*0Sstevel@tonic-gate 					sl.sl_cmap = lmp;
738*0Sstevel@tonic-gate 					sl.sl_imap = 0;
739*0Sstevel@tonic-gate 					sl.sl_hash = 0;
740*0Sstevel@tonic-gate 					sl.sl_rsymndx = rsymndx;
741*0Sstevel@tonic-gate 
742*0Sstevel@tonic-gate 					if (rtype == R_386_COPY)
743*0Sstevel@tonic-gate 						sl.sl_flags = LKUP_COPY;
744*0Sstevel@tonic-gate 					else
745*0Sstevel@tonic-gate 						sl.sl_flags = LKUP_DEFT;
746*0Sstevel@tonic-gate 
747*0Sstevel@tonic-gate 					sl.sl_flags |= LKUP_ALLCNTLIST;
748*0Sstevel@tonic-gate 
749*0Sstevel@tonic-gate 					if (rtype != R_386_JMP_SLOT)
750*0Sstevel@tonic-gate 						sl.sl_flags |= LKUP_SPEC;
751*0Sstevel@tonic-gate 
752*0Sstevel@tonic-gate 					bind = ELF_ST_BIND(symref->st_info);
753*0Sstevel@tonic-gate 					if (bind == STB_WEAK)
754*0Sstevel@tonic-gate 						sl.sl_flags |= LKUP_WEAK;
755*0Sstevel@tonic-gate 
756*0Sstevel@tonic-gate 					symdef = lookup_sym(&sl, &_lmp, &binfo);
757*0Sstevel@tonic-gate 
758*0Sstevel@tonic-gate 					/*
759*0Sstevel@tonic-gate 					 * If the symbol is not found and the
760*0Sstevel@tonic-gate 					 * reference was not to a weak symbol,
761*0Sstevel@tonic-gate 					 * report an error.  Weak references
762*0Sstevel@tonic-gate 					 * may be unresolved.
763*0Sstevel@tonic-gate 					 * chkmsg: MSG_INTL(MSG_LDD_SYM_NFOUND)
764*0Sstevel@tonic-gate 					 */
765*0Sstevel@tonic-gate 					if (symdef == 0) {
766*0Sstevel@tonic-gate 					    if (bind != STB_WEAK) {
767*0Sstevel@tonic-gate 						if (LIST(lmp)->lm_flags &
768*0Sstevel@tonic-gate 						    LML_FLG_IGNRELERR) {
769*0Sstevel@tonic-gate 						    continue;
770*0Sstevel@tonic-gate 						} else if (LIST(lmp)->lm_flags &
771*0Sstevel@tonic-gate 						    LML_FLG_TRC_WARN) {
772*0Sstevel@tonic-gate 						    (void) printf(MSG_INTL(
773*0Sstevel@tonic-gate 							MSG_LDD_SYM_NFOUND),
774*0Sstevel@tonic-gate 							demangle(name),
775*0Sstevel@tonic-gate 							NAME(lmp));
776*0Sstevel@tonic-gate 						    continue;
777*0Sstevel@tonic-gate 						} else {
778*0Sstevel@tonic-gate 						    eprintf(ERR_FATAL,
779*0Sstevel@tonic-gate 							MSG_INTL(MSG_REL_NOSYM),
780*0Sstevel@tonic-gate 							NAME(lmp),
781*0Sstevel@tonic-gate 							demangle(name));
782*0Sstevel@tonic-gate 						    ret = 0;
783*0Sstevel@tonic-gate 						    break;
784*0Sstevel@tonic-gate 						}
785*0Sstevel@tonic-gate 					    } else {
786*0Sstevel@tonic-gate 						psymndx = rsymndx;
787*0Sstevel@tonic-gate 						psymdef = 0;
788*0Sstevel@tonic-gate 
789*0Sstevel@tonic-gate 						DBG_CALL(Dbg_bind_weak(
790*0Sstevel@tonic-gate 						    NAME(lmp), (caddr_t)roffset,
791*0Sstevel@tonic-gate 						    (caddr_t)
792*0Sstevel@tonic-gate 						    (roffset - basebgn), name));
793*0Sstevel@tonic-gate 						continue;
794*0Sstevel@tonic-gate 					    }
795*0Sstevel@tonic-gate 					}
796*0Sstevel@tonic-gate 
797*0Sstevel@tonic-gate 					/*
798*0Sstevel@tonic-gate 					 * If symbol was found in an object
799*0Sstevel@tonic-gate 					 * other than the referencing object
800*0Sstevel@tonic-gate 					 * then record the binding.
801*0Sstevel@tonic-gate 					 */
802*0Sstevel@tonic-gate 					if ((lmp != _lmp) && ((FLAGS1(_lmp) &
803*0Sstevel@tonic-gate 					    FL1_RT_NOINIFIN) == 0)) {
804*0Sstevel@tonic-gate 						if (alist_test(&bound, _lmp,
805*0Sstevel@tonic-gate 						    sizeof (Rt_map *),
806*0Sstevel@tonic-gate 						    AL_CNT_RELBIND) == 0) {
807*0Sstevel@tonic-gate 							ret = 0;
808*0Sstevel@tonic-gate 							break;
809*0Sstevel@tonic-gate 						}
810*0Sstevel@tonic-gate 					}
811*0Sstevel@tonic-gate 
812*0Sstevel@tonic-gate 					/*
813*0Sstevel@tonic-gate 					 * Calculate the location of definition;
814*0Sstevel@tonic-gate 					 * symbol value plus base address of
815*0Sstevel@tonic-gate 					 * containing shared object.
816*0Sstevel@tonic-gate 					 */
817*0Sstevel@tonic-gate 					value = symdef->st_value;
818*0Sstevel@tonic-gate 					if (!(FLAGS(_lmp) & FLG_RT_FIXED) &&
819*0Sstevel@tonic-gate 					    (symdef->st_shndx != SHN_ABS) &&
820*0Sstevel@tonic-gate 					    (ELF_ST_TYPE(symdef->st_info) !=
821*0Sstevel@tonic-gate 					    STT_TLS))
822*0Sstevel@tonic-gate 						value += ADDR(_lmp);
823*0Sstevel@tonic-gate 
824*0Sstevel@tonic-gate 					/*
825*0Sstevel@tonic-gate 					 * Retain this symbol index and the
826*0Sstevel@tonic-gate 					 * value in case it can be used for the
827*0Sstevel@tonic-gate 					 * subsequent relocations.
828*0Sstevel@tonic-gate 					 */
829*0Sstevel@tonic-gate 					if (rtype != R_386_COPY) {
830*0Sstevel@tonic-gate 						psymndx = rsymndx;
831*0Sstevel@tonic-gate 						pvalue = value;
832*0Sstevel@tonic-gate 						pname = name;
833*0Sstevel@tonic-gate 						psymdef = symdef;
834*0Sstevel@tonic-gate 						psymref = symref;
835*0Sstevel@tonic-gate 						plmp = _lmp;
836*0Sstevel@tonic-gate 						pbinfo = binfo;
837*0Sstevel@tonic-gate 					}
838*0Sstevel@tonic-gate 					if ((LIST(_lmp)->lm_tflags |
839*0Sstevel@tonic-gate 					    FLAGS1(_lmp)) &
840*0Sstevel@tonic-gate 					    LML_TFLG_AUD_SYMBIND) {
841*0Sstevel@tonic-gate 						dsymndx = (((uintptr_t)symdef -
842*0Sstevel@tonic-gate 						    (uintptr_t)SYMTAB(_lmp)) /
843*0Sstevel@tonic-gate 						    SYMENT(_lmp));
844*0Sstevel@tonic-gate 						value = audit_symbind(lmp, _lmp,
845*0Sstevel@tonic-gate 						    symdef, dsymndx, value,
846*0Sstevel@tonic-gate 						    &sb_flags);
847*0Sstevel@tonic-gate 					}
848*0Sstevel@tonic-gate 				}
849*0Sstevel@tonic-gate 
850*0Sstevel@tonic-gate 				/*
851*0Sstevel@tonic-gate 				 * If relocation is PC-relative, subtract
852*0Sstevel@tonic-gate 				 * offset address.
853*0Sstevel@tonic-gate 				 */
854*0Sstevel@tonic-gate 				if (IS_PC_RELATIVE(rtype))
855*0Sstevel@tonic-gate 					value -= roffset;
856*0Sstevel@tonic-gate 
857*0Sstevel@tonic-gate 				/*
858*0Sstevel@tonic-gate 				 * TLS relocation - value for DTPMOD32
859*0Sstevel@tonic-gate 				 * relocation is the TLS modid.
860*0Sstevel@tonic-gate 				 */
861*0Sstevel@tonic-gate 				if (rtype == R_386_TLS_DTPMOD32)
862*0Sstevel@tonic-gate 					value = TLSMODID(_lmp);
863*0Sstevel@tonic-gate 				else if (rtype == R_386_TLS_TPOFF)
864*0Sstevel@tonic-gate 					value = -(TLSSTATOFF(_lmp) - value);
865*0Sstevel@tonic-gate 			}
866*0Sstevel@tonic-gate 		} else {
867*0Sstevel@tonic-gate 			/*
868*0Sstevel@tonic-gate 			 * Special case:
869*0Sstevel@tonic-gate 			 *
870*0Sstevel@tonic-gate 			 * A DTPMOD32 relocation is a local binding to a TLS
871*0Sstevel@tonic-gate 			 * symbol.  Fill in the TLSMODID for the current object.
872*0Sstevel@tonic-gate 			 */
873*0Sstevel@tonic-gate 			if (rtype == R_386_TLS_DTPMOD32)
874*0Sstevel@tonic-gate 				value = TLSMODID(lmp);
875*0Sstevel@tonic-gate 			else
876*0Sstevel@tonic-gate 				value = basebgn;
877*0Sstevel@tonic-gate 			name = (char *)0;
878*0Sstevel@tonic-gate 		}
879*0Sstevel@tonic-gate 
880*0Sstevel@tonic-gate 		/*
881*0Sstevel@tonic-gate 		 * If this object has relocations in the text segment, turn
882*0Sstevel@tonic-gate 		 * off the write protect.
883*0Sstevel@tonic-gate 		 */
884*0Sstevel@tonic-gate 		if ((roffset < etext) && (textrel == 0)) {
885*0Sstevel@tonic-gate 			if (elf_set_prot(lmp, PROT_WRITE) == 0) {
886*0Sstevel@tonic-gate 				ret = 0;
887*0Sstevel@tonic-gate 				break;
888*0Sstevel@tonic-gate 			}
889*0Sstevel@tonic-gate 			textrel = 1;
890*0Sstevel@tonic-gate 		}
891*0Sstevel@tonic-gate 
892*0Sstevel@tonic-gate 		/*
893*0Sstevel@tonic-gate 		 * Call relocation routine to perform required relocation.
894*0Sstevel@tonic-gate 		 */
895*0Sstevel@tonic-gate 		DBG_CALL(Dbg_reloc_in(M_MACH, M_REL_SHT_TYPE, rel, name, NULL));
896*0Sstevel@tonic-gate 
897*0Sstevel@tonic-gate 		switch (rtype) {
898*0Sstevel@tonic-gate 		case R_386_COPY:
899*0Sstevel@tonic-gate 			if (elf_copy_reloc(name, symref, lmp, (void *)roffset,
900*0Sstevel@tonic-gate 			    symdef, _lmp, (const void *)value) == 0)
901*0Sstevel@tonic-gate 				ret = 0;
902*0Sstevel@tonic-gate 			break;
903*0Sstevel@tonic-gate 		case R_386_JMP_SLOT:
904*0Sstevel@tonic-gate 			if (((LIST(lmp)->lm_tflags | FLAGS1(lmp)) &
905*0Sstevel@tonic-gate 			    (LML_TFLG_AUD_PLTENTER | LML_TFLG_AUD_PLTEXIT)) &&
906*0Sstevel@tonic-gate 			    AUDINFO(lmp)->ai_dynplts) {
907*0Sstevel@tonic-gate 				int	fail = 0;
908*0Sstevel@tonic-gate 				int	pltndx = (((ulong_t)rel -
909*0Sstevel@tonic-gate 					(uintptr_t)JMPREL(lmp)) / relsiz);
910*0Sstevel@tonic-gate 				int	symndx = (((uintptr_t)symdef -
911*0Sstevel@tonic-gate 					    (uintptr_t)SYMTAB(_lmp)) /
912*0Sstevel@tonic-gate 					    SYMENT(_lmp));
913*0Sstevel@tonic-gate 
914*0Sstevel@tonic-gate 				(void) elf_plt_trace_write(roffset, lmp, _lmp,
915*0Sstevel@tonic-gate 				    symdef, symndx, pltndx, (caddr_t)value,
916*0Sstevel@tonic-gate 				    sb_flags, &fail);
917*0Sstevel@tonic-gate 				if (fail)
918*0Sstevel@tonic-gate 					ret = 0;
919*0Sstevel@tonic-gate 			} else {
920*0Sstevel@tonic-gate 				/*
921*0Sstevel@tonic-gate 				 * Write standard PLT entry to jump directly
922*0Sstevel@tonic-gate 				 * to newly bound function.
923*0Sstevel@tonic-gate 				 */
924*0Sstevel@tonic-gate 				DBG_CALL(Dbg_reloc_apply((Xword)roffset,
925*0Sstevel@tonic-gate 				    (Xword)value));
926*0Sstevel@tonic-gate 				*(ulong_t *)roffset = value;
927*0Sstevel@tonic-gate 			}
928*0Sstevel@tonic-gate 			break;
929*0Sstevel@tonic-gate 		default:
930*0Sstevel@tonic-gate 			/*
931*0Sstevel@tonic-gate 			 * Write the relocation out.
932*0Sstevel@tonic-gate 			 */
933*0Sstevel@tonic-gate 			if (do_reloc(rtype, (uchar_t *)roffset,
934*0Sstevel@tonic-gate 			    (Word *)&value, name, NAME(lmp)) == 0)
935*0Sstevel@tonic-gate 				ret = 0;
936*0Sstevel@tonic-gate 
937*0Sstevel@tonic-gate 			DBG_CALL(Dbg_reloc_apply((Xword)roffset,
938*0Sstevel@tonic-gate 			    (Xword)value));
939*0Sstevel@tonic-gate 		}
940*0Sstevel@tonic-gate 
941*0Sstevel@tonic-gate 		if ((ret == 0) &&
942*0Sstevel@tonic-gate 		    ((LIST(lmp)->lm_flags & LML_FLG_TRC_WARN) == 0))
943*0Sstevel@tonic-gate 			break;
944*0Sstevel@tonic-gate 
945*0Sstevel@tonic-gate 		if (binfo) {
946*0Sstevel@tonic-gate 			DBG_CALL(Dbg_bind_global(NAME(lmp), (caddr_t)roffset,
947*0Sstevel@tonic-gate 			    (caddr_t)(roffset - basebgn), (Xword)(-1),
948*0Sstevel@tonic-gate 			    PLT_T_FULL, NAME(_lmp), (caddr_t)value,
949*0Sstevel@tonic-gate 			    (caddr_t)symdef->st_value, name, binfo));
950*0Sstevel@tonic-gate 		}
951*0Sstevel@tonic-gate 	}
952*0Sstevel@tonic-gate 
953*0Sstevel@tonic-gate 	return (relocate_finish(lmp, bound, textrel, ret));
954*0Sstevel@tonic-gate }
955*0Sstevel@tonic-gate 
956*0Sstevel@tonic-gate /*
957*0Sstevel@tonic-gate  * Initialize the first few got entries so that function calls go to
958*0Sstevel@tonic-gate  * elf_rtbndr:
959*0Sstevel@tonic-gate  *
960*0Sstevel@tonic-gate  *	GOT[GOT_XLINKMAP] =	the address of the link map
961*0Sstevel@tonic-gate  *	GOT[GOT_XRTLD] =	the address of rtbinder
962*0Sstevel@tonic-gate  */
963*0Sstevel@tonic-gate void
964*0Sstevel@tonic-gate elf_plt_init(void *got, caddr_t l)
965*0Sstevel@tonic-gate {
966*0Sstevel@tonic-gate 	uint_t		*_got;
967*0Sstevel@tonic-gate 	/* LINTED */
968*0Sstevel@tonic-gate 	Rt_map		*lmp = (Rt_map *)l;
969*0Sstevel@tonic-gate 
970*0Sstevel@tonic-gate 	_got = (uint_t *)got + M_GOT_XLINKMAP;
971*0Sstevel@tonic-gate 	*_got = (uint_t)lmp;
972*0Sstevel@tonic-gate 	_got = (uint_t *)got + M_GOT_XRTLD;
973*0Sstevel@tonic-gate 	*_got = (uint_t)elf_rtbndr;
974*0Sstevel@tonic-gate }
975*0Sstevel@tonic-gate 
976*0Sstevel@tonic-gate /*
977*0Sstevel@tonic-gate  * For SVR4 Intel compatability.  USL uses /usr/lib/libc.so.1 as the run-time
978*0Sstevel@tonic-gate  * linker, so the interpreter's address will differ from /usr/lib/ld.so.1.
979*0Sstevel@tonic-gate  * Further, USL has special _iob[] and _ctype[] processing that makes up for the
980*0Sstevel@tonic-gate  * fact that these arrays do not have associated copy relocations.  So we try
981*0Sstevel@tonic-gate  * and make up for that here.  Any relocations found will be added to the global
982*0Sstevel@tonic-gate  * copy relocation list and will be processed in setup().
983*0Sstevel@tonic-gate  */
984*0Sstevel@tonic-gate static int
985*0Sstevel@tonic-gate _elf_copy_reloc(const char *name, Rt_map *rlmp, Rt_map *dlmp)
986*0Sstevel@tonic-gate {
987*0Sstevel@tonic-gate 	Sym		*symref, *symdef;
988*0Sstevel@tonic-gate 	caddr_t 	ref, def;
989*0Sstevel@tonic-gate 	Rt_map		*_lmp;
990*0Sstevel@tonic-gate 	Rel		rel;
991*0Sstevel@tonic-gate 	Slookup		sl;
992*0Sstevel@tonic-gate 	uint_t		binfo;
993*0Sstevel@tonic-gate 
994*0Sstevel@tonic-gate 	/*
995*0Sstevel@tonic-gate 	 * Determine if the special symbol exists as a reference in the dynamic
996*0Sstevel@tonic-gate 	 * executable, and that an associated definition exists in libc.so.1.
997*0Sstevel@tonic-gate 	 */
998*0Sstevel@tonic-gate 	sl.sl_name = name;
999*0Sstevel@tonic-gate 	sl.sl_cmap = rlmp;
1000*0Sstevel@tonic-gate 	sl.sl_imap = rlmp;
1001*0Sstevel@tonic-gate 	sl.sl_hash = 0;
1002*0Sstevel@tonic-gate 	sl.sl_rsymndx = 0;
1003*0Sstevel@tonic-gate 	sl.sl_flags = LKUP_FIRST;
1004*0Sstevel@tonic-gate 
1005*0Sstevel@tonic-gate 	if ((symref = lookup_sym(&sl, &_lmp, &binfo)) == 0)
1006*0Sstevel@tonic-gate 		return (1);
1007*0Sstevel@tonic-gate 
1008*0Sstevel@tonic-gate 	sl.sl_imap = dlmp;
1009*0Sstevel@tonic-gate 	sl.sl_flags = LKUP_DEFT;
1010*0Sstevel@tonic-gate 
1011*0Sstevel@tonic-gate 	if ((symdef = lookup_sym(&sl, &_lmp, &binfo)) == 0)
1012*0Sstevel@tonic-gate 		return (1);
1013*0Sstevel@tonic-gate 	if (strcmp(NAME(_lmp), MSG_ORIG(MSG_PTH_LIBC)))
1014*0Sstevel@tonic-gate 		return (1);
1015*0Sstevel@tonic-gate 
1016*0Sstevel@tonic-gate 	/*
1017*0Sstevel@tonic-gate 	 * Determine the reference and definition addresses.
1018*0Sstevel@tonic-gate 	 */
1019*0Sstevel@tonic-gate 	ref = (void *)(symref->st_value);
1020*0Sstevel@tonic-gate 	if (!(FLAGS(rlmp) & FLG_RT_FIXED))
1021*0Sstevel@tonic-gate 		ref += ADDR(rlmp);
1022*0Sstevel@tonic-gate 	def = (void *)(symdef->st_value);
1023*0Sstevel@tonic-gate 	if (!(FLAGS(_lmp) & FLG_RT_FIXED))
1024*0Sstevel@tonic-gate 		def += ADDR(_lmp);
1025*0Sstevel@tonic-gate 
1026*0Sstevel@tonic-gate 	/*
1027*0Sstevel@tonic-gate 	 * Set up a relocation entry for debugging and call the generic copy
1028*0Sstevel@tonic-gate 	 * relocation function to provide symbol size error checking and to
1029*0Sstevel@tonic-gate 	 * record the copy relocation that must be performed.
1030*0Sstevel@tonic-gate 	 */
1031*0Sstevel@tonic-gate 	rel.r_offset = (Addr)ref;
1032*0Sstevel@tonic-gate 	rel.r_info = (Word)R_386_COPY;
1033*0Sstevel@tonic-gate 	DBG_CALL(Dbg_reloc_in(M_MACH, M_REL_SHT_TYPE, &rel, name, 0));
1034*0Sstevel@tonic-gate 
1035*0Sstevel@tonic-gate 	return (elf_copy_reloc((char *)name, symref, rlmp, (void *)ref, symdef,
1036*0Sstevel@tonic-gate 	    _lmp, (void *)def));
1037*0Sstevel@tonic-gate }
1038*0Sstevel@tonic-gate 
1039*0Sstevel@tonic-gate int
1040*0Sstevel@tonic-gate elf_copy_gen(Rt_map *lmp)
1041*0Sstevel@tonic-gate {
1042*0Sstevel@tonic-gate 	if (interp && ((ulong_t)interp->i_faddr !=
1043*0Sstevel@tonic-gate 	    r_debug.rtd_rdebug.r_ldbase) &&
1044*0Sstevel@tonic-gate 	    !(strcmp(interp->i_name, MSG_ORIG(MSG_PTH_LIBC)))) {
1045*0Sstevel@tonic-gate 
1046*0Sstevel@tonic-gate 		DBG_CALL(Dbg_reloc_run(pr_name, M_REL_SHT_TYPE, 0,
1047*0Sstevel@tonic-gate 		    DBG_REL_START));
1048*0Sstevel@tonic-gate 
1049*0Sstevel@tonic-gate 		if (_elf_copy_reloc(MSG_ORIG(MSG_SYM_CTYPE), lmp,
1050*0Sstevel@tonic-gate 		    (Rt_map *)NEXT(lmp)) == 0)
1051*0Sstevel@tonic-gate 			return (0);
1052*0Sstevel@tonic-gate 		if (_elf_copy_reloc(MSG_ORIG(MSG_SYM_IOB), lmp,
1053*0Sstevel@tonic-gate 		    (Rt_map *)NEXT(lmp)) == 0)
1054*0Sstevel@tonic-gate 			return (0);
1055*0Sstevel@tonic-gate 	}
1056*0Sstevel@tonic-gate 	return (1);
1057*0Sstevel@tonic-gate }
1058*0Sstevel@tonic-gate 
1059*0Sstevel@tonic-gate /*
1060*0Sstevel@tonic-gate  * Plt writing interface to allow debugging initialization to be generic.
1061*0Sstevel@tonic-gate  */
1062*0Sstevel@tonic-gate Pltbindtype
1063*0Sstevel@tonic-gate /* ARGSUSED1 */
1064*0Sstevel@tonic-gate elf_plt_write(uintptr_t addr, uintptr_t vaddr, void *rptr, uintptr_t symval,
1065*0Sstevel@tonic-gate 	Xword pltndx)
1066*0Sstevel@tonic-gate {
1067*0Sstevel@tonic-gate 	Rel		*rel = (Rel*)rptr;
1068*0Sstevel@tonic-gate 	uintptr_t	pltaddr;
1069*0Sstevel@tonic-gate 
1070*0Sstevel@tonic-gate 	pltaddr = addr + rel->r_offset;
1071*0Sstevel@tonic-gate 	*(ulong_t *)pltaddr = (ulong_t)symval;
1072*0Sstevel@tonic-gate 	DBG_CALL(pltcntfull++);
1073*0Sstevel@tonic-gate 	return (PLT_T_FULL);
1074*0Sstevel@tonic-gate }
1075*0Sstevel@tonic-gate 
1076*0Sstevel@tonic-gate /*
1077*0Sstevel@tonic-gate  * Provide a machine specific interface to the conversion routine.  By calling
1078*0Sstevel@tonic-gate  * the machine specific version, rather than the generic version, we insure that
1079*0Sstevel@tonic-gate  * the data tables/strings for all known machine versions aren't dragged into
1080*0Sstevel@tonic-gate  * ld.so.1.
1081*0Sstevel@tonic-gate  */
1082*0Sstevel@tonic-gate const char *
1083*0Sstevel@tonic-gate _conv_reloc_type_str(uint_t rel)
1084*0Sstevel@tonic-gate {
1085*0Sstevel@tonic-gate 	return (conv_reloc_386_type_str(rel));
1086*0Sstevel@tonic-gate }
1087