xref: /titanic_51/usr/src/cmd/sgs/libelf/common/xlate.m4 (revision 3228339cea1b23699cb9832992ee764dec04b2f1)
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>
34*3228339cSAli 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 * x32:  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 'x32[]' 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 elf32_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 *	These routines make a subtle implicit assumption.
717c478bd9Sstevel@tonic-gate *	The file representations of all structures are "packed,"
727c478bd9Sstevel@tonic-gate *	meaning no implicit padding bytes occur.  This might not
737c478bd9Sstevel@tonic-gate *	be the case for the memory representations.  Consequently,
747c478bd9Sstevel@tonic-gate *	the memory representations ALWAYS contain at least as many
757c478bd9Sstevel@tonic-gate *	bytes as the file representations.  Otherwise, the memory
767c478bd9Sstevel@tonic-gate *	structures would lose information, meaning they're not
777c478bd9Sstevel@tonic-gate *	implemented properly.
787c478bd9Sstevel@tonic-gate *
797c478bd9Sstevel@tonic-gate *	The words above apply to structures with the same members.
807c478bd9Sstevel@tonic-gate *	If a future version changes the number of members, the
817c478bd9Sstevel@tonic-gate *	relative structure sizes for different version must be
827c478bd9Sstevel@tonic-gate *	tested with the compiler.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate#define	HI32	0x80000000UL
867c478bd9Sstevel@tonic-gate#define	LO31	0x7fffffffUL
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate/*
897c478bd9Sstevel@tonic-gate *	These macros create indexes for accessing the bytes of
907c478bd9Sstevel@tonic-gate *	words and halfwords for ELFCLASS32 data representations
917c478bd9Sstevel@tonic-gate *	(currently ELFDATA2LSB and ELFDATA2MSB).  In all cases,
927c478bd9Sstevel@tonic-gate *
937c478bd9Sstevel@tonic-gate *	w = (((((X_3 << 8) + X_2) << 8) + X_1) << 8) + X_0
947c478bd9Sstevel@tonic-gate *	h = (X_1 << 8) + X_0
957c478bd9Sstevel@tonic-gate *
967c478bd9Sstevel@tonic-gate *	These assume the file representations for Addr, Off,
977c478bd9Sstevel@tonic-gate *	Sword, and Word use 4 bytes, but the memory def's for
987c478bd9Sstevel@tonic-gate *	the types may differ.
997c478bd9Sstevel@tonic-gate *
1007c478bd9Sstevel@tonic-gate *	Naming convention:
1017c478bd9Sstevel@tonic-gate *		..._L	ELFDATA2LSB
1027c478bd9Sstevel@tonic-gate *		..._M	ELFDATA2MSB
1037c478bd9Sstevel@tonic-gate *
1047c478bd9Sstevel@tonic-gate *	enuma_*(n)	define enum names for addr n
1057c478bd9Sstevel@tonic-gate *	enumb_*(n)	define enum names for byte n
1067c478bd9Sstevel@tonic-gate *	enumh_*(n)	define enum names for half n
1077c478bd9Sstevel@tonic-gate *	enumo_*(n)	define enum names for off n
1087c478bd9Sstevel@tonic-gate *	enumw_*(n)	define enum names for word n
1097c478bd9Sstevel@tonic-gate *	enuml_*(n)	define enum names for Lword n
1107c478bd9Sstevel@tonic-gate *	tofa(d,s,n)	xlate addr n from mem s to file d
1117c478bd9Sstevel@tonic-gate *	tofb(d,s,n)	xlate byte n from mem s to file d
1127c478bd9Sstevel@tonic-gate *	tofh(d,s,n)	xlate half n from mem s to file d
1137c478bd9Sstevel@tonic-gate *	tofo(d,s,n)	xlate off n from mem s to file d
1147c478bd9Sstevel@tonic-gate *	tofw(d,s,n)	xlate word n from mem s to file d
1157c478bd9Sstevel@tonic-gate *	tofl(d,s,n)	xlate Lword n from mem s to file d
1167c478bd9Sstevel@tonic-gate *	toma(s,n)	xlate addr n from file s to expression value
1177c478bd9Sstevel@tonic-gate *	tomb(s,n)	xlate byte n from file s to expression value
1187c478bd9Sstevel@tonic-gate *	tomh(s,n)	xlate half n from file s to expression value
1197c478bd9Sstevel@tonic-gate *	tomo(s,n)	xlate off n from file s to expression value
1207c478bd9Sstevel@tonic-gate *	tomw(s,n)	xlate word n from file s to expression value
1217c478bd9Sstevel@tonic-gate *	toml(s,n)	xlate Lword n from file s to expression value
1227c478bd9Sstevel@tonic-gate *
1237c478bd9Sstevel@tonic-gate *	tof*() macros must move a multi-byte value into a temporary
1247c478bd9Sstevel@tonic-gate *	because ``in place'' conversions are allowed.  If a temp is not
1257c478bd9Sstevel@tonic-gate *	used for multi-byte objects, storing an initial destination byte
1267c478bd9Sstevel@tonic-gate *	may clobber a source byte not yet examined.
1277c478bd9Sstevel@tonic-gate *
1287c478bd9Sstevel@tonic-gate *	tom*() macros compute an expression value from the source
1297c478bd9Sstevel@tonic-gate *	without touching the destination; so they're safe.
1307c478bd9Sstevel@tonic-gate */
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gatedefine(enuma_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl
1337c478bd9Sstevel@tonic-gatedefine(enuma_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl
1347c478bd9Sstevel@tonic-gatedefine(enumb_L, `$1_L')dnl
1357c478bd9Sstevel@tonic-gatedefine(enumb_M, `$1_M')dnl
1367c478bd9Sstevel@tonic-gatedefine(enumh_L, `$1_L0, $1_L1')dnl
1377c478bd9Sstevel@tonic-gatedefine(enumh_M, `$1_M1, $1_M0')dnl
1387c478bd9Sstevel@tonic-gatedefine(enumo_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl
1397c478bd9Sstevel@tonic-gatedefine(enumo_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl
1407c478bd9Sstevel@tonic-gatedefine(enumw_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl
1417c478bd9Sstevel@tonic-gatedefine(enumw_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl
1427c478bd9Sstevel@tonic-gatedefine(enuml_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl
1437c478bd9Sstevel@tonic-gatedefine(enuml_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gatedefine(tofa, `{ register Elf32_Addr _t_ = $2;
1467c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (unsigned char)_t_,
1477c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (unsigned char)(_t_>>8),
1487c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (unsigned char)(_t_>>16),
1497c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl
1507c478bd9Sstevel@tonic-gatedefine(tofb, `($1)[$3] = (unsigned char)($2)')dnl
1517c478bd9Sstevel@tonic-gatedefine(tofh, `{ register Elf32_Half _t_ = $2;
1527c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (unsigned char)_t_,
1537c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (unsigned char)(_t_>>8); }')dnl
1547c478bd9Sstevel@tonic-gatedefine(tofo, `{ register Elf32_Off _t_ = $2;
1557c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (unsigned char)_t_,
1567c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (unsigned char)(_t_>>8),
1577c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (unsigned char)(_t_>>16),
1587c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl
1597c478bd9Sstevel@tonic-gatedefine(tofw, `{ register Elf32_Word _t_ = $2;
1607c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (unsigned char)_t_,
1617c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (unsigned char)(_t_>>8),
1627c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (unsigned char)(_t_>>16),
1637c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl
1647c478bd9Sstevel@tonic-gatedefine(tofl, `{ Elf32_Lword _t_ = $2;
1657c478bd9Sstevel@tonic-gate		($1)[$3`'0] = (Byte)_t_,
1667c478bd9Sstevel@tonic-gate		($1)[$3`'1] = (Byte)(_t_>>8),
1677c478bd9Sstevel@tonic-gate		($1)[$3`'2] = (Byte)(_t_>>16),
1687c478bd9Sstevel@tonic-gate		($1)[$3`'3] = (Byte)(_t_>>24),
1697c478bd9Sstevel@tonic-gate		($1)[$3`'4] = (Byte)(_t_>>32),
1707c478bd9Sstevel@tonic-gate		($1)[$3`'5] = (Byte)(_t_>>40),
1717c478bd9Sstevel@tonic-gate		($1)[$3`'6] = (Byte)(_t_>>48),
1727c478bd9Sstevel@tonic-gate		($1)[$3`'7] = (Byte)(_t_>>56); }')dnl
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gatedefine(toma, `(((((((Elf32_Addr)($1)[$2`'3]<<8)
1757c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
1767c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
1777c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
1787c478bd9Sstevel@tonic-gatedefine(tomb, `((unsigned char)($1)[$2])')dnl
1797c478bd9Sstevel@tonic-gatedefine(tomh, `(((Elf32_Half)($1)[$2`'1]<<8)+($1)[$2`'0])')dnl
1807c478bd9Sstevel@tonic-gatedefine(tomo, `(((((((Elf32_Off)($1)[$2`'3]<<8)
1817c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
1827c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
1837c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
1847c478bd9Sstevel@tonic-gatedefine(tomw, `(((((((Elf32_Word)($1)[$2`'3]<<8)
1857c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
1867c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
1877c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
1887c478bd9Sstevel@tonic-gatedefine(toml, `(((((((((((Elf32_Lword)($1)[$2`'7]<<8)
1897c478bd9Sstevel@tonic-gate		+($1)[$2`'6]<<8)
1907c478bd9Sstevel@tonic-gate		+($1)[$2`'5]<<8)
1917c478bd9Sstevel@tonic-gate		+($1)[$2`'4]<<8)
1927c478bd9Sstevel@tonic-gate		+($1)[$2`'3]<<8)
1937c478bd9Sstevel@tonic-gate		+($1)[$2`'2])<<8)
1947c478bd9Sstevel@tonic-gate		+($1)[$2`'1])<<8)
1957c478bd9Sstevel@tonic-gate		+($1)[$2`'0])')dnl
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate/*
1997c478bd9Sstevel@tonic-gate * ELF data object indexes
2007c478bd9Sstevel@tonic-gate *	The enums are broken apart to get around deficiencies
2017c478bd9Sstevel@tonic-gate *	in some compilers.
2027c478bd9Sstevel@tonic-gate */
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gatedefine(Addr, `
2057c478bd9Sstevel@tonic-gateenum
2067c478bd9Sstevel@tonic-gate{
2077c478bd9Sstevel@tonic-gate	enuma_$1(A)`'ifelse(`$2', `', `', `,
2087c478bd9Sstevel@tonic-gate	A_sizeof')
2097c478bd9Sstevel@tonic-gate};')
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gateAddr(L)
2127c478bd9Sstevel@tonic-gateAddr(M,1)
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gatedefine(Half, `
2167c478bd9Sstevel@tonic-gateenum
2177c478bd9Sstevel@tonic-gate{
2187c478bd9Sstevel@tonic-gate	enumh_$1(H)`'ifelse(`$2', `', `', `,
2197c478bd9Sstevel@tonic-gate	H_sizeof')
2207c478bd9Sstevel@tonic-gate};')
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gateHalf(L)
2237c478bd9Sstevel@tonic-gateHalf(M,1)
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gatedefine(Lword, `
2267c478bd9Sstevel@tonic-gateenum
2277c478bd9Sstevel@tonic-gate{
2287c478bd9Sstevel@tonic-gate	enuml_$1(L)`'ifelse(`$2', `', `', `,
2297c478bd9Sstevel@tonic-gate	L_sizeof')
2307c478bd9Sstevel@tonic-gate};')
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gateLword(L)
2337c478bd9Sstevel@tonic-gateLword(M,1)
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gatedefine(Move_1, `
2377c478bd9Sstevel@tonic-gateenum
2387c478bd9Sstevel@tonic-gate{
2397c478bd9Sstevel@tonic-gate	enuml_$1(M1_value),
2407c478bd9Sstevel@tonic-gate	enumw_$1(M1_info),
2417c478bd9Sstevel@tonic-gate	enumw_$1(M1_poffset),
2427c478bd9Sstevel@tonic-gate	enumh_$1(M1_repeat),
2437c478bd9Sstevel@tonic-gate	enumh_$1(M1_stride)`'ifelse(`$2', `', `', `,
2447c478bd9Sstevel@tonic-gate	M1_sizeof')
2457c478bd9Sstevel@tonic-gate};')
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gateMove_1(L)
2487c478bd9Sstevel@tonic-gateMove_1(M,1)
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gatedefine(MoveP_1, `
2527c478bd9Sstevel@tonic-gateenum
2537c478bd9Sstevel@tonic-gate{
2547c478bd9Sstevel@tonic-gate	enuml_$1(MP1_value),
2557c478bd9Sstevel@tonic-gate	enumw_$1(MP1_info),
2567c478bd9Sstevel@tonic-gate	enumw_$1(MP1_poffset),
2577c478bd9Sstevel@tonic-gate	enumh_$1(MP1_repeat),
2587c478bd9Sstevel@tonic-gate	enumh_$1(MP1_stride),
2597c478bd9Sstevel@tonic-gate	enumw_$1(MP1_padding)`'ifelse(`$2', `', `', `,
2607c478bd9Sstevel@tonic-gate	MP1_sizeof')
2617c478bd9Sstevel@tonic-gate};')
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gateMoveP_1(L)
2647c478bd9Sstevel@tonic-gateMoveP_1(M,1)
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gatedefine(Off, `
2687c478bd9Sstevel@tonic-gateenum
2697c478bd9Sstevel@tonic-gate{
2707c478bd9Sstevel@tonic-gate	enumo_$1(O)`'ifelse(`$2', `', `', `,
2717c478bd9Sstevel@tonic-gate	O_sizeof')
2727c478bd9Sstevel@tonic-gate};')
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gateOff(L)
2757c478bd9Sstevel@tonic-gateOff(M,1)
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gatedefine(Word, `
2797c478bd9Sstevel@tonic-gateenum
2807c478bd9Sstevel@tonic-gate{
2817c478bd9Sstevel@tonic-gate	enumw_$1(W)`'ifelse(`$2', `', `', `,
2827c478bd9Sstevel@tonic-gate	W_sizeof')
2837c478bd9Sstevel@tonic-gate};')
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gateWord(L)
2867c478bd9Sstevel@tonic-gateWord(M,1)
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gatedefine(Dyn_1, `
2907c478bd9Sstevel@tonic-gateenum
2917c478bd9Sstevel@tonic-gate{
2927c478bd9Sstevel@tonic-gate	enumw_$1(D1_tag),
2937c478bd9Sstevel@tonic-gate	enumw_$1(D1_val)`'ifelse(`$2', `', `', `,
2947c478bd9Sstevel@tonic-gate	D1_sizeof')
2957c478bd9Sstevel@tonic-gate};')
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gateDyn_1(L)
2987c478bd9Sstevel@tonic-gateDyn_1(M,1)
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate#define	E1_Nident	16
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gatedefine(Ehdr_1, `
3047c478bd9Sstevel@tonic-gateenum
3057c478bd9Sstevel@tonic-gate{
3067c478bd9Sstevel@tonic-gate	ifelse(`$2', `', `E1_ident, ')E1_ident_$1_Z = E1_Nident - 1,
3077c478bd9Sstevel@tonic-gate	enumh_$1(E1_type),
3087c478bd9Sstevel@tonic-gate	enumh_$1(E1_machine),
3097c478bd9Sstevel@tonic-gate	enumw_$1(E1_version),
3107c478bd9Sstevel@tonic-gate	enuma_$1(E1_entry),
3117c478bd9Sstevel@tonic-gate	enumo_$1(E1_phoff),
3127c478bd9Sstevel@tonic-gate	enumo_$1(E1_shoff),
3137c478bd9Sstevel@tonic-gate	enumw_$1(E1_flags),
3147c478bd9Sstevel@tonic-gate	enumh_$1(E1_ehsize),
3157c478bd9Sstevel@tonic-gate	enumh_$1(E1_phentsize),
3167c478bd9Sstevel@tonic-gate	enumh_$1(E1_phnum),
3177c478bd9Sstevel@tonic-gate	enumh_$1(E1_shentsize),
3187c478bd9Sstevel@tonic-gate	enumh_$1(E1_shnum),
3197c478bd9Sstevel@tonic-gate	enumh_$1(E1_shstrndx)`'ifelse(`$2', `', `', `,
3207c478bd9Sstevel@tonic-gate	E1_sizeof')
3217c478bd9Sstevel@tonic-gate};')
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gateEhdr_1(L)
3247c478bd9Sstevel@tonic-gateEhdr_1(M,1)
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gatedefine(Nhdr_1, `
3277c478bd9Sstevel@tonic-gateenum
3287c478bd9Sstevel@tonic-gate{
3297c478bd9Sstevel@tonic-gate	enumw_$1(N1_namesz),
3307c478bd9Sstevel@tonic-gate	enumw_$1(N1_descsz),
3317c478bd9Sstevel@tonic-gate	enumw_$1(N1_type)`'ifelse(`$2', `', `', `,
3327c478bd9Sstevel@tonic-gate	N1_sizeof')
3337c478bd9Sstevel@tonic-gate};')
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gateNhdr_1(L)
3367c478bd9Sstevel@tonic-gateNhdr_1(M,1)
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gatedefine(Phdr_1, `
3397c478bd9Sstevel@tonic-gateenum
3407c478bd9Sstevel@tonic-gate{
3417c478bd9Sstevel@tonic-gate	enumw_$1(P1_type),
3427c478bd9Sstevel@tonic-gate	enumo_$1(P1_offset),
3437c478bd9Sstevel@tonic-gate	enuma_$1(P1_vaddr),
3447c478bd9Sstevel@tonic-gate	enuma_$1(P1_paddr),
3457c478bd9Sstevel@tonic-gate	enumw_$1(P1_filesz),
3467c478bd9Sstevel@tonic-gate	enumw_$1(P1_memsz),
3477c478bd9Sstevel@tonic-gate	enumw_$1(P1_flags),
3487c478bd9Sstevel@tonic-gate	enumw_$1(P1_align)`'ifelse(`$2', `', `', `,
3497c478bd9Sstevel@tonic-gate	P1_sizeof')
3507c478bd9Sstevel@tonic-gate};')
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gatePhdr_1(L)
3537c478bd9Sstevel@tonic-gatePhdr_1(M,1)
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gatedefine(Rel_1, `
3577c478bd9Sstevel@tonic-gateenum
3587c478bd9Sstevel@tonic-gate{
3597c478bd9Sstevel@tonic-gate	enuma_$1(R1_offset),
3607c478bd9Sstevel@tonic-gate	enumw_$1(R1_info)`'ifelse(`$2', `', `', `,
3617c478bd9Sstevel@tonic-gate	R1_sizeof')
3627c478bd9Sstevel@tonic-gate};')
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gateRel_1(L)
3657c478bd9Sstevel@tonic-gateRel_1(M,1)
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gatedefine(Rela_1, `
3697c478bd9Sstevel@tonic-gateenum
3707c478bd9Sstevel@tonic-gate{
3717c478bd9Sstevel@tonic-gate	enuma_$1(RA1_offset),
3727c478bd9Sstevel@tonic-gate	enumw_$1(RA1_info),
3737c478bd9Sstevel@tonic-gate	enumw_$1(RA1_addend)`'ifelse(`$2', `', `', `,
3747c478bd9Sstevel@tonic-gate	RA1_sizeof')
3757c478bd9Sstevel@tonic-gate};')
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gateRela_1(L)
3787c478bd9Sstevel@tonic-gateRela_1(M,1)
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gatedefine(Shdr_1, `
3827c478bd9Sstevel@tonic-gateenum
3837c478bd9Sstevel@tonic-gate{
3847c478bd9Sstevel@tonic-gate	enumw_$1(SH1_name),
3857c478bd9Sstevel@tonic-gate	enumw_$1(SH1_type),
3867c478bd9Sstevel@tonic-gate	enumw_$1(SH1_flags),
3877c478bd9Sstevel@tonic-gate	enuma_$1(SH1_addr),
3887c478bd9Sstevel@tonic-gate	enumo_$1(SH1_offset),
3897c478bd9Sstevel@tonic-gate	enumw_$1(SH1_size),
3907c478bd9Sstevel@tonic-gate	enumw_$1(SH1_link),
3917c478bd9Sstevel@tonic-gate	enumw_$1(SH1_info),
3927c478bd9Sstevel@tonic-gate	enumw_$1(SH1_addralign),
3937c478bd9Sstevel@tonic-gate	enumw_$1(SH1_entsize)`'ifelse(`$2', `', `', `,
3947c478bd9Sstevel@tonic-gate	SH1_sizeof')
3957c478bd9Sstevel@tonic-gate};')
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gateShdr_1(L)
3987c478bd9Sstevel@tonic-gateShdr_1(M,1)
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gatedefine(Sym_1, `
4027c478bd9Sstevel@tonic-gateenum
4037c478bd9Sstevel@tonic-gate{
4047c478bd9Sstevel@tonic-gate	enumw_$1(ST1_name),
4057c478bd9Sstevel@tonic-gate	enuma_$1(ST1_value),
4067c478bd9Sstevel@tonic-gate	enumw_$1(ST1_size),
4077c478bd9Sstevel@tonic-gate	enumb_$1(ST1_info),
4087c478bd9Sstevel@tonic-gate	enumb_$1(ST1_other),
4097c478bd9Sstevel@tonic-gate	enumh_$1(ST1_shndx)`'ifelse(`$2', `', `', `,
4107c478bd9Sstevel@tonic-gate	ST1_sizeof')
4117c478bd9Sstevel@tonic-gate};')
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gateSym_1(L)
4147c478bd9Sstevel@tonic-gateSym_1(M,1)
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gatedefine(Syminfo_1, `
4187c478bd9Sstevel@tonic-gateenum
4197c478bd9Sstevel@tonic-gate{
4207c478bd9Sstevel@tonic-gate	enumh_$1(SI1_boundto),
4217c478bd9Sstevel@tonic-gate	enumh_$1(SI1_flags)`'ifelse(`$2', `', `', `,
4227c478bd9Sstevel@tonic-gate	SI1_sizeof')
4237c478bd9Sstevel@tonic-gate};')
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gateSyminfo_1(L)
4267c478bd9Sstevel@tonic-gateSyminfo_1(M,1)
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gatedefine(Cap_1, `
4307c478bd9Sstevel@tonic-gateenum
4317c478bd9Sstevel@tonic-gate{
4327c478bd9Sstevel@tonic-gate	enumw_$1(C1_tag),
4337c478bd9Sstevel@tonic-gate	enumw_$1(C1_val)`'ifelse(`$2', `', `', `,
4347c478bd9Sstevel@tonic-gate	C1_sizeof')
4357c478bd9Sstevel@tonic-gate};')
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gateCap_1(L)
4387c478bd9Sstevel@tonic-gateCap_1(M,1)
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gatedefine(Verdef_1, `
4427c478bd9Sstevel@tonic-gateenum
4437c478bd9Sstevel@tonic-gate{
4447c478bd9Sstevel@tonic-gate	enumh_$1(VD1_version),
4457c478bd9Sstevel@tonic-gate	enumh_$1(VD1_flags),
4467c478bd9Sstevel@tonic-gate	enumh_$1(VD1_ndx),
4477c478bd9Sstevel@tonic-gate	enumh_$1(VD1_cnt),
4487c478bd9Sstevel@tonic-gate	enumw_$1(VD1_hash),
4497c478bd9Sstevel@tonic-gate	enumw_$1(VD1_aux),
4507c478bd9Sstevel@tonic-gate	enumw_$1(VD1_next)`'ifelse(`$2', `', `', `,
4517c478bd9Sstevel@tonic-gate	VD1_sizeof')
4527c478bd9Sstevel@tonic-gate};')
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gateVerdef_1(L)
4557c478bd9Sstevel@tonic-gateVerdef_1(M,1)
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gatedefine(Verdaux_1, `
4597c478bd9Sstevel@tonic-gateenum
4607c478bd9Sstevel@tonic-gate{
4617c478bd9Sstevel@tonic-gate	enuma_$1(VDA1_name),
4627c478bd9Sstevel@tonic-gate	enumw_$1(VDA1_next)`'ifelse(`$2', `', `', `,
4637c478bd9Sstevel@tonic-gate	VDA1_sizeof')
4647c478bd9Sstevel@tonic-gate};')
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gateVerdaux_1(L)
4677c478bd9Sstevel@tonic-gateVerdaux_1(M,1)
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gatedefine(Verneed_1, `
4717c478bd9Sstevel@tonic-gateenum
4727c478bd9Sstevel@tonic-gate{
4737c478bd9Sstevel@tonic-gate	enumh_$1(VN1_version),
4747c478bd9Sstevel@tonic-gate	enumh_$1(VN1_cnt),
4757c478bd9Sstevel@tonic-gate	enuma_$1(VN1_file),
4767c478bd9Sstevel@tonic-gate	enumw_$1(VN1_aux),
4777c478bd9Sstevel@tonic-gate	enumw_$1(VN1_next)`'ifelse(`$2', `', `', `,
4787c478bd9Sstevel@tonic-gate	VN1_sizeof')
4797c478bd9Sstevel@tonic-gate};')
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gateVerneed_1(L)
4827c478bd9Sstevel@tonic-gateVerneed_1(M,1)
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gatedefine(Vernaux_1, `
4867c478bd9Sstevel@tonic-gateenum
4877c478bd9Sstevel@tonic-gate{
4887c478bd9Sstevel@tonic-gate	enumw_$1(VNA1_hash),
4897c478bd9Sstevel@tonic-gate	enumh_$1(VNA1_flags),
4907c478bd9Sstevel@tonic-gate	enumh_$1(VNA1_other),
4917c478bd9Sstevel@tonic-gate	enuma_$1(VNA1_name),
4927c478bd9Sstevel@tonic-gate	enumw_$1(VNA1_next)`'ifelse(`$2', `', `', `,
4937c478bd9Sstevel@tonic-gate	VNA1_sizeof')
4947c478bd9Sstevel@tonic-gate};')
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gateVernaux_1(L)
4977c478bd9Sstevel@tonic-gateVernaux_1(M,1)
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate/*
5017c478bd9Sstevel@tonic-gate *	Translation function declarations.
5027c478bd9Sstevel@tonic-gate *
5037c478bd9Sstevel@tonic-gate *		<object>_<data><dver><sver>_tof
5047c478bd9Sstevel@tonic-gate *		<object>_<data><dver><sver>_tom
5057c478bd9Sstevel@tonic-gate *	where
5067c478bd9Sstevel@tonic-gate *		<data>	2L	ELFDATA2LSB
5077c478bd9Sstevel@tonic-gate *			2M	ELFDATA2MSB
5087c478bd9Sstevel@tonic-gate */
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gatestatic void	addr_2L_tof(), addr_2L_tom(),
5117c478bd9Sstevel@tonic-gate		addr_2M_tof(), addr_2M_tom(),
5127c478bd9Sstevel@tonic-gate		byte_to(),
5137c478bd9Sstevel@tonic-gate		dyn_2L11_tof(), dyn_2L11_tom(),
5147c478bd9Sstevel@tonic-gate		dyn_2M11_tof(), dyn_2M11_tom(),
5157c478bd9Sstevel@tonic-gate		ehdr_2L11_tof(), ehdr_2L11_tom(),
5167c478bd9Sstevel@tonic-gate		ehdr_2M11_tof(), ehdr_2M11_tom(),
5177c478bd9Sstevel@tonic-gate		half_2L_tof(), half_2L_tom(),
5187c478bd9Sstevel@tonic-gate		half_2M_tof(), half_2M_tom(),
5197c478bd9Sstevel@tonic-gate		move_2L11_tof(), move_2L11_tom(),
5207c478bd9Sstevel@tonic-gate		move_2M11_tof(), move_2M11_tom(),
5217c478bd9Sstevel@tonic-gate		movep_2L11_tof(), movep_2L11_tom(),
5227c478bd9Sstevel@tonic-gate		movep_2M11_tof(), movep_2M11_tom(),
5237c478bd9Sstevel@tonic-gate		off_2L_tof(), off_2L_tom(),
5247c478bd9Sstevel@tonic-gate		off_2M_tof(), off_2M_tom(),
5257c478bd9Sstevel@tonic-gate		note_2L11_tof(), note_2L11_tom(),
5267c478bd9Sstevel@tonic-gate		note_2M11_tof(), note_2M11_tom(),
5277c478bd9Sstevel@tonic-gate		phdr_2L11_tof(), phdr_2L11_tom(),
5287c478bd9Sstevel@tonic-gate		phdr_2M11_tof(), phdr_2M11_tom(),
5297c478bd9Sstevel@tonic-gate		rel_2L11_tof(), rel_2L11_tom(),
5307c478bd9Sstevel@tonic-gate		rel_2M11_tof(), rel_2M11_tom(),
5317c478bd9Sstevel@tonic-gate		rela_2L11_tof(), rela_2L11_tom(),
5327c478bd9Sstevel@tonic-gate		rela_2M11_tof(), rela_2M11_tom(),
5337c478bd9Sstevel@tonic-gate		shdr_2L11_tof(), shdr_2L11_tom(),
5347c478bd9Sstevel@tonic-gate		shdr_2M11_tof(), shdr_2M11_tom(),
5357c478bd9Sstevel@tonic-gate		sword_2L_tof(), sword_2L_tom(),
5367c478bd9Sstevel@tonic-gate		sword_2M_tof(), sword_2M_tom(),
5377c478bd9Sstevel@tonic-gate		sym_2L11_tof(), sym_2L11_tom(),
5387c478bd9Sstevel@tonic-gate		sym_2M11_tof(), sym_2M11_tom(),
5397c478bd9Sstevel@tonic-gate		syminfo_2L11_tof(), syminfo_2L11_tom(),
5407c478bd9Sstevel@tonic-gate		syminfo_2M11_tof(), syminfo_2M11_tom(),
5417c478bd9Sstevel@tonic-gate		word_2L_tof(), word_2L_tom(),
5427c478bd9Sstevel@tonic-gate		word_2M_tof(), word_2M_tom(),
5437c478bd9Sstevel@tonic-gate		verdef_2L11_tof(), verdef_2L11_tom(),
5447c478bd9Sstevel@tonic-gate		verdef_2M11_tof(), verdef_2M11_tom(),
5457c478bd9Sstevel@tonic-gate		verneed_2L11_tof(), verneed_2L11_tom(),
5467c478bd9Sstevel@tonic-gate		verneed_2M11_tof(), verneed_2M11_tom(),
5477c478bd9Sstevel@tonic-gate		cap_2L11_tof(), cap_2L11_tom(),
5487c478bd9Sstevel@tonic-gate		cap_2M11_tof(), cap_2M11_tom();
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate/*	x32 [dst_version - 1] [src_version - 1] [encode - 1] [type]
5527c478bd9Sstevel@tonic-gate */
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gatestatic struct {
5557c478bd9Sstevel@tonic-gate	void	(*x_tof)(),
5567c478bd9Sstevel@tonic-gate		(*x_tom)();
5577c478bd9Sstevel@tonic-gate} x32 [EV_CURRENT] [EV_CURRENT] [ELFDATANUM - 1] [ELF_T_NUM] =
5587c478bd9Sstevel@tonic-gate{
5597c478bd9Sstevel@tonic-gate	{
5607c478bd9Sstevel@tonic-gate		{
5617c478bd9Sstevel@tonic-gate			{			/* [1-1][1-1][2LSB-1][.] */
5627c478bd9Sstevel@tonic-gate/* BYTE */			{ byte_to, byte_to },
5637c478bd9Sstevel@tonic-gate/* ADDR */			{ addr_2L_tof, addr_2L_tom },
5647c478bd9Sstevel@tonic-gate/* DYN */			{ dyn_2L11_tof, dyn_2L11_tom },
5657c478bd9Sstevel@tonic-gate/* EHDR */			{ ehdr_2L11_tof, ehdr_2L11_tom },
5667c478bd9Sstevel@tonic-gate/* HALF */			{ half_2L_tof, half_2L_tom },
5677c478bd9Sstevel@tonic-gate/* OFF */			{ off_2L_tof, off_2L_tom },
5687c478bd9Sstevel@tonic-gate/* PHDR */			{ phdr_2L11_tof, phdr_2L11_tom },
5697c478bd9Sstevel@tonic-gate/* RELA */			{ rela_2L11_tof, rela_2L11_tom },
5707c478bd9Sstevel@tonic-gate/* REL */			{ rel_2L11_tof, rel_2L11_tom },
5717c478bd9Sstevel@tonic-gate/* SHDR */			{ shdr_2L11_tof, shdr_2L11_tom },
5727c478bd9Sstevel@tonic-gate/* SWORD */			{ sword_2L_tof, sword_2L_tom },
5737c478bd9Sstevel@tonic-gate/* SYM */			{ sym_2L11_tof, sym_2L11_tom },
5747c478bd9Sstevel@tonic-gate/* WORD */			{ word_2L_tof, word_2L_tom },
5757c478bd9Sstevel@tonic-gate/* VERDEF */			{ verdef_2L11_tof, verdef_2L11_tom},
5767c478bd9Sstevel@tonic-gate/* VERNEED */			{ verneed_2L11_tof, verneed_2L11_tom},
5777c478bd9Sstevel@tonic-gate/* SXWORD */			{ 0, 0 },	/* illegal 32-bit op */
5787c478bd9Sstevel@tonic-gate/* XWORD */			{ 0, 0 },	/* illegal 32-bit op */
5797c478bd9Sstevel@tonic-gate/* SYMINFO */			{ syminfo_2L11_tof, syminfo_2L11_tom },
5807c478bd9Sstevel@tonic-gate/* NOTE */			{ note_2L11_tof, note_2L11_tom },
5817c478bd9Sstevel@tonic-gate/* MOVE */			{ move_2L11_tof, move_2L11_tom },
5827c478bd9Sstevel@tonic-gate/* MOVEP */			{ movep_2L11_tof, movep_2L11_tom },
5837c478bd9Sstevel@tonic-gate/* CAP */			{ cap_2L11_tof, cap_2L11_tom },
5847c478bd9Sstevel@tonic-gate			},
5857c478bd9Sstevel@tonic-gate			{			/* [1-1][1-1][2MSB-1][.] */
5867c478bd9Sstevel@tonic-gate/* BYTE */			{ byte_to, byte_to },
5877c478bd9Sstevel@tonic-gate/* ADDR */			{ addr_2M_tof, addr_2M_tom },
5887c478bd9Sstevel@tonic-gate/* DYN */			{ dyn_2M11_tof, dyn_2M11_tom },
5897c478bd9Sstevel@tonic-gate/* EHDR */			{ ehdr_2M11_tof, ehdr_2M11_tom },
5907c478bd9Sstevel@tonic-gate/* HALF */			{ half_2M_tof, half_2M_tom },
5917c478bd9Sstevel@tonic-gate/* OFF */			{ off_2M_tof, off_2M_tom },
5927c478bd9Sstevel@tonic-gate/* PHDR */			{ phdr_2M11_tof, phdr_2M11_tom },
5937c478bd9Sstevel@tonic-gate/* RELA */			{ rela_2M11_tof, rela_2M11_tom },
5947c478bd9Sstevel@tonic-gate/* REL */			{ rel_2M11_tof, rel_2M11_tom },
5957c478bd9Sstevel@tonic-gate/* SHDR */			{ shdr_2M11_tof, shdr_2M11_tom },
5967c478bd9Sstevel@tonic-gate/* SWORD */			{ sword_2M_tof, sword_2M_tom },
5977c478bd9Sstevel@tonic-gate/* SYM */			{ sym_2M11_tof, sym_2M11_tom },
5987c478bd9Sstevel@tonic-gate/* WORD */			{ word_2M_tof, word_2M_tom },
5997c478bd9Sstevel@tonic-gate/* VERDEF */			{ verdef_2M11_tof, verdef_2M11_tom},
6007c478bd9Sstevel@tonic-gate/* VERNEED */			{ verneed_2M11_tof, verneed_2M11_tom},
6017c478bd9Sstevel@tonic-gate/* SXWORD */			{ 0, 0 },	/* illegal 32-bit op */
6027c478bd9Sstevel@tonic-gate/* XWORD */			{ 0, 0 },	/* illegal 32-bit op */
6037c478bd9Sstevel@tonic-gate/* SYMINFO */			{ syminfo_2M11_tof, syminfo_2M11_tom },
6047c478bd9Sstevel@tonic-gate/* NOTE */			{ note_2M11_tof, note_2M11_tom },
6057c478bd9Sstevel@tonic-gate/* MOVE */			{ move_2M11_tof, move_2M11_tom },
6067c478bd9Sstevel@tonic-gate/* MOVEP */			{ movep_2M11_tof, movep_2M11_tom },
6077c478bd9Sstevel@tonic-gate/* CAP */			{ cap_2M11_tof, cap_2M11_tom },
6087c478bd9Sstevel@tonic-gate			},
6097c478bd9Sstevel@tonic-gate		},
6107c478bd9Sstevel@tonic-gate	},
6117c478bd9Sstevel@tonic-gate};
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate/*
6157c478bd9Sstevel@tonic-gate *	size [version - 1] [type]
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gatestatic const struct {
6197c478bd9Sstevel@tonic-gate	size_t	s_filesz,
6207c478bd9Sstevel@tonic-gate		s_memsz;
6217c478bd9Sstevel@tonic-gate} fmsize [EV_CURRENT] [ELF_T_NUM] =
6227c478bd9Sstevel@tonic-gate{
6237c478bd9Sstevel@tonic-gate	{					/* [1-1][.] */
6247c478bd9Sstevel@tonic-gate/* BYTE */	{ 1, 1 },
6257c478bd9Sstevel@tonic-gate/* ADDR */	{ A_sizeof, sizeof (Elf32_Addr) },
6267c478bd9Sstevel@tonic-gate/* DYN */	{ D1_sizeof, sizeof (Elf32_Dyn) },
6277c478bd9Sstevel@tonic-gate/* EHDR */	{ E1_sizeof, sizeof (Elf32_Ehdr) },
6287c478bd9Sstevel@tonic-gate/* HALF */	{ H_sizeof, sizeof (Elf32_Half) },
6297c478bd9Sstevel@tonic-gate/* OFF */	{ O_sizeof, sizeof (Elf32_Off) },
6307c478bd9Sstevel@tonic-gate/* PHDR */	{ P1_sizeof, sizeof (Elf32_Phdr) },
6317c478bd9Sstevel@tonic-gate/* RELA */	{ RA1_sizeof, sizeof (Elf32_Rela) },
6327c478bd9Sstevel@tonic-gate/* REL */	{ R1_sizeof, sizeof (Elf32_Rel) },
6337c478bd9Sstevel@tonic-gate/* SHDR */	{ SH1_sizeof, sizeof (Elf32_Shdr) },
6347c478bd9Sstevel@tonic-gate/* SWORD */	{ W_sizeof, sizeof (Elf32_Sword) },
6357c478bd9Sstevel@tonic-gate/* SYM */	{ ST1_sizeof, sizeof (Elf32_Sym) },
6367c478bd9Sstevel@tonic-gate/* WORD */	{ W_sizeof, sizeof (Elf32_Word) },
6377c478bd9Sstevel@tonic-gate/* VERDEF */	{ 1, 1},	/* because bot VERDEF & VERNEED have varying */
6387c478bd9Sstevel@tonic-gate/* VERNEED */	{ 1, 1},	/* sized structures we set their sizes */
6397c478bd9Sstevel@tonic-gate				/* to 1 byte */
6407c478bd9Sstevel@tonic-gate/* SXWORD */			{ 0, 0 },	/* illegal 32-bit op */
6417c478bd9Sstevel@tonic-gate/* XWORD */			{ 0, 0 },	/* illegal 32-bit op */
6427c478bd9Sstevel@tonic-gate/* SYMINFO */	{ SI1_sizeof, sizeof (Elf32_Syminfo) },
6437c478bd9Sstevel@tonic-gate/* NOTE */	{ 1, 1},	/* NOTE has varying sized data we can't */
6447c478bd9Sstevel@tonic-gate				/*  use the usual table magic. */
6457c478bd9Sstevel@tonic-gate/* MOVE */	{ M1_sizeof, sizeof (Elf32_Move) },
6467c478bd9Sstevel@tonic-gate/* MOVEP */	{ MP1_sizeof, sizeof (Elf32_Move) },
6477c478bd9Sstevel@tonic-gate/* CAP */	{ C1_sizeof, sizeof (Elf32_Cap) },
6487c478bd9Sstevel@tonic-gate	},
6497c478bd9Sstevel@tonic-gate};
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate/*
6537c478bd9Sstevel@tonic-gate *	memory type [version - 1] [section type]
6547c478bd9Sstevel@tonic-gate */
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gatestatic const Elf_Type	mtype[EV_CURRENT][SHT_NUM] =
6577c478bd9Sstevel@tonic-gate{
6587c478bd9Sstevel@tonic-gate	{			/* [1-1][.] */
6597c478bd9Sstevel@tonic-gate/* NULL */		ELF_T_BYTE,
6607c478bd9Sstevel@tonic-gate/* PROGBITS */		ELF_T_BYTE,
6617c478bd9Sstevel@tonic-gate/* SYMTAB */		ELF_T_SYM,
6627c478bd9Sstevel@tonic-gate/* STRTAB */		ELF_T_BYTE,
6637c478bd9Sstevel@tonic-gate/* RELA */		ELF_T_RELA,
6647c478bd9Sstevel@tonic-gate/* HASH */		ELF_T_WORD,
6657c478bd9Sstevel@tonic-gate/* DYNAMIC */		ELF_T_DYN,
6667c478bd9Sstevel@tonic-gate/* NOTE */		ELF_T_NOTE,
6677c478bd9Sstevel@tonic-gate/* NOBITS */		ELF_T_BYTE,
6687c478bd9Sstevel@tonic-gate/* REL */		ELF_T_REL,
6697c478bd9Sstevel@tonic-gate/* SHLIB */		ELF_T_BYTE,
6707c478bd9Sstevel@tonic-gate/* DYNSYM */		ELF_T_SYM,
6717c478bd9Sstevel@tonic-gate/* UNKNOWN12 */		ELF_T_BYTE,
6727c478bd9Sstevel@tonic-gate/* UNKNOWN13 */		ELF_T_BYTE,
6737c478bd9Sstevel@tonic-gate/* INIT_ARRAY */	ELF_T_ADDR,
6747c478bd9Sstevel@tonic-gate/* FINI_ARRAY */	ELF_T_ADDR,
6757c478bd9Sstevel@tonic-gate/* PREINIT_ARRAY */	ELF_T_ADDR,
6767c478bd9Sstevel@tonic-gate/* GROUP */		ELF_T_WORD,
6777c478bd9Sstevel@tonic-gate/* SYMTAB_SHNDX */	ELF_T_WORD
6787c478bd9Sstevel@tonic-gate	},
6797c478bd9Sstevel@tonic-gate};
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gatesize_t
6837c478bd9Sstevel@tonic-gateelf32_fsize(Elf_Type type, size_t count, unsigned ver)
6847c478bd9Sstevel@tonic-gate{
6857c478bd9Sstevel@tonic-gate	if (--ver >= EV_CURRENT) {
6867c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_VER, 0);
6877c478bd9Sstevel@tonic-gate		return (0);
6887c478bd9Sstevel@tonic-gate	}
6897c478bd9Sstevel@tonic-gate	if ((unsigned)type >= ELF_T_NUM) {
6907c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_TYPE, 0);
6917c478bd9Sstevel@tonic-gate		return (0);
6927c478bd9Sstevel@tonic-gate	}
6937c478bd9Sstevel@tonic-gate	return (fmsize[ver][type].s_filesz * count);
6947c478bd9Sstevel@tonic-gate}
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate
6977c478bd9Sstevel@tonic-gatesize_t
6987c478bd9Sstevel@tonic-gate_elf32_msize(Elf_Type type, unsigned ver)
6997c478bd9Sstevel@tonic-gate{
7007c478bd9Sstevel@tonic-gate	return (fmsize[ver - 1][type].s_memsz);
7017c478bd9Sstevel@tonic-gate}
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gateElf_Type
7057c478bd9Sstevel@tonic-gate_elf32_mtype(Elf * elf, Elf32_Word shtype, unsigned ver)
7067c478bd9Sstevel@tonic-gate{
7077c478bd9Sstevel@tonic-gate	Elf32_Ehdr *	ehdr = (Elf32_Ehdr *)elf->ed_ehdr;
7087c478bd9Sstevel@tonic-gate
7097c478bd9Sstevel@tonic-gate	if (shtype < SHT_NUM)
7107c478bd9Sstevel@tonic-gate		return (mtype[ver - 1][shtype]);
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate	switch (shtype) {
7137a5d89c4Sab196087	case SHT_SUNW_symsort:
7147a5d89c4Sab196087	case SHT_SUNW_tlssort:
7157a5d89c4Sab196087		return (ELF_T_WORD);
7167a5d89c4Sab196087	case SHT_SUNW_LDYNSYM:
7177a5d89c4Sab196087		return (ELF_T_SYM);
7187c478bd9Sstevel@tonic-gate	case SHT_SUNW_dof:
7197c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7207c478bd9Sstevel@tonic-gate	case SHT_SUNW_cap:
7217c478bd9Sstevel@tonic-gate		return (ELF_T_CAP);
72208278a5eSRod Evans	case SHT_SUNW_capchain:
72308278a5eSRod Evans		return (ELF_T_WORD);
72408278a5eSRod Evans	case SHT_SUNW_capinfo:
72508278a5eSRod Evans		return (ELF_T_WORD);
7267c478bd9Sstevel@tonic-gate	case SHT_SUNW_SIGNATURE:
7277c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7287c478bd9Sstevel@tonic-gate	case SHT_SUNW_ANNOTATE:
7297c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7307c478bd9Sstevel@tonic-gate	case SHT_SUNW_DEBUGSTR:
7317c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7327c478bd9Sstevel@tonic-gate	case SHT_SUNW_DEBUG:
7337c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7347c478bd9Sstevel@tonic-gate	case SHT_SUNW_move:
7357c478bd9Sstevel@tonic-gate		/*
7367c478bd9Sstevel@tonic-gate		 * 32bit sparc binaries have a padded
7377c478bd9Sstevel@tonic-gate		 * MOVE structure.  So - return the
7387c478bd9Sstevel@tonic-gate		 * appropriate type.
7397c478bd9Sstevel@tonic-gate		 */
7407c478bd9Sstevel@tonic-gate		if ((ehdr->e_machine == EM_SPARC) ||
7417c478bd9Sstevel@tonic-gate		    (ehdr->e_machine == EM_SPARC32PLUS)) {
7427c478bd9Sstevel@tonic-gate			return (ELF_T_MOVEP);
7437c478bd9Sstevel@tonic-gate		}
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate		return (ELF_T_MOVE);
7467c478bd9Sstevel@tonic-gate	case SHT_SUNW_COMDAT:
7477c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7487c478bd9Sstevel@tonic-gate	case SHT_SUNW_syminfo:
7497c478bd9Sstevel@tonic-gate		return (ELF_T_SYMINFO);
7507c478bd9Sstevel@tonic-gate	case SHT_SUNW_verdef:
7517c478bd9Sstevel@tonic-gate		return (ELF_T_VDEF);
7527c478bd9Sstevel@tonic-gate	case SHT_SUNW_verneed:
7537c478bd9Sstevel@tonic-gate		return (ELF_T_VNEED);
7547c478bd9Sstevel@tonic-gate	case SHT_SUNW_versym:
7557c478bd9Sstevel@tonic-gate		return (ELF_T_HALF);
7567c478bd9Sstevel@tonic-gate	};
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate	/*
7597c478bd9Sstevel@tonic-gate	 * Check for the sparc specific section types
7607c478bd9Sstevel@tonic-gate	 * below.
7617c478bd9Sstevel@tonic-gate	 */
7627c478bd9Sstevel@tonic-gate	if (((ehdr->e_machine == EM_SPARC) ||
7637c478bd9Sstevel@tonic-gate	    (ehdr->e_machine == EM_SPARC32PLUS) ||
7647c478bd9Sstevel@tonic-gate	    (ehdr->e_machine == EM_SPARCV9)) &&
7657c478bd9Sstevel@tonic-gate	    (shtype == SHT_SPARC_GOTDATA))
7667c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate	/*
7697c478bd9Sstevel@tonic-gate	 * Check for the amd64 specific section types
7707c478bd9Sstevel@tonic-gate	 * below.
7717c478bd9Sstevel@tonic-gate	 */
7727c478bd9Sstevel@tonic-gate	if ((ehdr->e_machine == EM_AMD64) &&
7737c478bd9Sstevel@tonic-gate	    (shtype == SHT_AMD64_UNWIND))
7747c478bd9Sstevel@tonic-gate		return (ELF_T_BYTE);
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate	/*
7777c478bd9Sstevel@tonic-gate	 * And the default is ELF_T_BYTE - but we should
7787c478bd9Sstevel@tonic-gate	 * certainly have caught any sections we know about
7797c478bd9Sstevel@tonic-gate	 * above.  This is for unknown sections to libelf.
7807c478bd9Sstevel@tonic-gate	 */
7817c478bd9Sstevel@tonic-gate	return (ELF_T_BYTE);
7827c478bd9Sstevel@tonic-gate}
7837c478bd9Sstevel@tonic-gate
7847c478bd9Sstevel@tonic-gate
7857a5d89c4Sab196087size_t
7867a5d89c4Sab196087_elf32_entsz(Elf *elf, Elf32_Word shtype, unsigned ver)
7877a5d89c4Sab196087{
7887a5d89c4Sab196087	Elf_Type	ttype;
7897a5d89c4Sab196087
7907a5d89c4Sab196087	ttype = _elf32_mtype(elf, shtype, ver);
7917a5d89c4Sab196087	return ((ttype == ELF_T_BYTE) ? 0 : fmsize[ver - 1][ttype].s_filesz);
7927a5d89c4Sab196087}
7937a5d89c4Sab196087
7947a5d89c4Sab196087
7957c478bd9Sstevel@tonic-gate/*
796f3324781Sab196087 * Determine the data encoding used by the current system.
797f3324781Sab196087 */
798f3324781Sab196087uint_t
799f3324781Sab196087_elf_sys_encoding(void)
800f3324781Sab196087{
801f3324781Sab196087	union {
802f3324781Sab196087		Elf32_Word	w;
803f3324781Sab196087		unsigned char	c[W_sizeof];
804f3324781Sab196087	} u;
805f3324781Sab196087
806f3324781Sab196087	u.w = 0x10203;
807f3324781Sab196087	/*CONSTANTCONDITION*/
808f3324781Sab196087	if (~(Elf32_Word)0 == -(Elf32_Sword)1 && tomw(u.c, W_L) == 0x10203)
809f3324781Sab196087		return (ELFDATA2LSB);
810f3324781Sab196087
811f3324781Sab196087	/*CONSTANTCONDITION*/
812f3324781Sab196087	if (~(Elf32_Word)0 == -(Elf32_Sword)1 && tomw(u.c, W_M) == 0x10203)
813f3324781Sab196087		return (ELFDATA2MSB);
814f3324781Sab196087
815f3324781Sab196087	/* Not expected to occur */
816f3324781Sab196087	return (ELFDATANONE);
817f3324781Sab196087}
818f3324781Sab196087
819f3324781Sab196087
820f3324781Sab196087/*
8217c478bd9Sstevel@tonic-gate * XX64	This routine is also used to 'version' interactions with Elf64
8227c478bd9Sstevel@tonic-gate *	applications, but there's no way to figure out if the caller is
8237c478bd9Sstevel@tonic-gate *	asking Elf32 or Elf64 questions, even though it has Elf32
8247c478bd9Sstevel@tonic-gate *	dependencies.  Ick.
8257c478bd9Sstevel@tonic-gate */
8267c478bd9Sstevel@tonic-gateunsigned
8277c478bd9Sstevel@tonic-gateelf_version(unsigned ver)
8287c478bd9Sstevel@tonic-gate{
8297c478bd9Sstevel@tonic-gate	register unsigned	j;
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate	if (ver == EV_NONE)
8327c478bd9Sstevel@tonic-gate		return EV_CURRENT;
8337c478bd9Sstevel@tonic-gate	if (ver > EV_CURRENT)
8347c478bd9Sstevel@tonic-gate	{
8357c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_VER, 0);
8367c478bd9Sstevel@tonic-gate		return EV_NONE;
8377c478bd9Sstevel@tonic-gate	}
8387c478bd9Sstevel@tonic-gate	(void) mutex_lock(&_elf_globals_mutex);
8397c478bd9Sstevel@tonic-gate	if (_elf_work != EV_NONE)
8407c478bd9Sstevel@tonic-gate	{
8417c478bd9Sstevel@tonic-gate		j = _elf_work;
8427c478bd9Sstevel@tonic-gate		_elf_work = ver;
8437c478bd9Sstevel@tonic-gate		(void) mutex_unlock(&_elf_globals_mutex);
8447c478bd9Sstevel@tonic-gate		return j;
8457c478bd9Sstevel@tonic-gate	}
8467c478bd9Sstevel@tonic-gate	_elf_work = ver;
8477c478bd9Sstevel@tonic-gate
848f3324781Sab196087	_elf_encode = _elf_sys_encoding();
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate	(void) mutex_unlock(&_elf_globals_mutex);
8517c478bd9Sstevel@tonic-gate
8527c478bd9Sstevel@tonic-gate	return ver;
8537c478bd9Sstevel@tonic-gate}
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gatestatic Elf_Data *
8577c478bd9Sstevel@tonic-gatexlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof)
8587c478bd9Sstevel@tonic-gate						/* tof !0 -> xlatetof */
8597c478bd9Sstevel@tonic-gate{
8607c478bd9Sstevel@tonic-gate	size_t		cnt, dsz, ssz;
8617c478bd9Sstevel@tonic-gate	unsigned	type;
8627c478bd9Sstevel@tonic-gate	unsigned	dver, sver;
8637c478bd9Sstevel@tonic-gate	void		(*f)();
8647c478bd9Sstevel@tonic-gate	unsigned	_encode;
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate	if (dst == 0 || src == 0)
8677c478bd9Sstevel@tonic-gate		return (0);
8687c478bd9Sstevel@tonic-gate	if (--encode >= (ELFDATANUM - 1)) {
8697c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_ENCODE, 0);
8707c478bd9Sstevel@tonic-gate		return (0);
8717c478bd9Sstevel@tonic-gate	}
8727c478bd9Sstevel@tonic-gate	if ((dver = dst->d_version - 1) >= EV_CURRENT ||
8737c478bd9Sstevel@tonic-gate	    (sver = src->d_version - 1) >= EV_CURRENT) {
8747c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_VER, 0);
8757c478bd9Sstevel@tonic-gate		return (0);
8767c478bd9Sstevel@tonic-gate	}
8777c478bd9Sstevel@tonic-gate	if ((type = src->d_type) >= ELF_T_NUM) {
8787c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_TYPE, 0);
8797c478bd9Sstevel@tonic-gate		return (0);
8807c478bd9Sstevel@tonic-gate	}
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate	if (tof) {
8837c478bd9Sstevel@tonic-gate		dsz = fmsize[dver][type].s_filesz;
8847c478bd9Sstevel@tonic-gate		ssz = fmsize[sver][type].s_memsz;
8857c478bd9Sstevel@tonic-gate		f = x32[dver][sver][encode][type].x_tof;
8867c478bd9Sstevel@tonic-gate	} else {
8877c478bd9Sstevel@tonic-gate		dsz = fmsize[dver][type].s_memsz;
8887c478bd9Sstevel@tonic-gate		ssz = fmsize[sver][type].s_filesz;
8897c478bd9Sstevel@tonic-gate		f = x32[dver][sver][encode][type].x_tom;
8907c478bd9Sstevel@tonic-gate	}
8917c478bd9Sstevel@tonic-gate	cnt = src->d_size / ssz;
8927c478bd9Sstevel@tonic-gate	if (dst->d_size < dsz * cnt) {
8937c478bd9Sstevel@tonic-gate		_elf_seterr(EREQ_DSZ, 0);
8947c478bd9Sstevel@tonic-gate		return (0);
8957c478bd9Sstevel@tonic-gate	}
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate	ELFACCESSDATA(_encode, _elf_encode)
8987c478bd9Sstevel@tonic-gate	if ((_encode == (encode + 1)) && (dsz == ssz)) {
8997c478bd9Sstevel@tonic-gate		/*
9007c478bd9Sstevel@tonic-gate		 *	ld(1) frequently produces empty sections (eg. .dynsym,
9017c478bd9Sstevel@tonic-gate		 *	.dynstr, .symtab, .strtab, etc) so that the initial
9027c478bd9Sstevel@tonic-gate		 *	output image can be created of the correct size.  Later
9037c478bd9Sstevel@tonic-gate		 *	these sections are filled in with the associated data.
9047c478bd9Sstevel@tonic-gate		 *	So that we don't have to pre-allocate buffers for
9057c478bd9Sstevel@tonic-gate		 *	these segments, allow for the src destination to be 0.
9067c478bd9Sstevel@tonic-gate		 */
9077c478bd9Sstevel@tonic-gate		if (src->d_buf && src->d_buf != dst->d_buf)
9087c478bd9Sstevel@tonic-gate			(void) memcpy(dst->d_buf, src->d_buf, src->d_size);
9097c478bd9Sstevel@tonic-gate		dst->d_type = src->d_type;
9107c478bd9Sstevel@tonic-gate		dst->d_size = src->d_size;
9117c478bd9Sstevel@tonic-gate		return (dst);
9127c478bd9Sstevel@tonic-gate	}
9137c478bd9Sstevel@tonic-gate	if (cnt)
9147c478bd9Sstevel@tonic-gate		(*f)(dst->d_buf, src->d_buf, cnt);
9157c478bd9Sstevel@tonic-gate	dst->d_size = dsz * cnt;
9167c478bd9Sstevel@tonic-gate	dst->d_type = src->d_type;
9177c478bd9Sstevel@tonic-gate	return (dst);
9187c478bd9Sstevel@tonic-gate}
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gateElf_Data *
9227c478bd9Sstevel@tonic-gateelf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode)
9237c478bd9Sstevel@tonic-gate{
9247c478bd9Sstevel@tonic-gate	return (xlate(dst, src, encode, 1));
9257c478bd9Sstevel@tonic-gate}
9267c478bd9Sstevel@tonic-gate
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gateElf_Data *
9297c478bd9Sstevel@tonic-gateelf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode)
9307c478bd9Sstevel@tonic-gate{
9317c478bd9Sstevel@tonic-gate	return (xlate(dst, src, encode, 0));
9327c478bd9Sstevel@tonic-gate}
9337c478bd9Sstevel@tonic-gate
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate/*
9367c478bd9Sstevel@tonic-gate * xlate to file format
9377c478bd9Sstevel@tonic-gate *
9387c478bd9Sstevel@tonic-gate *	..._tof(name, data) -- macros
9397c478bd9Sstevel@tonic-gate *
9407c478bd9Sstevel@tonic-gate *	Recall that the file format must be no larger than the
9417c478bd9Sstevel@tonic-gate *	memory format (equal versions).  Use "forward" copy.
9427c478bd9Sstevel@tonic-gate *	All these routines require non-null, non-zero arguments.
9437c478bd9Sstevel@tonic-gate */
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gatedefine(addr_tof, `
9467c478bd9Sstevel@tonic-gatestatic void
9477c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Addr *src, size_t cnt)
9487c478bd9Sstevel@tonic-gate{
9497c478bd9Sstevel@tonic-gate	Elf32_Addr	*end = src + cnt;
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate	do {
9527c478bd9Sstevel@tonic-gate		tofa(dst, *src, A_$2);
9537c478bd9Sstevel@tonic-gate		dst += A_sizeof;
9547c478bd9Sstevel@tonic-gate	} while (++src < end);
9557c478bd9Sstevel@tonic-gate}')
9567c478bd9Sstevel@tonic-gate
9577c478bd9Sstevel@tonic-gateaddr_tof(addr_2L_tof,L)
9587c478bd9Sstevel@tonic-gateaddr_tof(addr_2M_tof,M)
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gatestatic void
9627c478bd9Sstevel@tonic-gatebyte_to(unsigned char *dst, unsigned char *src, size_t cnt)
9637c478bd9Sstevel@tonic-gate{
9647c478bd9Sstevel@tonic-gate	if (dst != src)
9657c478bd9Sstevel@tonic-gate		(void) memcpy(dst, src, cnt);
9667c478bd9Sstevel@tonic-gate}
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gatedefine(dyn_11_tof, `
9707c478bd9Sstevel@tonic-gatestatic void
9717c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Dyn *src, size_t cnt)
9727c478bd9Sstevel@tonic-gate{
9737c478bd9Sstevel@tonic-gate	Elf32_Dyn	*end = src + cnt;
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate	do {
9767c478bd9Sstevel@tonic-gate		tofw(dst, src->d_tag, D1_tag_$2);
9777c478bd9Sstevel@tonic-gate		tofo(dst, src->d_un.d_val, D1_val_$2);
9787c478bd9Sstevel@tonic-gate		dst += D1_sizeof;
9797c478bd9Sstevel@tonic-gate	} while (++src < end);
9807c478bd9Sstevel@tonic-gate}')
9817c478bd9Sstevel@tonic-gate
9827c478bd9Sstevel@tonic-gatedyn_11_tof(dyn_2L11_tof,L)
9837c478bd9Sstevel@tonic-gatedyn_11_tof(dyn_2M11_tof,M)
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gatedefine(ehdr_11_tof, `
9877c478bd9Sstevel@tonic-gatestatic void
9887c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Ehdr *src, size_t cnt)
9897c478bd9Sstevel@tonic-gate{
9907c478bd9Sstevel@tonic-gate	Elf32_Ehdr	*end = src + cnt;
9917c478bd9Sstevel@tonic-gate
9927c478bd9Sstevel@tonic-gate	do {
9937c478bd9Sstevel@tonic-gate		if (&dst[E1_ident] != src->e_ident)
9947c478bd9Sstevel@tonic-gate			(void) memcpy(&dst[E1_ident], src->e_ident, E1_Nident);
9957c478bd9Sstevel@tonic-gate		tofh(dst, src->e_type, E1_type_$2);
9967c478bd9Sstevel@tonic-gate		tofh(dst, src->e_machine, E1_machine_$2);
9977c478bd9Sstevel@tonic-gate		tofw(dst, src->e_version, E1_version_$2);
9987c478bd9Sstevel@tonic-gate		tofa(dst, src->e_entry, E1_entry_$2);
9997c478bd9Sstevel@tonic-gate		tofo(dst, src->e_phoff, E1_phoff_$2);
10007c478bd9Sstevel@tonic-gate		tofo(dst, src->e_shoff, E1_shoff_$2);
10017c478bd9Sstevel@tonic-gate		tofw(dst, src->e_flags, E1_flags_$2);
10027c478bd9Sstevel@tonic-gate		tofh(dst, src->e_ehsize, E1_ehsize_$2);
10037c478bd9Sstevel@tonic-gate		tofh(dst, src->e_phentsize, E1_phentsize_$2);
10047c478bd9Sstevel@tonic-gate		tofh(dst, src->e_phnum, E1_phnum_$2);
10057c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shentsize, E1_shentsize_$2);
10067c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shnum, E1_shnum_$2);
10077c478bd9Sstevel@tonic-gate		tofh(dst, src->e_shstrndx, E1_shstrndx_$2);
10087c478bd9Sstevel@tonic-gate		dst += E1_sizeof;
10097c478bd9Sstevel@tonic-gate	} while (++src < end);
10107c478bd9Sstevel@tonic-gate}')
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gateehdr_11_tof(ehdr_2L11_tof,L)
10137c478bd9Sstevel@tonic-gateehdr_11_tof(ehdr_2M11_tof,M)
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gatedefine(half_tof, `
10177c478bd9Sstevel@tonic-gatestatic void
10187c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Half *src, size_t cnt)
10197c478bd9Sstevel@tonic-gate{
10207c478bd9Sstevel@tonic-gate	Elf32_Half	*end = src + cnt;
10217c478bd9Sstevel@tonic-gate
10227c478bd9Sstevel@tonic-gate	do {
10237c478bd9Sstevel@tonic-gate		tofh(dst, *src, H_$2);
10247c478bd9Sstevel@tonic-gate		dst += H_sizeof;
10257c478bd9Sstevel@tonic-gate	} while (++src < end);
10267c478bd9Sstevel@tonic-gate}')
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gatehalf_tof(half_2L_tof,L)
10297c478bd9Sstevel@tonic-gatehalf_tof(half_2M_tof,M)
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate
10327c478bd9Sstevel@tonic-gatedefine(move_11_tof, `
10337c478bd9Sstevel@tonic-gatestatic void
10347c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Move *src, size_t cnt)
10357c478bd9Sstevel@tonic-gate{
10367c478bd9Sstevel@tonic-gate	Elf32_Move	*end = src + cnt;
10377c478bd9Sstevel@tonic-gate
10387c478bd9Sstevel@tonic-gate	do {
10397c478bd9Sstevel@tonic-gate		tofl(dst, src->m_value, M1_value_$2);
10407c478bd9Sstevel@tonic-gate		tofw(dst, src->m_info, M1_info_$2);
10417c478bd9Sstevel@tonic-gate		tofw(dst, src->m_poffset, M1_poffset_$2);
10427c478bd9Sstevel@tonic-gate		tofh(dst, src->m_repeat, M1_repeat_$2);
10437c478bd9Sstevel@tonic-gate		tofh(dst, src->m_stride, M1_stride_$2);
10447c478bd9Sstevel@tonic-gate		dst += M1_sizeof;
10457c478bd9Sstevel@tonic-gate	} while (++src < end);
10467c478bd9Sstevel@tonic-gate}')
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gatemove_11_tof(move_2L11_tof,L)
10497c478bd9Sstevel@tonic-gatemove_11_tof(move_2M11_tof,M)
10507c478bd9Sstevel@tonic-gate
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gatedefine(movep_11_tof, `
10537c478bd9Sstevel@tonic-gatestatic void
10547c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Move *src, size_t cnt)
10557c478bd9Sstevel@tonic-gate{
10567c478bd9Sstevel@tonic-gate	Elf32_Move	*end = src + cnt;
10577c478bd9Sstevel@tonic-gate
10587c478bd9Sstevel@tonic-gate	do {
10597c478bd9Sstevel@tonic-gate		tofl(dst, src->m_value, MP1_value_$2);
10607c478bd9Sstevel@tonic-gate		tofw(dst, src->m_info, MP1_info_$2);
10617c478bd9Sstevel@tonic-gate		tofw(dst, src->m_poffset, MP1_poffset_$2);
10627c478bd9Sstevel@tonic-gate		tofh(dst, src->m_repeat, MP1_repeat_$2);
10637c478bd9Sstevel@tonic-gate		tofh(dst, src->m_stride, MP1_stride_$2);
10647c478bd9Sstevel@tonic-gate		dst += MP1_sizeof;
10657c478bd9Sstevel@tonic-gate	} while (++src < end);
10667c478bd9Sstevel@tonic-gate}')
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gatemovep_11_tof(movep_2L11_tof,L)
10697c478bd9Sstevel@tonic-gatemovep_11_tof(movep_2M11_tof,M)
10707c478bd9Sstevel@tonic-gate
10717c478bd9Sstevel@tonic-gate
10727c478bd9Sstevel@tonic-gatedefine(off_tof, `
10737c478bd9Sstevel@tonic-gatestatic void
10747c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Off *src, size_t cnt)
10757c478bd9Sstevel@tonic-gate{
10767c478bd9Sstevel@tonic-gate	Elf32_Off	*end = src + cnt;
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate	do {
10797c478bd9Sstevel@tonic-gate		tofo(dst, *src, O_$2);
10807c478bd9Sstevel@tonic-gate		dst += O_sizeof;
10817c478bd9Sstevel@tonic-gate	} while (++src < end);
10827c478bd9Sstevel@tonic-gate}')
10837c478bd9Sstevel@tonic-gate
10847c478bd9Sstevel@tonic-gateoff_tof(off_2L_tof,L)
10857c478bd9Sstevel@tonic-gateoff_tof(off_2M_tof,M)
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate
10887c478bd9Sstevel@tonic-gatedefine(note_11_tof, `
10897c478bd9Sstevel@tonic-gatestatic void
10907c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Nhdr *src, size_t cnt)
10917c478bd9Sstevel@tonic-gate{
10927c478bd9Sstevel@tonic-gate	/* LINTED */
10937c478bd9Sstevel@tonic-gate	Elf32_Nhdr 	*end = (Elf32_Nhdr *)((char *)src + cnt);
10947c478bd9Sstevel@tonic-gate
1095*3228339cSAli Bahrami	/*
1096*3228339cSAli Bahrami	 * Copy the note data to the source, translating the
1097*3228339cSAli Bahrami	 * length fields. Clip against the size of the actual buffer
1098*3228339cSAli Bahrami	 * to guard against corrupt note data.
1099*3228339cSAli Bahrami	 */
11007c478bd9Sstevel@tonic-gate	do {
11017c478bd9Sstevel@tonic-gate		Elf32_Word	descsz, namesz;
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate		/*
11047c478bd9Sstevel@tonic-gate		 * cache size of desc & name fields - while rounding
11057c478bd9Sstevel@tonic-gate		 * up their size.
11067c478bd9Sstevel@tonic-gate		 */
11077c478bd9Sstevel@tonic-gate		namesz = S_ROUND(src->n_namesz, sizeof (Elf32_Word));
11087c478bd9Sstevel@tonic-gate		descsz = src->n_descsz;
11097c478bd9Sstevel@tonic-gate
11107c478bd9Sstevel@tonic-gate		/*
11117c478bd9Sstevel@tonic-gate		 * Copy contents of Elf32_Nhdr
11127c478bd9Sstevel@tonic-gate		 */
1113*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_namesz) + sizeof(Elf32_Word) +
1114*3228339cSAli Bahrami		    (char *) src) >= (char *) end)
1115*3228339cSAli Bahrami			break;
11167c478bd9Sstevel@tonic-gate		tofw(dst, src->n_namesz, N1_namesz_$2);
1117*3228339cSAli Bahrami
1118*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_descsz) + sizeof(Elf32_Word) +
1119*3228339cSAli Bahrami		    (char *) src) >= (char *) end)
1120*3228339cSAli Bahrami			break;
11217c478bd9Sstevel@tonic-gate		tofw(dst, src->n_descsz, N1_descsz_$2);
1122*3228339cSAli Bahrami
1123*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_type) + sizeof(Elf32_Word) +
1124*3228339cSAli Bahrami		    (char *) src) >= (char *) end)
1125*3228339cSAli Bahrami			break;
11267c478bd9Sstevel@tonic-gate		tofw(dst, src->n_type, N1_type_$2);
11277c478bd9Sstevel@tonic-gate
11287c478bd9Sstevel@tonic-gate		/*
11297c478bd9Sstevel@tonic-gate		 * Copy contents of Name field
11307c478bd9Sstevel@tonic-gate		 */
11317c478bd9Sstevel@tonic-gate		dst += N1_sizeof;
11327c478bd9Sstevel@tonic-gate		src++;
1133*3228339cSAli Bahrami		if ((namesz + (char *) src) > (char *) end) {
1134*3228339cSAli Bahrami			namesz = (char *) end - (char *) src;
1135*3228339cSAli Bahrami			if (namesz == 0)
1136*3228339cSAli Bahrami				break;
1137*3228339cSAli Bahrami		}
11387c478bd9Sstevel@tonic-gate		(void)memcpy(dst, src, namesz);
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate		/*
11417c478bd9Sstevel@tonic-gate		 * Copy contents of desc field
11427c478bd9Sstevel@tonic-gate		 */
11437c478bd9Sstevel@tonic-gate		dst += namesz;
11447c478bd9Sstevel@tonic-gate		src = (Elf32_Nhdr *)((uintptr_t)src + namesz);
1145*3228339cSAli Bahrami		if ((descsz + (char *) src) > (char *) end) {
1146*3228339cSAli Bahrami			descsz = (char *) end - (char *) src;
1147*3228339cSAli Bahrami			if (descsz == 0)
1148*3228339cSAli Bahrami				break;
1149*3228339cSAli Bahrami		}
11507c478bd9Sstevel@tonic-gate		(void)memcpy(dst, src, descsz);
1151*3228339cSAli Bahrami
11527c478bd9Sstevel@tonic-gate		descsz = S_ROUND(descsz, sizeof (Elf32_Word));
11537c478bd9Sstevel@tonic-gate		dst += descsz;
11547c478bd9Sstevel@tonic-gate		src = (Elf32_Nhdr *)((uintptr_t)src + descsz);
11557c478bd9Sstevel@tonic-gate	} while (src < end);
11567c478bd9Sstevel@tonic-gate}')
11577c478bd9Sstevel@tonic-gate
11587c478bd9Sstevel@tonic-gatenote_11_tof(note_2L11_tof,L)
11597c478bd9Sstevel@tonic-gatenote_11_tof(note_2M11_tof,M)
11607c478bd9Sstevel@tonic-gate
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gatedefine(phdr_11_tof, `
11637c478bd9Sstevel@tonic-gatestatic void
11647c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Phdr *src, size_t cnt)
11657c478bd9Sstevel@tonic-gate{
11667c478bd9Sstevel@tonic-gate	Elf32_Phdr	*end = src + cnt;
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate	do {
11697c478bd9Sstevel@tonic-gate		tofw(dst, src->p_type, P1_type_$2);
11707c478bd9Sstevel@tonic-gate		tofo(dst, src->p_offset, P1_offset_$2);
11717c478bd9Sstevel@tonic-gate		tofa(dst, src->p_vaddr, P1_vaddr_$2);
11727c478bd9Sstevel@tonic-gate		tofa(dst, src->p_paddr, P1_paddr_$2);
11737c478bd9Sstevel@tonic-gate		tofw(dst, src->p_filesz, P1_filesz_$2);
11747c478bd9Sstevel@tonic-gate		tofw(dst, src->p_memsz, P1_memsz_$2);
11757c478bd9Sstevel@tonic-gate		tofw(dst, src->p_flags, P1_flags_$2);
11767c478bd9Sstevel@tonic-gate		tofw(dst, src->p_align, P1_align_$2);
11777c478bd9Sstevel@tonic-gate		dst += P1_sizeof;
11787c478bd9Sstevel@tonic-gate	} while (++src < end);
11797c478bd9Sstevel@tonic-gate}')
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gatephdr_11_tof(phdr_2L11_tof,L)
11827c478bd9Sstevel@tonic-gatephdr_11_tof(phdr_2M11_tof,M)
11837c478bd9Sstevel@tonic-gate
11847c478bd9Sstevel@tonic-gate
11857c478bd9Sstevel@tonic-gatedefine(rel_11_tof, `
11867c478bd9Sstevel@tonic-gatestatic void
11877c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Rel *src, size_t cnt)
11887c478bd9Sstevel@tonic-gate{
11897c478bd9Sstevel@tonic-gate	Elf32_Rel	*end = src + cnt;
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate	do {
11927c478bd9Sstevel@tonic-gate		tofa(dst, src->r_offset, R1_offset_$2);
11937c478bd9Sstevel@tonic-gate		tofw(dst, src->r_info, R1_info_$2);
11947c478bd9Sstevel@tonic-gate		dst += R1_sizeof;
11957c478bd9Sstevel@tonic-gate	} while (++src < end);
11967c478bd9Sstevel@tonic-gate}')
11977c478bd9Sstevel@tonic-gate
11987c478bd9Sstevel@tonic-gaterel_11_tof(rel_2L11_tof,L)
11997c478bd9Sstevel@tonic-gaterel_11_tof(rel_2M11_tof,M)
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate
12027c478bd9Sstevel@tonic-gatedefine(rela_11_tof, `
12037c478bd9Sstevel@tonic-gatestatic void
12047c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Rela *src, size_t cnt)
12057c478bd9Sstevel@tonic-gate{
12067c478bd9Sstevel@tonic-gate	Elf32_Rela	*end = src + cnt;
12077c478bd9Sstevel@tonic-gate
12087c478bd9Sstevel@tonic-gate	do {
12097c478bd9Sstevel@tonic-gate		tofa(dst, src->r_offset, RA1_offset_$2);
12107c478bd9Sstevel@tonic-gate		tofw(dst, src->r_info, RA1_info_$2);
12117c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
12127c478bd9Sstevel@tonic-gate		if (~(Elf32_Word)0 == -(Elf32_Sword)1) {	/* 2s comp */
12137c478bd9Sstevel@tonic-gate			tofw(dst, src->r_addend, RA1_addend_$2);
12147c478bd9Sstevel@tonic-gate		} else {
12157c478bd9Sstevel@tonic-gate			Elf32_Word	w;
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate			if (src->r_addend < 0) {
12187c478bd9Sstevel@tonic-gate				w = - src->r_addend;
12197c478bd9Sstevel@tonic-gate				w = ~w + 1;
12207c478bd9Sstevel@tonic-gate			} else
12217c478bd9Sstevel@tonic-gate				w = src->r_addend;
12227c478bd9Sstevel@tonic-gate			tofw(dst, w, RA1_addend_$2);
12237c478bd9Sstevel@tonic-gate		}
12247c478bd9Sstevel@tonic-gate		dst += RA1_sizeof;
12257c478bd9Sstevel@tonic-gate	} while (++src < end);
12267c478bd9Sstevel@tonic-gate}')
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gaterela_11_tof(rela_2L11_tof,L)
12297c478bd9Sstevel@tonic-gaterela_11_tof(rela_2M11_tof,M)
12307c478bd9Sstevel@tonic-gate
12317c478bd9Sstevel@tonic-gate
12327c478bd9Sstevel@tonic-gatedefine(shdr_11_tof, `
12337c478bd9Sstevel@tonic-gatestatic void
12347c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Shdr *src, size_t cnt)
12357c478bd9Sstevel@tonic-gate{
12367c478bd9Sstevel@tonic-gate	Elf32_Shdr	*end = src + cnt;
12377c478bd9Sstevel@tonic-gate
12387c478bd9Sstevel@tonic-gate	do {
12397c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_name, SH1_name_$2);
12407c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_type, SH1_type_$2);
12417c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_flags, SH1_flags_$2);
12427c478bd9Sstevel@tonic-gate		tofa(dst, src->sh_addr, SH1_addr_$2);
12437c478bd9Sstevel@tonic-gate		tofo(dst, src->sh_offset, SH1_offset_$2);
12447c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_size, SH1_size_$2);
12457c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_link, SH1_link_$2);
12467c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_info, SH1_info_$2);
12477c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_addralign, SH1_addralign_$2);
12487c478bd9Sstevel@tonic-gate		tofw(dst, src->sh_entsize, SH1_entsize_$2);
12497c478bd9Sstevel@tonic-gate		dst += SH1_sizeof;
12507c478bd9Sstevel@tonic-gate	} while (++src < end);
12517c478bd9Sstevel@tonic-gate}')
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gateshdr_11_tof(shdr_2L11_tof,L)
12547c478bd9Sstevel@tonic-gateshdr_11_tof(shdr_2M11_tof,M)
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate
12577c478bd9Sstevel@tonic-gatedefine(sword_tof, `
12587c478bd9Sstevel@tonic-gatestatic void
12597c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Sword *src, size_t cnt)
12607c478bd9Sstevel@tonic-gate{
12617c478bd9Sstevel@tonic-gate	Elf32_Sword	*end = src + cnt;
12627c478bd9Sstevel@tonic-gate
12637c478bd9Sstevel@tonic-gate	do {
12647c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
12657c478bd9Sstevel@tonic-gate		if (~(Elf32_Word)0 == -(Elf32_Sword)1) {	/* 2s comp */
12667c478bd9Sstevel@tonic-gate			tofw(dst, *src, W_$2);
12677c478bd9Sstevel@tonic-gate		} else {
12687c478bd9Sstevel@tonic-gate			Elf32_Word	w;
12697c478bd9Sstevel@tonic-gate
12707c478bd9Sstevel@tonic-gate			if (*src < 0) {
12717c478bd9Sstevel@tonic-gate				w = - *src;
12727c478bd9Sstevel@tonic-gate				w = ~w + 1;
12737c478bd9Sstevel@tonic-gate			} else
12747c478bd9Sstevel@tonic-gate				w = *src;
12757c478bd9Sstevel@tonic-gate			tofw(dst, w, W_$2);
12767c478bd9Sstevel@tonic-gate		}
12777c478bd9Sstevel@tonic-gate		dst += W_sizeof;
12787c478bd9Sstevel@tonic-gate	} while (++src < end);
12797c478bd9Sstevel@tonic-gate}')
12807c478bd9Sstevel@tonic-gate
12817c478bd9Sstevel@tonic-gatesword_tof(sword_2L_tof,L)
12827c478bd9Sstevel@tonic-gatesword_tof(sword_2M_tof,M)
12837c478bd9Sstevel@tonic-gate
12847c478bd9Sstevel@tonic-gate
12857c478bd9Sstevel@tonic-gatedefine(cap_11_tof, `
12867c478bd9Sstevel@tonic-gatestatic void
12877c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Cap *src, size_t cnt)
12887c478bd9Sstevel@tonic-gate{
12897c478bd9Sstevel@tonic-gate	Elf32_Cap	*end = src + cnt;
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gate	do {
12927c478bd9Sstevel@tonic-gate		tofw(dst, src->c_tag, C1_tag_$2);
12937c478bd9Sstevel@tonic-gate		tofw(dst, src->c_un.c_val, C1_val_$2);
12947c478bd9Sstevel@tonic-gate		dst += C1_sizeof;
12957c478bd9Sstevel@tonic-gate	} while (++src < end);
12967c478bd9Sstevel@tonic-gate}')
12977c478bd9Sstevel@tonic-gate
12987c478bd9Sstevel@tonic-gatecap_11_tof(cap_2L11_tof,L)
12997c478bd9Sstevel@tonic-gatecap_11_tof(cap_2M11_tof,M)
13007c478bd9Sstevel@tonic-gate
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gatedefine(syminfo_11_tof, `
13037c478bd9Sstevel@tonic-gatestatic void
13047c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Syminfo *src, size_t cnt)
13057c478bd9Sstevel@tonic-gate{
13067c478bd9Sstevel@tonic-gate	Elf32_Syminfo	*end = src + cnt;
13077c478bd9Sstevel@tonic-gate
13087c478bd9Sstevel@tonic-gate	do {
13097c478bd9Sstevel@tonic-gate		tofh(dst, src->si_boundto, SI1_boundto_$2);
13107c478bd9Sstevel@tonic-gate		tofh(dst, src->si_flags, SI1_flags_$2);
13117c478bd9Sstevel@tonic-gate		dst += SI1_sizeof;
13127c478bd9Sstevel@tonic-gate	} while (++src < end);
13137c478bd9Sstevel@tonic-gate}')
13147c478bd9Sstevel@tonic-gate
13157c478bd9Sstevel@tonic-gatesyminfo_11_tof(syminfo_2L11_tof,L)
13167c478bd9Sstevel@tonic-gatesyminfo_11_tof(syminfo_2M11_tof,M)
13177c478bd9Sstevel@tonic-gate
13187c478bd9Sstevel@tonic-gate
13197c478bd9Sstevel@tonic-gatedefine(sym_11_tof, `
13207c478bd9Sstevel@tonic-gatestatic void
13217c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Sym *src, size_t cnt)
13227c478bd9Sstevel@tonic-gate{
13237c478bd9Sstevel@tonic-gate	Elf32_Sym	*end = src + cnt;
13247c478bd9Sstevel@tonic-gate
13257c478bd9Sstevel@tonic-gate	do {
13267c478bd9Sstevel@tonic-gate		tofw(dst, src->st_name, ST1_name_$2);
13277c478bd9Sstevel@tonic-gate		tofa(dst, src->st_value, ST1_value_$2);
13287c478bd9Sstevel@tonic-gate		tofw(dst, src->st_size, ST1_size_$2);
13297c478bd9Sstevel@tonic-gate		tofb(dst, src->st_info, ST1_info_$2);
13307c478bd9Sstevel@tonic-gate		tofb(dst, src->st_other, ST1_other_$2);
13317c478bd9Sstevel@tonic-gate		tofh(dst, src->st_shndx, ST1_shndx_$2);
13327c478bd9Sstevel@tonic-gate		dst += ST1_sizeof;
13337c478bd9Sstevel@tonic-gate	} while (++src < end);
13347c478bd9Sstevel@tonic-gate}')
13357c478bd9Sstevel@tonic-gate
13367c478bd9Sstevel@tonic-gatesym_11_tof(sym_2L11_tof,L)
13377c478bd9Sstevel@tonic-gatesym_11_tof(sym_2M11_tof,M)
13387c478bd9Sstevel@tonic-gate
13397c478bd9Sstevel@tonic-gate
13407c478bd9Sstevel@tonic-gatedefine(word_tof, `
13417c478bd9Sstevel@tonic-gatestatic void
13427c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Word *src, size_t cnt)
13437c478bd9Sstevel@tonic-gate{
13447c478bd9Sstevel@tonic-gate	Elf32_Word	*end = src + cnt;
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate	do {
13477c478bd9Sstevel@tonic-gate		tofw(dst, *src, W_$2);
13487c478bd9Sstevel@tonic-gate		dst += W_sizeof;
13497c478bd9Sstevel@tonic-gate	} while (++src < end);
13507c478bd9Sstevel@tonic-gate}')
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gateword_tof(word_2L_tof,L)
13537c478bd9Sstevel@tonic-gateword_tof(word_2M_tof,M)
13547c478bd9Sstevel@tonic-gate
13557c478bd9Sstevel@tonic-gate
13567c478bd9Sstevel@tonic-gatedefine(verdef_11_tof, `
13577c478bd9Sstevel@tonic-gatestatic void
13587c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Verdef *src, size_t cnt)
13597c478bd9Sstevel@tonic-gate{
13607c478bd9Sstevel@tonic-gate	/* LINTED */
13617c478bd9Sstevel@tonic-gate	Elf32_Verdef	*end = (Elf32_Verdef *)((char *)src + cnt);
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate	do {
13647c478bd9Sstevel@tonic-gate		Elf32_Verdef	*next_verdef;
13657c478bd9Sstevel@tonic-gate		Elf32_Verdaux	*vaux;
13667c478bd9Sstevel@tonic-gate		Elf32_Half	i;
13677c478bd9Sstevel@tonic-gate		unsigned char	*vaux_dst;
13687c478bd9Sstevel@tonic-gate		unsigned char	*dst_next;
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate		/* LINTED */
13717c478bd9Sstevel@tonic-gate		next_verdef = (Elf32_Verdef *)(src->vd_next ?
13727c478bd9Sstevel@tonic-gate		    (char *)src + src->vd_next : (char *)end);
13737c478bd9Sstevel@tonic-gate		dst_next = dst + src->vd_next;
13747c478bd9Sstevel@tonic-gate
13757c478bd9Sstevel@tonic-gate		/* LINTED */
13767c478bd9Sstevel@tonic-gate		vaux = (Elf32_Verdaux *)((char *)src + src->vd_aux);
13777c478bd9Sstevel@tonic-gate		vaux_dst = dst + src->vd_aux;
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate		/*
13807c478bd9Sstevel@tonic-gate		 * Convert auxilary structures
13817c478bd9Sstevel@tonic-gate		 */
13827c478bd9Sstevel@tonic-gate		for (i = 0; i < src->vd_cnt; i++) {
13837c478bd9Sstevel@tonic-gate			Elf32_Verdaux	*vaux_next;
13847c478bd9Sstevel@tonic-gate			unsigned char	*vaux_dst_next;
13857c478bd9Sstevel@tonic-gate
13867c478bd9Sstevel@tonic-gate			/*
13877c478bd9Sstevel@tonic-gate			 * because our source and destination can be
13887c478bd9Sstevel@tonic-gate			 * the same place we need to figure out the next
13897c478bd9Sstevel@tonic-gate			 * location now.
13907c478bd9Sstevel@tonic-gate			 */
13917c478bd9Sstevel@tonic-gate			/* LINTED */
13927c478bd9Sstevel@tonic-gate			vaux_next = (Elf32_Verdaux *)((char *)vaux +
13937c478bd9Sstevel@tonic-gate			    vaux->vda_next);
13947c478bd9Sstevel@tonic-gate			vaux_dst_next = vaux_dst + vaux->vda_next;
13957c478bd9Sstevel@tonic-gate
13967c478bd9Sstevel@tonic-gate			tofa(vaux_dst, vaux->vda_name, VDA1_name_$2);
13977c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vda_next, VDA1_next_$2);
13987c478bd9Sstevel@tonic-gate			vaux_dst = vaux_dst_next;
13997c478bd9Sstevel@tonic-gate			vaux = vaux_next;
14007c478bd9Sstevel@tonic-gate		}
14017c478bd9Sstevel@tonic-gate
14027c478bd9Sstevel@tonic-gate		/*
14037c478bd9Sstevel@tonic-gate		 * Convert Elf32_Verdef structure.
14047c478bd9Sstevel@tonic-gate		 */
14057c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_version, VD1_version_$2);
14067c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_flags, VD1_flags_$2);
14077c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_ndx, VD1_ndx_$2);
14087c478bd9Sstevel@tonic-gate		tofh(dst, src->vd_cnt, VD1_cnt_$2);
14097c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_hash, VD1_hash_$2);
14107c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_aux, VD1_aux_$2);
14117c478bd9Sstevel@tonic-gate		tofw(dst, src->vd_next, VD1_next_$2);
14127c478bd9Sstevel@tonic-gate		src = next_verdef;
14137c478bd9Sstevel@tonic-gate		dst = dst_next;
14147c478bd9Sstevel@tonic-gate	} while (src < end);
14157c478bd9Sstevel@tonic-gate}')
14167c478bd9Sstevel@tonic-gate
14177c478bd9Sstevel@tonic-gateverdef_11_tof(verdef_2L11_tof, L)
14187c478bd9Sstevel@tonic-gateverdef_11_tof(verdef_2M11_tof, M)
14197c478bd9Sstevel@tonic-gate
14207c478bd9Sstevel@tonic-gatedefine(verneed_11_tof, `
14217c478bd9Sstevel@tonic-gatestatic void
14227c478bd9Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Verneed *src, size_t cnt)
14237c478bd9Sstevel@tonic-gate{
14247c478bd9Sstevel@tonic-gate	/* LINTED */
14257c478bd9Sstevel@tonic-gate	Elf32_Verneed	*end = (Elf32_Verneed *)((char *)src + cnt);
14267c478bd9Sstevel@tonic-gate
14277c478bd9Sstevel@tonic-gate	do {
14287c478bd9Sstevel@tonic-gate		Elf32_Verneed	*next_verneed;
14297c478bd9Sstevel@tonic-gate		Elf32_Vernaux	*vaux;
14307c478bd9Sstevel@tonic-gate		Elf32_Half	i;
14317c478bd9Sstevel@tonic-gate		unsigned char	*vaux_dst;
14327c478bd9Sstevel@tonic-gate		unsigned char	*dst_next;
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate		/* LINTED */
14357c478bd9Sstevel@tonic-gate		next_verneed = (Elf32_Verneed *)(src->vn_next ?
14367c478bd9Sstevel@tonic-gate		    (char *)src + src->vn_next : (char *)end);
14377c478bd9Sstevel@tonic-gate		dst_next = dst + src->vn_next;
14387c478bd9Sstevel@tonic-gate
14397c478bd9Sstevel@tonic-gate		/* LINTED */
14407c478bd9Sstevel@tonic-gate		vaux = (Elf32_Vernaux *)((char *)src + src->vn_aux);
14417c478bd9Sstevel@tonic-gate		vaux_dst = dst + src->vn_aux;
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gate		/*
14447c478bd9Sstevel@tonic-gate		 * Convert auxilary structures first
14457c478bd9Sstevel@tonic-gate		 */
14467c478bd9Sstevel@tonic-gate		for (i = 0; i < src->vn_cnt; i++) {
14477c478bd9Sstevel@tonic-gate			Elf32_Vernaux *	vaux_next;
14487c478bd9Sstevel@tonic-gate			unsigned char *	vaux_dst_next;
14497c478bd9Sstevel@tonic-gate
14507c478bd9Sstevel@tonic-gate			/*
14517c478bd9Sstevel@tonic-gate			 * because our source and destination can be
14527c478bd9Sstevel@tonic-gate			 * the same place we need to figure out the
14537c478bd9Sstevel@tonic-gate			 * next location now.
14547c478bd9Sstevel@tonic-gate			 */
14557c478bd9Sstevel@tonic-gate			/* LINTED */
14567c478bd9Sstevel@tonic-gate			vaux_next = (Elf32_Vernaux *)((char *)vaux +
14577c478bd9Sstevel@tonic-gate			    vaux->vna_next);
14587c478bd9Sstevel@tonic-gate			vaux_dst_next = vaux_dst + vaux->vna_next;
14597c478bd9Sstevel@tonic-gate
14607c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vna_hash, VNA1_hash_$2);
14617c478bd9Sstevel@tonic-gate			tofh(vaux_dst, vaux->vna_flags, VNA1_flags_$2);
14627c478bd9Sstevel@tonic-gate			tofh(vaux_dst, vaux->vna_other, VNA1_other_$2);
14637c478bd9Sstevel@tonic-gate			tofa(vaux_dst, vaux->vna_name, VNA1_name_$2);
14647c478bd9Sstevel@tonic-gate			tofw(vaux_dst, vaux->vna_next, VNA1_next_$2);
14657c478bd9Sstevel@tonic-gate			vaux_dst = vaux_dst_next;
14667c478bd9Sstevel@tonic-gate			vaux = vaux_next;
14677c478bd9Sstevel@tonic-gate		}
14687c478bd9Sstevel@tonic-gate		/*
14697c478bd9Sstevel@tonic-gate		 * Convert Elf32_Verneed structure.
14707c478bd9Sstevel@tonic-gate		 */
14717c478bd9Sstevel@tonic-gate		tofh(dst, src->vn_version, VN1_version_$2);
14727c478bd9Sstevel@tonic-gate		tofh(dst, src->vn_cnt, VN1_cnt_$2);
14737c478bd9Sstevel@tonic-gate		tofa(dst, src->vn_file, VN1_file_$2);
14747c478bd9Sstevel@tonic-gate		tofw(dst, src->vn_aux, VN1_aux_$2);
14757c478bd9Sstevel@tonic-gate		tofw(dst, src->vn_next, VN1_next_$2);
14767c478bd9Sstevel@tonic-gate		src = next_verneed;
14777c478bd9Sstevel@tonic-gate		dst = dst_next;
14787c478bd9Sstevel@tonic-gate	} while (src < end);
14797c478bd9Sstevel@tonic-gate}')
14807c478bd9Sstevel@tonic-gate
14817c478bd9Sstevel@tonic-gateverneed_11_tof(verneed_2L11_tof, L)
14827c478bd9Sstevel@tonic-gateverneed_11_tof(verneed_2M11_tof, M)
14837c478bd9Sstevel@tonic-gate
14847c478bd9Sstevel@tonic-gate
14857c478bd9Sstevel@tonic-gate/* xlate to memory format
14867c478bd9Sstevel@tonic-gate *
14877c478bd9Sstevel@tonic-gate *	..._tom(name, data) -- macros
14887c478bd9Sstevel@tonic-gate *
14897c478bd9Sstevel@tonic-gate *	Recall that the memory format may be larger than the
14907c478bd9Sstevel@tonic-gate *	file format (equal versions).  Use "backward" copy.
14917c478bd9Sstevel@tonic-gate *	All these routines require non-null, non-zero arguments.
14927c478bd9Sstevel@tonic-gate */
14937c478bd9Sstevel@tonic-gate
14947c478bd9Sstevel@tonic-gate
14957c478bd9Sstevel@tonic-gatedefine(addr_tom, `
14967c478bd9Sstevel@tonic-gatestatic void
14977c478bd9Sstevel@tonic-gate$1(Elf32_Addr *dst, unsigned char *src, size_t cnt)
14987c478bd9Sstevel@tonic-gate{
14997c478bd9Sstevel@tonic-gate	Elf32_Addr	*end = dst;
15007c478bd9Sstevel@tonic-gate
15017c478bd9Sstevel@tonic-gate	dst += cnt;
15027c478bd9Sstevel@tonic-gate	src += cnt * A_sizeof;
15037c478bd9Sstevel@tonic-gate	while (dst-- > end) {
15047c478bd9Sstevel@tonic-gate		src -= A_sizeof;
15057c478bd9Sstevel@tonic-gate		*dst = toma(src, A_$2);
15067c478bd9Sstevel@tonic-gate	}
15077c478bd9Sstevel@tonic-gate}')
15087c478bd9Sstevel@tonic-gate
15097c478bd9Sstevel@tonic-gateaddr_tom(addr_2L_tom,L)
15107c478bd9Sstevel@tonic-gateaddr_tom(addr_2M_tom,M)
15117c478bd9Sstevel@tonic-gate
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gatedefine(dyn_11_tom, `
15147c478bd9Sstevel@tonic-gatestatic void
15157c478bd9Sstevel@tonic-gate$1(Elf32_Dyn *dst, unsigned char *src, size_t cnt)
15167c478bd9Sstevel@tonic-gate{
15177c478bd9Sstevel@tonic-gate	Elf32_Dyn	*end = dst + cnt;
15187c478bd9Sstevel@tonic-gate
15197c478bd9Sstevel@tonic-gate	do {
15207c478bd9Sstevel@tonic-gate		dst->d_tag = tomw(src, D1_tag_$2);
15217c478bd9Sstevel@tonic-gate		dst->d_un.d_val = tomw(src, D1_val_$2);
15227c478bd9Sstevel@tonic-gate		src += D1_sizeof;
15237c478bd9Sstevel@tonic-gate	} while (++dst < end);
15247c478bd9Sstevel@tonic-gate}')
15257c478bd9Sstevel@tonic-gate
15267c478bd9Sstevel@tonic-gatedyn_11_tom(dyn_2L11_tom,L)
15277c478bd9Sstevel@tonic-gatedyn_11_tom(dyn_2M11_tom,M)
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate
15307c478bd9Sstevel@tonic-gatedefine(ehdr_11_tom, `
15317c478bd9Sstevel@tonic-gatestatic void
15327c478bd9Sstevel@tonic-gate$1(Elf32_Ehdr *dst, unsigned char *src, size_t cnt)
15337c478bd9Sstevel@tonic-gate{
15347c478bd9Sstevel@tonic-gate	Elf32_Ehdr	*end = dst;
15357c478bd9Sstevel@tonic-gate
15367c478bd9Sstevel@tonic-gate	dst += cnt;
15377c478bd9Sstevel@tonic-gate	src += cnt * E1_sizeof;
15387c478bd9Sstevel@tonic-gate	while (dst-- > end) {
15397c478bd9Sstevel@tonic-gate		src -= E1_sizeof;
15407c478bd9Sstevel@tonic-gate		dst->e_shstrndx = tomh(src, E1_shstrndx_$2);
15417c478bd9Sstevel@tonic-gate		dst->e_shnum = tomh(src, E1_shnum_$2);
15427c478bd9Sstevel@tonic-gate		dst->e_shentsize = tomh(src, E1_shentsize_$2);
15437c478bd9Sstevel@tonic-gate		dst->e_phnum = tomh(src, E1_phnum_$2);
15447c478bd9Sstevel@tonic-gate		dst->e_phentsize = tomh(src, E1_phentsize_$2);
15457c478bd9Sstevel@tonic-gate		dst->e_ehsize = tomh(src, E1_ehsize_$2);
15467c478bd9Sstevel@tonic-gate		dst->e_flags = tomw(src, E1_flags_$2);
15477c478bd9Sstevel@tonic-gate		dst->e_shoff = tomo(src, E1_shoff_$2);
15487c478bd9Sstevel@tonic-gate		dst->e_phoff = tomo(src, E1_phoff_$2);
15497c478bd9Sstevel@tonic-gate		dst->e_entry = toma(src, E1_entry_$2);
15507c478bd9Sstevel@tonic-gate		dst->e_version = tomw(src, E1_version_$2);
15517c478bd9Sstevel@tonic-gate		dst->e_machine = tomh(src, E1_machine_$2);
15527c478bd9Sstevel@tonic-gate		dst->e_type = tomh(src, E1_type_$2);
15537c478bd9Sstevel@tonic-gate		if (dst->e_ident != &src[E1_ident])
15547c478bd9Sstevel@tonic-gate			(void) memcpy(dst->e_ident, &src[E1_ident], E1_Nident);
15557c478bd9Sstevel@tonic-gate	}
15567c478bd9Sstevel@tonic-gate}')
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gateehdr_11_tom(ehdr_2L11_tom,L)
15597c478bd9Sstevel@tonic-gateehdr_11_tom(ehdr_2M11_tom,M)
15607c478bd9Sstevel@tonic-gate
15617c478bd9Sstevel@tonic-gate
15627c478bd9Sstevel@tonic-gatedefine(half_tom, `
15637c478bd9Sstevel@tonic-gatestatic void
15647c478bd9Sstevel@tonic-gate$1(Elf32_Half *dst, unsigned char *src, size_t cnt)
15657c478bd9Sstevel@tonic-gate{
15667c478bd9Sstevel@tonic-gate	Elf32_Half	*end = dst;
15677c478bd9Sstevel@tonic-gate
15687c478bd9Sstevel@tonic-gate	dst += cnt;
15697c478bd9Sstevel@tonic-gate	src += cnt * H_sizeof;
15707c478bd9Sstevel@tonic-gate	while (dst-- > end) {
15717c478bd9Sstevel@tonic-gate		src -= H_sizeof;
15727c478bd9Sstevel@tonic-gate		*dst = tomh(src, H_$2);
15737c478bd9Sstevel@tonic-gate	}
15747c478bd9Sstevel@tonic-gate}')
15757c478bd9Sstevel@tonic-gate
15767c478bd9Sstevel@tonic-gatehalf_tom(half_2L_tom,L)
15777c478bd9Sstevel@tonic-gatehalf_tom(half_2M_tom,M)
15787c478bd9Sstevel@tonic-gate
15797c478bd9Sstevel@tonic-gate
15807c478bd9Sstevel@tonic-gatedefine(move_11_tom, `
15817c478bd9Sstevel@tonic-gatestatic void
15827c478bd9Sstevel@tonic-gate$1(Elf32_Move *dst, unsigned char *src, size_t cnt)
15837c478bd9Sstevel@tonic-gate{
15847c478bd9Sstevel@tonic-gate	Elf32_Move	*end = dst + cnt;
15857c478bd9Sstevel@tonic-gate
15867c478bd9Sstevel@tonic-gate	do {
15877c478bd9Sstevel@tonic-gate		dst->m_value = toml(src, M1_value_$2);
15887c478bd9Sstevel@tonic-gate		dst->m_info = tomw(src, M1_info_$2);
15897c478bd9Sstevel@tonic-gate		dst->m_poffset = tomw(src, M1_poffset_$2);
15907c478bd9Sstevel@tonic-gate		dst->m_repeat = tomh(src, M1_repeat_$2);
15917c478bd9Sstevel@tonic-gate		dst->m_stride = tomh(src, M1_stride_$2);
15927c478bd9Sstevel@tonic-gate		src += M1_sizeof;
15937c478bd9Sstevel@tonic-gate	} while (++dst < end);
15947c478bd9Sstevel@tonic-gate}')
15957c478bd9Sstevel@tonic-gate
15967c478bd9Sstevel@tonic-gatemove_11_tom(move_2L11_tom,L)
15977c478bd9Sstevel@tonic-gatemove_11_tom(move_2M11_tom,M)
15987c478bd9Sstevel@tonic-gate
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gatedefine(movep_11_tom, `
16017c478bd9Sstevel@tonic-gatestatic void
16027c478bd9Sstevel@tonic-gate$1(Elf32_Move *dst, unsigned char *src, size_t cnt)
16037c478bd9Sstevel@tonic-gate{
16047c478bd9Sstevel@tonic-gate	Elf32_Move		*end = dst + cnt;
16057c478bd9Sstevel@tonic-gate
16067c478bd9Sstevel@tonic-gate	do
16077c478bd9Sstevel@tonic-gate	{
16087c478bd9Sstevel@tonic-gate		dst->m_value = toml(src, MP1_value_$2);
16097c478bd9Sstevel@tonic-gate		dst->m_info = tomw(src, MP1_info_$2);
16107c478bd9Sstevel@tonic-gate		dst->m_poffset = tomw(src, MP1_poffset_$2);
16117c478bd9Sstevel@tonic-gate		dst->m_repeat = tomh(src, MP1_repeat_$2);
16127c478bd9Sstevel@tonic-gate		dst->m_stride = tomh(src, MP1_stride_$2);
16137c478bd9Sstevel@tonic-gate		src += MP1_sizeof;
16147c478bd9Sstevel@tonic-gate	} while (++dst < end);
16157c478bd9Sstevel@tonic-gate}')
16167c478bd9Sstevel@tonic-gate
16177c478bd9Sstevel@tonic-gatemovep_11_tom(movep_2L11_tom,L)
16187c478bd9Sstevel@tonic-gatemovep_11_tom(movep_2M11_tom,M)
16197c478bd9Sstevel@tonic-gate
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gatedefine(note_11_tom, `
16227c478bd9Sstevel@tonic-gatestatic void
16237c478bd9Sstevel@tonic-gate$1(Elf32_Nhdr *dst, unsigned char *src, size_t cnt)
16247c478bd9Sstevel@tonic-gate{
16257c478bd9Sstevel@tonic-gate	/* LINTED */
16267c478bd9Sstevel@tonic-gate	Elf32_Nhdr	*end = (Elf32_Nhdr *)((char *)dst + cnt);
16277c478bd9Sstevel@tonic-gate
1628*3228339cSAli Bahrami	/*
1629*3228339cSAli Bahrami	 * Copy the note data to the destination, translating the
1630*3228339cSAli Bahrami	 * length fields. Clip against the size of the actual buffer
1631*3228339cSAli Bahrami	 * to guard against corrupt note data.
1632*3228339cSAli Bahrami	 */
16337c478bd9Sstevel@tonic-gate	 while (dst < end) {
16347c478bd9Sstevel@tonic-gate		Elf32_Nhdr 	*nhdr;
16357c478bd9Sstevel@tonic-gate		unsigned char 	*namestr;
16367c478bd9Sstevel@tonic-gate		void 		*desc;
16377c478bd9Sstevel@tonic-gate		Elf32_Word	field_sz;
16387c478bd9Sstevel@tonic-gate
1639*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_namesz) + sizeof(Elf32_Word) +
1640*3228339cSAli Bahrami		    (char *) dst) >= (char *) end)
1641*3228339cSAli Bahrami			break;
16427c478bd9Sstevel@tonic-gate		dst->n_namesz = tomw(src, N1_namesz_$2);
1643*3228339cSAli Bahrami
1644*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_descsz) + sizeof(Elf32_Word) +
1645*3228339cSAli Bahrami		    (char *) dst) >= (char *) end)
1646*3228339cSAli Bahrami			break;
16477c478bd9Sstevel@tonic-gate		dst->n_descsz = tomw(src, N1_descsz_$2);
1648*3228339cSAli Bahrami
1649*3228339cSAli Bahrami		if ((offsetof(Elf32_Nhdr, n_type) + sizeof(Elf32_Word) +
1650*3228339cSAli Bahrami		    (char *) dst) >= (char *) end)
1651*3228339cSAli Bahrami			break;
16527c478bd9Sstevel@tonic-gate		dst->n_type = tomw(src, N1_type_$2);
16537c478bd9Sstevel@tonic-gate		nhdr = dst;
1654*3228339cSAli Bahrami
16555aefb655Srie		/* LINTED */
16567c478bd9Sstevel@tonic-gate		dst = (Elf32_Nhdr *)((char *)dst + sizeof (Elf32_Nhdr));
16577c478bd9Sstevel@tonic-gate		namestr = src + N1_sizeof;
16587c478bd9Sstevel@tonic-gate		field_sz = S_ROUND(nhdr->n_namesz, sizeof (Elf32_Word));
1659*3228339cSAli Bahrami		if ((field_sz + (char *) dst) > (char *) end) {
1660*3228339cSAli Bahrami			field_sz = (char *) end - (char *) dst;
1661*3228339cSAli Bahrami			if (field_sz == 0)
1662*3228339cSAli Bahrami				break;
1663*3228339cSAli Bahrami		}
16647c478bd9Sstevel@tonic-gate		(void)memcpy((void *)dst, namestr, field_sz);
16657c478bd9Sstevel@tonic-gate		desc = namestr + field_sz;
1666*3228339cSAli Bahrami
16675aefb655Srie		/* LINTED */
16687c478bd9Sstevel@tonic-gate		dst = (Elf32_Nhdr *)((char *)dst + field_sz);
16697c478bd9Sstevel@tonic-gate		field_sz = nhdr->n_descsz;
1670*3228339cSAli Bahrami		if ((field_sz + (char *) dst) > (char *) end) {
1671*3228339cSAli Bahrami			field_sz = (char *) end - (char *) dst;
1672*3228339cSAli Bahrami			if (field_sz == 0)
1673*3228339cSAli Bahrami				break;
1674*3228339cSAli Bahrami		}
16757c478bd9Sstevel@tonic-gate		(void)memcpy(dst, desc, field_sz);
16767c478bd9Sstevel@tonic-gate		field_sz = S_ROUND(field_sz, sizeof (Elf32_Word));
1677*3228339cSAli Bahrami
16785aefb655Srie		/* LINTED */
16797c478bd9Sstevel@tonic-gate		dst = (Elf32_Nhdr *)((char *)dst + field_sz);
16807c478bd9Sstevel@tonic-gate		src = (unsigned char *)desc + field_sz;
16817c478bd9Sstevel@tonic-gate	}
16827c478bd9Sstevel@tonic-gate}')
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gatenote_11_tom(note_2L11_tom,L)
16857c478bd9Sstevel@tonic-gatenote_11_tom(note_2M11_tom,M)
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate
16887c478bd9Sstevel@tonic-gatedefine(off_tom, `
16897c478bd9Sstevel@tonic-gatestatic void
16907c478bd9Sstevel@tonic-gate$1(Elf32_Off *dst, unsigned char *src, size_t cnt)
16917c478bd9Sstevel@tonic-gate{
16927c478bd9Sstevel@tonic-gate	Elf32_Off	*end = dst;
16937c478bd9Sstevel@tonic-gate
16947c478bd9Sstevel@tonic-gate	dst += cnt;
16957c478bd9Sstevel@tonic-gate	src += cnt * O_sizeof;
16967c478bd9Sstevel@tonic-gate	while (dst-- > end) {
16977c478bd9Sstevel@tonic-gate		src -= O_sizeof;
16987c478bd9Sstevel@tonic-gate		*dst = tomo(src, O_$2);
16997c478bd9Sstevel@tonic-gate	}
17007c478bd9Sstevel@tonic-gate}')
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gateoff_tom(off_2L_tom,L)
17037c478bd9Sstevel@tonic-gateoff_tom(off_2M_tom,M)
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate
17067c478bd9Sstevel@tonic-gatedefine(phdr_11_tom, `
17077c478bd9Sstevel@tonic-gatestatic void
17087c478bd9Sstevel@tonic-gate$1(Elf32_Phdr *dst, unsigned char *src, size_t cnt)
17097c478bd9Sstevel@tonic-gate{
17107c478bd9Sstevel@tonic-gate	Elf32_Phdr	*end = dst;
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate	dst += cnt;
17137c478bd9Sstevel@tonic-gate	src += cnt * P1_sizeof;
17147c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17157c478bd9Sstevel@tonic-gate		src -= P1_sizeof;
17167c478bd9Sstevel@tonic-gate		dst->p_align = tomw(src, P1_align_$2);
17177c478bd9Sstevel@tonic-gate		dst->p_flags = tomw(src, P1_flags_$2);
17187c478bd9Sstevel@tonic-gate		dst->p_memsz = tomw(src, P1_memsz_$2);
17197c478bd9Sstevel@tonic-gate		dst->p_filesz = tomw(src, P1_filesz_$2);
17207c478bd9Sstevel@tonic-gate		dst->p_paddr = toma(src, P1_paddr_$2);
17217c478bd9Sstevel@tonic-gate		dst->p_vaddr = toma(src, P1_vaddr_$2);
17227c478bd9Sstevel@tonic-gate		dst->p_offset = tomo(src, P1_offset_$2);
17237c478bd9Sstevel@tonic-gate		dst->p_type = tomw(src, P1_type_$2);
17247c478bd9Sstevel@tonic-gate	}
17257c478bd9Sstevel@tonic-gate}')
17267c478bd9Sstevel@tonic-gate
17277c478bd9Sstevel@tonic-gatephdr_11_tom(phdr_2L11_tom,L)
17287c478bd9Sstevel@tonic-gatephdr_11_tom(phdr_2M11_tom,M)
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate
17317c478bd9Sstevel@tonic-gatedefine(rel_11_tom, `
17327c478bd9Sstevel@tonic-gatestatic void
17337c478bd9Sstevel@tonic-gate$1(Elf32_Rel *dst, unsigned char *src, size_t cnt)
17347c478bd9Sstevel@tonic-gate{
17357c478bd9Sstevel@tonic-gate	Elf32_Rel	*end = dst;
17367c478bd9Sstevel@tonic-gate
17377c478bd9Sstevel@tonic-gate	dst += cnt;
17387c478bd9Sstevel@tonic-gate	src += cnt * R1_sizeof;
17397c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17407c478bd9Sstevel@tonic-gate		src -= R1_sizeof;
17417c478bd9Sstevel@tonic-gate		dst->r_info = tomw(src, R1_info_$2);
17427c478bd9Sstevel@tonic-gate		dst->r_offset = toma(src, R1_offset_$2);
17437c478bd9Sstevel@tonic-gate	}
17447c478bd9Sstevel@tonic-gate}')
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gaterel_11_tom(rel_2L11_tom,L)
17477c478bd9Sstevel@tonic-gaterel_11_tom(rel_2M11_tom,M)
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate
17507c478bd9Sstevel@tonic-gatedefine(rela_11_tom, `
17517c478bd9Sstevel@tonic-gatestatic void
17527c478bd9Sstevel@tonic-gate$1(Elf32_Rela *dst, unsigned char *src, size_t cnt)
17537c478bd9Sstevel@tonic-gate{
17547c478bd9Sstevel@tonic-gate	Elf32_Rela	*end = dst;
17557c478bd9Sstevel@tonic-gate
17567c478bd9Sstevel@tonic-gate	dst += cnt;
17577c478bd9Sstevel@tonic-gate	src += cnt * RA1_sizeof;
17587c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17597c478bd9Sstevel@tonic-gate		src -= RA1_sizeof;
17607c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
17617c478bd9Sstevel@tonic-gate		if (~(Elf32_Word)0 == -(Elf32_Sword)1 &&	/* 2s comp */
17627c478bd9Sstevel@tonic-gate		    ~(~(Elf32_Word)0 >> 1) == HI32) {
17637c478bd9Sstevel@tonic-gate			dst->r_addend = tomw(src, RA1_addend_$2);
17647c478bd9Sstevel@tonic-gate		} else {
17657c478bd9Sstevel@tonic-gate			union {
17667c478bd9Sstevel@tonic-gate				Elf32_Word w;
17677c478bd9Sstevel@tonic-gate				Elf32_Sword sw;
17687c478bd9Sstevel@tonic-gate			} u;
17697c478bd9Sstevel@tonic-gate
17707c478bd9Sstevel@tonic-gate			if ((u.w = tomw(src, RA1_addend_$2)) & HI32) {
17717c478bd9Sstevel@tonic-gate				u.w |= ~(Elf32_Word)LO31;
17727c478bd9Sstevel@tonic-gate				u.w = ~u.w + 1;
17737c478bd9Sstevel@tonic-gate				u.sw = -u.w;
17747c478bd9Sstevel@tonic-gate			}
17757c478bd9Sstevel@tonic-gate			dst->r_addend = u.sw;
17767c478bd9Sstevel@tonic-gate		}
17777c478bd9Sstevel@tonic-gate		dst->r_info = tomw(src, RA1_info_$2);
17787c478bd9Sstevel@tonic-gate		dst->r_offset = toma(src, RA1_offset_$2);
17797c478bd9Sstevel@tonic-gate	}
17807c478bd9Sstevel@tonic-gate}')
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gaterela_11_tom(rela_2L11_tom,L)
17837c478bd9Sstevel@tonic-gaterela_11_tom(rela_2M11_tom,M)
17847c478bd9Sstevel@tonic-gate
17857c478bd9Sstevel@tonic-gate
17867c478bd9Sstevel@tonic-gatedefine(shdr_11_tom, `
17877c478bd9Sstevel@tonic-gatestatic void
17887c478bd9Sstevel@tonic-gate$1(Elf32_Shdr *dst, unsigned char *src, size_t cnt)
17897c478bd9Sstevel@tonic-gate{
17907c478bd9Sstevel@tonic-gate	Elf32_Shdr	*end = dst;
17917c478bd9Sstevel@tonic-gate
17927c478bd9Sstevel@tonic-gate	dst += cnt;
17937c478bd9Sstevel@tonic-gate	src += cnt * SH1_sizeof;
17947c478bd9Sstevel@tonic-gate	while (dst-- > end) {
17957c478bd9Sstevel@tonic-gate		src -= SH1_sizeof;
17967c478bd9Sstevel@tonic-gate		dst->sh_entsize = tomw(src, SH1_entsize_$2);
17977c478bd9Sstevel@tonic-gate		dst->sh_addralign = tomw(src, SH1_addralign_$2);
17987c478bd9Sstevel@tonic-gate		dst->sh_info = tomw(src, SH1_info_$2);
17997c478bd9Sstevel@tonic-gate		dst->sh_link = tomw(src, SH1_link_$2);
18007c478bd9Sstevel@tonic-gate		dst->sh_size = tomw(src, SH1_size_$2);
18017c478bd9Sstevel@tonic-gate		dst->sh_offset = tomo(src, SH1_offset_$2);
18027c478bd9Sstevel@tonic-gate		dst->sh_addr = toma(src, SH1_addr_$2);
18037c478bd9Sstevel@tonic-gate		dst->sh_flags = tomw(src, SH1_flags_$2);
18047c478bd9Sstevel@tonic-gate		dst->sh_type = tomw(src, SH1_type_$2);
18057c478bd9Sstevel@tonic-gate		dst->sh_name = tomw(src, SH1_name_$2);
18067c478bd9Sstevel@tonic-gate	}
18077c478bd9Sstevel@tonic-gate}')
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gateshdr_11_tom(shdr_2L11_tom,L)
18107c478bd9Sstevel@tonic-gateshdr_11_tom(shdr_2M11_tom,M)
18117c478bd9Sstevel@tonic-gate
18127c478bd9Sstevel@tonic-gate
18137c478bd9Sstevel@tonic-gate
18147c478bd9Sstevel@tonic-gatedefine(sword_tom, `
18157c478bd9Sstevel@tonic-gatestatic void
18167c478bd9Sstevel@tonic-gate$1(Elf32_Sword *dst, unsigned char *src, size_t cnt)
18177c478bd9Sstevel@tonic-gate{
18187c478bd9Sstevel@tonic-gate	Elf32_Sword	*end = dst;
18197c478bd9Sstevel@tonic-gate
18207c478bd9Sstevel@tonic-gate	dst += cnt;
18217c478bd9Sstevel@tonic-gate	src += cnt * W_sizeof;
18227c478bd9Sstevel@tonic-gate	while (dst-- > end) {
18237c478bd9Sstevel@tonic-gate		src -= W_sizeof;
18247c478bd9Sstevel@tonic-gate		/*CONSTANTCONDITION*/
18257c478bd9Sstevel@tonic-gate		if (~(Elf32_Word)0 == -(Elf32_Sword)1 &&	/* 2s comp */
18267c478bd9Sstevel@tonic-gate		    ~(~(Elf32_Word)0 >> 1) == HI32) {
18277c478bd9Sstevel@tonic-gate			*dst = tomw(src, W_$2);
18287c478bd9Sstevel@tonic-gate		} else {
18297c478bd9Sstevel@tonic-gate			union {
18307c478bd9Sstevel@tonic-gate				Elf32_Word w;
18317c478bd9Sstevel@tonic-gate				Elf32_Sword sw;
18327c478bd9Sstevel@tonic-gate			} u;
18337c478bd9Sstevel@tonic-gate
18347c478bd9Sstevel@tonic-gate			if ((u.w = tomw(src, W_$2)) & HI32) {
18357c478bd9Sstevel@tonic-gate				u.w |= ~(Elf32_Word)LO31;
18367c478bd9Sstevel@tonic-gate				u.w = ~u.w + 1;
18377c478bd9Sstevel@tonic-gate				u.sw = -u.w;
18387c478bd9Sstevel@tonic-gate			}
18397c478bd9Sstevel@tonic-gate			*dst = u.sw;
18407c478bd9Sstevel@tonic-gate		}
18417c478bd9Sstevel@tonic-gate	}
18427c478bd9Sstevel@tonic-gate}')
18437c478bd9Sstevel@tonic-gate
18447c478bd9Sstevel@tonic-gatesword_tom(sword_2L_tom,L)
18457c478bd9Sstevel@tonic-gatesword_tom(sword_2M_tom,M)
18467c478bd9Sstevel@tonic-gate
18477c478bd9Sstevel@tonic-gate
18487c478bd9Sstevel@tonic-gatedefine(cap_11_tom, `
18497c478bd9Sstevel@tonic-gatestatic void
18507c478bd9Sstevel@tonic-gate$1(Elf32_Cap *dst, unsigned char *src, size_t cnt)
18517c478bd9Sstevel@tonic-gate{
18527c478bd9Sstevel@tonic-gate	Elf32_Cap	*end = dst + cnt;
18537c478bd9Sstevel@tonic-gate
18547c478bd9Sstevel@tonic-gate	do {
18557c478bd9Sstevel@tonic-gate		dst->c_tag = tomw(src, C1_tag_$2);
18567c478bd9Sstevel@tonic-gate		dst->c_un.c_val = tomw(src, C1_val_$2);
18577c478bd9Sstevel@tonic-gate		src += C1_sizeof;
18587c478bd9Sstevel@tonic-gate	} while (++dst < end);
18597c478bd9Sstevel@tonic-gate}')
18607c478bd9Sstevel@tonic-gate
18617c478bd9Sstevel@tonic-gatecap_11_tom(cap_2L11_tom,L)
18627c478bd9Sstevel@tonic-gatecap_11_tom(cap_2M11_tom,M)
18637c478bd9Sstevel@tonic-gate
18647c478bd9Sstevel@tonic-gate
18657c478bd9Sstevel@tonic-gatedefine(syminfo_11_tom, `
18667c478bd9Sstevel@tonic-gatestatic void
18677c478bd9Sstevel@tonic-gate$1(Elf32_Syminfo *dst, unsigned char *src, size_t cnt)
18687c478bd9Sstevel@tonic-gate{
18697c478bd9Sstevel@tonic-gate	Elf32_Syminfo	*end = dst;
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gate	dst += cnt;
18727c478bd9Sstevel@tonic-gate	src += cnt * SI1_sizeof;
18737c478bd9Sstevel@tonic-gate	while (dst-- > end) {
18747c478bd9Sstevel@tonic-gate		src -= SI1_sizeof;
18757c478bd9Sstevel@tonic-gate		dst->si_boundto = tomh(src, SI1_boundto_$2);
18767c478bd9Sstevel@tonic-gate		dst->si_flags = tomh(src, SI1_flags_$2);
18777c478bd9Sstevel@tonic-gate	}
18787c478bd9Sstevel@tonic-gate}')
18797c478bd9Sstevel@tonic-gate
18807c478bd9Sstevel@tonic-gatesyminfo_11_tom(syminfo_2L11_tom,L)
18817c478bd9Sstevel@tonic-gatesyminfo_11_tom(syminfo_2M11_tom,M)
18827c478bd9Sstevel@tonic-gate
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gatedefine(sym_11_tom, `
18857c478bd9Sstevel@tonic-gatestatic void
18867c478bd9Sstevel@tonic-gate$1(Elf32_Sym *dst, unsigned char *src, size_t cnt)
18877c478bd9Sstevel@tonic-gate{
18887c478bd9Sstevel@tonic-gate	Elf32_Sym	*end = dst;
18897c478bd9Sstevel@tonic-gate
18907c478bd9Sstevel@tonic-gate	dst += cnt;
18917c478bd9Sstevel@tonic-gate	src += cnt * ST1_sizeof;
18927c478bd9Sstevel@tonic-gate	while (dst-- > end) {
18937c478bd9Sstevel@tonic-gate		src -= ST1_sizeof;
18947c478bd9Sstevel@tonic-gate		dst->st_shndx = tomh(src, ST1_shndx_$2);
18957c478bd9Sstevel@tonic-gate		dst->st_other = tomb(src, ST1_other_$2);
18967c478bd9Sstevel@tonic-gate		dst->st_info = tomb(src, ST1_info_$2);
18977c478bd9Sstevel@tonic-gate		dst->st_size = tomw(src, ST1_size_$2);
18987c478bd9Sstevel@tonic-gate		dst->st_value = toma(src, ST1_value_$2);
18997c478bd9Sstevel@tonic-gate		dst->st_name = tomw(src, ST1_name_$2);
19007c478bd9Sstevel@tonic-gate	}
19017c478bd9Sstevel@tonic-gate}')
19027c478bd9Sstevel@tonic-gate
19037c478bd9Sstevel@tonic-gatesym_11_tom(sym_2L11_tom,L)
19047c478bd9Sstevel@tonic-gatesym_11_tom(sym_2M11_tom,M)
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate
19077c478bd9Sstevel@tonic-gatedefine(word_tom, `
19087c478bd9Sstevel@tonic-gatestatic void
19097c478bd9Sstevel@tonic-gate$1(Elf32_Word *dst, unsigned char *src, size_t cnt)
19107c478bd9Sstevel@tonic-gate{
19117c478bd9Sstevel@tonic-gate	Elf32_Word	*end = dst;
19127c478bd9Sstevel@tonic-gate
19137c478bd9Sstevel@tonic-gate	dst += cnt;
19147c478bd9Sstevel@tonic-gate	src += cnt * W_sizeof;
19157c478bd9Sstevel@tonic-gate	while (dst-- > end) {
19167c478bd9Sstevel@tonic-gate		src -= W_sizeof;
19177c478bd9Sstevel@tonic-gate		*dst = tomw(src, W_$2);
19187c478bd9Sstevel@tonic-gate	}
19197c478bd9Sstevel@tonic-gate}')
19207c478bd9Sstevel@tonic-gate
19217c478bd9Sstevel@tonic-gateword_tom(word_2L_tom,L)
19227c478bd9Sstevel@tonic-gateword_tom(word_2M_tom,M)
19237c478bd9Sstevel@tonic-gate
19247c478bd9Sstevel@tonic-gate
19257c478bd9Sstevel@tonic-gatedefine(verdef_11_tom, `
19267c478bd9Sstevel@tonic-gatestatic void
19277c478bd9Sstevel@tonic-gate$1(Elf32_Verdef *dst, unsigned char *src, size_t cnt)
19287c478bd9Sstevel@tonic-gate{
19297c478bd9Sstevel@tonic-gate	/* LINTED */
19307c478bd9Sstevel@tonic-gate	Elf32_Verdef	*end = (Elf32_Verdef *)((char *)dst + cnt);
19317c478bd9Sstevel@tonic-gate
19327c478bd9Sstevel@tonic-gate	while (dst < end) {
19337c478bd9Sstevel@tonic-gate		Elf32_Verdaux	*vaux;
19347c478bd9Sstevel@tonic-gate		unsigned char	*src_vaux;
19357c478bd9Sstevel@tonic-gate		Elf32_Half	i;
19367c478bd9Sstevel@tonic-gate
19377c478bd9Sstevel@tonic-gate		dst->vd_version = tomh(src, VD1_version_$2);
19387c478bd9Sstevel@tonic-gate		dst->vd_flags = tomh(src, VD1_flags_$2);
19397c478bd9Sstevel@tonic-gate		dst->vd_ndx = tomh(src, VD1_ndx_$2);
19407c478bd9Sstevel@tonic-gate		dst->vd_cnt = tomh(src, VD1_cnt_$2);
19417c478bd9Sstevel@tonic-gate		dst->vd_hash = tomw(src, VD1_hash_$2);
19427c478bd9Sstevel@tonic-gate		dst->vd_aux = tomw(src, VD1_aux_$2);
19437c478bd9Sstevel@tonic-gate		dst->vd_next = tomw(src, VD1_next_$2);
19447c478bd9Sstevel@tonic-gate
19457c478bd9Sstevel@tonic-gate		src_vaux = src + dst->vd_aux;
19467c478bd9Sstevel@tonic-gate		/* LINTED */
19477c478bd9Sstevel@tonic-gate		vaux = (Elf32_Verdaux*)((char *)dst + dst->vd_aux);
19487c478bd9Sstevel@tonic-gate		for (i = 0; i < dst->vd_cnt; i++) {
19497c478bd9Sstevel@tonic-gate			vaux->vda_name = toma(src_vaux, VDA1_name_$2);
19507c478bd9Sstevel@tonic-gate			vaux->vda_next = toma(src_vaux, VDA1_next_$2);
19517c478bd9Sstevel@tonic-gate			src_vaux += vaux->vda_next;
19527c478bd9Sstevel@tonic-gate			/* LINTED */
19537c478bd9Sstevel@tonic-gate			vaux = (Elf32_Verdaux *)((char *)vaux +
19547c478bd9Sstevel@tonic-gate			    vaux->vda_next);
19557c478bd9Sstevel@tonic-gate		}
19567c478bd9Sstevel@tonic-gate		src += dst->vd_next;
19577c478bd9Sstevel@tonic-gate		/* LINTED */
19587c478bd9Sstevel@tonic-gate		dst = (Elf32_Verdef *)(dst->vd_next ?
19597c478bd9Sstevel@tonic-gate		    (char *)dst + dst->vd_next : (char *)end);
19607c478bd9Sstevel@tonic-gate	}
19617c478bd9Sstevel@tonic-gate}')
19627c478bd9Sstevel@tonic-gate
19637c478bd9Sstevel@tonic-gateverdef_11_tom(verdef_2L11_tom,L)
19647c478bd9Sstevel@tonic-gateverdef_11_tom(verdef_2M11_tom,M)
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate
19677c478bd9Sstevel@tonic-gatedefine(verneed_11_tom, `
19687c478bd9Sstevel@tonic-gatestatic void
19697c478bd9Sstevel@tonic-gate$1(Elf32_Verneed *dst, unsigned char *src, size_t cnt)
19707c478bd9Sstevel@tonic-gate{
19717c478bd9Sstevel@tonic-gate	/* LINTED */
19727c478bd9Sstevel@tonic-gate	Elf32_Verneed	*end = (Elf32_Verneed *)((char *)dst + cnt);
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gate	while (dst < end) {
19757c478bd9Sstevel@tonic-gate		Elf32_Vernaux *	vaux;
19767c478bd9Sstevel@tonic-gate		unsigned char *	src_vaux;
19777c478bd9Sstevel@tonic-gate		Elf32_Half	i;
19787c478bd9Sstevel@tonic-gate		dst->vn_version = tomh(src, VN1_version_$2);
19797c478bd9Sstevel@tonic-gate		dst->vn_cnt = tomh(src, VN1_cnt_$2);
19807c478bd9Sstevel@tonic-gate		dst->vn_file = toma(src, VN1_file_$2);
19817c478bd9Sstevel@tonic-gate		dst->vn_aux = tomw(src, VN1_aux_$2);
19827c478bd9Sstevel@tonic-gate		dst->vn_next = tomw(src, VN1_next_$2);
19837c478bd9Sstevel@tonic-gate
19847c478bd9Sstevel@tonic-gate		src_vaux = src + dst->vn_aux;
19857c478bd9Sstevel@tonic-gate		/* LINTED */
19867c478bd9Sstevel@tonic-gate		vaux = (Elf32_Vernaux *)((char *)dst + dst->vn_aux);
19877c478bd9Sstevel@tonic-gate		for (i = 0; i < dst->vn_cnt; i++) {
19887c478bd9Sstevel@tonic-gate			vaux->vna_hash = tomw(src_vaux, VNA1_hash_$2);
19897c478bd9Sstevel@tonic-gate			vaux->vna_flags = tomh(src_vaux, VNA1_flags_$2);
19907c478bd9Sstevel@tonic-gate			vaux->vna_other = tomh(src_vaux, VNA1_other_$2);
19917c478bd9Sstevel@tonic-gate			vaux->vna_name = toma(src_vaux, VNA1_name_$2);
19927c478bd9Sstevel@tonic-gate			vaux->vna_next = tomw(src_vaux, VNA1_next_$2);
19937c478bd9Sstevel@tonic-gate			src_vaux += vaux->vna_next;
19947c478bd9Sstevel@tonic-gate			/* LINTED */
19957c478bd9Sstevel@tonic-gate			vaux = (Elf32_Vernaux *)((char *)vaux +
19967c478bd9Sstevel@tonic-gate			    vaux->vna_next);
19977c478bd9Sstevel@tonic-gate		}
19987c478bd9Sstevel@tonic-gate		src += dst->vn_next;
19997c478bd9Sstevel@tonic-gate		/* LINTED */
20007c478bd9Sstevel@tonic-gate		dst = (Elf32_Verneed *)(dst->vn_next ?
20017c478bd9Sstevel@tonic-gate		    (char *)dst + dst->vn_next : (char *)end);
20027c478bd9Sstevel@tonic-gate	}
20037c478bd9Sstevel@tonic-gate}')
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gateverneed_11_tom(verneed_2L11_tom,L)
20067c478bd9Sstevel@tonic-gateverneed_11_tom(verneed_2M11_tom,M)
2007