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 * x32: 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 'x32[]' 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 elf32_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 * These routines make a subtle implicit assumption. 710Sstevel@tonic-gate * The file representations of all structures are "packed," 720Sstevel@tonic-gate * meaning no implicit padding bytes occur. This might not 730Sstevel@tonic-gate * be the case for the memory representations. Consequently, 740Sstevel@tonic-gate * the memory representations ALWAYS contain at least as many 750Sstevel@tonic-gate * bytes as the file representations. Otherwise, the memory 760Sstevel@tonic-gate * structures would lose information, meaning they're not 770Sstevel@tonic-gate * implemented properly. 780Sstevel@tonic-gate * 790Sstevel@tonic-gate * The words above apply to structures with the same members. 800Sstevel@tonic-gate * If a future version changes the number of members, the 810Sstevel@tonic-gate * relative structure sizes for different version must be 820Sstevel@tonic-gate * tested with the compiler. 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate 850Sstevel@tonic-gate#define HI32 0x80000000UL 860Sstevel@tonic-gate#define LO31 0x7fffffffUL 870Sstevel@tonic-gate 880Sstevel@tonic-gate/* 890Sstevel@tonic-gate * These macros create indexes for accessing the bytes of 900Sstevel@tonic-gate * words and halfwords for ELFCLASS32 data representations 910Sstevel@tonic-gate * (currently ELFDATA2LSB and ELFDATA2MSB). In all cases, 920Sstevel@tonic-gate * 930Sstevel@tonic-gate * w = (((((X_3 << 8) + X_2) << 8) + X_1) << 8) + X_0 940Sstevel@tonic-gate * h = (X_1 << 8) + X_0 950Sstevel@tonic-gate * 960Sstevel@tonic-gate * These assume the file representations for Addr, Off, 970Sstevel@tonic-gate * Sword, and Word use 4 bytes, but the memory def's for 980Sstevel@tonic-gate * the types may differ. 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * Naming convention: 1010Sstevel@tonic-gate * ..._L ELFDATA2LSB 1020Sstevel@tonic-gate * ..._M ELFDATA2MSB 1030Sstevel@tonic-gate * 1040Sstevel@tonic-gate * enuma_*(n) define enum names for addr n 1050Sstevel@tonic-gate * enumb_*(n) define enum names for byte n 1060Sstevel@tonic-gate * enumh_*(n) define enum names for half n 1070Sstevel@tonic-gate * enumo_*(n) define enum names for off n 1080Sstevel@tonic-gate * enumw_*(n) define enum names for word n 1090Sstevel@tonic-gate * enuml_*(n) define enum names for Lword n 1100Sstevel@tonic-gate * tofa(d,s,n) xlate addr n from mem s to file d 1110Sstevel@tonic-gate * tofb(d,s,n) xlate byte n from mem s to file d 1120Sstevel@tonic-gate * tofh(d,s,n) xlate half n from mem s to file d 1130Sstevel@tonic-gate * tofo(d,s,n) xlate off n from mem s to file d 1140Sstevel@tonic-gate * tofw(d,s,n) xlate word n from mem s to file d 1150Sstevel@tonic-gate * tofl(d,s,n) xlate Lword n from mem s to file d 1160Sstevel@tonic-gate * toma(s,n) xlate addr n from file s to expression value 1170Sstevel@tonic-gate * tomb(s,n) xlate byte n from file s to expression value 1180Sstevel@tonic-gate * tomh(s,n) xlate half n from file s to expression value 1190Sstevel@tonic-gate * tomo(s,n) xlate off n from file s to expression value 1200Sstevel@tonic-gate * tomw(s,n) xlate word n from file s to expression value 1210Sstevel@tonic-gate * toml(s,n) xlate Lword n from file s to expression value 1220Sstevel@tonic-gate * 1230Sstevel@tonic-gate * tof*() macros must move a multi-byte value into a temporary 1240Sstevel@tonic-gate * because ``in place'' conversions are allowed. If a temp is not 1250Sstevel@tonic-gate * used for multi-byte objects, storing an initial destination byte 1260Sstevel@tonic-gate * may clobber a source byte not yet examined. 1270Sstevel@tonic-gate * 1280Sstevel@tonic-gate * tom*() macros compute an expression value from the source 1290Sstevel@tonic-gate * without touching the destination; so they're safe. 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate 1320Sstevel@tonic-gatedefine(enuma_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl 1330Sstevel@tonic-gatedefine(enuma_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl 1340Sstevel@tonic-gatedefine(enumb_L, `$1_L')dnl 1350Sstevel@tonic-gatedefine(enumb_M, `$1_M')dnl 1360Sstevel@tonic-gatedefine(enumh_L, `$1_L0, $1_L1')dnl 1370Sstevel@tonic-gatedefine(enumh_M, `$1_M1, $1_M0')dnl 1380Sstevel@tonic-gatedefine(enumo_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl 1390Sstevel@tonic-gatedefine(enumo_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl 1400Sstevel@tonic-gatedefine(enumw_L, `$1_L0, $1_L1, $1_L2, $1_L3')dnl 1410Sstevel@tonic-gatedefine(enumw_M, `$1_M3, $1_M2, $1_M1, $1_M0')dnl 1420Sstevel@tonic-gatedefine(enuml_L, `$1_L0, $1_L1, $1_L2, $1_L3, $1_L4, $1_L5, $1_L6, $1_L7')dnl 1430Sstevel@tonic-gatedefine(enuml_M, `$1_M7, $1_M6, $1_M5, $1_M4, $1_M3, $1_M2, $1_M1, $1_M0')dnl 1440Sstevel@tonic-gate 1450Sstevel@tonic-gatedefine(tofa, `{ register Elf32_Addr _t_ = $2; 1460Sstevel@tonic-gate ($1)[$3`'0] = (unsigned char)_t_, 1470Sstevel@tonic-gate ($1)[$3`'1] = (unsigned char)(_t_>>8), 1480Sstevel@tonic-gate ($1)[$3`'2] = (unsigned char)(_t_>>16), 1490Sstevel@tonic-gate ($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl 1500Sstevel@tonic-gatedefine(tofb, `($1)[$3] = (unsigned char)($2)')dnl 1510Sstevel@tonic-gatedefine(tofh, `{ register Elf32_Half _t_ = $2; 1520Sstevel@tonic-gate ($1)[$3`'0] = (unsigned char)_t_, 1530Sstevel@tonic-gate ($1)[$3`'1] = (unsigned char)(_t_>>8); }')dnl 1540Sstevel@tonic-gatedefine(tofo, `{ register Elf32_Off _t_ = $2; 1550Sstevel@tonic-gate ($1)[$3`'0] = (unsigned char)_t_, 1560Sstevel@tonic-gate ($1)[$3`'1] = (unsigned char)(_t_>>8), 1570Sstevel@tonic-gate ($1)[$3`'2] = (unsigned char)(_t_>>16), 1580Sstevel@tonic-gate ($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl 1590Sstevel@tonic-gatedefine(tofw, `{ register Elf32_Word _t_ = $2; 1600Sstevel@tonic-gate ($1)[$3`'0] = (unsigned char)_t_, 1610Sstevel@tonic-gate ($1)[$3`'1] = (unsigned char)(_t_>>8), 1620Sstevel@tonic-gate ($1)[$3`'2] = (unsigned char)(_t_>>16), 1630Sstevel@tonic-gate ($1)[$3`'3] = (unsigned char)(_t_>>24); }')dnl 1640Sstevel@tonic-gatedefine(tofl, `{ Elf32_Lword _t_ = $2; 1650Sstevel@tonic-gate ($1)[$3`'0] = (Byte)_t_, 1660Sstevel@tonic-gate ($1)[$3`'1] = (Byte)(_t_>>8), 1670Sstevel@tonic-gate ($1)[$3`'2] = (Byte)(_t_>>16), 1680Sstevel@tonic-gate ($1)[$3`'3] = (Byte)(_t_>>24), 1690Sstevel@tonic-gate ($1)[$3`'4] = (Byte)(_t_>>32), 1700Sstevel@tonic-gate ($1)[$3`'5] = (Byte)(_t_>>40), 1710Sstevel@tonic-gate ($1)[$3`'6] = (Byte)(_t_>>48), 1720Sstevel@tonic-gate ($1)[$3`'7] = (Byte)(_t_>>56); }')dnl 1730Sstevel@tonic-gate 1740Sstevel@tonic-gatedefine(toma, `(((((((Elf32_Addr)($1)[$2`'3]<<8) 1750Sstevel@tonic-gate +($1)[$2`'2])<<8) 1760Sstevel@tonic-gate +($1)[$2`'1])<<8) 1770Sstevel@tonic-gate +($1)[$2`'0])')dnl 1780Sstevel@tonic-gatedefine(tomb, `((unsigned char)($1)[$2])')dnl 1790Sstevel@tonic-gatedefine(tomh, `(((Elf32_Half)($1)[$2`'1]<<8)+($1)[$2`'0])')dnl 1800Sstevel@tonic-gatedefine(tomo, `(((((((Elf32_Off)($1)[$2`'3]<<8) 1810Sstevel@tonic-gate +($1)[$2`'2])<<8) 1820Sstevel@tonic-gate +($1)[$2`'1])<<8) 1830Sstevel@tonic-gate +($1)[$2`'0])')dnl 1840Sstevel@tonic-gatedefine(tomw, `(((((((Elf32_Word)($1)[$2`'3]<<8) 1850Sstevel@tonic-gate +($1)[$2`'2])<<8) 1860Sstevel@tonic-gate +($1)[$2`'1])<<8) 1870Sstevel@tonic-gate +($1)[$2`'0])')dnl 1880Sstevel@tonic-gatedefine(toml, `(((((((((((Elf32_Lword)($1)[$2`'7]<<8) 1890Sstevel@tonic-gate +($1)[$2`'6]<<8) 1900Sstevel@tonic-gate +($1)[$2`'5]<<8) 1910Sstevel@tonic-gate +($1)[$2`'4]<<8) 1920Sstevel@tonic-gate +($1)[$2`'3]<<8) 1930Sstevel@tonic-gate +($1)[$2`'2])<<8) 1940Sstevel@tonic-gate +($1)[$2`'1])<<8) 1950Sstevel@tonic-gate +($1)[$2`'0])')dnl 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate/* 1990Sstevel@tonic-gate * ELF data object indexes 2000Sstevel@tonic-gate * The enums are broken apart to get around deficiencies 2010Sstevel@tonic-gate * in some compilers. 2020Sstevel@tonic-gate */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gatedefine(Addr, ` 2050Sstevel@tonic-gateenum 2060Sstevel@tonic-gate{ 2070Sstevel@tonic-gate enuma_$1(A)`'ifelse(`$2', `', `', `, 2080Sstevel@tonic-gate A_sizeof') 2090Sstevel@tonic-gate};') 2100Sstevel@tonic-gate 2110Sstevel@tonic-gateAddr(L) 2120Sstevel@tonic-gateAddr(M,1) 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate 2150Sstevel@tonic-gatedefine(Half, ` 2160Sstevel@tonic-gateenum 2170Sstevel@tonic-gate{ 2180Sstevel@tonic-gate enumh_$1(H)`'ifelse(`$2', `', `', `, 2190Sstevel@tonic-gate H_sizeof') 2200Sstevel@tonic-gate};') 2210Sstevel@tonic-gate 2220Sstevel@tonic-gateHalf(L) 2230Sstevel@tonic-gateHalf(M,1) 2240Sstevel@tonic-gate 2250Sstevel@tonic-gatedefine(Lword, ` 2260Sstevel@tonic-gateenum 2270Sstevel@tonic-gate{ 2280Sstevel@tonic-gate enuml_$1(L)`'ifelse(`$2', `', `', `, 2290Sstevel@tonic-gate L_sizeof') 2300Sstevel@tonic-gate};') 2310Sstevel@tonic-gate 2320Sstevel@tonic-gateLword(L) 2330Sstevel@tonic-gateLword(M,1) 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate 2360Sstevel@tonic-gatedefine(Move_1, ` 2370Sstevel@tonic-gateenum 2380Sstevel@tonic-gate{ 2390Sstevel@tonic-gate enuml_$1(M1_value), 2400Sstevel@tonic-gate enumw_$1(M1_info), 2410Sstevel@tonic-gate enumw_$1(M1_poffset), 2420Sstevel@tonic-gate enumh_$1(M1_repeat), 2430Sstevel@tonic-gate enumh_$1(M1_stride)`'ifelse(`$2', `', `', `, 2440Sstevel@tonic-gate M1_sizeof') 2450Sstevel@tonic-gate};') 2460Sstevel@tonic-gate 2470Sstevel@tonic-gateMove_1(L) 2480Sstevel@tonic-gateMove_1(M,1) 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate 2510Sstevel@tonic-gatedefine(MoveP_1, ` 2520Sstevel@tonic-gateenum 2530Sstevel@tonic-gate{ 2540Sstevel@tonic-gate enuml_$1(MP1_value), 2550Sstevel@tonic-gate enumw_$1(MP1_info), 2560Sstevel@tonic-gate enumw_$1(MP1_poffset), 2570Sstevel@tonic-gate enumh_$1(MP1_repeat), 2580Sstevel@tonic-gate enumh_$1(MP1_stride), 2590Sstevel@tonic-gate enumw_$1(MP1_padding)`'ifelse(`$2', `', `', `, 2600Sstevel@tonic-gate MP1_sizeof') 2610Sstevel@tonic-gate};') 2620Sstevel@tonic-gate 2630Sstevel@tonic-gateMoveP_1(L) 2640Sstevel@tonic-gateMoveP_1(M,1) 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate 2670Sstevel@tonic-gatedefine(Off, ` 2680Sstevel@tonic-gateenum 2690Sstevel@tonic-gate{ 2700Sstevel@tonic-gate enumo_$1(O)`'ifelse(`$2', `', `', `, 2710Sstevel@tonic-gate O_sizeof') 2720Sstevel@tonic-gate};') 2730Sstevel@tonic-gate 2740Sstevel@tonic-gateOff(L) 2750Sstevel@tonic-gateOff(M,1) 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate 2780Sstevel@tonic-gatedefine(Word, ` 2790Sstevel@tonic-gateenum 2800Sstevel@tonic-gate{ 2810Sstevel@tonic-gate enumw_$1(W)`'ifelse(`$2', `', `', `, 2820Sstevel@tonic-gate W_sizeof') 2830Sstevel@tonic-gate};') 2840Sstevel@tonic-gate 2850Sstevel@tonic-gateWord(L) 2860Sstevel@tonic-gateWord(M,1) 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate 2890Sstevel@tonic-gatedefine(Dyn_1, ` 2900Sstevel@tonic-gateenum 2910Sstevel@tonic-gate{ 2920Sstevel@tonic-gate enumw_$1(D1_tag), 2930Sstevel@tonic-gate enumw_$1(D1_val)`'ifelse(`$2', `', `', `, 2940Sstevel@tonic-gate D1_sizeof') 2950Sstevel@tonic-gate};') 2960Sstevel@tonic-gate 2970Sstevel@tonic-gateDyn_1(L) 2980Sstevel@tonic-gateDyn_1(M,1) 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate#define E1_Nident 16 3020Sstevel@tonic-gate 3030Sstevel@tonic-gatedefine(Ehdr_1, ` 3040Sstevel@tonic-gateenum 3050Sstevel@tonic-gate{ 3060Sstevel@tonic-gate ifelse(`$2', `', `E1_ident, ')E1_ident_$1_Z = E1_Nident - 1, 3070Sstevel@tonic-gate enumh_$1(E1_type), 3080Sstevel@tonic-gate enumh_$1(E1_machine), 3090Sstevel@tonic-gate enumw_$1(E1_version), 3100Sstevel@tonic-gate enuma_$1(E1_entry), 3110Sstevel@tonic-gate enumo_$1(E1_phoff), 3120Sstevel@tonic-gate enumo_$1(E1_shoff), 3130Sstevel@tonic-gate enumw_$1(E1_flags), 3140Sstevel@tonic-gate enumh_$1(E1_ehsize), 3150Sstevel@tonic-gate enumh_$1(E1_phentsize), 3160Sstevel@tonic-gate enumh_$1(E1_phnum), 3170Sstevel@tonic-gate enumh_$1(E1_shentsize), 3180Sstevel@tonic-gate enumh_$1(E1_shnum), 3190Sstevel@tonic-gate enumh_$1(E1_shstrndx)`'ifelse(`$2', `', `', `, 3200Sstevel@tonic-gate E1_sizeof') 3210Sstevel@tonic-gate};') 3220Sstevel@tonic-gate 3230Sstevel@tonic-gateEhdr_1(L) 3240Sstevel@tonic-gateEhdr_1(M,1) 3250Sstevel@tonic-gate 3260Sstevel@tonic-gatedefine(Nhdr_1, ` 3270Sstevel@tonic-gateenum 3280Sstevel@tonic-gate{ 3290Sstevel@tonic-gate enumw_$1(N1_namesz), 3300Sstevel@tonic-gate enumw_$1(N1_descsz), 3310Sstevel@tonic-gate enumw_$1(N1_type)`'ifelse(`$2', `', `', `, 3320Sstevel@tonic-gate N1_sizeof') 3330Sstevel@tonic-gate};') 3340Sstevel@tonic-gate 3350Sstevel@tonic-gateNhdr_1(L) 3360Sstevel@tonic-gateNhdr_1(M,1) 3370Sstevel@tonic-gate 3380Sstevel@tonic-gatedefine(Phdr_1, ` 3390Sstevel@tonic-gateenum 3400Sstevel@tonic-gate{ 3410Sstevel@tonic-gate enumw_$1(P1_type), 3420Sstevel@tonic-gate enumo_$1(P1_offset), 3430Sstevel@tonic-gate enuma_$1(P1_vaddr), 3440Sstevel@tonic-gate enuma_$1(P1_paddr), 3450Sstevel@tonic-gate enumw_$1(P1_filesz), 3460Sstevel@tonic-gate enumw_$1(P1_memsz), 3470Sstevel@tonic-gate enumw_$1(P1_flags), 3480Sstevel@tonic-gate enumw_$1(P1_align)`'ifelse(`$2', `', `', `, 3490Sstevel@tonic-gate P1_sizeof') 3500Sstevel@tonic-gate};') 3510Sstevel@tonic-gate 3520Sstevel@tonic-gatePhdr_1(L) 3530Sstevel@tonic-gatePhdr_1(M,1) 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate 3560Sstevel@tonic-gatedefine(Rel_1, ` 3570Sstevel@tonic-gateenum 3580Sstevel@tonic-gate{ 3590Sstevel@tonic-gate enuma_$1(R1_offset), 3600Sstevel@tonic-gate enumw_$1(R1_info)`'ifelse(`$2', `', `', `, 3610Sstevel@tonic-gate R1_sizeof') 3620Sstevel@tonic-gate};') 3630Sstevel@tonic-gate 3640Sstevel@tonic-gateRel_1(L) 3650Sstevel@tonic-gateRel_1(M,1) 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate 3680Sstevel@tonic-gatedefine(Rela_1, ` 3690Sstevel@tonic-gateenum 3700Sstevel@tonic-gate{ 3710Sstevel@tonic-gate enuma_$1(RA1_offset), 3720Sstevel@tonic-gate enumw_$1(RA1_info), 3730Sstevel@tonic-gate enumw_$1(RA1_addend)`'ifelse(`$2', `', `', `, 3740Sstevel@tonic-gate RA1_sizeof') 3750Sstevel@tonic-gate};') 3760Sstevel@tonic-gate 3770Sstevel@tonic-gateRela_1(L) 3780Sstevel@tonic-gateRela_1(M,1) 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate 3810Sstevel@tonic-gatedefine(Shdr_1, ` 3820Sstevel@tonic-gateenum 3830Sstevel@tonic-gate{ 3840Sstevel@tonic-gate enumw_$1(SH1_name), 3850Sstevel@tonic-gate enumw_$1(SH1_type), 3860Sstevel@tonic-gate enumw_$1(SH1_flags), 3870Sstevel@tonic-gate enuma_$1(SH1_addr), 3880Sstevel@tonic-gate enumo_$1(SH1_offset), 3890Sstevel@tonic-gate enumw_$1(SH1_size), 3900Sstevel@tonic-gate enumw_$1(SH1_link), 3910Sstevel@tonic-gate enumw_$1(SH1_info), 3920Sstevel@tonic-gate enumw_$1(SH1_addralign), 3930Sstevel@tonic-gate enumw_$1(SH1_entsize)`'ifelse(`$2', `', `', `, 3940Sstevel@tonic-gate SH1_sizeof') 3950Sstevel@tonic-gate};') 3960Sstevel@tonic-gate 3970Sstevel@tonic-gateShdr_1(L) 3980Sstevel@tonic-gateShdr_1(M,1) 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate 4010Sstevel@tonic-gatedefine(Sym_1, ` 4020Sstevel@tonic-gateenum 4030Sstevel@tonic-gate{ 4040Sstevel@tonic-gate enumw_$1(ST1_name), 4050Sstevel@tonic-gate enuma_$1(ST1_value), 4060Sstevel@tonic-gate enumw_$1(ST1_size), 4070Sstevel@tonic-gate enumb_$1(ST1_info), 4080Sstevel@tonic-gate enumb_$1(ST1_other), 4090Sstevel@tonic-gate enumh_$1(ST1_shndx)`'ifelse(`$2', `', `', `, 4100Sstevel@tonic-gate ST1_sizeof') 4110Sstevel@tonic-gate};') 4120Sstevel@tonic-gate 4130Sstevel@tonic-gateSym_1(L) 4140Sstevel@tonic-gateSym_1(M,1) 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate 4170Sstevel@tonic-gatedefine(Syminfo_1, ` 4180Sstevel@tonic-gateenum 4190Sstevel@tonic-gate{ 4200Sstevel@tonic-gate enumh_$1(SI1_boundto), 4210Sstevel@tonic-gate enumh_$1(SI1_flags)`'ifelse(`$2', `', `', `, 4220Sstevel@tonic-gate SI1_sizeof') 4230Sstevel@tonic-gate};') 4240Sstevel@tonic-gate 4250Sstevel@tonic-gateSyminfo_1(L) 4260Sstevel@tonic-gateSyminfo_1(M,1) 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate 4290Sstevel@tonic-gatedefine(Cap_1, ` 4300Sstevel@tonic-gateenum 4310Sstevel@tonic-gate{ 4320Sstevel@tonic-gate enumw_$1(C1_tag), 4330Sstevel@tonic-gate enumw_$1(C1_val)`'ifelse(`$2', `', `', `, 4340Sstevel@tonic-gate C1_sizeof') 4350Sstevel@tonic-gate};') 4360Sstevel@tonic-gate 4370Sstevel@tonic-gateCap_1(L) 4380Sstevel@tonic-gateCap_1(M,1) 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate 4410Sstevel@tonic-gatedefine(Verdef_1, ` 4420Sstevel@tonic-gateenum 4430Sstevel@tonic-gate{ 4440Sstevel@tonic-gate enumh_$1(VD1_version), 4450Sstevel@tonic-gate enumh_$1(VD1_flags), 4460Sstevel@tonic-gate enumh_$1(VD1_ndx), 4470Sstevel@tonic-gate enumh_$1(VD1_cnt), 4480Sstevel@tonic-gate enumw_$1(VD1_hash), 4490Sstevel@tonic-gate enumw_$1(VD1_aux), 4500Sstevel@tonic-gate enumw_$1(VD1_next)`'ifelse(`$2', `', `', `, 4510Sstevel@tonic-gate VD1_sizeof') 4520Sstevel@tonic-gate};') 4530Sstevel@tonic-gate 4540Sstevel@tonic-gateVerdef_1(L) 4550Sstevel@tonic-gateVerdef_1(M,1) 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate 4580Sstevel@tonic-gatedefine(Verdaux_1, ` 4590Sstevel@tonic-gateenum 4600Sstevel@tonic-gate{ 4610Sstevel@tonic-gate enuma_$1(VDA1_name), 4620Sstevel@tonic-gate enumw_$1(VDA1_next)`'ifelse(`$2', `', `', `, 4630Sstevel@tonic-gate VDA1_sizeof') 4640Sstevel@tonic-gate};') 4650Sstevel@tonic-gate 4660Sstevel@tonic-gateVerdaux_1(L) 4670Sstevel@tonic-gateVerdaux_1(M,1) 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate 4700Sstevel@tonic-gatedefine(Verneed_1, ` 4710Sstevel@tonic-gateenum 4720Sstevel@tonic-gate{ 4730Sstevel@tonic-gate enumh_$1(VN1_version), 4740Sstevel@tonic-gate enumh_$1(VN1_cnt), 4750Sstevel@tonic-gate enuma_$1(VN1_file), 4760Sstevel@tonic-gate enumw_$1(VN1_aux), 4770Sstevel@tonic-gate enumw_$1(VN1_next)`'ifelse(`$2', `', `', `, 4780Sstevel@tonic-gate VN1_sizeof') 4790Sstevel@tonic-gate};') 4800Sstevel@tonic-gate 4810Sstevel@tonic-gateVerneed_1(L) 4820Sstevel@tonic-gateVerneed_1(M,1) 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate 4850Sstevel@tonic-gatedefine(Vernaux_1, ` 4860Sstevel@tonic-gateenum 4870Sstevel@tonic-gate{ 4880Sstevel@tonic-gate enumw_$1(VNA1_hash), 4890Sstevel@tonic-gate enumh_$1(VNA1_flags), 4900Sstevel@tonic-gate enumh_$1(VNA1_other), 4910Sstevel@tonic-gate enuma_$1(VNA1_name), 4920Sstevel@tonic-gate enumw_$1(VNA1_next)`'ifelse(`$2', `', `', `, 4930Sstevel@tonic-gate VNA1_sizeof') 4940Sstevel@tonic-gate};') 4950Sstevel@tonic-gate 4960Sstevel@tonic-gateVernaux_1(L) 4970Sstevel@tonic-gateVernaux_1(M,1) 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate/* 5010Sstevel@tonic-gate * Translation function declarations. 5020Sstevel@tonic-gate * 5030Sstevel@tonic-gate * <object>_<data><dver><sver>_tof 5040Sstevel@tonic-gate * <object>_<data><dver><sver>_tom 5050Sstevel@tonic-gate * where 5060Sstevel@tonic-gate * <data> 2L ELFDATA2LSB 5070Sstevel@tonic-gate * 2M ELFDATA2MSB 5080Sstevel@tonic-gate */ 5090Sstevel@tonic-gate 5100Sstevel@tonic-gatestatic void addr_2L_tof(), addr_2L_tom(), 5110Sstevel@tonic-gate addr_2M_tof(), addr_2M_tom(), 5120Sstevel@tonic-gate byte_to(), 5130Sstevel@tonic-gate dyn_2L11_tof(), dyn_2L11_tom(), 5140Sstevel@tonic-gate dyn_2M11_tof(), dyn_2M11_tom(), 5150Sstevel@tonic-gate ehdr_2L11_tof(), ehdr_2L11_tom(), 5160Sstevel@tonic-gate ehdr_2M11_tof(), ehdr_2M11_tom(), 5170Sstevel@tonic-gate half_2L_tof(), half_2L_tom(), 5180Sstevel@tonic-gate half_2M_tof(), half_2M_tom(), 5190Sstevel@tonic-gate move_2L11_tof(), move_2L11_tom(), 5200Sstevel@tonic-gate move_2M11_tof(), move_2M11_tom(), 5210Sstevel@tonic-gate movep_2L11_tof(), movep_2L11_tom(), 5220Sstevel@tonic-gate movep_2M11_tof(), movep_2M11_tom(), 5230Sstevel@tonic-gate off_2L_tof(), off_2L_tom(), 5240Sstevel@tonic-gate off_2M_tof(), off_2M_tom(), 5250Sstevel@tonic-gate note_2L11_tof(), note_2L11_tom(), 5260Sstevel@tonic-gate note_2M11_tof(), note_2M11_tom(), 5270Sstevel@tonic-gate phdr_2L11_tof(), phdr_2L11_tom(), 5280Sstevel@tonic-gate phdr_2M11_tof(), phdr_2M11_tom(), 5290Sstevel@tonic-gate rel_2L11_tof(), rel_2L11_tom(), 5300Sstevel@tonic-gate rel_2M11_tof(), rel_2M11_tom(), 5310Sstevel@tonic-gate rela_2L11_tof(), rela_2L11_tom(), 5320Sstevel@tonic-gate rela_2M11_tof(), rela_2M11_tom(), 5330Sstevel@tonic-gate shdr_2L11_tof(), shdr_2L11_tom(), 5340Sstevel@tonic-gate shdr_2M11_tof(), shdr_2M11_tom(), 5350Sstevel@tonic-gate sword_2L_tof(), sword_2L_tom(), 5360Sstevel@tonic-gate sword_2M_tof(), sword_2M_tom(), 5370Sstevel@tonic-gate sym_2L11_tof(), sym_2L11_tom(), 5380Sstevel@tonic-gate sym_2M11_tof(), sym_2M11_tom(), 5390Sstevel@tonic-gate syminfo_2L11_tof(), syminfo_2L11_tom(), 5400Sstevel@tonic-gate syminfo_2M11_tof(), syminfo_2M11_tom(), 5410Sstevel@tonic-gate word_2L_tof(), word_2L_tom(), 5420Sstevel@tonic-gate word_2M_tof(), word_2M_tom(), 5430Sstevel@tonic-gate verdef_2L11_tof(), verdef_2L11_tom(), 5440Sstevel@tonic-gate verdef_2M11_tof(), verdef_2M11_tom(), 5450Sstevel@tonic-gate verneed_2L11_tof(), verneed_2L11_tom(), 5460Sstevel@tonic-gate verneed_2M11_tof(), verneed_2M11_tom(), 5470Sstevel@tonic-gate cap_2L11_tof(), cap_2L11_tom(), 5480Sstevel@tonic-gate cap_2M11_tof(), cap_2M11_tom(); 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate/* x32 [dst_version - 1] [src_version - 1] [encode - 1] [type] 5520Sstevel@tonic-gate */ 5530Sstevel@tonic-gate 5540Sstevel@tonic-gatestatic struct { 5550Sstevel@tonic-gate void (*x_tof)(), 5560Sstevel@tonic-gate (*x_tom)(); 5570Sstevel@tonic-gate} x32 [EV_CURRENT] [EV_CURRENT] [ELFDATANUM - 1] [ELF_T_NUM] = 5580Sstevel@tonic-gate{ 5590Sstevel@tonic-gate { 5600Sstevel@tonic-gate { 5610Sstevel@tonic-gate { /* [1-1][1-1][2LSB-1][.] */ 5620Sstevel@tonic-gate/* BYTE */ { byte_to, byte_to }, 5630Sstevel@tonic-gate/* ADDR */ { addr_2L_tof, addr_2L_tom }, 5640Sstevel@tonic-gate/* DYN */ { dyn_2L11_tof, dyn_2L11_tom }, 5650Sstevel@tonic-gate/* EHDR */ { ehdr_2L11_tof, ehdr_2L11_tom }, 5660Sstevel@tonic-gate/* HALF */ { half_2L_tof, half_2L_tom }, 5670Sstevel@tonic-gate/* OFF */ { off_2L_tof, off_2L_tom }, 5680Sstevel@tonic-gate/* PHDR */ { phdr_2L11_tof, phdr_2L11_tom }, 5690Sstevel@tonic-gate/* RELA */ { rela_2L11_tof, rela_2L11_tom }, 5700Sstevel@tonic-gate/* REL */ { rel_2L11_tof, rel_2L11_tom }, 5710Sstevel@tonic-gate/* SHDR */ { shdr_2L11_tof, shdr_2L11_tom }, 5720Sstevel@tonic-gate/* SWORD */ { sword_2L_tof, sword_2L_tom }, 5730Sstevel@tonic-gate/* SYM */ { sym_2L11_tof, sym_2L11_tom }, 5740Sstevel@tonic-gate/* WORD */ { word_2L_tof, word_2L_tom }, 5750Sstevel@tonic-gate/* VERDEF */ { verdef_2L11_tof, verdef_2L11_tom}, 5760Sstevel@tonic-gate/* VERNEED */ { verneed_2L11_tof, verneed_2L11_tom}, 5770Sstevel@tonic-gate/* SXWORD */ { 0, 0 }, /* illegal 32-bit op */ 5780Sstevel@tonic-gate/* XWORD */ { 0, 0 }, /* illegal 32-bit op */ 5790Sstevel@tonic-gate/* SYMINFO */ { syminfo_2L11_tof, syminfo_2L11_tom }, 5800Sstevel@tonic-gate/* NOTE */ { note_2L11_tof, note_2L11_tom }, 5810Sstevel@tonic-gate/* MOVE */ { move_2L11_tof, move_2L11_tom }, 5820Sstevel@tonic-gate/* MOVEP */ { movep_2L11_tof, movep_2L11_tom }, 5830Sstevel@tonic-gate/* CAP */ { cap_2L11_tof, cap_2L11_tom }, 5840Sstevel@tonic-gate }, 5850Sstevel@tonic-gate { /* [1-1][1-1][2MSB-1][.] */ 5860Sstevel@tonic-gate/* BYTE */ { byte_to, byte_to }, 5870Sstevel@tonic-gate/* ADDR */ { addr_2M_tof, addr_2M_tom }, 5880Sstevel@tonic-gate/* DYN */ { dyn_2M11_tof, dyn_2M11_tom }, 5890Sstevel@tonic-gate/* EHDR */ { ehdr_2M11_tof, ehdr_2M11_tom }, 5900Sstevel@tonic-gate/* HALF */ { half_2M_tof, half_2M_tom }, 5910Sstevel@tonic-gate/* OFF */ { off_2M_tof, off_2M_tom }, 5920Sstevel@tonic-gate/* PHDR */ { phdr_2M11_tof, phdr_2M11_tom }, 5930Sstevel@tonic-gate/* RELA */ { rela_2M11_tof, rela_2M11_tom }, 5940Sstevel@tonic-gate/* REL */ { rel_2M11_tof, rel_2M11_tom }, 5950Sstevel@tonic-gate/* SHDR */ { shdr_2M11_tof, shdr_2M11_tom }, 5960Sstevel@tonic-gate/* SWORD */ { sword_2M_tof, sword_2M_tom }, 5970Sstevel@tonic-gate/* SYM */ { sym_2M11_tof, sym_2M11_tom }, 5980Sstevel@tonic-gate/* WORD */ { word_2M_tof, word_2M_tom }, 5990Sstevel@tonic-gate/* VERDEF */ { verdef_2M11_tof, verdef_2M11_tom}, 6000Sstevel@tonic-gate/* VERNEED */ { verneed_2M11_tof, verneed_2M11_tom}, 6010Sstevel@tonic-gate/* SXWORD */ { 0, 0 }, /* illegal 32-bit op */ 6020Sstevel@tonic-gate/* XWORD */ { 0, 0 }, /* illegal 32-bit op */ 6030Sstevel@tonic-gate/* SYMINFO */ { syminfo_2M11_tof, syminfo_2M11_tom }, 6040Sstevel@tonic-gate/* NOTE */ { note_2M11_tof, note_2M11_tom }, 6050Sstevel@tonic-gate/* MOVE */ { move_2M11_tof, move_2M11_tom }, 6060Sstevel@tonic-gate/* MOVEP */ { movep_2M11_tof, movep_2M11_tom }, 6070Sstevel@tonic-gate/* CAP */ { cap_2M11_tof, cap_2M11_tom }, 6080Sstevel@tonic-gate }, 6090Sstevel@tonic-gate }, 6100Sstevel@tonic-gate }, 6110Sstevel@tonic-gate}; 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate/* 6150Sstevel@tonic-gate * size [version - 1] [type] 6160Sstevel@tonic-gate */ 6170Sstevel@tonic-gate 6180Sstevel@tonic-gatestatic const struct { 6190Sstevel@tonic-gate size_t s_filesz, 6200Sstevel@tonic-gate s_memsz; 6210Sstevel@tonic-gate} fmsize [EV_CURRENT] [ELF_T_NUM] = 6220Sstevel@tonic-gate{ 6230Sstevel@tonic-gate { /* [1-1][.] */ 6240Sstevel@tonic-gate/* BYTE */ { 1, 1 }, 6250Sstevel@tonic-gate/* ADDR */ { A_sizeof, sizeof (Elf32_Addr) }, 6260Sstevel@tonic-gate/* DYN */ { D1_sizeof, sizeof (Elf32_Dyn) }, 6270Sstevel@tonic-gate/* EHDR */ { E1_sizeof, sizeof (Elf32_Ehdr) }, 6280Sstevel@tonic-gate/* HALF */ { H_sizeof, sizeof (Elf32_Half) }, 6290Sstevel@tonic-gate/* OFF */ { O_sizeof, sizeof (Elf32_Off) }, 6300Sstevel@tonic-gate/* PHDR */ { P1_sizeof, sizeof (Elf32_Phdr) }, 6310Sstevel@tonic-gate/* RELA */ { RA1_sizeof, sizeof (Elf32_Rela) }, 6320Sstevel@tonic-gate/* REL */ { R1_sizeof, sizeof (Elf32_Rel) }, 6330Sstevel@tonic-gate/* SHDR */ { SH1_sizeof, sizeof (Elf32_Shdr) }, 6340Sstevel@tonic-gate/* SWORD */ { W_sizeof, sizeof (Elf32_Sword) }, 6350Sstevel@tonic-gate/* SYM */ { ST1_sizeof, sizeof (Elf32_Sym) }, 6360Sstevel@tonic-gate/* WORD */ { W_sizeof, sizeof (Elf32_Word) }, 6370Sstevel@tonic-gate/* VERDEF */ { 1, 1}, /* because bot VERDEF & VERNEED have varying */ 6380Sstevel@tonic-gate/* VERNEED */ { 1, 1}, /* sized structures we set their sizes */ 6390Sstevel@tonic-gate /* to 1 byte */ 6400Sstevel@tonic-gate/* SXWORD */ { 0, 0 }, /* illegal 32-bit op */ 6410Sstevel@tonic-gate/* XWORD */ { 0, 0 }, /* illegal 32-bit op */ 6420Sstevel@tonic-gate/* SYMINFO */ { SI1_sizeof, sizeof (Elf32_Syminfo) }, 6430Sstevel@tonic-gate/* NOTE */ { 1, 1}, /* NOTE has varying sized data we can't */ 6440Sstevel@tonic-gate /* use the usual table magic. */ 6450Sstevel@tonic-gate/* MOVE */ { M1_sizeof, sizeof (Elf32_Move) }, 6460Sstevel@tonic-gate/* MOVEP */ { MP1_sizeof, sizeof (Elf32_Move) }, 6470Sstevel@tonic-gate/* CAP */ { C1_sizeof, sizeof (Elf32_Cap) }, 6480Sstevel@tonic-gate }, 6490Sstevel@tonic-gate}; 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate/* 6530Sstevel@tonic-gate * memory type [version - 1] [section type] 6540Sstevel@tonic-gate */ 6550Sstevel@tonic-gate 6560Sstevel@tonic-gatestatic const Elf_Type mtype[EV_CURRENT][SHT_NUM] = 6570Sstevel@tonic-gate{ 6580Sstevel@tonic-gate { /* [1-1][.] */ 6590Sstevel@tonic-gate/* NULL */ ELF_T_BYTE, 6600Sstevel@tonic-gate/* PROGBITS */ ELF_T_BYTE, 6610Sstevel@tonic-gate/* SYMTAB */ ELF_T_SYM, 6620Sstevel@tonic-gate/* STRTAB */ ELF_T_BYTE, 6630Sstevel@tonic-gate/* RELA */ ELF_T_RELA, 6640Sstevel@tonic-gate/* HASH */ ELF_T_WORD, 6650Sstevel@tonic-gate/* DYNAMIC */ ELF_T_DYN, 6660Sstevel@tonic-gate/* NOTE */ ELF_T_NOTE, 6670Sstevel@tonic-gate/* NOBITS */ ELF_T_BYTE, 6680Sstevel@tonic-gate/* REL */ ELF_T_REL, 6690Sstevel@tonic-gate/* SHLIB */ ELF_T_BYTE, 6700Sstevel@tonic-gate/* DYNSYM */ ELF_T_SYM, 6710Sstevel@tonic-gate/* UNKNOWN12 */ ELF_T_BYTE, 6720Sstevel@tonic-gate/* UNKNOWN13 */ ELF_T_BYTE, 6730Sstevel@tonic-gate/* INIT_ARRAY */ ELF_T_ADDR, 6740Sstevel@tonic-gate/* FINI_ARRAY */ ELF_T_ADDR, 6750Sstevel@tonic-gate/* PREINIT_ARRAY */ ELF_T_ADDR, 6760Sstevel@tonic-gate/* GROUP */ ELF_T_WORD, 6770Sstevel@tonic-gate/* SYMTAB_SHNDX */ ELF_T_WORD 6780Sstevel@tonic-gate }, 6790Sstevel@tonic-gate}; 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate 6820Sstevel@tonic-gatesize_t 6830Sstevel@tonic-gateelf32_fsize(Elf_Type type, size_t count, unsigned ver) 6840Sstevel@tonic-gate{ 6850Sstevel@tonic-gate if (--ver >= EV_CURRENT) { 6860Sstevel@tonic-gate _elf_seterr(EREQ_VER, 0); 6870Sstevel@tonic-gate return (0); 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate if ((unsigned)type >= ELF_T_NUM) { 6900Sstevel@tonic-gate _elf_seterr(EREQ_TYPE, 0); 6910Sstevel@tonic-gate return (0); 6920Sstevel@tonic-gate } 6930Sstevel@tonic-gate return (fmsize[ver][type].s_filesz * count); 6940Sstevel@tonic-gate} 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate 6970Sstevel@tonic-gatesize_t 6980Sstevel@tonic-gate_elf32_msize(Elf_Type type, unsigned ver) 6990Sstevel@tonic-gate{ 7000Sstevel@tonic-gate return (fmsize[ver - 1][type].s_memsz); 7010Sstevel@tonic-gate} 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate 7040Sstevel@tonic-gateElf_Type 7050Sstevel@tonic-gate_elf32_mtype(Elf * elf, Elf32_Word shtype, unsigned ver) 7060Sstevel@tonic-gate{ 7070Sstevel@tonic-gate Elf32_Ehdr * ehdr = (Elf32_Ehdr *)elf->ed_ehdr; 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate if (shtype < SHT_NUM) 7100Sstevel@tonic-gate return (mtype[ver - 1][shtype]); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate switch (shtype) { 7133621Sab196087 case SHT_SUNW_symsort: 7143621Sab196087 case SHT_SUNW_tlssort: 7153621Sab196087 return (ELF_T_WORD); 7163621Sab196087 case SHT_SUNW_LDYNSYM: 7173621Sab196087 return (ELF_T_SYM); 7180Sstevel@tonic-gate case SHT_SUNW_dof: 7190Sstevel@tonic-gate return (ELF_T_BYTE); 7200Sstevel@tonic-gate case SHT_SUNW_cap: 7210Sstevel@tonic-gate return (ELF_T_CAP); 72211827SRod.Evans@Sun.COM case SHT_SUNW_capchain: 72311827SRod.Evans@Sun.COM return (ELF_T_WORD); 72411827SRod.Evans@Sun.COM case SHT_SUNW_capinfo: 72511827SRod.Evans@Sun.COM return (ELF_T_WORD); 7260Sstevel@tonic-gate case SHT_SUNW_SIGNATURE: 7270Sstevel@tonic-gate return (ELF_T_BYTE); 7280Sstevel@tonic-gate case SHT_SUNW_ANNOTATE: 7290Sstevel@tonic-gate return (ELF_T_BYTE); 7300Sstevel@tonic-gate case SHT_SUNW_DEBUGSTR: 7310Sstevel@tonic-gate return (ELF_T_BYTE); 7320Sstevel@tonic-gate case SHT_SUNW_DEBUG: 7330Sstevel@tonic-gate return (ELF_T_BYTE); 7340Sstevel@tonic-gate case SHT_SUNW_move: 7350Sstevel@tonic-gate /* 7360Sstevel@tonic-gate * 32bit sparc binaries have a padded 7370Sstevel@tonic-gate * MOVE structure. So - return the 7380Sstevel@tonic-gate * appropriate type. 7390Sstevel@tonic-gate */ 7400Sstevel@tonic-gate if ((ehdr->e_machine == EM_SPARC) || 7410Sstevel@tonic-gate (ehdr->e_machine == EM_SPARC32PLUS)) { 7420Sstevel@tonic-gate return (ELF_T_MOVEP); 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate return (ELF_T_MOVE); 7460Sstevel@tonic-gate case SHT_SUNW_COMDAT: 7470Sstevel@tonic-gate return (ELF_T_BYTE); 7480Sstevel@tonic-gate case SHT_SUNW_syminfo: 7490Sstevel@tonic-gate return (ELF_T_SYMINFO); 7500Sstevel@tonic-gate case SHT_SUNW_verdef: 7510Sstevel@tonic-gate return (ELF_T_VDEF); 7520Sstevel@tonic-gate case SHT_SUNW_verneed: 7530Sstevel@tonic-gate return (ELF_T_VNEED); 7540Sstevel@tonic-gate case SHT_SUNW_versym: 7550Sstevel@tonic-gate return (ELF_T_HALF); 7560Sstevel@tonic-gate }; 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* 7590Sstevel@tonic-gate * Check for the sparc specific section types 7600Sstevel@tonic-gate * below. 7610Sstevel@tonic-gate */ 7620Sstevel@tonic-gate if (((ehdr->e_machine == EM_SPARC) || 7630Sstevel@tonic-gate (ehdr->e_machine == EM_SPARC32PLUS) || 7640Sstevel@tonic-gate (ehdr->e_machine == EM_SPARCV9)) && 7650Sstevel@tonic-gate (shtype == SHT_SPARC_GOTDATA)) 7660Sstevel@tonic-gate return (ELF_T_BYTE); 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate /* 7690Sstevel@tonic-gate * Check for the amd64 specific section types 7700Sstevel@tonic-gate * below. 7710Sstevel@tonic-gate */ 7720Sstevel@tonic-gate if ((ehdr->e_machine == EM_AMD64) && 7730Sstevel@tonic-gate (shtype == SHT_AMD64_UNWIND)) 7740Sstevel@tonic-gate return (ELF_T_BYTE); 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate /* 7770Sstevel@tonic-gate * And the default is ELF_T_BYTE - but we should 7780Sstevel@tonic-gate * certainly have caught any sections we know about 7790Sstevel@tonic-gate * above. This is for unknown sections to libelf. 7800Sstevel@tonic-gate */ 7810Sstevel@tonic-gate return (ELF_T_BYTE); 7820Sstevel@tonic-gate} 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate 7853621Sab196087size_t 7863621Sab196087_elf32_entsz(Elf *elf, Elf32_Word shtype, unsigned ver) 7873621Sab196087{ 7883621Sab196087 Elf_Type ttype; 7893621Sab196087 7903621Sab196087 ttype = _elf32_mtype(elf, shtype, ver); 7913621Sab196087 return ((ttype == ELF_T_BYTE) ? 0 : fmsize[ver - 1][ttype].s_filesz); 7923621Sab196087} 7933621Sab196087 7943621Sab196087 7950Sstevel@tonic-gate/* 7965189Sab196087 * Determine the data encoding used by the current system. 7975189Sab196087 */ 7985189Sab196087uint_t 7995189Sab196087_elf_sys_encoding(void) 8005189Sab196087{ 8015189Sab196087 union { 8025189Sab196087 Elf32_Word w; 8035189Sab196087 unsigned char c[W_sizeof]; 8045189Sab196087 } u; 8055189Sab196087 8065189Sab196087 u.w = 0x10203; 8075189Sab196087 /*CONSTANTCONDITION*/ 8085189Sab196087 if (~(Elf32_Word)0 == -(Elf32_Sword)1 && tomw(u.c, W_L) == 0x10203) 8095189Sab196087 return (ELFDATA2LSB); 8105189Sab196087 8115189Sab196087 /*CONSTANTCONDITION*/ 8125189Sab196087 if (~(Elf32_Word)0 == -(Elf32_Sword)1 && tomw(u.c, W_M) == 0x10203) 8135189Sab196087 return (ELFDATA2MSB); 8145189Sab196087 8155189Sab196087 /* Not expected to occur */ 8165189Sab196087 return (ELFDATANONE); 8175189Sab196087} 8185189Sab196087 8195189Sab196087 8205189Sab196087/* 8210Sstevel@tonic-gate * XX64 This routine is also used to 'version' interactions with Elf64 8220Sstevel@tonic-gate * applications, but there's no way to figure out if the caller is 8230Sstevel@tonic-gate * asking Elf32 or Elf64 questions, even though it has Elf32 8240Sstevel@tonic-gate * dependencies. Ick. 8250Sstevel@tonic-gate */ 8260Sstevel@tonic-gateunsigned 8270Sstevel@tonic-gateelf_version(unsigned ver) 8280Sstevel@tonic-gate{ 8290Sstevel@tonic-gate register unsigned j; 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate if (ver == EV_NONE) 8320Sstevel@tonic-gate return EV_CURRENT; 8330Sstevel@tonic-gate if (ver > EV_CURRENT) 8340Sstevel@tonic-gate { 8350Sstevel@tonic-gate _elf_seterr(EREQ_VER, 0); 8360Sstevel@tonic-gate return EV_NONE; 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate (void) mutex_lock(&_elf_globals_mutex); 8390Sstevel@tonic-gate if (_elf_work != EV_NONE) 8400Sstevel@tonic-gate { 8410Sstevel@tonic-gate j = _elf_work; 8420Sstevel@tonic-gate _elf_work = ver; 8430Sstevel@tonic-gate (void) mutex_unlock(&_elf_globals_mutex); 8440Sstevel@tonic-gate return j; 8450Sstevel@tonic-gate } 8460Sstevel@tonic-gate _elf_work = ver; 8470Sstevel@tonic-gate 8485189Sab196087 _elf_encode = _elf_sys_encoding(); 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate (void) mutex_unlock(&_elf_globals_mutex); 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate return ver; 8530Sstevel@tonic-gate} 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate 8560Sstevel@tonic-gatestatic Elf_Data * 8570Sstevel@tonic-gatexlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) 8580Sstevel@tonic-gate /* tof !0 -> xlatetof */ 8590Sstevel@tonic-gate{ 8600Sstevel@tonic-gate size_t cnt, dsz, ssz; 8610Sstevel@tonic-gate unsigned type; 8620Sstevel@tonic-gate unsigned dver, sver; 8630Sstevel@tonic-gate void (*f)(); 8640Sstevel@tonic-gate unsigned _encode; 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate if (dst == 0 || src == 0) 8670Sstevel@tonic-gate return (0); 8680Sstevel@tonic-gate if (--encode >= (ELFDATANUM - 1)) { 8690Sstevel@tonic-gate _elf_seterr(EREQ_ENCODE, 0); 8700Sstevel@tonic-gate return (0); 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate if ((dver = dst->d_version - 1) >= EV_CURRENT || 8730Sstevel@tonic-gate (sver = src->d_version - 1) >= EV_CURRENT) { 8740Sstevel@tonic-gate _elf_seterr(EREQ_VER, 0); 8750Sstevel@tonic-gate return (0); 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate if ((type = src->d_type) >= ELF_T_NUM) { 8780Sstevel@tonic-gate _elf_seterr(EREQ_TYPE, 0); 8790Sstevel@tonic-gate return (0); 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate if (tof) { 8830Sstevel@tonic-gate dsz = fmsize[dver][type].s_filesz; 8840Sstevel@tonic-gate ssz = fmsize[sver][type].s_memsz; 8850Sstevel@tonic-gate f = x32[dver][sver][encode][type].x_tof; 8860Sstevel@tonic-gate } else { 8870Sstevel@tonic-gate dsz = fmsize[dver][type].s_memsz; 8880Sstevel@tonic-gate ssz = fmsize[sver][type].s_filesz; 8890Sstevel@tonic-gate f = x32[dver][sver][encode][type].x_tom; 8900Sstevel@tonic-gate } 8910Sstevel@tonic-gate cnt = src->d_size / ssz; 8920Sstevel@tonic-gate if (dst->d_size < dsz * cnt) { 8930Sstevel@tonic-gate _elf_seterr(EREQ_DSZ, 0); 8940Sstevel@tonic-gate return (0); 8950Sstevel@tonic-gate } 8960Sstevel@tonic-gate 8970Sstevel@tonic-gate ELFACCESSDATA(_encode, _elf_encode) 8980Sstevel@tonic-gate if ((_encode == (encode + 1)) && (dsz == ssz)) { 8990Sstevel@tonic-gate /* 9000Sstevel@tonic-gate * ld(1) frequently produces empty sections (eg. .dynsym, 9010Sstevel@tonic-gate * .dynstr, .symtab, .strtab, etc) so that the initial 9020Sstevel@tonic-gate * output image can be created of the correct size. Later 9030Sstevel@tonic-gate * these sections are filled in with the associated data. 9040Sstevel@tonic-gate * So that we don't have to pre-allocate buffers for 9050Sstevel@tonic-gate * these segments, allow for the src destination to be 0. 9060Sstevel@tonic-gate */ 9070Sstevel@tonic-gate if (src->d_buf && src->d_buf != dst->d_buf) 9080Sstevel@tonic-gate (void) memcpy(dst->d_buf, src->d_buf, src->d_size); 9090Sstevel@tonic-gate dst->d_type = src->d_type; 9100Sstevel@tonic-gate dst->d_size = src->d_size; 9110Sstevel@tonic-gate return (dst); 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate if (cnt) 9140Sstevel@tonic-gate (*f)(dst->d_buf, src->d_buf, cnt); 9150Sstevel@tonic-gate dst->d_size = dsz * cnt; 9160Sstevel@tonic-gate dst->d_type = src->d_type; 9170Sstevel@tonic-gate return (dst); 9180Sstevel@tonic-gate} 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate 9210Sstevel@tonic-gateElf_Data * 9220Sstevel@tonic-gateelf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode) 9230Sstevel@tonic-gate{ 9240Sstevel@tonic-gate return (xlate(dst, src, encode, 1)); 9250Sstevel@tonic-gate} 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate 9280Sstevel@tonic-gateElf_Data * 9290Sstevel@tonic-gateelf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode) 9300Sstevel@tonic-gate{ 9310Sstevel@tonic-gate return (xlate(dst, src, encode, 0)); 9320Sstevel@tonic-gate} 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate/* 9360Sstevel@tonic-gate * xlate to file format 9370Sstevel@tonic-gate * 9380Sstevel@tonic-gate * ..._tof(name, data) -- macros 9390Sstevel@tonic-gate * 9400Sstevel@tonic-gate * Recall that the file format must be no larger than the 9410Sstevel@tonic-gate * memory format (equal versions). Use "forward" copy. 9420Sstevel@tonic-gate * All these routines require non-null, non-zero arguments. 9430Sstevel@tonic-gate */ 9440Sstevel@tonic-gate 9450Sstevel@tonic-gatedefine(addr_tof, ` 9460Sstevel@tonic-gatestatic void 9470Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Addr *src, size_t cnt) 9480Sstevel@tonic-gate{ 9490Sstevel@tonic-gate Elf32_Addr *end = src + cnt; 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate do { 9520Sstevel@tonic-gate tofa(dst, *src, A_$2); 9530Sstevel@tonic-gate dst += A_sizeof; 9540Sstevel@tonic-gate } while (++src < end); 9550Sstevel@tonic-gate}') 9560Sstevel@tonic-gate 9570Sstevel@tonic-gateaddr_tof(addr_2L_tof,L) 9580Sstevel@tonic-gateaddr_tof(addr_2M_tof,M) 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate 9610Sstevel@tonic-gatestatic void 9620Sstevel@tonic-gatebyte_to(unsigned char *dst, unsigned char *src, size_t cnt) 9630Sstevel@tonic-gate{ 9640Sstevel@tonic-gate if (dst != src) 9650Sstevel@tonic-gate (void) memcpy(dst, src, cnt); 9660Sstevel@tonic-gate} 9670Sstevel@tonic-gate 9680Sstevel@tonic-gate 9690Sstevel@tonic-gatedefine(dyn_11_tof, ` 9700Sstevel@tonic-gatestatic void 9710Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Dyn *src, size_t cnt) 9720Sstevel@tonic-gate{ 9730Sstevel@tonic-gate Elf32_Dyn *end = src + cnt; 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate do { 9760Sstevel@tonic-gate tofw(dst, src->d_tag, D1_tag_$2); 9770Sstevel@tonic-gate tofo(dst, src->d_un.d_val, D1_val_$2); 9780Sstevel@tonic-gate dst += D1_sizeof; 9790Sstevel@tonic-gate } while (++src < end); 9800Sstevel@tonic-gate}') 9810Sstevel@tonic-gate 9820Sstevel@tonic-gatedyn_11_tof(dyn_2L11_tof,L) 9830Sstevel@tonic-gatedyn_11_tof(dyn_2M11_tof,M) 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate 9860Sstevel@tonic-gatedefine(ehdr_11_tof, ` 9870Sstevel@tonic-gatestatic void 9880Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Ehdr *src, size_t cnt) 9890Sstevel@tonic-gate{ 9900Sstevel@tonic-gate Elf32_Ehdr *end = src + cnt; 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate do { 9930Sstevel@tonic-gate if (&dst[E1_ident] != src->e_ident) 9940Sstevel@tonic-gate (void) memcpy(&dst[E1_ident], src->e_ident, E1_Nident); 9950Sstevel@tonic-gate tofh(dst, src->e_type, E1_type_$2); 9960Sstevel@tonic-gate tofh(dst, src->e_machine, E1_machine_$2); 9970Sstevel@tonic-gate tofw(dst, src->e_version, E1_version_$2); 9980Sstevel@tonic-gate tofa(dst, src->e_entry, E1_entry_$2); 9990Sstevel@tonic-gate tofo(dst, src->e_phoff, E1_phoff_$2); 10000Sstevel@tonic-gate tofo(dst, src->e_shoff, E1_shoff_$2); 10010Sstevel@tonic-gate tofw(dst, src->e_flags, E1_flags_$2); 10020Sstevel@tonic-gate tofh(dst, src->e_ehsize, E1_ehsize_$2); 10030Sstevel@tonic-gate tofh(dst, src->e_phentsize, E1_phentsize_$2); 10040Sstevel@tonic-gate tofh(dst, src->e_phnum, E1_phnum_$2); 10050Sstevel@tonic-gate tofh(dst, src->e_shentsize, E1_shentsize_$2); 10060Sstevel@tonic-gate tofh(dst, src->e_shnum, E1_shnum_$2); 10070Sstevel@tonic-gate tofh(dst, src->e_shstrndx, E1_shstrndx_$2); 10080Sstevel@tonic-gate dst += E1_sizeof; 10090Sstevel@tonic-gate } while (++src < end); 10100Sstevel@tonic-gate}') 10110Sstevel@tonic-gate 10120Sstevel@tonic-gateehdr_11_tof(ehdr_2L11_tof,L) 10130Sstevel@tonic-gateehdr_11_tof(ehdr_2M11_tof,M) 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate 10160Sstevel@tonic-gatedefine(half_tof, ` 10170Sstevel@tonic-gatestatic void 10180Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Half *src, size_t cnt) 10190Sstevel@tonic-gate{ 10200Sstevel@tonic-gate Elf32_Half *end = src + cnt; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate do { 10230Sstevel@tonic-gate tofh(dst, *src, H_$2); 10240Sstevel@tonic-gate dst += H_sizeof; 10250Sstevel@tonic-gate } while (++src < end); 10260Sstevel@tonic-gate}') 10270Sstevel@tonic-gate 10280Sstevel@tonic-gatehalf_tof(half_2L_tof,L) 10290Sstevel@tonic-gatehalf_tof(half_2M_tof,M) 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate 10320Sstevel@tonic-gatedefine(move_11_tof, ` 10330Sstevel@tonic-gatestatic void 10340Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Move *src, size_t cnt) 10350Sstevel@tonic-gate{ 10360Sstevel@tonic-gate Elf32_Move *end = src + cnt; 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate do { 10390Sstevel@tonic-gate tofl(dst, src->m_value, M1_value_$2); 10400Sstevel@tonic-gate tofw(dst, src->m_info, M1_info_$2); 10410Sstevel@tonic-gate tofw(dst, src->m_poffset, M1_poffset_$2); 10420Sstevel@tonic-gate tofh(dst, src->m_repeat, M1_repeat_$2); 10430Sstevel@tonic-gate tofh(dst, src->m_stride, M1_stride_$2); 10440Sstevel@tonic-gate dst += M1_sizeof; 10450Sstevel@tonic-gate } while (++src < end); 10460Sstevel@tonic-gate}') 10470Sstevel@tonic-gate 10480Sstevel@tonic-gatemove_11_tof(move_2L11_tof,L) 10490Sstevel@tonic-gatemove_11_tof(move_2M11_tof,M) 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate 10520Sstevel@tonic-gatedefine(movep_11_tof, ` 10530Sstevel@tonic-gatestatic void 10540Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Move *src, size_t cnt) 10550Sstevel@tonic-gate{ 10560Sstevel@tonic-gate Elf32_Move *end = src + cnt; 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate do { 10590Sstevel@tonic-gate tofl(dst, src->m_value, MP1_value_$2); 10600Sstevel@tonic-gate tofw(dst, src->m_info, MP1_info_$2); 10610Sstevel@tonic-gate tofw(dst, src->m_poffset, MP1_poffset_$2); 10620Sstevel@tonic-gate tofh(dst, src->m_repeat, MP1_repeat_$2); 10630Sstevel@tonic-gate tofh(dst, src->m_stride, MP1_stride_$2); 10640Sstevel@tonic-gate dst += MP1_sizeof; 10650Sstevel@tonic-gate } while (++src < end); 10660Sstevel@tonic-gate}') 10670Sstevel@tonic-gate 10680Sstevel@tonic-gatemovep_11_tof(movep_2L11_tof,L) 10690Sstevel@tonic-gatemovep_11_tof(movep_2M11_tof,M) 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate 10720Sstevel@tonic-gatedefine(off_tof, ` 10730Sstevel@tonic-gatestatic void 10740Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Off *src, size_t cnt) 10750Sstevel@tonic-gate{ 10760Sstevel@tonic-gate Elf32_Off *end = src + cnt; 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate do { 10790Sstevel@tonic-gate tofo(dst, *src, O_$2); 10800Sstevel@tonic-gate dst += O_sizeof; 10810Sstevel@tonic-gate } while (++src < end); 10820Sstevel@tonic-gate}') 10830Sstevel@tonic-gate 10840Sstevel@tonic-gateoff_tof(off_2L_tof,L) 10850Sstevel@tonic-gateoff_tof(off_2M_tof,M) 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate 10880Sstevel@tonic-gatedefine(note_11_tof, ` 10890Sstevel@tonic-gatestatic void 10900Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Nhdr *src, size_t cnt) 10910Sstevel@tonic-gate{ 10920Sstevel@tonic-gate /* LINTED */ 1093*11957SAli.Bahrami@Sun.COM Elf32_Nhdr *end = (Elf32_Nhdr *)((char *)src + cnt); 10940Sstevel@tonic-gate 1095*11957SAli.Bahrami@Sun.COM /* 1096*11957SAli.Bahrami@Sun.COM * Copy the note data to the source, translating the 1097*11957SAli.Bahrami@Sun.COM * length fields. Clip against the size of the actual buffer 1098*11957SAli.Bahrami@Sun.COM * to guard against corrupt note data. 1099*11957SAli.Bahrami@Sun.COM */ 11000Sstevel@tonic-gate do { 11010Sstevel@tonic-gate Elf32_Word descsz, namesz; 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate /* 11040Sstevel@tonic-gate * cache size of desc & name fields - while rounding 11050Sstevel@tonic-gate * up their size. 11060Sstevel@tonic-gate */ 11070Sstevel@tonic-gate namesz = S_ROUND(src->n_namesz, sizeof (Elf32_Word)); 11080Sstevel@tonic-gate descsz = src->n_descsz; 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate /* 11110Sstevel@tonic-gate * Copy contents of Elf32_Nhdr 11120Sstevel@tonic-gate */ 1113*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_namesz) + sizeof(Elf32_Word) + 1114*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1115*11957SAli.Bahrami@Sun.COM break; 11160Sstevel@tonic-gate tofw(dst, src->n_namesz, N1_namesz_$2); 1117*11957SAli.Bahrami@Sun.COM 1118*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_descsz) + sizeof(Elf32_Word) + 1119*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1120*11957SAli.Bahrami@Sun.COM break; 11210Sstevel@tonic-gate tofw(dst, src->n_descsz, N1_descsz_$2); 1122*11957SAli.Bahrami@Sun.COM 1123*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_type) + sizeof(Elf32_Word) + 1124*11957SAli.Bahrami@Sun.COM (char *) src) >= (char *) end) 1125*11957SAli.Bahrami@Sun.COM break; 11260Sstevel@tonic-gate tofw(dst, src->n_type, N1_type_$2); 11270Sstevel@tonic-gate 11280Sstevel@tonic-gate /* 11290Sstevel@tonic-gate * Copy contents of Name field 11300Sstevel@tonic-gate */ 11310Sstevel@tonic-gate dst += N1_sizeof; 11320Sstevel@tonic-gate src++; 1133*11957SAli.Bahrami@Sun.COM if ((namesz + (char *) src) > (char *) end) { 1134*11957SAli.Bahrami@Sun.COM namesz = (char *) end - (char *) src; 1135*11957SAli.Bahrami@Sun.COM if (namesz == 0) 1136*11957SAli.Bahrami@Sun.COM break; 1137*11957SAli.Bahrami@Sun.COM } 11380Sstevel@tonic-gate (void)memcpy(dst, src, namesz); 11390Sstevel@tonic-gate 11400Sstevel@tonic-gate /* 11410Sstevel@tonic-gate * Copy contents of desc field 11420Sstevel@tonic-gate */ 11430Sstevel@tonic-gate dst += namesz; 11440Sstevel@tonic-gate src = (Elf32_Nhdr *)((uintptr_t)src + namesz); 1145*11957SAli.Bahrami@Sun.COM if ((descsz + (char *) src) > (char *) end) { 1146*11957SAli.Bahrami@Sun.COM descsz = (char *) end - (char *) src; 1147*11957SAli.Bahrami@Sun.COM if (descsz == 0) 1148*11957SAli.Bahrami@Sun.COM break; 1149*11957SAli.Bahrami@Sun.COM } 11500Sstevel@tonic-gate (void)memcpy(dst, src, descsz); 1151*11957SAli.Bahrami@Sun.COM 11520Sstevel@tonic-gate descsz = S_ROUND(descsz, sizeof (Elf32_Word)); 11530Sstevel@tonic-gate dst += descsz; 11540Sstevel@tonic-gate src = (Elf32_Nhdr *)((uintptr_t)src + descsz); 11550Sstevel@tonic-gate } while (src < end); 11560Sstevel@tonic-gate}') 11570Sstevel@tonic-gate 11580Sstevel@tonic-gatenote_11_tof(note_2L11_tof,L) 11590Sstevel@tonic-gatenote_11_tof(note_2M11_tof,M) 11600Sstevel@tonic-gate 11610Sstevel@tonic-gate 11620Sstevel@tonic-gatedefine(phdr_11_tof, ` 11630Sstevel@tonic-gatestatic void 11640Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Phdr *src, size_t cnt) 11650Sstevel@tonic-gate{ 11660Sstevel@tonic-gate Elf32_Phdr *end = src + cnt; 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate do { 11690Sstevel@tonic-gate tofw(dst, src->p_type, P1_type_$2); 11700Sstevel@tonic-gate tofo(dst, src->p_offset, P1_offset_$2); 11710Sstevel@tonic-gate tofa(dst, src->p_vaddr, P1_vaddr_$2); 11720Sstevel@tonic-gate tofa(dst, src->p_paddr, P1_paddr_$2); 11730Sstevel@tonic-gate tofw(dst, src->p_filesz, P1_filesz_$2); 11740Sstevel@tonic-gate tofw(dst, src->p_memsz, P1_memsz_$2); 11750Sstevel@tonic-gate tofw(dst, src->p_flags, P1_flags_$2); 11760Sstevel@tonic-gate tofw(dst, src->p_align, P1_align_$2); 11770Sstevel@tonic-gate dst += P1_sizeof; 11780Sstevel@tonic-gate } while (++src < end); 11790Sstevel@tonic-gate}') 11800Sstevel@tonic-gate 11810Sstevel@tonic-gatephdr_11_tof(phdr_2L11_tof,L) 11820Sstevel@tonic-gatephdr_11_tof(phdr_2M11_tof,M) 11830Sstevel@tonic-gate 11840Sstevel@tonic-gate 11850Sstevel@tonic-gatedefine(rel_11_tof, ` 11860Sstevel@tonic-gatestatic void 11870Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Rel *src, size_t cnt) 11880Sstevel@tonic-gate{ 11890Sstevel@tonic-gate Elf32_Rel *end = src + cnt; 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate do { 11920Sstevel@tonic-gate tofa(dst, src->r_offset, R1_offset_$2); 11930Sstevel@tonic-gate tofw(dst, src->r_info, R1_info_$2); 11940Sstevel@tonic-gate dst += R1_sizeof; 11950Sstevel@tonic-gate } while (++src < end); 11960Sstevel@tonic-gate}') 11970Sstevel@tonic-gate 11980Sstevel@tonic-gaterel_11_tof(rel_2L11_tof,L) 11990Sstevel@tonic-gaterel_11_tof(rel_2M11_tof,M) 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate 12020Sstevel@tonic-gatedefine(rela_11_tof, ` 12030Sstevel@tonic-gatestatic void 12040Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Rela *src, size_t cnt) 12050Sstevel@tonic-gate{ 12060Sstevel@tonic-gate Elf32_Rela *end = src + cnt; 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate do { 12090Sstevel@tonic-gate tofa(dst, src->r_offset, RA1_offset_$2); 12100Sstevel@tonic-gate tofw(dst, src->r_info, RA1_info_$2); 12110Sstevel@tonic-gate /*CONSTANTCONDITION*/ 12120Sstevel@tonic-gate if (~(Elf32_Word)0 == -(Elf32_Sword)1) { /* 2s comp */ 12130Sstevel@tonic-gate tofw(dst, src->r_addend, RA1_addend_$2); 12140Sstevel@tonic-gate } else { 12150Sstevel@tonic-gate Elf32_Word w; 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate if (src->r_addend < 0) { 12180Sstevel@tonic-gate w = - src->r_addend; 12190Sstevel@tonic-gate w = ~w + 1; 12200Sstevel@tonic-gate } else 12210Sstevel@tonic-gate w = src->r_addend; 12220Sstevel@tonic-gate tofw(dst, w, RA1_addend_$2); 12230Sstevel@tonic-gate } 12240Sstevel@tonic-gate dst += RA1_sizeof; 12250Sstevel@tonic-gate } while (++src < end); 12260Sstevel@tonic-gate}') 12270Sstevel@tonic-gate 12280Sstevel@tonic-gaterela_11_tof(rela_2L11_tof,L) 12290Sstevel@tonic-gaterela_11_tof(rela_2M11_tof,M) 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate 12320Sstevel@tonic-gatedefine(shdr_11_tof, ` 12330Sstevel@tonic-gatestatic void 12340Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Shdr *src, size_t cnt) 12350Sstevel@tonic-gate{ 12360Sstevel@tonic-gate Elf32_Shdr *end = src + cnt; 12370Sstevel@tonic-gate 12380Sstevel@tonic-gate do { 12390Sstevel@tonic-gate tofw(dst, src->sh_name, SH1_name_$2); 12400Sstevel@tonic-gate tofw(dst, src->sh_type, SH1_type_$2); 12410Sstevel@tonic-gate tofw(dst, src->sh_flags, SH1_flags_$2); 12420Sstevel@tonic-gate tofa(dst, src->sh_addr, SH1_addr_$2); 12430Sstevel@tonic-gate tofo(dst, src->sh_offset, SH1_offset_$2); 12440Sstevel@tonic-gate tofw(dst, src->sh_size, SH1_size_$2); 12450Sstevel@tonic-gate tofw(dst, src->sh_link, SH1_link_$2); 12460Sstevel@tonic-gate tofw(dst, src->sh_info, SH1_info_$2); 12470Sstevel@tonic-gate tofw(dst, src->sh_addralign, SH1_addralign_$2); 12480Sstevel@tonic-gate tofw(dst, src->sh_entsize, SH1_entsize_$2); 12490Sstevel@tonic-gate dst += SH1_sizeof; 12500Sstevel@tonic-gate } while (++src < end); 12510Sstevel@tonic-gate}') 12520Sstevel@tonic-gate 12530Sstevel@tonic-gateshdr_11_tof(shdr_2L11_tof,L) 12540Sstevel@tonic-gateshdr_11_tof(shdr_2M11_tof,M) 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate 12570Sstevel@tonic-gatedefine(sword_tof, ` 12580Sstevel@tonic-gatestatic void 12590Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Sword *src, size_t cnt) 12600Sstevel@tonic-gate{ 12610Sstevel@tonic-gate Elf32_Sword *end = src + cnt; 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate do { 12640Sstevel@tonic-gate /*CONSTANTCONDITION*/ 12650Sstevel@tonic-gate if (~(Elf32_Word)0 == -(Elf32_Sword)1) { /* 2s comp */ 12660Sstevel@tonic-gate tofw(dst, *src, W_$2); 12670Sstevel@tonic-gate } else { 12680Sstevel@tonic-gate Elf32_Word w; 12690Sstevel@tonic-gate 12700Sstevel@tonic-gate if (*src < 0) { 12710Sstevel@tonic-gate w = - *src; 12720Sstevel@tonic-gate w = ~w + 1; 12730Sstevel@tonic-gate } else 12740Sstevel@tonic-gate w = *src; 12750Sstevel@tonic-gate tofw(dst, w, W_$2); 12760Sstevel@tonic-gate } 12770Sstevel@tonic-gate dst += W_sizeof; 12780Sstevel@tonic-gate } while (++src < end); 12790Sstevel@tonic-gate}') 12800Sstevel@tonic-gate 12810Sstevel@tonic-gatesword_tof(sword_2L_tof,L) 12820Sstevel@tonic-gatesword_tof(sword_2M_tof,M) 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate 12850Sstevel@tonic-gatedefine(cap_11_tof, ` 12860Sstevel@tonic-gatestatic void 12870Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Cap *src, size_t cnt) 12880Sstevel@tonic-gate{ 12890Sstevel@tonic-gate Elf32_Cap *end = src + cnt; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate do { 12920Sstevel@tonic-gate tofw(dst, src->c_tag, C1_tag_$2); 12930Sstevel@tonic-gate tofw(dst, src->c_un.c_val, C1_val_$2); 12940Sstevel@tonic-gate dst += C1_sizeof; 12950Sstevel@tonic-gate } while (++src < end); 12960Sstevel@tonic-gate}') 12970Sstevel@tonic-gate 12980Sstevel@tonic-gatecap_11_tof(cap_2L11_tof,L) 12990Sstevel@tonic-gatecap_11_tof(cap_2M11_tof,M) 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate 13020Sstevel@tonic-gatedefine(syminfo_11_tof, ` 13030Sstevel@tonic-gatestatic void 13040Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Syminfo *src, size_t cnt) 13050Sstevel@tonic-gate{ 13060Sstevel@tonic-gate Elf32_Syminfo *end = src + cnt; 13070Sstevel@tonic-gate 13080Sstevel@tonic-gate do { 13090Sstevel@tonic-gate tofh(dst, src->si_boundto, SI1_boundto_$2); 13100Sstevel@tonic-gate tofh(dst, src->si_flags, SI1_flags_$2); 13110Sstevel@tonic-gate dst += SI1_sizeof; 13120Sstevel@tonic-gate } while (++src < end); 13130Sstevel@tonic-gate}') 13140Sstevel@tonic-gate 13150Sstevel@tonic-gatesyminfo_11_tof(syminfo_2L11_tof,L) 13160Sstevel@tonic-gatesyminfo_11_tof(syminfo_2M11_tof,M) 13170Sstevel@tonic-gate 13180Sstevel@tonic-gate 13190Sstevel@tonic-gatedefine(sym_11_tof, ` 13200Sstevel@tonic-gatestatic void 13210Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Sym *src, size_t cnt) 13220Sstevel@tonic-gate{ 13230Sstevel@tonic-gate Elf32_Sym *end = src + cnt; 13240Sstevel@tonic-gate 13250Sstevel@tonic-gate do { 13260Sstevel@tonic-gate tofw(dst, src->st_name, ST1_name_$2); 13270Sstevel@tonic-gate tofa(dst, src->st_value, ST1_value_$2); 13280Sstevel@tonic-gate tofw(dst, src->st_size, ST1_size_$2); 13290Sstevel@tonic-gate tofb(dst, src->st_info, ST1_info_$2); 13300Sstevel@tonic-gate tofb(dst, src->st_other, ST1_other_$2); 13310Sstevel@tonic-gate tofh(dst, src->st_shndx, ST1_shndx_$2); 13320Sstevel@tonic-gate dst += ST1_sizeof; 13330Sstevel@tonic-gate } while (++src < end); 13340Sstevel@tonic-gate}') 13350Sstevel@tonic-gate 13360Sstevel@tonic-gatesym_11_tof(sym_2L11_tof,L) 13370Sstevel@tonic-gatesym_11_tof(sym_2M11_tof,M) 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate 13400Sstevel@tonic-gatedefine(word_tof, ` 13410Sstevel@tonic-gatestatic void 13420Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Word *src, size_t cnt) 13430Sstevel@tonic-gate{ 13440Sstevel@tonic-gate Elf32_Word *end = src + cnt; 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate do { 13470Sstevel@tonic-gate tofw(dst, *src, W_$2); 13480Sstevel@tonic-gate dst += W_sizeof; 13490Sstevel@tonic-gate } while (++src < end); 13500Sstevel@tonic-gate}') 13510Sstevel@tonic-gate 13520Sstevel@tonic-gateword_tof(word_2L_tof,L) 13530Sstevel@tonic-gateword_tof(word_2M_tof,M) 13540Sstevel@tonic-gate 13550Sstevel@tonic-gate 13560Sstevel@tonic-gatedefine(verdef_11_tof, ` 13570Sstevel@tonic-gatestatic void 13580Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Verdef *src, size_t cnt) 13590Sstevel@tonic-gate{ 13600Sstevel@tonic-gate /* LINTED */ 13610Sstevel@tonic-gate Elf32_Verdef *end = (Elf32_Verdef *)((char *)src + cnt); 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate do { 13640Sstevel@tonic-gate Elf32_Verdef *next_verdef; 13650Sstevel@tonic-gate Elf32_Verdaux *vaux; 13660Sstevel@tonic-gate Elf32_Half i; 13670Sstevel@tonic-gate unsigned char *vaux_dst; 13680Sstevel@tonic-gate unsigned char *dst_next; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate /* LINTED */ 13710Sstevel@tonic-gate next_verdef = (Elf32_Verdef *)(src->vd_next ? 13720Sstevel@tonic-gate (char *)src + src->vd_next : (char *)end); 13730Sstevel@tonic-gate dst_next = dst + src->vd_next; 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate /* LINTED */ 13760Sstevel@tonic-gate vaux = (Elf32_Verdaux *)((char *)src + src->vd_aux); 13770Sstevel@tonic-gate vaux_dst = dst + src->vd_aux; 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate /* 13800Sstevel@tonic-gate * Convert auxilary structures 13810Sstevel@tonic-gate */ 13820Sstevel@tonic-gate for (i = 0; i < src->vd_cnt; i++) { 13830Sstevel@tonic-gate Elf32_Verdaux *vaux_next; 13840Sstevel@tonic-gate unsigned char *vaux_dst_next; 13850Sstevel@tonic-gate 13860Sstevel@tonic-gate /* 13870Sstevel@tonic-gate * because our source and destination can be 13880Sstevel@tonic-gate * the same place we need to figure out the next 13890Sstevel@tonic-gate * location now. 13900Sstevel@tonic-gate */ 13910Sstevel@tonic-gate /* LINTED */ 13920Sstevel@tonic-gate vaux_next = (Elf32_Verdaux *)((char *)vaux + 13930Sstevel@tonic-gate vaux->vda_next); 13940Sstevel@tonic-gate vaux_dst_next = vaux_dst + vaux->vda_next; 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate tofa(vaux_dst, vaux->vda_name, VDA1_name_$2); 13970Sstevel@tonic-gate tofw(vaux_dst, vaux->vda_next, VDA1_next_$2); 13980Sstevel@tonic-gate vaux_dst = vaux_dst_next; 13990Sstevel@tonic-gate vaux = vaux_next; 14000Sstevel@tonic-gate } 14010Sstevel@tonic-gate 14020Sstevel@tonic-gate /* 14030Sstevel@tonic-gate * Convert Elf32_Verdef structure. 14040Sstevel@tonic-gate */ 14050Sstevel@tonic-gate tofh(dst, src->vd_version, VD1_version_$2); 14060Sstevel@tonic-gate tofh(dst, src->vd_flags, VD1_flags_$2); 14070Sstevel@tonic-gate tofh(dst, src->vd_ndx, VD1_ndx_$2); 14080Sstevel@tonic-gate tofh(dst, src->vd_cnt, VD1_cnt_$2); 14090Sstevel@tonic-gate tofw(dst, src->vd_hash, VD1_hash_$2); 14100Sstevel@tonic-gate tofw(dst, src->vd_aux, VD1_aux_$2); 14110Sstevel@tonic-gate tofw(dst, src->vd_next, VD1_next_$2); 14120Sstevel@tonic-gate src = next_verdef; 14130Sstevel@tonic-gate dst = dst_next; 14140Sstevel@tonic-gate } while (src < end); 14150Sstevel@tonic-gate}') 14160Sstevel@tonic-gate 14170Sstevel@tonic-gateverdef_11_tof(verdef_2L11_tof, L) 14180Sstevel@tonic-gateverdef_11_tof(verdef_2M11_tof, M) 14190Sstevel@tonic-gate 14200Sstevel@tonic-gatedefine(verneed_11_tof, ` 14210Sstevel@tonic-gatestatic void 14220Sstevel@tonic-gate$1(unsigned char *dst, Elf32_Verneed *src, size_t cnt) 14230Sstevel@tonic-gate{ 14240Sstevel@tonic-gate /* LINTED */ 14250Sstevel@tonic-gate Elf32_Verneed *end = (Elf32_Verneed *)((char *)src + cnt); 14260Sstevel@tonic-gate 14270Sstevel@tonic-gate do { 14280Sstevel@tonic-gate Elf32_Verneed *next_verneed; 14290Sstevel@tonic-gate Elf32_Vernaux *vaux; 14300Sstevel@tonic-gate Elf32_Half i; 14310Sstevel@tonic-gate unsigned char *vaux_dst; 14320Sstevel@tonic-gate unsigned char *dst_next; 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate /* LINTED */ 14350Sstevel@tonic-gate next_verneed = (Elf32_Verneed *)(src->vn_next ? 14360Sstevel@tonic-gate (char *)src + src->vn_next : (char *)end); 14370Sstevel@tonic-gate dst_next = dst + src->vn_next; 14380Sstevel@tonic-gate 14390Sstevel@tonic-gate /* LINTED */ 14400Sstevel@tonic-gate vaux = (Elf32_Vernaux *)((char *)src + src->vn_aux); 14410Sstevel@tonic-gate vaux_dst = dst + src->vn_aux; 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate /* 14440Sstevel@tonic-gate * Convert auxilary structures first 14450Sstevel@tonic-gate */ 14460Sstevel@tonic-gate for (i = 0; i < src->vn_cnt; i++) { 14470Sstevel@tonic-gate Elf32_Vernaux * vaux_next; 14480Sstevel@tonic-gate unsigned char * vaux_dst_next; 14490Sstevel@tonic-gate 14500Sstevel@tonic-gate /* 14510Sstevel@tonic-gate * because our source and destination can be 14520Sstevel@tonic-gate * the same place we need to figure out the 14530Sstevel@tonic-gate * next location now. 14540Sstevel@tonic-gate */ 14550Sstevel@tonic-gate /* LINTED */ 14560Sstevel@tonic-gate vaux_next = (Elf32_Vernaux *)((char *)vaux + 14570Sstevel@tonic-gate vaux->vna_next); 14580Sstevel@tonic-gate vaux_dst_next = vaux_dst + vaux->vna_next; 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate tofw(vaux_dst, vaux->vna_hash, VNA1_hash_$2); 14610Sstevel@tonic-gate tofh(vaux_dst, vaux->vna_flags, VNA1_flags_$2); 14620Sstevel@tonic-gate tofh(vaux_dst, vaux->vna_other, VNA1_other_$2); 14630Sstevel@tonic-gate tofa(vaux_dst, vaux->vna_name, VNA1_name_$2); 14640Sstevel@tonic-gate tofw(vaux_dst, vaux->vna_next, VNA1_next_$2); 14650Sstevel@tonic-gate vaux_dst = vaux_dst_next; 14660Sstevel@tonic-gate vaux = vaux_next; 14670Sstevel@tonic-gate } 14680Sstevel@tonic-gate /* 14690Sstevel@tonic-gate * Convert Elf32_Verneed structure. 14700Sstevel@tonic-gate */ 14710Sstevel@tonic-gate tofh(dst, src->vn_version, VN1_version_$2); 14720Sstevel@tonic-gate tofh(dst, src->vn_cnt, VN1_cnt_$2); 14730Sstevel@tonic-gate tofa(dst, src->vn_file, VN1_file_$2); 14740Sstevel@tonic-gate tofw(dst, src->vn_aux, VN1_aux_$2); 14750Sstevel@tonic-gate tofw(dst, src->vn_next, VN1_next_$2); 14760Sstevel@tonic-gate src = next_verneed; 14770Sstevel@tonic-gate dst = dst_next; 14780Sstevel@tonic-gate } while (src < end); 14790Sstevel@tonic-gate}') 14800Sstevel@tonic-gate 14810Sstevel@tonic-gateverneed_11_tof(verneed_2L11_tof, L) 14820Sstevel@tonic-gateverneed_11_tof(verneed_2M11_tof, M) 14830Sstevel@tonic-gate 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate/* xlate to memory format 14860Sstevel@tonic-gate * 14870Sstevel@tonic-gate * ..._tom(name, data) -- macros 14880Sstevel@tonic-gate * 14890Sstevel@tonic-gate * Recall that the memory format may be larger than the 14900Sstevel@tonic-gate * file format (equal versions). Use "backward" copy. 14910Sstevel@tonic-gate * All these routines require non-null, non-zero arguments. 14920Sstevel@tonic-gate */ 14930Sstevel@tonic-gate 14940Sstevel@tonic-gate 14950Sstevel@tonic-gatedefine(addr_tom, ` 14960Sstevel@tonic-gatestatic void 14970Sstevel@tonic-gate$1(Elf32_Addr *dst, unsigned char *src, size_t cnt) 14980Sstevel@tonic-gate{ 14990Sstevel@tonic-gate Elf32_Addr *end = dst; 15000Sstevel@tonic-gate 15010Sstevel@tonic-gate dst += cnt; 15020Sstevel@tonic-gate src += cnt * A_sizeof; 15030Sstevel@tonic-gate while (dst-- > end) { 15040Sstevel@tonic-gate src -= A_sizeof; 15050Sstevel@tonic-gate *dst = toma(src, A_$2); 15060Sstevel@tonic-gate } 15070Sstevel@tonic-gate}') 15080Sstevel@tonic-gate 15090Sstevel@tonic-gateaddr_tom(addr_2L_tom,L) 15100Sstevel@tonic-gateaddr_tom(addr_2M_tom,M) 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate 15130Sstevel@tonic-gatedefine(dyn_11_tom, ` 15140Sstevel@tonic-gatestatic void 15150Sstevel@tonic-gate$1(Elf32_Dyn *dst, unsigned char *src, size_t cnt) 15160Sstevel@tonic-gate{ 15170Sstevel@tonic-gate Elf32_Dyn *end = dst + cnt; 15180Sstevel@tonic-gate 15190Sstevel@tonic-gate do { 15200Sstevel@tonic-gate dst->d_tag = tomw(src, D1_tag_$2); 15210Sstevel@tonic-gate dst->d_un.d_val = tomw(src, D1_val_$2); 15220Sstevel@tonic-gate src += D1_sizeof; 15230Sstevel@tonic-gate } while (++dst < end); 15240Sstevel@tonic-gate}') 15250Sstevel@tonic-gate 15260Sstevel@tonic-gatedyn_11_tom(dyn_2L11_tom,L) 15270Sstevel@tonic-gatedyn_11_tom(dyn_2M11_tom,M) 15280Sstevel@tonic-gate 15290Sstevel@tonic-gate 15300Sstevel@tonic-gatedefine(ehdr_11_tom, ` 15310Sstevel@tonic-gatestatic void 15320Sstevel@tonic-gate$1(Elf32_Ehdr *dst, unsigned char *src, size_t cnt) 15330Sstevel@tonic-gate{ 15340Sstevel@tonic-gate Elf32_Ehdr *end = dst; 15350Sstevel@tonic-gate 15360Sstevel@tonic-gate dst += cnt; 15370Sstevel@tonic-gate src += cnt * E1_sizeof; 15380Sstevel@tonic-gate while (dst-- > end) { 15390Sstevel@tonic-gate src -= E1_sizeof; 15400Sstevel@tonic-gate dst->e_shstrndx = tomh(src, E1_shstrndx_$2); 15410Sstevel@tonic-gate dst->e_shnum = tomh(src, E1_shnum_$2); 15420Sstevel@tonic-gate dst->e_shentsize = tomh(src, E1_shentsize_$2); 15430Sstevel@tonic-gate dst->e_phnum = tomh(src, E1_phnum_$2); 15440Sstevel@tonic-gate dst->e_phentsize = tomh(src, E1_phentsize_$2); 15450Sstevel@tonic-gate dst->e_ehsize = tomh(src, E1_ehsize_$2); 15460Sstevel@tonic-gate dst->e_flags = tomw(src, E1_flags_$2); 15470Sstevel@tonic-gate dst->e_shoff = tomo(src, E1_shoff_$2); 15480Sstevel@tonic-gate dst->e_phoff = tomo(src, E1_phoff_$2); 15490Sstevel@tonic-gate dst->e_entry = toma(src, E1_entry_$2); 15500Sstevel@tonic-gate dst->e_version = tomw(src, E1_version_$2); 15510Sstevel@tonic-gate dst->e_machine = tomh(src, E1_machine_$2); 15520Sstevel@tonic-gate dst->e_type = tomh(src, E1_type_$2); 15530Sstevel@tonic-gate if (dst->e_ident != &src[E1_ident]) 15540Sstevel@tonic-gate (void) memcpy(dst->e_ident, &src[E1_ident], E1_Nident); 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate}') 15570Sstevel@tonic-gate 15580Sstevel@tonic-gateehdr_11_tom(ehdr_2L11_tom,L) 15590Sstevel@tonic-gateehdr_11_tom(ehdr_2M11_tom,M) 15600Sstevel@tonic-gate 15610Sstevel@tonic-gate 15620Sstevel@tonic-gatedefine(half_tom, ` 15630Sstevel@tonic-gatestatic void 15640Sstevel@tonic-gate$1(Elf32_Half *dst, unsigned char *src, size_t cnt) 15650Sstevel@tonic-gate{ 15660Sstevel@tonic-gate Elf32_Half *end = dst; 15670Sstevel@tonic-gate 15680Sstevel@tonic-gate dst += cnt; 15690Sstevel@tonic-gate src += cnt * H_sizeof; 15700Sstevel@tonic-gate while (dst-- > end) { 15710Sstevel@tonic-gate src -= H_sizeof; 15720Sstevel@tonic-gate *dst = tomh(src, H_$2); 15730Sstevel@tonic-gate } 15740Sstevel@tonic-gate}') 15750Sstevel@tonic-gate 15760Sstevel@tonic-gatehalf_tom(half_2L_tom,L) 15770Sstevel@tonic-gatehalf_tom(half_2M_tom,M) 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate 15800Sstevel@tonic-gatedefine(move_11_tom, ` 15810Sstevel@tonic-gatestatic void 15820Sstevel@tonic-gate$1(Elf32_Move *dst, unsigned char *src, size_t cnt) 15830Sstevel@tonic-gate{ 15840Sstevel@tonic-gate Elf32_Move *end = dst + cnt; 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate do { 15870Sstevel@tonic-gate dst->m_value = toml(src, M1_value_$2); 15880Sstevel@tonic-gate dst->m_info = tomw(src, M1_info_$2); 15890Sstevel@tonic-gate dst->m_poffset = tomw(src, M1_poffset_$2); 15900Sstevel@tonic-gate dst->m_repeat = tomh(src, M1_repeat_$2); 15910Sstevel@tonic-gate dst->m_stride = tomh(src, M1_stride_$2); 15920Sstevel@tonic-gate src += M1_sizeof; 15930Sstevel@tonic-gate } while (++dst < end); 15940Sstevel@tonic-gate}') 15950Sstevel@tonic-gate 15960Sstevel@tonic-gatemove_11_tom(move_2L11_tom,L) 15970Sstevel@tonic-gatemove_11_tom(move_2M11_tom,M) 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate 16000Sstevel@tonic-gatedefine(movep_11_tom, ` 16010Sstevel@tonic-gatestatic void 16020Sstevel@tonic-gate$1(Elf32_Move *dst, unsigned char *src, size_t cnt) 16030Sstevel@tonic-gate{ 16040Sstevel@tonic-gate Elf32_Move *end = dst + cnt; 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate do 16070Sstevel@tonic-gate { 16080Sstevel@tonic-gate dst->m_value = toml(src, MP1_value_$2); 16090Sstevel@tonic-gate dst->m_info = tomw(src, MP1_info_$2); 16100Sstevel@tonic-gate dst->m_poffset = tomw(src, MP1_poffset_$2); 16110Sstevel@tonic-gate dst->m_repeat = tomh(src, MP1_repeat_$2); 16120Sstevel@tonic-gate dst->m_stride = tomh(src, MP1_stride_$2); 16130Sstevel@tonic-gate src += MP1_sizeof; 16140Sstevel@tonic-gate } while (++dst < end); 16150Sstevel@tonic-gate}') 16160Sstevel@tonic-gate 16170Sstevel@tonic-gatemovep_11_tom(movep_2L11_tom,L) 16180Sstevel@tonic-gatemovep_11_tom(movep_2M11_tom,M) 16190Sstevel@tonic-gate 16200Sstevel@tonic-gate 16210Sstevel@tonic-gatedefine(note_11_tom, ` 16220Sstevel@tonic-gatestatic void 16230Sstevel@tonic-gate$1(Elf32_Nhdr *dst, unsigned char *src, size_t cnt) 16240Sstevel@tonic-gate{ 16250Sstevel@tonic-gate /* LINTED */ 16260Sstevel@tonic-gate Elf32_Nhdr *end = (Elf32_Nhdr *)((char *)dst + cnt); 16270Sstevel@tonic-gate 1628*11957SAli.Bahrami@Sun.COM /* 1629*11957SAli.Bahrami@Sun.COM * Copy the note data to the destination, translating the 1630*11957SAli.Bahrami@Sun.COM * length fields. Clip against the size of the actual buffer 1631*11957SAli.Bahrami@Sun.COM * to guard against corrupt note data. 1632*11957SAli.Bahrami@Sun.COM */ 1633*11957SAli.Bahrami@Sun.COM while (dst < end) { 1634*11957SAli.Bahrami@Sun.COM Elf32_Nhdr *nhdr; 1635*11957SAli.Bahrami@Sun.COM unsigned char *namestr; 1636*11957SAli.Bahrami@Sun.COM void *desc; 16370Sstevel@tonic-gate Elf32_Word field_sz; 16380Sstevel@tonic-gate 1639*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_namesz) + sizeof(Elf32_Word) + 1640*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1641*11957SAli.Bahrami@Sun.COM break; 16420Sstevel@tonic-gate dst->n_namesz = tomw(src, N1_namesz_$2); 1643*11957SAli.Bahrami@Sun.COM 1644*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_descsz) + sizeof(Elf32_Word) + 1645*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1646*11957SAli.Bahrami@Sun.COM break; 16470Sstevel@tonic-gate dst->n_descsz = tomw(src, N1_descsz_$2); 1648*11957SAli.Bahrami@Sun.COM 1649*11957SAli.Bahrami@Sun.COM if ((offsetof(Elf32_Nhdr, n_type) + sizeof(Elf32_Word) + 1650*11957SAli.Bahrami@Sun.COM (char *) dst) >= (char *) end) 1651*11957SAli.Bahrami@Sun.COM break; 16520Sstevel@tonic-gate dst->n_type = tomw(src, N1_type_$2); 16530Sstevel@tonic-gate nhdr = dst; 1654*11957SAli.Bahrami@Sun.COM 16551618Srie /* LINTED */ 16560Sstevel@tonic-gate dst = (Elf32_Nhdr *)((char *)dst + sizeof (Elf32_Nhdr)); 16570Sstevel@tonic-gate namestr = src + N1_sizeof; 16580Sstevel@tonic-gate field_sz = S_ROUND(nhdr->n_namesz, sizeof (Elf32_Word)); 1659*11957SAli.Bahrami@Sun.COM if ((field_sz + (char *) dst) > (char *) end) { 1660*11957SAli.Bahrami@Sun.COM field_sz = (char *) end - (char *) dst; 1661*11957SAli.Bahrami@Sun.COM if (field_sz == 0) 1662*11957SAli.Bahrami@Sun.COM break; 1663*11957SAli.Bahrami@Sun.COM } 16640Sstevel@tonic-gate (void)memcpy((void *)dst, namestr, field_sz); 16650Sstevel@tonic-gate desc = namestr + field_sz; 1666*11957SAli.Bahrami@Sun.COM 16671618Srie /* LINTED */ 16680Sstevel@tonic-gate dst = (Elf32_Nhdr *)((char *)dst + field_sz); 16690Sstevel@tonic-gate field_sz = nhdr->n_descsz; 1670*11957SAli.Bahrami@Sun.COM if ((field_sz + (char *) dst) > (char *) end) { 1671*11957SAli.Bahrami@Sun.COM field_sz = (char *) end - (char *) dst; 1672*11957SAli.Bahrami@Sun.COM if (field_sz == 0) 1673*11957SAli.Bahrami@Sun.COM break; 1674*11957SAli.Bahrami@Sun.COM } 16750Sstevel@tonic-gate (void)memcpy(dst, desc, field_sz); 16760Sstevel@tonic-gate field_sz = S_ROUND(field_sz, sizeof (Elf32_Word)); 1677*11957SAli.Bahrami@Sun.COM 16781618Srie /* LINTED */ 16790Sstevel@tonic-gate dst = (Elf32_Nhdr *)((char *)dst + field_sz); 16800Sstevel@tonic-gate src = (unsigned char *)desc + field_sz; 16810Sstevel@tonic-gate } 16820Sstevel@tonic-gate}') 16830Sstevel@tonic-gate 16840Sstevel@tonic-gatenote_11_tom(note_2L11_tom,L) 16850Sstevel@tonic-gatenote_11_tom(note_2M11_tom,M) 16860Sstevel@tonic-gate 16870Sstevel@tonic-gate 16880Sstevel@tonic-gatedefine(off_tom, ` 16890Sstevel@tonic-gatestatic void 16900Sstevel@tonic-gate$1(Elf32_Off *dst, unsigned char *src, size_t cnt) 16910Sstevel@tonic-gate{ 16920Sstevel@tonic-gate Elf32_Off *end = dst; 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate dst += cnt; 16950Sstevel@tonic-gate src += cnt * O_sizeof; 16960Sstevel@tonic-gate while (dst-- > end) { 16970Sstevel@tonic-gate src -= O_sizeof; 16980Sstevel@tonic-gate *dst = tomo(src, O_$2); 16990Sstevel@tonic-gate } 17000Sstevel@tonic-gate}') 17010Sstevel@tonic-gate 17020Sstevel@tonic-gateoff_tom(off_2L_tom,L) 17030Sstevel@tonic-gateoff_tom(off_2M_tom,M) 17040Sstevel@tonic-gate 17050Sstevel@tonic-gate 17060Sstevel@tonic-gatedefine(phdr_11_tom, ` 17070Sstevel@tonic-gatestatic void 17080Sstevel@tonic-gate$1(Elf32_Phdr *dst, unsigned char *src, size_t cnt) 17090Sstevel@tonic-gate{ 17100Sstevel@tonic-gate Elf32_Phdr *end = dst; 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate dst += cnt; 17130Sstevel@tonic-gate src += cnt * P1_sizeof; 17140Sstevel@tonic-gate while (dst-- > end) { 17150Sstevel@tonic-gate src -= P1_sizeof; 17160Sstevel@tonic-gate dst->p_align = tomw(src, P1_align_$2); 17170Sstevel@tonic-gate dst->p_flags = tomw(src, P1_flags_$2); 17180Sstevel@tonic-gate dst->p_memsz = tomw(src, P1_memsz_$2); 17190Sstevel@tonic-gate dst->p_filesz = tomw(src, P1_filesz_$2); 17200Sstevel@tonic-gate dst->p_paddr = toma(src, P1_paddr_$2); 17210Sstevel@tonic-gate dst->p_vaddr = toma(src, P1_vaddr_$2); 17220Sstevel@tonic-gate dst->p_offset = tomo(src, P1_offset_$2); 17230Sstevel@tonic-gate dst->p_type = tomw(src, P1_type_$2); 17240Sstevel@tonic-gate } 17250Sstevel@tonic-gate}') 17260Sstevel@tonic-gate 17270Sstevel@tonic-gatephdr_11_tom(phdr_2L11_tom,L) 17280Sstevel@tonic-gatephdr_11_tom(phdr_2M11_tom,M) 17290Sstevel@tonic-gate 17300Sstevel@tonic-gate 17310Sstevel@tonic-gatedefine(rel_11_tom, ` 17320Sstevel@tonic-gatestatic void 17330Sstevel@tonic-gate$1(Elf32_Rel *dst, unsigned char *src, size_t cnt) 17340Sstevel@tonic-gate{ 17350Sstevel@tonic-gate Elf32_Rel *end = dst; 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate dst += cnt; 17380Sstevel@tonic-gate src += cnt * R1_sizeof; 17390Sstevel@tonic-gate while (dst-- > end) { 17400Sstevel@tonic-gate src -= R1_sizeof; 17410Sstevel@tonic-gate dst->r_info = tomw(src, R1_info_$2); 17420Sstevel@tonic-gate dst->r_offset = toma(src, R1_offset_$2); 17430Sstevel@tonic-gate } 17440Sstevel@tonic-gate}') 17450Sstevel@tonic-gate 17460Sstevel@tonic-gaterel_11_tom(rel_2L11_tom,L) 17470Sstevel@tonic-gaterel_11_tom(rel_2M11_tom,M) 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate 17500Sstevel@tonic-gatedefine(rela_11_tom, ` 17510Sstevel@tonic-gatestatic void 17520Sstevel@tonic-gate$1(Elf32_Rela *dst, unsigned char *src, size_t cnt) 17530Sstevel@tonic-gate{ 17540Sstevel@tonic-gate Elf32_Rela *end = dst; 17550Sstevel@tonic-gate 17560Sstevel@tonic-gate dst += cnt; 17570Sstevel@tonic-gate src += cnt * RA1_sizeof; 17580Sstevel@tonic-gate while (dst-- > end) { 17590Sstevel@tonic-gate src -= RA1_sizeof; 17600Sstevel@tonic-gate /*CONSTANTCONDITION*/ 17610Sstevel@tonic-gate if (~(Elf32_Word)0 == -(Elf32_Sword)1 && /* 2s comp */ 17620Sstevel@tonic-gate ~(~(Elf32_Word)0 >> 1) == HI32) { 17630Sstevel@tonic-gate dst->r_addend = tomw(src, RA1_addend_$2); 17640Sstevel@tonic-gate } else { 17650Sstevel@tonic-gate union { 17660Sstevel@tonic-gate Elf32_Word w; 17670Sstevel@tonic-gate Elf32_Sword sw; 17680Sstevel@tonic-gate } u; 17690Sstevel@tonic-gate 17700Sstevel@tonic-gate if ((u.w = tomw(src, RA1_addend_$2)) & HI32) { 17710Sstevel@tonic-gate u.w |= ~(Elf32_Word)LO31; 17720Sstevel@tonic-gate u.w = ~u.w + 1; 17730Sstevel@tonic-gate u.sw = -u.w; 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate dst->r_addend = u.sw; 17760Sstevel@tonic-gate } 17770Sstevel@tonic-gate dst->r_info = tomw(src, RA1_info_$2); 17780Sstevel@tonic-gate dst->r_offset = toma(src, RA1_offset_$2); 17790Sstevel@tonic-gate } 17800Sstevel@tonic-gate}') 17810Sstevel@tonic-gate 17820Sstevel@tonic-gaterela_11_tom(rela_2L11_tom,L) 17830Sstevel@tonic-gaterela_11_tom(rela_2M11_tom,M) 17840Sstevel@tonic-gate 17850Sstevel@tonic-gate 17860Sstevel@tonic-gatedefine(shdr_11_tom, ` 17870Sstevel@tonic-gatestatic void 17880Sstevel@tonic-gate$1(Elf32_Shdr *dst, unsigned char *src, size_t cnt) 17890Sstevel@tonic-gate{ 17900Sstevel@tonic-gate Elf32_Shdr *end = dst; 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate dst += cnt; 17930Sstevel@tonic-gate src += cnt * SH1_sizeof; 17940Sstevel@tonic-gate while (dst-- > end) { 17950Sstevel@tonic-gate src -= SH1_sizeof; 17960Sstevel@tonic-gate dst->sh_entsize = tomw(src, SH1_entsize_$2); 17970Sstevel@tonic-gate dst->sh_addralign = tomw(src, SH1_addralign_$2); 17980Sstevel@tonic-gate dst->sh_info = tomw(src, SH1_info_$2); 17990Sstevel@tonic-gate dst->sh_link = tomw(src, SH1_link_$2); 18000Sstevel@tonic-gate dst->sh_size = tomw(src, SH1_size_$2); 18010Sstevel@tonic-gate dst->sh_offset = tomo(src, SH1_offset_$2); 18020Sstevel@tonic-gate dst->sh_addr = toma(src, SH1_addr_$2); 18030Sstevel@tonic-gate dst->sh_flags = tomw(src, SH1_flags_$2); 18040Sstevel@tonic-gate dst->sh_type = tomw(src, SH1_type_$2); 18050Sstevel@tonic-gate dst->sh_name = tomw(src, SH1_name_$2); 18060Sstevel@tonic-gate } 18070Sstevel@tonic-gate}') 18080Sstevel@tonic-gate 18090Sstevel@tonic-gateshdr_11_tom(shdr_2L11_tom,L) 18100Sstevel@tonic-gateshdr_11_tom(shdr_2M11_tom,M) 18110Sstevel@tonic-gate 18120Sstevel@tonic-gate 18130Sstevel@tonic-gate 18140Sstevel@tonic-gatedefine(sword_tom, ` 18150Sstevel@tonic-gatestatic void 18160Sstevel@tonic-gate$1(Elf32_Sword *dst, unsigned char *src, size_t cnt) 18170Sstevel@tonic-gate{ 18180Sstevel@tonic-gate Elf32_Sword *end = dst; 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate dst += cnt; 18210Sstevel@tonic-gate src += cnt * W_sizeof; 18220Sstevel@tonic-gate while (dst-- > end) { 18230Sstevel@tonic-gate src -= W_sizeof; 18240Sstevel@tonic-gate /*CONSTANTCONDITION*/ 18250Sstevel@tonic-gate if (~(Elf32_Word)0 == -(Elf32_Sword)1 && /* 2s comp */ 18260Sstevel@tonic-gate ~(~(Elf32_Word)0 >> 1) == HI32) { 18270Sstevel@tonic-gate *dst = tomw(src, W_$2); 18280Sstevel@tonic-gate } else { 18290Sstevel@tonic-gate union { 18300Sstevel@tonic-gate Elf32_Word w; 18310Sstevel@tonic-gate Elf32_Sword sw; 18320Sstevel@tonic-gate } u; 18330Sstevel@tonic-gate 18340Sstevel@tonic-gate if ((u.w = tomw(src, W_$2)) & HI32) { 18350Sstevel@tonic-gate u.w |= ~(Elf32_Word)LO31; 18360Sstevel@tonic-gate u.w = ~u.w + 1; 18370Sstevel@tonic-gate u.sw = -u.w; 18380Sstevel@tonic-gate } 18390Sstevel@tonic-gate *dst = u.sw; 18400Sstevel@tonic-gate } 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate}') 18430Sstevel@tonic-gate 18440Sstevel@tonic-gatesword_tom(sword_2L_tom,L) 18450Sstevel@tonic-gatesword_tom(sword_2M_tom,M) 18460Sstevel@tonic-gate 18470Sstevel@tonic-gate 18480Sstevel@tonic-gatedefine(cap_11_tom, ` 18490Sstevel@tonic-gatestatic void 18500Sstevel@tonic-gate$1(Elf32_Cap *dst, unsigned char *src, size_t cnt) 18510Sstevel@tonic-gate{ 18520Sstevel@tonic-gate Elf32_Cap *end = dst + cnt; 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate do { 18550Sstevel@tonic-gate dst->c_tag = tomw(src, C1_tag_$2); 18560Sstevel@tonic-gate dst->c_un.c_val = tomw(src, C1_val_$2); 18570Sstevel@tonic-gate src += C1_sizeof; 18580Sstevel@tonic-gate } while (++dst < end); 18590Sstevel@tonic-gate}') 18600Sstevel@tonic-gate 18610Sstevel@tonic-gatecap_11_tom(cap_2L11_tom,L) 18620Sstevel@tonic-gatecap_11_tom(cap_2M11_tom,M) 18630Sstevel@tonic-gate 18640Sstevel@tonic-gate 18650Sstevel@tonic-gatedefine(syminfo_11_tom, ` 18660Sstevel@tonic-gatestatic void 18670Sstevel@tonic-gate$1(Elf32_Syminfo *dst, unsigned char *src, size_t cnt) 18680Sstevel@tonic-gate{ 18690Sstevel@tonic-gate Elf32_Syminfo *end = dst; 18700Sstevel@tonic-gate 18710Sstevel@tonic-gate dst += cnt; 18720Sstevel@tonic-gate src += cnt * SI1_sizeof; 18730Sstevel@tonic-gate while (dst-- > end) { 18740Sstevel@tonic-gate src -= SI1_sizeof; 18750Sstevel@tonic-gate dst->si_boundto = tomh(src, SI1_boundto_$2); 18760Sstevel@tonic-gate dst->si_flags = tomh(src, SI1_flags_$2); 18770Sstevel@tonic-gate } 18780Sstevel@tonic-gate}') 18790Sstevel@tonic-gate 18800Sstevel@tonic-gatesyminfo_11_tom(syminfo_2L11_tom,L) 18810Sstevel@tonic-gatesyminfo_11_tom(syminfo_2M11_tom,M) 18820Sstevel@tonic-gate 18830Sstevel@tonic-gate 18840Sstevel@tonic-gatedefine(sym_11_tom, ` 18850Sstevel@tonic-gatestatic void 18860Sstevel@tonic-gate$1(Elf32_Sym *dst, unsigned char *src, size_t cnt) 18870Sstevel@tonic-gate{ 18880Sstevel@tonic-gate Elf32_Sym *end = dst; 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate dst += cnt; 18910Sstevel@tonic-gate src += cnt * ST1_sizeof; 18920Sstevel@tonic-gate while (dst-- > end) { 18930Sstevel@tonic-gate src -= ST1_sizeof; 18940Sstevel@tonic-gate dst->st_shndx = tomh(src, ST1_shndx_$2); 18950Sstevel@tonic-gate dst->st_other = tomb(src, ST1_other_$2); 18960Sstevel@tonic-gate dst->st_info = tomb(src, ST1_info_$2); 18970Sstevel@tonic-gate dst->st_size = tomw(src, ST1_size_$2); 18980Sstevel@tonic-gate dst->st_value = toma(src, ST1_value_$2); 18990Sstevel@tonic-gate dst->st_name = tomw(src, ST1_name_$2); 19000Sstevel@tonic-gate } 19010Sstevel@tonic-gate}') 19020Sstevel@tonic-gate 19030Sstevel@tonic-gatesym_11_tom(sym_2L11_tom,L) 19040Sstevel@tonic-gatesym_11_tom(sym_2M11_tom,M) 19050Sstevel@tonic-gate 19060Sstevel@tonic-gate 19070Sstevel@tonic-gatedefine(word_tom, ` 19080Sstevel@tonic-gatestatic void 19090Sstevel@tonic-gate$1(Elf32_Word *dst, unsigned char *src, size_t cnt) 19100Sstevel@tonic-gate{ 19110Sstevel@tonic-gate Elf32_Word *end = dst; 19120Sstevel@tonic-gate 19130Sstevel@tonic-gate dst += cnt; 19140Sstevel@tonic-gate src += cnt * W_sizeof; 19150Sstevel@tonic-gate while (dst-- > end) { 19160Sstevel@tonic-gate src -= W_sizeof; 19170Sstevel@tonic-gate *dst = tomw(src, W_$2); 19180Sstevel@tonic-gate } 19190Sstevel@tonic-gate}') 19200Sstevel@tonic-gate 19210Sstevel@tonic-gateword_tom(word_2L_tom,L) 19220Sstevel@tonic-gateword_tom(word_2M_tom,M) 19230Sstevel@tonic-gate 19240Sstevel@tonic-gate 19250Sstevel@tonic-gatedefine(verdef_11_tom, ` 19260Sstevel@tonic-gatestatic void 19270Sstevel@tonic-gate$1(Elf32_Verdef *dst, unsigned char *src, size_t cnt) 19280Sstevel@tonic-gate{ 19290Sstevel@tonic-gate /* LINTED */ 19300Sstevel@tonic-gate Elf32_Verdef *end = (Elf32_Verdef *)((char *)dst + cnt); 19310Sstevel@tonic-gate 19320Sstevel@tonic-gate while (dst < end) { 19330Sstevel@tonic-gate Elf32_Verdaux *vaux; 19340Sstevel@tonic-gate unsigned char *src_vaux; 19350Sstevel@tonic-gate Elf32_Half i; 19360Sstevel@tonic-gate 19370Sstevel@tonic-gate dst->vd_version = tomh(src, VD1_version_$2); 19380Sstevel@tonic-gate dst->vd_flags = tomh(src, VD1_flags_$2); 19390Sstevel@tonic-gate dst->vd_ndx = tomh(src, VD1_ndx_$2); 19400Sstevel@tonic-gate dst->vd_cnt = tomh(src, VD1_cnt_$2); 19410Sstevel@tonic-gate dst->vd_hash = tomw(src, VD1_hash_$2); 19420Sstevel@tonic-gate dst->vd_aux = tomw(src, VD1_aux_$2); 19430Sstevel@tonic-gate dst->vd_next = tomw(src, VD1_next_$2); 19440Sstevel@tonic-gate 19450Sstevel@tonic-gate src_vaux = src + dst->vd_aux; 19460Sstevel@tonic-gate /* LINTED */ 19470Sstevel@tonic-gate vaux = (Elf32_Verdaux*)((char *)dst + dst->vd_aux); 19480Sstevel@tonic-gate for (i = 0; i < dst->vd_cnt; i++) { 19490Sstevel@tonic-gate vaux->vda_name = toma(src_vaux, VDA1_name_$2); 19500Sstevel@tonic-gate vaux->vda_next = toma(src_vaux, VDA1_next_$2); 19510Sstevel@tonic-gate src_vaux += vaux->vda_next; 19520Sstevel@tonic-gate /* LINTED */ 19530Sstevel@tonic-gate vaux = (Elf32_Verdaux *)((char *)vaux + 19540Sstevel@tonic-gate vaux->vda_next); 19550Sstevel@tonic-gate } 19560Sstevel@tonic-gate src += dst->vd_next; 19570Sstevel@tonic-gate /* LINTED */ 19580Sstevel@tonic-gate dst = (Elf32_Verdef *)(dst->vd_next ? 19590Sstevel@tonic-gate (char *)dst + dst->vd_next : (char *)end); 19600Sstevel@tonic-gate } 19610Sstevel@tonic-gate}') 19620Sstevel@tonic-gate 19630Sstevel@tonic-gateverdef_11_tom(verdef_2L11_tom,L) 19640Sstevel@tonic-gateverdef_11_tom(verdef_2M11_tom,M) 19650Sstevel@tonic-gate 19660Sstevel@tonic-gate 19670Sstevel@tonic-gatedefine(verneed_11_tom, ` 19680Sstevel@tonic-gatestatic void 19690Sstevel@tonic-gate$1(Elf32_Verneed *dst, unsigned char *src, size_t cnt) 19700Sstevel@tonic-gate{ 19710Sstevel@tonic-gate /* LINTED */ 19720Sstevel@tonic-gate Elf32_Verneed *end = (Elf32_Verneed *)((char *)dst + cnt); 19730Sstevel@tonic-gate 19740Sstevel@tonic-gate while (dst < end) { 19750Sstevel@tonic-gate Elf32_Vernaux * vaux; 19760Sstevel@tonic-gate unsigned char * src_vaux; 19770Sstevel@tonic-gate Elf32_Half i; 19780Sstevel@tonic-gate dst->vn_version = tomh(src, VN1_version_$2); 19790Sstevel@tonic-gate dst->vn_cnt = tomh(src, VN1_cnt_$2); 19800Sstevel@tonic-gate dst->vn_file = toma(src, VN1_file_$2); 19810Sstevel@tonic-gate dst->vn_aux = tomw(src, VN1_aux_$2); 19820Sstevel@tonic-gate dst->vn_next = tomw(src, VN1_next_$2); 19830Sstevel@tonic-gate 19840Sstevel@tonic-gate src_vaux = src + dst->vn_aux; 19850Sstevel@tonic-gate /* LINTED */ 19860Sstevel@tonic-gate vaux = (Elf32_Vernaux *)((char *)dst + dst->vn_aux); 19870Sstevel@tonic-gate for (i = 0; i < dst->vn_cnt; i++) { 19880Sstevel@tonic-gate vaux->vna_hash = tomw(src_vaux, VNA1_hash_$2); 19890Sstevel@tonic-gate vaux->vna_flags = tomh(src_vaux, VNA1_flags_$2); 19900Sstevel@tonic-gate vaux->vna_other = tomh(src_vaux, VNA1_other_$2); 19910Sstevel@tonic-gate vaux->vna_name = toma(src_vaux, VNA1_name_$2); 19920Sstevel@tonic-gate vaux->vna_next = tomw(src_vaux, VNA1_next_$2); 19930Sstevel@tonic-gate src_vaux += vaux->vna_next; 19940Sstevel@tonic-gate /* LINTED */ 19950Sstevel@tonic-gate vaux = (Elf32_Vernaux *)((char *)vaux + 19960Sstevel@tonic-gate vaux->vna_next); 19970Sstevel@tonic-gate } 19980Sstevel@tonic-gate src += dst->vn_next; 19990Sstevel@tonic-gate /* LINTED */ 20000Sstevel@tonic-gate dst = (Elf32_Verneed *)(dst->vn_next ? 20010Sstevel@tonic-gate (char *)dst + dst->vn_next : (char *)end); 20020Sstevel@tonic-gate } 20030Sstevel@tonic-gate}') 20040Sstevel@tonic-gate 20050Sstevel@tonic-gateverneed_11_tom(verneed_2L11_tom,L) 20060Sstevel@tonic-gateverneed_11_tom(verneed_2M11_tom,M) 2007