17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21552ff457Srie 
227c478bd9Sstevel@tonic-gate /*
23bf994817SAli Bahrami  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #if	defined(_KERNEL)
277c478bd9Sstevel@tonic-gate #include	<sys/types.h>
287c478bd9Sstevel@tonic-gate #include	"reloc.h"
297c478bd9Sstevel@tonic-gate #else
30ba2be530Sab #define	ELF_TARGET_AMD64
31ba2be530Sab #if defined(DO_RELOC_LIBLD)
32ba2be530Sab #undef DO_RELOC_LIBLD
33ba2be530Sab #define	DO_RELOC_LIBLD_X86
34ba2be530Sab #endif
357c478bd9Sstevel@tonic-gate #include	<stdio.h>
367c478bd9Sstevel@tonic-gate #include	"sgs.h"
377c478bd9Sstevel@tonic-gate #include	"machdep.h"
387c478bd9Sstevel@tonic-gate #include	"libld.h"
397c478bd9Sstevel@tonic-gate #include	"reloc.h"
407c478bd9Sstevel@tonic-gate #include	"conv.h"
417c478bd9Sstevel@tonic-gate #include	"msg.h"
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
44ba2be530Sab /*
45ba2be530Sab  * We need to build this code differently when it is used for
46ba2be530Sab  * cross linking:
47ba2be530Sab  *	- Data alignment requirements can differ from those
48ba2be530Sab  *		of the running system, so we can't access data
49ba2be530Sab  *		in units larger than a byte
50ba2be530Sab  *	- We have to include code to do byte swapping when the
51ba2be530Sab  *		target and linker host use different byte ordering,
52ba2be530Sab  *		but such code is a waste when running natively.
53ba2be530Sab  */
5486ef0a63SRichard Lowe #if !defined(DO_RELOC_LIBLD) || defined(__x86)
55ba2be530Sab #define	DORELOC_NATIVE
56ba2be530Sab #endif
57ba2be530Sab 
587c478bd9Sstevel@tonic-gate /*
59552ff457Srie  * This table represents the current relocations that do_reloc() is able to
60552ff457Srie  * process.  The relocations below that are marked SPECIAL are relocations that
61552ff457Srie  * take special processing and shouldn't actually ever be passed to do_reloc().
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate const Rel_entry	reloc_table[R_AMD64_NUM] = {
64a530dbfeSRichard Lowe 	[R_AMD64_NONE]		= {0, FLG_RE_NOTREL, 0, 0, 0},
65a530dbfeSRichard Lowe 	[R_AMD64_64]		= {0, FLG_RE_NOTREL, 8, 0, 0},
66a530dbfeSRichard Lowe 	[R_AMD64_PC32]		= {0, FLG_RE_PCREL, 4, 0, 0},
67a530dbfeSRichard Lowe 	[R_AMD64_GOT32]		= {0, FLG_RE_NOTSUP, 0, 0, 0},
68a530dbfeSRichard Lowe 	[R_AMD64_PLT32]		= {0, FLG_RE_PCREL | FLG_RE_PLTREL |
69a530dbfeSRichard Lowe 	    FLG_RE_VERIFY | FLG_RE_SIGN, 4, 0, 0},
70a530dbfeSRichard Lowe 	[R_AMD64_COPY]		= {0, FLG_RE_NOTSUP, 0, 0, 0},	/* SPECIAL */
71a530dbfeSRichard Lowe 	[R_AMD64_GLOB_DAT]	= {0, FLG_RE_NOTREL, 8, 0, 0},
72a530dbfeSRichard Lowe 	[R_AMD64_JUMP_SLOT]	= {0, FLG_RE_NOTSUP, 0, 0, 0},	/* SPECIAL */
73a530dbfeSRichard Lowe 	[R_AMD64_RELATIVE]	= {0, FLG_RE_NOTREL, 8, 0, 0},
74a530dbfeSRichard Lowe 	[R_AMD64_GOTPCREL]	= {0, FLG_RE_GOTPC | FLG_RE_GOTADD, 4, 0, 0},
75a530dbfeSRichard Lowe 	[R_AMD64_32]		= {0, FLG_RE_NOTREL, 4, 0, 0},
76a530dbfeSRichard Lowe 	[R_AMD64_32S]		= {0, FLG_RE_NOTREL, 4, 0, 0},
77a530dbfeSRichard Lowe 	[R_AMD64_16]		= {0, FLG_RE_NOTREL, 2, 0, 0},
78a530dbfeSRichard Lowe 	[R_AMD64_PC16]		= {0, FLG_RE_PCREL, 2, 0, 0},
79a530dbfeSRichard Lowe 	[R_AMD64_8]		= {0, FLG_RE_NOTREL, 1, 0, 0},
80a530dbfeSRichard Lowe 	[R_AMD64_PC8]		= {0, FLG_RE_PCREL, 1, 0, 0},
81a530dbfeSRichard Lowe 	[R_AMD64_DTPMOD64]	= {0, FLG_RE_NOTREL, 8, 0, 0},
82a530dbfeSRichard Lowe 	[R_AMD64_DTPOFF64]	= {0, FLG_RE_NOTREL, 8, 0, 0},
83a530dbfeSRichard Lowe 	[R_AMD64_TPOFF64]	= {0, FLG_RE_NOTREL, 8, 0, 0},
84a530dbfeSRichard Lowe 	[R_AMD64_TLSGD]		= {0, FLG_RE_GOTPC | FLG_RE_GOTADD |
85a530dbfeSRichard Lowe 	    FLG_RE_TLSGD, 4, 0, 0},
86a530dbfeSRichard Lowe 	[R_AMD64_TLSLD]		= {0, FLG_RE_GOTPC | FLG_RE_GOTADD |
87a530dbfeSRichard Lowe 	    FLG_RE_TLSLD, 4, 0, 0},
88*11793bb3SToomas Soome 	[R_AMD64_DTPOFF32]	= {0, FLG_RE_TLSLD, 4, 0, 0},
89a530dbfeSRichard Lowe 	[R_AMD64_GOTTPOFF]	= {0, FLG_RE_GOTPC | FLG_RE_GOTADD |
90a530dbfeSRichard Lowe 	    FLG_RE_TLSIE, 4, 0, 0},
91a530dbfeSRichard Lowe 	[R_AMD64_TPOFF32]	= {0, FLG_RE_TLSLE, 4, 0, 0},
92a530dbfeSRichard Lowe 	[R_AMD64_PC64]		= {0, FLG_RE_PCREL, 8, 0, 0},
93a530dbfeSRichard Lowe 	[R_AMD64_GOTOFF64]	= {0, FLG_RE_GOTREL, 8, 0, 0},
94a530dbfeSRichard Lowe 	[R_AMD64_GOTPC32]	= {0, FLG_RE_PCREL | FLG_RE_GOTPC |
95a530dbfeSRichard Lowe 	    FLG_RE_LOCLBND, 4, 0, 0},
96a530dbfeSRichard Lowe 	[R_AMD64_GOT64]		= {0, FLG_RE_NOTSUP, 0, 0, 0},
97*11793bb3SToomas Soome 	[R_AMD64_GOTPCREL64]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
98a530dbfeSRichard Lowe 	[R_AMD64_GOTPC64]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
99a530dbfeSRichard Lowe 	[R_AMD64_GOTPLT64]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
100a530dbfeSRichard Lowe 	[R_AMD64_PLTOFF64]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
101a530dbfeSRichard Lowe 	[R_AMD64_SIZE32]	= {0, FLG_RE_SIZE, 4, 0, 0},
102a530dbfeSRichard Lowe 	[R_AMD64_SIZE64]	= {0, FLG_RE_SIZE, 8, 0, 0},
103a530dbfeSRichard Lowe 	[R_AMD64_GOTPC32_TLSDESC] = {0, FLG_RE_NOTSUP, 0, 0, 0},
104a530dbfeSRichard Lowe 	[R_AMD64_TLSDESC_CALL]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
105a530dbfeSRichard Lowe 	[R_AMD64_TLSDESC]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
106a530dbfeSRichard Lowe 	[R_AMD64_IRELATIVE]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
107a530dbfeSRichard Lowe 	[R_AMD64_RELATIVE64]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
108a530dbfeSRichard Lowe 	[R_AMD64_UNKNOWN39]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
109a530dbfeSRichard Lowe 	[R_AMD64_UNKNOWN40]	= {0, FLG_RE_NOTSUP, 0, 0, 0},
1102c4055ebSRichard Lowe 	[R_AMD64_GOTPCRELX]	= {0, FLG_RE_GOTPC | FLG_RE_GOTADD, 4, 0, 0},
1112c4055ebSRichard Lowe 	[R_AMD64_REX_GOTPCRELX]	= {0, FLG_RE_GOTPC | FLG_RE_GOTADD, 4, 0, 0},
1127c478bd9Sstevel@tonic-gate };
113a530dbfeSRichard Lowe #if	(R_AMD64_NUM != (R_AMD64_REX_GOTPCRELX + 1))
1147c478bd9Sstevel@tonic-gate #error	"R_AMD64_NUM has grown"
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Write a single relocated value to its reference location.
119552ff457Srie  * We assume we wish to add the relocation amount, value, to the
1207c478bd9Sstevel@tonic-gate  * value of the address already present at the offset.
1217c478bd9Sstevel@tonic-gate  *
122a530dbfeSRichard Lowe  * NAME				VALUE	FIELD		CALCULATION
1237c478bd9Sstevel@tonic-gate  *
124a530dbfeSRichard Lowe  * R_AMD64_NONE			 0	none		none
125a530dbfeSRichard Lowe  * R_AMD64_64			 1	word64		S + A
126a530dbfeSRichard Lowe  * R_AMD64_PC32			 2	word64		S + A
127a530dbfeSRichard Lowe  * R_AMD64_GOT32		 3	word32		G + A
128a530dbfeSRichard Lowe  * R_AMD64_PLT32		 4	word32		L + A - P
129a530dbfeSRichard Lowe  * R_AMD64_COPY			 5	none		none
130a530dbfeSRichard Lowe  * R_AMD64_GLOB_DAT		 6	word64		S
131a530dbfeSRichard Lowe  * R_AMD64_JUMP_SLOT		 7	word64		S
132a530dbfeSRichard Lowe  * R_AMD64_RELATIVE		 8	word64		B + A
133a530dbfeSRichard Lowe  * R_AMD64_GOTPCREL		 9	word32		G + GOT + A - P
134a530dbfeSRichard Lowe  * R_AMD64_32			10	word32		S + A
135a530dbfeSRichard Lowe  * R_AMD64_32S			11	word32		S + A
136a530dbfeSRichard Lowe  * R_AMD64_16			12	word16		S + A
137a530dbfeSRichard Lowe  * R_AMD64_PC16			13	word16		S + A - P
138a530dbfeSRichard Lowe  * R_AMD64_8			14	word8		S + A
139a530dbfeSRichard Lowe  * R_AMD64_PC8			15	word8		S + A - P
140a530dbfeSRichard Lowe  * R_AMD64_DTPMOD64		16	word64
141a530dbfeSRichard Lowe  * R_AMD64_DTPOFF64		17	word64
142a530dbfeSRichard Lowe  * R_AMD64_TPOFF64		18	word64
143a530dbfeSRichard Lowe  * R_AMD64_TLSGD		19	word32
144a530dbfeSRichard Lowe  * R_AMD64_TLSLD		20	word32
145a530dbfeSRichard Lowe  * R_AMD64_DTPOFF32		21	word32
146a530dbfeSRichard Lowe  * R_AMD64_GOTTPOFF		22	word32
147a530dbfeSRichard Lowe  * R_AMD64_TPOFF32		23	word32
148a530dbfeSRichard Lowe  * R_AMD64_PC64			24	word32		S + A - P
149a530dbfeSRichard Lowe  * R_AMD64_GOTOFF64		25	word32		S + A - GOT
150a530dbfeSRichard Lowe  * R_AMD64_GOTPC32		26	word32		GOT + A - P
151a530dbfeSRichard Lowe  * R_AMD64_GOT64		27			future expansion
152a530dbfeSRichard Lowe  * R_AMD64_GOTPCREL64		28			future expansion
153a530dbfeSRichard Lowe  * R_AMD64_GOTPC64		29			future expansion
154a530dbfeSRichard Lowe  * R_AMD64_GOTPLT64		30			future expansion
155a530dbfeSRichard Lowe  * R_AMD64_PLTOFF64		31			future expansion
156a530dbfeSRichard Lowe  * R_AMD64_SIZE32		32	word32		Z + A
157a530dbfeSRichard Lowe  * R_AMD64_SIZE64		33	word64		Z + A
158a530dbfeSRichard Lowe  * R_AMD64_GOTPC32_TLSDESC	34	word32
159a530dbfeSRichard Lowe  * R_AMD64_TLSDESC_CALL		35	none
160a530dbfeSRichard Lowe  * R_AMD64_TLSDESC		36	word64*2
161a530dbfeSRichard Lowe  * R_AMD64_IRELATIVE		37	word64		indirect (B + A)
162a530dbfeSRichard Lowe  * R_AMD64_RELATIVE64		38	word64		B + A
163a530dbfeSRichard Lowe  * R_AMD64_GOTPCRELX		41	word32		G + GOT + A - P
164a530dbfeSRichard Lowe  * R_AMD64_REX_GOTPCRELX	42	word32		G + GOT + A - P
1657c478bd9Sstevel@tonic-gate  *
1667c478bd9Sstevel@tonic-gate  * Relocation calculations:
1677c478bd9Sstevel@tonic-gate  *	A	Represents the addend used to compute the value of the
1687c478bd9Sstevel@tonic-gate  *		relocatable field.
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  *	B	Represents the base address at which a shared objects has
1717c478bd9Sstevel@tonic-gate  *		been loaded into memory during executaion.  Generally, a
1727c478bd9Sstevel@tonic-gate  *		shared objects is built with a 0 base virtual address,
1737c478bd9Sstevel@tonic-gate  *		but the execution address will be different.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  *	G	Represents the offset into the global offset table
1767c478bd9Sstevel@tonic-gate  *		at which the relocation entry's symbol will reside
1777c478bd9Sstevel@tonic-gate  *		during execution.
1787c478bd9Sstevel@tonic-gate  *
1797c478bd9Sstevel@tonic-gate  *	GOT	Rrepresents the address of the global offset table.
1807c478bd9Sstevel@tonic-gate  *
1817c478bd9Sstevel@tonic-gate  *	L	Represents the place (section offset or address) of
1827c478bd9Sstevel@tonic-gate  *		the Procedure Linkage Table entry for a symbol.
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  *	P	Represents the place (section offset or address) of the
1857c478bd9Sstevel@tonic-gate  *		storage unit being relocated (computed using r_offset).
1867c478bd9Sstevel@tonic-gate  *
1877c478bd9Sstevel@tonic-gate  *	S	Represents the value of the symbol whose index resides
1887c478bd9Sstevel@tonic-gate  *		in the relocation entry.
1892926dd2eSrie  *
1902926dd2eSrie  *	Z	the size of the symbol whose index resides in the relocation
1912926dd2eSrie  *		entry
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1946136c589SRichard Lowe 
1956136c589SRichard Lowe /*
1966136c589SRichard Lowe  * Bits that must be cleared or identical for a value to act as if extended in
1976136c589SRichard Lowe  * the given way.
1986136c589SRichard Lowe  */
1996136c589SRichard Lowe #define	ZEROEXBITS	0xffffffff00000000ULL
2006136c589SRichard Lowe #define	SIGNEXBITS	0xffffffff80000000ULL
2017c478bd9Sstevel@tonic-gate 
20286ef0a63SRichard Lowe /* BEGIN CSTYLED */
203f3324781Sab #if defined(_KERNEL)
204f3324781Sab #define	lml	0		/* Needed by arglist of REL_ERR_* macros */
2057c478bd9Sstevel@tonic-gate int
do_reloc_krtld(uchar_t rtype,uchar_t * off,Xword * value,const char * sym,const char * file)206f3324781Sab do_reloc_krtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
207f3324781Sab     const char *file)
208f3324781Sab #elif defined(DO_RELOC_LIBLD)
209ba2be530Sab /*ARGSUSED5*/
210f3324781Sab int
211bf994817SAli Bahrami do_reloc_ld(Rel_desc *rdesc, uchar_t *off, Xword *value,
212bf994817SAli Bahrami     rel_desc_sname_func_t rel_desc_sname_func,
213f3324781Sab     const char *file, int bswap, void *lml)
214f3324781Sab #else
215f3324781Sab int
216f3324781Sab do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
2175aefb655Srie     const char *file, void *lml)
218f3324781Sab #endif
2197c478bd9Sstevel@tonic-gate {
22086ef0a63SRichard Lowe /* END CSTYLED */
221bf994817SAli Bahrami #ifdef DO_RELOC_LIBLD
222bf994817SAli Bahrami #define	sym (* rel_desc_sname_func)(rdesc)
223bf994817SAli Bahrami 	uchar_t	rtype = rdesc->rel_rtype;
224bf994817SAli Bahrami #endif
2257c478bd9Sstevel@tonic-gate 	const Rel_entry	*rep;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	rep = &reloc_table[rtype];
2287c478bd9Sstevel@tonic-gate 
229552ff457Srie 	switch (rep->re_fsize) {
230552ff457Srie 	case 1:
231552ff457Srie 		/* LINTED */
232552ff457Srie 		*((uchar_t *)off) = (uchar_t)(*value);
233552ff457Srie 		break;
234ba2be530Sab 
235552ff457Srie 	case 2:
236ba2be530Sab #if defined(DORELOC_NATIVE)
237552ff457Srie 		/* LINTED */
238552ff457Srie 		*((Half *)off) = (Half)(*value);
239ba2be530Sab #else
240ba2be530Sab 		{
241ba2be530Sab 			Half	v = (Half)(*value);
242ba2be530Sab 			uchar_t	*v_bytes = (uchar_t *)&v;
243ba2be530Sab 
244ba2be530Sab 			if (bswap) {
245ba2be530Sab 				UL_ASSIGN_BSWAP_HALF(off, v_bytes);
246ba2be530Sab 			} else {
247ba2be530Sab 				UL_ASSIGN_HALF(off, v_bytes);
248ba2be530Sab 			}
249ba2be530Sab 		}
250ba2be530Sab #endif
251552ff457Srie 		break;
252ba2be530Sab 
253552ff457Srie 	case 4:
2547c478bd9Sstevel@tonic-gate 		/*
255552ff457Srie 		 * The amd64 psABI requires that we perform the following
256552ff457Srie 		 * verifications:
2577c478bd9Sstevel@tonic-gate 		 *
258552ff457Srie 		 *    The R_AMD64_32 and R_AMD64_32S relocations truncate the
259552ff457Srie 		 *    computed value to 32bits.  Verify that the generated value
260552ff457Srie 		 *    for the R_AMD64_32/32S relocation zero-extends (sign
261552ff457Srie 		 *    extends) to the original 64-bit value.
2627c478bd9Sstevel@tonic-gate 		 *
263552ff457Srie 		 * Also, the following relocations are all 32 bit PC relative
264552ff457Srie 		 * references.  Validate that the value being written will fit
265552ff457Srie 		 * in the field provided.
2667c478bd9Sstevel@tonic-gate 		 *
2672c4055ebSRichard Lowe 		 *    R_AMD64_PC32, R_AMD64_GOTPC32, R_AMD64_GOTPCREL,
2682c4055ebSRichard Lowe 		 *    R_AMD64_GOTPCRELX, R_AMD64_REX_GOTPCRELX.
2697c478bd9Sstevel@tonic-gate 		 */
2707c478bd9Sstevel@tonic-gate 		if (rtype == R_AMD64_32) {
2717c478bd9Sstevel@tonic-gate 			/*
2726136c589SRichard Lowe 			 * Verify that this value will act as a zero-extended
2736136c589SRichard Lowe 			 * unsigned 32 bit value.  That is, that the upper
2746136c589SRichard Lowe 			 * 32 bits are zero.
2757c478bd9Sstevel@tonic-gate 			 */
2766136c589SRichard Lowe 			if ((*value & ZEROEXBITS) != 0) {
2777c478bd9Sstevel@tonic-gate 				/*
278552ff457Srie 				 * To keep chkmsg() happy:
2797c478bd9Sstevel@tonic-gate 				 *  MSG_INTL(MSG_REL_NOFIT)
2807c478bd9Sstevel@tonic-gate 				 */
2815aefb655Srie 				REL_ERR_NOFIT(lml, file, sym, rtype, *value);
2827c478bd9Sstevel@tonic-gate 				return (0);
2837c478bd9Sstevel@tonic-gate 			}
284552ff457Srie 		} else if ((rtype == R_AMD64_32S) || (rtype == R_AMD64_PC32) ||
2852c4055ebSRichard Lowe 		    (rtype == R_AMD64_GOTPCREL) || (rtype == R_AMD64_GOTPC32) ||
2862c4055ebSRichard Lowe 		    (rtype == R_AMD64_GOTPCRELX) ||
2872c4055ebSRichard Lowe 		    (rtype == R_AMD64_REX_GOTPCRELX)) {
2887c478bd9Sstevel@tonic-gate 			/*
2896136c589SRichard Lowe 			 * Verify that this value will act as a sign-extended
2906136c589SRichard Lowe 			 * signed 32 bit value, that is that the upper 33 bits
2916136c589SRichard Lowe 			 * are either all zero or all one.
2927c478bd9Sstevel@tonic-gate 			 */
2936136c589SRichard Lowe 			if (((*value & SIGNEXBITS) != SIGNEXBITS) &&
2946136c589SRichard Lowe 			    ((*value & SIGNEXBITS) != 0)) {
2957c478bd9Sstevel@tonic-gate 				/*
296552ff457Srie 				 * To keep chkmsg() happy:
2977c478bd9Sstevel@tonic-gate 				 *  MSG_INTL(MSG_REL_NOFIT)
2987c478bd9Sstevel@tonic-gate 				 */
2995aefb655Srie 				REL_ERR_NOFIT(lml, file, sym, rtype, *value);
3007c478bd9Sstevel@tonic-gate 				return (0);
3017c478bd9Sstevel@tonic-gate 			}
3027c478bd9Sstevel@tonic-gate 		}
303ba2be530Sab 
304ba2be530Sab #if defined(DORELOC_NATIVE)
3057c478bd9Sstevel@tonic-gate 		/* LINTED */
3067c478bd9Sstevel@tonic-gate 		*((Word *)off) += *value;
307ba2be530Sab #else
308ba2be530Sab 		{
309ba2be530Sab 			Word	v;
310ba2be530Sab 			uchar_t	*v_bytes = (uchar_t *)&v;
311ba2be530Sab 
312ba2be530Sab 			if (bswap) {
313ba2be530Sab 				UL_ASSIGN_BSWAP_WORD(v_bytes, off);
314ba2be530Sab 				v += *value;
315ba2be530Sab 				UL_ASSIGN_BSWAP_WORD(off, v_bytes);
316ba2be530Sab 			} else {
317ba2be530Sab 				UL_ASSIGN_WORD(v_bytes, off);
318ba2be530Sab 				v += *value;
319ba2be530Sab 				UL_ASSIGN_WORD(off, v_bytes);
320ba2be530Sab 			}
321ba2be530Sab 		}
322ba2be530Sab #endif
323552ff457Srie 		break;
324ba2be530Sab 
325552ff457Srie 	case 8:
326ba2be530Sab #if defined(DORELOC_NATIVE)
327552ff457Srie 		/* LINTED */
3287c478bd9Sstevel@tonic-gate 		*((Xword *)off) += *value;
329ba2be530Sab #else
330ba2be530Sab 		{
331ba2be530Sab 			Xword	v;
332ba2be530Sab 			uchar_t	*v_bytes = (uchar_t *)&v;
333ba2be530Sab 
334ba2be530Sab 			if (bswap) {
335ba2be530Sab 				UL_ASSIGN_BSWAP_XWORD(v_bytes, off);
336ba2be530Sab 				v += *value;
337ba2be530Sab 				UL_ASSIGN_BSWAP_XWORD(off, v_bytes);
338ba2be530Sab 			} else {
339ba2be530Sab 				UL_ASSIGN_XWORD(v_bytes, off);
340ba2be530Sab 				v += *value;
341ba2be530Sab 				UL_ASSIGN_XWORD(off, v_bytes);
342ba2be530Sab 			}
343ba2be530Sab 		}
344ba2be530Sab #endif
345552ff457Srie 		break;
346552ff457Srie 	default:
347552ff457Srie 		/*
348552ff457Srie 		 * To keep chkmsg() happy: MSG_INTL(MSG_REL_UNSUPSZ)
349552ff457Srie 		 */
3505aefb655Srie 		REL_ERR_UNSUPSZ(lml, file, sym, rtype, rep->re_fsize);
3517c478bd9Sstevel@tonic-gate 		return (0);
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 	return (1);
354bf994817SAli Bahrami 
355bf994817SAli Bahrami #ifdef DO_RELOC_LIBLD
356bf994817SAli Bahrami #undef sym
357bf994817SAli Bahrami #endif
3587c478bd9Sstevel@tonic-gate }
359