10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211618Srie 220Sstevel@tonic-gate/* 2311827SRod.Evans@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate#include <memory.h> 270Sstevel@tonic-gate#include <libelf.h> 280Sstevel@tonic-gate#include <link.h> 290Sstevel@tonic-gate#include <sys/elf_SPARC.h> 300Sstevel@tonic-gate#include <sys/elf_amd64.h> 310Sstevel@tonic-gate#include <decl.h> 320Sstevel@tonic-gate#include <msg.h> 330Sstevel@tonic-gate#include <sgs.h> 34*11957SAli.Bahrami@Sun.COM#include <stddef.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate/* 370Sstevel@tonic-gate * fmsize: Array used to determine what size the the structures 380Sstevel@tonic-gate * are (for memory image & file image). 390Sstevel@tonic-gate * 400Sstevel@tonic-gate * x64: Translation routines - to file & to memory. 410Sstevel@tonic-gate * 420Sstevel@tonic-gate * What must be done when adding a new type for conversion: 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * The first question is whether you need a new ELF_T_* type 450Sstevel@tonic-gate * to be created. If you've introduced a new structure - then 460Sstevel@tonic-gate * it will need to be described - this is done by: 470Sstevel@tonic-gate * 480Sstevel@tonic-gate * o adding a new type ELF_T_* to usr/src/head/libelf.h 490Sstevel@tonic-gate * o Create a new macro to define the bytes contained in the structure. Take a 500Sstevel@tonic-gate * look at the 'Syminfo_1' macro defined below. The declarations describe 510Sstevel@tonic-gate * the structure based off of the field size of each element of the structure. 520Sstevel@tonic-gate * o Add a entry to the fmsize table for the new ELF_T_* type. 530Sstevel@tonic-gate * o Create a <newtype>_11_tof macro. Take a look at 'syminfo_11_tof'. 540Sstevel@tonic-gate * o Create a <newtype>_11_tom macro. Take a look at 'syminfo_11_tom'. 550Sstevel@tonic-gate * o The <newtype>_11_tof & <newtype>_11_tom results in conversion routines 560Sstevel@tonic-gate * <newtype>_2L11_tof, <newtype>_2L11_tom, <newtype>_2M11_tof, 570Sstevel@tonic-gate * <newtype>_2M11_tom being created in xlate.c. These routines 580Sstevel@tonic-gate * need to be added to the 'x64[]' array. 590Sstevel@tonic-gate * o Add entries to getdata.c::align32[] and getdata.c::align64[]. These 600Sstevel@tonic-gate * tables define what the alignment requirements for a data type are. 610Sstevel@tonic-gate * 620Sstevel@tonic-gate * In order to tie a section header type (SHT_*) to a data 630Sstevel@tonic-gate * structure you need to update elf64_mtype() so that it can 640Sstevel@tonic-gate * make the association. If you are introducing a new section built 650Sstevel@tonic-gate * on a basic datatype (SHT_INIT_ARRAY) then this is all the updating 660Sstevel@tonic-gate * that needs to be done. 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * 690Sstevel@tonic-gate * ELF translation routines 700Sstevel@tonic-gate * 710Sstevel@tonic-gate * These routines make a subtle implicit assumption. 720Sstevel@tonic-gate * The file representations of all structures are "packed," 730Sstevel@tonic-gate * meaning no implicit padding bytes occur. This might not 740Sstevel@tonic-gate * be the case for the memory representations. Consequently, 750Sstevel@tonic-gate * the memory representations ALWAYS contain at least as many 760Sstevel@tonic-gate * bytes as the file representations. Otherwise, the memory 770Sstevel@tonic-gate * structures would lose information, meaning they're not 780Sstevel@tonic-gate * implemented properly. 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * The words above apply to structures with the same members. 810Sstevel@tonic-gate * If a future version changes the number of members, the 820Sstevel@tonic-gate * relative structure sizes for different version must be 830Sstevel@tonic-gate * tested with the compiler. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate#define HI32 0x80000000UL 870Sstevel@tonic-gate#define LO31 0x7fffffffUL 880Sstevel@tonic-gate 890Sstevel@tonic-gate#define HI64 0x8000000000000000ULL 900Sstevel@tonic-gate#define LO63 0x7fffffffffffffffULL 910Sstevel@tonic-gate 920Sstevel@tonic-gate/* 930Sstevel@tonic-gate * These macros create indexes for accessing the bytes of 940Sstevel@tonic-gate * words and halfwords for ELFCLASS64 data representations 950Sstevel@tonic-gate * (currently ELFDATA2LSB and ELFDATA2MSB). In all cases, 960Sstevel@tonic-gate * 970Sstevel@tonic-gate * x = ((((((((((((X_7 << 8) + X_6) << 8) + X_5) << 8) + X_4) << 8 980Sstevel@tonic-gate * + X_3) << 8) + X_2) << 8) + X_1) << 8) + X_0 990Sstevel@tonic-gate * w = (((((X_3 << 8) + X_2) << 8) + X_1) << 8) + X_0 1000Sstevel@tonic-gate * h = (X_1 << 8) + X_0 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * These assume the file representations for Addr, Off, 1030Sstevel@tonic-gate * Sword, and Word use 4 bytes, but the memory def's for 1040Sstevel@tonic-gate * the types may differ. 1050Sstevel@tonic-gate * 1060Sstevel@tonic-gate * Naming convention: 1070Sstevel@tonic-gate * ..._L ELFDATA2LSB 1080Sstevel@tonic-gate * ..._M ELFDATA2MSB 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * enuma_*(n) define enum names for addr n 1110Sstevel@tonic-gate * enumb_*(n) define enum names for byte n 1120Sstevel@tonic-gate * enumh_*(n) define enum names for half n 1130Sstevel@tonic-gate * enumo_*(n) define enum names for off n 1140Sstevel@tonic-gate * enumw_*(n) define enum names for word n 1150Sstevel@tonic-gate * enumx_*(n) define enum names for xword n 1160Sstevel@tonic-gate * enuml_*(n) define enum names for Lword n 1170Sstevel@tonic-gate * tofa(d,s,n) xlate addr n from mem s to file d 1180Sstevel@tonic-gate * tofb(d,s,n) xlate byte n from mem s to file d 1190Sstevel@tonic-gate * tofh(d,s,n) xlate half n from mem s to file d 1200Sstevel@tonic-gate * tofo(d,s,n) xlate off n from mem s to file d 1210Sstevel@tonic-gate * tofw(d,s,n) xlate word n from mem s to file d 1220Sstevel@tonic-gate * tofx(d,s,n) xlate xword n from mem s to file d 1230Sstevel@tonic-gate * tofl(d,s,n) xlate Lword n from mem s to file d 1240Sstevel@tonic-gate * toma(s,n) xlate addr n from file s to expression value 1250Sstevel@tonic-gate * tomb(s,n) xlate byte n from file s to expression value 1260Sstevel@tonic-gate * tomh(s,n) xlate half n from file s to expression value 1270Sstevel@tonic-gate * tomo(s,n) xlate off n from file s to expression value 1280Sstevel@tonic-gate * tomw(s,n) xlate word n from file s to expression value 1290Sstevel@tonic-gate * tomx(s,n) xlate xword n from file s to expression value 1300Sstevel@tonic-gate * toml(s,n) xlate Lword n from file s to expression value 1310Sstevel@tonic-gate * 1320Sstevel@tonic-gate * tof*() macros must move a multi-byte value into a temporary 1330Sstevel@tonic-gate * because ``in place'' conversions are allowed. If a temp is not 1340Sstevel@tonic-gate * used for multi-byte objects, storing an initial destination byte 1350Sstevel@tonic-gate * may clobber a source byte not yet examined. 1360Sstevel@tonic-gate * 1370Sstevel@tonic-gate * tom*() macros compute an expression value from the source 1380Sstevel@tonic-gate * without touching the destination; so they're safe. 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate 1410Sstevel@tonic-gatedefine(enuma_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl 1420Sstevel@tonic-gatedefine(enuma_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl 1430Sstevel@tonic-gatedefine(enumb_L, `$1_L')dnl 1440Sstevel@tonic-gatedefine(enumb_M, `$1_M')dnl 1450Sstevel@tonic-gatedefine(enumh_L, `$1_L0, $1_L1')dnl 1460Sstevel@tonic-gatedefine(enumh_M, `$1_M1, $1_M0')dnl 1470Sstevel@tonic-gatedefine(enumo_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl 1480Sstevel@tonic-gatedefine(enumo_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl 1490Sstevel@tonic-gatedefine(enumw_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl 1500Sstevel@tonic-gatedefine(enumw_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl 1510Sstevel@tonic-gatedefine(enumx_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl 1520Sstevel@tonic-gatedefine(enumx_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl 1530Sstevel@tonic-gatedefine(enuml_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl 1540Sstevel@tonic-gatedefine(enuml_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl 1550Sstevel@tonic-gate 1560Sstevel@tonic-gatedefine(tofa, `{ Elf64_Addr _t_ = $2; 1570Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1580Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1590Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1600Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24), 1610Sstevel@tonic-gate ($1)[$3`'4] = (Byte)(_t_>>32), 1620Sstevel@tonic-gate ($1)[$3`'5] = (Byte)(_t_>>40), 1630Sstevel@tonic-gate ($1)[$3`'6] = (Byte)(_t_>>48), 1640Sstevel@tonic-gate ($1)[$3`'7] = (Byte)(_t_>>56); }')dnl 1650Sstevel@tonic-gatedefine(tofb, `($1)[$3] = (Byte)($2)')dnl 1660Sstevel@tonic-gatedefine(tofh, `{ Elf64_Half _t_ = $2; 1670Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1680Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8); }')dnl 1690Sstevel@tonic-gatedefine(tofo, `{ Elf64_Off _t_ = $2; 1700Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1710Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1720Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1730Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24), 1740Sstevel@tonic-gate ($1)[$3`'4] = (Byte)(_t_>>32), 1750Sstevel@tonic-gate ($1)[$3`'5] = (Byte)(_t_>>40), 1760Sstevel@tonic-gate ($1)[$3`'6] = (Byte)(_t_>>48), 1770Sstevel@tonic-gate ($1)[$3`'7] = (Byte)(_t_>>56); }')dnl 1780Sstevel@tonic-gatedefine(tofw, `{ Elf64_Word _t_ = $2; 1790Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1800Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1810Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1820Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24); }')dnl 1830Sstevel@tonic-gatedefine(tofx, `{ Elf64_Xword _t_ = $2; 1840Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1850Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1860Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1870Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24), 1880Sstevel@tonic-gate ($1)[$3`'4] = (Byte)(_t_>>32), 1890Sstevel@tonic-gate ($1)[$3`'5] = (Byte)(_t_>>40), 1900Sstevel@tonic-gate ($1)[$3`'6] = (Byte)(_t_>>48), 1910Sstevel@tonic-gate ($1)[$3`'7] = (Byte)(_t_>>56); }')dnl 1920Sstevel@tonic-gatedefine(tofl, `{ Elf64_Lword _t_ = $2; 1930Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1940Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1950Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1960Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24), 1970Sstevel@tonic-gate ($1)[$3`'4] = (Byte)(_t_>>32), 1980Sstevel@tonic-gate ($1)[$3`'5] = (Byte)(_t_>>40), 1990Sstevel@tonic-gate ($1)[$3`'6] = (Byte)(_t_>>48), 2000Sstevel@tonic-gate ($1)[$3`'7] = (Byte)(_t_>>56); }')dnl 2010Sstevel@tonic-gate 2020Sstevel@tonic-gatedefine(toma, `(((((((((((Elf64_Addr)($1)[$2`'7]<<8) 2030Sstevel@tonic-gate +($1)[$2`'6]<<8) 2040Sstevel@tonic-gate +($1)[$2`'5]<<8) 2050Sstevel@tonic-gate +($1)[$2`'4]<<8) 2060Sstevel@tonic-gate +($1)[$2`'3]<<8) 2070Sstevel@tonic-gate +($1)[$2`'2])<<8) 2080Sstevel@tonic-gate +($1)[$2`'1])<<8) 2090Sstevel@tonic-gate +($1)[$2`'0])')dnl 2100Sstevel@tonic-gatedefine(tomb, `((Byte)($1)[$2])')dnl 2110Sstevel@tonic-gatedefine(tomh, `(((Elf64_Half)($1)[$2`'1]<<8)+($1)[$2`'0])')dnl 2120Sstevel@tonic-gatedefine(tomo, `(((((((((((Elf64_Off)($1)[$2`'7]<<8) 2130Sstevel@tonic-gate +($1)[$2`'6]<<8) 2140Sstevel@tonic-gate +($1)[$2`'5]<<8) 2150Sstevel@tonic-gate +($1)[$2`'4]<<8) 2160Sstevel@tonic-gate +($1)[$2`'3]<<8) 2170Sstevel@tonic-gate +($1)[$2`'2])<<8) 2180Sstevel@tonic-gate +($1)[$2`'1])<<8) 2190Sstevel@tonic-gate +($1)[$2`'0])')dnl 2200Sstevel@tonic-gatedefine(tomw, `(((((((Elf64_Word)($1)[$2`'3]<<8) 2210Sstevel@tonic-gate +($1)[$2`'2])<<8) 2220Sstevel@tonic-gate +($1)[$2`'1])<<8) 2230Sstevel@tonic-gate +($1)[$2`'0])')dnl 2240Sstevel@tonic-gatedefine(tomx, `(((((((((((Elf64_Xword)($1)[$2`'7]<<8) 2250Sstevel@tonic-gate +($1)[$2`'6]<<8) 2260Sstevel@tonic-gate +($1)[$2`'5]<<8) 2270Sstevel@tonic-gate +($1)[$2`'4]<<8) 2280Sstevel@tonic-gate +($1)[$2`'3]<<8) 2290Sstevel@tonic-gate +($1)[$2`'2])<<8) 2300Sstevel@tonic-gate +($1)[$2`'1])<<8) 2310Sstevel@tonic-gate +($1)[$2`'0])')dnl 2320Sstevel@tonic-gatedefine(toml, `(((((((((((Elf64_Lword)($1)[$2`'7]<<8) 2330Sstevel@tonic-gate +($1)[$2`'6]<<8) 2340Sstevel@tonic-gate +($1)[$2`'5]<<8) 2350Sstevel@tonic-gate +($1)[$2`'4]<<8) 2360Sstevel@tonic-gate +($1)[$2`'3]<<8) 2370Sstevel@tonic-gate +($1)[$2`'2])<<8) 2380Sstevel@tonic-gate +($1)[$2`'1])<<8) 2390Sstevel@tonic-gate +($1)[$2`'0])')dnl 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate/* 2430Sstevel@tonic-gate * ELF data object indexes 2440Sstevel@tonic-gate * The enums are broken apart to get around deficiencies 2450Sstevel@tonic-gate * in some compilers. 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate 2480Sstevel@tonic-gatedefine(Addr, ` 2490Sstevel@tonic-gateenum 2500Sstevel@tonic-gate{ 2510Sstevel@tonic-gate enuma_$1(A)`'ifelse(`$2', `', `', `, 2520Sstevel@tonic-gate A_sizeof') 2530Sstevel@tonic-gate};') 2540Sstevel@tonic-gate 2550Sstevel@tonic-gateAddr(L) 2560Sstevel@tonic-gateAddr(M,1) 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate 2590Sstevel@tonic-gatedefine(Half, ` 2600Sstevel@tonic-gateenum 2610Sstevel@tonic-gate{ 2620Sstevel@tonic-gate enumh_$1(H)`'ifelse(`$2', `', `', `, 2630Sstevel@tonic-gate H_sizeof') 2640Sstevel@tonic-gate};') 2650Sstevel@tonic-gate 2660Sstevel@tonic-gateHalf(L) 2670Sstevel@tonic-gateHalf(M,1) 2680Sstevel@tonic-gate 2690Sstevel@tonic-gatedefine(Lword, ` 2700Sstevel@tonic-gateenum 2710Sstevel@tonic-gate{ 2720Sstevel@tonic-gate enuml_$1(L)`'ifelse(`$2', `', `', `, 2730Sstevel@tonic-gate L_sizeof') 2740Sstevel@tonic-gate};') 2750Sstevel@tonic-gate 2760Sstevel@tonic-gateLword(L) 2770Sstevel@tonic-gateLword(M,1) 2780Sstevel@tonic-gate 2790Sstevel@tonic-gatedefine(Move_1, ` 2800Sstevel@tonic-gateenum 2810Sstevel@tonic-gate{ 2820Sstevel@tonic-gate enuml_$1(M1_value), 2830Sstevel@tonic-gate enumx_$1(M1_info), 2840Sstevel@tonic-gate enumx_$1(M1_poffset), 2850Sstevel@tonic-gate enumh_$1(M1_repeat), 2860Sstevel@tonic-gate enumh_$1(M1_stride)`'ifelse(`$2', `', `', `, 2870Sstevel@tonic-gate M1_sizeof') 2880Sstevel@tonic-gate};') 2890Sstevel@tonic-gate 2900Sstevel@tonic-gateMove_1(L) 2910Sstevel@tonic-gateMove_1(M,1) 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate 2940Sstevel@tonic-gatedefine(MoveP_1, ` 2950Sstevel@tonic-gateenum 2960Sstevel@tonic-gate{ 2970Sstevel@tonic-gate enuml_$1(MP1_value), 2980Sstevel@tonic-gate enumx_$1(MP1_info), 2990Sstevel@tonic-gate enumx_$1(MP1_poffset), 3000Sstevel@tonic-gate enumh_$1(MP1_repeat), 3010Sstevel@tonic-gate enumh_$1(MP1_stride), 3020Sstevel@tonic-gate enumw_$1(MP1_padding)`'ifelse(`$2', `', `', `, 3030Sstevel@tonic-gate MP1_sizeof') 3040Sstevel@tonic-gate};') 3050Sstevel@tonic-gate 3060Sstevel@tonic-gateMoveP_1(L) 3070Sstevel@tonic-gateMoveP_1(M,1) 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate 3100Sstevel@tonic-gatedefine(Off, ` 3110Sstevel@tonic-gateenum 3120Sstevel@tonic-gate{ 3130Sstevel@tonic-gate enumo_$1(O)`'ifelse(`$2', `', `', `, 3140Sstevel@tonic-gate O_sizeof') 3150Sstevel@tonic-gate};') 3160Sstevel@tonic-gate 3170Sstevel@tonic-gateOff(L) 3180Sstevel@tonic-gateOff(M,1) 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate 3210Sstevel@tonic-gatedefine(Word, ` 3220Sstevel@tonic-gateenum 3230Sstevel@tonic-gate{ 3240Sstevel@tonic-gate enumw_$1(W)`'ifelse(`$2', `', `', `, 3250Sstevel@tonic-gate W_sizeof') 3260Sstevel@tonic-gate};') 3270Sstevel@tonic-gate 3280Sstevel@tonic-gateWord(L) 3290Sstevel@tonic-gateWord(M,1) 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate 3320Sstevel@tonic-gatedefine(Xword, ` 3330Sstevel@tonic-gateenum 3340Sstevel@tonic-gate{ 3350Sstevel@tonic-gate enumx_$1(X)`'ifelse(`$2',`', `', `, 3360Sstevel@tonic-gate X_sizeof') 3370Sstevel@tonic-gate};') 3380Sstevel@tonic-gate 3390Sstevel@tonic-gateXword(L) 3400Sstevel@tonic-gateXword(M,1) 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate 3430Sstevel@tonic-gatedefine(Dyn_1, ` 3440Sstevel@tonic-gateenum 3450Sstevel@tonic-gate{ 3460Sstevel@tonic-gate enumx_$1(D1_tag), 3470Sstevel@tonic-gate enumx_$1(D1_val)`'ifelse(`$2', `', `', `, 3480Sstevel@tonic-gate D1_sizeof') 3490Sstevel@tonic-gate};') 3500Sstevel@tonic-gate 3510Sstevel@tonic-gateDyn_1(L) 3520Sstevel@tonic-gateDyn_1(M,1) 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate#define E1_Nident 16 3560Sstevel@tonic-gate 3570Sstevel@tonic-gatedefine(Ehdr_1, ` 3580Sstevel@tonic-gateenum { 3590Sstevel@tonic-gate ifelse(`$2', `', `E1_ident, ')E1_ident_$1_Z = E1_Nident - 1, 3600Sstevel@tonic-gate enumh_$1(E1_type), 3610Sstevel@tonic-gate enumh_$1(E1_machine), 3620Sstevel@tonic-gate enumw_$1(E1_version), 3630Sstevel@tonic-gate enuma_$1(E1_entry), 3640Sstevel@tonic-gate enumo_$1(E1_phoff), 3650Sstevel@tonic-gate enumo_$1(E1_shoff), 3660Sstevel@tonic-gate enumw_$1(E1_flags), 3670Sstevel@tonic-gate enumh_$1(E1_ehsize), 3680Sstevel@tonic-gate enumh_$1(E1_phentsize), 3690Sstevel@tonic-gate enumh_$1(E1_phnum), 3700Sstevel@tonic-gate enumh_$1(E1_shentsize), 3710Sstevel@tonic-gate enumh_$1(E1_shnum), 3720Sstevel@tonic-gate enumh_$1(E1_shstrndx)`'ifelse(`$2', `', `', `, 3730Sstevel@tonic-gate E1_sizeof') 3740Sstevel@tonic-gate};') 3750Sstevel@tonic-gate 3760Sstevel@tonic-gateEhdr_1(L) 3770Sstevel@tonic-gateEhdr_1(M,1) 3780Sstevel@tonic-gate 3790Sstevel@tonic-gatedefine(Nhdr_1, ` 3800Sstevel@tonic-gateenum 3810Sstevel@tonic-gate{ 3820Sstevel@tonic-gate enumw_$1(N1_namesz), 3830Sstevel@tonic-gate enumw_$1(N1_descsz), 3840Sstevel@tonic-gate enumw_$1(N1_type)`'ifelse(`$2', `', `', `, 3850Sstevel@tonic-gate N1_sizeof') 3860Sstevel@tonic-gate};') 3870Sstevel@tonic-gate 3880Sstevel@tonic-gateNhdr_1(L) 3890Sstevel@tonic-gateNhdr_1(M,1) 3900Sstevel@tonic-gate 3910Sstevel@tonic-gatedefine(Phdr_1, ` 3920Sstevel@tonic-gateenum 3930Sstevel@tonic-gate{ 3940Sstevel@tonic-gate enumw_$1(P1_type), 3950Sstevel@tonic-gate enumw_$1(P1_flags), 3960Sstevel@tonic-gate enumo_$1(P1_offset), 3970Sstevel@tonic-gate enuma_$1(P1_vaddr), 3980Sstevel@tonic-gate enuma_$1(P1_paddr), 3990Sstevel@tonic-gate enumx_$1(P1_filesz), 4000Sstevel@tonic-gate enumx_$1(P1_memsz), 4010Sstevel@tonic-gate enumx_$1(P1_align)`'ifelse(`$2', `', `', `, 4020Sstevel@tonic-gate P1_sizeof') 4030Sstevel@tonic-gate};') 4040Sstevel@tonic-gate 4050Sstevel@tonic-gatePhdr_1(L) 4060Sstevel@tonic-gatePhdr_1(M,1) 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate 4090Sstevel@tonic-gatedefine(Rel_1, ` 4100Sstevel@tonic-gateenum 4110Sstevel@tonic-gate{ 4120Sstevel@tonic-gate enuma_$1(R1_offset), 4130Sstevel@tonic-gate enumx_$1(R1_info)`'ifelse(`$2', `', `', `, 4140Sstevel@tonic-gate R1_sizeof') 4150Sstevel@tonic-gate};') 4160Sstevel@tonic-gate 4170Sstevel@tonic-gateRel_1(L) 4180Sstevel@tonic-gateRel_1(M,1) 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate 4210Sstevel@tonic-gatedefine(Rela_1, ` 4220Sstevel@tonic-gateenum 4230Sstevel@tonic-gate{ 4240Sstevel@tonic-gate enuma_$1(RA1_offset), 4250Sstevel@tonic-gate enumx_$1(RA1_info), 4260Sstevel@tonic-gate enumx_$1(RA1_addend)`'ifelse(`$2', `', `', `, 4270Sstevel@tonic-gate RA1_sizeof') 4280Sstevel@tonic-gate};') 4290Sstevel@tonic-gate 4300Sstevel@tonic-gateRela_1(L) 4310Sstevel@tonic-gateRela_1(M,1) 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate 4340Sstevel@tonic-gatedefine(Shdr_1, ` 4350Sstevel@tonic-gateenum 4360Sstevel@tonic-gate{ 4370Sstevel@tonic-gate enumw_$1(SH1_name), 4380Sstevel@tonic-gate enumw_$1(SH1_type), 4390Sstevel@tonic-gate enumx_$1(SH1_flags), 4400Sstevel@tonic-gate enuma_$1(SH1_addr), 4410Sstevel@tonic-gate enumo_$1(SH1_offset), 4420Sstevel@tonic-gate enumx_$1(SH1_size), 4430Sstevel@tonic-gate enumw_$1(SH1_link), 4440Sstevel@tonic-gate enumw_$1(SH1_info), 4450Sstevel@tonic-gate enumx_$1(SH1_addralign), 4460Sstevel@tonic-gate enumx_$1(SH1_entsize)`'ifelse(`$2', `', `', `, 4470Sstevel@tonic-gate SH1_sizeof') 4480Sstevel@tonic-gate};') 4490Sstevel@tonic-gate 4500Sstevel@tonic-gateShdr_1(L) 4510Sstevel@tonic-gateShdr_1(M,1) 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate 4540Sstevel@tonic-gatedefine(Sym_1, ` 4550Sstevel@tonic-gateenum 4560Sstevel@tonic-gate{ 4570Sstevel@tonic-gate enumw_$1(ST1_name), 4580Sstevel@tonic-gate enumb_$1(ST1_info), 4590Sstevel@tonic-gate enumb_$1(ST1_other), 4600Sstevel@tonic-gate enumh_$1(ST1_shndx), 4610Sstevel@tonic-gate enuma_$1(ST1_value), 4620Sstevel@tonic-gate enumx_$1(ST1_size)`'ifelse(`$2', `', `', `, 4630Sstevel@tonic-gate ST1_sizeof') 4640Sstevel@tonic-gate};') 4650Sstevel@tonic-gate 4660Sstevel@tonic-gateSym_1(L) 4670Sstevel@tonic-gateSym_1(M,1) 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate 4700Sstevel@tonic-gatedefine(Syminfo_1, ` 4710Sstevel@tonic-gateenum 4720Sstevel@tonic-gate{ 4730Sstevel@tonic-gate enumh_$1(SI1_boundto), 4740Sstevel@tonic-gate enumh_$1(SI1_flags)`'ifelse(`$2', `', `', `, 4750Sstevel@tonic-gate SI1_sizeof') 4760Sstevel@tonic-gate};') 4770Sstevel@tonic-gate 4780Sstevel@tonic-gateSyminfo_1(L) 4790Sstevel@tonic-gateSyminfo_1(M,1) 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate 4820Sstevel@tonic-gatedefine(Cap_1, ` 4830Sstevel@tonic-gateenum 4840Sstevel@tonic-gate{ 4850Sstevel@tonic-gate enumx_$1(C1_tag), 4860Sstevel@tonic-gate enumx_$1(C1_val)`'ifelse(`$2', `', `', `, 4870Sstevel@tonic-gate C1_sizeof') 4880Sstevel@tonic-gate};') 4890Sstevel@tonic-gate 4900Sstevel@tonic-gateCap_1(L) 4910Sstevel@tonic-gateCap_1(M,1) 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate 4940Sstevel@tonic-gatedefine(Verdef_1, ` 4950Sstevel@tonic-gateenum 4960Sstevel@tonic-gate{ 4970Sstevel@tonic-gate enumh_$1(VD1_version), 4980Sstevel@tonic-gate enumh_$1(VD1_flags), 4990Sstevel@tonic-gate enumh_$1(VD1_ndx), 5000Sstevel@tonic-gate enumh_$1(VD1_cnt), 5010Sstevel@tonic-gate enumw_$1(VD1_hash), 5020Sstevel@tonic-gate enumw_$1(VD1_aux), 5030Sstevel@tonic-gate enumw_$1(VD1_next)`'ifelse(`$2', `', `', `, 5040Sstevel@tonic-gate VD1_sizeof') 5050Sstevel@tonic-gate};') 5060Sstevel@tonic-gate 5070Sstevel@tonic-gateVerdef_1(L) 5080Sstevel@tonic-gateVerdef_1(M,1) 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate 5110Sstevel@tonic-gatedefine(Verdaux_1, ` 5120Sstevel@tonic-gateenum 5130Sstevel@tonic-gate{ 5140Sstevel@tonic-gate enumw_$1(VDA1_name), 5150Sstevel@tonic-gate enumw_$1(VDA1_next)`'ifelse(`$2', `', `', `, 5160Sstevel@tonic-gate VDA1_sizeof') 5170Sstevel@tonic-gate};') 5180Sstevel@tonic-gate 5190Sstevel@tonic-gateVerdaux_1(L) 5200Sstevel@tonic-gateVerdaux_1(M,1) 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate 5230Sstevel@tonic-gatedefine(Verneed_1, ` 5240Sstevel@tonic-gateenum 5250Sstevel@tonic-gate{ 5260Sstevel@tonic-gate enumh_$1(VN1_version), 5270Sstevel@tonic-gate enumh_$1(VN1_cnt), 5280Sstevel@tonic-gate enumw_$1(VN1_file), 5290Sstevel@tonic-gate enumw_$1(VN1_aux), 5300Sstevel@tonic-gate enumw_$1(VN1_next)`'ifelse(`$2', `', `', `, 5310Sstevel@tonic-gate VN1_sizeof') 5320Sstevel@tonic-gate};') 5330Sstevel@tonic-gate 5340Sstevel@tonic-gateVerneed_1(L) 5350Sstevel@tonic-gateVerneed_1(M,1) 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate 5380Sstevel@tonic-gatedefine(Vernaux_1, ` 5390Sstevel@tonic-gateenum 5400Sstevel@tonic-gate{ 5410Sstevel@tonic-gate enumw_$1(VNA1_hash), 5420Sstevel@tonic-gate enumh_$1(VNA1_flags), 5430Sstevel@tonic-gate enumh_$1(VNA1_other), 5440Sstevel@tonic-gate enumw_$1(VNA1_name), 5450Sstevel@tonic-gate enumw_$1(VNA1_next)`'ifelse(`$2', `', `', `, 5460Sstevel@tonic-gate VNA1_sizeof') 5470Sstevel@tonic-gate};') 5480Sstevel@tonic-gate 5490Sstevel@tonic-gateVernaux_1(L) 5500Sstevel@tonic-gateVernaux_1(M,1) 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate/* 5540Sstevel@tonic-gate * Translation function declarations. 5550Sstevel@tonic-gate * 5560Sstevel@tonic-gate * <object>_<data><dver><sver>_tof 5570Sstevel@tonic-gate * <object>_<data><dver><sver>_tom 5580Sstevel@tonic-gate * where 5590Sstevel@tonic-gate * <data> 2L ELFDATA2LSB 5600Sstevel@tonic-gate * 2M ELFDATA2MSB 5610Sstevel@tonic-gate */ 5620Sstevel@tonic-gate 5630Sstevel@tonic-gatestatic void addr_2L_tof(), addr_2L_tom(), 5640Sstevel@tonic-gate addr_2M_tof(), addr_2M_tom(), 5650Sstevel@tonic-gate byte_to(), 5660Sstevel@tonic-gate dyn_2L11_tof(), dyn_2L11_tom(), 5670Sstevel@tonic-gate dyn_2M11_tof(), dyn_2M11_tom(), 5680Sstevel@tonic-gate ehdr_2L11_tof(), ehdr_2L11_tom(), 5690Sstevel@tonic-gate ehdr_2M11_tof(), ehdr_2M11_tom(), 5700Sstevel@tonic-gate half_2L_tof(), half_2L_tom(), 5710Sstevel@tonic-gate half_2M_tof(), half_2M_tom(), 5720Sstevel@tonic-gate move_2L11_tof(), move_2L11_tom(), 5730Sstevel@tonic-gate move_2M11_tof(), move_2M11_tom(), 5740Sstevel@tonic-gate movep_2L11_tof(), movep_2L11_tom(), 5750Sstevel@tonic-gate movep_2M11_tof(), movep_2M11_tom(), 5760Sstevel@tonic-gate off_2L_tof(), off_2L_tom(), 5770Sstevel@tonic-gate off_2M_tof(), off_2M_tom(), 5780Sstevel@tonic-gate note_2L11_tof(), note_2L11_tom(), 5790Sstevel@tonic-gate note_2M11_tof(), note_2M11_tom(), 5800Sstevel@tonic-gate phdr_2L11_tof(), phdr_2L11_tom(), 5810Sstevel@tonic-gate phdr_2M11_tof(), phdr_2M11_tom(), 5820Sstevel@tonic-gate rel_2L11_tof(), rel_2L11_tom(), 5830Sstevel@tonic-gate rel_2M11_tof(), rel_2M11_tom(), 5840Sstevel@tonic-gate rela_2L11_tof(), rela_2L11_tom(), 5850Sstevel@tonic-gate rela_2M11_tof(), rela_2M11_tom(), 5860Sstevel@tonic-gate shdr_2L11_tof(), shdr_2L11_tom(), 5870Sstevel@tonic-gate shdr_2M11_tof(), shdr_2M11_tom(), 5880Sstevel@tonic-gate sword_2L_tof(), sword_2L_tom(), 5890Sstevel@tonic-gate sword_2M_tof(), sword_2M_tom(), 5900Sstevel@tonic-gate sym_2L11_tof(), sym_2L11_tom(), 5910Sstevel@tonic-gate sym_2M11_tof(), sym_2M11_tom(), 5920Sstevel@tonic-gate syminfo_2L11_tof(), syminfo_2L11_tom(), 5930Sstevel@tonic-gate syminfo_2M11_tof(), syminfo_2M11_tom(), 5940Sstevel@tonic-gate word_2L_tof(), word_2L_tom(), 5950Sstevel@tonic-gate word_2M_tof(), word_2M_tom(), 5960Sstevel@tonic-gate verdef_2L11_tof(), verdef_2L11_tom(), 5970Sstevel@tonic-gate verdef_2M11_tof(), verdef_2M11_tom(), 5980Sstevel@tonic-gate verneed_2L11_tof(), verneed_2L11_tom(), 5990Sstevel@tonic-gate verneed_2M11_tof(), verneed_2M11_tom(), 6000Sstevel@tonic-gate sxword_2L_tof(), sxword_2L_tom(), 6010Sstevel@tonic-gate sxword_2M_tof(), sxword_2M_tom(), 6020Sstevel@tonic-gate xword_2L_tof(), xword_2L_tom(), 6030Sstevel@tonic-gate xword_2M_tof(), xword_2M_tom(), 6040Sstevel@tonic-gate cap_2L11_tof(), cap_2L11_tom(), 6050Sstevel@tonic-gate cap_2M11_tof(), cap_2M11_tom(); 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate/* 6090Sstevel@tonic-gate * x64 [dst_version - 1] [src_version - 1] [encode - 1] [type] 6100Sstevel@tonic-gate */ 6110Sstevel@tonic-gate 6120Sstevel@tonic-gatestatic struct { 6130Sstevel@tonic-gate void (*x_tof)(), 6140Sstevel@tonic-gate (*x_tom)(); 6150Sstevel@tonic-gate} x64 [EV_CURRENT] [EV_CURRENT] [ELFDATANUM - 1] [ELF_T_NUM] = { 6160Sstevel@tonic-gate { 6170Sstevel@tonic-gate { 6180Sstevel@tonic-gate { /* [1-1][1-1][2LSB-1][.] */ 6190Sstevel@tonic-gate/* BYTE */ { byte_to, byte_to }, 6200Sstevel@tonic-gate/* ADDR */ { addr_2L_tof, addr_2L_tom }, 6210Sstevel@tonic-gate/* DYN */ { dyn_2L11_tof, dyn_2L11_tom }, 6220Sstevel@tonic-gate/* EHDR */ { ehdr_2L11_tof, ehdr_2L11_tom }, 6230Sstevel@tonic-gate/* HALF */ { half_2L_tof, half_2L_tom }, 6240Sstevel@tonic-gate/* OFF */ { off_2L_tof, off_2L_tom }, 6250Sstevel@tonic-gate/* PHDR */ { phdr_2L11_tof, phdr_2L11_tom }, 6260Sstevel@tonic-gate/* RELA */ { rela_2L11_tof, rela_2L11_tom }, 6270Sstevel@tonic-gate/* REL */ { rel_2L11_tof, rel_2L11_tom }, 6280Sstevel@tonic-gate/* SHDR */ { shdr_2L11_tof, shdr_2L11_tom }, 6290Sstevel@tonic-gate/* SWORD */ { sword_2L_tof, sword_2L_tom }, 6300Sstevel@tonic-gate/* SYM */ { sym_2L11_tof, sym_2L11_tom }, 6310Sstevel@tonic-gate/* WORD */ { word_2L_tof, word_2L_tom }, 6320Sstevel@tonic-gate/* VERDEF */ { verdef_2L11_tof, verdef_2L11_tom}, 6330Sstevel@tonic-gate/* VERNEED */ { verneed_2L11_tof, verneed_2L11_tom}, 6340Sstevel@tonic-gate/* SXWORD */ { sxword_2L_tof, sxword_2L_tom }, 6350Sstevel@tonic-gate/* XWORD */ { xword_2L_tof, xword_2L_tom }, 6360Sstevel@tonic-gate/* SYMINFO */ { syminfo_2L11_tof, syminfo_2L11_tom }, 6370Sstevel@tonic-gate/* NOTE */ { note_2L11_tof, note_2L11_tom }, 6380Sstevel@tonic-gate/* MOVE */ { move_2L11_tof, move_2L11_tom }, 6390Sstevel@tonic-gate/* MOVEP */ { movep_2L11_tof, movep_2L11_tom }, 6400Sstevel@tonic-gate/* CAP */ { cap_2L11_tof, cap_2L11_tom }, 6410Sstevel@tonic-gate }, 6420Sstevel@tonic-gate { /* [1-1][1-1][2MSB-1][.] */ 6430Sstevel@tonic-gate/* BYTE */ { byte_to, byte_to }, 6440Sstevel@tonic-gate/* ADDR */ { addr_2M_tof, addr_2M_tom }, 6450Sstevel@tonic-gate/* DYN */ { dyn_2M11_tof, dyn_2M11_tom }, 6460Sstevel@tonic-gate/* EHDR */ { ehdr_2M11_tof, ehdr_2M11_tom }, 6470Sstevel@tonic-gate/* HALF */ { half_2M_tof, half_2M_tom }, 6480Sstevel@tonic-gate/* OFF */ { off_2M_tof, off_2M_tom }, 6490Sstevel@tonic-gate/* PHDR */ { phdr_2M11_tof, phdr_2M11_tom }, 6500Sstevel@tonic-gate/* RELA */ { rela_2M11_tof, rela_2M11_tom }, 6510Sstevel@tonic-gate/* REL */ { rel_2M11_tof, rel_2M11_tom }, 6520Sstevel@tonic-gate/* SHDR */ { shdr_2M11_tof, shdr_2M11_tom }, 6530Sstevel@tonic-gate/* SWORD */ { sword_2M_tof, sword_2M_tom }, 6540Sstevel@tonic-gate/* SYM */ { sym_2M11_tof, sym_2M11_tom }, 6550Sstevel@tonic-gate/* WORD */ { word_2M_tof, word_2M_tom }, 6560Sstevel@tonic-gate/* VERDEF */ { verdef_2M11_tof, verdef_2M11_tom}, 6570Sstevel@tonic-gate/* VERNEED */ { verneed_2M11_tof, verneed_2M11_tom}, 6580Sstevel@tonic-gate/* SXWORD */ { sxword_2M_tof, sxword_2M_tom }, 6590Sstevel@tonic-gate/* XWORD */ { xword_2M_tof, xword_2M_tom }, 6600Sstevel@tonic-gate/* SYMINFO */ { syminfo_2M11_tof, syminfo_2M11_tom }, 6610Sstevel@tonic-gate/* NOTE */ { note_2M11_tof, note_2M11_tom }, 6620Sstevel@tonic-gate/* MOVE */ { move_2M11_tof, move_2M11_tom }, 6630Sstevel@tonic-gate/* MOVEP */ { movep_2M11_tof, movep_2M11_tom }, 6640Sstevel@tonic-gate/* CAP */ { cap_2M11_tof, cap_2M11_tom }, 6650Sstevel@tonic-gate }, 6660Sstevel@tonic-gate }, 6670Sstevel@tonic-gate }, 6680Sstevel@tonic-gate}; 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate/* 6720Sstevel@tonic-gate * size [version - 1] [type] 6730Sstevel@tonic-gate */ 6740Sstevel@tonic-gate 6750Sstevel@tonic-gatestatic const struct { 6760Sstevel@tonic-gate size_t s_filesz, 6770Sstevel@tonic-gate s_memsz; 6780Sstevel@tonic-gate} fmsize [EV_CURRENT] [ELF_T_NUM] = 6790Sstevel@tonic-gate{ 6800Sstevel@tonic-gate { /* [1-1][.] */ 6810Sstevel@tonic-gate/* BYTE */ { 1, 1 }, 6820Sstevel@tonic-gate/* ADDR */ { A_sizeof, sizeof (Elf64_Addr) }, 6830Sstevel@tonic-gate/* DYN */ { D1_sizeof, sizeof (Elf64_Dyn) }, 6840Sstevel@tonic-gate/* EHDR */ { E1_sizeof, sizeof (Elf64_Ehdr) }, 6850Sstevel@tonic-gate/* HALF */ { H_sizeof, sizeof (Elf64_Half) }, 6860Sstevel@tonic-gate/* OFF */ { O_sizeof, sizeof (Elf64_Off) }, 6870Sstevel@tonic-gate/* PHDR */ { P1_sizeof, sizeof (Elf64_Phdr) }, 6880Sstevel@tonic-gate/* RELA */ { RA1_sizeof, sizeof (Elf64_Rela) }, 6890Sstevel@tonic-gate/* REL */ { R1_sizeof, sizeof (Elf64_Rel) }, 6900Sstevel@tonic-gate/* SHDR */ { SH1_sizeof, sizeof (Elf64_Shdr) }, 6910Sstevel@tonic-gate/* SWORD */ { W_sizeof, sizeof (Elf64_Sword) }, 6920Sstevel@tonic-gate/* SYM */ { ST1_sizeof, sizeof (Elf64_Sym) }, 6930Sstevel@tonic-gate/* WORD */ { W_sizeof, sizeof (Elf64_Word) }, 6940Sstevel@tonic-gate/* VERDEF */ { 1, 1 }, /* both VERDEF & VERNEED have varying size */ 6950Sstevel@tonic-gate/* VERNEED */ { 1, 1 }, /* structures so we set their sizes to 1 */ 6960Sstevel@tonic-gate/* SXWORD */ { X_sizeof, sizeof (Elf64_Sxword) }, 6970Sstevel@tonic-gate/* XWORD */ { X_sizeof, sizeof (Elf64_Xword) }, 6980Sstevel@tonic-gate/* SYMINFO */ { SI1_sizeof, sizeof (Elf64_Syminfo) }, 6990Sstevel@tonic-gate/* NOTE */ { 1, 1}, /* NOTE has varying sized data we can't */ 7000Sstevel@tonic-gate /* use the usual table magic. */ 7010Sstevel@tonic-gate/* MOVE */ { M1_sizeof, sizeof (Elf64_Move) }, 7020Sstevel@tonic-gate/* MOVEP */ { MP1_sizeof, sizeof (Elf64_Move) }, 7030Sstevel@tonic-gate/* CAP */ { C1_sizeof, sizeof (Elf64_Cap) }, 7040Sstevel@tonic-gate }, 7050Sstevel@tonic-gate}; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate/* 7090Sstevel@tonic-gate * memory type [version - 1] [section type] 7100Sstevel@tonic-gate */ 7110Sstevel@tonic-gate 7120Sstevel@tonic-gatestatic const Elf_Type mtype[EV_CURRENT][SHT_NUM] = 7130Sstevel@tonic-gate{ 7140Sstevel@tonic-gate { /* [1-1][.] */ 7150Sstevel@tonic-gate/* NULL */ ELF_T_BYTE, 7160Sstevel@tonic-gate/* PROGBITS */ ELF_T_BYTE, 7170Sstevel@tonic-gate/* SYMTAB */ ELF_T_SYM, 7180Sstevel@tonic-gate/* STRTAB */ ELF_T_BYTE, 7190Sstevel@tonic-gate/* RELA */ ELF_T_RELA, 7200Sstevel@tonic-gate/* HASH */ ELF_T_WORD, 7210Sstevel@tonic-gate/* DYNAMIC */ ELF_T_DYN, 7220Sstevel@tonic-gate/* NOTE */ ELF_T_NOTE, 7230Sstevel@tonic-gate/* NOBITS */ ELF_T_BYTE, 7240Sstevel@tonic-gate/* REL */ ELF_T_REL, 7250Sstevel@tonic-gate/* SHLIB */ ELF_T_BYTE, 7260Sstevel@tonic-gate/* DYNSYM */ ELF_T_SYM, 7270Sstevel@tonic-gate/* UNKNOWN12 */ ELF_T_BYTE, 7280Sstevel@tonic-gate/* UNKNOWN13 */ ELF_T_BYTE, 7290Sstevel@tonic-gate/* INIT_ARRAY */ ELF_T_ADDR, 7300Sstevel@tonic-gate/* FINI_ARRAY */ ELF_T_ADDR, 7310Sstevel@tonic-gate/* PREINIT_ARRAY */ ELF_T_ADDR, 7320Sstevel@tonic-gate/* GROUP */ ELF_T_WORD, 7330Sstevel@tonic-gate/* SYMTAB_SHNDX */ ELF_T_WORD 7340Sstevel@tonic-gate }, 7350Sstevel@tonic-gate}; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate 7380Sstevel@tonic-gatesize_t 7390Sstevel@tonic-gateelf64_fsize(Elf_Type type, size_t count, unsigned ver) 7400Sstevel@tonic-gate{ 7410Sstevel@tonic-gate if (--ver >= EV_CURRENT) { 7420Sstevel@tonic-gate _elf_seterr(EREQ_VER, 0); 7430Sstevel@tonic-gate return (0); 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate if ((unsigned)type >= ELF_T_NUM) { 7460Sstevel@tonic-gate _elf_seterr(EREQ_TYPE, 0); 7470Sstevel@tonic-gate return (0); 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate return (fmsize[ver][type].s_filesz * count); 7500Sstevel@tonic-gate} 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate 7530Sstevel@tonic-gatesize_t 7540Sstevel@tonic-gate_elf64_msize(Elf_Type type, unsigned ver) 7550Sstevel@tonic-gate{ 7560Sstevel@tonic-gate return (fmsize[ver - 1][type].s_memsz); 7570Sstevel@tonic-gate} 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate 7600Sstevel@tonic-gateElf_Type 7610Sstevel@tonic-gate/* ARGSUSED */ 7620Sstevel@tonic-gate_elf64_mtype(Elf * elf, Elf64_Word shtype, unsigned ver) 7630Sstevel@tonic-gate{ 7640Sstevel@tonic-gate Elf64_Ehdr * ehdr = (Elf64_Ehdr *)elf->ed_ehdr; 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if (shtype < SHT_NUM) 7670Sstevel@tonic-gate return (mtype[ver - 1][shtype]); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate switch (shtype) { 7703621Sab196087 case SHT_SUNW_symsort: 7713621Sab196087 case SHT_SUNW_tlssort: 7723621Sab196087 return (ELF_T_WORD); 7733621Sab196087 case SHT_SUNW_LDYNSYM: 7743621Sab196087 return (ELF_T_SYM); 7750Sstevel@tonic-gate case SHT_SUNW_dof: 7760Sstevel@tonic-gate return (ELF_T_BYTE); 7770Sstevel@tonic-gate case SHT_SUNW_cap: 7780Sstevel@tonic-gate return (ELF_T_CAP); 77911827SRod.Evans@Sun.COM case SHT_SUNW_capchain: 78011827SRod.Evans@Sun.COM return (ELF_T_WORD); 78111827SRod.Evans@Sun.COM case SHT_SUNW_capinfo: 78211827SRod.Evans@Sun.COM return (ELF_T_XWORD); 7830Sstevel@tonic-gate case SHT_SUNW_SIGNATURE: 7840Sstevel@tonic-gate return (ELF_T_BYTE); 7850Sstevel@tonic-gate case SHT_SUNW_ANNOTATE: 7860Sstevel@tonic-gate return (ELF_T_BYTE); 7870Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR: 7880Sstevel@tonic-gate return (ELF_T_BYTE); 7890Sstevel@tonic-gate case SHT_SUNW_DEBUG: 7900Sstevel@tonic-gate return (ELF_T_BYTE); 7910Sstevel@tonic-gate case SHT_SUNW_move: 7920Sstevel@tonic-gate /* 7930Sstevel@tonic-gate * Right now - the only 64bit binaries I know 7940Sstevel@tonic-gate * about with a move is SPARC - and SPARC 7950Sstevel@tonic-gate * binaries pad the size of the move. 7960Sstevel@tonic-gate */ 7970Sstevel@tonic-gate return (ELF_T_MOVEP); 7980Sstevel@tonic-gate case SHT_SUNW_COMDAT: 7990Sstevel@tonic-gate return (ELF_T_BYTE); 8000Sstevel@tonic-gate case SHT_SUNW_syminfo: 8010Sstevel@tonic-gate return (ELF_T_SYMINFO); 8020Sstevel@tonic-gate case SHT_SUNW_verdef: 8030Sstevel@tonic-gate return (ELF_T_VDEF); 8040Sstevel@tonic-gate case SHT_SUNW_verneed: 8050Sstevel@tonic-gate return (ELF_T_VNEED); 8060Sstevel@tonic-gate case SHT_SUNW_versym: 8070Sstevel@tonic-gate return (ELF_T_HALF); 8080Sstevel@tonic-gate }; 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate /* 8110Sstevel@tonic-gate * Check for the sparc specific section types 8120Sstevel@tonic-gate * below. 8130Sstevel@tonic-gate */ 8140Sstevel@tonic-gate if (((ehdr->e_machine == EM_SPARC) || 8150Sstevel@tonic-gate (ehdr->e_machine == EM_SPARC32PLUS) || 8160Sstevel@tonic-gate (ehdr->e_machine == EM_SPARCV9)) && 8170Sstevel@tonic-gate (shtype == SHT_SPARC_GOTDATA)) 8180Sstevel@tonic-gate return (ELF_T_BYTE); 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate /* 8210Sstevel@tonic-gate * Check for the amd64 specific section types 8220Sstevel@tonic-gate * below. 8230Sstevel@tonic-gate */ 8240Sstevel@tonic-gate if ((ehdr->e_machine == EM_AMD64) && 8250Sstevel@tonic-gate (shtype == SHT_AMD64_UNWIND)) 8260Sstevel@tonic-gate return (ELF_T_BYTE); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate /* 8290Sstevel@tonic-gate * And the default is ELF_T_BYTE - but we should 8300Sstevel@tonic-gate * certainly have caught any sections we know about 8310Sstevel@tonic-gate * above. This is for unknown sections to libelf. 8320Sstevel@tonic-gate */ 8330Sstevel@tonic-gate return (ELF_T_BYTE); 8340Sstevel@tonic-gate} 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate 8373621Sab196087size_t 8383621Sab196087_elf64_entsz(Elf *elf, Elf64_Word shtype, unsigned ver) 8393621Sab196087{ 8403621Sab196087 Elf_Type ttype; 8413621Sab196087 8423621Sab196087 ttype = _elf64_mtype(elf, shtype, ver); 8433621Sab196087 return ((ttype == ELF_T_BYTE) ? 0 : fmsize[ver - 1][ttype].s_filesz); 8443621Sab196087} 8453621Sab196087 8463621Sab196087 8470Sstevel@tonic-gatestatic Elf_Data * 8480Sstevel@tonic-gatexlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) 8490Sstevel@tonic-gate /* !0 -> xlatetof */ 8500Sstevel@tonic-gate{ 8510Sstevel@tonic-gate size_t cnt, dsz, ssz; 8520Sstevel@tonic-gate unsigned type; 8530Sstevel@tonic-gate unsigned dver, sver; 8540Sstevel@tonic-gate void (*f)(); 8550Sstevel@tonic-gate unsigned _encode; 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate if (dst == 0 || src == 0) 8580Sstevel@tonic-gate return (0); 8590Sstevel@tonic-gate if (--encode >= (ELFDATANUM - 1)) { 8600Sstevel@tonic-gate _elf_seterr(EREQ_ENCODE, 0); 8610Sstevel@tonic-gate return (0); 8620Sstevel@tonic-gate } 8630Sstevel@tonic-gate if ((dver = dst->d_version - 1) >= EV_CURRENT || 8640Sstevel@tonic-gate (sver = src->d_version - 1) >= EV_CURRENT) { 8650Sstevel@tonic-gate _elf_seterr(EREQ_VER, 0); 8660Sstevel@tonic-gate return (0); 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate if ((type = src->d_type) >= ELF_T_NUM) { 8690Sstevel@tonic-gate _elf_seterr(EREQ_TYPE, 0); 8700Sstevel@tonic-gate return (0); 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate if (tof) { 8740Sstevel@tonic-gate dsz = fmsize[dver][type].s_filesz; 8750Sstevel@tonic-gate ssz = fmsize[sver][type].s_memsz; 8760Sstevel@tonic-gate f = x64[dver][sver][encode][type].x_tof; 8770Sstevel@tonic-gate } else { 8780Sstevel@tonic-gate dsz = fmsize[dver][type].s_memsz; 8790Sstevel@tonic-gate ssz = fmsize[sver][type].s_filesz; 8800Sstevel@tonic-gate f = x64[dver][sver][encode][type].x_tom; 8810Sstevel@tonic-gate } 8820Sstevel@tonic-gate cnt = src->d_size / ssz; 8830Sstevel@tonic-gate if (dst->d_size < dsz * cnt) { 8840Sstevel@tonic-gate _elf_seterr(EREQ_DSZ, 0); 8850Sstevel@tonic-gate return (0); 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate ELFACCESSDATA(_encode, _elf_encode) 8890Sstevel@tonic-gate if ((_encode == (encode + 1)) && (dsz == ssz)) { 8900Sstevel@tonic-gate /* 8910Sstevel@tonic-gate * ld(1) frequently produces empty sections (eg. .dynsym, 8920Sstevel@tonic-gate * .dynstr, .symtab, .strtab, etc) so that the initial 8930Sstevel@tonic-gate * output image can be created of the correct size. Later 8940Sstevel@tonic-gate * these sections are filled in with the associated data. 8950Sstevel@tonic-gate * So that we don't have to pre-allocate buffers for 8960Sstevel@tonic-gate * these segments, allow for the src destination to be 0. 8970Sstevel@tonic-gate */ 8980Sstevel@tonic-gate if (src->d_buf && src->d_buf != dst->d_buf) 8990Sstevel@tonic-gate (void) memcpy(dst->d_buf, src->d_buf, src->d_size); 9000Sstevel@tonic-gate dst->d_type = src->d_type; 9010Sstevel@tonic-gate dst->d_size = src->d_size; 9020Sstevel@tonic-gate return (dst); 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate if (cnt) 9050Sstevel@tonic-gate (*f)(dst->d_buf, src->d_buf, cnt); 9060Sstevel@tonic-gate dst->d_size = dsz * cnt; 9070Sstevel@tonic-gate dst->d_type = src->d_type; 9080Sstevel@tonic-gate return (dst); 9090Sstevel@tonic-gate} 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate 9120Sstevel@tonic-gateElf_Data * 9130Sstevel@tonic-gateelf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode) 9140Sstevel@tonic-gate{ 9150Sstevel@tonic-gate return (xlate(dst, src, encode, 1)); 9160Sstevel@tonic-gate} 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate 9190Sstevel@tonic-gateElf_Data * 9200Sstevel@tonic-gateelf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode) 9210Sstevel@tonic-gate{ 9220Sstevel@tonic-gate return (xlate(dst, src, encode, 0)); 9230Sstevel@tonic-gate} 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate/* 9270Sstevel@tonic-gate * xlate to file format 9280Sstevel@tonic-gate * 9290Sstevel@tonic-gate * ..._tof(name, data) -- macros 9300Sstevel@tonic-gate * 9310Sstevel@tonic-gate * Recall that the file format must be no larger than the 9320Sstevel@tonic-gate * memory format (equal versions). Use "forward" copy. 9330Sstevel@tonic-gate * All these routines require non-null, non-zero arguments. 9340Sstevel@tonic-gate */ 9350Sstevel@tonic-gate 9360Sstevel@tonic-gatedefine(addr_tof, ` 9370Sstevel@tonic-gatestatic void 9380Sstevel@tonic-gate$1(Byte *dst, Elf64_Addr *src, size_t cnt) 9390Sstevel@tonic-gate{ 9400Sstevel@tonic-gate Elf64_Addr *end = src + cnt; 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate do { 9430Sstevel@tonic-gate tofa(dst, *src, A_$2); 9440Sstevel@tonic-gate dst += A_sizeof; 9450Sstevel@tonic-gate } while (++src < end); 9460Sstevel@tonic-gate}') 9470Sstevel@tonic-gate 9480Sstevel@tonic-gateaddr_tof(addr_2L_tof,L) 9490Sstevel@tonic-gateaddr_tof(addr_2M_tof,M) 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate 9520Sstevel@tonic-gatestatic void 9530Sstevel@tonic-gatebyte_to(Byte *dst, Byte *src, size_t cnt) 9540Sstevel@tonic-gate{ 9550Sstevel@tonic-gate if (dst != src) 9560Sstevel@tonic-gate (void) memcpy(dst, src, cnt); 9570Sstevel@tonic-gate} 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate 9600Sstevel@tonic-gatedefine(dyn_11_tof, ` 9610Sstevel@tonic-gatestatic void 9620Sstevel@tonic-gate$1(Byte *dst, Elf64_Dyn *src, size_t cnt) 9630Sstevel@tonic-gate{ 9640Sstevel@tonic-gate Elf64_Dyn *end = src + cnt; 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate do { 9670Sstevel@tonic-gate tofx(dst, src->d_tag, D1_tag_$2); 9680Sstevel@tonic-gate tofx(dst, src->d_un.d_val, D1_val_$2); 9690Sstevel@tonic-gate dst += D1_sizeof; 9700Sstevel@tonic-gate } while (++src < end); 9710Sstevel@tonic-gate}') 9720Sstevel@tonic-gate 9730Sstevel@tonic-gatedyn_11_tof(dyn_2L11_tof,L) 9740Sstevel@tonic-gatedyn_11_tof(dyn_2M11_tof,M) 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate 9770Sstevel@tonic-gatedefine(ehdr_11_tof, ` 9780Sstevel@tonic-gatestatic void 9790Sstevel@tonic-gate$1(Byte *dst, Elf64_Ehdr *src, size_t cnt) 9800Sstevel@tonic-gate{ 9810Sstevel@tonic-gate Elf64_Ehdr *end = src + cnt; 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate do { 9840Sstevel@tonic-gate if (&dst[E1_ident] != src->e_ident) 9850Sstevel@tonic-gate (void) memcpy(&dst[E1_ident], src->e_ident, E1_Nident); 9860Sstevel@tonic-gate tofh(dst, src->e_type, E1_type_$2); 9870Sstevel@tonic-gate tofh(dst, src->e_machine, E1_machine_$2); 9880Sstevel@tonic-gate tofw(dst, src->e_version, E1_version_$2); 9890Sstevel@tonic-gate tofa(dst, src->e_entry, E1_entry_$2); 9900Sstevel@tonic-gate tofo(dst, src->e_phoff, E1_phoff_$2); 9910Sstevel@tonic-gate tofo(dst, src->e_shoff, E1_shoff_$2); 9920Sstevel@tonic-gate tofw(dst, src->e_flags, E1_flags_$2); 9930Sstevel@tonic-gate tofh(dst, src->e_ehsize, E1_ehsize_$2); 9940Sstevel@tonic-gate tofh(dst, src->e_phentsize, E1_phentsize_$2); 9950Sstevel@tonic-gate tofh(dst, src->e_phnum, E1_phnum_$2); 9960Sstevel@tonic-gate tofh(dst, src->e_shentsize, E1_shentsize_$2); 9970Sstevel@tonic-gate tofh(dst, src->e_shnum, E1_shnum_$2); 9980Sstevel@tonic-gate tofh(dst, src->e_shstrndx, E1_shstrndx_$2); 9990Sstevel@tonic-gate dst += E1_sizeof; 10000Sstevel@tonic-gate } while (++src < end); 10010Sstevel@tonic-gate}') 10020Sstevel@tonic-gate 10030Sstevel@tonic-gateehdr_11_tof(ehdr_2L11_tof,L) 10040Sstevel@tonic-gateehdr_11_tof(ehdr_2M11_tof,M) 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate 10070Sstevel@tonic-gatedefine(half_tof, ` 10080Sstevel@tonic-gatestatic void 10090Sstevel@tonic-gate$1(Byte *dst, Elf64_Half *src, size_t cnt) 10100Sstevel@tonic-gate{ 10110Sstevel@tonic-gate Elf64_Half *end = src + cnt; 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate do { 10140Sstevel@tonic-gate tofh(dst, *src, H_$2); 10150Sstevel@tonic-gate dst += H_sizeof; 10160Sstevel@tonic-gate } while (++src < end); 10170Sstevel@tonic-gate}') 10180Sstevel@tonic-gate 10190Sstevel@tonic-gatehalf_tof(half_2L_tof,L) 10200Sstevel@tonic-gatehalf_tof(half_2M_tof,M) 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate 10230Sstevel@tonic-gatedefine(move_11_tof, ` 10240Sstevel@tonic-gatestatic void 10250Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Move *src, size_t cnt) 10260Sstevel@tonic-gate{ 10270Sstevel@tonic-gate Elf64_Move *end = src + cnt; 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate do { 10300Sstevel@tonic-gate tofl(dst, src->m_value, M1_value_$2); 10310Sstevel@tonic-gate tofw(dst, src->m_info, M1_info_$2); 10320Sstevel@tonic-gate tofw(dst, src->m_poffset, M1_poffset_$2); 10330Sstevel@tonic-gate tofh(dst, src->m_repeat, M1_repeat_$2); 10340Sstevel@tonic-gate tofh(dst, src->m_stride, M1_stride_$2); 10350Sstevel@tonic-gate dst += M1_sizeof; 10360Sstevel@tonic-gate } while (++src < end); 10370Sstevel@tonic-gate}') 10380Sstevel@tonic-gate 10390Sstevel@tonic-gatemove_11_tof(move_2L11_tof,L) 10400Sstevel@tonic-gatemove_11_tof(move_2M11_tof,M) 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate 10430Sstevel@tonic-gatedefine(movep_11_tof, ` 10440Sstevel@tonic-gatestatic void 10450Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Move *src, size_t cnt) 10460Sstevel@tonic-gate{ 10470Sstevel@tonic-gate Elf64_Move *end = src + cnt; 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate do { 10500Sstevel@tonic-gate tofl(dst, src->m_value, MP1_value_$2); 10510Sstevel@tonic-gate tofw(dst, src->m_info, MP1_info_$2); 10520Sstevel@tonic-gate tofw(dst, src->m_poffset, MP1_poffset_$2); 10530Sstevel@tonic-gate tofh(dst, src->m_repeat, MP1_repeat_$2); 10540Sstevel@tonic-gate tofh(dst, src->m_stride, MP1_stride_$2); 10550Sstevel@tonic-gate dst += MP1_sizeof; 10560Sstevel@tonic-gate } while (++src < end); 10570Sstevel@tonic-gate}') 10580Sstevel@tonic-gate 10590Sstevel@tonic-gatemovep_11_tof(movep_2L11_tof,L) 10600Sstevel@tonic-gatemovep_11_tof(movep_2M11_tof,M) 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate 10630Sstevel@tonic-gatedefine(off_tof, ` 10640Sstevel@tonic-gatestatic void 10650Sstevel@tonic-gate$1(Byte *dst, Elf64_Off *src, size_t cnt) 10660Sstevel@tonic-gate{ 10670Sstevel@tonic-gate Elf64_Off *end = src + cnt; 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate do { 10700Sstevel@tonic-gate tofo(dst, *src, O_$2); 10710Sstevel@tonic-gate dst += O_sizeof; 10720Sstevel@tonic-gate } while (++src < end); 10730Sstevel@tonic-gate}') 10740Sstevel@tonic-gate 10750Sstevel@tonic-gateoff_tof(off_2L_tof,L) 10760Sstevel@tonic-gateoff_tof(off_2M_tof,M) 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate 10790Sstevel@tonic-gatedefine(note_11_tof, ` 10800Sstevel@tonic-gatestatic void 10810Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Nhdr *src, size_t cnt) 10820Sstevel@tonic-gate{ 10830Sstevel@tonic-gate /* LINTED */ 1084*11957SAli.Bahrami@Sun.COM Elf64_Nhdr *end = (Elf64_Nhdr *)((char *)src + cnt); 10850Sstevel@tonic-gate 1086*11957SAli.Bahrami@Sun.COM /* 1087*11957SAli.Bahrami@Sun.COM * Copy the note data to the source, translating the 1088*11957SAli.Bahrami@Sun.COM * length fields. Clip against the size of the actual buffer 1089*11957SAli.Bahrami@Sun.COM * to guard against corrupt note data. 1090*11957SAli.Bahrami@Sun.COM */ 10910Sstevel@tonic-gate do { 10920Sstevel@tonic-gate Elf64_Word descsz, namesz; 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate /* 10950Sstevel@tonic-gate * cache size of desc & name fields - while rounding 10960Sstevel@tonic-gate * up their size. 10970Sstevel@tonic-gate */ 10980Sstevel@tonic-gate namesz = S_ROUND(src->n_namesz, sizeof (Elf64_Word)); 10990Sstevel@tonic-gate descsz = src->n_descsz; 11000Sstevel@tonic-gate 11010Sstevel@tonic-gate /* 11020Sstevel@tonic-gate * Copy contents of Elf64_Nhdr 11030Sstevel@tonic-gate */ 1104*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_namesz) + sizeof(Elf64_Word) + 1105*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1106*11957SAli.Bahrami@Sun.COM break; 11070Sstevel@tonic-gate tofw(dst, src->n_namesz, N1_namesz_$2); 1108*11957SAli.Bahrami@Sun.COM 1109*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_descsz) + sizeof(Elf64_Word) + 1110*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1111*11957SAli.Bahrami@Sun.COM break; 11120Sstevel@tonic-gate tofw(dst, src->n_descsz, N1_descsz_$2); 1113*11957SAli.Bahrami@Sun.COM 1114*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_type) + sizeof(Elf64_Word) + 1115*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1116*11957SAli.Bahrami@Sun.COM break; 11170Sstevel@tonic-gate tofw(dst, src->n_type, N1_type_$2); 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate /* 11200Sstevel@tonic-gate * Copy contents of Name field 11210Sstevel@tonic-gate */ 11220Sstevel@tonic-gate dst += N1_sizeof; 11230Sstevel@tonic-gate src++; 1124*11957SAli.Bahrami@Sun.COM if ((namesz + (char *) src) > (char *) end) { 1125*11957SAli.Bahrami@Sun.COM namesz = (char *) end - (char *) src; 1126*11957SAli.Bahrami@Sun.COM if (namesz == 0) 1127*11957SAli.Bahrami@Sun.COM break; 1128*11957SAli.Bahrami@Sun.COM } 11290Sstevel@tonic-gate (void)memcpy(dst, src, namesz); 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate /* 11320Sstevel@tonic-gate * Copy contents of desc field 11330Sstevel@tonic-gate */ 11340Sstevel@tonic-gate dst += namesz; 11350Sstevel@tonic-gate src = (Elf64_Nhdr *)((uintptr_t)src + namesz); 1136*11957SAli.Bahrami@Sun.COM if ((descsz + (char *) src) > (char *) end) { 1137*11957SAli.Bahrami@Sun.COM descsz = (char *) end - (char *) src; 1138*11957SAli.Bahrami@Sun.COM if (descsz == 0) 1139*11957SAli.Bahrami@Sun.COM break; 1140*11957SAli.Bahrami@Sun.COM } 11410Sstevel@tonic-gate (void)memcpy(dst, src, descsz); 1142*11957SAli.Bahrami@Sun.COM 11430Sstevel@tonic-gate descsz = S_ROUND(descsz, sizeof (Elf64_Word)); 11440Sstevel@tonic-gate dst += descsz; 11450Sstevel@tonic-gate src = (Elf64_Nhdr *)((uintptr_t)src + descsz); 11460Sstevel@tonic-gate } while (src < end); 11470Sstevel@tonic-gate}') 11480Sstevel@tonic-gate 11490Sstevel@tonic-gatenote_11_tof(note_2L11_tof,L) 11500Sstevel@tonic-gatenote_11_tof(note_2M11_tof,M) 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate 11530Sstevel@tonic-gatedefine(phdr_11_tof, ` 11540Sstevel@tonic-gatestatic void 11550Sstevel@tonic-gate$1(Byte *dst, Elf64_Phdr *src, size_t cnt) 11560Sstevel@tonic-gate{ 11570Sstevel@tonic-gate Elf64_Phdr *end = src + cnt; 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate do { 11600Sstevel@tonic-gate tofw(dst, src->p_type, P1_type_$2); 11610Sstevel@tonic-gate tofw(dst, src->p_flags, P1_flags_$2); 11620Sstevel@tonic-gate tofo(dst, src->p_offset, P1_offset_$2); 11630Sstevel@tonic-gate tofa(dst, src->p_vaddr, P1_vaddr_$2); 11640Sstevel@tonic-gate tofa(dst, src->p_paddr, P1_paddr_$2); 11650Sstevel@tonic-gate tofx(dst, src->p_filesz, P1_filesz_$2); 11660Sstevel@tonic-gate tofx(dst, src->p_memsz, P1_memsz_$2); 11670Sstevel@tonic-gate tofx(dst, src->p_align, P1_align_$2); 11680Sstevel@tonic-gate dst += P1_sizeof; 11690Sstevel@tonic-gate } while (++src < end); 11700Sstevel@tonic-gate}') 11710Sstevel@tonic-gate 11720Sstevel@tonic-gatephdr_11_tof(phdr_2L11_tof,L) 11730Sstevel@tonic-gatephdr_11_tof(phdr_2M11_tof,M) 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate 11760Sstevel@tonic-gatedefine(rel_11_tof, ` 11770Sstevel@tonic-gatestatic void 11780Sstevel@tonic-gate$1(Byte *dst, Elf64_Rel *src, size_t cnt) 11790Sstevel@tonic-gate{ 11800Sstevel@tonic-gate Elf64_Rel *end = src + cnt; 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate do { 11830Sstevel@tonic-gate tofa(dst, src->r_offset, R1_offset_$2); 11840Sstevel@tonic-gate tofx(dst, src->r_info, R1_info_$2); 11850Sstevel@tonic-gate dst += R1_sizeof; 11860Sstevel@tonic-gate } while (++src < end); 11870Sstevel@tonic-gate}') 11880Sstevel@tonic-gate 11890Sstevel@tonic-gaterel_11_tof(rel_2L11_tof,L) 11900Sstevel@tonic-gaterel_11_tof(rel_2M11_tof,M) 11910Sstevel@tonic-gate 11920Sstevel@tonic-gate 11930Sstevel@tonic-gatedefine(rela_11_tof, ` 11940Sstevel@tonic-gatestatic void 11950Sstevel@tonic-gate$1(Byte *dst, Elf64_Rela *src, size_t cnt) 11960Sstevel@tonic-gate{ 11970Sstevel@tonic-gate Elf64_Rela *end = src + cnt; 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate do { 12000Sstevel@tonic-gate tofa(dst, src->r_offset, RA1_offset_$2); 12010Sstevel@tonic-gate tofx(dst, src->r_info, RA1_info_$2); 12020Sstevel@tonic-gate /*CONSTANTCONDITION*/ 12030Sstevel@tonic-gate if (~(Elf64_Xword)0 == -(Elf64_Sxword)1) { /* 2s comp */ 12040Sstevel@tonic-gate tofx(dst, src->r_addend, RA1_addend_$2); 12050Sstevel@tonic-gate } else { 12060Sstevel@tonic-gate Elf64_Xword w; 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate if (src->r_addend < 0) { 12090Sstevel@tonic-gate w = - src->r_addend; 12100Sstevel@tonic-gate w = ~w + 1; 12110Sstevel@tonic-gate } else 12120Sstevel@tonic-gate w = src->r_addend; 12130Sstevel@tonic-gate tofx(dst, w, RA1_addend_$2); 12140Sstevel@tonic-gate } 12150Sstevel@tonic-gate dst += RA1_sizeof; 12160Sstevel@tonic-gate } while (++src < end); 12170Sstevel@tonic-gate}') 12180Sstevel@tonic-gate 12190Sstevel@tonic-gaterela_11_tof(rela_2L11_tof,L) 12200Sstevel@tonic-gaterela_11_tof(rela_2M11_tof,M) 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate 12230Sstevel@tonic-gatedefine(shdr_11_tof, ` 12240Sstevel@tonic-gatestatic void 12250Sstevel@tonic-gate$1(Byte *dst, Elf64_Shdr *src, size_t cnt) 12260Sstevel@tonic-gate{ 12270Sstevel@tonic-gate Elf64_Shdr *end = src + cnt; 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate do { 12300Sstevel@tonic-gate tofw(dst, src->sh_name, SH1_name_$2); 12310Sstevel@tonic-gate tofw(dst, src->sh_type, SH1_type_$2); 12320Sstevel@tonic-gate tofx(dst, src->sh_flags, SH1_flags_$2); 12330Sstevel@tonic-gate tofa(dst, src->sh_addr, SH1_addr_$2); 12340Sstevel@tonic-gate tofo(dst, src->sh_offset, SH1_offset_$2); 12350Sstevel@tonic-gate tofx(dst, src->sh_size, SH1_size_$2); 12360Sstevel@tonic-gate tofw(dst, src->sh_link, SH1_link_$2); 12370Sstevel@tonic-gate tofw(dst, src->sh_info, SH1_info_$2); 12380Sstevel@tonic-gate tofx(dst, src->sh_addralign, SH1_addralign_$2); 12390Sstevel@tonic-gate tofx(dst, src->sh_entsize, SH1_entsize_$2); 12400Sstevel@tonic-gate dst += SH1_sizeof; 12410Sstevel@tonic-gate } while (++src < end); 12420Sstevel@tonic-gate}') 12430Sstevel@tonic-gate 12440Sstevel@tonic-gateshdr_11_tof(shdr_2L11_tof,L) 12450Sstevel@tonic-gateshdr_11_tof(shdr_2M11_tof,M) 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate 12480Sstevel@tonic-gatedefine(sword_tof, ` 12490Sstevel@tonic-gatestatic void 12500Sstevel@tonic-gate$1(Byte *dst, Elf64_Sword *src, size_t cnt) 12510Sstevel@tonic-gate{ 12520Sstevel@tonic-gate Elf64_Sword *end = src + cnt; 12530Sstevel@tonic-gate 12540Sstevel@tonic-gate do { 12550Sstevel@tonic-gate /*CONSTANTCONDITION*/ 12560Sstevel@tonic-gate if (~(Elf64_Word)0 == -(Elf64_Sword)1) { /* 2s comp */ 12570Sstevel@tonic-gate tofw(dst, *src, W_$2); 12580Sstevel@tonic-gate } else { 12590Sstevel@tonic-gate Elf64_Word w; 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate if (*src < 0) { 12620Sstevel@tonic-gate w = - *src; 12630Sstevel@tonic-gate w = ~w + 1; 12640Sstevel@tonic-gate } else 12650Sstevel@tonic-gate w = *src; 12660Sstevel@tonic-gate tofw(dst, w, W_$2); 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate dst += W_sizeof; 12690Sstevel@tonic-gate } while (++src < end); 12700Sstevel@tonic-gate}') 12710Sstevel@tonic-gate 12720Sstevel@tonic-gatesword_tof(sword_2L_tof,L) 12730Sstevel@tonic-gatesword_tof(sword_2M_tof,M) 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate 12760Sstevel@tonic-gatedefine(cap_11_tof, ` 12770Sstevel@tonic-gatestatic void 12780Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Cap *src, size_t cnt) 12790Sstevel@tonic-gate{ 12800Sstevel@tonic-gate Elf64_Cap *end = src + cnt; 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate do { 12830Sstevel@tonic-gate tofx(dst, src->c_tag, C1_tag_$2); 12840Sstevel@tonic-gate tofx(dst, src->c_un.c_val, C1_val_$2); 12850Sstevel@tonic-gate dst += C1_sizeof; 12860Sstevel@tonic-gate } while (++src < end); 12870Sstevel@tonic-gate}') 12880Sstevel@tonic-gate 12890Sstevel@tonic-gatecap_11_tof(cap_2L11_tof,L) 12900Sstevel@tonic-gatecap_11_tof(cap_2M11_tof,M) 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate 12930Sstevel@tonic-gatedefine(syminfo_11_tof, ` 12940Sstevel@tonic-gatestatic void 12950Sstevel@tonic-gate$1(unsigned char *dst, Elf64_Syminfo *src, size_t cnt) 12960Sstevel@tonic-gate{ 12970Sstevel@tonic-gate Elf64_Syminfo *end = src + cnt; 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate do { 13000Sstevel@tonic-gate tofh(dst, src->si_boundto, SI1_boundto_$2); 13010Sstevel@tonic-gate tofh(dst, src->si_flags, SI1_flags_$2); 13020Sstevel@tonic-gate dst += SI1_sizeof; 13030Sstevel@tonic-gate } while (++src < end); 13040Sstevel@tonic-gate}') 13050Sstevel@tonic-gate 13060Sstevel@tonic-gatesyminfo_11_tof(syminfo_2L11_tof,L) 13070Sstevel@tonic-gatesyminfo_11_tof(syminfo_2M11_tof,M) 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate 13100Sstevel@tonic-gatedefine(sym_11_tof, ` 13110Sstevel@tonic-gatestatic void 13120Sstevel@tonic-gate$1(Byte *dst, Elf64_Sym *src, size_t cnt) 13130Sstevel@tonic-gate{ 13140Sstevel@tonic-gate Elf64_Sym *end = src + cnt; 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate do { 13170Sstevel@tonic-gate tofw(dst, src->st_name, ST1_name_$2); 13180Sstevel@tonic-gate tofb(dst, src->st_info, ST1_info_$2); 13190Sstevel@tonic-gate tofb(dst, src->st_other, ST1_other_$2); 13200Sstevel@tonic-gate tofh(dst, src->st_shndx, ST1_shndx_$2); 13210Sstevel@tonic-gate tofa(dst, src->st_value, ST1_value_$2); 13220Sstevel@tonic-gate tofx(dst, src->st_size, ST1_size_$2); 13230Sstevel@tonic-gate dst += ST1_sizeof; 13240Sstevel@tonic-gate } while (++src < end); 13250Sstevel@tonic-gate}') 13260Sstevel@tonic-gate 13270Sstevel@tonic-gatesym_11_tof(sym_2L11_tof,L) 13280Sstevel@tonic-gatesym_11_tof(sym_2M11_tof,M) 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate 13310Sstevel@tonic-gatedefine(word_tof, ` 13320Sstevel@tonic-gatestatic void 13330Sstevel@tonic-gate$1(Byte *dst, Elf64_Word *src, size_t cnt) 13340Sstevel@tonic-gate{ 13350Sstevel@tonic-gate Elf64_Word *end = src + cnt; 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate do { 13380Sstevel@tonic-gate tofw(dst, *src, W_$2); 13390Sstevel@tonic-gate dst += W_sizeof; 13400Sstevel@tonic-gate } while (++src < end); 13410Sstevel@tonic-gate}') 13420Sstevel@tonic-gate 13430Sstevel@tonic-gateword_tof(word_2L_tof,L) 13440Sstevel@tonic-gateword_tof(word_2M_tof,M) 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate 13470Sstevel@tonic-gatedefine(verdef_11_tof, ` 13480Sstevel@tonic-gatestatic void 13490Sstevel@tonic-gate$1(Byte *dst, Elf64_Verdef *src, size_t cnt) 13500Sstevel@tonic-gate{ 13510Sstevel@tonic-gate /* LINTED */ 13520Sstevel@tonic-gate Elf64_Verdef *end = (Elf64_Verdef *)((Byte *)src + cnt); 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate do { 13550Sstevel@tonic-gate Elf64_Verdef *next_verdef; 13560Sstevel@tonic-gate Elf64_Verdaux *vaux; 13570Sstevel@tonic-gate Elf64_Half i; 13580Sstevel@tonic-gate Byte *vaux_dst; 13590Sstevel@tonic-gate Byte *dst_next; 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate /* LINTED */ 13620Sstevel@tonic-gate next_verdef = (Elf64_Verdef *)(src->vd_next ? 13630Sstevel@tonic-gate (Byte *)src + src->vd_next : (Byte *)end); 13640Sstevel@tonic-gate dst_next = dst + src->vd_next; 13650Sstevel@tonic-gate 13660Sstevel@tonic-gate /* LINTED */ 13670Sstevel@tonic-gate vaux = (Elf64_Verdaux *)((Byte *)src + src->vd_aux); 13680Sstevel@tonic-gate vaux_dst = dst + src->vd_aux; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate /* 13710Sstevel@tonic-gate * Convert auxilary structures 13720Sstevel@tonic-gate */ 13730Sstevel@tonic-gate for (i = 0; i < src->vd_cnt; i++) { 13740Sstevel@tonic-gate Elf64_Verdaux *vaux_next; 13750Sstevel@tonic-gate Byte *vaux_dst_next; 13760Sstevel@tonic-gate 13770Sstevel@tonic-gate /* 13780Sstevel@tonic-gate * because our source and destination can be 13790Sstevel@tonic-gate * the same place we need to figure out the next 13800Sstevel@tonic-gate * location now. 13810Sstevel@tonic-gate */ 13820Sstevel@tonic-gate /* LINTED */ 13830Sstevel@tonic-gate vaux_next = (Elf64_Verdaux *)((Byte *)vaux + 13840Sstevel@tonic-gate vaux->vda_next); 13850Sstevel@tonic-gate vaux_dst_next = vaux_dst + vaux->vda_next; 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate tofw(vaux_dst, vaux->vda_name, VDA1_name_$2); 13880Sstevel@tonic-gate tofw(vaux_dst, vaux->vda_next, VDA1_next_$2); 13890Sstevel@tonic-gate vaux_dst = vaux_dst_next; 13900Sstevel@tonic-gate vaux = vaux_next; 13910Sstevel@tonic-gate } 13920Sstevel@tonic-gate 13930Sstevel@tonic-gate /* 13940Sstevel@tonic-gate * Convert Elf64_Verdef structure. 13950Sstevel@tonic-gate */ 13960Sstevel@tonic-gate tofh(dst, src->vd_version, VD1_version_$2); 13970Sstevel@tonic-gate tofh(dst, src->vd_flags, VD1_flags_$2); 13980Sstevel@tonic-gate tofh(dst, src->vd_ndx, VD1_ndx_$2); 13990Sstevel@tonic-gate tofh(dst, src->vd_cnt, VD1_cnt_$2); 14000Sstevel@tonic-gate tofw(dst, src->vd_hash, VD1_hash_$2); 14010Sstevel@tonic-gate tofw(dst, src->vd_aux, VD1_aux_$2); 14020Sstevel@tonic-gate tofw(dst, src->vd_next, VD1_next_$2); 14030Sstevel@tonic-gate src = next_verdef; 14040Sstevel@tonic-gate dst = dst_next; 14050Sstevel@tonic-gate } while (src < end); 14060Sstevel@tonic-gate}') 14070Sstevel@tonic-gate 14080Sstevel@tonic-gateverdef_11_tof(verdef_2L11_tof, L) 14090Sstevel@tonic-gateverdef_11_tof(verdef_2M11_tof, M) 14100Sstevel@tonic-gate 14110Sstevel@tonic-gatedefine(verneed_11_tof, ` 14120Sstevel@tonic-gatestatic void 14130Sstevel@tonic-gate$1(Byte *dst, Elf64_Verneed *src, size_t cnt) 14140Sstevel@tonic-gate{ 14150Sstevel@tonic-gate /* LINTED */ 14160Sstevel@tonic-gate Elf64_Verneed *end = (Elf64_Verneed *)((char *)src + cnt); 14170Sstevel@tonic-gate 14180Sstevel@tonic-gate do { 14190Sstevel@tonic-gate Elf64_Verneed * next_verneed; 14200Sstevel@tonic-gate Elf64_Vernaux * vaux; 14210Sstevel@tonic-gate Elf64_Half i; 14220Sstevel@tonic-gate Byte * vaux_dst; 14230Sstevel@tonic-gate Byte * dst_next; 14240Sstevel@tonic-gate 14250Sstevel@tonic-gate /* LINTED */ 14260Sstevel@tonic-gate next_verneed = (Elf64_Verneed *)(src->vn_next ? 14270Sstevel@tonic-gate (Byte *)src + src->vn_next : (Byte *)end); 14280Sstevel@tonic-gate dst_next = dst + src->vn_next; 14290Sstevel@tonic-gate 14300Sstevel@tonic-gate /* LINTED */ 14310Sstevel@tonic-gate vaux = (Elf64_Vernaux *)((Byte *)src + src->vn_aux); 14320Sstevel@tonic-gate vaux_dst = dst + src->vn_aux; 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate /* 14350Sstevel@tonic-gate * Convert auxilary structures first 14360Sstevel@tonic-gate */ 14370Sstevel@tonic-gate for (i = 0; i < src->vn_cnt; i++) { 14380Sstevel@tonic-gate Elf64_Vernaux *vaux_next; 14390Sstevel@tonic-gate Byte *vaux_dst_next; 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate /* 14420Sstevel@tonic-gate * because our source and destination can be 14430Sstevel@tonic-gate * the same place we need to figure out the 14440Sstevel@tonic-gate * next location now. 14450Sstevel@tonic-gate */ 14460Sstevel@tonic-gate /* LINTED */ 14470Sstevel@tonic-gate vaux_next = (Elf64_Vernaux *)((Byte *)vaux + 14480Sstevel@tonic-gate vaux->vna_next); 14490Sstevel@tonic-gate vaux_dst_next = vaux_dst + vaux->vna_next; 14500Sstevel@tonic-gate 14510Sstevel@tonic-gate tofw(vaux_dst, vaux->vna_hash, VNA1_hash_$2); 14520Sstevel@tonic-gate tofh(vaux_dst, vaux->vna_flags, VNA1_flags_$2); 14530Sstevel@tonic-gate tofh(vaux_dst, vaux->vna_other, VNA1_other_$2); 14540Sstevel@tonic-gate tofw(vaux_dst, vaux->vna_name, VNA1_name_$2); 14550Sstevel@tonic-gate tofw(vaux_dst, vaux->vna_next, VNA1_next_$2); 14560Sstevel@tonic-gate vaux_dst = vaux_dst_next; 14570Sstevel@tonic-gate vaux = vaux_next; 14580Sstevel@tonic-gate } 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate /* 14610Sstevel@tonic-gate * Convert Elf64_Verneed structure. 14620Sstevel@tonic-gate */ 14630Sstevel@tonic-gate tofh(dst, src->vn_version, VN1_version_$2); 14640Sstevel@tonic-gate tofh(dst, src->vn_cnt, VN1_cnt_$2); 14650Sstevel@tonic-gate tofw(dst, src->vn_file, VN1_file_$2); 14660Sstevel@tonic-gate tofw(dst, src->vn_aux, VN1_aux_$2); 14670Sstevel@tonic-gate tofw(dst, src->vn_next, VN1_next_$2); 14680Sstevel@tonic-gate src = next_verneed; 14690Sstevel@tonic-gate dst = dst_next; 14700Sstevel@tonic-gate } while (src < end); 14710Sstevel@tonic-gate}') 14720Sstevel@tonic-gate 14730Sstevel@tonic-gateverneed_11_tof(verneed_2L11_tof, L) 14740Sstevel@tonic-gateverneed_11_tof(verneed_2M11_tof, M) 14750Sstevel@tonic-gate 14760Sstevel@tonic-gate 14770Sstevel@tonic-gatedefine(sxword_tof, ` 14780Sstevel@tonic-gatestatic void 14790Sstevel@tonic-gate$1(Byte *dst, Elf64_Sxword *src, size_t cnt) 14800Sstevel@tonic-gate{ 14810Sstevel@tonic-gate Elf64_Sxword *end = src + cnt; 14820Sstevel@tonic-gate 14830Sstevel@tonic-gate do { 14840Sstevel@tonic-gate /*CONSTANTCONDITION*/ 14850Sstevel@tonic-gate if (~(Elf64_Xword)0 == -(Elf64_Sxword)1) { /* 2s comp */ 14860Sstevel@tonic-gate tofx(dst, *src, X_$2); 14870Sstevel@tonic-gate } 14880Sstevel@tonic-gate else { /* unknown */ 14890Sstevel@tonic-gate Elf64_Xword w; 14900Sstevel@tonic-gate 14910Sstevel@tonic-gate if (*src < 0) { 14920Sstevel@tonic-gate w = - *src; 14930Sstevel@tonic-gate w = ~w + 1; 14940Sstevel@tonic-gate } else 14950Sstevel@tonic-gate w = *src; 14960Sstevel@tonic-gate tofx(dst, w, X_$2); 14970Sstevel@tonic-gate } 14980Sstevel@tonic-gate dst += X_sizeof; 14990Sstevel@tonic-gate } while (++src < end); 15000Sstevel@tonic-gate}') 15010Sstevel@tonic-gate 15020Sstevel@tonic-gatesxword_tof(sxword_2L_tof,L) 15030Sstevel@tonic-gatesxword_tof(sxword_2M_tof,M) 15040Sstevel@tonic-gate 15050Sstevel@tonic-gate 15060Sstevel@tonic-gatedefine(xword_tof, ` 15070Sstevel@tonic-gatestatic void 15080Sstevel@tonic-gate$1(Byte *dst, Elf64_Xword *src, size_t cnt) 15090Sstevel@tonic-gate{ 15100Sstevel@tonic-gate Elf64_Xword *end = src + cnt; 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate do { 15130Sstevel@tonic-gate tofx(dst, *src, X_$2); 15140Sstevel@tonic-gate dst += X_sizeof; 15150Sstevel@tonic-gate } while (++src < end); 15160Sstevel@tonic-gate}') 15170Sstevel@tonic-gate 15180Sstevel@tonic-gatexword_tof(xword_2L_tof,L) 15190Sstevel@tonic-gatexword_tof(xword_2M_tof,M) 15200Sstevel@tonic-gate 15210Sstevel@tonic-gate 15220Sstevel@tonic-gate/* 15230Sstevel@tonic-gate * xlate to memory format 15240Sstevel@tonic-gate * 15250Sstevel@tonic-gate * ..._tom(name, data) -- macros 15260Sstevel@tonic-gate * 15270Sstevel@tonic-gate * Recall that the memory format may be larger than the 15280Sstevel@tonic-gate * file format (equal versions). Use "backward" copy. 15290Sstevel@tonic-gate * All these routines require non-null, non-zero arguments. 15300Sstevel@tonic-gate */ 15310Sstevel@tonic-gate 15320Sstevel@tonic-gate 15330Sstevel@tonic-gatedefine(addr_tom, ` 15340Sstevel@tonic-gatestatic void 15350Sstevel@tonic-gate$1(Elf64_Addr *dst, Byte *src, size_t cnt) 15360Sstevel@tonic-gate{ 15370Sstevel@tonic-gate Elf64_Addr *end = dst; 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate dst += cnt; 15400Sstevel@tonic-gate src += cnt * A_sizeof; 15410Sstevel@tonic-gate while (dst-- > end) { 15420Sstevel@tonic-gate src -= A_sizeof; 15430Sstevel@tonic-gate *dst = toma(src, A_$2); 15440Sstevel@tonic-gate } 15450Sstevel@tonic-gate}') 15460Sstevel@tonic-gate 15470Sstevel@tonic-gateaddr_tom(addr_2L_tom,L) 15480Sstevel@tonic-gateaddr_tom(addr_2M_tom,M) 15490Sstevel@tonic-gate 15500Sstevel@tonic-gate 15510Sstevel@tonic-gatedefine(dyn_11_tom, ` 15520Sstevel@tonic-gatestatic void 15530Sstevel@tonic-gate$1(Elf64_Dyn *dst, Byte *src, size_t cnt) 15540Sstevel@tonic-gate{ 15550Sstevel@tonic-gate Elf64_Dyn *end = dst + cnt; 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate do { 15580Sstevel@tonic-gate dst->d_tag = tomx(src, D1_tag_$2); 15590Sstevel@tonic-gate dst->d_un.d_val = tomx(src, D1_val_$2); 15600Sstevel@tonic-gate src += D1_sizeof; 15610Sstevel@tonic-gate } while (++dst < end); 15620Sstevel@tonic-gate}') 15630Sstevel@tonic-gate 15640Sstevel@tonic-gatedyn_11_tom(dyn_2L11_tom,L) 15650Sstevel@tonic-gatedyn_11_tom(dyn_2M11_tom,M) 15660Sstevel@tonic-gate 15670Sstevel@tonic-gate 15680Sstevel@tonic-gatedefine(ehdr_11_tom, ` 15690Sstevel@tonic-gatestatic void 15700Sstevel@tonic-gate$1(Elf64_Ehdr *dst, Byte *src, size_t cnt) 15710Sstevel@tonic-gate{ 15720Sstevel@tonic-gate Elf64_Ehdr *end = dst; 15730Sstevel@tonic-gate 15740Sstevel@tonic-gate dst += cnt; 15750Sstevel@tonic-gate src += cnt * E1_sizeof; 15760Sstevel@tonic-gate while (dst-- > end) { 15770Sstevel@tonic-gate src -= E1_sizeof; 15780Sstevel@tonic-gate dst->e_shstrndx = tomh(src, E1_shstrndx_$2); 15790Sstevel@tonic-gate dst->e_shnum = tomh(src, E1_shnum_$2); 15800Sstevel@tonic-gate dst->e_shentsize = tomh(src, E1_shentsize_$2); 15810Sstevel@tonic-gate dst->e_phnum = tomh(src, E1_phnum_$2); 15820Sstevel@tonic-gate dst->e_phentsize = tomh(src, E1_phentsize_$2); 15830Sstevel@tonic-gate dst->e_ehsize = tomh(src, E1_ehsize_$2); 15840Sstevel@tonic-gate dst->e_flags = tomw(src, E1_flags_$2); 15850Sstevel@tonic-gate dst->e_shoff = tomo(src, E1_shoff_$2); 15860Sstevel@tonic-gate dst->e_phoff = tomo(src, E1_phoff_$2); 15870Sstevel@tonic-gate dst->e_entry = toma(src, E1_entry_$2); 15880Sstevel@tonic-gate dst->e_version = tomw(src, E1_version_$2); 15890Sstevel@tonic-gate dst->e_machine = tomh(src, E1_machine_$2); 15900Sstevel@tonic-gate dst->e_type = tomh(src, E1_type_$2); 15910Sstevel@tonic-gate if (dst->e_ident != &src[E1_ident]) 15920Sstevel@tonic-gate (void) memcpy(dst->e_ident, &src[E1_ident], E1_Nident); 15930Sstevel@tonic-gate } 15940Sstevel@tonic-gate}') 15950Sstevel@tonic-gate 15960Sstevel@tonic-gateehdr_11_tom(ehdr_2L11_tom,L) 15970Sstevel@tonic-gateehdr_11_tom(ehdr_2M11_tom,M) 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate 16000Sstevel@tonic-gatedefine(half_tom, ` 16010Sstevel@tonic-gatestatic void 16020Sstevel@tonic-gate$1(Elf64_Half *dst, Byte *src, size_t cnt) 16030Sstevel@tonic-gate{ 16040Sstevel@tonic-gate Elf64_Half *end = dst; 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate dst += cnt; 16070Sstevel@tonic-gate src += cnt * H_sizeof; 16080Sstevel@tonic-gate while (dst-- > end) { 16090Sstevel@tonic-gate src -= H_sizeof; 16100Sstevel@tonic-gate *dst = tomh(src, H_$2); 16110Sstevel@tonic-gate } 16120Sstevel@tonic-gate}') 16130Sstevel@tonic-gate 16140Sstevel@tonic-gatehalf_tom(half_2L_tom,L) 16150Sstevel@tonic-gatehalf_tom(half_2M_tom,M) 16160Sstevel@tonic-gate 16170Sstevel@tonic-gate 16180Sstevel@tonic-gatedefine(move_11_tom, ` 16190Sstevel@tonic-gatestatic void 16200Sstevel@tonic-gate$1(Elf64_Move *dst, unsigned char *src, size_t cnt) 16210Sstevel@tonic-gate{ 16220Sstevel@tonic-gate Elf64_Move *end = dst + cnt; 16230Sstevel@tonic-gate 16240Sstevel@tonic-gate do { 16250Sstevel@tonic-gate dst->m_value = toml(src, M1_value_$2); 16260Sstevel@tonic-gate dst->m_info = tomw(src, M1_info_$2); 16270Sstevel@tonic-gate dst->m_poffset = tomw(src, M1_poffset_$2); 16280Sstevel@tonic-gate dst->m_repeat = tomh(src, M1_repeat_$2); 16290Sstevel@tonic-gate dst->m_stride = tomh(src, M1_stride_$2); 16300Sstevel@tonic-gate src += M1_sizeof; 16310Sstevel@tonic-gate } while (++dst < end); 16320Sstevel@tonic-gate}') 16330Sstevel@tonic-gate 16340Sstevel@tonic-gatemove_11_tom(move_2L11_tom,L) 16350Sstevel@tonic-gatemove_11_tom(move_2M11_tom,M) 16360Sstevel@tonic-gate 16370Sstevel@tonic-gate 16380Sstevel@tonic-gatedefine(movep_11_tom, ` 16390Sstevel@tonic-gatestatic void 16400Sstevel@tonic-gate$1(Elf64_Move *dst, unsigned char *src, size_t cnt) 16410Sstevel@tonic-gate{ 16420Sstevel@tonic-gate Elf64_Move *end = dst + cnt; 16430Sstevel@tonic-gate 16440Sstevel@tonic-gate do 16450Sstevel@tonic-gate { 16460Sstevel@tonic-gate dst->m_value = toml(src, MP1_value_$2); 16470Sstevel@tonic-gate dst->m_info = tomw(src, MP1_info_$2); 16480Sstevel@tonic-gate dst->m_poffset = tomw(src, MP1_poffset_$2); 16490Sstevel@tonic-gate dst->m_repeat = tomh(src, MP1_repeat_$2); 16500Sstevel@tonic-gate dst->m_stride = tomh(src, MP1_stride_$2); 16510Sstevel@tonic-gate src += MP1_sizeof; 16520Sstevel@tonic-gate } while (++dst < end); 16530Sstevel@tonic-gate}') 16540Sstevel@tonic-gate 16550Sstevel@tonic-gatemovep_11_tom(movep_2L11_tom,L) 16560Sstevel@tonic-gatemovep_11_tom(movep_2M11_tom,M) 16570Sstevel@tonic-gate 16580Sstevel@tonic-gate 16590Sstevel@tonic-gatedefine(note_11_tom, ` 16600Sstevel@tonic-gatestatic void 16610Sstevel@tonic-gate$1(Elf64_Nhdr *dst, unsigned char *src, size_t cnt) 16620Sstevel@tonic-gate{ 16630Sstevel@tonic-gate /* LINTED */ 16640Sstevel@tonic-gate Elf64_Nhdr *end = (Elf64_Nhdr *)((char *)dst + cnt); 16650Sstevel@tonic-gate 1666*11957SAli.Bahrami@Sun.COM /* 1667*11957SAli.Bahrami@Sun.COM * Copy the note data to the destination, translating the 1668*11957SAli.Bahrami@Sun.COM * length fields. Clip against the size of the actual buffer 1669*11957SAli.Bahrami@Sun.COM * to guard against corrupt note data. 1670*11957SAli.Bahrami@Sun.COM */ 1671*11957SAli.Bahrami@Sun.COM while (dst < end) { 1672*11957SAli.Bahrami@Sun.COM Elf64_Nhdr *nhdr; 1673*11957SAli.Bahrami@Sun.COM unsigned char *namestr; 1674*11957SAli.Bahrami@Sun.COM void *desc; 16750Sstevel@tonic-gate Elf64_Word field_sz; 16760Sstevel@tonic-gate 1677*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_namesz) + sizeof(Elf64_Word) + 1678*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1679*11957SAli.Bahrami@Sun.COM break; 16800Sstevel@tonic-gate dst->n_namesz = tomw(src, N1_namesz_$2); 1681*11957SAli.Bahrami@Sun.COM 1682*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_descsz) + sizeof(Elf64_Word) + 1683*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1684*11957SAli.Bahrami@Sun.COM break; 16850Sstevel@tonic-gate dst->n_descsz = tomw(src, N1_descsz_$2); 1686*11957SAli.Bahrami@Sun.COM 1687*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf64_Nhdr, n_type) + sizeof(Elf64_Word) + 1688*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1689*11957SAli.Bahrami@Sun.COM break; 16900Sstevel@tonic-gate dst->n_type = tomw(src, N1_type_$2); 16910Sstevel@tonic-gate nhdr = dst; 1692*11957SAli.Bahrami@Sun.COM 16931618Srie /* LINTED */ 16940Sstevel@tonic-gate dst = (Elf64_Nhdr *)((char *)dst + sizeof (Elf64_Nhdr)); 16950Sstevel@tonic-gate namestr = src + N1_sizeof; 16960Sstevel@tonic-gate field_sz = S_ROUND(nhdr->n_namesz, sizeof (Elf64_Word)); 1697*11957SAli.Bahrami@Sun.COM if ((field_sz + (char *) dst) > (char *) end) { 1698*11957SAli.Bahrami@Sun.COM field_sz = (char *) end - (char *) dst; 1699*11957SAli.Bahrami@Sun.COM if (field_sz == 0) 1700*11957SAli.Bahrami@Sun.COM break; 1701*11957SAli.Bahrami@Sun.COM } 17020Sstevel@tonic-gate (void)memcpy((void *)dst, namestr, field_sz); 17030Sstevel@tonic-gate desc = namestr + field_sz; 1704*11957SAli.Bahrami@Sun.COM 17051618Srie /* LINTED */ 17060Sstevel@tonic-gate dst = (Elf64_Nhdr *)((char *)dst + field_sz); 17070Sstevel@tonic-gate field_sz = nhdr->n_descsz; 1708*11957SAli.Bahrami@Sun.COM if ((field_sz + (char *) dst) > (char *) end) { 1709*11957SAli.Bahrami@Sun.COM field_sz = (char *) end - (char *) dst; 1710*11957SAli.Bahrami@Sun.COM if (field_sz == 0) 1711*11957SAli.Bahrami@Sun.COM break; 1712*11957SAli.Bahrami@Sun.COM } 17130Sstevel@tonic-gate (void)memcpy(dst, desc, field_sz); 17140Sstevel@tonic-gate field_sz = S_ROUND(field_sz, sizeof (Elf64_Word)); 1715*11957SAli.Bahrami@Sun.COM 17161618Srie /* LINTED */ 17170Sstevel@tonic-gate dst = (Elf64_Nhdr *)((char *)dst + field_sz); 17180Sstevel@tonic-gate src = (unsigned char *)desc + field_sz; 17190Sstevel@tonic-gate } 17200Sstevel@tonic-gate}') 17210Sstevel@tonic-gate 17220Sstevel@tonic-gatenote_11_tom(note_2L11_tom,L) 17230Sstevel@tonic-gatenote_11_tom(note_2M11_tom,M) 17240Sstevel@tonic-gate 17250Sstevel@tonic-gatedefine(off_tom, ` 17260Sstevel@tonic-gatestatic void 17270Sstevel@tonic-gate$1(Elf64_Off *dst, Byte *src, size_t cnt) 17280Sstevel@tonic-gate{ 17290Sstevel@tonic-gate Elf64_Off *end = dst; 17300Sstevel@tonic-gate 17310Sstevel@tonic-gate dst += cnt; 17320Sstevel@tonic-gate src += cnt * O_sizeof; 17330Sstevel@tonic-gate while (dst-- > end) { 17340Sstevel@tonic-gate src -= O_sizeof; 17350Sstevel@tonic-gate *dst = tomo(src, O_$2); 17360Sstevel@tonic-gate } 17370Sstevel@tonic-gate}') 17380Sstevel@tonic-gate 17390Sstevel@tonic-gateoff_tom(off_2L_tom,L) 17400Sstevel@tonic-gateoff_tom(off_2M_tom,M) 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate 17430Sstevel@tonic-gatedefine(phdr_11_tom, ` 17440Sstevel@tonic-gatestatic void 17450Sstevel@tonic-gate$1(Elf64_Phdr *dst, Byte *src, size_t cnt) 17460Sstevel@tonic-gate{ 17470Sstevel@tonic-gate Elf64_Phdr *end = dst; 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate dst += cnt; 17500Sstevel@tonic-gate src += cnt * P1_sizeof; 17510Sstevel@tonic-gate while (dst-- > end) { 17520Sstevel@tonic-gate src -= P1_sizeof; 17530Sstevel@tonic-gate dst->p_align = tomx(src, P1_align_$2); 17540Sstevel@tonic-gate dst->p_memsz = tomx(src, P1_memsz_$2); 17550Sstevel@tonic-gate dst->p_filesz = tomx(src, P1_filesz_$2); 17560Sstevel@tonic-gate dst->p_paddr = toma(src, P1_paddr_$2); 17570Sstevel@tonic-gate dst->p_vaddr = toma(src, P1_vaddr_$2); 17580Sstevel@tonic-gate dst->p_offset = tomo(src, P1_offset_$2); 17590Sstevel@tonic-gate dst->p_flags = tomw(src, P1_flags_$2); 17600Sstevel@tonic-gate dst->p_type = tomw(src, P1_type_$2); 17610Sstevel@tonic-gate } 17620Sstevel@tonic-gate}') 17630Sstevel@tonic-gate 17640Sstevel@tonic-gatephdr_11_tom(phdr_2L11_tom,L) 17650Sstevel@tonic-gatephdr_11_tom(phdr_2M11_tom,M) 17660Sstevel@tonic-gate 17670Sstevel@tonic-gate 17680Sstevel@tonic-gatedefine(rel_11_tom, ` 17690Sstevel@tonic-gatestatic void 17700Sstevel@tonic-gate$1(Elf64_Rel *dst, Byte *src, size_t cnt) 17710Sstevel@tonic-gate{ 17720Sstevel@tonic-gate Elf64_Rel *end = dst; 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate dst += cnt; 17750Sstevel@tonic-gate src += cnt * R1_sizeof; 17760Sstevel@tonic-gate while (dst-- > end) { 17770Sstevel@tonic-gate src -= R1_sizeof; 17780Sstevel@tonic-gate dst->r_info = tomx(src, R1_info_$2); 17790Sstevel@tonic-gate dst->r_offset = toma(src, R1_offset_$2); 17800Sstevel@tonic-gate } 17810Sstevel@tonic-gate}') 17820Sstevel@tonic-gate 17830Sstevel@tonic-gaterel_11_tom(rel_2L11_tom,L) 17840Sstevel@tonic-gaterel_11_tom(rel_2M11_tom,M) 17850Sstevel@tonic-gate 17860Sstevel@tonic-gate 17870Sstevel@tonic-gatedefine(rela_11_tom, ` 17880Sstevel@tonic-gatestatic void 17890Sstevel@tonic-gate$1(Elf64_Rela *dst, Byte *src, size_t cnt) 17900Sstevel@tonic-gate{ 17910Sstevel@tonic-gate Elf64_Rela *end = dst; 17920Sstevel@tonic-gate 17930Sstevel@tonic-gate dst += cnt; 17940Sstevel@tonic-gate src += cnt * RA1_sizeof; 17950Sstevel@tonic-gate while (dst-- > end) { 17960Sstevel@tonic-gate src -= RA1_sizeof; 17970Sstevel@tonic-gate /*CONSTANTCONDITION*/ 17980Sstevel@tonic-gate if (~(Elf64_Xword)0 == -(Elf64_Sxword)1 && /* 2s comp */ 17990Sstevel@tonic-gate ~(~(Elf64_Xword)0 >> 1) == HI64) { 18000Sstevel@tonic-gate dst->r_addend = tomx(src, RA1_addend_$2); 18010Sstevel@tonic-gate } else { 18020Sstevel@tonic-gate union { 18030Sstevel@tonic-gate Elf64_Xword w; 18040Sstevel@tonic-gate Elf64_Sxword sw; 18050Sstevel@tonic-gate } u; 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate if ((u.w = tomx(src, RA1_addend_$2)) & HI64) { 18080Sstevel@tonic-gate /* LINTED */ 18090Sstevel@tonic-gate u.w |= ~(Elf64_Xword)LO63; 18100Sstevel@tonic-gate u.w = ~u.w + 1; 18110Sstevel@tonic-gate u.sw = -u.w; 18120Sstevel@tonic-gate } 18130Sstevel@tonic-gate dst->r_addend = u.sw; 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate dst->r_info = tomx(src, RA1_info_$2); 18160Sstevel@tonic-gate dst->r_offset = toma(src, RA1_offset_$2); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate}') 18190Sstevel@tonic-gate 18200Sstevel@tonic-gaterela_11_tom(rela_2L11_tom,L) 18210Sstevel@tonic-gaterela_11_tom(rela_2M11_tom,M) 18220Sstevel@tonic-gate 18230Sstevel@tonic-gate 18240Sstevel@tonic-gatedefine(shdr_11_tom, ` 18250Sstevel@tonic-gatestatic void 18260Sstevel@tonic-gate$1(Elf64_Shdr *dst, Byte *src, size_t cnt) 18270Sstevel@tonic-gate{ 18280Sstevel@tonic-gate Elf64_Shdr *end = dst; 18290Sstevel@tonic-gate 18300Sstevel@tonic-gate dst += cnt; 18310Sstevel@tonic-gate src += cnt * SH1_sizeof; 18320Sstevel@tonic-gate while (dst-- > end) { 18330Sstevel@tonic-gate src -= SH1_sizeof; 18340Sstevel@tonic-gate dst->sh_entsize = tomx(src, SH1_entsize_$2); 18350Sstevel@tonic-gate dst->sh_addralign = tomx(src, SH1_addralign_$2); 18360Sstevel@tonic-gate dst->sh_info = tomw(src, SH1_info_$2); 18370Sstevel@tonic-gate dst->sh_link = tomw(src, SH1_link_$2); 18380Sstevel@tonic-gate dst->sh_size = tomx(src, SH1_size_$2); 18390Sstevel@tonic-gate dst->sh_offset = tomo(src, SH1_offset_$2); 18400Sstevel@tonic-gate dst->sh_addr = toma(src, SH1_addr_$2); 18410Sstevel@tonic-gate dst->sh_flags = tomx(src, SH1_flags_$2); 18420Sstevel@tonic-gate dst->sh_type = tomw(src, SH1_type_$2); 18430Sstevel@tonic-gate dst->sh_name = tomw(src, SH1_name_$2); 18440Sstevel@tonic-gate } 18450Sstevel@tonic-gate}') 18460Sstevel@tonic-gate 18470Sstevel@tonic-gateshdr_11_tom(shdr_2L11_tom,L) 18480Sstevel@tonic-gateshdr_11_tom(shdr_2M11_tom,M) 18490Sstevel@tonic-gate 18500Sstevel@tonic-gate 18510Sstevel@tonic-gatedefine(sword_tom, ` 18520Sstevel@tonic-gatestatic void 18530Sstevel@tonic-gate$1(Elf64_Sword *dst, Byte *src, size_t cnt) 18540Sstevel@tonic-gate{ 18550Sstevel@tonic-gate Elf64_Sword *end = dst; 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate dst += cnt; 18580Sstevel@tonic-gate src += cnt * W_sizeof; 18590Sstevel@tonic-gate while (dst-- > end) { 18600Sstevel@tonic-gate src -= W_sizeof; 18610Sstevel@tonic-gate /*CONSTANTCONDITION*/ 18620Sstevel@tonic-gate if (~(Elf64_Word)0 == -(Elf64_Sword)1 && 18630Sstevel@tonic-gate ~(~(Elf64_Word)0 >> 1) == HI32) { /* 2s comp */ 18640Sstevel@tonic-gate *dst = tomw(src, W_$2); 18650Sstevel@tonic-gate } else { 18660Sstevel@tonic-gate union { 18670Sstevel@tonic-gate Elf64_Word w; 18680Sstevel@tonic-gate Elf64_Sword sw; 18690Sstevel@tonic-gate } u; 18700Sstevel@tonic-gate 18710Sstevel@tonic-gate if ((u.w = tomw(src, W_$2)) & HI32) { 18720Sstevel@tonic-gate u.w |= ~(Elf64_Word)LO31; 18730Sstevel@tonic-gate u.w = ~u.w + 1; 18740Sstevel@tonic-gate u.sw = -u.w; 18750Sstevel@tonic-gate } 18760Sstevel@tonic-gate *dst = u.sw; 18770Sstevel@tonic-gate } 18780Sstevel@tonic-gate } 18790Sstevel@tonic-gate}') 18800Sstevel@tonic-gate 18810Sstevel@tonic-gatesword_tom(sword_2L_tom,L) 18820Sstevel@tonic-gatesword_tom(sword_2M_tom,M) 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate 18850Sstevel@tonic-gatedefine(cap_11_tom, ` 18860Sstevel@tonic-gatestatic void 18870Sstevel@tonic-gate$1(Elf64_Cap *dst, unsigned char *src, size_t cnt) 18880Sstevel@tonic-gate{ 18890Sstevel@tonic-gate Elf64_Cap *end = dst + cnt; 18900Sstevel@tonic-gate 18910Sstevel@tonic-gate do { 18920Sstevel@tonic-gate dst->c_tag = tomx(src, C1_tag_$2); 18930Sstevel@tonic-gate dst->c_un.c_val = tomx(src, C1_val_$2); 18940Sstevel@tonic-gate src += C1_sizeof; 18950Sstevel@tonic-gate } while (++dst < end); 18960Sstevel@tonic-gate}') 18970Sstevel@tonic-gate 18980Sstevel@tonic-gatecap_11_tom(cap_2L11_tom,L) 18990Sstevel@tonic-gatecap_11_tom(cap_2M11_tom,M) 19000Sstevel@tonic-gate 19010Sstevel@tonic-gate 19020Sstevel@tonic-gatedefine(syminfo_11_tom, ` 19030Sstevel@tonic-gatestatic void 19040Sstevel@tonic-gate$1(Elf64_Syminfo *dst, unsigned char *src, size_t cnt) 19050Sstevel@tonic-gate{ 19060Sstevel@tonic-gate Elf64_Syminfo *end = dst; 19070Sstevel@tonic-gate 19080Sstevel@tonic-gate dst += cnt; 19090Sstevel@tonic-gate src += cnt * SI1_sizeof; 19100Sstevel@tonic-gate while (dst-- > end) 19110Sstevel@tonic-gate { 19120Sstevel@tonic-gate src -= SI1_sizeof; 19130Sstevel@tonic-gate dst->si_boundto = tomh(src, SI1_boundto_$2); 19140Sstevel@tonic-gate dst->si_flags = tomh(src, SI1_flags_$2); 19150Sstevel@tonic-gate } 19160Sstevel@tonic-gate}') 19170Sstevel@tonic-gate 19180Sstevel@tonic-gatesyminfo_11_tom(syminfo_2L11_tom,L) 19190Sstevel@tonic-gatesyminfo_11_tom(syminfo_2M11_tom,M) 19200Sstevel@tonic-gate 19210Sstevel@tonic-gate 19220Sstevel@tonic-gatedefine(sym_11_tom, ` 19230Sstevel@tonic-gatestatic void 19240Sstevel@tonic-gate$1(Elf64_Sym *dst, Byte *src, size_t cnt) 19250Sstevel@tonic-gate{ 19260Sstevel@tonic-gate Elf64_Sym *end = dst; 19270Sstevel@tonic-gate 19280Sstevel@tonic-gate dst += cnt; 19290Sstevel@tonic-gate src += cnt * ST1_sizeof; 19300Sstevel@tonic-gate while (dst-- > end) { 19310Sstevel@tonic-gate src -= ST1_sizeof; 19320Sstevel@tonic-gate dst->st_size = tomx(src, ST1_size_$2); 19330Sstevel@tonic-gate dst->st_value = toma(src, ST1_value_$2); 19340Sstevel@tonic-gate dst->st_shndx = tomh(src, ST1_shndx_$2); 19350Sstevel@tonic-gate dst->st_other = tomb(src, ST1_other_$2); 19360Sstevel@tonic-gate dst->st_info = tomb(src, ST1_info_$2); 19370Sstevel@tonic-gate dst->st_name = tomw(src, ST1_name_$2); 19380Sstevel@tonic-gate } 19390Sstevel@tonic-gate}') 19400Sstevel@tonic-gate 19410Sstevel@tonic-gatesym_11_tom(sym_2L11_tom,L) 19420Sstevel@tonic-gatesym_11_tom(sym_2M11_tom,M) 19430Sstevel@tonic-gate 19440Sstevel@tonic-gate 19450Sstevel@tonic-gatedefine(word_tom, ` 19460Sstevel@tonic-gatestatic void 19470Sstevel@tonic-gate$1(Elf64_Word *dst, Byte *src, size_t cnt) 19480Sstevel@tonic-gate{ 19490Sstevel@tonic-gate Elf64_Word *end = dst; 19500Sstevel@tonic-gate 19510Sstevel@tonic-gate dst += cnt; 19520Sstevel@tonic-gate src += cnt * W_sizeof; 19530Sstevel@tonic-gate while (dst-- > end) { 19540Sstevel@tonic-gate src -= W_sizeof; 19550Sstevel@tonic-gate *dst = tomw(src, W_$2); 19560Sstevel@tonic-gate } 19570Sstevel@tonic-gate}') 19580Sstevel@tonic-gate 19590Sstevel@tonic-gateword_tom(word_2L_tom,L) 19600Sstevel@tonic-gateword_tom(word_2M_tom,M) 19610Sstevel@tonic-gate 19620Sstevel@tonic-gate 19630Sstevel@tonic-gatedefine(verdef_11_tom, ` 19640Sstevel@tonic-gatestatic void 19650Sstevel@tonic-gate$1(Elf64_Verdef *dst, Byte *src, size_t cnt) 19660Sstevel@tonic-gate{ 19670Sstevel@tonic-gate /* LINTED */ 19680Sstevel@tonic-gate Elf64_Verdef *end = (Elf64_Verdef *)((Byte *)dst + cnt); 19690Sstevel@tonic-gate 19700Sstevel@tonic-gate while (dst < end) { 19710Sstevel@tonic-gate Elf64_Verdaux *vaux; 19720Sstevel@tonic-gate Byte *src_vaux; 19730Sstevel@tonic-gate Elf64_Half i; 19740Sstevel@tonic-gate 19750Sstevel@tonic-gate dst->vd_version = tomh(src, VD1_version_$2); 19760Sstevel@tonic-gate dst->vd_flags = tomh(src, VD1_flags_$2); 19770Sstevel@tonic-gate dst->vd_ndx = tomh(src, VD1_ndx_$2); 19780Sstevel@tonic-gate dst->vd_cnt = tomh(src, VD1_cnt_$2); 19790Sstevel@tonic-gate dst->vd_hash = tomw(src, VD1_hash_$2); 19800Sstevel@tonic-gate dst->vd_aux = tomw(src, VD1_aux_$2); 19810Sstevel@tonic-gate dst->vd_next = tomw(src, VD1_next_$2); 19820Sstevel@tonic-gate 19830Sstevel@tonic-gate src_vaux = src + dst->vd_aux; 19840Sstevel@tonic-gate /* LINTED */ 19850Sstevel@tonic-gate vaux = (Elf64_Verdaux *)((Byte *)dst + dst->vd_aux); 19860Sstevel@tonic-gate for (i = 0; i < dst->vd_cnt; i++) { 19870Sstevel@tonic-gate vaux->vda_name = tomw(src_vaux, VDA1_name_$2); 19880Sstevel@tonic-gate vaux->vda_next = tomw(src_vaux, VDA1_next_$2); 19890Sstevel@tonic-gate src_vaux += vaux->vda_next; 19900Sstevel@tonic-gate /* LINTED */ 19910Sstevel@tonic-gate vaux = (Elf64_Verdaux *)((Byte *)vaux + 19920Sstevel@tonic-gate vaux->vda_next); 19930Sstevel@tonic-gate } 19940Sstevel@tonic-gate src += dst->vd_next; 19950Sstevel@tonic-gate /* LINTED */ 19960Sstevel@tonic-gate dst = (Elf64_Verdef *)(dst->vd_next ? 19970Sstevel@tonic-gate (Byte *)dst + dst->vd_next : (Byte *)end); 19980Sstevel@tonic-gate } 19990Sstevel@tonic-gate}') 20000Sstevel@tonic-gate 20010Sstevel@tonic-gateverdef_11_tom(verdef_2L11_tom,L) 20020Sstevel@tonic-gateverdef_11_tom(verdef_2M11_tom,M) 20030Sstevel@tonic-gate 20040Sstevel@tonic-gate 20050Sstevel@tonic-gatedefine(verneed_11_tom, ` 20060Sstevel@tonic-gatestatic void 20070Sstevel@tonic-gate$1(Elf64_Verneed *dst, Byte *src, size_t cnt) 20080Sstevel@tonic-gate{ 20090Sstevel@tonic-gate /* LINTED */ 20100Sstevel@tonic-gate Elf64_Verneed *end = (Elf64_Verneed *)((char *)dst + cnt); 20110Sstevel@tonic-gate 20120Sstevel@tonic-gate while (dst < end) { 20130Sstevel@tonic-gate Elf64_Vernaux * vaux; 20140Sstevel@tonic-gate Byte * src_vaux; 20150Sstevel@tonic-gate Elf64_Half i; 20160Sstevel@tonic-gate 20170Sstevel@tonic-gate dst->vn_version = tomh(src, VN1_version_$2); 20180Sstevel@tonic-gate dst->vn_cnt = tomh(src, VN1_cnt_$2); 20190Sstevel@tonic-gate dst->vn_file = tomw(src, VN1_file_$2); 20200Sstevel@tonic-gate dst->vn_aux = tomw(src, VN1_aux_$2); 20210Sstevel@tonic-gate dst->vn_next = tomw(src, VN1_next_$2); 20220Sstevel@tonic-gate 20230Sstevel@tonic-gate src_vaux = src + dst->vn_aux; 20240Sstevel@tonic-gate /* LINTED */ 20250Sstevel@tonic-gate vaux = (Elf64_Vernaux *)((Byte *)dst + dst->vn_aux); 20260Sstevel@tonic-gate for (i = 0; i < dst->vn_cnt; i++) { 20270Sstevel@tonic-gate vaux->vna_hash = tomw(src_vaux, VNA1_hash_$2); 20280Sstevel@tonic-gate vaux->vna_flags = tomh(src_vaux, VNA1_flags_$2); 20290Sstevel@tonic-gate vaux->vna_other = tomh(src_vaux, VNA1_other_$2); 20300Sstevel@tonic-gate vaux->vna_name = tomw(src_vaux, VNA1_name_$2); 20310Sstevel@tonic-gate vaux->vna_next = tomw(src_vaux, VNA1_next_$2); 20320Sstevel@tonic-gate src_vaux += vaux->vna_next; 20330Sstevel@tonic-gate /* LINTED */ 20340Sstevel@tonic-gate vaux = (Elf64_Vernaux *)((Byte *)vaux + 20350Sstevel@tonic-gate vaux->vna_next); 20360Sstevel@tonic-gate } 20370Sstevel@tonic-gate src += dst->vn_next; 20380Sstevel@tonic-gate /* LINTED */ 20390Sstevel@tonic-gate dst = (Elf64_Verneed *)(dst->vn_next ? 20400Sstevel@tonic-gate (Byte *)dst + dst->vn_next : (Byte *)end); 20410Sstevel@tonic-gate } 20420Sstevel@tonic-gate}') 20430Sstevel@tonic-gate 20440Sstevel@tonic-gateverneed_11_tom(verneed_2L11_tom,L) 20450Sstevel@tonic-gateverneed_11_tom(verneed_2M11_tom,M) 20460Sstevel@tonic-gate 20470Sstevel@tonic-gate 20480Sstevel@tonic-gatedefine(sxword_tom, ` 20490Sstevel@tonic-gatestatic void 20500Sstevel@tonic-gate$1(Elf64_Sxword *dst, Byte *src, size_t cnt) 20510Sstevel@tonic-gate{ 20520Sstevel@tonic-gate Elf64_Sxword *end = dst; 20530Sstevel@tonic-gate 20540Sstevel@tonic-gate dst += cnt; 20550Sstevel@tonic-gate src += cnt * X_sizeof; 20560Sstevel@tonic-gate while (dst-- > end) { 20570Sstevel@tonic-gate src -= X_sizeof; 20580Sstevel@tonic-gate /*CONSTANTCONDITION*/ 20590Sstevel@tonic-gate if (~(Elf64_Xword)0 == -(Elf64_Sxword)1 && 20600Sstevel@tonic-gate ~(~(Elf64_Xword)0 >> 1) == HI64) { /* 2s comp */ 20610Sstevel@tonic-gate *dst = tomx(src, X_$2); 20620Sstevel@tonic-gate } else { /* other */ 20630Sstevel@tonic-gate union { 20640Sstevel@tonic-gate Elf64_Xword w; 20650Sstevel@tonic-gate Elf64_Sxword sw; 20660Sstevel@tonic-gate } u; 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate if ((u.w = tomx(src, X_$2)) & HI64) { 20690Sstevel@tonic-gate /* LINTED */ 20700Sstevel@tonic-gate u.w |= ~(Elf64_Xword)LO63; 20710Sstevel@tonic-gate u.w = ~u.w + 1; 20720Sstevel@tonic-gate u.sw = -u.w; 20730Sstevel@tonic-gate } 20740Sstevel@tonic-gate *dst = u.sw; 20750Sstevel@tonic-gate } 20760Sstevel@tonic-gate } 20770Sstevel@tonic-gate}') 20780Sstevel@tonic-gate 20790Sstevel@tonic-gatesxword_tom(sxword_2L_tom,L) 20800Sstevel@tonic-gatesxword_tom(sxword_2M_tom,M) 20810Sstevel@tonic-gate 20820Sstevel@tonic-gate 20830Sstevel@tonic-gatedefine(xword_tom, ` 20840Sstevel@tonic-gatestatic void 20850Sstevel@tonic-gate$1(Elf64_Xword *dst, Byte *src, size_t cnt) 20860Sstevel@tonic-gate{ 20870Sstevel@tonic-gate Elf64_Xword *end = dst; 20880Sstevel@tonic-gate 20890Sstevel@tonic-gate dst += cnt; 20900Sstevel@tonic-gate src += cnt * X_sizeof; 20910Sstevel@tonic-gate while (dst-- > end) { 20920Sstevel@tonic-gate src -= X_sizeof; 20930Sstevel@tonic-gate *dst = tomx(src, X_$2); 20940Sstevel@tonic-gate } 20950Sstevel@tonic-gate}') 20960Sstevel@tonic-gate 20970Sstevel@tonic-gatexword_tom(xword_2L_tom,L) 20980Sstevel@tonic-gatexword_tom(xword_2M_tom,M) 2099