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 */
215aefb655Srie
227c478bd9Sstevel@tonic-gate/*
2308278a5eSRod Evans * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate#include <memory.h>
277c478bd9Sstevel@tonic-gate#include <libelf.h>
287c478bd9Sstevel@tonic-gate#include <link.h>
297c478bd9Sstevel@tonic-gate#include <sys/elf_SPARC.h>
307c478bd9Sstevel@tonic-gate#include <sys/elf_amd64.h>
317c478bd9Sstevel@tonic-gate#include <decl.h>
327c478bd9Sstevel@tonic-gate#include <msg.h>
337c478bd9Sstevel@tonic-gate#include <sgs.h>
343228339cSAli Bahrami#include <stddef.h>
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate/*
377c478bd9Sstevel@tonic-gate * fmsize:  Array used to determine what size the the structures
387c478bd9Sstevel@tonic-gate *	    are (for memory image & file image).
397c478bd9Sstevel@tonic-gate *
407c478bd9Sstevel@tonic-gate * x64:  Translation routines - to file & to memory.
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate * What must be done when adding a new type for conversion:
437c478bd9Sstevel@tonic-gate *
447c478bd9Sstevel@tonic-gate * The first question is whether you need a new ELF_T_* type
457c478bd9Sstevel@tonic-gate * to be created.  If you've introduced a new structure - then
467c478bd9Sstevel@tonic-gate * it will need to be described - this is done by:
477c478bd9Sstevel@tonic-gate *
487c478bd9Sstevel@tonic-gate * o adding a new type ELF_T_* to usr/src/head/libelf.h
497c478bd9Sstevel@tonic-gate * o Create a new macro to define the bytes contained in the structure. Take a
507c478bd9Sstevel@tonic-gate *   look at the 'Syminfo_1' macro defined below.  The declarations describe
517c478bd9Sstevel@tonic-gate *   the structure based off of the field size of each element of the structure.
527c478bd9Sstevel@tonic-gate * o Add a entry to the fmsize table for the new ELF_T_* type.
537c478bd9Sstevel@tonic-gate * o Create a <newtype>_11_tof macro.  Take a look at 'syminfo_11_tof'.
547c478bd9Sstevel@tonic-gate * o Create a <newtype>_11_tom macro.  Take a look at 'syminfo_11_tom'.
557c478bd9Sstevel@tonic-gate * o The <newtype>_11_tof & <newtype>_11_tom results in conversion routines
567c478bd9Sstevel@tonic-gate *   <newtype>_2L11_tof, <newtype>_2L11_tom, <newtype>_2M11_tof,
577c478bd9Sstevel@tonic-gate *   <newtype>_2M11_tom being created in xlate.c.  These routines
587c478bd9Sstevel@tonic-gate *   need to be added to the 'x64[]' array.
597c478bd9Sstevel@tonic-gate * o Add entries to getdata.c::align32[] and getdata.c::align64[].  These
607c478bd9Sstevel@tonic-gate *   tables define what the alignment requirements for a data type are.
617c478bd9Sstevel@tonic-gate *
627c478bd9Sstevel@tonic-gate * In order to tie a section header type (SHT_*) to a data
637c478bd9Sstevel@tonic-gate * structure you need to update elf64_mtype() so that it can
647c478bd9Sstevel@tonic-gate * make the association.  If you are introducing a new section built
657c478bd9Sstevel@tonic-gate * on a basic datatype (SHT_INIT_ARRAY) then this is all the updating
667c478bd9Sstevel@tonic-gate * that needs to be done.
677c478bd9Sstevel@tonic-gate *
687c478bd9Sstevel@tonic-gate *
697c478bd9Sstevel@tonic-gate * ELF translation routines
707c478bd9Sstevel@tonic-gate *
717c478bd9Sstevel@tonic-gate *	These routines make a subtle implicit assumption.
727c478bd9Sstevel@tonic-gate *	The file representations of all structures are "packed,"
737c478bd9Sstevel@tonic-gate *	meaning no implicit padding bytes occur.  This might not
747c478bd9Sstevel@tonic-gate *	be the case for the memory representations.  Consequently,
757c478bd9Sstevel@tonic-gate *	the memory representations ALWAYS contain at least as many
767c478bd9Sstevel@tonic-gate *	bytes as the file representations.  Otherwise, the memory
777c478bd9Sstevel@tonic-gate *	structures would lose information, meaning they're not
787c478bd9Sstevel@tonic-gate *	implemented properly.
797c478bd9Sstevel@tonic-gate *
807c478bd9Sstevel@tonic-gate *	The words above apply to structures with the same members.
817c478bd9Sstevel@tonic-gate *	If a future version changes the number of members, the
827c478bd9Sstevel@tonic-gate *	relative structure sizes for different version must be
837c478bd9Sstevel@tonic-gate *	tested with the compiler.
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate#define	HI32	0x80000000UL
877c478bd9Sstevel@tonic-gate#define	LO31	0x7fffffffUL
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate#define	HI64	0x8000000000000000ULL
907c478bd9Sstevel@tonic-gate#define	LO63	0x7fffffffffffffffULL
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate/*
937c478bd9Sstevel@tonic-gate *	These macros create indexes for accessing the bytes of
947c478bd9Sstevel@tonic-gate *	words and halfwords for ELFCLASS64 data representations
957c478bd9Sstevel@tonic-gate *	(currently ELFDATA2LSB and ELFDATA2MSB).  In all cases,
967c478bd9Sstevel@tonic-gate *
977c478bd9Sstevel@tonic-gate *	x = ((((((((((((X_7 << 8) + X_6) << 8) + X_5) << 8) + X_4) << 8
987c478bd9Sstevel@tonic-gate *		+ X_3) << 8) + X_2) << 8) + X_1) << 8) + X_0
997c478bd9Sstevel@tonic-gate *	w = (((((X_3 << 8) + X_2) << 8) + X_1) << 8) + X_0
1007c478bd9Sstevel@tonic-gate *	h = (X_1 << 8) + X_0
1017c478bd9Sstevel@tonic-gate *
1027c478bd9Sstevel@tonic-gate *	These assume the file representations for Addr, Off,
1037c478bd9Sstevel@tonic-gate *	Sword, and Word use 4 bytes, but the memory def's for
1047c478bd9Sstevel@tonic-gate *	the types may differ.
1057c478bd9Sstevel@tonic-gate *
1067c478bd9Sstevel@tonic-gate *	Naming convention:
1077c478bd9Sstevel@tonic-gate *		..._L	ELFDATA2LSB
1087c478bd9Sstevel@tonic-gate *		..._M	ELFDATA2MSB
1097c478bd9Sstevel@tonic-gate *
1107c478bd9Sstevel@tonic-gate *	enuma_*(n)	define enum names for addr n
1117c478bd9Sstevel@tonic-gate *	enumb_*(n)	define enum names for byte n
1127c478bd9Sstevel@tonic-gate *	enumh_*(n)	define enum names for half n
1137c478bd9Sstevel@tonic-gate *	enumo_*(n)	define enum names for off n
1147c478bd9Sstevel@tonic-gate *	enumw_*(n)	define enum names for word n
1157c478bd9Sstevel@tonic-gate *	enumx_*(n)	define enum names for xword n
1167c478bd9Sstevel@tonic-gate *	enuml_*(n)	define enum names for Lword n
1177c478bd9Sstevel@tonic-gate *	tofa(d,s,n)	xlate addr n from mem s to file d
1187c478bd9Sstevel@tonic-gate *	tofb(d,s,n)	xlate byte n from mem s to file d
1197c478bd9Sstevel@tonic-gate *	tofh(d,s,n)	xlate half n from mem s to file d
1207c478bd9Sstevel@tonic-gate *	tofo(d,s,n)	xlate off n from mem s to file d
1217c478bd9Sstevel@tonic-gate *	tofw(d,s,n)	xlate word n from mem s to file d
1227c478bd9Sstevel@tonic-gate *	tofx(d,s,n)	xlate xword n from mem s to file d
1237c478bd9Sstevel@tonic-gate *	tofl(d,s,n)	xlate Lword n from mem s to file d
1247c478bd9Sstevel@tonic-gate *	toma(s,n)	xlate addr n from file s to expression value
1257c478bd9Sstevel@tonic-gate *	tomb(s,n)	xlate byte n from file s to expression value
1267c478bd9Sstevel@tonic-gate *	tomh(s,n)	xlate half n from file s to expression value
1277c478bd9Sstevel@tonic-gate *	tomo(s,n)	xlate off n from file s to expression value
1287c478bd9Sstevel@tonic-gate *	tomw(s,n)	xlate word n from file s to expression value
1297c478bd9Sstevel@tonic-gate *	tomx(s,n)	xlate xword n from file s to expression value
1307c478bd9Sstevel@tonic-gate *	toml(s,n)	xlate Lword n from file s to expression value
1317c478bd9Sstevel@tonic-gate *
1327c478bd9Sstevel@tonic-gate *	tof*() macros must move a multi-byte value into a temporary
1337c478bd9Sstevel@tonic-gate *	because ``in place'' conversions are allowed.  If a temp is not
1347c478bd9Sstevel@tonic-gate *	used for multi-byte objects, storing an initial destination byte
1357c478bd9Sstevel@tonic-gate *	may clobber a source byte not yet examined.
1367c478bd9Sstevel@tonic-gate *
1377c478bd9Sstevel@tonic-gate *	tom*() macros compute an expression value from the source
1387c478bd9Sstevel@tonic-gate *	without touching the destination; so they're safe.
1397c478bd9Sstevel@tonic-gate */
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gatedefine(enuma_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl
1427c478bd9Sstevel@tonic-gatedefine(enuma_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl
1437c478bd9Sstevel@tonic-gatedefine(enumb_L, `$1_L')dnl
1447c478bd9Sstevel@tonic-gatedefine(enumb_M, `$1_M')dnl
1457c478bd9Sstevel@tonic-gatedefine(enumh_L, `$1_L0, $1_L1')dnl
1467c478bd9Sstevel@tonic-gatedefine(enumh_M, `$1_M1, $1_M0')dnl
1477c478bd9Sstevel@tonic-gatedefine(enumo_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl
1487c478bd9Sstevel@tonic-gatedefine(enumo_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl
1497c478bd9Sstevel@tonic-gatedefine(enumw_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl
1507c478bd9Sstevel@tonic-gatedefine(enumw_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl
1517c478bd9Sstevel@tonic-gatedefine(enumx_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl
1527c478bd9Sstevel@tonic-gatedefine(enumx_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl
1537c478bd9Sstevel@tonic-gatedefine(enuml_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl
1547c478bd9Sstevel@tonic-gatedefine(enuml_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gatedefine(tofa, `{	Elf64_Addr _t_ = $2;
1577c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1587c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1597c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1607c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24),
1617c478bd9Sstevel@tonic-gate		($1)[$3`'4] = (Byte)(_t_>>32),
1627c478bd9Sstevel@tonic-gate		($1)[$3`'5] = (Byte)(_t_>>40),
1637c478bd9Sstevel@tonic-gate		($1)[$3`'6] = (Byte)(_t_>>48),
1647c478bd9Sstevel@tonic-gate		($1)[$3`'7] = (Byte)(_t_>>56); }')dnl
1657c478bd9Sstevel@tonic-gatedefine(tofb, `($1)[$3] = (Byte)($2)')dnl
1667c478bd9Sstevel@tonic-gatedefine(tofh, `{ Elf64_Half _t_ = $2;
1677c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1687c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8); }')dnl
1697c478bd9Sstevel@tonic-gatedefine(tofo, `{ Elf64_Off _t_ = $2;
1707c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1717c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1727c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1737c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24),
1747c478bd9Sstevel@tonic-gate		($1)[$3`'4] = (Byte)(_t_>>32),
1757c478bd9Sstevel@tonic-gate		($1)[$3`'5] = (Byte)(_t_>>40),
1767c478bd9Sstevel@tonic-gate		($1)[$3`'6] = (Byte)(_t_>>48),
1777c478bd9Sstevel@tonic-gate		($1)[$3`'7] = (Byte)(_t_>>56); }')dnl
1787c478bd9Sstevel@tonic-gatedefine(tofw, `{ Elf64_Word _t_ = $2;
1797c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1807c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1817c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1827c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24); }')dnl
1837c478bd9Sstevel@tonic-gatedefine(tofx, `{ Elf64_Xword _t_ = $2;
1847c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1857c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1867c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1877c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24),
1887c478bd9Sstevel@tonic-gate		($1)[$3`'4] = (Byte)(_t_>>32),
1897c478bd9Sstevel@tonic-gate		($1)[$3`'5] = (Byte)(_t_>>40),
1907c478bd9Sstevel@tonic-gate		($1)[$3`'6] = (Byte)(_t_>>48),
1917c478bd9Sstevel@tonic-gate		($1)[$3`'7] = (Byte)(_t_>>56); }')dnl
1927c478bd9Sstevel@tonic-gatedefine(tofl, `{ Elf64_Lword _t_ = $2;
1937c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1947c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1957c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1967c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24),
1977c478bd9Sstevel@tonic-gate		($1)[$3`'4] = (Byte)(_t_>>32),
1987c478bd9Sstevel@tonic-gate		($1)[$3`'5] = (Byte)(_t_>>40),
1997c478bd9Sstevel@tonic-gate		($1)[$3`'6] = (Byte)(_t_>>48),
2007c478bd9Sstevel@tonic-gate		($1)[$3`'7] = (Byte)(_t_>>56); }')dnl
201*7dbbfe77SToomas Soome
202*7dbbfe77SToomas Soomedefine(toma, `(((((((((((((((Elf64_Addr)($1)[$2`'7]<<8)
203*7dbbfe77SToomas Soome		+($1)[$2`'6])<<8)
204*7dbbfe77SToomas Soome		+($1)[$2`'5])<<8)
205*7dbbfe77SToomas Soome		+($1)[$2`'4])<<8)
206*7dbbfe77SToomas Soome		+($1)[$2`'3])<<8)
2077c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
2087c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
2097c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
2107c478bd9Sstevel@tonic-gatedefine(tomb, `((Byte)($1)[$2])')dnl
2117c478bd9Sstevel@tonic-gatedefine(tomh, `(((Elf64_Half)($1)[$2`'1]<<8)+($1)[$2`'0])')dnl
212*7dbbfe77SToomas Soomedefine(tomo, `(((((((((((((((Elf64_Off)($1)[$2`'7]<<8)
213*7dbbfe77SToomas Soome		+($1)[$2`'6])<<8)
214*7dbbfe77SToomas Soome		+($1)[$2`'5])<<8)
215*7dbbfe77SToomas Soome		+($1)[$2`'4])<<8)
216*7dbbfe77SToomas Soome		+($1)[$2`'3])<<8)
2177c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
2187c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
2197c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
2207c478bd9Sstevel@tonic-gatedefine(tomw, `(((((((Elf64_Word)($1)[$2`'3]<<8)
2217c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
2227c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
2237c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
224*7dbbfe77SToomas Soomedefine(tomx, `(((((((((((((((Elf64_Xword)($1)[$2`'7]<<8)
225*7dbbfe77SToomas Soome		+($1)[$2`'6])<<8)
226*7dbbfe77SToomas Soome		+($1)[$2`'5])<<8)
227*7dbbfe77SToomas Soome		+($1)[$2`'4])<<8)
228*7dbbfe77SToomas Soome		+($1)[$2`'3])<<8)
2297c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
2307c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
2317c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
232*7dbbfe77SToomas Soomedefine(toml, `(((((((((((((((Elf64_Lword)($1)[$2`'7]<<8)
233*7dbbfe77SToomas Soome		+($1)[$2`'6])<<8)
234*7dbbfe77SToomas Soome		+($1)[$2`'5])<<8)
235*7dbbfe77SToomas Soome		+($1)[$2`'4])<<8)
236*7dbbfe77SToomas Soome		+($1)[$2`'3])<<8)
2377c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
2387c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
2397c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate/*
2437c478bd9Sstevel@tonic-gate * ELF data object indexes
2447c478bd9Sstevel@tonic-gate *	The enums are broken apart to get around deficiencies
2457c478bd9Sstevel@tonic-gate *	in some compilers.
2467c478bd9Sstevel@tonic-gate */
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gatedefine(Addr, `
2497c478bd9Sstevel@tonic-gateenum
2507c478bd9Sstevel@tonic-gate{
2517c478bd9Sstevel@tonic-gate	enuma_$1(A)`'ifelse(`$2', `', `', `,
2527c478bd9Sstevel@tonic-gate	A_sizeof')
2537c478bd9Sstevel@tonic-gate};')
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gateAddr(L)
2567c478bd9Sstevel@tonic-gateAddr(M,1)
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gatedefine(Half, `
2607c478bd9Sstevel@tonic-gateenum
2617c478bd9Sstevel@tonic-gate{
2627c478bd9Sstevel@tonic-gate	enumh_$1(H)`'ifelse(`$2', `', `', `,
2637c478bd9Sstevel@tonic-gate	H_sizeof')
2647c478bd9Sstevel@tonic-gate};')
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gateHalf(L)
2677c478bd9Sstevel@tonic-gateHalf(M,1)
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gatedefine(Lword, `
2707c478bd9Sstevel@tonic-gateenum
2717c478bd9Sstevel@tonic-gate{
2727c478bd9Sstevel@tonic-gate	enuml_$1(L)`'ifelse(`$2', `', `', `,
2737c478bd9Sstevel@tonic-gate	L_sizeof')
2747c478bd9Sstevel@tonic-gate};')
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gateLword(L)
2777c478bd9Sstevel@tonic-gateLword(M,1)
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gatedefine(Move_1, `
2807c478bd9Sstevel@tonic-gateenum
2817c478bd9Sstevel@tonic-gate{
2827c478bd9Sstevel@tonic-gate	enuml_$1(M1_value),
2837c478bd9Sstevel@tonic-gate	enumx_$1(M1_info),
2847c478bd9Sstevel@tonic-gate	enumx_$1(M1_poffset),
2857c478bd9Sstevel@tonic-gate	enumh_$1(M1_repeat),
2867c478bd9Sstevel@tonic-gate	enumh_$1(M1_stride)`'ifelse(`$2', `', `', `,
2877c478bd9Sstevel@tonic-gate	M1_sizeof')
2887c478bd9Sstevel@tonic-gate};')
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gateMove_1(L)
2917c478bd9Sstevel@tonic-gateMove_1(M,1)
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gatedefine(MoveP_1, `
2957c478bd9Sstevel@tonic-gateenum
2967c478bd9Sstevel@tonic-gate{
2977c478bd9Sstevel@tonic-gate	enuml_$1(MP1_value),
2987c478bd9Sstevel@tonic-gate	enumx_$1(MP1_info),
2997c478bd9Sstevel@tonic-gate	enumx_$1(MP1_poffset),
3007c478bd9Sstevel@tonic-gate	enumh_$1(MP1_repeat),
3017c478bd9Sstevel@tonic-gate	enumh_$1(MP1_stride),
3027c478bd9Sstevel@tonic-gate	enumw_$1(MP1_padding)`'ifelse(`$2', `', `', `,
3037c478bd9Sstevel@tonic-gate	MP1_sizeof')
3047c478bd9Sstevel@tonic-gate};')
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gateMoveP_1(L)
3077c478bd9Sstevel@tonic-gateMoveP_1(M,1)
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gatedefine(Off, `
3117c478bd9Sstevel@tonic-gateenum
3127c478bd9Sstevel@tonic-gate{
3137c478bd9Sstevel@tonic-gate	enumo_$1(O)`'ifelse(`$2', `', `', `,
3147c478bd9Sstevel@tonic-gate	O_sizeof')
3157c478bd9Sstevel@tonic-gate};')
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gateOff(L)
3187c478bd9Sstevel@tonic-gateOff(M,1)
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gatedefine(Word, `
3227c478bd9Sstevel@tonic-gateenum
3237c478bd9Sstevel@tonic-gate{
3247c478bd9Sstevel@tonic-gate	enumw_$1(W)`'ifelse(`$2', `', `', `,
3257c478bd9Sstevel@tonic-gate	W_sizeof')
3267c478bd9Sstevel@tonic-gate};')
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gateWord(L)
3297c478bd9Sstevel@tonic-gateWord(M,1)
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gatedefine(Xword, `
3337c478bd9Sstevel@tonic-gateenum
3347c478bd9Sstevel@tonic-gate{
3357c478bd9Sstevel@tonic-gate	enumx_$1(X)`'ifelse(`$2',`', `', `,
3367c478bd9Sstevel@tonic-gate	X_sizeof')
3377c478bd9Sstevel@tonic-gate};')
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gateXword(L)
3407c478bd9Sstevel@tonic-gateXword(M,1)
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gatedefine(Dyn_1, `
3447c478bd9Sstevel@tonic-gateenum
3457c478bd9Sstevel@tonic-gate{
3467c478bd9Sstevel@tonic-gate	enumx_$1(D1_tag),
3477c478bd9Sstevel@tonic-gate	enumx_$1(D1_val)`'ifelse(`$2', `', `', `,
3487c478bd9Sstevel@tonic-gate	D1_sizeof')
3497c478bd9Sstevel@tonic-gate};')
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gateDyn_1(L)
3527c478bd9Sstevel@tonic-gateDyn_1(M,1)
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate#define	E1_Nident	16
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gatedefine(Ehdr_1, `
3587c478bd9Sstevel@tonic-gateenum {
3597c478bd9Sstevel@tonic-gate	ifelse(`$2', `', `E1_ident, ')E1_ident_$1_Z = E1_Nident - 1,
3607c478bd9Sstevel@tonic-gate	enumh_$1(E1_type),
3617c478bd9Sstevel@tonic-gate	enumh_$1(E1_machine),
3627c478bd9Sstevel@tonic-gate	enumw_$1(E1_version),
3637c478bd9Sstevel@tonic-gate	enuma_$1(E1_entry),
3647c478bd9Sstevel@tonic-gate	enumo_$1(E1_phoff),
3657c478bd9Sstevel@tonic-gate	enumo_$1(E1_shoff),
3667c478bd9Sstevel@tonic-gate	enumw_$1(E1_flags),
3677c478bd9Sstevel@tonic-gate	enumh_$1(E1_ehsize),
3687c478bd9Sstevel@tonic-gate	enumh_$1(E1_phentsize),
3697c478bd9Sstevel@tonic-gate	enumh_$1(E1_phnum),
3707c478bd9Sstevel@tonic-gate	enumh_$1(E1_shentsize),
3717c478bd9Sstevel@tonic-gate	enumh_$1(E1_shnum),
3727c478bd9Sstevel@tonic-gate	enumh_$1(E1_shstrndx)`'ifelse(`$2', `', `', `,
3737c478bd9Sstevel@tonic-gate	E1_sizeof')
3747c478bd9Sstevel@tonic-gate};')
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gateEhdr_1(L)
3777c478bd9Sstevel@tonic-gateEhdr_1(M,1)
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gatedefine(Nhdr_1, `
3807c478bd9Sstevel@tonic-gateenum
3817c478bd9Sstevel@tonic-gate{
3827c478bd9Sstevel@tonic-gate	enumw_$1(N1_namesz),
3837c478bd9Sstevel@tonic-gate	enumw_$1(N1_descsz),
3847c478bd9Sstevel@tonic-gate	enumw_$1(N1_type)`'ifelse(`$2', `', `', `,
3857c478bd9Sstevel@tonic-gate	N1_sizeof')
3867c478bd9Sstevel@tonic-gate};')
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gateNhdr_1(L)
3897c478bd9Sstevel@tonic-gateNhdr_1(M,1)
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gatedefine(Phdr_1, `
3927c478bd9Sstevel@tonic-gateenum
3937c478bd9Sstevel@tonic-gate{
3947c478bd9Sstevel@tonic-gate	enumw_$1(P1_type),
3957c478bd9Sstevel@tonic-gate	enumw_$1(P1_flags),
3967c478bd9Sstevel@tonic-gate	enumo_$1(P1_offset),
3977c478bd9Sstevel@tonic-gate	enuma_$1(P1_vaddr),
3987c478bd9Sstevel@tonic-gate	enuma_$1(P1_paddr),
3997c478bd9Sstevel@tonic-gate	enumx_$1(P1_filesz),
4007c478bd9Sstevel@tonic-gate	enumx_$1(P1_memsz),
4017c478bd9Sstevel@tonic-gate	enumx_$1(P1_align)`'ifelse(`$2', `', `', `,
4027c478bd9Sstevel@tonic-gate	P1_sizeof')
4037c478bd9Sstevel@tonic-gate};')
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gatePhdr_1(L)
4067c478bd9Sstevel@tonic-gatePhdr_1(M,1)
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gatedefine(Rel_1, `
4107c478bd9Sstevel@tonic-gateenum
4117c478bd9Sstevel@tonic-gate{
4127c478bd9Sstevel@tonic-gate	enuma_$1(R1_offset),
4137c478bd9Sstevel@tonic-gate	enumx_$1(R1_info)`'ifelse(`$2', `', `', `,
4147c478bd9Sstevel@tonic-gate	R1_sizeof')
4157c478bd9Sstevel@tonic-gate};')
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gateRel_1(L)
4187c478bd9Sstevel@tonic-gateRel_1(M,1)
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gatedefine(Rela_1, `
4227c478bd9Sstevel@tonic-gateenum
4237c478bd9Sstevel@tonic-gate{
4247c478bd9Sstevel@tonic-gate	enuma_$1(RA1_offset),
4257c478bd9Sstevel@tonic-gate	enumx_$1(RA1_info),
4267c478bd9Sstevel@tonic-gate	enumx_$1(RA1_addend)`'ifelse(`$2', `', `', `,
4277c478bd9Sstevel@tonic-gate	RA1_sizeof')
4287c478bd9Sstevel@tonic-gate};')
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gateRela_1(L)
4317c478bd9Sstevel@tonic-gateRela_1(M,1)
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gatedefine(Shdr_1, `
4357c478bd9Sstevel@tonic-gateenum
4367c478bd9Sstevel@tonic-gate{
4377c478bd9Sstevel@tonic-gate	enumw_$1(SH1_name),
4387c478bd9Sstevel@tonic-gate	enumw_$1(SH1_type),
4397c478bd9Sstevel@tonic-gate	enumx_$1(SH1_flags),
4407c478bd9Sstevel@tonic-gate	enuma_$1(SH1_addr),
4417c478bd9Sstevel@tonic-gate	enumo_$1(SH1_offset),
4427c478bd9Sstevel@tonic-gate	enumx_$1(SH1_size),
4437c478bd9Sstevel@tonic-gate	enumw_$1(SH1_link),
4447c478bd9Sstevel@tonic-gate	enumw_$1(SH1_info),
4457c478bd9Sstevel@tonic-gate	enumx_$1(SH1_addralign),
4467c478bd9Sstevel@tonic-gate	enumx_$1(SH1_entsize)`'ifelse(`$2', `', `', `,
4477c478bd9Sstevel@tonic-gate	SH1_sizeof')
4487c478bd9Sstevel@tonic-gate};')
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gateShdr_1(L)
4517c478bd9Sstevel@tonic-gateShdr_1(M,1)
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gatedefine(Sym_1, `
4557c478bd9Sstevel@tonic-gateenum
4567c478bd9Sstevel@tonic-gate{
4577c478bd9Sstevel@tonic-gate	enumw_$1(ST1_name),
4587c478bd9Sstevel@tonic-gate	enumb_$1(ST1_info),
4597c478bd9Sstevel@tonic-gate	enumb_$1(ST1_other),
4607c478bd9Sstevel@tonic-gate	enumh_$1(ST1_shndx),
4617c478bd9Sstevel@tonic-gate	enuma_$1(ST1_value),
4627c478bd9Sstevel@tonic-gate	enumx_$1(ST1_size)`'ifelse(`$2', `', `', `,
4637c478bd9Sstevel@tonic-gate	ST1_sizeof')
4647c478bd9Sstevel@tonic-gate};')
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gateSym_1(L)
4677c478bd9Sstevel@tonic-gateSym_1(M,1)
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gatedefine(Syminfo_1, `
4717c478bd9Sstevel@tonic-gateenum
4727c478bd9Sstevel@tonic-gate{
4737c478bd9Sstevel@tonic-gate	enumh_$1(SI1_boundto),
4747c478bd9Sstevel@tonic-gate	enumh_$1(SI1_flags)`'ifelse(`$2', `', `', `,
4757c478bd9Sstevel@tonic-gate	SI1_sizeof')
4767c478bd9Sstevel@tonic-gate};')
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gateSyminfo_1(L)
4797c478bd9Sstevel@tonic-gateSyminfo_1(M,1)
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gatedefine(Cap_1, `
4837c478bd9Sstevel@tonic-gateenum
4847c478bd9Sstevel@tonic-gate{
4857c478bd9Sstevel@tonic-gate	enumx_$1(C1_tag),
4867c478bd9Sstevel@tonic-gate	enumx_$1(C1_val)`'ifelse(`$2', `', `', `,
4877c478bd9Sstevel@tonic-gate	C1_sizeof')
4887c478bd9Sstevel@tonic-gate};')
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gateCap_1(L)
4917c478bd9Sstevel@tonic-gateCap_1(M,1)
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gatedefine(Verdef_1, `
4957c478bd9Sstevel@tonic-gateenum
4967c478bd9Sstevel@tonic-gate{
4977c478bd9Sstevel@tonic-gate	enumh_$1(VD1_version),
4987c478bd9Sstevel@tonic-gate	enumh_$1(VD1_flags),
4997c478bd9Sstevel@tonic-gate	enumh_$1(VD1_ndx),
5007c478bd9Sstevel@tonic-gate	enumh_$1(VD1_cnt),
5017c478bd9Sstevel@tonic-gate	enumw_$1(VD1_hash),
5027c478bd9Sstevel@tonic-gate	enumw_$1(VD1_aux),
5037c478bd9Sstevel@tonic-gate	enumw_$1(VD1_next)`'ifelse(`$2', `', `', `,
5047c478bd9Sstevel@tonic-gate	VD1_sizeof')
5057c478bd9Sstevel@tonic-gate};')
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gateVerdef_1(L)
5087c478bd9Sstevel@tonic-gateVerdef_1(M,1)
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gatedefine(Verdaux_1, `
5127c478bd9Sstevel@tonic-gateenum
5137c478bd9Sstevel@tonic-gate{
5147c478bd9Sstevel@tonic-gate	enumw_$1(VDA1_name),
5157c478bd9Sstevel@tonic-gate	enumw_$1(VDA1_next)`'ifelse(`$2', `', `', `,
5167c478bd9Sstevel@tonic-gate	VDA1_sizeof')
5177c478bd9Sstevel@tonic-gate};')
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gateVerdaux_1(L)
5207c478bd9Sstevel@tonic-gateVerdaux_1(M,1)
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gatedefine(Verneed_1, `
5247c478bd9Sstevel@tonic-gateenum
5257c478bd9Sstevel@tonic-gate{
5267c478bd9Sstevel@tonic-gate	enumh_$1(VN1_version),
5277c478bd9Sstevel@tonic-gate	enumh_$1(VN1_cnt),
5287c478bd9Sstevel@tonic-gate	enumw_$1(VN1_file),
5297c478bd9Sstevel@tonic-gate	enumw_$1(VN1_aux),
5307c478bd9Sstevel@tonic-gate	enumw_$1(VN1_next)`'ifelse(`$2', `', `', `,
5317c478bd9Sstevel@tonic-gate	VN1_sizeof')
5327c478bd9Sstevel@tonic-gate};')
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gateVerneed_1(L)
5357c478bd9Sstevel@tonic-gateVerneed_1(M,1)
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate
5387c478bd9Sstevel@tonic-gatedefine(Vernaux_1, `
5397c478bd9Sstevel@tonic-gateenum
5407c478bd9Sstevel@tonic-gate{
5417c478bd9Sstevel@tonic-gate	enumw_$1(VNA1_hash),
5427c478bd9Sstevel@tonic-gate	enumh_$1(VNA1_flags),
5437c478bd9Sstevel@tonic-gate	enumh_$1(VNA1_other),
5447c478bd9Sstevel@tonic-gate	enumw_$1(VNA1_name),
5457c478bd9Sstevel@tonic-gate	enumw_$1(VNA1_next)`'ifelse(`$2', `', `', `,
5467c478bd9Sstevel@tonic-gate	VNA1_sizeof')
5477c478bd9Sstevel@tonic-gate};')
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gateVernaux_1(L)
5507c478bd9Sstevel@tonic-gateVernaux_1(M,1)
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate/*
5547c478bd9Sstevel@tonic-gate *	Translation function declarations.
5557c478bd9Sstevel@tonic-gate *
5567c478bd9Sstevel@tonic-gate *		<object>_<data><dver><sver>_tof
5577c478bd9Sstevel@tonic-gate *		<object>_<data><dver><sver>_tom
5587c478bd9Sstevel@tonic-gate *	where
5597c478bd9Sstevel@tonic-gate *		<data>	2L	ELFDATA2LSB
5607c478bd9Sstevel@tonic-gate *			2M	ELFDATA2MSB
5617c478bd9Sstevel@tonic-gate */
5627c478bd9Sstevel@tonic-gate
5637c478bd9Sstevel@tonic-gatestatic void	addr_2L_tof(), addr_2L_tom(),
5647c478bd9Sstevel@tonic-gate		addr_2M_tof(), addr_2M_tom(),
5657c478bd9Sstevel@tonic-gate		byte_to(),
5667c478bd9Sstevel@tonic-gate		dyn_2L11_tof(), dyn_2L11_tom(),
5677c478bd9Sstevel@tonic-gate		dyn_2M11_tof(), dyn_2M11_tom(),
5687c478bd9Sstevel@tonic-gate		ehdr_2L11_tof(), ehdr_2L11_tom(),
5697c478bd9Sstevel@tonic-gate		ehdr_2M11_tof(), ehdr_2M11_tom(),
5707c478bd9Sstevel@tonic-gate		half_2L_tof(), half_2L_tom(),
5717c478bd9Sstevel@tonic-gate		half_2M_tof(), half_2M_tom(),
5727c478bd9Sstevel@tonic-gate		move_2L11_tof(), move_2L11_tom(),
5737c478bd9Sstevel@tonic-gate		move_2M11_tof(), move_2M11_tom(),
5747c478bd9Sstevel@tonic-gate		movep_2L11_tof(), movep_2L11_tom(),
5757c478bd9Sstevel@tonic-gate		movep_2M11_tof(), movep_2M11_tom(),
5767c478bd9Sstevel@tonic-gate		off_2L_tof(), off_2L_tom(),
5777c478bd9Sstevel@tonic-gate		off_2M_tof(), off_2M_tom(),
5787c478bd9Sstevel@tonic-gate		note_2L11_tof(), note_2L11_tom(),
5797c478bd9Sstevel@tonic-gate		note_2M11_tof(), note_2M11_tom(),
5807c478bd9Sstevel@tonic-gate		phdr_2L11_tof(), phdr_2L11_tom(),
5817c478bd9Sstevel@tonic-gate		phdr_2M11_tof(), phdr_2M11_tom(),
5827c478bd9Sstevel@tonic-gate		rel_2L11_tof(), rel_2L11_tom(),
5837c478bd9Sstevel@tonic-gate		rel_2M11_tof(), rel_2M11_tom(),
5847c478bd9Sstevel@tonic-gate		rela_2L11_tof(), rela_2L11_tom(),
5857c478bd9Sstevel@tonic-gate		rela_2M11_tof(), rela_2M11_tom(),
5867c478bd9Sstevel@tonic-gate		shdr_2L11_tof(), shdr_2L11_tom(),
5877c478bd9Sstevel@tonic-gate		shdr_2M11_tof(), shdr_2M11_tom(),
5887c478bd9Sstevel@tonic-gate		sword_2L_tof(), sword_2L_tom(),
5897c478bd9Sstevel@tonic-gate		sword_2M_tof(), sword_2M_tom(),
5907c478bd9Sstevel@tonic-gate		sym_2L11_tof(), sym_2L11_tom(),
5917c478bd9Sstevel@tonic-gate		sym_2M11_tof(), sym_2M11_tom(),
5927c478bd9Sstevel@tonic-gate		syminfo_2L11_tof(), syminfo_2L11_tom(),
5937c478bd9Sstevel@tonic-gate		syminfo_2M11_tof(), syminfo_2M11_tom(),
5947c478bd9Sstevel@tonic-gate		word_2L_tof(), word_2L_tom(),
5957c478bd9Sstevel@tonic-gate		word_2M_tof(), word_2M_tom(),
5967c478bd9Sstevel@tonic-gate		verdef_2L11_tof(), verdef_2L11_tom(),
5977c478bd9Sstevel@tonic-gate		verdef_2M11_tof(), verdef_2M11_tom(),
5987c478bd9Sstevel@tonic-gate		verneed_2L11_tof(), verneed_2L11_tom(),
5997c478bd9Sstevel@tonic-gate		verneed_2M11_tof(), verneed_2M11_tom(),
6007c478bd9Sstevel@tonic-gate		sxword_2L_tof(), sxword_2L_tom(),
6017c478bd9Sstevel@tonic-gate		sxword_2M_tof(), sxword_2M_tom(),
6027c478bd9Sstevel@tonic-gate		xword_2L_tof(), xword_2L_tom(),
6037c478bd9Sstevel@tonic-gate		xword_2M_tof(), xword_2M_tom(),
6047c478bd9Sstevel@tonic-gate		cap_2L11_tof(), cap_2L11_tom(),
6057c478bd9Sstevel@tonic-gate		cap_2M11_tof(), cap_2M11_tom();
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate/*
6097c478bd9Sstevel@tonic-gate *	x64 [dst_version - 1] [src_version - 1] [encode - 1] [type]
6107c478bd9Sstevel@tonic-gate */
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gatestatic struct {
6137c478bd9Sstevel@tonic-gate	void	(*x_tof)(),
6147c478bd9Sstevel@tonic-gate		(*x_tom)();
6157c478bd9Sstevel@tonic-gate} x64 [EV_CURRENT] [EV_CURRENT] [ELFDATANUM - 1] [ELF_T_NUM] = {
6167c478bd9Sstevel@tonic-gate	{
6177c478bd9Sstevel@tonic-gate		{
6187c478bd9Sstevel@tonic-gate			{			/* [1-1][1-1][2LSB-1][.] */
6197c478bd9Sstevel@tonic-gate/* BYTE */			{ byte_to, byte_to },
6207c478bd9Sstevel@tonic-gate/* ADDR */			{ addr_2L_tof, addr_2L_tom },
6217c478bd9Sstevel@tonic-gate/* DYN */			{ dyn_2L11_tof, dyn_2L11_tom },
6227c478bd9Sstevel@tonic-gate/* EHDR */			{ ehdr_2L11_tof, ehdr_2L11_tom },
6237c478bd9Sstevel@tonic-gate/* HALF */			{ half_2L_tof, half_2L_tom },
6247c478bd9Sstevel@tonic-gate/* OFF */			{ off_2L_tof, off_2L_tom },
6257c478bd9Sstevel@tonic-gate/* PHDR */			{ phdr_2L11_tof, phdr_2L11_tom },
6267c478bd9Sstevel@tonic-gate/* RELA */			{ rela_2L11_tof, rela_2L11_tom },
6277c478bd9Sstevel@tonic-gate/* REL */			{ rel_2L11_tof, rel_2L11_tom },
6287c478bd9Sstevel@tonic-gate/* SHDR */			{ shdr_2L11_tof, shdr_2L11_tom },
6297c478bd9Sstevel@tonic-gate/* SWORD */			{ sword_2L_tof, sword_2L_tom },
6307c478bd9Sstevel@tonic-gate/* SYM */			{ sym_2L11_tof, sym_2L11_tom },
6317c478bd9Sstevel@tonic-gate/* WORD */			{ word_2L_tof, word_2L_tom },
6327c478bd9Sstevel@tonic-gate/* VERDEF */			{ verdef_2L11_tof, verdef_2L11_tom},
6337c478bd9Sstevel@tonic-gate/* VERNEED */			{ verneed_2L11_tof, verneed_2L11_tom},
6347c478bd9Sstevel@tonic-gate/* SXWORD */			{ sxword_2L_tof, sxword_2L_tom },
6357c478bd9Sstevel@tonic-gate/* XWORD */			{ xword_2L_tof, xword_2L_tom },
6367c478bd9Sstevel@tonic-gate/* SYMINFO */			{ syminfo_2L11_tof, syminfo_2L11_tom },
6377c478bd9Sstevel@tonic-gate/* NOTE */			{ note_2L11_tof, note_2L11_tom },
6387c478bd9Sstevel@tonic-gate/* MOVE */			{ move_2L11_tof, move_2L11_tom },
6397c478bd9Sstevel@tonic-gate/* MOVEP */			{ movep_2L11_tof, movep_2L11_tom },
6407c478bd9Sstevel@tonic-gate/* CAP */			{ cap_2L11_tof, cap_2L11_tom },
6417c478bd9Sstevel@tonic-gate			},
6427c478bd9Sstevel@tonic-gate			{			/* [1-1][1-1][2MSB-1][.] */
6437c478bd9Sstevel@tonic-gate/* BYTE */			{ byte_to, byte_to },
6447c478bd9Sstevel@tonic-gate/* ADDR */			{ addr_2M_tof, addr_2M_tom },
6457c478bd9Sstevel@tonic-gate/* DYN */			{ dyn_2M11_tof, dyn_2M11_tom },
6467c478bd9Sstevel@tonic-gate/* EHDR */			{ ehdr_2M11_tof, ehdr_2M11_tom },
6477c478bd9Sstevel@tonic-gate/* HALF */			{ half_2M_tof, half_2M_tom },
6487c478bd9Sstevel@tonic-gate/* OFF */			{ off_2M_tof, off_2M_tom },
6497c478bd9Sstevel@tonic-gate/* PHDR */			{ phdr_2M11_tof, phdr_2M11_tom },
6507c478bd9Sstevel@tonic-gate/* RELA */			{ rela_2M11_tof, rela_2M11_tom },
6517c478bd9Sstevel@tonic-gate/* REL */			{ rel_2M11_tof, rel_2M11_tom },
6527c478bd9Sstevel@tonic-gate/* SHDR */			{ shdr_2M11_tof, shdr_2M11_tom },
6537c478bd9Sstevel@tonic-gate/* SWORD */			{ sword_2M_tof, sword_2M_tom },
6547c478bd9Sstevel@tonic-gate/* SYM */			{ sym_2M11_tof, sym_2M11_tom },
6557c478bd9Sstevel@tonic-gate/* WORD */			{ word_2M_tof, word_2M_tom },
6567c478bd9Sstevel@tonic-gate/* VERDEF */			{ verdef_2M11_tof, verdef_2M11_tom},
6577c478bd9Sstevel@tonic-gate/* VERNEED */			{ verneed_2M11_tof, verneed_2M11_tom},
6587c478bd9Sstevel@tonic-gate/* SXWORD */			{ sxword_2M_tof, sxword_2M_tom },
6597c478bd9Sstevel@tonic-gate/* XWORD */			{ xword_2M_tof, xword_2M_tom },
6607c478bd9Sstevel@tonic-gate/* SYMINFO */			{ syminfo_2M11_tof, syminfo_2M11_tom },
6617c478bd9Sstevel@tonic-gate/* NOTE */			{ note_2M11_tof, note_2M11_tom },
6627c478bd9Sstevel@tonic-gate/* MOVE */			{ move_2M11_tof, move_2M11_tom },
6637c478bd9Sstevel@tonic-gate/* MOVEP */			{ movep_2M11_tof, movep_2M11_tom },
6647c478bd9Sstevel@tonic-gate/* CAP */			{ cap_2M11_tof, cap_2M11_tom },
6657c478bd9Sstevel@tonic-gate			},
6667c478bd9Sstevel@tonic-gate		},
6677c478bd9Sstevel@tonic-gate	},
6687c478bd9Sstevel@tonic-gate};
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate/*
6727c478bd9Sstevel@tonic-gate *	size [version - 1] [type]
6737c478bd9Sstevel@tonic-gate */
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gatestatic const struct {
6767c478bd9Sstevel@tonic-gate	size_t	s_filesz,
6777c478bd9Sstevel@tonic-gate		s_memsz;
6787c478bd9Sstevel@tonic-gate} fmsize [EV_CURRENT] [ELF_T_NUM] =
6797c478bd9Sstevel@tonic-gate{
6807c478bd9Sstevel@tonic-gate	{					/* [1-1][.] */
6817c478bd9Sstevel@tonic-gate/* BYTE */	{ 1, 1 },
6827c478bd9Sstevel@tonic-gate/* ADDR */	{ A_sizeof, sizeof (Elf64_Addr) },
6837c478bd9Sstevel@tonic-gate/* DYN */	{ D1_sizeof, sizeof (Elf64_Dyn) },
6847c478bd9Sstevel@tonic-gate/* EHDR */	{ E1_sizeof, sizeof (Elf64_Ehdr) },
6857c478bd9Sstevel@tonic-gate/* HALF */	{ H_sizeof, sizeof (Elf64_Half) },
6867c478bd9Sstevel@tonic-gate/* OFF */	{ O_sizeof, sizeof (Elf64_Off) },
6877c478bd9Sstevel@tonic-gate/* PHDR */	{ P1_sizeof, sizeof (Elf64_Phdr) },
6887c478bd9Sstevel@tonic-gate/* RELA */	{ RA1_sizeof, sizeof (Elf64_Rela) },
6897c478bd9Sstevel@tonic-gate/* REL */	{ R1_sizeof, sizeof (Elf64_Rel) },
6907c478bd9Sstevel@tonic-gate/* SHDR */	{ SH1_sizeof, sizeof (Elf64_Shdr) },
6917c478bd9Sstevel@tonic-gate/* SWORD */	{ W_sizeof, sizeof (Elf64_Sword) },
6927c478bd9Sstevel@tonic-gate/* SYM */	{ ST1_sizeof, sizeof (Elf64_Sym) },
6937c478bd9Sstevel@tonic-gate/* WORD */	{ W_sizeof, sizeof (Elf64_Word) },
6947c478bd9Sstevel@tonic-gate/* VERDEF */	{ 1, 1 },	/* both VERDEF & VERNEED have varying size */
6957c478bd9Sstevel@tonic-gate/* VERNEED */	{ 1, 1 },	/* structures so we set their sizes to 1 */
6967c478bd9Sstevel@tonic-gate/* SXWORD */	{ X_sizeof, sizeof (Elf64_Sxword) },
6977c478bd9Sstevel@tonic-gate/* XWORD */	{ X_sizeof, sizeof (Elf64_Xword) },
6987c478bd9Sstevel@tonic-gate/* SYMINFO */	{ SI1_sizeof, sizeof (Elf64_Syminfo) },
6997c478bd9Sstevel@tonic-gate/* NOTE */	{ 1, 1},	/* NOTE has varying sized data we can't */
7007c478bd9Sstevel@tonic-gate				/*  use the usual table magic. */
7017c478bd9Sstevel@tonic-gate/* MOVE */	{ M1_sizeof, sizeof (Elf64_Move) },
7027c478bd9Sstevel@tonic-gate/* MOVEP */	{ MP1_sizeof, sizeof (Elf64_Move) },
7037c478bd9Sstevel@tonic-gate/* CAP */	{ C1_sizeof, sizeof (Elf64_Cap) },
7047c478bd9Sstevel@tonic-gate	},
7057c478bd9Sstevel@tonic-gate};
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate/*
7097c478bd9Sstevel@tonic-gate *	memory type [version - 1] [section type]
7107c478bd9Sstevel@tonic-gate */
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gatestatic const Elf_Type	mtype[EV_CURRENT][SHT_NUM] =
7137c478bd9Sstevel@tonic-gate{
7147c478bd9Sstevel@tonic-gate	{			/* [1-1][.] */
7157c478bd9Sstevel@tonic-gate/* NULL */		ELF_T_BYTE,
7167c478bd9Sstevel@tonic-gate/* PROGBITS */		ELF_T_BYTE,
7177c478bd9Sstevel@tonic-gate/* SYMTAB */		ELF_T_SYM,
7187c478bd9Sstevel@tonic-gate/* STRTAB */		ELF_T_BYTE,
7197c478bd9Sstevel@tonic-gate/* RELA */		ELF_T_RELA,
7207c478bd9Sstevel@tonic-gate/* HASH */		ELF_T_WORD,
7217c478bd9Sstevel@tonic-gate/* DYNAMIC */		ELF_T_DYN,
7227c478bd9Sstevel@tonic-gate/* NOTE */		ELF_T_NOTE,
7237c478bd9Sstevel@tonic-gate/* NOBITS */		ELF_T_BYTE,
7247c478bd9Sstevel@tonic-gate/* REL */		ELF_T_REL,
7257c478bd9Sstevel@tonic-gate/* SHLIB */		ELF_T_BYTE,
7267c478bd9Sstevel@tonic-gate/* DYNSYM */		ELF_T_SYM,
7277c478bd9Sstevel@tonic-gate/* UNKNOWN12 */		ELF_T_BYTE,
7287c478bd9Sstevel@tonic-gate/* UNKNOWN13 */		ELF_T_BYTE,
7297c478bd9Sstevel@tonic-gate/* INIT_ARRAY */	ELF_T_ADDR,
7307c478bd9Sstevel@tonic-gate/* FINI_ARRAY */	ELF_T_ADDR,
7317c478bd9Sstevel@tonic-gate/* PREINIT_ARRAY */	ELF_T_ADDR,
7327c478bd9Sstevel@tonic-gate/* GROUP */		ELF_T_WORD,
7337c478bd9Sstevel@tonic-gate/* SYMTAB_SHNDX */	ELF_T_WORD
7347c478bd9Sstevel@tonic-gate	},
7357c478bd9Sstevel@tonic-gate};
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gatesize_t
7397c478bd9Sstevel@tonic-gateelf64_fsize(Elf_Type type, size_t count, unsigned ver)
7407c478bd9Sstevel@tonic-gate{
7417c478bd9Sstevel@tonic-gate	if (--ver >= EV_CURRENT) {
7427c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_VER, 0);
7437c478bd9Sstevel@tonic-gate		return (0);
7447c478bd9Sstevel@tonic-gate	}
7457c478bd9Sstevel@tonic-gate	if ((unsigned)type >= ELF_T_NUM) {
7467c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_TYPE, 0);
7477c478bd9Sstevel@tonic-gate		return (0);
7487c478bd9Sstevel@tonic-gate	}
7497c478bd9Sstevel@tonic-gate	return (fmsize[ver][type].s_filesz * count);
7507c478bd9Sstevel@tonic-gate}
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gatesize_t
7547c478bd9Sstevel@tonic-gate_elf64_msize(Elf_Type type, unsigned ver)
7557c478bd9Sstevel@tonic-gate{
7567c478bd9Sstevel@tonic-gate	return (fmsize[ver - 1][type].s_memsz);
7577c478bd9Sstevel@tonic-gate}
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gateElf_Type
7617c478bd9Sstevel@tonic-gate/* ARGSUSED */
7627c478bd9Sstevel@tonic-gate_elf64_mtype(Elf * elf, Elf64_Word shtype, unsigned ver)
7637c478bd9Sstevel@tonic-gate{
7647c478bd9Sstevel@tonic-gate	Elf64_Ehdr *	ehdr = (Elf64_Ehdr *)elf->ed_ehdr;
7657c478bd9Sstevel@tonic-gate
7667c478bd9Sstevel@tonic-gate	if (shtype < SHT_NUM)
7677c478bd9Sstevel@tonic-gate		return (mtype[ver - 1][shtype]);
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate	switch (shtype) {
7707a5d89c4Sab	case SHT_SUNW_symsort:
7717a5d89c4Sab	case SHT_SUNW_tlssort:
7727a5d89c4Sab		return (ELF_T_WORD);
7737a5d89c4Sab	case SHT_SUNW_LDYNSYM:
7747a5d89c4Sab		return (ELF_T_SYM);
7757c478bd9Sstevel@tonic-gate	case SHT_SUNW_dof:
7767c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7777c478bd9Sstevel@tonic-gate	case SHT_SUNW_cap:
7787c478bd9Sstevel@tonic-gate		return (ELF_T_CAP);
77908278a5eSRod Evans	case SHT_SUNW_capchain:
78008278a5eSRod Evans		return (ELF_T_WORD);
78108278a5eSRod Evans	case SHT_SUNW_capinfo:
78208278a5eSRod Evans		return (ELF_T_XWORD);
7837c478bd9Sstevel@tonic-gate	case SHT_SUNW_SIGNATURE:
7847c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7857c478bd9Sstevel@tonic-gate	case SHT_SUNW_ANNOTATE:
7867c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7877c478bd9Sstevel@tonic-gate	case SHT_SUNW_DEBUGSTR:
7887c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7897c478bd9Sstevel@tonic-gate	case SHT_SUNW_DEBUG:
7907c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7917c478bd9Sstevel@tonic-gate	case SHT_SUNW_move:
7927c478bd9Sstevel@tonic-gate		/*
7937c478bd9Sstevel@tonic-gate		 * Right now - the only 64bit binaries I know
7947c478bd9Sstevel@tonic-gate		 * about with a move is SPARC - and SPARC
7957c478bd9Sstevel@tonic-gate		 * binaries pad the size of the move.
7967c478bd9Sstevel@tonic-gate		 */
7977c478bd9Sstevel@tonic-gate		return (ELF_T_MOVEP);
7987c478bd9Sstevel@tonic-gate	case SHT_SUNW_COMDAT:
7997c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
8007c478bd9Sstevel@tonic-gate	case SHT_SUNW_syminfo:
8017c478bd9Sstevel@tonic-gate		return (ELF_T_SYMINFO);
8027c478bd9Sstevel@tonic-gate	case SHT_SUNW_verdef:
8037c478bd9Sstevel@tonic-gate		return (ELF_T_VDEF);
8047c478bd9Sstevel@tonic-gate	case SHT_SUNW_verneed:
8057c478bd9Sstevel@tonic-gate		return (ELF_T_VNEED);
8067c478bd9Sstevel@tonic-gate	case SHT_SUNW_versym:
8077c478bd9Sstevel@tonic-gate		return (ELF_T_HALF);
8087c478bd9Sstevel@tonic-gate	};
8097c478bd9Sstevel@tonic-gate
8107c478bd9Sstevel@tonic-gate	/*
8117c478bd9Sstevel@tonic-gate	 * Check for the sparc specific section types
8127c478bd9Sstevel@tonic-gate	 * below.
8137c478bd9Sstevel@tonic-gate	 */
8147c478bd9Sstevel@tonic-gate	if (((ehdr->e_machine == EM_SPARC) ||
8157c478bd9Sstevel@tonic-gate	    (ehdr->e_machine == EM_SPARC32PLUS) ||
8167c478bd9Sstevel@tonic-gate	    (ehdr->e_machine == EM_SPARCV9)) &&
8177c478bd9Sstevel@tonic-gate	    (shtype == SHT_SPARC_GOTDATA))
8187c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate	/*
8217c478bd9Sstevel@tonic-gate	 * Check for the amd64 specific section types
8227c478bd9Sstevel@tonic-gate	 * below.
8237c478bd9Sstevel@tonic-gate	 */
8247c478bd9Sstevel@tonic-gate	if ((ehdr->e_machine == EM_AMD64) &&
8257c478bd9Sstevel@tonic-gate	    (shtype == SHT_AMD64_UNWIND))
8267c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate	/*
8297c478bd9Sstevel@tonic-gate	 * And the default is ELF_T_BYTE - but we should
8307c478bd9Sstevel@tonic-gate	 * certainly have caught any sections we know about
8317c478bd9Sstevel@tonic-gate	 * above.  This is for unknown sections to libelf.
8327c478bd9Sstevel@tonic-gate	 */
8337c478bd9Sstevel@tonic-gate	return (ELF_T_BYTE);
8347c478bd9Sstevel@tonic-gate}
8357c478bd9Sstevel@tonic-gate
8367c478bd9Sstevel@tonic-gate
8377a5d89c4Sabsize_t
8387a5d89c4Sab_elf64_entsz(Elf *elf, Elf64_Word shtype, unsigned ver)
8397a5d89c4Sab{
8407a5d89c4Sab	Elf_Type	ttype;
8417a5d89c4Sab
8427a5d89c4Sab	ttype = _elf64_mtype(elf, shtype, ver);
843*7dbbfe77SToomas Soome	return ((ttype == ELF_T_BYTE) ? 0 : fmsize[ver - 1][ttype].s_filesz);
8447a5d89c4Sab}
8457a5d89c4Sab
8467a5d89c4Sab
8477c478bd9Sstevel@tonic-gatestatic Elf_Data *
8487c478bd9Sstevel@tonic-gatexlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof)
8497c478bd9Sstevel@tonic-gate						/* !0 -> xlatetof */
8507c478bd9Sstevel@tonic-gate{
8517c478bd9Sstevel@tonic-gate	size_t		cnt, dsz, ssz;
8527c478bd9Sstevel@tonic-gate	unsigned	type;
8537c478bd9Sstevel@tonic-gate	unsigned	dver, sver;
8547c478bd9Sstevel@tonic-gate	void		(*f)();
8557c478bd9Sstevel@tonic-gate	unsigned	_encode;
8567c478bd9Sstevel@tonic-gate
8577c478bd9Sstevel@tonic-gate	if (dst == 0 || src == 0)
8587c478bd9Sstevel@tonic-gate		return (0);
8597c478bd9Sstevel@tonic-gate	if (--encode >= (ELFDATANUM - 1)) {
8607c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_ENCODE, 0);
8617c478bd9Sstevel@tonic-gate		return (0);
8627c478bd9Sstevel@tonic-gate	}
8637c478bd9Sstevel@tonic-gate	if ((dver = dst->d_version - 1) >= EV_CURRENT ||
8647c478bd9Sstevel@tonic-gate	    (sver = src->d_version - 1) >= EV_CURRENT) {
8657c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_VER, 0);
8667c478bd9Sstevel@tonic-gate		return (0);
8677c478bd9Sstevel@tonic-gate	}
8687c478bd9Sstevel@tonic-gate	if ((type = src->d_type) >= ELF_T_NUM) {
8697c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_TYPE, 0);
8707c478bd9Sstevel@tonic-gate		return (0);
8717c478bd9Sstevel@tonic-gate	}
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate	if (tof) {
8747c478bd9Sstevel@tonic-gate		dsz = fmsize[dver][type].s_filesz;
8757c478bd9Sstevel@tonic-gate		ssz = fmsize[sver][type].s_memsz;
8767c478bd9Sstevel@tonic-gate		f = x64[dver][sver][encode][type].x_tof;
8777c478bd9Sstevel@tonic-gate	} else {
8787c478bd9Sstevel@tonic-gate		dsz = fmsize[dver][type].s_memsz;
8797c478bd9Sstevel@tonic-gate		ssz = fmsize[sver][type].s_filesz;
8807c478bd9Sstevel@tonic-gate		f = x64[dver][sver][encode][type].x_tom;
8817c478bd9Sstevel@tonic-gate	}
8827c478bd9Sstevel@tonic-gate	cnt = src->d_size / ssz;
8837c478bd9Sstevel@tonic-gate	if (dst->d_size < dsz * cnt) {
8847c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_DSZ, 0);
8857c478bd9Sstevel@tonic-gate		return (0);
8867c478bd9Sstevel@tonic-gate	}
8877c478bd9Sstevel@tonic-gate
8887c478bd9Sstevel@tonic-gate	ELFACCESSDATA(_encode, _elf_encode)
8897c478bd9Sstevel@tonic-gate	if ((_encode == (encode + 1)) && (dsz == ssz)) {
8907c478bd9Sstevel@tonic-gate		/*
8917c478bd9Sstevel@tonic-gate		 *	ld(1) frequently produces empty sections (eg. .dynsym,
8927c478bd9Sstevel@tonic-gate		 *	.dynstr, .symtab, .strtab, etc) so that the initial
8937c478bd9Sstevel@tonic-gate		 *	output image can be created of the correct size.  Later
8947c478bd9Sstevel@tonic-gate		 *	these sections are filled in with the associated data.
8957c478bd9Sstevel@tonic-gate		 *	So that we don't have to pre-allocate buffers for
8967c478bd9Sstevel@tonic-gate		 *	these segments, allow for the src destination to be 0.
8977c478bd9Sstevel@tonic-gate		 */
8987c478bd9Sstevel@tonic-gate		if (src->d_buf && src->d_buf != dst->d_buf)
8997c478bd9Sstevel@tonic-gate			(void) memcpy(dst->d_buf, src->d_buf, src->d_size);
9007c478bd9Sstevel@tonic-gate		dst->d_type = src->d_type;
9017c478bd9Sstevel@tonic-gate		dst->d_size = src->d_size;
9027c478bd9Sstevel@tonic-gate		return (dst);
9037c478bd9Sstevel@tonic-gate	}
9047c478bd9Sstevel@tonic-gate	if (cnt)
9057c478bd9Sstevel@tonic-gate		(*f)(dst->d_buf, src->d_buf, cnt);
9067c478bd9Sstevel@tonic-gate	dst->d_size = dsz * cnt;
9077c478bd9Sstevel@tonic-gate	dst->d_type = src->d_type;
9087c478bd9Sstevel@tonic-gate	return (dst);
9097c478bd9Sstevel@tonic-gate}
9107c478bd9Sstevel@tonic-gate
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gateElf_Data *
9137c478bd9Sstevel@tonic-gateelf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode)
9147c478bd9Sstevel@tonic-gate{
9157c478bd9Sstevel@tonic-gate	return (xlate(dst, src, encode, 1));
9167c478bd9Sstevel@tonic-gate}
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gateElf_Data *
9207c478bd9Sstevel@tonic-gateelf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode)
9217c478bd9Sstevel@tonic-gate{
9227c478bd9Sstevel@tonic-gate	return (xlate(dst, src, encode, 0));
9237c478bd9Sstevel@tonic-gate}
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate/*
9277c478bd9Sstevel@tonic-gate * xlate to file format
9287c478bd9Sstevel@tonic-gate *
9297c478bd9Sstevel@tonic-gate *	..._tof(name, data) -- macros
9307c478bd9Sstevel@tonic-gate *
9317c478bd9Sstevel@tonic-gate *	Recall that the file format must be no larger than the
9327c478bd9Sstevel@tonic-gate *	memory format (equal versions).  Use "forward" copy.
9337c478bd9Sstevel@tonic-gate *	All these routines require non-null, non-zero arguments.
9347c478bd9Sstevel@tonic-gate */
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gatedefine(addr_tof, `
9377c478bd9Sstevel@tonic-gatestatic void
9387c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Addr *src, size_t cnt)
9397c478bd9Sstevel@tonic-gate{
9407c478bd9Sstevel@tonic-gate	Elf64_Addr	*end = src + cnt;
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate	do {
9437c478bd9Sstevel@tonic-gate		tofa(dst, *src, A_$2);
9447c478bd9Sstevel@tonic-gate		dst += A_sizeof;
9457c478bd9Sstevel@tonic-gate	} while (++src < end);
9467c478bd9Sstevel@tonic-gate}')
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gateaddr_tof(addr_2L_tof,L)
9497c478bd9Sstevel@tonic-gateaddr_tof(addr_2M_tof,M)
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate
9527c478bd9Sstevel@tonic-gatestatic void
9537c478bd9Sstevel@tonic-gatebyte_to(Byte *dst, Byte *src, size_t cnt)
9547c478bd9Sstevel@tonic-gate{
9557c478bd9Sstevel@tonic-gate	if (dst != src)
9567c478bd9Sstevel@tonic-gate		(void) memcpy(dst, src, cnt);
9577c478bd9Sstevel@tonic-gate}
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gatedefine(dyn_11_tof, `
9617c478bd9Sstevel@tonic-gatestatic void
9627c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Dyn *src, size_t cnt)
9637c478bd9Sstevel@tonic-gate{
9647c478bd9Sstevel@tonic-gate	Elf64_Dyn	*end = src + cnt;
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate	do {
9677c478bd9Sstevel@tonic-gate		tofx(dst, src->d_tag, D1_tag_$2);
9687c478bd9Sstevel@tonic-gate		tofx(dst, src->d_un.d_val, D1_val_$2);
9697c478bd9Sstevel@tonic-gate		dst += D1_sizeof;
9707c478bd9Sstevel@tonic-gate	} while (++src < end);
9717c478bd9Sstevel@tonic-gate}')
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gatedyn_11_tof(dyn_2L11_tof,L)
9747c478bd9Sstevel@tonic-gatedyn_11_tof(dyn_2M11_tof,M)
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gatedefine(ehdr_11_tof, `
9787c478bd9Sstevel@tonic-gatestatic void
9797c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Ehdr *src, size_t cnt)
9807c478bd9Sstevel@tonic-gate{
9817c478bd9Sstevel@tonic-gate	Elf64_Ehdr	*end = src + cnt;
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate	do {
9847c478bd9Sstevel@tonic-gate		if (&dst[E1_ident] != src->e_ident)
9857c478bd9Sstevel@tonic-gate			(void) memcpy(&dst[E1_ident], src->e_ident, E1_Nident);
9867c478bd9Sstevel@tonic-gate		tofh(dst, src->e_type, E1_type_$2);
9877c478bd9Sstevel@tonic-gate		tofh(dst, src->e_machine, E1_machine_$2);
9887c478bd9Sstevel@tonic-gate		tofw(dst, src->e_version, E1_version_$2);
9897c478bd9Sstevel@tonic-gate		tofa(dst, src->e_entry, E1_entry_$2);
9907c478bd9Sstevel@tonic-gate		tofo(dst, src->e_phoff, E1_phoff_$2);
9917c478bd9Sstevel@tonic-gate		tofo(dst, src->e_shoff, E1_shoff_$2);
9927c478bd9Sstevel@tonic-gate		tofw(dst, src->e_flags, E1_flags_$2);
9937c478bd9Sstevel@tonic-gate		tofh(dst, src->e_ehsize, E1_ehsize_$2);
9947c478bd9Sstevel@tonic-gate		tofh(dst, src->e_phentsize, E1_phentsize_$2);
9957c478bd9Sstevel@tonic-gate		tofh(dst, src->e_phnum, E1_phnum_$2);
9967c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shentsize, E1_shentsize_$2);
9977c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shnum, E1_shnum_$2);
9987c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shstrndx, E1_shstrndx_$2);
9997c478bd9Sstevel@tonic-gate		dst += E1_sizeof;
10007c478bd9Sstevel@tonic-gate	} while (++src < end);
10017c478bd9Sstevel@tonic-gate}')
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gateehdr_11_tof(ehdr_2L11_tof,L)
10047c478bd9Sstevel@tonic-gateehdr_11_tof(ehdr_2M11_tof,M)
10057c478bd9Sstevel@tonic-gate
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gatedefine(half_tof, `
10087c478bd9Sstevel@tonic-gatestatic void
10097c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Half *src, size_t cnt)
10107c478bd9Sstevel@tonic-gate{
10117c478bd9Sstevel@tonic-gate	Elf64_Half	*end = src + cnt;
10127c478bd9Sstevel@tonic-gate
10137c478bd9Sstevel@tonic-gate	do {
10147c478bd9Sstevel@tonic-gate		tofh(dst, *src, H_$2);
10157c478bd9Sstevel@tonic-gate		dst += H_sizeof;
10167c478bd9Sstevel@tonic-gate	} while (++src < end);
10177c478bd9Sstevel@tonic-gate}')
10187c478bd9Sstevel@tonic-gate
10197c478bd9Sstevel@tonic-gatehalf_tof(half_2L_tof,L)
10207c478bd9Sstevel@tonic-gatehalf_tof(half_2M_tof,M)
10217c478bd9Sstevel@tonic-gate
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gatedefine(move_11_tof, `
10247c478bd9Sstevel@tonic-gatestatic void
10257c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Move *src, size_t cnt)
10267c478bd9Sstevel@tonic-gate{
10277c478bd9Sstevel@tonic-gate	Elf64_Move	*end = src + cnt;
10287c478bd9Sstevel@tonic-gate
10297c478bd9Sstevel@tonic-gate	do {
10307c478bd9Sstevel@tonic-gate		tofl(dst, src->m_value, M1_value_$2);
10317c478bd9Sstevel@tonic-gate		tofw(dst, src->m_info, M1_info_$2);
10327c478bd9Sstevel@tonic-gate		tofw(dst, src->m_poffset, M1_poffset_$2);
10337c478bd9Sstevel@tonic-gate		tofh(dst, src->m_repeat, M1_repeat_$2);
10347c478bd9Sstevel@tonic-gate		tofh(dst, src->m_stride, M1_stride_$2);
10357c478bd9Sstevel@tonic-gate		dst += M1_sizeof;
10367c478bd9Sstevel@tonic-gate	} while (++src < end);
10377c478bd9Sstevel@tonic-gate}')
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gatemove_11_tof(move_2L11_tof,L)
10407c478bd9Sstevel@tonic-gatemove_11_tof(move_2M11_tof,M)
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gatedefine(movep_11_tof, `
10447c478bd9Sstevel@tonic-gatestatic void
10457c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Move *src, size_t cnt)
10467c478bd9Sstevel@tonic-gate{
10477c478bd9Sstevel@tonic-gate	Elf64_Move	*end = src + cnt;
10487c478bd9Sstevel@tonic-gate
10497c478bd9Sstevel@tonic-gate	do {
10507c478bd9Sstevel@tonic-gate		tofl(dst, src->m_value, MP1_value_$2);
10517c478bd9Sstevel@tonic-gate		tofw(dst, src->m_info, MP1_info_$2);
10527c478bd9Sstevel@tonic-gate		tofw(dst, src->m_poffset, MP1_poffset_$2);
10537c478bd9Sstevel@tonic-gate		tofh(dst, src->m_repeat, MP1_repeat_$2);
10547c478bd9Sstevel@tonic-gate		tofh(dst, src->m_stride, MP1_stride_$2);
10557c478bd9Sstevel@tonic-gate		dst += MP1_sizeof;
10567c478bd9Sstevel@tonic-gate	} while (++src < end);
10577c478bd9Sstevel@tonic-gate}')
10587c478bd9Sstevel@tonic-gate
10597c478bd9Sstevel@tonic-gatemovep_11_tof(movep_2L11_tof,L)
10607c478bd9Sstevel@tonic-gatemovep_11_tof(movep_2M11_tof,M)
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate
10637c478bd9Sstevel@tonic-gatedefine(off_tof, `
10647c478bd9Sstevel@tonic-gatestatic void
10657c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Off *src, size_t cnt)
10667c478bd9Sstevel@tonic-gate{
10677c478bd9Sstevel@tonic-gate	Elf64_Off	*end = src + cnt;
10687c478bd9Sstevel@tonic-gate
10697c478bd9Sstevel@tonic-gate	do {
10707c478bd9Sstevel@tonic-gate		tofo(dst, *src, O_$2);
10717c478bd9Sstevel@tonic-gate		dst += O_sizeof;
10727c478bd9Sstevel@tonic-gate	} while (++src < end);
10737c478bd9Sstevel@tonic-gate}')
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gateoff_tof(off_2L_tof,L)
10767c478bd9Sstevel@tonic-gateoff_tof(off_2M_tof,M)
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gatedefine(note_11_tof, `
10807c478bd9Sstevel@tonic-gatestatic void
10817c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Nhdr *src, size_t cnt)
10827c478bd9Sstevel@tonic-gate{
10837c478bd9Sstevel@tonic-gate	/* LINTED */
1084*7dbbfe77SToomas Soome	Elf64_Nhdr	*end = (Elf64_Nhdr *)((char *)src + cnt);
10857c478bd9Sstevel@tonic-gate
10863228339cSAli Bahrami	/*
10873228339cSAli Bahrami	 * Copy the note data to the source, translating the
10883228339cSAli Bahrami	 * length fields. Clip against the size of the actual buffer
10893228339cSAli Bahrami	 * to guard against corrupt note data.
10903228339cSAli Bahrami	 */
10917c478bd9Sstevel@tonic-gate	do {
10927c478bd9Sstevel@tonic-gate		Elf64_Word	descsz, namesz;
10937c478bd9Sstevel@tonic-gate
10947c478bd9Sstevel@tonic-gate		/*
10957c478bd9Sstevel@tonic-gate		 * cache size of desc & name fields - while rounding
10967c478bd9Sstevel@tonic-gate		 * up their size.
10977c478bd9Sstevel@tonic-gate		 */
10987c478bd9Sstevel@tonic-gate		namesz = S_ROUND(src->n_namesz, sizeof (Elf64_Word));
10997c478bd9Sstevel@tonic-gate		descsz = src->n_descsz;
11007c478bd9Sstevel@tonic-gate
11017c478bd9Sstevel@tonic-gate		/*
11027c478bd9Sstevel@tonic-gate		 * Copy contents of Elf64_Nhdr
11037c478bd9Sstevel@tonic-gate		 */
11043228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_namesz) + sizeof(Elf64_Word) +
11053228339cSAli Bahrami		    (char *) src) >= (char *) end)
11063228339cSAli Bahrami			break;
11077c478bd9Sstevel@tonic-gate		tofw(dst, src->n_namesz, N1_namesz_$2);
11083228339cSAli Bahrami
11093228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_descsz) + sizeof(Elf64_Word) +
11103228339cSAli Bahrami		    (char *) src) >= (char *) end)
11113228339cSAli Bahrami			break;
11127c478bd9Sstevel@tonic-gate		tofw(dst, src->n_descsz, N1_descsz_$2);
11133228339cSAli Bahrami
11143228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_type) + sizeof(Elf64_Word) +
11153228339cSAli Bahrami		    (char *) src) >= (char *) end)
11163228339cSAli Bahrami			break;
11177c478bd9Sstevel@tonic-gate		tofw(dst, src->n_type, N1_type_$2);
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate		/*
11207c478bd9Sstevel@tonic-gate		 * Copy contents of Name field
11217c478bd9Sstevel@tonic-gate		 */
11227c478bd9Sstevel@tonic-gate		dst += N1_sizeof;
11237c478bd9Sstevel@tonic-gate		src++;
11243228339cSAli Bahrami		if ((namesz + (char *) src) > (char *) end) {
11253228339cSAli Bahrami			namesz = (char *) end - (char *) src;
11263228339cSAli Bahrami			if (namesz == 0)
11273228339cSAli Bahrami				break;
11283228339cSAli Bahrami		}
11297c478bd9Sstevel@tonic-gate		(void)memcpy(dst, src, namesz);
11307c478bd9Sstevel@tonic-gate
11317c478bd9Sstevel@tonic-gate		/*
11327c478bd9Sstevel@tonic-gate		 * Copy contents of desc field
11337c478bd9Sstevel@tonic-gate		 */
11347c478bd9Sstevel@tonic-gate		dst += namesz;
11357c478bd9Sstevel@tonic-gate		src = (Elf64_Nhdr *)((uintptr_t)src + namesz);
11363228339cSAli Bahrami		if ((descsz + (char *) src) > (char *) end) {
11373228339cSAli Bahrami			descsz = (char *) end - (char *) src;
11383228339cSAli Bahrami			if (descsz == 0)
11393228339cSAli Bahrami				break;
11403228339cSAli Bahrami		}
11417c478bd9Sstevel@tonic-gate		(void)memcpy(dst, src, descsz);
11423228339cSAli Bahrami
11437c478bd9Sstevel@tonic-gate		descsz = S_ROUND(descsz, sizeof (Elf64_Word));
11447c478bd9Sstevel@tonic-gate		dst += descsz;
11457c478bd9Sstevel@tonic-gate		src = (Elf64_Nhdr *)((uintptr_t)src + descsz);
11467c478bd9Sstevel@tonic-gate	} while (src < end);
11477c478bd9Sstevel@tonic-gate}')
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gatenote_11_tof(note_2L11_tof,L)
11507c478bd9Sstevel@tonic-gatenote_11_tof(note_2M11_tof,M)
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gatedefine(phdr_11_tof, `
11547c478bd9Sstevel@tonic-gatestatic void
11557c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Phdr *src, size_t cnt)
11567c478bd9Sstevel@tonic-gate{
11577c478bd9Sstevel@tonic-gate	Elf64_Phdr	*end = src + cnt;
11587c478bd9Sstevel@tonic-gate
11597c478bd9Sstevel@tonic-gate	do {
11607c478bd9Sstevel@tonic-gate		tofw(dst, src->p_type, P1_type_$2);
11617c478bd9Sstevel@tonic-gate		tofw(dst, src->p_flags, P1_flags_$2);
11627c478bd9Sstevel@tonic-gate		tofo(dst, src->p_offset, P1_offset_$2);
11637c478bd9Sstevel@tonic-gate		tofa(dst, src->p_vaddr, P1_vaddr_$2);
11647c478bd9Sstevel@tonic-gate		tofa(dst, src->p_paddr, P1_paddr_$2);
11657c478bd9Sstevel@tonic-gate		tofx(dst, src->p_filesz, P1_filesz_$2);
11667c478bd9Sstevel@tonic-gate		tofx(dst, src->p_memsz, P1_memsz_$2);
11677c478bd9Sstevel@tonic-gate		tofx(dst, src->p_align, P1_align_$2);
11687c478bd9Sstevel@tonic-gate		dst += P1_sizeof;
11697c478bd9Sstevel@tonic-gate	} while (++src < end);
11707c478bd9Sstevel@tonic-gate}')
11717c478bd9Sstevel@tonic-gate
11727c478bd9Sstevel@tonic-gatephdr_11_tof(phdr_2L11_tof,L)
11737c478bd9Sstevel@tonic-gatephdr_11_tof(phdr_2M11_tof,M)
11747c478bd9Sstevel@tonic-gate
11757c478bd9Sstevel@tonic-gate
11767c478bd9Sstevel@tonic-gatedefine(rel_11_tof, `
11777c478bd9Sstevel@tonic-gatestatic void
11787c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Rel *src, size_t cnt)
11797c478bd9Sstevel@tonic-gate{
11807c478bd9Sstevel@tonic-gate	Elf64_Rel	*end = src + cnt;
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate	do {
11837c478bd9Sstevel@tonic-gate		tofa(dst, src->r_offset, R1_offset_$2);
11847c478bd9Sstevel@tonic-gate		tofx(dst, src->r_info, R1_info_$2);
11857c478bd9Sstevel@tonic-gate		dst += R1_sizeof;
11867c478bd9Sstevel@tonic-gate	} while (++src < end);
11877c478bd9Sstevel@tonic-gate}')
11887c478bd9Sstevel@tonic-gate
11897c478bd9Sstevel@tonic-gaterel_11_tof(rel_2L11_tof,L)
11907c478bd9Sstevel@tonic-gaterel_11_tof(rel_2M11_tof,M)
11917c478bd9Sstevel@tonic-gate
11927c478bd9Sstevel@tonic-gate
11937c478bd9Sstevel@tonic-gatedefine(rela_11_tof, `
11947c478bd9Sstevel@tonic-gatestatic void
11957c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Rela *src, size_t cnt)
11967c478bd9Sstevel@tonic-gate{
11977c478bd9Sstevel@tonic-gate	Elf64_Rela	*end = src + cnt;
11987c478bd9Sstevel@tonic-gate
11997c478bd9Sstevel@tonic-gate	do {
12007c478bd9Sstevel@tonic-gate		tofa(dst, src->r_offset, RA1_offset_$2);
12017c478bd9Sstevel@tonic-gate		tofx(dst, src->r_info, RA1_info_$2);
12027c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
12037c478bd9Sstevel@tonic-gate		if (~(Elf64_Xword)0 == -(Elf64_Sxword)1) {	/* 2s comp */
12047c478bd9Sstevel@tonic-gate			tofx(dst, src->r_addend, RA1_addend_$2);
12057c478bd9Sstevel@tonic-gate		} else {
12067c478bd9Sstevel@tonic-gate			Elf64_Xword	w;
12077c478bd9Sstevel@tonic-gate
12087c478bd9Sstevel@tonic-gate			if (src->r_addend < 0) {
12097c478bd9Sstevel@tonic-gate				w = - src->r_addend;
12107c478bd9Sstevel@tonic-gate				w = ~w + 1;
12117c478bd9Sstevel@tonic-gate			} else
12127c478bd9Sstevel@tonic-gate				w = src->r_addend;
12137c478bd9Sstevel@tonic-gate			tofx(dst, w, RA1_addend_$2);
12147c478bd9Sstevel@tonic-gate		}
12157c478bd9Sstevel@tonic-gate		dst += RA1_sizeof;
12167c478bd9Sstevel@tonic-gate	} while (++src < end);
12177c478bd9Sstevel@tonic-gate}')
12187c478bd9Sstevel@tonic-gate
12197c478bd9Sstevel@tonic-gaterela_11_tof(rela_2L11_tof,L)
12207c478bd9Sstevel@tonic-gaterela_11_tof(rela_2M11_tof,M)
12217c478bd9Sstevel@tonic-gate
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gatedefine(shdr_11_tof, `
12247c478bd9Sstevel@tonic-gatestatic void
12257c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Shdr *src, size_t cnt)
12267c478bd9Sstevel@tonic-gate{
12277c478bd9Sstevel@tonic-gate	Elf64_Shdr	*end = src + cnt;
12287c478bd9Sstevel@tonic-gate
12297c478bd9Sstevel@tonic-gate	do {
12307c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_name, SH1_name_$2);
12317c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_type, SH1_type_$2);
12327c478bd9Sstevel@tonic-gate		tofx(dst, src->sh_flags, SH1_flags_$2);
12337c478bd9Sstevel@tonic-gate		tofa(dst, src->sh_addr, SH1_addr_$2);
12347c478bd9Sstevel@tonic-gate		tofo(dst, src->sh_offset, SH1_offset_$2);
12357c478bd9Sstevel@tonic-gate		tofx(dst, src->sh_size, SH1_size_$2);
12367c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_link, SH1_link_$2);
12377c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_info, SH1_info_$2);
12387c478bd9Sstevel@tonic-gate		tofx(dst, src->sh_addralign, SH1_addralign_$2);
12397c478bd9Sstevel@tonic-gate		tofx(dst, src->sh_entsize, SH1_entsize_$2);
12407c478bd9Sstevel@tonic-gate		dst += SH1_sizeof;
12417c478bd9Sstevel@tonic-gate	} while (++src < end);
12427c478bd9Sstevel@tonic-gate}')
12437c478bd9Sstevel@tonic-gate
12447c478bd9Sstevel@tonic-gateshdr_11_tof(shdr_2L11_tof,L)
12457c478bd9Sstevel@tonic-gateshdr_11_tof(shdr_2M11_tof,M)
12467c478bd9Sstevel@tonic-gate
12477c478bd9Sstevel@tonic-gate
12487c478bd9Sstevel@tonic-gatedefine(sword_tof, `
12497c478bd9Sstevel@tonic-gatestatic void
12507c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Sword *src, size_t cnt)
12517c478bd9Sstevel@tonic-gate{
12527c478bd9Sstevel@tonic-gate	Elf64_Sword	*end = src + cnt;
12537c478bd9Sstevel@tonic-gate
12547c478bd9Sstevel@tonic-gate	do {
12557c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
12567c478bd9Sstevel@tonic-gate		if (~(Elf64_Word)0 == -(Elf64_Sword)1) {	/* 2s comp */
12577c478bd9Sstevel@tonic-gate			tofw(dst, *src, W_$2);
12587c478bd9Sstevel@tonic-gate		} else {
12597c478bd9Sstevel@tonic-gate			Elf64_Word	w;
12607c478bd9Sstevel@tonic-gate
12617c478bd9Sstevel@tonic-gate			if (*src < 0) {
12627c478bd9Sstevel@tonic-gate				w = - *src;
12637c478bd9Sstevel@tonic-gate				w = ~w + 1;
12647c478bd9Sstevel@tonic-gate			} else
12657c478bd9Sstevel@tonic-gate				w = *src;
12667c478bd9Sstevel@tonic-gate			tofw(dst, w, W_$2);
12677c478bd9Sstevel@tonic-gate		}
12687c478bd9Sstevel@tonic-gate		dst += W_sizeof;
12697c478bd9Sstevel@tonic-gate	} while (++src < end);
12707c478bd9Sstevel@tonic-gate}')
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gatesword_tof(sword_2L_tof,L)
12737c478bd9Sstevel@tonic-gatesword_tof(sword_2M_tof,M)
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gatedefine(cap_11_tof, `
12777c478bd9Sstevel@tonic-gatestatic void
12787c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Cap *src, size_t cnt)
12797c478bd9Sstevel@tonic-gate{
12807c478bd9Sstevel@tonic-gate	Elf64_Cap	*end = src + cnt;
12817c478bd9Sstevel@tonic-gate
12827c478bd9Sstevel@tonic-gate	do {
12837c478bd9Sstevel@tonic-gate		tofx(dst, src->c_tag, C1_tag_$2);
12847c478bd9Sstevel@tonic-gate		tofx(dst, src->c_un.c_val, C1_val_$2);
12857c478bd9Sstevel@tonic-gate		dst += C1_sizeof;
12867c478bd9Sstevel@tonic-gate	} while (++src < end);
12877c478bd9Sstevel@tonic-gate}')
12887c478bd9Sstevel@tonic-gate
12897c478bd9Sstevel@tonic-gatecap_11_tof(cap_2L11_tof,L)
12907c478bd9Sstevel@tonic-gatecap_11_tof(cap_2M11_tof,M)
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate
12937c478bd9Sstevel@tonic-gatedefine(syminfo_11_tof, `
12947c478bd9Sstevel@tonic-gatestatic void
12957c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Syminfo *src, size_t cnt)
12967c478bd9Sstevel@tonic-gate{
12977c478bd9Sstevel@tonic-gate	Elf64_Syminfo	*end = src + cnt;
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate	do {
13007c478bd9Sstevel@tonic-gate		tofh(dst, src->si_boundto, SI1_boundto_$2);
13017c478bd9Sstevel@tonic-gate		tofh(dst, src->si_flags, SI1_flags_$2);
13027c478bd9Sstevel@tonic-gate		dst += SI1_sizeof;
13037c478bd9Sstevel@tonic-gate	} while (++src < end);
13047c478bd9Sstevel@tonic-gate}')
13057c478bd9Sstevel@tonic-gate
13067c478bd9Sstevel@tonic-gatesyminfo_11_tof(syminfo_2L11_tof,L)
13077c478bd9Sstevel@tonic-gatesyminfo_11_tof(syminfo_2M11_tof,M)
13087c478bd9Sstevel@tonic-gate
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gatedefine(sym_11_tof, `
13117c478bd9Sstevel@tonic-gatestatic void
13127c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Sym *src, size_t cnt)
13137c478bd9Sstevel@tonic-gate{
13147c478bd9Sstevel@tonic-gate	Elf64_Sym	*end = src + cnt;
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate	do {
13177c478bd9Sstevel@tonic-gate		tofw(dst, src->st_name, ST1_name_$2);
13187c478bd9Sstevel@tonic-gate		tofb(dst, src->st_info, ST1_info_$2);
13197c478bd9Sstevel@tonic-gate		tofb(dst, src->st_other, ST1_other_$2);
13207c478bd9Sstevel@tonic-gate		tofh(dst, src->st_shndx, ST1_shndx_$2);
13217c478bd9Sstevel@tonic-gate		tofa(dst, src->st_value, ST1_value_$2);
13227c478bd9Sstevel@tonic-gate		tofx(dst, src->st_size, ST1_size_$2);
13237c478bd9Sstevel@tonic-gate		dst += ST1_sizeof;
13247c478bd9Sstevel@tonic-gate	} while (++src < end);
13257c478bd9Sstevel@tonic-gate}')
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gatesym_11_tof(sym_2L11_tof,L)
13287c478bd9Sstevel@tonic-gatesym_11_tof(sym_2M11_tof,M)
13297c478bd9Sstevel@tonic-gate
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gatedefine(word_tof, `
13327c478bd9Sstevel@tonic-gatestatic void
13337c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Word *src, size_t cnt)
13347c478bd9Sstevel@tonic-gate{
13357c478bd9Sstevel@tonic-gate	Elf64_Word	*end = src + cnt;
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate	do {
13387c478bd9Sstevel@tonic-gate		tofw(dst, *src, W_$2);
13397c478bd9Sstevel@tonic-gate		dst += W_sizeof;
13407c478bd9Sstevel@tonic-gate	} while (++src < end);
13417c478bd9Sstevel@tonic-gate}')
13427c478bd9Sstevel@tonic-gate
13437c478bd9Sstevel@tonic-gateword_tof(word_2L_tof,L)
13447c478bd9Sstevel@tonic-gateword_tof(word_2M_tof,M)
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate
13477c478bd9Sstevel@tonic-gatedefine(verdef_11_tof, `
13487c478bd9Sstevel@tonic-gatestatic void
13497c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Verdef *src, size_t cnt)
13507c478bd9Sstevel@tonic-gate{
13517c478bd9Sstevel@tonic-gate	/* LINTED */
13527c478bd9Sstevel@tonic-gate	Elf64_Verdef	*end = (Elf64_Verdef *)((Byte *)src + cnt);
13537c478bd9Sstevel@tonic-gate
13547c478bd9Sstevel@tonic-gate	do {
13557c478bd9Sstevel@tonic-gate		Elf64_Verdef	*next_verdef;
13567c478bd9Sstevel@tonic-gate		Elf64_Verdaux	*vaux;
13577c478bd9Sstevel@tonic-gate		Elf64_Half	i;
13587c478bd9Sstevel@tonic-gate		Byte		*vaux_dst;
13597c478bd9Sstevel@tonic-gate		Byte		*dst_next;
13607c478bd9Sstevel@tonic-gate
13617c478bd9Sstevel@tonic-gate		/* LINTED */
13627c478bd9Sstevel@tonic-gate		next_verdef = (Elf64_Verdef *)(src->vd_next ?
13637c478bd9Sstevel@tonic-gate		    (Byte *)src + src->vd_next : (Byte *)end);
13647c478bd9Sstevel@tonic-gate		dst_next = dst + src->vd_next;
13657c478bd9Sstevel@tonic-gate
13667c478bd9Sstevel@tonic-gate		/* LINTED */
13677c478bd9Sstevel@tonic-gate		vaux = (Elf64_Verdaux *)((Byte *)src + src->vd_aux);
13687c478bd9Sstevel@tonic-gate		vaux_dst = dst + src->vd_aux;
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate		/*
13717c478bd9Sstevel@tonic-gate		 * Convert auxilary structures
13727c478bd9Sstevel@tonic-gate		 */
13737c478bd9Sstevel@tonic-gate		for (i = 0; i < src->vd_cnt; i++) {
13747c478bd9Sstevel@tonic-gate			Elf64_Verdaux	*vaux_next;
13757c478bd9Sstevel@tonic-gate			Byte		*vaux_dst_next;
13767c478bd9Sstevel@tonic-gate
13777c478bd9Sstevel@tonic-gate			/*
13787c478bd9Sstevel@tonic-gate			 * because our source and destination can be
13797c478bd9Sstevel@tonic-gate			 * the same place we need to figure out the next
13807c478bd9Sstevel@tonic-gate			 * location now.
13817c478bd9Sstevel@tonic-gate			 */
13827c478bd9Sstevel@tonic-gate			/* LINTED */
13837c478bd9Sstevel@tonic-gate			vaux_next = (Elf64_Verdaux *)((Byte *)vaux +
13847c478bd9Sstevel@tonic-gate			    vaux->vda_next);
13857c478bd9Sstevel@tonic-gate			vaux_dst_next = vaux_dst + vaux->vda_next;
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vda_name, VDA1_name_$2);
13887c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vda_next, VDA1_next_$2);
13897c478bd9Sstevel@tonic-gate			vaux_dst = vaux_dst_next;
13907c478bd9Sstevel@tonic-gate			vaux = vaux_next;
13917c478bd9Sstevel@tonic-gate		}
13927c478bd9Sstevel@tonic-gate
13937c478bd9Sstevel@tonic-gate		/*
13947c478bd9Sstevel@tonic-gate		 * Convert Elf64_Verdef structure.
13957c478bd9Sstevel@tonic-gate		 */
13967c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_version, VD1_version_$2);
13977c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_flags, VD1_flags_$2);
13987c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_ndx, VD1_ndx_$2);
13997c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_cnt, VD1_cnt_$2);
14007c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_hash, VD1_hash_$2);
14017c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_aux, VD1_aux_$2);
14027c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_next, VD1_next_$2);
14037c478bd9Sstevel@tonic-gate		src = next_verdef;
14047c478bd9Sstevel@tonic-gate		dst = dst_next;
14057c478bd9Sstevel@tonic-gate	} while (src < end);
14067c478bd9Sstevel@tonic-gate}')
14077c478bd9Sstevel@tonic-gate
14087c478bd9Sstevel@tonic-gateverdef_11_tof(verdef_2L11_tof, L)
14097c478bd9Sstevel@tonic-gateverdef_11_tof(verdef_2M11_tof, M)
14107c478bd9Sstevel@tonic-gate
14117c478bd9Sstevel@tonic-gatedefine(verneed_11_tof, `
14127c478bd9Sstevel@tonic-gatestatic void
14137c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Verneed *src, size_t cnt)
14147c478bd9Sstevel@tonic-gate{
14157c478bd9Sstevel@tonic-gate	/* LINTED */
14167c478bd9Sstevel@tonic-gate	Elf64_Verneed	*end = (Elf64_Verneed *)((char *)src + cnt);
14177c478bd9Sstevel@tonic-gate
14187c478bd9Sstevel@tonic-gate	do {
14197c478bd9Sstevel@tonic-gate		Elf64_Verneed *	next_verneed;
14207c478bd9Sstevel@tonic-gate		Elf64_Vernaux *	vaux;
14217c478bd9Sstevel@tonic-gate		Elf64_Half	i;
14227c478bd9Sstevel@tonic-gate		Byte *		vaux_dst;
14237c478bd9Sstevel@tonic-gate		Byte *		dst_next;
14247c478bd9Sstevel@tonic-gate
14257c478bd9Sstevel@tonic-gate		/* LINTED */
14267c478bd9Sstevel@tonic-gate		next_verneed = (Elf64_Verneed *)(src->vn_next ?
14277c478bd9Sstevel@tonic-gate		    (Byte *)src + src->vn_next : (Byte *)end);
14287c478bd9Sstevel@tonic-gate		dst_next = dst + src->vn_next;
14297c478bd9Sstevel@tonic-gate
14307c478bd9Sstevel@tonic-gate		/* LINTED */
14317c478bd9Sstevel@tonic-gate		vaux = (Elf64_Vernaux *)((Byte *)src + src->vn_aux);
14327c478bd9Sstevel@tonic-gate		vaux_dst = dst + src->vn_aux;
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate		/*
14357c478bd9Sstevel@tonic-gate		 * Convert auxilary structures first
14367c478bd9Sstevel@tonic-gate		 */
14377c478bd9Sstevel@tonic-gate		for (i = 0; i < src->vn_cnt; i++) {
14387c478bd9Sstevel@tonic-gate			Elf64_Vernaux	*vaux_next;
14397c478bd9Sstevel@tonic-gate			Byte		*vaux_dst_next;
14407c478bd9Sstevel@tonic-gate
14417c478bd9Sstevel@tonic-gate			/*
14427c478bd9Sstevel@tonic-gate			 * because our source and destination can be
14437c478bd9Sstevel@tonic-gate			 * the same place we need to figure out the
14447c478bd9Sstevel@tonic-gate			 * next location now.
14457c478bd9Sstevel@tonic-gate			 */
14467c478bd9Sstevel@tonic-gate			/* LINTED */
14477c478bd9Sstevel@tonic-gate			vaux_next = (Elf64_Vernaux *)((Byte *)vaux +
14487c478bd9Sstevel@tonic-gate			    vaux->vna_next);
14497c478bd9Sstevel@tonic-gate			vaux_dst_next = vaux_dst + vaux->vna_next;
14507c478bd9Sstevel@tonic-gate
14517c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vna_hash, VNA1_hash_$2);
14527c478bd9Sstevel@tonic-gate			tofh(vaux_dst, vaux->vna_flags, VNA1_flags_$2);
14537c478bd9Sstevel@tonic-gate			tofh(vaux_dst, vaux->vna_other, VNA1_other_$2);
14547c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vna_name, VNA1_name_$2);
14557c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vna_next, VNA1_next_$2);
14567c478bd9Sstevel@tonic-gate			vaux_dst = vaux_dst_next;
14577c478bd9Sstevel@tonic-gate			vaux = vaux_next;
14587c478bd9Sstevel@tonic-gate		}
14597c478bd9Sstevel@tonic-gate
14607c478bd9Sstevel@tonic-gate		/*
14617c478bd9Sstevel@tonic-gate		 * Convert Elf64_Verneed structure.
14627c478bd9Sstevel@tonic-gate		 */
14637c478bd9Sstevel@tonic-gate		tofh(dst, src->vn_version, VN1_version_$2);
14647c478bd9Sstevel@tonic-gate		tofh(dst, src->vn_cnt, VN1_cnt_$2);
14657c478bd9Sstevel@tonic-gate		tofw(dst, src->vn_file, VN1_file_$2);
14667c478bd9Sstevel@tonic-gate		tofw(dst, src->vn_aux, VN1_aux_$2);
14677c478bd9Sstevel@tonic-gate		tofw(dst, src->vn_next, VN1_next_$2);
14687c478bd9Sstevel@tonic-gate		src = next_verneed;
14697c478bd9Sstevel@tonic-gate		dst = dst_next;
14707c478bd9Sstevel@tonic-gate	} while (src < end);
14717c478bd9Sstevel@tonic-gate}')
14727c478bd9Sstevel@tonic-gate
14737c478bd9Sstevel@tonic-gateverneed_11_tof(verneed_2L11_tof, L)
14747c478bd9Sstevel@tonic-gateverneed_11_tof(verneed_2M11_tof, M)
14757c478bd9Sstevel@tonic-gate
14767c478bd9Sstevel@tonic-gate
14777c478bd9Sstevel@tonic-gatedefine(sxword_tof, `
14787c478bd9Sstevel@tonic-gatestatic void
14797c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Sxword *src, size_t cnt)
14807c478bd9Sstevel@tonic-gate{
14817c478bd9Sstevel@tonic-gate	Elf64_Sxword *end = src + cnt;
14827c478bd9Sstevel@tonic-gate
14837c478bd9Sstevel@tonic-gate	do {
14847c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
14857c478bd9Sstevel@tonic-gate		if (~(Elf64_Xword)0 == -(Elf64_Sxword)1) {	/* 2s comp */
14867c478bd9Sstevel@tonic-gate			tofx(dst, *src, X_$2);
14877c478bd9Sstevel@tonic-gate		}
14887c478bd9Sstevel@tonic-gate		else {					/* unknown */
14897c478bd9Sstevel@tonic-gate			Elf64_Xword w;
14907c478bd9Sstevel@tonic-gate
14917c478bd9Sstevel@tonic-gate			if (*src < 0) {
14927c478bd9Sstevel@tonic-gate				w = - *src;
14937c478bd9Sstevel@tonic-gate				w = ~w + 1;
14947c478bd9Sstevel@tonic-gate			} else
14957c478bd9Sstevel@tonic-gate				w = *src;
14967c478bd9Sstevel@tonic-gate			tofx(dst, w, X_$2);
14977c478bd9Sstevel@tonic-gate		}
14987c478bd9Sstevel@tonic-gate		dst += X_sizeof;
14997c478bd9Sstevel@tonic-gate	} while (++src < end);
15007c478bd9Sstevel@tonic-gate}')
15017c478bd9Sstevel@tonic-gate
15027c478bd9Sstevel@tonic-gatesxword_tof(sxword_2L_tof,L)
15037c478bd9Sstevel@tonic-gatesxword_tof(sxword_2M_tof,M)
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gate
15067c478bd9Sstevel@tonic-gatedefine(xword_tof, `
15077c478bd9Sstevel@tonic-gatestatic void
15087c478bd9Sstevel@tonic-gate$1(Byte *dst, Elf64_Xword *src, size_t cnt)
15097c478bd9Sstevel@tonic-gate{
15107c478bd9Sstevel@tonic-gate	Elf64_Xword *end = src + cnt;
15117c478bd9Sstevel@tonic-gate
15127c478bd9Sstevel@tonic-gate	do {
15137c478bd9Sstevel@tonic-gate		tofx(dst, *src, X_$2);
15147c478bd9Sstevel@tonic-gate		dst += X_sizeof;
15157c478bd9Sstevel@tonic-gate	} while (++src < end);
15167c478bd9Sstevel@tonic-gate}')
15177c478bd9Sstevel@tonic-gate
15187c478bd9Sstevel@tonic-gatexword_tof(xword_2L_tof,L)
15197c478bd9Sstevel@tonic-gatexword_tof(xword_2M_tof,M)
15207c478bd9Sstevel@tonic-gate
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gate/*
15237c478bd9Sstevel@tonic-gate * xlate to memory format
15247c478bd9Sstevel@tonic-gate *
15257c478bd9Sstevel@tonic-gate *	..._tom(name, data) -- macros
15267c478bd9Sstevel@tonic-gate *
15277c478bd9Sstevel@tonic-gate *	Recall that the memory format may be larger than the
15287c478bd9Sstevel@tonic-gate *	file format (equal versions).  Use "backward" copy.
15297c478bd9Sstevel@tonic-gate *	All these routines require non-null, non-zero arguments.
15307c478bd9Sstevel@tonic-gate */
15317c478bd9Sstevel@tonic-gate
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gatedefine(addr_tom, `
15347c478bd9Sstevel@tonic-gatestatic void
15357c478bd9Sstevel@tonic-gate$1(Elf64_Addr *dst, Byte *src, size_t cnt)
15367c478bd9Sstevel@tonic-gate{
15377c478bd9Sstevel@tonic-gate	Elf64_Addr	*end = dst;
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate	dst += cnt;
15407c478bd9Sstevel@tonic-gate	src += cnt * A_sizeof;
15417c478bd9Sstevel@tonic-gate	while (dst-- > end) {
15427c478bd9Sstevel@tonic-gate		src -= A_sizeof;
15437c478bd9Sstevel@tonic-gate		*dst = toma(src, A_$2);
15447c478bd9Sstevel@tonic-gate	}
15457c478bd9Sstevel@tonic-gate}')
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gateaddr_tom(addr_2L_tom,L)
15487c478bd9Sstevel@tonic-gateaddr_tom(addr_2M_tom,M)
15497c478bd9Sstevel@tonic-gate
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gatedefine(dyn_11_tom, `
15527c478bd9Sstevel@tonic-gatestatic void
15537c478bd9Sstevel@tonic-gate$1(Elf64_Dyn *dst, Byte *src, size_t cnt)
15547c478bd9Sstevel@tonic-gate{
15557c478bd9Sstevel@tonic-gate	Elf64_Dyn	*end = dst + cnt;
15567c478bd9Sstevel@tonic-gate
15577c478bd9Sstevel@tonic-gate	do {
15587c478bd9Sstevel@tonic-gate		dst->d_tag = tomx(src, D1_tag_$2);
15597c478bd9Sstevel@tonic-gate		dst->d_un.d_val = tomx(src, D1_val_$2);
15607c478bd9Sstevel@tonic-gate		src += D1_sizeof;
15617c478bd9Sstevel@tonic-gate	} while (++dst < end);
15627c478bd9Sstevel@tonic-gate}')
15637c478bd9Sstevel@tonic-gate
15647c478bd9Sstevel@tonic-gatedyn_11_tom(dyn_2L11_tom,L)
15657c478bd9Sstevel@tonic-gatedyn_11_tom(dyn_2M11_tom,M)
15667c478bd9Sstevel@tonic-gate
15677c478bd9Sstevel@tonic-gate
15687c478bd9Sstevel@tonic-gatedefine(ehdr_11_tom, `
15697c478bd9Sstevel@tonic-gatestatic void
15707c478bd9Sstevel@tonic-gate$1(Elf64_Ehdr *dst, Byte *src, size_t cnt)
15717c478bd9Sstevel@tonic-gate{
15727c478bd9Sstevel@tonic-gate	Elf64_Ehdr	*end = dst;
15737c478bd9Sstevel@tonic-gate
15747c478bd9Sstevel@tonic-gate	dst += cnt;
15757c478bd9Sstevel@tonic-gate	src += cnt * E1_sizeof;
15767c478bd9Sstevel@tonic-gate	while (dst-- > end) {
15777c478bd9Sstevel@tonic-gate		src -= E1_sizeof;
15787c478bd9Sstevel@tonic-gate		dst->e_shstrndx = tomh(src, E1_shstrndx_$2);
15797c478bd9Sstevel@tonic-gate		dst->e_shnum = tomh(src, E1_shnum_$2);
15807c478bd9Sstevel@tonic-gate		dst->e_shentsize = tomh(src, E1_shentsize_$2);
15817c478bd9Sstevel@tonic-gate		dst->e_phnum = tomh(src, E1_phnum_$2);
15827c478bd9Sstevel@tonic-gate		dst->e_phentsize = tomh(src, E1_phentsize_$2);
15837c478bd9Sstevel@tonic-gate		dst->e_ehsize = tomh(src, E1_ehsize_$2);
15847c478bd9Sstevel@tonic-gate		dst->e_flags = tomw(src, E1_flags_$2);
15857c478bd9Sstevel@tonic-gate		dst->e_shoff = tomo(src, E1_shoff_$2);
15867c478bd9Sstevel@tonic-gate		dst->e_phoff = tomo(src, E1_phoff_$2);
15877c478bd9Sstevel@tonic-gate		dst->e_entry = toma(src, E1_entry_$2);
15887c478bd9Sstevel@tonic-gate		dst->e_version = tomw(src, E1_version_$2);
15897c478bd9Sstevel@tonic-gate		dst->e_machine = tomh(src, E1_machine_$2);
15907c478bd9Sstevel@tonic-gate		dst->e_type = tomh(src, E1_type_$2);
15917c478bd9Sstevel@tonic-gate		if (dst->e_ident != &src[E1_ident])
15927c478bd9Sstevel@tonic-gate			(void) memcpy(dst->e_ident, &src[E1_ident], E1_Nident);
15937c478bd9Sstevel@tonic-gate	}
15947c478bd9Sstevel@tonic-gate}')
15957c478bd9Sstevel@tonic-gate
15967c478bd9Sstevel@tonic-gateehdr_11_tom(ehdr_2L11_tom,L)
15977c478bd9Sstevel@tonic-gateehdr_11_tom(ehdr_2M11_tom,M)
15987c478bd9Sstevel@tonic-gate
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gatedefine(half_tom, `
16017c478bd9Sstevel@tonic-gatestatic void
16027c478bd9Sstevel@tonic-gate$1(Elf64_Half *dst, Byte *src, size_t cnt)
16037c478bd9Sstevel@tonic-gate{
16047c478bd9Sstevel@tonic-gate	Elf64_Half	*end = dst;
16057c478bd9Sstevel@tonic-gate
16067c478bd9Sstevel@tonic-gate	dst += cnt;
16077c478bd9Sstevel@tonic-gate	src += cnt * H_sizeof;
16087c478bd9Sstevel@tonic-gate	while (dst-- > end) {
16097c478bd9Sstevel@tonic-gate		src -= H_sizeof;
16107c478bd9Sstevel@tonic-gate		*dst = tomh(src, H_$2);
16117c478bd9Sstevel@tonic-gate	}
16127c478bd9Sstevel@tonic-gate}')
16137c478bd9Sstevel@tonic-gate
16147c478bd9Sstevel@tonic-gatehalf_tom(half_2L_tom,L)
16157c478bd9Sstevel@tonic-gatehalf_tom(half_2M_tom,M)
16167c478bd9Sstevel@tonic-gate
16177c478bd9Sstevel@tonic-gate
16187c478bd9Sstevel@tonic-gatedefine(move_11_tom, `
16197c478bd9Sstevel@tonic-gatestatic void
16207c478bd9Sstevel@tonic-gate$1(Elf64_Move *dst, unsigned char *src, size_t cnt)
16217c478bd9Sstevel@tonic-gate{
16227c478bd9Sstevel@tonic-gate	Elf64_Move	*end = dst + cnt;
16237c478bd9Sstevel@tonic-gate
16247c478bd9Sstevel@tonic-gate	do {
16257c478bd9Sstevel@tonic-gate		dst->m_value = toml(src, M1_value_$2);
16267c478bd9Sstevel@tonic-gate		dst->m_info = tomw(src, M1_info_$2);
16277c478bd9Sstevel@tonic-gate		dst->m_poffset = tomw(src, M1_poffset_$2);
16287c478bd9Sstevel@tonic-gate		dst->m_repeat = tomh(src, M1_repeat_$2);
16297c478bd9Sstevel@tonic-gate		dst->m_stride = tomh(src, M1_stride_$2);
16307c478bd9Sstevel@tonic-gate		src += M1_sizeof;
16317c478bd9Sstevel@tonic-gate	} while (++dst < end);
16327c478bd9Sstevel@tonic-gate}')
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gatemove_11_tom(move_2L11_tom,L)
16357c478bd9Sstevel@tonic-gatemove_11_tom(move_2M11_tom,M)
16367c478bd9Sstevel@tonic-gate
16377c478bd9Sstevel@tonic-gate
16387c478bd9Sstevel@tonic-gatedefine(movep_11_tom, `
16397c478bd9Sstevel@tonic-gatestatic void
16407c478bd9Sstevel@tonic-gate$1(Elf64_Move *dst, unsigned char *src, size_t cnt)
16417c478bd9Sstevel@tonic-gate{
16427c478bd9Sstevel@tonic-gate	Elf64_Move	*end = dst + cnt;
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate	do
16457c478bd9Sstevel@tonic-gate	{
16467c478bd9Sstevel@tonic-gate		dst->m_value = toml(src, MP1_value_$2);
16477c478bd9Sstevel@tonic-gate		dst->m_info = tomw(src, MP1_info_$2);
16487c478bd9Sstevel@tonic-gate		dst->m_poffset = tomw(src, MP1_poffset_$2);
16497c478bd9Sstevel@tonic-gate		dst->m_repeat = tomh(src, MP1_repeat_$2);
16507c478bd9Sstevel@tonic-gate		dst->m_stride = tomh(src, MP1_stride_$2);
16517c478bd9Sstevel@tonic-gate		src += MP1_sizeof;
16527c478bd9Sstevel@tonic-gate	} while (++dst < end);
16537c478bd9Sstevel@tonic-gate}')
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gatemovep_11_tom(movep_2L11_tom,L)
16567c478bd9Sstevel@tonic-gatemovep_11_tom(movep_2M11_tom,M)
16577c478bd9Sstevel@tonic-gate
16587c478bd9Sstevel@tonic-gate
16597c478bd9Sstevel@tonic-gatedefine(note_11_tom, `
16607c478bd9Sstevel@tonic-gatestatic void
16617c478bd9Sstevel@tonic-gate$1(Elf64_Nhdr *dst, unsigned char *src, size_t cnt)
16627c478bd9Sstevel@tonic-gate{
16637c478bd9Sstevel@tonic-gate	/* LINTED */
16647c478bd9Sstevel@tonic-gate	Elf64_Nhdr	*end = (Elf64_Nhdr *)((char *)dst + cnt);
16657c478bd9Sstevel@tonic-gate
16663228339cSAli Bahrami	/*
16673228339cSAli Bahrami	 * Copy the note data to the destination, translating the
16683228339cSAli Bahrami	 * length fields. Clip against the size of the actual buffer
16693228339cSAli Bahrami	 * to guard against corrupt note data.
16703228339cSAli Bahrami	 */
16713228339cSAli Bahrami	while (dst < end) {
16723228339cSAli Bahrami		Elf64_Nhdr	*nhdr;
16733228339cSAli Bahrami		unsigned char	*namestr;
16743228339cSAli Bahrami		void		*desc;
16757c478bd9Sstevel@tonic-gate		Elf64_Word	field_sz;
16767c478bd9Sstevel@tonic-gate
16773228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_namesz) + sizeof(Elf64_Word) +
16783228339cSAli Bahrami		    (char *) dst) >= (char *) end)
16793228339cSAli Bahrami			break;
16807c478bd9Sstevel@tonic-gate		dst->n_namesz = tomw(src, N1_namesz_$2);
16813228339cSAli Bahrami
16823228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_descsz) + sizeof(Elf64_Word) +
16833228339cSAli Bahrami		    (char *) dst) >= (char *) end)
16843228339cSAli Bahrami			break;
16857c478bd9Sstevel@tonic-gate		dst->n_descsz = tomw(src, N1_descsz_$2);
16863228339cSAli Bahrami
16873228339cSAli Bahrami		if ((offsetof(Elf64_Nhdr, n_type) + sizeof(Elf64_Word) +
16883228339cSAli Bahrami		    (char *) dst) >= (char *) end)
16893228339cSAli Bahrami			break;
16907c478bd9Sstevel@tonic-gate		dst->n_type = tomw(src, N1_type_$2);
16917c478bd9Sstevel@tonic-gate		nhdr = dst;
16923228339cSAli Bahrami
16935aefb655Srie		/* LINTED */
16947c478bd9Sstevel@tonic-gate		dst = (Elf64_Nhdr *)((char *)dst + sizeof (Elf64_Nhdr));
16957c478bd9Sstevel@tonic-gate		namestr = src + N1_sizeof;
16967c478bd9Sstevel@tonic-gate		field_sz = S_ROUND(nhdr->n_namesz, sizeof (Elf64_Word));
16973228339cSAli Bahrami		if ((field_sz + (char *) dst) > (char *) end) {
16983228339cSAli Bahrami			field_sz = (char *) end - (char *) dst;
16993228339cSAli Bahrami			if (field_sz == 0)
17003228339cSAli Bahrami				break;
17013228339cSAli Bahrami		}
17027c478bd9Sstevel@tonic-gate		(void)memcpy((void *)dst, namestr, field_sz);
17037c478bd9Sstevel@tonic-gate		desc = namestr + field_sz;
17043228339cSAli Bahrami
17055aefb655Srie		/* LINTED */
17067c478bd9Sstevel@tonic-gate		dst = (Elf64_Nhdr *)((char *)dst + field_sz);
17077c478bd9Sstevel@tonic-gate		field_sz = nhdr->n_descsz;
17083228339cSAli Bahrami		if ((field_sz + (char *) dst) > (char *) end) {
17093228339cSAli Bahrami			field_sz = (char *) end - (char *) dst;
17103228339cSAli Bahrami			if (field_sz == 0)
17113228339cSAli Bahrami				break;
17123228339cSAli Bahrami		}
17137c478bd9Sstevel@tonic-gate		(void)memcpy(dst, desc, field_sz);
17147c478bd9Sstevel@tonic-gate		field_sz = S_ROUND(field_sz, sizeof (Elf64_Word));
17153228339cSAli Bahrami
17165aefb655Srie		/* LINTED */
17177c478bd9Sstevel@tonic-gate		dst = (Elf64_Nhdr *)((char *)dst + field_sz);
17187c478bd9Sstevel@tonic-gate		src = (unsigned char *)desc + field_sz;
17197c478bd9Sstevel@tonic-gate	}
17207c478bd9Sstevel@tonic-gate}')
17217c478bd9Sstevel@tonic-gate
17227c478bd9Sstevel@tonic-gatenote_11_tom(note_2L11_tom,L)
17237c478bd9Sstevel@tonic-gatenote_11_tom(note_2M11_tom,M)
17247c478bd9Sstevel@tonic-gate
17257c478bd9Sstevel@tonic-gatedefine(off_tom, `
17267c478bd9Sstevel@tonic-gatestatic void
17277c478bd9Sstevel@tonic-gate$1(Elf64_Off *dst, Byte *src, size_t cnt)
17287c478bd9Sstevel@tonic-gate{
17297c478bd9Sstevel@tonic-gate	Elf64_Off	*end = dst;
17307c478bd9Sstevel@tonic-gate
17317c478bd9Sstevel@tonic-gate	dst += cnt;
17327c478bd9Sstevel@tonic-gate	src += cnt * O_sizeof;
17337c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17347c478bd9Sstevel@tonic-gate		src -= O_sizeof;
17357c478bd9Sstevel@tonic-gate		*dst = tomo(src, O_$2);
17367c478bd9Sstevel@tonic-gate	}
17377c478bd9Sstevel@tonic-gate}')
17387c478bd9Sstevel@tonic-gate
17397c478bd9Sstevel@tonic-gateoff_tom(off_2L_tom,L)
17407c478bd9Sstevel@tonic-gateoff_tom(off_2M_tom,M)
17417c478bd9Sstevel@tonic-gate
17427c478bd9Sstevel@tonic-gate
17437c478bd9Sstevel@tonic-gatedefine(phdr_11_tom, `
17447c478bd9Sstevel@tonic-gatestatic void
17457c478bd9Sstevel@tonic-gate$1(Elf64_Phdr *dst, Byte *src, size_t cnt)
17467c478bd9Sstevel@tonic-gate{
17477c478bd9Sstevel@tonic-gate	Elf64_Phdr	*end = dst;
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate	dst += cnt;
17507c478bd9Sstevel@tonic-gate	src += cnt * P1_sizeof;
17517c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17527c478bd9Sstevel@tonic-gate		src -= P1_sizeof;
17537c478bd9Sstevel@tonic-gate		dst->p_align = tomx(src, P1_align_$2);
17547c478bd9Sstevel@tonic-gate		dst->p_memsz = tomx(src, P1_memsz_$2);
17557c478bd9Sstevel@tonic-gate		dst->p_filesz = tomx(src, P1_filesz_$2);
17567c478bd9Sstevel@tonic-gate		dst->p_paddr = toma(src, P1_paddr_$2);
17577c478bd9Sstevel@tonic-gate		dst->p_vaddr = toma(src, P1_vaddr_$2);
17587c478bd9Sstevel@tonic-gate		dst->p_offset = tomo(src, P1_offset_$2);
17597c478bd9Sstevel@tonic-gate		dst->p_flags = tomw(src, P1_flags_$2);
17607c478bd9Sstevel@tonic-gate		dst->p_type = tomw(src, P1_type_$2);
17617c478bd9Sstevel@tonic-gate	}
17627c478bd9Sstevel@tonic-gate}')
17637c478bd9Sstevel@tonic-gate
17647c478bd9Sstevel@tonic-gatephdr_11_tom(phdr_2L11_tom,L)
17657c478bd9Sstevel@tonic-gatephdr_11_tom(phdr_2M11_tom,M)
17667c478bd9Sstevel@tonic-gate
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gatedefine(rel_11_tom, `
17697c478bd9Sstevel@tonic-gatestatic void
17707c478bd9Sstevel@tonic-gate$1(Elf64_Rel *dst, Byte *src, size_t cnt)
17717c478bd9Sstevel@tonic-gate{
17727c478bd9Sstevel@tonic-gate	Elf64_Rel	*end = dst;
17737c478bd9Sstevel@tonic-gate
17747c478bd9Sstevel@tonic-gate	dst += cnt;
17757c478bd9Sstevel@tonic-gate	src += cnt * R1_sizeof;
17767c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17777c478bd9Sstevel@tonic-gate		src -= R1_sizeof;
17787c478bd9Sstevel@tonic-gate		dst->r_info = tomx(src, R1_info_$2);
17797c478bd9Sstevel@tonic-gate		dst->r_offset = toma(src, R1_offset_$2);
17807c478bd9Sstevel@tonic-gate	}
17817c478bd9Sstevel@tonic-gate}')
17827c478bd9Sstevel@tonic-gate
17837c478bd9Sstevel@tonic-gaterel_11_tom(rel_2L11_tom,L)
17847c478bd9Sstevel@tonic-gaterel_11_tom(rel_2M11_tom,M)
17857c478bd9Sstevel@tonic-gate
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gatedefine(rela_11_tom, `
17887c478bd9Sstevel@tonic-gatestatic void
17897c478bd9Sstevel@tonic-gate$1(Elf64_Rela *dst, Byte *src, size_t cnt)
17907c478bd9Sstevel@tonic-gate{
17917c478bd9Sstevel@tonic-gate	Elf64_Rela *end = dst;
17927c478bd9Sstevel@tonic-gate
17937c478bd9Sstevel@tonic-gate	dst += cnt;
17947c478bd9Sstevel@tonic-gate	src += cnt * RA1_sizeof;
17957c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17967c478bd9Sstevel@tonic-gate		src -= RA1_sizeof;
17977c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
17987c478bd9Sstevel@tonic-gate		if (~(Elf64_Xword)0 == -(Elf64_Sxword)1 &&	/* 2s comp */
17997c478bd9Sstevel@tonic-gate		    ~(~(Elf64_Xword)0 >> 1) == HI64) {
18007c478bd9Sstevel@tonic-gate			dst->r_addend = tomx(src, RA1_addend_$2);
18017c478bd9Sstevel@tonic-gate		} else {
18027c478bd9Sstevel@tonic-gate			union {
18037c478bd9Sstevel@tonic-gate				Elf64_Xword w;
18047c478bd9Sstevel@tonic-gate				Elf64_Sxword sw;
18057c478bd9Sstevel@tonic-gate			} u;
18067c478bd9Sstevel@tonic-gate
18077c478bd9Sstevel@tonic-gate			if ((u.w = tomx(src, RA1_addend_$2)) & HI64) {
18087c478bd9Sstevel@tonic-gate				/* LINTED */
18097c478bd9Sstevel@tonic-gate				u.w |= ~(Elf64_Xword)LO63;
18107c478bd9Sstevel@tonic-gate				u.w = ~u.w + 1;
18117c478bd9Sstevel@tonic-gate				u.sw = -u.w;
18127c478bd9Sstevel@tonic-gate			}
18137c478bd9Sstevel@tonic-gate			dst->r_addend = u.sw;
18147c478bd9Sstevel@tonic-gate		}
18157c478bd9Sstevel@tonic-gate		dst->r_info = tomx(src, RA1_info_$2);
18167c478bd9Sstevel@tonic-gate		dst->r_offset = toma(src, RA1_offset_$2);
18177c478bd9Sstevel@tonic-gate	}
18187c478bd9Sstevel@tonic-gate}')
18197c478bd9Sstevel@tonic-gate
18207c478bd9Sstevel@tonic-gaterela_11_tom(rela_2L11_tom,L)
18217c478bd9Sstevel@tonic-gaterela_11_tom(rela_2M11_tom,M)
18227c478bd9Sstevel@tonic-gate
18237c478bd9Sstevel@tonic-gate
18247c478bd9Sstevel@tonic-gatedefine(shdr_11_tom, `
18257c478bd9Sstevel@tonic-gatestatic void
18267c478bd9Sstevel@tonic-gate$1(Elf64_Shdr *dst, Byte *src, size_t cnt)
18277c478bd9Sstevel@tonic-gate{
18287c478bd9Sstevel@tonic-gate	Elf64_Shdr	*end = dst;
18297c478bd9Sstevel@tonic-gate
18307c478bd9Sstevel@tonic-gate	dst += cnt;
18317c478bd9Sstevel@tonic-gate	src += cnt * SH1_sizeof;
18327c478bd9Sstevel@tonic-gate	while (dst-- > end) {
18337c478bd9Sstevel@tonic-gate		src -= SH1_sizeof;
18347c478bd9Sstevel@tonic-gate		dst->sh_entsize = tomx(src, SH1_entsize_$2);
18357c478bd9Sstevel@tonic-gate		dst->sh_addralign = tomx(src, SH1_addralign_$2);
18367c478bd9Sstevel@tonic-gate		dst->sh_info = tomw(src, SH1_info_$2);
18377c478bd9Sstevel@tonic-gate		dst->sh_link = tomw(src, SH1_link_$2);
18387c478bd9Sstevel@tonic-gate		dst->sh_size = tomx(src, SH1_size_$2);
18397c478bd9Sstevel@tonic-gate		dst->sh_offset = tomo(src, SH1_offset_$2);
18407c478bd9Sstevel@tonic-gate		dst->sh_addr = toma(src, SH1_addr_$2);
18417c478bd9Sstevel@tonic-gate		dst->sh_flags = tomx(src, SH1_flags_$2);
18427c478bd9Sstevel@tonic-gate		dst->sh_type = tomw(src, SH1_type_$2);
18437c478bd9Sstevel@tonic-gate		dst->sh_name = tomw(src, SH1_name_$2);
18447c478bd9Sstevel@tonic-gate	}
18457c478bd9Sstevel@tonic-gate}')
18467c478bd9Sstevel@tonic-gate
18477c478bd9Sstevel@tonic-gateshdr_11_tom(shdr_2L11_tom,L)
18487c478bd9Sstevel@tonic-gateshdr_11_tom(shdr_2M11_tom,M)
18497c478bd9Sstevel@tonic-gate
18507c478bd9Sstevel@tonic-gate
18517c478bd9Sstevel@tonic-gatedefine(sword_tom, `
18527c478bd9Sstevel@tonic-gatestatic void
18537c478bd9Sstevel@tonic-gate$1(Elf64_Sword *dst, Byte *src, size_t cnt)
18547c478bd9Sstevel@tonic-gate{
18557c478bd9Sstevel@tonic-gate	Elf64_Sword	*end = dst;
18567c478bd9Sstevel@tonic-gate
18577c478bd9Sstevel@tonic-gate	dst += cnt;
18587c478bd9Sstevel@tonic-gate	src += cnt * W_sizeof;
18597c478bd9Sstevel@tonic-gate	while (dst-- > end) {
18607c478bd9Sstevel@tonic-gate		src -= W_sizeof;
18617c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
18627c478bd9Sstevel@tonic-gate		if (~(Elf64_Word)0 == -(Elf64_Sword)1 &&
18637c478bd9Sstevel@tonic-gate		    ~(~(Elf64_Word)0 >> 1) == HI32) {	/* 2s comp */
18647c478bd9Sstevel@tonic-gate			*dst = tomw(src, W_$2);
18657c478bd9Sstevel@tonic-gate		} else {
18667c478bd9Sstevel@tonic-gate			union {
18677c478bd9Sstevel@tonic-gate				Elf64_Word w;
18687c478bd9Sstevel@tonic-gate				Elf64_Sword sw;
18697c478bd9Sstevel@tonic-gate			} u;
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gate			if ((u.w = tomw(src, W_$2)) & HI32) {
18727c478bd9Sstevel@tonic-gate				u.w |= ~(Elf64_Word)LO31;
18737c478bd9Sstevel@tonic-gate				u.w = ~u.w + 1;
18747c478bd9Sstevel@tonic-gate				u.sw = -u.w;
18757c478bd9Sstevel@tonic-gate			}
18767c478bd9Sstevel@tonic-gate			*dst = u.sw;
18777c478bd9Sstevel@tonic-gate		}
18787c478bd9Sstevel@tonic-gate	}
18797c478bd9Sstevel@tonic-gate}')
18807c478bd9Sstevel@tonic-gate
18817c478bd9Sstevel@tonic-gatesword_tom(sword_2L_tom,L)
18827c478bd9Sstevel@tonic-gatesword_tom(sword_2M_tom,M)
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate
18857c478bd9Sstevel@tonic-gatedefine(cap_11_tom, `
18867c478bd9Sstevel@tonic-gatestatic void
18877c478bd9Sstevel@tonic-gate$1(Elf64_Cap *dst, unsigned char *src, size_t cnt)
18887c478bd9Sstevel@tonic-gate{
18897c478bd9Sstevel@tonic-gate	Elf64_Cap	*end = dst + cnt;
18907c478bd9Sstevel@tonic-gate
18917c478bd9Sstevel@tonic-gate	do {
18927c478bd9Sstevel@tonic-gate		dst->c_tag = tomx(src, C1_tag_$2);
18937c478bd9Sstevel@tonic-gate		dst->c_un.c_val = tomx(src, C1_val_$2);
18947c478bd9Sstevel@tonic-gate		src += C1_sizeof;
18957c478bd9Sstevel@tonic-gate	} while (++dst < end);
18967c478bd9Sstevel@tonic-gate}')
18977c478bd9Sstevel@tonic-gate
18987c478bd9Sstevel@tonic-gatecap_11_tom(cap_2L11_tom,L)
18997c478bd9Sstevel@tonic-gatecap_11_tom(cap_2M11_tom,M)
19007c478bd9Sstevel@tonic-gate
19017c478bd9Sstevel@tonic-gate
19027c478bd9Sstevel@tonic-gatedefine(syminfo_11_tom, `
19037c478bd9Sstevel@tonic-gatestatic void
19047c478bd9Sstevel@tonic-gate$1(Elf64_Syminfo *dst, unsigned char *src, size_t cnt)
19057c478bd9Sstevel@tonic-gate{
19067c478bd9Sstevel@tonic-gate	Elf64_Syminfo	*end = dst;
19077c478bd9Sstevel@tonic-gate
19087c478bd9Sstevel@tonic-gate	dst += cnt;
19097c478bd9Sstevel@tonic-gate	src += cnt * SI1_sizeof;
19107c478bd9Sstevel@tonic-gate	while (dst-- > end)
19117c478bd9Sstevel@tonic-gate	{
19127c478bd9Sstevel@tonic-gate		src -= SI1_sizeof;
19137c478bd9Sstevel@tonic-gate		dst->si_boundto = tomh(src, SI1_boundto_$2);
19147c478bd9Sstevel@tonic-gate		dst->si_flags = tomh(src, SI1_flags_$2);
19157c478bd9Sstevel@tonic-gate	}
19167c478bd9Sstevel@tonic-gate}')
19177c478bd9Sstevel@tonic-gate
19187c478bd9Sstevel@tonic-gatesyminfo_11_tom(syminfo_2L11_tom,L)
19197c478bd9Sstevel@tonic-gatesyminfo_11_tom(syminfo_2M11_tom,M)
19207c478bd9Sstevel@tonic-gate
19217c478bd9Sstevel@tonic-gate
19227c478bd9Sstevel@tonic-gatedefine(sym_11_tom, `
19237c478bd9Sstevel@tonic-gatestatic void
19247c478bd9Sstevel@tonic-gate$1(Elf64_Sym *dst, Byte *src, size_t cnt)
19257c478bd9Sstevel@tonic-gate{
19267c478bd9Sstevel@tonic-gate	Elf64_Sym	*end = dst;
19277c478bd9Sstevel@tonic-gate
19287c478bd9Sstevel@tonic-gate	dst += cnt;
19297c478bd9Sstevel@tonic-gate	src += cnt * ST1_sizeof;
19307c478bd9Sstevel@tonic-gate	while (dst-- > end) {
19317c478bd9Sstevel@tonic-gate		src -= ST1_sizeof;
19327c478bd9Sstevel@tonic-gate		dst->st_size = tomx(src, ST1_size_$2);
19337c478bd9Sstevel@tonic-gate		dst->st_value = toma(src, ST1_value_$2);
19347c478bd9Sstevel@tonic-gate		dst->st_shndx = tomh(src, ST1_shndx_$2);
19357c478bd9Sstevel@tonic-gate		dst->st_other = tomb(src, ST1_other_$2);
19367c478bd9Sstevel@tonic-gate		dst->st_info = tomb(src, ST1_info_$2);
19377c478bd9Sstevel@tonic-gate		dst->st_name = tomw(src, ST1_name_$2);
19387c478bd9Sstevel@tonic-gate	}
19397c478bd9Sstevel@tonic-gate}')
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gatesym_11_tom(sym_2L11_tom,L)
19427c478bd9Sstevel@tonic-gatesym_11_tom(sym_2M11_tom,M)
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gate
19457c478bd9Sstevel@tonic-gatedefine(word_tom, `
19467c478bd9Sstevel@tonic-gatestatic void
19477c478bd9Sstevel@tonic-gate$1(Elf64_Word *dst, Byte *src, size_t cnt)
19487c478bd9Sstevel@tonic-gate{
19497c478bd9Sstevel@tonic-gate	Elf64_Word	*end = dst;
19507c478bd9Sstevel@tonic-gate
19517c478bd9Sstevel@tonic-gate	dst += cnt;
19527c478bd9Sstevel@tonic-gate	src += cnt * W_sizeof;
19537c478bd9Sstevel@tonic-gate	while (dst-- > end) {
19547c478bd9Sstevel@tonic-gate		src -= W_sizeof;
19557c478bd9Sstevel@tonic-gate		*dst = tomw(src, W_$2);
19567c478bd9Sstevel@tonic-gate	}
19577c478bd9Sstevel@tonic-gate}')
19587c478bd9Sstevel@tonic-gate
19597c478bd9Sstevel@tonic-gateword_tom(word_2L_tom,L)
19607c478bd9Sstevel@tonic-gateword_tom(word_2M_tom,M)
19617c478bd9Sstevel@tonic-gate
19627c478bd9Sstevel@tonic-gate
19637c478bd9Sstevel@tonic-gatedefine(verdef_11_tom, `
19647c478bd9Sstevel@tonic-gatestatic void
19657c478bd9Sstevel@tonic-gate$1(Elf64_Verdef *dst, Byte *src, size_t cnt)
19667c478bd9Sstevel@tonic-gate{
19677c478bd9Sstevel@tonic-gate	/* LINTED */
19687c478bd9Sstevel@tonic-gate	Elf64_Verdef	*end = (Elf64_Verdef *)((Byte *)dst + cnt);
19697c478bd9Sstevel@tonic-gate
19707c478bd9Sstevel@tonic-gate	while (dst < end) {
19717c478bd9Sstevel@tonic-gate		Elf64_Verdaux	*vaux;
19727c478bd9Sstevel@tonic-gate		Byte		*src_vaux;
19737c478bd9Sstevel@tonic-gate		Elf64_Half	i;
19747c478bd9Sstevel@tonic-gate
19757c478bd9Sstevel@tonic-gate		dst->vd_version = tomh(src, VD1_version_$2);
19767c478bd9Sstevel@tonic-gate		dst->vd_flags = tomh(src, VD1_flags_$2);
19777c478bd9Sstevel@tonic-gate		dst->vd_ndx = tomh(src, VD1_ndx_$2);
19787c478bd9Sstevel@tonic-gate		dst->vd_cnt = tomh(src, VD1_cnt_$2);
19797c478bd9Sstevel@tonic-gate		dst->vd_hash = tomw(src, VD1_hash_$2);
19807c478bd9Sstevel@tonic-gate		dst->vd_aux = tomw(src, VD1_aux_$2);
19817c478bd9Sstevel@tonic-gate		dst->vd_next = tomw(src, VD1_next_$2);
19827c478bd9Sstevel@tonic-gate
19837c478bd9Sstevel@tonic-gate		src_vaux = src + dst->vd_aux;
19847c478bd9Sstevel@tonic-gate		/* LINTED */
19857c478bd9Sstevel@tonic-gate		vaux = (Elf64_Verdaux *)((Byte *)dst + dst->vd_aux);
19867c478bd9Sstevel@tonic-gate		for (i = 0; i < dst->vd_cnt; i++) {
19877c478bd9Sstevel@tonic-gate			vaux->vda_name = tomw(src_vaux, VDA1_name_$2);
19887c478bd9Sstevel@tonic-gate			vaux->vda_next = tomw(src_vaux, VDA1_next_$2);
19897c478bd9Sstevel@tonic-gate			src_vaux += vaux->vda_next;
19907c478bd9Sstevel@tonic-gate			/* LINTED */
19917c478bd9Sstevel@tonic-gate			vaux = (Elf64_Verdaux *)((Byte *)vaux +
19927c478bd9Sstevel@tonic-gate			    vaux->vda_next);
19937c478bd9Sstevel@tonic-gate		}
19947c478bd9Sstevel@tonic-gate		src += dst->vd_next;
19957c478bd9Sstevel@tonic-gate		/* LINTED */
19967c478bd9Sstevel@tonic-gate		dst = (Elf64_Verdef *)(dst->vd_next ?
19977c478bd9Sstevel@tonic-gate		    (Byte *)dst + dst->vd_next : (Byte *)end);
19987c478bd9Sstevel@tonic-gate	}
19997c478bd9Sstevel@tonic-gate}')
20007c478bd9Sstevel@tonic-gate
20017c478bd9Sstevel@tonic-gateverdef_11_tom(verdef_2L11_tom,L)
20027c478bd9Sstevel@tonic-gateverdef_11_tom(verdef_2M11_tom,M)
20037c478bd9Sstevel@tonic-gate
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gatedefine(verneed_11_tom, `
20067c478bd9Sstevel@tonic-gatestatic void
20077c478bd9Sstevel@tonic-gate$1(Elf64_Verneed *dst, Byte *src, size_t cnt)
20087c478bd9Sstevel@tonic-gate{
20097c478bd9Sstevel@tonic-gate	/* LINTED */
20107c478bd9Sstevel@tonic-gate	Elf64_Verneed	*end = (Elf64_Verneed *)((char *)dst + cnt);
20117c478bd9Sstevel@tonic-gate
20127c478bd9Sstevel@tonic-gate	while (dst < end) {
20137c478bd9Sstevel@tonic-gate		Elf64_Vernaux *	vaux;
20147c478bd9Sstevel@tonic-gate		Byte *		src_vaux;
20157c478bd9Sstevel@tonic-gate		Elf64_Half	i;
20167c478bd9Sstevel@tonic-gate
20177c478bd9Sstevel@tonic-gate		dst->vn_version = tomh(src, VN1_version_$2);
20187c478bd9Sstevel@tonic-gate		dst->vn_cnt = tomh(src, VN1_cnt_$2);
20197c478bd9Sstevel@tonic-gate		dst->vn_file = tomw(src, VN1_file_$2);
20207c478bd9Sstevel@tonic-gate		dst->vn_aux = tomw(src, VN1_aux_$2);
20217c478bd9Sstevel@tonic-gate		dst->vn_next = tomw(src, VN1_next_$2);
20227c478bd9Sstevel@tonic-gate
20237c478bd9Sstevel@tonic-gate		src_vaux = src + dst->vn_aux;
20247c478bd9Sstevel@tonic-gate		/* LINTED */
20257c478bd9Sstevel@tonic-gate		vaux = (Elf64_Vernaux *)((Byte *)dst + dst->vn_aux);
20267c478bd9Sstevel@tonic-gate		for (i = 0; i < dst->vn_cnt; i++) {
20277c478bd9Sstevel@tonic-gate			vaux->vna_hash = tomw(src_vaux, VNA1_hash_$2);
20287c478bd9Sstevel@tonic-gate			vaux->vna_flags = tomh(src_vaux, VNA1_flags_$2);
20297c478bd9Sstevel@tonic-gate			vaux->vna_other = tomh(src_vaux, VNA1_other_$2);
20307c478bd9Sstevel@tonic-gate			vaux->vna_name = tomw(src_vaux, VNA1_name_$2);
20317c478bd9Sstevel@tonic-gate			vaux->vna_next = tomw(src_vaux, VNA1_next_$2);
20327c478bd9Sstevel@tonic-gate			src_vaux += vaux->vna_next;
20337c478bd9Sstevel@tonic-gate			/* LINTED */
20347c478bd9Sstevel@tonic-gate			vaux = (Elf64_Vernaux *)((Byte *)vaux +
20357c478bd9Sstevel@tonic-gate			    vaux->vna_next);
20367c478bd9Sstevel@tonic-gate		}
20377c478bd9Sstevel@tonic-gate		src += dst->vn_next;
20387c478bd9Sstevel@tonic-gate		/* LINTED */
20397c478bd9Sstevel@tonic-gate		dst = (Elf64_Verneed *)(dst->vn_next ?
20407c478bd9Sstevel@tonic-gate		    (Byte *)dst + dst->vn_next : (Byte *)end);
20417c478bd9Sstevel@tonic-gate	}
20427c478bd9Sstevel@tonic-gate}')
20437c478bd9Sstevel@tonic-gate
20447c478bd9Sstevel@tonic-gateverneed_11_tom(verneed_2L11_tom,L)
20457c478bd9Sstevel@tonic-gateverneed_11_tom(verneed_2M11_tom,M)
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gate
20487c478bd9Sstevel@tonic-gatedefine(sxword_tom, `
20497c478bd9Sstevel@tonic-gatestatic void
20507c478bd9Sstevel@tonic-gate$1(Elf64_Sxword *dst, Byte *src, size_t cnt)
20517c478bd9Sstevel@tonic-gate{
20527c478bd9Sstevel@tonic-gate	Elf64_Sxword	*end = dst;
20537c478bd9Sstevel@tonic-gate
20547c478bd9Sstevel@tonic-gate	dst += cnt;
20557c478bd9Sstevel@tonic-gate	src += cnt * X_sizeof;
20567c478bd9Sstevel@tonic-gate	while (dst-- > end) {
20577c478bd9Sstevel@tonic-gate		src -= X_sizeof;
20587c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
20597c478bd9Sstevel@tonic-gate		if (~(Elf64_Xword)0 == -(Elf64_Sxword)1 &&
20607c478bd9Sstevel@tonic-gate		    ~(~(Elf64_Xword)0 >> 1) == HI64) {	/* 2s comp */
20617c478bd9Sstevel@tonic-gate			*dst = tomx(src, X_$2);
20627c478bd9Sstevel@tonic-gate		} else {				/* other */
20637c478bd9Sstevel@tonic-gate			union {
20647c478bd9Sstevel@tonic-gate				Elf64_Xword w;
20657c478bd9Sstevel@tonic-gate				Elf64_Sxword sw;
20667c478bd9Sstevel@tonic-gate			} u;
20677c478bd9Sstevel@tonic-gate
20687c478bd9Sstevel@tonic-gate			if ((u.w = tomx(src, X_$2)) & HI64) {
20697c478bd9Sstevel@tonic-gate				/* LINTED */
20707c478bd9Sstevel@tonic-gate				u.w |= ~(Elf64_Xword)LO63;
20717c478bd9Sstevel@tonic-gate				u.w = ~u.w + 1;
20727c478bd9Sstevel@tonic-gate				u.sw = -u.w;
20737c478bd9Sstevel@tonic-gate			}
20747c478bd9Sstevel@tonic-gate			*dst = u.sw;
20757c478bd9Sstevel@tonic-gate		}
20767c478bd9Sstevel@tonic-gate	}
20777c478bd9Sstevel@tonic-gate}')
20787c478bd9Sstevel@tonic-gate
20797c478bd9Sstevel@tonic-gatesxword_tom(sxword_2L_tom,L)
20807c478bd9Sstevel@tonic-gatesxword_tom(sxword_2M_tom,M)
20817c478bd9Sstevel@tonic-gate
20827c478bd9Sstevel@tonic-gate
20837c478bd9Sstevel@tonic-gatedefine(xword_tom, `
20847c478bd9Sstevel@tonic-gatestatic void
20857c478bd9Sstevel@tonic-gate$1(Elf64_Xword *dst, Byte *src, size_t cnt)
20867c478bd9Sstevel@tonic-gate{
20877c478bd9Sstevel@tonic-gate	Elf64_Xword	*end = dst;
20887c478bd9Sstevel@tonic-gate
20897c478bd9Sstevel@tonic-gate	dst += cnt;
20907c478bd9Sstevel@tonic-gate	src += cnt * X_sizeof;
20917c478bd9Sstevel@tonic-gate	while (dst-- > end) {
20927c478bd9Sstevel@tonic-gate		src -= X_sizeof;
20937c478bd9Sstevel@tonic-gate		*dst = tomx(src, X_$2);
20947c478bd9Sstevel@tonic-gate	}
20957c478bd9Sstevel@tonic-gate}')
20967c478bd9Sstevel@tonic-gate
20977c478bd9Sstevel@tonic-gatexword_tom(xword_2L_tom,L)
20987c478bd9Sstevel@tonic-gatexword_tom(xword_2M_tom,M)
2099