xref: /onnv-gate/usr/src/uts/intel/amd64/krtld/kobj_boot.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 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * Bootstrap the linker/loader.
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <sys/types.h>
34*0Sstevel@tonic-gate #include <sys/bootconf.h>
35*0Sstevel@tonic-gate #include <sys/link.h>
36*0Sstevel@tonic-gate #include <sys/auxv.h>
37*0Sstevel@tonic-gate #include <sys/kobj.h>
38*0Sstevel@tonic-gate #include <sys/elf.h>
39*0Sstevel@tonic-gate #include <sys/bootsvcs.h>
40*0Sstevel@tonic-gate #include <sys/kobj_impl.h>
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #if !defined(__GNUC__)
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * We don't use the global offset table, but
46*0Sstevel@tonic-gate  * ld may throw in an UNDEFINED reference in
47*0Sstevel@tonic-gate  * our symbol table.
48*0Sstevel@tonic-gate  */
49*0Sstevel@tonic-gate #if !defined(_KERNEL)
50*0Sstevel@tonic-gate #pragma weak _GLOBAL_OFFSET_TABLE_
51*0Sstevel@tonic-gate #endif
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate #else
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate  * We -do- use the global offset table, but only by
57*0Sstevel@tonic-gate  * accident -- when you tell gcc to emit PIC code,
58*0Sstevel@tonic-gate  * it -always- generates a reference to the GOT in
59*0Sstevel@tonic-gate  * a register, even if the compilation unit never
60*0Sstevel@tonic-gate  * uses it.
61*0Sstevel@tonic-gate  *
62*0Sstevel@tonic-gate  * Rumoured to be fixed in a later version of gcc..
63*0Sstevel@tonic-gate  */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate long	_GLOBAL_OFFSET_TABLE_[1];
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate #endif
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #define	roundup		ALIGN
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate #define	MAXSECT		64	/* max # of sects. */
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate #define	HIBITS		0xffffffff80000000	/* upper 32 bits */
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate  * Boot transfers control here. At this point,
77*0Sstevel@tonic-gate  * we haven't relocated our own symbols, so the
78*0Sstevel@tonic-gate  * world (as we know it) is pretty small right now.
79*0Sstevel@tonic-gate  */
80*0Sstevel@tonic-gate void
81*0Sstevel@tonic-gate _kobj_boot(
82*0Sstevel@tonic-gate 	struct boot_syscalls *syscallp,
83*0Sstevel@tonic-gate 	void *dvec,
84*0Sstevel@tonic-gate 	struct bootops *bootops,
85*0Sstevel@tonic-gate 	Boot *ebp)
86*0Sstevel@tonic-gate {
87*0Sstevel@tonic-gate 	Shdr *section[MAXSECT];	/* cache */
88*0Sstevel@tonic-gate 	val_t bootaux[BA_NUM];
89*0Sstevel@tonic-gate 	struct bootops *bop;
90*0Sstevel@tonic-gate 	Phdr *phdr;
91*0Sstevel@tonic-gate 	auxv_t *auxv = NULL;
92*0Sstevel@tonic-gate 	Shdr *sh;
93*0Sstevel@tonic-gate 	Half sh_num;
94*0Sstevel@tonic-gate 	ulong_t end, edata = 0;
95*0Sstevel@tonic-gate 	int i;
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate 	bop = (dvec) ? *(struct bootops **)bootops : bootops;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate 	for (i = 0; i < BA_NUM; i++)
100*0Sstevel@tonic-gate 		bootaux[i].ba_val = NULL;
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	/*
103*0Sstevel@tonic-gate 	 * Check the bootstrap vector.
104*0Sstevel@tonic-gate 	 */
105*0Sstevel@tonic-gate 	for (; ebp->eb_tag != EB_NULL; ebp++) {
106*0Sstevel@tonic-gate 		switch (ebp->eb_tag) {
107*0Sstevel@tonic-gate #if defined(__GNUC__)
108*0Sstevel@tonic-gate 		/*
109*0Sstevel@tonic-gate 		 * gcc 2.95, 3.1 cannot be told to not generate GOT references,
110*0Sstevel@tonic-gate 		 * which krtld cannot handle.  yet switch statements which
111*0Sstevel@tonic-gate 		 * can be mapped to jump tables are a frequent generator
112*0Sstevel@tonic-gate 		 * of such references.
113*0Sstevel@tonic-gate 		 */
114*0Sstevel@tonic-gate 		case 0x12345678:
115*0Sstevel@tonic-gate 			/*
116*0Sstevel@tonic-gate 			 * deliberately mess up the compilers
117*0Sstevel@tonic-gate 			 * temptation to create a jump table
118*0Sstevel@tonic-gate 			 */
119*0Sstevel@tonic-gate 			break;
120*0Sstevel@tonic-gate #endif
121*0Sstevel@tonic-gate 		case EB_AUXV:
122*0Sstevel@tonic-gate 			auxv = (auxv_t *)ebp->eb_un.eb_ptr;
123*0Sstevel@tonic-gate 			break;
124*0Sstevel@tonic-gate 		case EB_DYNAMIC:
125*0Sstevel@tonic-gate 			bootaux[BA_DYNAMIC].ba_ptr = (void *)ebp->eb_un.eb_ptr;
126*0Sstevel@tonic-gate 			break;
127*0Sstevel@tonic-gate 		default:
128*0Sstevel@tonic-gate 			break;
129*0Sstevel@tonic-gate 		}
130*0Sstevel@tonic-gate 	}
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	if (auxv == NULL)
133*0Sstevel@tonic-gate 		return;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	/*
136*0Sstevel@tonic-gate 	 * Now the aux vector.
137*0Sstevel@tonic-gate 	 */
138*0Sstevel@tonic-gate 	for (; auxv->a_type != AT_NULL; auxv++) {
139*0Sstevel@tonic-gate 		switch (auxv->a_type) {
140*0Sstevel@tonic-gate #if defined(__GNUC__)
141*0Sstevel@tonic-gate 		case 0x12345678:
142*0Sstevel@tonic-gate 			/*
143*0Sstevel@tonic-gate 			 * deliberately mess up the compilers
144*0Sstevel@tonic-gate 			 * temptation to create a jump table
145*0Sstevel@tonic-gate 			 */
146*0Sstevel@tonic-gate 			break;
147*0Sstevel@tonic-gate #endif
148*0Sstevel@tonic-gate 		case AT_PHDR:
149*0Sstevel@tonic-gate 			bootaux[BA_PHDR].ba_ptr = auxv->a_un.a_ptr;
150*0Sstevel@tonic-gate 			break;
151*0Sstevel@tonic-gate 		case AT_PHENT:
152*0Sstevel@tonic-gate 			bootaux[BA_PHENT].ba_val = auxv->a_un.a_val;
153*0Sstevel@tonic-gate 			break;
154*0Sstevel@tonic-gate 		case AT_PHNUM:
155*0Sstevel@tonic-gate 			bootaux[BA_PHNUM].ba_val = auxv->a_un.a_val;
156*0Sstevel@tonic-gate 			break;
157*0Sstevel@tonic-gate 		case AT_PAGESZ:
158*0Sstevel@tonic-gate 			bootaux[BA_PAGESZ].ba_val = auxv->a_un.a_val;
159*0Sstevel@tonic-gate 			break;
160*0Sstevel@tonic-gate 		case AT_SUN_LDELF:
161*0Sstevel@tonic-gate 			bootaux[BA_LDELF].ba_ptr = auxv->a_un.a_ptr;
162*0Sstevel@tonic-gate 			break;
163*0Sstevel@tonic-gate 		case AT_SUN_LDSHDR:
164*0Sstevel@tonic-gate 			bootaux[BA_LDSHDR].ba_ptr = auxv->a_un.a_ptr;
165*0Sstevel@tonic-gate 			break;
166*0Sstevel@tonic-gate 		case AT_SUN_LDNAME:
167*0Sstevel@tonic-gate 			bootaux[BA_LDNAME].ba_ptr = auxv->a_un.a_ptr;
168*0Sstevel@tonic-gate 			break;
169*0Sstevel@tonic-gate 		case AT_SUN_LPAGESZ:
170*0Sstevel@tonic-gate 			bootaux[BA_LPAGESZ].ba_val = auxv->a_un.a_val;
171*0Sstevel@tonic-gate 			break;
172*0Sstevel@tonic-gate 		case AT_SUN_CPU:
173*0Sstevel@tonic-gate 			bootaux[BA_CPU].ba_ptr = auxv->a_un.a_ptr;
174*0Sstevel@tonic-gate 			break;
175*0Sstevel@tonic-gate 		case AT_SUN_MMU:
176*0Sstevel@tonic-gate 			bootaux[BA_MMU].ba_ptr = auxv->a_un.a_ptr;
177*0Sstevel@tonic-gate 			break;
178*0Sstevel@tonic-gate 		case AT_ENTRY:
179*0Sstevel@tonic-gate 			bootaux[BA_ENTRY].ba_ptr = auxv->a_un.a_ptr;
180*0Sstevel@tonic-gate 			break;
181*0Sstevel@tonic-gate 		default:
182*0Sstevel@tonic-gate 			break;
183*0Sstevel@tonic-gate 		}
184*0Sstevel@tonic-gate 	}
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 
187*0Sstevel@tonic-gate 	sh = (Shdr *)bootaux[BA_LDSHDR].ba_ptr;
188*0Sstevel@tonic-gate 	sh_num = ((Ehdr *)bootaux[BA_LDELF].ba_ptr)->e_shnum;
189*0Sstevel@tonic-gate 	/*
190*0Sstevel@tonic-gate 	 * Make sure we won't overflow stack allocated cache
191*0Sstevel@tonic-gate 	 */
192*0Sstevel@tonic-gate 	if (sh_num >= MAXSECT)
193*0Sstevel@tonic-gate 		return;
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate 	/*
196*0Sstevel@tonic-gate 	 * Build cache table for section addresses.
197*0Sstevel@tonic-gate 	 */
198*0Sstevel@tonic-gate 	for (i = 0; i < sh_num; i++) {
199*0Sstevel@tonic-gate 		section[i] = sh++;
200*0Sstevel@tonic-gate 	}
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 	/*
203*0Sstevel@tonic-gate 	 * Find the end of data
204*0Sstevel@tonic-gate 	 * (to allocate bss)
205*0Sstevel@tonic-gate 	 */
206*0Sstevel@tonic-gate 	phdr = (Phdr *)bootaux[BA_PHDR].ba_ptr;
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	for (i = 0; i < bootaux[BA_PHNUM].ba_val; i++) {
209*0Sstevel@tonic-gate 		if (phdr->p_type == PT_LOAD &&
210*0Sstevel@tonic-gate 		    (phdr->p_flags & PF_W) && (phdr->p_flags & PF_X)) {
211*0Sstevel@tonic-gate 			edata = end = phdr->p_vaddr + phdr->p_memsz;
212*0Sstevel@tonic-gate 			break;
213*0Sstevel@tonic-gate 		}
214*0Sstevel@tonic-gate 		phdr = (Phdr *)((ulong_t)phdr + bootaux[BA_PHENT].ba_val);
215*0Sstevel@tonic-gate 	}
216*0Sstevel@tonic-gate 	if (edata == NULL)
217*0Sstevel@tonic-gate 		return;
218*0Sstevel@tonic-gate 
219*0Sstevel@tonic-gate 	/*
220*0Sstevel@tonic-gate 	 * Find the symbol table, and then loop
221*0Sstevel@tonic-gate 	 * through the symbols adjusting their
222*0Sstevel@tonic-gate 	 * values to reflect where the sections
223*0Sstevel@tonic-gate 	 * were loaded.
224*0Sstevel@tonic-gate 	 */
225*0Sstevel@tonic-gate 	for (i = 1; i < sh_num; i++) {
226*0Sstevel@tonic-gate 		Shdr *shp;
227*0Sstevel@tonic-gate 		Sym *sp;
228*0Sstevel@tonic-gate 		ulong_t off;
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate 		shp = section[i];
231*0Sstevel@tonic-gate 		if (shp->sh_type != SHT_SYMTAB)
232*0Sstevel@tonic-gate 			continue;
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate 		for (off = 0; off < shp->sh_size; off += shp->sh_entsize) {
235*0Sstevel@tonic-gate 			sp = (Sym *)(shp->sh_addr + off);
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 			if (sp->st_shndx == SHN_ABS ||
238*0Sstevel@tonic-gate 			    sp->st_shndx == SHN_UNDEF)
239*0Sstevel@tonic-gate 				continue;
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 			/*
242*0Sstevel@tonic-gate 			 * Assign the addresses for COMMON
243*0Sstevel@tonic-gate 			 * symbols even though we haven't
244*0Sstevel@tonic-gate 			 * actually allocated bss yet.
245*0Sstevel@tonic-gate 			 */
246*0Sstevel@tonic-gate 			if (sp->st_shndx == SHN_COMMON) {
247*0Sstevel@tonic-gate 				end = ALIGN(end, sp->st_value);
248*0Sstevel@tonic-gate 				sp->st_value = end;
249*0Sstevel@tonic-gate 				/*
250*0Sstevel@tonic-gate 				 * Squirrel it away for later.
251*0Sstevel@tonic-gate 				 */
252*0Sstevel@tonic-gate 				if (bootaux[BA_BSS].ba_val == 0)
253*0Sstevel@tonic-gate 					bootaux[BA_BSS].ba_val = end;
254*0Sstevel@tonic-gate 				end += sp->st_size;
255*0Sstevel@tonic-gate 				continue;
256*0Sstevel@tonic-gate 			} else if (sp->st_shndx > (Half)sh_num) {
257*0Sstevel@tonic-gate 				BSVC_PUTCHAR(syscallp, '>');
258*0Sstevel@tonic-gate 				return;
259*0Sstevel@tonic-gate 			}
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate 			/*
262*0Sstevel@tonic-gate 			 * Symbol's new address.
263*0Sstevel@tonic-gate 			 */
264*0Sstevel@tonic-gate 			sp->st_value += section[sp->st_shndx]->sh_addr;
265*0Sstevel@tonic-gate 		}
266*0Sstevel@tonic-gate 	}
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 	/*
269*0Sstevel@tonic-gate 	 * Allocate bss for COMMON, if any.
270*0Sstevel@tonic-gate 	 */
271*0Sstevel@tonic-gate 	if (end > edata) {
272*0Sstevel@tonic-gate 		unsigned long va, bva;
273*0Sstevel@tonic-gate 		unsigned long asize;
274*0Sstevel@tonic-gate 		unsigned long align;
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate 		if (bootaux[BA_LPAGESZ].ba_val) {
277*0Sstevel@tonic-gate 			asize = bootaux[BA_LPAGESZ].ba_val;
278*0Sstevel@tonic-gate 			align = bootaux[BA_LPAGESZ].ba_val;
279*0Sstevel@tonic-gate 		} else {
280*0Sstevel@tonic-gate 			asize = bootaux[BA_PAGESZ].ba_val;
281*0Sstevel@tonic-gate 			align = BO_NO_ALIGN;
282*0Sstevel@tonic-gate 		}
283*0Sstevel@tonic-gate 		va = roundup(edata, asize);
284*0Sstevel@tonic-gate 		bva = roundup(end, asize);
285*0Sstevel@tonic-gate 
286*0Sstevel@tonic-gate 		if (bva > va) {
287*0Sstevel@tonic-gate 			bva = (unsigned long)BOP_ALLOC(bop, (caddr_t)va,
288*0Sstevel@tonic-gate 				bva - va, align);
289*0Sstevel@tonic-gate 			if (bva == NULL)
290*0Sstevel@tonic-gate 				return;
291*0Sstevel@tonic-gate 		}
292*0Sstevel@tonic-gate 		/*
293*0Sstevel@tonic-gate 		 * Zero it.
294*0Sstevel@tonic-gate 		 */
295*0Sstevel@tonic-gate 		for (va = edata; va < end; va++)
296*0Sstevel@tonic-gate 			*(char *)va = 0;
297*0Sstevel@tonic-gate 		/*
298*0Sstevel@tonic-gate 		 * Update the size of data.
299*0Sstevel@tonic-gate 		 */
300*0Sstevel@tonic-gate 		phdr->p_memsz += (end - edata);
301*0Sstevel@tonic-gate 	}
302*0Sstevel@tonic-gate 
303*0Sstevel@tonic-gate 	/*
304*0Sstevel@tonic-gate 	 * Relocate our own symbols.  We'll handle the
305*0Sstevel@tonic-gate 	 * undefined symbols later.
306*0Sstevel@tonic-gate 	 */
307*0Sstevel@tonic-gate 	for (i = 1; i < sh_num; i++) {
308*0Sstevel@tonic-gate 		Shdr *rshp, *shp, *ssp;
309*0Sstevel@tonic-gate 		unsigned long baseaddr, reladdr, rend;
310*0Sstevel@tonic-gate 		long relocsize;
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 		rshp = section[i];
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 		if (rshp->sh_type != SHT_RELA)
315*0Sstevel@tonic-gate 			continue;
316*0Sstevel@tonic-gate 		/*
317*0Sstevel@tonic-gate 		 * Get the section being relocated
318*0Sstevel@tonic-gate 		 * and the symbol table.
319*0Sstevel@tonic-gate 		 */
320*0Sstevel@tonic-gate 		shp = section[rshp->sh_info];
321*0Sstevel@tonic-gate 		ssp = section[rshp->sh_link];
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate 		/*
324*0Sstevel@tonic-gate 		 * Only perform relocations against allocatable
325*0Sstevel@tonic-gate 		 * sections.
326*0Sstevel@tonic-gate 		 */
327*0Sstevel@tonic-gate 		if ((shp->sh_flags & SHF_ALLOC) == 0)
328*0Sstevel@tonic-gate 			continue;
329*0Sstevel@tonic-gate 
330*0Sstevel@tonic-gate 		reladdr = rshp->sh_addr;
331*0Sstevel@tonic-gate 		baseaddr = shp->sh_addr;
332*0Sstevel@tonic-gate 		rend = reladdr + rshp->sh_size;
333*0Sstevel@tonic-gate 		relocsize = rshp->sh_entsize;
334*0Sstevel@tonic-gate 		/*
335*0Sstevel@tonic-gate 		 * Loop through relocations.
336*0Sstevel@tonic-gate 		 */
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate 		while (reladdr < rend) {
339*0Sstevel@tonic-gate 			Sym *symref;
340*0Sstevel@tonic-gate 			Rela *reloc;
341*0Sstevel@tonic-gate 			unsigned long stndx;
342*0Sstevel@tonic-gate 			unsigned long off, *offptr;
343*0Sstevel@tonic-gate 			long addend, value;
344*0Sstevel@tonic-gate 			unsigned long symoff, symsize;
345*0Sstevel@tonic-gate 			int rtype;
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate 			reloc = (Rela *)reladdr;
348*0Sstevel@tonic-gate 			off = reloc->r_offset;
349*0Sstevel@tonic-gate 			addend = (long)reloc->r_addend;
350*0Sstevel@tonic-gate 			rtype = ELF_R_TYPE(reloc->r_info);
351*0Sstevel@tonic-gate 			stndx = ELF_R_SYM(reloc->r_info);
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate 			reladdr += relocsize;
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 			if (rtype == R_AMD64_NONE)
356*0Sstevel@tonic-gate 				continue;
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate 			off += baseaddr;
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 			symsize = ssp->sh_entsize;
361*0Sstevel@tonic-gate 			symoff = stndx * symsize;
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate 			/*
364*0Sstevel@tonic-gate 			 * Check for bad symbol index.
365*0Sstevel@tonic-gate 			 */
366*0Sstevel@tonic-gate 			if (symoff > ssp->sh_size)
367*0Sstevel@tonic-gate 				return;
368*0Sstevel@tonic-gate 
369*0Sstevel@tonic-gate 			symref = (Sym *)(ssp->sh_addr + symoff);
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate 			/*
373*0Sstevel@tonic-gate 			 * Just bind our own symbols at this point.
374*0Sstevel@tonic-gate 			 */
375*0Sstevel@tonic-gate 			if (symref->st_shndx == SHN_UNDEF)
376*0Sstevel@tonic-gate 				continue;
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate 			value = symref->st_value;
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate 			if ((rtype == R_AMD64_PC32) ||
381*0Sstevel@tonic-gate 			    (rtype == R_AMD64_PLT32))
382*0Sstevel@tonic-gate 				/*
383*0Sstevel@tonic-gate 				 * If PC-relative, subtract ref addr.
384*0Sstevel@tonic-gate 				 */
385*0Sstevel@tonic-gate 				value -= off;
386*0Sstevel@tonic-gate 			else if (rtype == R_AMD64_32) {
387*0Sstevel@tonic-gate 				/*
388*0Sstevel@tonic-gate 				 * It's illegal to have any HIBITS
389*0Sstevel@tonic-gate 				 * set for R_AMD64_32 reloc.
390*0Sstevel@tonic-gate 				 */
391*0Sstevel@tonic-gate 				if (value & HIBITS) {
392*0Sstevel@tonic-gate 					BSVC_PUTCHAR(syscallp, 'h');
393*0Sstevel@tonic-gate 					return;
394*0Sstevel@tonic-gate 				}
395*0Sstevel@tonic-gate 			} else if (rtype == R_AMD64_32S) {
396*0Sstevel@tonic-gate 				/*
397*0Sstevel@tonic-gate 				 * All HIBITS for R_AMD64_32S
398*0Sstevel@tonic-gate 				 * *must* be set.
399*0Sstevel@tonic-gate 				 */
400*0Sstevel@tonic-gate 				if ((value & HIBITS) != HIBITS) {
401*0Sstevel@tonic-gate 					BSVC_PUTCHAR(syscallp, 'H');
402*0Sstevel@tonic-gate 					return;
403*0Sstevel@tonic-gate 				}
404*0Sstevel@tonic-gate 			}
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate 			offptr = (unsigned long *)off;
407*0Sstevel@tonic-gate 			/*
408*0Sstevel@tonic-gate 			 * insert value calculated at reference point
409*0Sstevel@tonic-gate 			 * 2 cases - normal byte order aligned, normal byte
410*0Sstevel@tonic-gate 			 * order unaligned.
411*0Sstevel@tonic-gate 			 */
412*0Sstevel@tonic-gate 			switch (rtype) {
413*0Sstevel@tonic-gate #if defined(__GNUC__)
414*0Sstevel@tonic-gate 			case 0x12345678:
415*0Sstevel@tonic-gate 				/*
416*0Sstevel@tonic-gate 				 * deliberately mess up the compilers
417*0Sstevel@tonic-gate 				 * temptation to create a jump table
418*0Sstevel@tonic-gate 				 */
419*0Sstevel@tonic-gate 				break;
420*0Sstevel@tonic-gate #endif
421*0Sstevel@tonic-gate 			case R_AMD64_64:
422*0Sstevel@tonic-gate 				*(unsigned long *)offptr = value + addend;
423*0Sstevel@tonic-gate 				break;
424*0Sstevel@tonic-gate 			case R_AMD64_PC32:
425*0Sstevel@tonic-gate 			case R_AMD64_32S:
426*0Sstevel@tonic-gate 			case R_AMD64_PLT32:
427*0Sstevel@tonic-gate 				*(uint_t *)offptr = (uint_t)(value + addend);
428*0Sstevel@tonic-gate 				break;
429*0Sstevel@tonic-gate 			case R_AMD64_GOT32:
430*0Sstevel@tonic-gate 				BSVC_PUTCHAR(syscallp, 'G');
431*0Sstevel@tonic-gate 				return;
432*0Sstevel@tonic-gate 			case R_AMD64_32:
433*0Sstevel@tonic-gate 				return;
434*0Sstevel@tonic-gate 			default:
435*0Sstevel@tonic-gate 				BSVC_PUTCHAR(syscallp, 'R');
436*0Sstevel@tonic-gate 				return;
437*0Sstevel@tonic-gate 			}
438*0Sstevel@tonic-gate 			/*
439*0Sstevel@tonic-gate 			 * We only need to do it once.
440*0Sstevel@tonic-gate 			 */
441*0Sstevel@tonic-gate 			reloc->r_info = ELF_R_INFO(stndx, R_AMD64_NONE);
442*0Sstevel@tonic-gate 		} /* while */
443*0Sstevel@tonic-gate 	}
444*0Sstevel@tonic-gate 
445*0Sstevel@tonic-gate 	/*
446*0Sstevel@tonic-gate 	 * Done relocating all of our *defined*
447*0Sstevel@tonic-gate 	 * symbols, so we hand off.
448*0Sstevel@tonic-gate 	 */
449*0Sstevel@tonic-gate 	kobj_init(syscallp, dvec, bootops, bootaux);
450*0Sstevel@tonic-gate }
451