src/pkg/debug/elf/elf.go - The Go Programming Language

Golang

Source file src/pkg/debug/elf/elf.go

     1	/*
     2	 * ELF constants and data structures
     3	 *
     4	 * Derived from:
     5	 * $FreeBSD: src/sys/sys/elf32.h,v 1.8.14.1 2005/12/30 22:13:58 marcel Exp $
     6	 * $FreeBSD: src/sys/sys/elf64.h,v 1.10.14.1 2005/12/30 22:13:58 marcel Exp $
     7	 * $FreeBSD: src/sys/sys/elf_common.h,v 1.15.8.1 2005/12/30 22:13:58 marcel Exp $
     8	 * $FreeBSD: src/sys/alpha/include/elf.h,v 1.14 2003/09/25 01:10:22 peter Exp $
     9	 * $FreeBSD: src/sys/amd64/include/elf.h,v 1.18 2004/08/03 08:21:48 dfr Exp $
    10	 * $FreeBSD: src/sys/arm/include/elf.h,v 1.5.2.1 2006/06/30 21:42:52 cognet Exp $
    11	 * $FreeBSD: src/sys/i386/include/elf.h,v 1.16 2004/08/02 19:12:17 dfr Exp $
    12	 * $FreeBSD: src/sys/powerpc/include/elf.h,v 1.7 2004/11/02 09:47:01 ssouhlal Exp $
    13	 * $FreeBSD: src/sys/sparc64/include/elf.h,v 1.12 2003/09/25 01:10:26 peter Exp $
    14	 *
    15	 * Copyright (c) 1996-1998 John D. Polstra.  All rights reserved.
    16	 * Copyright (c) 2001 David E. O'Brien
    17	 * Portions Copyright 2009 The Go Authors.  All rights reserved.
    18	 *
    19	 * Redistribution and use in source and binary forms, with or without
    20	 * modification, are permitted provided that the following conditions
    21	 * are met:
    22	 * 1. Redistributions of source code must retain the above copyright
    23	 *    notice, this list of conditions and the following disclaimer.
    24	 * 2. Redistributions in binary form must reproduce the above copyright
    25	 *    notice, this list of conditions and the following disclaimer in the
    26	 *    documentation and/or other materials provided with the distribution.
    27	 *
    28	 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    29	 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    30	 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    31	 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    32	 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    33	 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    34	 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    35	 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    36	 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    37	 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    38	 * SUCH DAMAGE.
    39	 */
    40	
    41	package elf
    42	
    43	import "strconv"
    44	
    45	/*
    46	 * Constants
    47	 */
    48	
    49	// Indexes into the Header.Ident array.
    50	const (
    51		EI_CLASS      = 4  /* Class of machine. */
    52		EI_DATA       = 5  /* Data format. */
    53		EI_VERSION    = 6  /* ELF format version. */
    54		EI_OSABI      = 7  /* Operating system / ABI identification */
    55		EI_ABIVERSION = 8  /* ABI version */
    56		EI_PAD        = 9  /* Start of padding (per SVR4 ABI). */
    57		EI_NIDENT     = 16 /* Size of e_ident array. */
    58	)
    59	
    60	// Initial magic number for ELF files.
    61	const ELFMAG = "\177ELF"
    62	
    63	// Version is found in Header.Ident[EI_VERSION] and Header.Version.
    64	type Version byte
    65	
    66	const (
    67		EV_NONE    Version = 0
    68		EV_CURRENT Version = 1
    69	)
    70	
    71	var versionStrings = []intName{
    72		{0, "EV_NONE"},
    73		{1, "EV_CURRENT"},
    74	}
    75	
    76	func (i Version) String() string   { return stringName(uint32(i), versionStrings, false) }
    77	func (i Version) GoString() string { return stringName(uint32(i), versionStrings, true) }
    78	
    79	// Class is found in Header.Ident[EI_CLASS] and Header.Class.
    80	type Class byte
    81	
    82	const (
    83		ELFCLASSNONE Class = 0 /* Unknown class. */
    84		ELFCLASS32   Class = 1 /* 32-bit architecture. */
    85		ELFCLASS64   Class = 2 /* 64-bit architecture. */
    86	)
    87	
    88	var classStrings = []intName{
    89		{0, "ELFCLASSNONE"},
    90		{1, "ELFCLASS32"},
    91		{2, "ELFCLASS64"},
    92	}
    93	
    94	func (i Class) String() string   { return stringName(uint32(i), classStrings, false) }
    95	func (i Class) GoString() string { return stringName(uint32(i), classStrings, true) }
    96	
    97	// Data is found in Header.Ident[EI_DATA] and Header.Data.
    98	type Data byte
    99	
   100	const (
   101		ELFDATANONE Data = 0 /* Unknown data format. */
   102		ELFDATA2LSB Data = 1 /* 2's complement little-endian. */
   103		ELFDATA2MSB Data = 2 /* 2's complement big-endian. */
   104	)
   105	
   106	var dataStrings = []intName{
   107		{0, "ELFDATANONE"},
   108		{1, "ELFDATA2LSB"},
   109		{2, "ELFDATA2MSB"},
   110	}
   111	
   112	func (i Data) String() string   { return stringName(uint32(i), dataStrings, false) }
   113	func (i Data) GoString() string { return stringName(uint32(i), dataStrings, true) }
   114	
   115	// OSABI is found in Header.Ident[EI_OSABI] and Header.OSABI.
   116	type OSABI byte
   117	
   118	const (
   119		ELFOSABI_NONE       OSABI = 0   /* UNIX System V ABI */
   120		ELFOSABI_HPUX       OSABI = 1   /* HP-UX operating system */
   121		ELFOSABI_NETBSD     OSABI = 2   /* NetBSD */
   122		ELFOSABI_LINUX      OSABI = 3   /* GNU/Linux */
   123		ELFOSABI_HURD       OSABI = 4   /* GNU/Hurd */
   124		ELFOSABI_86OPEN     OSABI = 5   /* 86Open common IA32 ABI */
   125		ELFOSABI_SOLARIS    OSABI = 6   /* Solaris */
   126		ELFOSABI_AIX        OSABI = 7   /* AIX */
   127		ELFOSABI_IRIX       OSABI = 8   /* IRIX */
   128		ELFOSABI_FREEBSD    OSABI = 9   /* FreeBSD */
   129		ELFOSABI_TRU64      OSABI = 10  /* TRU64 UNIX */
   130		ELFOSABI_MODESTO    OSABI = 11  /* Novell Modesto */
   131		ELFOSABI_OPENBSD    OSABI = 12  /* OpenBSD */
   132		ELFOSABI_OPENVMS    OSABI = 13  /* Open VMS */
   133		ELFOSABI_NSK        OSABI = 14  /* HP Non-Stop Kernel */
   134		ELFOSABI_ARM        OSABI = 97  /* ARM */
   135		ELFOSABI_STANDALONE OSABI = 255 /* Standalone (embedded) application */
   136	)
   137	
   138	var osabiStrings = []intName{
   139		{0, "ELFOSABI_NONE"},
   140		{1, "ELFOSABI_HPUX"},
   141		{2, "ELFOSABI_NETBSD"},
   142		{3, "ELFOSABI_LINUX"},
   143		{4, "ELFOSABI_HURD"},
   144		{5, "ELFOSABI_86OPEN"},
   145		{6, "ELFOSABI_SOLARIS"},
   146		{7, "ELFOSABI_AIX"},
   147		{8, "ELFOSABI_IRIX"},
   148		{9, "ELFOSABI_FREEBSD"},
   149		{10, "ELFOSABI_TRU64"},
   150		{11, "ELFOSABI_MODESTO"},
   151		{12, "ELFOSABI_OPENBSD"},
   152		{13, "ELFOSABI_OPENVMS"},
   153		{14, "ELFOSABI_NSK"},
   154		{97, "ELFOSABI_ARM"},
   155		{255, "ELFOSABI_STANDALONE"},
   156	}
   157	
   158	func (i OSABI) String() string   { return stringName(uint32(i), osabiStrings, false) }
   159	func (i OSABI) GoString() string { return stringName(uint32(i), osabiStrings, true) }
   160	
   161	// Type is found in Header.Type.
   162	type Type uint16
   163	
   164	const (
   165		ET_NONE   Type = 0      /* Unknown type. */
   166		ET_REL    Type = 1      /* Relocatable. */
   167		ET_EXEC   Type = 2      /* Executable. */
   168		ET_DYN    Type = 3      /* Shared object. */
   169		ET_CORE   Type = 4      /* Core file. */
   170		ET_LOOS   Type = 0xfe00 /* First operating system specific. */
   171		ET_HIOS   Type = 0xfeff /* Last operating system-specific. */
   172		ET_LOPROC Type = 0xff00 /* First processor-specific. */
   173		ET_HIPROC Type = 0xffff /* Last processor-specific. */
   174	)
   175	
   176	var typeStrings = []intName{
   177		{0, "ET_NONE"},
   178		{1, "ET_REL"},
   179		{2, "ET_EXEC"},
   180		{3, "ET_DYN"},
   181		{4, "ET_CORE"},
   182		{0xfe00, "ET_LOOS"},
   183		{0xfeff, "ET_HIOS"},
   184		{0xff00, "ET_LOPROC"},
   185		{0xffff, "ET_HIPROC"},
   186	}
   187	
   188	func (i Type) String() string   { return stringName(uint32(i), typeStrings, false) }
   189	func (i Type) GoString() string { return stringName(uint32(i), typeStrings, true) }
   190	
   191	// Machine is found in Header.Machine.
   192	type Machine uint16
   193	
   194	const (
   195		EM_NONE        Machine = 0  /* Unknown machine. */
   196		EM_M32         Machine = 1  /* AT&T WE32100. */
   197		EM_SPARC       Machine = 2  /* Sun SPARC. */
   198		EM_386         Machine = 3  /* Intel i386. */
   199		EM_68K         Machine = 4  /* Motorola 68000. */
   200		EM_88K         Machine = 5  /* Motorola 88000. */
   201		EM_860         Machine = 7  /* Intel i860. */
   202		EM_MIPS        Machine = 8  /* MIPS R3000 Big-Endian only. */
   203		EM_S370        Machine = 9  /* IBM System/370. */
   204		EM_MIPS_RS3_LE Machine = 10 /* MIPS R3000 Little-Endian. */
   205		EM_PARISC      Machine = 15 /* HP PA-RISC. */
   206		EM_VPP500      Machine = 17 /* Fujitsu VPP500. */
   207		EM_SPARC32PLUS Machine = 18 /* SPARC v8plus. */
   208		EM_960         Machine = 19 /* Intel 80960. */
   209		EM_PPC         Machine = 20 /* PowerPC 32-bit. */
   210		EM_PPC64       Machine = 21 /* PowerPC 64-bit. */
   211		EM_S390        Machine = 22 /* IBM System/390. */
   212		EM_V800        Machine = 36 /* NEC V800. */
   213		EM_FR20        Machine = 37 /* Fujitsu FR20. */
   214		EM_RH32        Machine = 38 /* TRW RH-32. */
   215		EM_RCE         Machine = 39 /* Motorola RCE. */
   216		EM_ARM         Machine = 40 /* ARM. */
   217		EM_SH          Machine = 42 /* Hitachi SH. */
   218		EM_SPARCV9     Machine = 43 /* SPARC v9 64-bit. */
   219		EM_TRICORE     Machine = 44 /* Siemens TriCore embedded processor. */
   220		EM_ARC         Machine = 45 /* Argonaut RISC Core. */
   221		EM_H8_300      Machine = 46 /* Hitachi H8/300. */
   222		EM_H8_300H     Machine = 47 /* Hitachi H8/300H. */
   223		EM_H8S         Machine = 48 /* Hitachi H8S. */
   224		EM_H8_500      Machine = 49 /* Hitachi H8/500. */
   225		EM_IA_64       Machine = 50 /* Intel IA-64 Processor. */
   226		EM_MIPS_X      Machine = 51 /* Stanford MIPS-X. */
   227		EM_COLDFIRE    Machine = 52 /* Motorola ColdFire. */
   228		EM_68HC12      Machine = 53 /* Motorola M68HC12. */
   229		EM_MMA         Machine = 54 /* Fujitsu MMA. */
   230		EM_PCP         Machine = 55 /* Siemens PCP. */
   231		EM_NCPU        Machine = 56 /* Sony nCPU. */
   232		EM_NDR1        Machine = 57 /* Denso NDR1 microprocessor. */
   233		EM_STARCORE    Machine = 58 /* Motorola Star*Core processor. */
   234		EM_ME16        Machine = 59 /* Toyota ME16 processor. */
   235		EM_ST100       Machine = 60 /* STMicroelectronics ST100 processor. */
   236		EM_TINYJ       Machine = 61 /* Advanced Logic Corp. TinyJ processor. */
   237		EM_X86_64      Machine = 62 /* Advanced Micro Devices x86-64 */
   238	
   239		/* Non-standard or deprecated. */
   240		EM_486         Machine = 6      /* Intel i486. */
   241		EM_MIPS_RS4_BE Machine = 10     /* MIPS R4000 Big-Endian */
   242		EM_ALPHA_STD   Machine = 41     /* Digital Alpha (standard value). */
   243		EM_ALPHA       Machine = 0x9026 /* Alpha (written in the absence of an ABI) */
   244	)
   245	
   246	var machineStrings = []intName{
   247		{0, "EM_NONE"},
   248		{1, "EM_M32"},
   249		{2, "EM_SPARC"},
   250		{3, "EM_386"},
   251		{4, "EM_68K"},
   252		{5, "EM_88K"},
   253		{7, "EM_860"},
   254		{8, "EM_MIPS"},
   255		{9, "EM_S370"},
   256		{10, "EM_MIPS_RS3_LE"},
   257		{15, "EM_PARISC"},
   258		{17, "EM_VPP500"},
   259		{18, "EM_SPARC32PLUS"},
   260		{19, "EM_960"},
   261		{20, "EM_PPC"},
   262		{21, "EM_PPC64"},
   263		{22, "EM_S390"},
   264		{36, "EM_V800"},
   265		{37, "EM_FR20"},
   266		{38, "EM_RH32"},
   267		{39, "EM_RCE"},
   268		{40, "EM_ARM"},
   269		{42, "EM_SH"},
   270		{43, "EM_SPARCV9"},
   271		{44, "EM_TRICORE"},
   272		{45, "EM_ARC"},
   273		{46, "EM_H8_300"},
   274		{47, "EM_H8_300H"},
   275		{48, "EM_H8S"},
   276		{49, "EM_H8_500"},
   277		{50, "EM_IA_64"},
   278		{51, "EM_MIPS_X"},
   279		{52, "EM_COLDFIRE"},
   280		{53, "EM_68HC12"},
   281		{54, "EM_MMA"},
   282		{55, "EM_PCP"},
   283		{56, "EM_NCPU"},
   284		{57, "EM_NDR1"},
   285		{58, "EM_STARCORE"},
   286		{59, "EM_ME16"},
   287		{60, "EM_ST100"},
   288		{61, "EM_TINYJ"},
   289		{62, "EM_X86_64"},
   290	
   291		/* Non-standard or deprecated. */
   292		{6, "EM_486"},
   293		{10, "EM_MIPS_RS4_BE"},
   294		{41, "EM_ALPHA_STD"},
   295		{0x9026, "EM_ALPHA"},
   296	}
   297	
   298	func (i Machine) String() string   { return stringName(uint32(i), machineStrings, false) }
   299	func (i Machine) GoString() string { return stringName(uint32(i), machineStrings, true) }
   300	
   301	// Special section indices.
   302	type SectionIndex int
   303	
   304	const (
   305		SHN_UNDEF     SectionIndex = 0      /* Undefined, missing, irrelevant. */
   306		SHN_LORESERVE SectionIndex = 0xff00 /* First of reserved range. */
   307		SHN_LOPROC    SectionIndex = 0xff00 /* First processor-specific. */
   308		SHN_HIPROC    SectionIndex = 0xff1f /* Last processor-specific. */
   309		SHN_LOOS      SectionIndex = 0xff20 /* First operating system-specific. */
   310		SHN_HIOS      SectionIndex = 0xff3f /* Last operating system-specific. */
   311		SHN_ABS       SectionIndex = 0xfff1 /* Absolute values. */
   312		SHN_COMMON    SectionIndex = 0xfff2 /* Common data. */
   313		SHN_XINDEX    SectionIndex = 0xffff /* Escape -- index stored elsewhere. */
   314		SHN_HIRESERVE SectionIndex = 0xffff /* Last of reserved range. */
   315	)
   316	
   317	var shnStrings = []intName{
   318		{0, "SHN_UNDEF"},
   319		{0xff00, "SHN_LOPROC"},
   320		{0xff20, "SHN_LOOS"},
   321		{0xfff1, "SHN_ABS"},
   322		{0xfff2, "SHN_COMMON"},
   323		{0xffff, "SHN_XINDEX"},
   324	}
   325	
   326	func (i SectionIndex) String() string   { return stringName(uint32(i), shnStrings, false) }
   327	func (i SectionIndex) GoString() string { return stringName(uint32(i), shnStrings, true) }
   328	
   329	// Section type.
   330	type SectionType uint32
   331	
   332	const (
   333		SHT_NULL           SectionType = 0          /* inactive */
   334		SHT_PROGBITS       SectionType = 1          /* program defined information */
   335		SHT_SYMTAB         SectionType = 2          /* symbol table section */
   336		SHT_STRTAB         SectionType = 3          /* string table section */
   337		SHT_RELA           SectionType = 4          /* relocation section with addends */
   338		SHT_HASH           SectionType = 5          /* symbol hash table section */
   339		SHT_DYNAMIC        SectionType = 6          /* dynamic section */
   340		SHT_NOTE           SectionType = 7          /* note section */
   341		SHT_NOBITS         SectionType = 8          /* no space section */
   342		SHT_REL            SectionType = 9          /* relocation section - no addends */
   343		SHT_SHLIB          SectionType = 10         /* reserved - purpose unknown */
   344		SHT_DYNSYM         SectionType = 11         /* dynamic symbol table section */
   345		SHT_INIT_ARRAY     SectionType = 14         /* Initialization function pointers. */
   346		SHT_FINI_ARRAY     SectionType = 15         /* Termination function pointers. */
   347		SHT_PREINIT_ARRAY  SectionType = 16         /* Pre-initialization function ptrs. */
   348		SHT_GROUP          SectionType = 17         /* Section group. */
   349		SHT_SYMTAB_SHNDX   SectionType = 18         /* Section indexes (see SHN_XINDEX). */
   350		SHT_LOOS           SectionType = 0x60000000 /* First of OS specific semantics */
   351		SHT_GNU_ATTRIBUTES SectionType = 0x6ffffff5 /* GNU object attributes */
   352		SHT_GNU_HASH       SectionType = 0x6ffffff6 /* GNU hash table */
   353		SHT_GNU_LIBLIST    SectionType = 0x6ffffff7 /* GNU prelink library list */
   354		SHT_GNU_VERDEF     SectionType = 0x6ffffffd /* GNU version definition section */
   355		SHT_GNU_VERNEED    SectionType = 0x6ffffffe /* GNU version needs section */
   356		SHT_GNU_VERSYM     SectionType = 0x6fffffff /* GNU version symbol table */
   357		SHT_HIOS           SectionType = 0x6fffffff /* Last of OS specific semantics */
   358		SHT_LOPROC         SectionType = 0x70000000 /* reserved range for processor */
   359		SHT_HIPROC         SectionType = 0x7fffffff /* specific section header types */
   360		SHT_LOUSER         SectionType = 0x80000000 /* reserved range for application */
   361		SHT_HIUSER         SectionType = 0xffffffff /* specific indexes */
   362	)
   363	
   364	var shtStrings = []intName{
   365		{0, "SHT_NULL"},
   366		{1, "SHT_PROGBITS"},
   367		{2, "SHT_SYMTAB"},
   368		{3, "SHT_STRTAB"},
   369		{4, "SHT_RELA"},
   370		{5, "SHT_HASH"},
   371		{6, "SHT_DYNAMIC"},
   372		{7, "SHT_NOTE"},
   373		{8, "SHT_NOBITS"},
   374		{9, "SHT_REL"},
   375		{10, "SHT_SHLIB"},
   376		{11, "SHT_DYNSYM"},
   377		{14, "SHT_INIT_ARRAY"},
   378		{15, "SHT_FINI_ARRAY"},
   379		{16, "SHT_PREINIT_ARRAY"},
   380		{17, "SHT_GROUP"},
   381		{18, "SHT_SYMTAB_SHNDX"},
   382		{0x60000000, "SHT_LOOS"},
   383		{0x6ffffff5, "SHT_GNU_ATTRIBUTES"},
   384		{0x6ffffff6, "SHT_GNU_HASH"},
   385		{0x6ffffff7, "SHT_GNU_LIBLIST"},
   386		{0x6ffffffd, "SHT_GNU_VERDEF"},
   387		{0x6ffffffe, "SHT_GNU_VERNEED"},
   388		{0x6fffffff, "SHT_GNU_VERSYM"},
   389		{0x70000000, "SHT_LOPROC"},
   390		{0x7fffffff, "SHT_HIPROC"},
   391		{0x80000000, "SHT_LOUSER"},
   392		{0xffffffff, "SHT_HIUSER"},
   393	}
   394	
   395	func (i SectionType) String() string   { return stringName(uint32(i), shtStrings, false) }
   396	func (i SectionType) GoString() string { return stringName(uint32(i), shtStrings, true) }
   397	
   398	// Section flags.
   399	type SectionFlag uint32
   400	
   401	const (
   402		SHF_WRITE            SectionFlag = 0x1        /* Section contains writable data. */
   403		SHF_ALLOC            SectionFlag = 0x2        /* Section occupies memory. */
   404		SHF_EXECINSTR        SectionFlag = 0x4        /* Section contains instructions. */
   405		SHF_MERGE            SectionFlag = 0x10       /* Section may be merged. */
   406		SHF_STRINGS          SectionFlag = 0x20       /* Section contains strings. */
   407		SHF_INFO_LINK        SectionFlag = 0x40       /* sh_info holds section index. */
   408		SHF_LINK_ORDER       SectionFlag = 0x80       /* Special ordering requirements. */
   409		SHF_OS_NONCONFORMING SectionFlag = 0x100      /* OS-specific processing required. */
   410		SHF_GROUP            SectionFlag = 0x200      /* Member of section group. */
   411		SHF_TLS              SectionFlag = 0x400      /* Section contains TLS data. */
   412		SHF_MASKOS           SectionFlag = 0x0ff00000 /* OS-specific semantics. */
   413		SHF_MASKPROC         SectionFlag = 0xf0000000 /* Processor-specific semantics. */
   414	)
   415	
   416	var shfStrings = []intName{
   417		{0x1, "SHF_WRITE"},
   418		{0x2, "SHF_ALLOC"},
   419		{0x4, "SHF_EXECINSTR"},
   420		{0x10, "SHF_MERGE"},
   421		{0x20, "SHF_STRINGS"},
   422		{0x40, "SHF_INFO_LINK"},
   423		{0x80, "SHF_LINK_ORDER"},
   424		{0x100, "SHF_OS_NONCONFORMING"},
   425		{0x200, "SHF_GROUP"},
   426		{0x400, "SHF_TLS"},
   427	}
   428	
   429	func (i SectionFlag) String() string   { return flagName(uint32(i), shfStrings, false) }
   430	func (i SectionFlag) GoString() string { return flagName(uint32(i), shfStrings, true) }
   431	
   432	// Prog.Type
   433	type ProgType int
   434	
   435	const (
   436		PT_NULL    ProgType = 0          /* Unused entry. */
   437		PT_LOAD    ProgType = 1          /* Loadable segment. */
   438		PT_DYNAMIC ProgType = 2          /* Dynamic linking information segment. */
   439		PT_INTERP  ProgType = 3          /* Pathname of interpreter. */
   440		PT_NOTE    ProgType = 4          /* Auxiliary information. */
   441		PT_SHLIB   ProgType = 5          /* Reserved (not used). */
   442		PT_PHDR    ProgType = 6          /* Location of program header itself. */
   443		PT_TLS     ProgType = 7          /* Thread local storage segment */
   444		PT_LOOS    ProgType = 0x60000000 /* First OS-specific. */
   445		PT_HIOS    ProgType = 0x6fffffff /* Last OS-specific. */
   446		PT_LOPROC  ProgType = 0x70000000 /* First processor-specific type. */
   447		PT_HIPROC  ProgType = 0x7fffffff /* Last processor-specific type. */
   448	)
   449	
   450	var ptStrings = []intName{
   451		{0, "PT_NULL"},
   452		{1, "PT_LOAD"},
   453		{2, "PT_DYNAMIC"},
   454		{3, "PT_INTERP"},
   455		{4, "PT_NOTE"},
   456		{5, "PT_SHLIB"},
   457		{6, "PT_PHDR"},
   458		{7, "PT_TLS"},
   459		{0x60000000, "PT_LOOS"},
   460		{0x6fffffff, "PT_HIOS"},
   461		{0x70000000, "PT_LOPROC"},
   462		{0x7fffffff, "PT_HIPROC"},
   463	}
   464	
   465	func (i ProgType) String() string   { return stringName(uint32(i), ptStrings, false) }
   466	func (i ProgType) GoString() string { return stringName(uint32(i), ptStrings, true) }
   467	
   468	// Prog.Flag
   469	type ProgFlag uint32
   470	
   471	const (
   472		PF_X        ProgFlag = 0x1        /* Executable. */
   473		PF_W        ProgFlag = 0x2        /* Writable. */
   474		PF_R        ProgFlag = 0x4        /* Readable. */
   475		PF_MASKOS   ProgFlag = 0x0ff00000 /* Operating system-specific. */
   476		PF_MASKPROC ProgFlag = 0xf0000000 /* Processor-specific. */
   477	)
   478	
   479	var pfStrings = []intName{
   480		{0x1, "PF_X"},
   481		{0x2, "PF_W"},
   482		{0x4, "PF_R"},
   483	}
   484	
   485	func (i ProgFlag) String() string   { return flagName(uint32(i), pfStrings, false) }
   486	func (i ProgFlag) GoString() string { return flagName(uint32(i), pfStrings, true) }
   487	
   488	// Dyn.Tag
   489	type DynTag int
   490	
   491	const (
   492		DT_NULL         DynTag = 0  /* Terminating entry. */
   493		DT_NEEDED       DynTag = 1  /* String table offset of a needed shared library. */
   494		DT_PLTRELSZ     DynTag = 2  /* Total size in bytes of PLT relocations. */
   495		DT_PLTGOT       DynTag = 3  /* Processor-dependent address. */
   496		DT_HASH         DynTag = 4  /* Address of symbol hash table. */
   497		DT_STRTAB       DynTag = 5  /* Address of string table. */
   498		DT_SYMTAB       DynTag = 6  /* Address of symbol table. */
   499		DT_RELA         DynTag = 7  /* Address of ElfNN_Rela relocations. */
   500		DT_RELASZ       DynTag = 8  /* Total size of ElfNN_Rela relocations. */
   501		DT_RELAENT      DynTag = 9  /* Size of each ElfNN_Rela relocation entry. */
   502		DT_STRSZ        DynTag = 10 /* Size of string table. */
   503		DT_SYMENT       DynTag = 11 /* Size of each symbol table entry. */
   504		DT_INIT         DynTag = 12 /* Address of initialization function. */
   505		DT_FINI         DynTag = 13 /* Address of finalization function. */
   506		DT_SONAME       DynTag = 14 /* String table offset of shared object name. */
   507		DT_RPATH        DynTag = 15 /* String table offset of library path. [sup] */
   508		DT_SYMBOLIC     DynTag = 16 /* Indicates "symbolic" linking. [sup] */
   509		DT_REL          DynTag = 17 /* Address of ElfNN_Rel relocations. */
   510		DT_RELSZ        DynTag = 18 /* Total size of ElfNN_Rel relocations. */
   511		DT_RELENT       DynTag = 19 /* Size of each ElfNN_Rel relocation. */
   512		DT_PLTREL       DynTag = 20 /* Type of relocation used for PLT. */
   513		DT_DEBUG        DynTag = 21 /* Reserved (not used). */
   514		DT_TEXTREL      DynTag = 22 /* Indicates there may be relocations in non-writable segments. [sup] */
   515		DT_JMPREL       DynTag = 23 /* Address of PLT relocations. */
   516		DT_BIND_NOW     DynTag = 24 /* [sup] */
   517		DT_INIT_ARRAY   DynTag = 25 /* Address of the array of pointers to initialization functions */
   518		DT_FINI_ARRAY   DynTag = 26 /* Address of the array of pointers to termination functions */
   519		DT_INIT_ARRAYSZ DynTag = 27 /* Size in bytes of the array of initialization functions. */
   520		DT_FINI_ARRAYSZ DynTag = 28 /* Size in bytes of the array of terminationfunctions. */
   521		DT_RUNPATH      DynTag = 29 /* String table offset of a null-terminated library search path string. */
   522		DT_FLAGS        DynTag = 30 /* Object specific flag values. */
   523		DT_ENCODING     DynTag = 32 /* Values greater than or equal to DT_ENCODING
   524		   and less than DT_LOOS follow the rules for
   525		   the interpretation of the d_un union
   526		   as follows: even == 'd_ptr', even == 'd_val'
   527		   or none */
   528		DT_PREINIT_ARRAY   DynTag = 32         /* Address of the array of pointers to pre-initialization functions. */
   529		DT_PREINIT_ARRAYSZ DynTag = 33         /* Size in bytes of the array of pre-initialization functions. */
   530		DT_LOOS            DynTag = 0x6000000d /* First OS-specific */
   531		DT_HIOS            DynTag = 0x6ffff000 /* Last OS-specific */
   532		DT_VERSYM          DynTag = 0x6ffffff0
   533		DT_VERNEED         DynTag = 0x6ffffffe
   534		DT_VERNEEDNUM      DynTag = 0x6fffffff
   535		DT_LOPROC          DynTag = 0x70000000 /* First processor-specific type. */
   536		DT_HIPROC          DynTag = 0x7fffffff /* Last processor-specific type. */
   537	)
   538	
   539	var dtStrings = []intName{
   540		{0, "DT_NULL"},
   541		{1, "DT_NEEDED"},
   542		{2, "DT_PLTRELSZ"},
   543		{3, "DT_PLTGOT"},
   544		{4, "DT_HASH"},
   545		{5, "DT_STRTAB"},
   546		{6, "DT_SYMTAB"},
   547		{7, "DT_RELA"},
   548		{8, "DT_RELASZ"},
   549		{9, "DT_RELAENT"},
   550		{10, "DT_STRSZ"},
   551		{11, "DT_SYMENT"},
   552		{12, "DT_INIT"},
   553		{13, "DT_FINI"},
   554		{14, "DT_SONAME"},
   555		{15, "DT_RPATH"},
   556		{16, "DT_SYMBOLIC"},
   557		{17, "DT_REL"},
   558		{18, "DT_RELSZ"},
   559		{19, "DT_RELENT"},
   560		{20, "DT_PLTREL"},
   561		{21, "DT_DEBUG"},
   562		{22, "DT_TEXTREL"},
   563		{23, "DT_JMPREL"},
   564		{24, "DT_BIND_NOW"},
   565		{25, "DT_INIT_ARRAY"},
   566		{26, "DT_FINI_ARRAY"},
   567		{27, "DT_INIT_ARRAYSZ"},
   568		{28, "DT_FINI_ARRAYSZ"},
   569		{29, "DT_RUNPATH"},
   570		{30, "DT_FLAGS"},
   571		{32, "DT_ENCODING"},
   572		{32, "DT_PREINIT_ARRAY"},
   573		{33, "DT_PREINIT_ARRAYSZ"},
   574		{0x6000000d, "DT_LOOS"},
   575		{0x6ffff000, "DT_HIOS"},
   576		{0x6ffffff0, "DT_VERSYM"},
   577		{0x6ffffffe, "DT_VERNEED"},
   578		{0x6fffffff, "DT_VERNEEDNUM"},
   579		{0x70000000, "DT_LOPROC"},
   580		{0x7fffffff, "DT_HIPROC"},
   581	}
   582	
   583	func (i DynTag) String() string   { return stringName(uint32(i), dtStrings, false) }
   584	func (i DynTag) GoString() string { return stringName(uint32(i), dtStrings, true) }
   585	
   586	// DT_FLAGS values.
   587	type DynFlag int
   588	
   589	const (
   590		DF_ORIGIN DynFlag = 0x0001 /* Indicates that the object being loaded may
   591		   make reference to the
   592		   $ORIGIN substitution string */
   593		DF_SYMBOLIC DynFlag = 0x0002 /* Indicates "symbolic" linking. */
   594		DF_TEXTREL  DynFlag = 0x0004 /* Indicates there may be relocations in non-writable segments. */
   595		DF_BIND_NOW DynFlag = 0x0008 /* Indicates that the dynamic linker should
   596		   process all relocations for the object
   597		   containing this entry before transferring
   598		   control to the program. */
   599		DF_STATIC_TLS DynFlag = 0x0010 /* Indicates that the shared object or
   600		   executable contains code using a static
   601		   thread-local storage scheme. */
   602	)
   603	
   604	var dflagStrings = []intName{
   605		{0x0001, "DF_ORIGIN"},
   606		{0x0002, "DF_SYMBOLIC"},
   607		{0x0004, "DF_TEXTREL"},
   608		{0x0008, "DF_BIND_NOW"},
   609		{0x0010, "DF_STATIC_TLS"},
   610	}
   611	
   612	func (i DynFlag) String() string   { return flagName(uint32(i), dflagStrings, false) }
   613	func (i DynFlag) GoString() string { return flagName(uint32(i), dflagStrings, true) }
   614	
   615	// NType values; used in core files.
   616	type NType int
   617	
   618	const (
   619		NT_PRSTATUS NType = 1 /* Process status. */
   620		NT_FPREGSET NType = 2 /* Floating point registers. */
   621		NT_PRPSINFO NType = 3 /* Process state info. */
   622	)
   623	
   624	var ntypeStrings = []intName{
   625		{1, "NT_PRSTATUS"},
   626		{2, "NT_FPREGSET"},
   627		{3, "NT_PRPSINFO"},
   628	}
   629	
   630	func (i NType) String() string   { return stringName(uint32(i), ntypeStrings, false) }
   631	func (i NType) GoString() string { return stringName(uint32(i), ntypeStrings, true) }
   632	
   633	/* Symbol Binding - ELFNN_ST_BIND - st_info */
   634	type SymBind int
   635	
   636	const (
   637		STB_LOCAL  SymBind = 0  /* Local symbol */
   638		STB_GLOBAL SymBind = 1  /* Global symbol */
   639		STB_WEAK   SymBind = 2  /* like global - lower precedence */
   640		STB_LOOS   SymBind = 10 /* Reserved range for operating system */
   641		STB_HIOS   SymBind = 12 /*   specific semantics. */
   642		STB_LOPROC SymBind = 13 /* reserved range for processor */
   643		STB_HIPROC SymBind = 15 /*   specific semantics. */
   644	)
   645	
   646	var stbStrings = []intName{
   647		{0, "STB_LOCAL"},
   648		{1, "STB_GLOBAL"},
   649		{2, "STB_WEAK"},
   650		{10, "STB_LOOS"},
   651		{12, "STB_HIOS"},
   652		{13, "STB_LOPROC"},
   653		{15, "STB_HIPROC"},
   654	}
   655	
   656	func (i SymBind) String() string   { return stringName(uint32(i), stbStrings, false) }
   657	func (i SymBind) GoString() string { return stringName(uint32(i), stbStrings, true) }
   658	
   659	/* Symbol type - ELFNN_ST_TYPE - st_info */
   660	type SymType int
   661	
   662	const (
   663		STT_NOTYPE  SymType = 0  /* Unspecified type. */
   664		STT_OBJECT  SymType = 1  /* Data object. */
   665		STT_FUNC    SymType = 2  /* Function. */
   666		STT_SECTION SymType = 3  /* Section. */
   667		STT_FILE    SymType = 4  /* Source file. */
   668		STT_COMMON  SymType = 5  /* Uninitialized common block. */
   669		STT_TLS     SymType = 6  /* TLS object. */
   670		STT_LOOS    SymType = 10 /* Reserved range for operating system */
   671		STT_HIOS    SymType = 12 /*   specific semantics. */
   672		STT_LOPROC  SymType = 13 /* reserved range for processor */
   673		STT_HIPROC  SymType = 15 /*   specific semantics. */
   674	)
   675	
   676	var sttStrings = []intName{
   677		{0, "STT_NOTYPE"},
   678		{1, "STT_OBJECT"},
   679		{2, "STT_FUNC"},
   680		{3, "STT_SECTION"},
   681		{4, "STT_FILE"},
   682		{5, "STT_COMMON"},
   683		{6, "STT_TLS"},
   684		{10, "STT_LOOS"},
   685		{12, "STT_HIOS"},
   686		{13, "STT_LOPROC"},
   687		{15, "STT_HIPROC"},
   688	}
   689	
   690	func (i SymType) String() string   { return stringName(uint32(i), sttStrings, false) }
   691	func (i SymType) GoString() string { return stringName(uint32(i), sttStrings, true) }
   692	
   693	/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */
   694	type SymVis int
   695	
   696	const (
   697		STV_DEFAULT   SymVis = 0x0 /* Default visibility (see binding). */
   698		STV_INTERNAL  SymVis = 0x1 /* Special meaning in relocatable objects. */
   699		STV_HIDDEN    SymVis = 0x2 /* Not visible. */
   700		STV_PROTECTED SymVis = 0x3 /* Visible but not preemptible. */
   701	)
   702	
   703	var stvStrings = []intName{
   704		{0x0, "STV_DEFAULT"},
   705		{0x1, "STV_INTERNAL"},
   706		{0x2, "STV_HIDDEN"},
   707		{0x3, "STV_PROTECTED"},
   708	}
   709	
   710	func (i SymVis) String() string   { return stringName(uint32(i), stvStrings, false) }
   711	func (i SymVis) GoString() string { return stringName(uint32(i), stvStrings, true) }
   712	
   713	/*
   714	 * Relocation types.
   715	 */
   716	
   717	// Relocation types for x86-64.
   718	type R_X86_64 int
   719	
   720	const (
   721		R_X86_64_NONE     R_X86_64 = 0  /* No relocation. */
   722		R_X86_64_64       R_X86_64 = 1  /* Add 64 bit symbol value. */
   723		R_X86_64_PC32     R_X86_64 = 2  /* PC-relative 32 bit signed sym value. */
   724		R_X86_64_GOT32    R_X86_64 = 3  /* PC-relative 32 bit GOT offset. */
   725		R_X86_64_PLT32    R_X86_64 = 4  /* PC-relative 32 bit PLT offset. */
   726		R_X86_64_COPY     R_X86_64 = 5  /* Copy data from shared object. */
   727		R_X86_64_GLOB_DAT R_X86_64 = 6  /* Set GOT entry to data address. */
   728		R_X86_64_JMP_SLOT R_X86_64 = 7  /* Set GOT entry to code address. */
   729		R_X86_64_RELATIVE R_X86_64 = 8  /* Add load address of shared object. */
   730		R_X86_64_GOTPCREL R_X86_64 = 9  /* Add 32 bit signed pcrel offset to GOT. */
   731		R_X86_64_32       R_X86_64 = 10 /* Add 32 bit zero extended symbol value */
   732		R_X86_64_32S      R_X86_64 = 11 /* Add 32 bit sign extended symbol value */
   733		R_X86_64_16       R_X86_64 = 12 /* Add 16 bit zero extended symbol value */
   734		R_X86_64_PC16     R_X86_64 = 13 /* Add 16 bit signed extended pc relative symbol value */
   735		R_X86_64_8        R_X86_64 = 14 /* Add 8 bit zero extended symbol value */
   736		R_X86_64_PC8      R_X86_64 = 15 /* Add 8 bit signed extended pc relative symbol value */
   737		R_X86_64_DTPMOD64 R_X86_64 = 16 /* ID of module containing symbol */
   738		R_X86_64_DTPOFF64 R_X86_64 = 17 /* Offset in TLS block */
   739		R_X86_64_TPOFF64  R_X86_64 = 18 /* Offset in static TLS block */
   740		R_X86_64_TLSGD    R_X86_64 = 19 /* PC relative offset to GD GOT entry */
   741		R_X86_64_TLSLD    R_X86_64 = 20 /* PC relative offset to LD GOT entry */
   742		R_X86_64_DTPOFF32 R_X86_64 = 21 /* Offset in TLS block */
   743		R_X86_64_GOTTPOFF R_X86_64 = 22 /* PC relative offset to IE GOT entry */
   744		R_X86_64_TPOFF32  R_X86_64 = 23 /* Offset in static TLS block */
   745	)
   746	
   747	var rx86_64Strings = []intName{
   748		{0, "R_X86_64_NONE"},
   749		{1, "R_X86_64_64"},
   750		{2, "R_X86_64_PC32"},
   751		{3, "R_X86_64_GOT32"},
   752		{4, "R_X86_64_PLT32"},
   753		{5, "R_X86_64_COPY"},
   754		{6, "R_X86_64_GLOB_DAT"},
   755		{7, "R_X86_64_JMP_SLOT"},
   756		{8, "R_X86_64_RELATIVE"},
   757		{9, "R_X86_64_GOTPCREL"},
   758		{10, "R_X86_64_32"},
   759		{11, "R_X86_64_32S"},
   760		{12, "R_X86_64_16"},
   761		{13, "R_X86_64_PC16"},
   762		{14, "R_X86_64_8"},
   763		{15, "R_X86_64_PC8"},
   764		{16, "R_X86_64_DTPMOD64"},
   765		{17, "R_X86_64_DTPOFF64"},
   766		{18, "R_X86_64_TPOFF64"},
   767		{19, "R_X86_64_TLSGD"},
   768		{20, "R_X86_64_TLSLD"},
   769		{21, "R_X86_64_DTPOFF32"},
   770		{22, "R_X86_64_GOTTPOFF"},
   771		{23, "R_X86_64_TPOFF32"},
   772	}
   773	
   774	func (i R_X86_64) String() string   { return stringName(uint32(i), rx86_64Strings, false) }
   775	func (i R_X86_64) GoString() string { return stringName(uint32(i), rx86_64Strings, true) }
   776	
   777	// Relocation types for Alpha.
   778	type R_ALPHA int
   779	
   780	const (
   781		R_ALPHA_NONE           R_ALPHA = 0  /* No reloc */
   782		R_ALPHA_REFLONG        R_ALPHA = 1  /* Direct 32 bit */
   783		R_ALPHA_REFQUAD        R_ALPHA = 2  /* Direct 64 bit */
   784		R_ALPHA_GPREL32        R_ALPHA = 3  /* GP relative 32 bit */
   785		R_ALPHA_LITERAL        R_ALPHA = 4  /* GP relative 16 bit w/optimization */
   786		R_ALPHA_LITUSE         R_ALPHA = 5  /* Optimization hint for LITERAL */
   787		R_ALPHA_GPDISP         R_ALPHA = 6  /* Add displacement to GP */
   788		R_ALPHA_BRADDR         R_ALPHA = 7  /* PC+4 relative 23 bit shifted */
   789		R_ALPHA_HINT           R_ALPHA = 8  /* PC+4 relative 16 bit shifted */
   790		R_ALPHA_SREL16         R_ALPHA = 9  /* PC relative 16 bit */
   791		R_ALPHA_SREL32         R_ALPHA = 10 /* PC relative 32 bit */
   792		R_ALPHA_SREL64         R_ALPHA = 11 /* PC relative 64 bit */
   793		R_ALPHA_OP_PUSH        R_ALPHA = 12 /* OP stack push */
   794		R_ALPHA_OP_STORE       R_ALPHA = 13 /* OP stack pop and store */
   795		R_ALPHA_OP_PSUB        R_ALPHA = 14 /* OP stack subtract */
   796		R_ALPHA_OP_PRSHIFT     R_ALPHA = 15 /* OP stack right shift */
   797		R_ALPHA_GPVALUE        R_ALPHA = 16
   798		R_ALPHA_GPRELHIGH      R_ALPHA = 17
   799		R_ALPHA_GPRELLOW       R_ALPHA = 18
   800		R_ALPHA_IMMED_GP_16    R_ALPHA = 19
   801		R_ALPHA_IMMED_GP_HI32  R_ALPHA = 20
   802		R_ALPHA_IMMED_SCN_HI32 R_ALPHA = 21
   803		R_ALPHA_IMMED_BR_HI32  R_ALPHA = 22
   804		R_ALPHA_IMMED_LO32     R_ALPHA = 23
   805		R_ALPHA_COPY           R_ALPHA = 24 /* Copy symbol at runtime */
   806		R_ALPHA_GLOB_DAT       R_ALPHA = 25 /* Create GOT entry */
   807		R_ALPHA_JMP_SLOT       R_ALPHA = 26 /* Create PLT entry */
   808		R_ALPHA_RELATIVE       R_ALPHA = 27 /* Adjust by program base */
   809	)
   810	
   811	var ralphaStrings = []intName{
   812		{0, "R_ALPHA_NONE"},
   813		{1, "R_ALPHA_REFLONG"},
   814		{2, "R_ALPHA_REFQUAD"},
   815		{3, "R_ALPHA_GPREL32"},
   816		{4, "R_ALPHA_LITERAL"},
   817		{5, "R_ALPHA_LITUSE"},
   818		{6, "R_ALPHA_GPDISP"},
   819		{7, "R_ALPHA_BRADDR"},
   820		{8, "R_ALPHA_HINT"},
   821		{9, "R_ALPHA_SREL16"},
   822		{10, "R_ALPHA_SREL32"},
   823		{11, "R_ALPHA_SREL64"},
   824		{12, "R_ALPHA_OP_PUSH"},
   825		{13, "R_ALPHA_OP_STORE"},
   826		{14, "R_ALPHA_OP_PSUB"},
   827		{15, "R_ALPHA_OP_PRSHIFT"},
   828		{16, "R_ALPHA_GPVALUE"},
   829		{17, "R_ALPHA_GPRELHIGH"},
   830		{18, "R_ALPHA_GPRELLOW"},
   831		{19, "R_ALPHA_IMMED_GP_16"},
   832		{20, "R_ALPHA_IMMED_GP_HI32"},
   833		{21, "R_ALPHA_IMMED_SCN_HI32"},
   834		{22, "R_ALPHA_IMMED_BR_HI32"},
   835		{23, "R_ALPHA_IMMED_LO32"},
   836		{24, "R_ALPHA_COPY"},
   837		{25, "R_ALPHA_GLOB_DAT"},
   838		{26, "R_ALPHA_JMP_SLOT"},
   839		{27, "R_ALPHA_RELATIVE"},
   840	}
   841	
   842	func (i R_ALPHA) String() string   { return stringName(uint32(i), ralphaStrings, false) }
   843	func (i R_ALPHA) GoString() string { return stringName(uint32(i), ralphaStrings, true) }
   844	
   845	// Relocation types for ARM.
   846	type R_ARM int
   847	
   848	const (
   849		R_ARM_NONE          R_ARM = 0 /* No relocation. */
   850		R_ARM_PC24          R_ARM = 1
   851		R_ARM_ABS32         R_ARM = 2
   852		R_ARM_REL32         R_ARM = 3
   853		R_ARM_PC13          R_ARM = 4
   854		R_ARM_ABS16         R_ARM = 5
   855		R_ARM_ABS12         R_ARM = 6
   856		R_ARM_THM_ABS5      R_ARM = 7
   857		R_ARM_ABS8          R_ARM = 8
   858		R_ARM_SBREL32       R_ARM = 9
   859		R_ARM_THM_PC22      R_ARM = 10
   860		R_ARM_THM_PC8       R_ARM = 11
   861		R_ARM_AMP_VCALL9    R_ARM = 12
   862		R_ARM_SWI24         R_ARM = 13
   863		R_ARM_THM_SWI8      R_ARM = 14
   864		R_ARM_XPC25         R_ARM = 15
   865		R_ARM_THM_XPC22     R_ARM = 16
   866		R_ARM_COPY          R_ARM = 20 /* Copy data from shared object. */
   867		R_ARM_GLOB_DAT      R_ARM = 21 /* Set GOT entry to data address. */
   868		R_ARM_JUMP_SLOT     R_ARM = 22 /* Set GOT entry to code address. */
   869		R_ARM_RELATIVE      R_ARM = 23 /* Add load address of shared object. */
   870		R_ARM_GOTOFF        R_ARM = 24 /* Add GOT-relative symbol address. */
   871		R_ARM_GOTPC         R_ARM = 25 /* Add PC-relative GOT table address. */
   872		R_ARM_GOT32         R_ARM = 26 /* Add PC-relative GOT offset. */
   873		R_ARM_PLT32         R_ARM = 27 /* Add PC-relative PLT offset. */
   874		R_ARM_GNU_VTENTRY   R_ARM = 100
   875		R_ARM_GNU_VTINHERIT R_ARM = 101
   876		R_ARM_RSBREL32      R_ARM = 250
   877		R_ARM_THM_RPC22     R_ARM = 251
   878		R_ARM_RREL32        R_ARM = 252
   879		R_ARM_RABS32        R_ARM = 253
   880		R_ARM_RPC24         R_ARM = 254
   881		R_ARM_RBASE         R_ARM = 255
   882	)
   883	
   884	var rarmStrings = []intName{
   885		{0, "R_ARM_NONE"},
   886		{1, "R_ARM_PC24"},
   887		{2, "R_ARM_ABS32"},
   888		{3, "R_ARM_REL32"},
   889		{4, "R_ARM_PC13"},
   890		{5, "R_ARM_ABS16"},
   891		{6, "R_ARM_ABS12"},
   892		{7, "R_ARM_THM_ABS5"},
   893		{8, "R_ARM_ABS8"},
   894		{9, "R_ARM_SBREL32"},
   895		{10, "R_ARM_THM_PC22"},
   896		{11, "R_ARM_THM_PC8"},
   897		{12, "R_ARM_AMP_VCALL9"},
   898		{13, "R_ARM_SWI24"},
   899		{14, "R_ARM_THM_SWI8"},
   900		{15, "R_ARM_XPC25"},
   901		{16, "R_ARM_THM_XPC22"},
   902		{20, "R_ARM_COPY"},
   903		{21, "R_ARM_GLOB_DAT"},
   904		{22, "R_ARM_JUMP_SLOT"},
   905		{23, "R_ARM_RELATIVE"},
   906		{24, "R_ARM_GOTOFF"},
   907		{25, "R_ARM_GOTPC"},
   908		{26, "R_ARM_GOT32"},
   909		{27, "R_ARM_PLT32"},
   910		{100, "R_ARM_GNU_VTENTRY"},
   911		{101, "R_ARM_GNU_VTINHERIT"},
   912		{250, "R_ARM_RSBREL32"},
   913		{251, "R_ARM_THM_RPC22"},
   914		{252, "R_ARM_RREL32"},
   915		{253, "R_ARM_RABS32"},
   916		{254, "R_ARM_RPC24"},
   917		{255, "R_ARM_RBASE"},
   918	}
   919	
   920	func (i R_ARM) String() string   { return stringName(uint32(i), rarmStrings, false) }
   921	func (i R_ARM) GoString() string { return stringName(uint32(i), rarmStrings, true) }
   922	
   923	// Relocation types for 386.
   924	type R_386 int
   925	
   926	const (
   927		R_386_NONE         R_386 = 0  /* No relocation. */
   928		R_386_32           R_386 = 1  /* Add symbol value. */
   929		R_386_PC32         R_386 = 2  /* Add PC-relative symbol value. */
   930		R_386_GOT32        R_386 = 3  /* Add PC-relative GOT offset. */
   931		R_386_PLT32        R_386 = 4  /* Add PC-relative PLT offset. */
   932		R_386_COPY         R_386 = 5  /* Copy data from shared object. */
   933		R_386_GLOB_DAT     R_386 = 6  /* Set GOT entry to data address. */
   934		R_386_JMP_SLOT     R_386 = 7  /* Set GOT entry to code address. */
   935		R_386_RELATIVE     R_386 = 8  /* Add load address of shared object. */
   936		R_386_GOTOFF       R_386 = 9  /* Add GOT-relative symbol address. */
   937		R_386_GOTPC        R_386 = 10 /* Add PC-relative GOT table address. */
   938		R_386_TLS_TPOFF    R_386 = 14 /* Negative offset in static TLS block */
   939		R_386_TLS_IE       R_386 = 15 /* Absolute address of GOT for -ve static TLS */
   940		R_386_TLS_GOTIE    R_386 = 16 /* GOT entry for negative static TLS block */
   941		R_386_TLS_LE       R_386 = 17 /* Negative offset relative to static TLS */
   942		R_386_TLS_GD       R_386 = 18 /* 32 bit offset to GOT (index,off) pair */
   943		R_386_TLS_LDM      R_386 = 19 /* 32 bit offset to GOT (index,zero) pair */
   944		R_386_TLS_GD_32    R_386 = 24 /* 32 bit offset to GOT (index,off) pair */
   945		R_386_TLS_GD_PUSH  R_386 = 25 /* pushl instruction for Sun ABI GD sequence */
   946		R_386_TLS_GD_CALL  R_386 = 26 /* call instruction for Sun ABI GD sequence */
   947		R_386_TLS_GD_POP   R_386 = 27 /* popl instruction for Sun ABI GD sequence */
   948		R_386_TLS_LDM_32   R_386 = 28 /* 32 bit offset to GOT (index,zero) pair */
   949		R_386_TLS_LDM_PUSH R_386 = 29 /* pushl instruction for Sun ABI LD sequence */
   950		R_386_TLS_LDM_CALL R_386 = 30 /* call instruction for Sun ABI LD sequence */
   951		R_386_TLS_LDM_POP  R_386 = 31 /* popl instruction for Sun ABI LD sequence */
   952		R_386_TLS_LDO_32   R_386 = 32 /* 32 bit offset from start of TLS block */
   953		R_386_TLS_IE_32    R_386 = 33 /* 32 bit offset to GOT static TLS offset entry */
   954		R_386_TLS_LE_32    R_386 = 34 /* 32 bit offset within static TLS block */
   955		R_386_TLS_DTPMOD32 R_386 = 35 /* GOT entry containing TLS index */
   956		R_386_TLS_DTPOFF32 R_386 = 36 /* GOT entry containing TLS offset */
   957		R_386_TLS_TPOFF32  R_386 = 37 /* GOT entry of -ve static TLS offset */
   958	)
   959	
   960	var r386Strings = []intName{
   961		{0, "R_386_NONE"},
   962		{1, "R_386_32"},
   963		{2, "R_386_PC32"},
   964		{3, "R_386_GOT32"},
   965		{4, "R_386_PLT32"},
   966		{5, "R_386_COPY"},
   967		{6, "R_386_GLOB_DAT"},
   968		{7, "R_386_JMP_SLOT"},
   969		{8, "R_386_RELATIVE"},
   970		{9, "R_386_GOTOFF"},
   971		{10, "R_386_GOTPC"},
   972		{14, "R_386_TLS_TPOFF"},
   973		{15, "R_386_TLS_IE"},
   974		{16, "R_386_TLS_GOTIE"},
   975		{17, "R_386_TLS_LE"},
   976		{18, "R_386_TLS_GD"},
   977		{19, "R_386_TLS_LDM"},
   978		{24, "R_386_TLS_GD_32"},
   979		{25, "R_386_TLS_GD_PUSH"},
   980		{26, "R_386_TLS_GD_CALL"},
   981		{27, "R_386_TLS_GD_POP"},
   982		{28, "R_386_TLS_LDM_32"},
   983		{29, "R_386_TLS_LDM_PUSH"},
   984		{30, "R_386_TLS_LDM_CALL"},
   985		{31, "R_386_TLS_LDM_POP"},
   986		{32, "R_386_TLS_LDO_32"},
   987		{33, "R_386_TLS_IE_32"},
   988		{34, "R_386_TLS_LE_32"},
   989		{35, "R_386_TLS_DTPMOD32"},
   990		{36, "R_386_TLS_DTPOFF32"},
   991		{37, "R_386_TLS_TPOFF32"},
   992	}
   993	
   994	func (i R_386) String() string   { return stringName(uint32(i), r386Strings, false) }
   995	func (i R_386) GoString() string { return stringName(uint32(i), r386Strings, true) }
   996	
   997	// Relocation types for PowerPC.
   998	type R_PPC int
   999	
  1000	const (
  1001		R_PPC_NONE            R_PPC = 0 /* No relocation. */
  1002		R_PPC_ADDR32          R_PPC = 1
  1003		R_PPC_ADDR24          R_PPC = 2
  1004		R_PPC_ADDR16          R_PPC = 3
  1005		R_PPC_ADDR16_LO       R_PPC = 4
  1006		R_PPC_ADDR16_HI       R_PPC = 5
  1007		R_PPC_ADDR16_HA       R_PPC = 6
  1008		R_PPC_ADDR14          R_PPC = 7
  1009		R_PPC_ADDR14_BRTAKEN  R_PPC = 8
  1010		R_PPC_ADDR14_BRNTAKEN R_PPC = 9
  1011		R_PPC_REL24           R_PPC = 10
  1012		R_PPC_REL14           R_PPC = 11
  1013		R_PPC_REL14_BRTAKEN   R_PPC = 12
  1014		R_PPC_REL14_BRNTAKEN  R_PPC = 13
  1015		R_PPC_GOT16           R_PPC = 14
  1016		R_PPC_GOT16_LO        R_PPC = 15
  1017		R_PPC_GOT16_HI        R_PPC = 16
  1018		R_PPC_GOT16_HA        R_PPC = 17
  1019		R_PPC_PLTREL24        R_PPC = 18
  1020		R_PPC_COPY            R_PPC = 19
  1021		R_PPC_GLOB_DAT        R_PPC = 20
  1022		R_PPC_JMP_SLOT        R_PPC = 21
  1023		R_PPC_RELATIVE        R_PPC = 22
  1024		R_PPC_LOCAL24PC       R_PPC = 23
  1025		R_PPC_UADDR32         R_PPC = 24
  1026		R_PPC_UADDR16         R_PPC = 25
  1027		R_PPC_REL32           R_PPC = 26
  1028		R_PPC_PLT32           R_PPC = 27
  1029		R_PPC_PLTREL32        R_PPC = 28
  1030		R_PPC_PLT16_LO        R_PPC = 29
  1031		R_PPC_PLT16_HI        R_PPC = 30
  1032		R_PPC_PLT16_HA        R_PPC = 31
  1033		R_PPC_SDAREL16        R_PPC = 32
  1034		R_PPC_SECTOFF         R_PPC = 33
  1035		R_PPC_SECTOFF_LO      R_PPC = 34
  1036		R_PPC_SECTOFF_HI      R_PPC = 35
  1037		R_PPC_SECTOFF_HA      R_PPC = 36
  1038		R_PPC_TLS             R_PPC = 67
  1039		R_PPC_DTPMOD32        R_PPC = 68
  1040		R_PPC_TPREL16         R_PPC = 69
  1041		R_PPC_TPREL16_LO      R_PPC = 70
  1042		R_PPC_TPREL16_HI      R_PPC = 71
  1043		R_PPC_TPREL16_HA      R_PPC = 72
  1044		R_PPC_TPREL32         R_PPC = 73
  1045		R_PPC_DTPREL16        R_PPC = 74
  1046		R_PPC_DTPREL16_LO     R_PPC = 75
  1047		R_PPC_DTPREL16_HI     R_PPC = 76
  1048		R_PPC_DTPREL16_HA     R_PPC = 77
  1049		R_PPC_DTPREL32        R_PPC = 78
  1050		R_PPC_GOT_TLSGD16     R_PPC = 79
  1051		R_PPC_GOT_TLSGD16_LO  R_PPC = 80
  1052		R_PPC_GOT_TLSGD16_HI  R_PPC = 81
  1053		R_PPC_GOT_TLSGD16_HA  R_PPC = 82
  1054		R_PPC_GOT_TLSLD16     R_PPC = 83
  1055		R_PPC_GOT_TLSLD16_LO  R_PPC = 84
  1056		R_PPC_GOT_TLSLD16_HI  R_PPC = 85
  1057		R_PPC_GOT_TLSLD16_HA  R_PPC = 86
  1058		R_PPC_GOT_TPREL16     R_PPC = 87
  1059		R_PPC_GOT_TPREL16_LO  R_PPC = 88
  1060		R_PPC_GOT_TPREL16_HI  R_PPC = 89
  1061		R_PPC_GOT_TPREL16_HA  R_PPC = 90
  1062		R_PPC_EMB_NADDR32     R_PPC = 101
  1063		R_PPC_EMB_NADDR16     R_PPC = 102
  1064		R_PPC_EMB_NADDR16_LO  R_PPC = 103
  1065		R_PPC_EMB_NADDR16_HI  R_PPC = 104
  1066		R_PPC_EMB_NADDR16_HA  R_PPC = 105
  1067		R_PPC_EMB_SDAI16      R_PPC = 106
  1068		R_PPC_EMB_SDA2I16     R_PPC = 107
  1069		R_PPC_EMB_SDA2REL     R_PPC = 108
  1070		R_PPC_EMB_SDA21       R_PPC = 109
  1071		R_PPC_EMB_MRKREF      R_PPC = 110
  1072		R_PPC_EMB_RELSEC16    R_PPC = 111
  1073		R_PPC_EMB_RELST_LO    R_PPC = 112
  1074		R_PPC_EMB_RELST_HI    R_PPC = 113
  1075		R_PPC_EMB_RELST_HA    R_PPC = 114
  1076		R_PPC_EMB_BIT_FLD     R_PPC = 115
  1077		R_PPC_EMB_RELSDA      R_PPC = 116
  1078	)
  1079	
  1080	var rppcStrings = []intName{
  1081		{0, "R_PPC_NONE"},
  1082		{1, "R_PPC_ADDR32"},
  1083		{2, "R_PPC_ADDR24"},
  1084		{3, "R_PPC_ADDR16"},
  1085		{4, "R_PPC_ADDR16_LO"},
  1086		{5, "R_PPC_ADDR16_HI"},
  1087		{6, "R_PPC_ADDR16_HA"},
  1088		{7, "R_PPC_ADDR14"},
  1089		{8, "R_PPC_ADDR14_BRTAKEN"},
  1090		{9, "R_PPC_ADDR14_BRNTAKEN"},
  1091		{10, "R_PPC_REL24"},
  1092		{11, "R_PPC_REL14"},
  1093		{12, "R_PPC_REL14_BRTAKEN"},
  1094		{13, "R_PPC_REL14_BRNTAKEN"},
  1095		{14, "R_PPC_GOT16"},
  1096		{15, "R_PPC_GOT16_LO"},
  1097		{16, "R_PPC_GOT16_HI"},
  1098		{17, "R_PPC_GOT16_HA"},
  1099		{18, "R_PPC_PLTREL24"},
  1100		{19, "R_PPC_COPY"},
  1101		{20, "R_PPC_GLOB_DAT"},
  1102		{21, "R_PPC_JMP_SLOT"},
  1103		{22, "R_PPC_RELATIVE"},
  1104		{23, "R_PPC_LOCAL24PC"},
  1105		{24, "R_PPC_UADDR32"},
  1106		{25, "R_PPC_UADDR16"},
  1107		{26, "R_PPC_REL32"},
  1108		{27, "R_PPC_PLT32"},
  1109		{28, "R_PPC_PLTREL32"},
  1110		{29, "R_PPC_PLT16_LO"},
  1111		{30, "R_PPC_PLT16_HI"},
  1112		{31, "R_PPC_PLT16_HA"},
  1113		{32, "R_PPC_SDAREL16"},
  1114		{33, "R_PPC_SECTOFF"},
  1115		{34, "R_PPC_SECTOFF_LO"},
  1116		{35, "R_PPC_SECTOFF_HI"},
  1117		{36, "R_PPC_SECTOFF_HA"},
  1118	
  1119		{67, "R_PPC_TLS"},
  1120		{68, "R_PPC_DTPMOD32"},
  1121		{69, "R_PPC_TPREL16"},
  1122		{70, "R_PPC_TPREL16_LO"},
  1123		{71, "R_PPC_TPREL16_HI"},
  1124		{72, "R_PPC_TPREL16_HA"},
  1125		{73, "R_PPC_TPREL32"},
  1126		{74, "R_PPC_DTPREL16"},
  1127		{75, "R_PPC_DTPREL16_LO"},
  1128		{76, "R_PPC_DTPREL16_HI"},
  1129		{77, "R_PPC_DTPREL16_HA"},
  1130		{78, "R_PPC_DTPREL32"},
  1131		{79, "R_PPC_GOT_TLSGD16"},
  1132		{80, "R_PPC_GOT_TLSGD16_LO"},
  1133		{81, "R_PPC_GOT_TLSGD16_HI"},
  1134		{82, "R_PPC_GOT_TLSGD16_HA"},
  1135		{83, "R_PPC_GOT_TLSLD16"},
  1136		{84, "R_PPC_GOT_TLSLD16_LO"},
  1137		{85, "R_PPC_GOT_TLSLD16_HI"},
  1138		{86, "R_PPC_GOT_TLSLD16_HA"},
  1139		{87, "R_PPC_GOT_TPREL16"},
  1140		{88, "R_PPC_GOT_TPREL16_LO"},
  1141		{89, "R_PPC_GOT_TPREL16_HI"},
  1142		{90, "R_PPC_GOT_TPREL16_HA"},
  1143	
  1144		{101, "R_PPC_EMB_NADDR32"},
  1145		{102, "R_PPC_EMB_NADDR16"},
  1146		{103, "R_PPC_EMB_NADDR16_LO"},
  1147		{104, "R_PPC_EMB_NADDR16_HI"},
  1148		{105, "R_PPC_EMB_NADDR16_HA"},
  1149		{106, "R_PPC_EMB_SDAI16"},
  1150		{107, "R_PPC_EMB_SDA2I16"},
  1151		{108, "R_PPC_EMB_SDA2REL"},
  1152		{109, "R_PPC_EMB_SDA21"},
  1153		{110, "R_PPC_EMB_MRKREF"},
  1154		{111, "R_PPC_EMB_RELSEC16"},
  1155		{112, "R_PPC_EMB_RELST_LO"},
  1156		{113, "R_PPC_EMB_RELST_HI"},
  1157		{114, "R_PPC_EMB_RELST_HA"},
  1158		{115, "R_PPC_EMB_BIT_FLD"},
  1159		{116, "R_PPC_EMB_RELSDA"},
  1160	}
  1161	
  1162	func (i R_PPC) String() string   { return stringName(uint32(i), rppcStrings, false) }
  1163	func (i R_PPC) GoString() string { return stringName(uint32(i), rppcStrings, true) }
  1164	
  1165	// Relocation types for SPARC.
  1166	type R_SPARC int
  1167	
  1168	const (
  1169		R_SPARC_NONE     R_SPARC = 0
  1170		R_SPARC_8        R_SPARC = 1
  1171		R_SPARC_16       R_SPARC = 2
  1172		R_SPARC_32       R_SPARC = 3
  1173		R_SPARC_DISP8    R_SPARC = 4
  1174		R_SPARC_DISP16   R_SPARC = 5
  1175		R_SPARC_DISP32   R_SPARC = 6
  1176		R_SPARC_WDISP30  R_SPARC = 7
  1177		R_SPARC_WDISP22  R_SPARC = 8
  1178		R_SPARC_HI22     R_SPARC = 9
  1179		R_SPARC_22       R_SPARC = 10
  1180		R_SPARC_13       R_SPARC = 11
  1181		R_SPARC_LO10     R_SPARC = 12
  1182		R_SPARC_GOT10    R_SPARC = 13
  1183		R_SPARC_GOT13    R_SPARC = 14
  1184		R_SPARC_GOT22    R_SPARC = 15
  1185		R_SPARC_PC10     R_SPARC = 16
  1186		R_SPARC_PC22     R_SPARC = 17
  1187		R_SPARC_WPLT30   R_SPARC = 18
  1188		R_SPARC_COPY     R_SPARC = 19
  1189		R_SPARC_GLOB_DAT R_SPARC = 20
  1190		R_SPARC_JMP_SLOT R_SPARC = 21
  1191		R_SPARC_RELATIVE R_SPARC = 22
  1192		R_SPARC_UA32     R_SPARC = 23
  1193		R_SPARC_PLT32    R_SPARC = 24
  1194		R_SPARC_HIPLT22  R_SPARC = 25
  1195		R_SPARC_LOPLT10  R_SPARC = 26
  1196		R_SPARC_PCPLT32  R_SPARC = 27
  1197		R_SPARC_PCPLT22  R_SPARC = 28
  1198		R_SPARC_PCPLT10  R_SPARC = 29
  1199		R_SPARC_10       R_SPARC = 30
  1200		R_SPARC_11       R_SPARC = 31
  1201		R_SPARC_64       R_SPARC = 32
  1202		R_SPARC_OLO10    R_SPARC = 33
  1203		R_SPARC_HH22     R_SPARC = 34
  1204		R_SPARC_HM10     R_SPARC = 35
  1205		R_SPARC_LM22     R_SPARC = 36
  1206		R_SPARC_PC_HH22  R_SPARC = 37
  1207		R_SPARC_PC_HM10  R_SPARC = 38
  1208		R_SPARC_PC_LM22  R_SPARC = 39
  1209		R_SPARC_WDISP16  R_SPARC = 40
  1210		R_SPARC_WDISP19  R_SPARC = 41
  1211		R_SPARC_GLOB_JMP R_SPARC = 42
  1212		R_SPARC_7        R_SPARC = 43
  1213		R_SPARC_5        R_SPARC = 44
  1214		R_SPARC_6        R_SPARC = 45
  1215		R_SPARC_DISP64   R_SPARC = 46
  1216		R_SPARC_PLT64    R_SPARC = 47
  1217		R_SPARC_HIX22    R_SPARC = 48
  1218		R_SPARC_LOX10    R_SPARC = 49
  1219		R_SPARC_H44      R_SPARC = 50
  1220		R_SPARC_M44      R_SPARC = 51
  1221		R_SPARC_L44      R_SPARC = 52
  1222		R_SPARC_REGISTER R_SPARC = 53
  1223		R_SPARC_UA64     R_SPARC = 54
  1224		R_SPARC_UA16     R_SPARC = 55
  1225	)
  1226	
  1227	var rsparcStrings = []intName{
  1228		{0, "R_SPARC_NONE"},
  1229		{1, "R_SPARC_8"},
  1230		{2, "R_SPARC_16"},
  1231		{3, "R_SPARC_32"},
  1232		{4, "R_SPARC_DISP8"},
  1233		{5, "R_SPARC_DISP16"},
  1234		{6, "R_SPARC_DISP32"},
  1235		{7, "R_SPARC_WDISP30"},
  1236		{8, "R_SPARC_WDISP22"},
  1237		{9, "R_SPARC_HI22"},
  1238		{10, "R_SPARC_22"},
  1239		{11, "R_SPARC_13"},
  1240		{12, "R_SPARC_LO10"},
  1241		{13, "R_SPARC_GOT10"},
  1242		{14, "R_SPARC_GOT13"},
  1243		{15, "R_SPARC_GOT22"},
  1244		{16, "R_SPARC_PC10"},
  1245		{17, "R_SPARC_PC22"},
  1246		{18, "R_SPARC_WPLT30"},
  1247		{19, "R_SPARC_COPY"},
  1248		{20, "R_SPARC_GLOB_DAT"},
  1249		{21, "R_SPARC_JMP_SLOT"},
  1250		{22, "R_SPARC_RELATIVE"},
  1251		{23, "R_SPARC_UA32"},
  1252		{24, "R_SPARC_PLT32"},
  1253		{25, "R_SPARC_HIPLT22"},
  1254		{26, "R_SPARC_LOPLT10"},
  1255		{27, "R_SPARC_PCPLT32"},
  1256		{28, "R_SPARC_PCPLT22"},
  1257		{29, "R_SPARC_PCPLT10"},
  1258		{30, "R_SPARC_10"},
  1259		{31, "R_SPARC_11"},
  1260		{32, "R_SPARC_64"},
  1261		{33, "R_SPARC_OLO10"},
  1262		{34, "R_SPARC_HH22"},
  1263		{35, "R_SPARC_HM10"},
  1264		{36, "R_SPARC_LM22"},
  1265		{37, "R_SPARC_PC_HH22"},
  1266		{38, "R_SPARC_PC_HM10"},
  1267		{39, "R_SPARC_PC_LM22"},
  1268		{40, "R_SPARC_WDISP16"},
  1269		{41, "R_SPARC_WDISP19"},
  1270		{42, "R_SPARC_GLOB_JMP"},
  1271		{43, "R_SPARC_7"},
  1272		{44, "R_SPARC_5"},
  1273		{45, "R_SPARC_6"},
  1274		{46, "R_SPARC_DISP64"},
  1275		{47, "R_SPARC_PLT64"},
  1276		{48, "R_SPARC_HIX22"},
  1277		{49, "R_SPARC_LOX10"},
  1278		{50, "R_SPARC_H44"},
  1279		{51, "R_SPARC_M44"},
  1280		{52, "R_SPARC_L44"},
  1281		{53, "R_SPARC_REGISTER"},
  1282		{54, "R_SPARC_UA64"},
  1283		{55, "R_SPARC_UA16"},
  1284	}
  1285	
  1286	func (i R_SPARC) String() string   { return stringName(uint32(i), rsparcStrings, false) }
  1287	func (i R_SPARC) GoString() string { return stringName(uint32(i), rsparcStrings, true) }
  1288	
  1289	// Magic number for the elf trampoline, chosen wisely to be an immediate value.
  1290	const ARM_MAGIC_TRAMP_NUMBER = 0x5c000003
  1291	
  1292	// ELF32 File header.
  1293	type Header32 struct {
  1294		Ident     [EI_NIDENT]byte /* File identification. */
  1295		Type      uint16          /* File type. */
  1296		Machine   uint16          /* Machine architecture. */
  1297		Version   uint32          /* ELF format version. */
  1298		Entry     uint32          /* Entry point. */
  1299		Phoff     uint32          /* Program header file offset. */
  1300		Shoff     uint32          /* Section header file offset. */
  1301		Flags     uint32          /* Architecture-specific flags. */
  1302		Ehsize    uint16          /* Size of ELF header in bytes. */
  1303		Phentsize uint16          /* Size of program header entry. */
  1304		Phnum     uint16          /* Number of program header entries. */
  1305		Shentsize uint16          /* Size of section header entry. */
  1306		Shnum     uint16          /* Number of section header entries. */
  1307		Shstrndx  uint16          /* Section name strings section. */
  1308	}
  1309	
  1310	// ELF32 Section header.
  1311	type Section32 struct {
  1312		Name      uint32 /* Section name (index into the section header string table). */
  1313		Type      uint32 /* Section type. */
  1314		Flags     uint32 /* Section flags. */
  1315		Addr      uint32 /* Address in memory image. */
  1316		Off       uint32 /* Offset in file. */
  1317		Size      uint32 /* Size in bytes. */
  1318		Link      uint32 /* Index of a related section. */
  1319		Info      uint32 /* Depends on section type. */
  1320		Addralign uint32 /* Alignment in bytes. */
  1321		Entsize   uint32 /* Size of each entry in section. */
  1322	}
  1323	
  1324	// ELF32 Program header.
  1325	type Prog32 struct {
  1326		Type   uint32 /* Entry type. */
  1327		Off    uint32 /* File offset of contents. */
  1328		Vaddr  uint32 /* Virtual address in memory image. */
  1329		Paddr  uint32 /* Physical address (not used). */
  1330		Filesz uint32 /* Size of contents in file. */
  1331		Memsz  uint32 /* Size of contents in memory. */
  1332		Flags  uint32 /* Access permission flags. */
  1333		Align  uint32 /* Alignment in memory and file. */
  1334	}
  1335	
  1336	// ELF32 Dynamic structure.  The ".dynamic" section contains an array of them.
  1337	type Dyn32 struct {
  1338		Tag int32  /* Entry type. */
  1339		Val uint32 /* Integer/Address value. */
  1340	}
  1341	
  1342	/*
  1343	 * Relocation entries.
  1344	 */
  1345	
  1346	// ELF32 Relocations that don't need an addend field.
  1347	type Rel32 struct {
  1348		Off  uint32 /* Location to be relocated. */
  1349		Info uint32 /* Relocation type and symbol index. */
  1350	}
  1351	
  1352	// ELF32 Relocations that need an addend field.
  1353	type Rela32 struct {
  1354		Off    uint32 /* Location to be relocated. */
  1355		Info   uint32 /* Relocation type and symbol index. */
  1356		Addend int32  /* Addend. */
  1357	}
  1358	
  1359	func R_SYM32(info uint32) uint32      { return uint32(info >> 8) }
  1360	func R_TYPE32(info uint32) uint32     { return uint32(info & 0xff) }
  1361	func R_INFO32(sym, typ uint32) uint32 { return sym<<8 | typ }
  1362	
  1363	// ELF32 Symbol.
  1364	type Sym32 struct {
  1365		Name  uint32
  1366		Value uint32
  1367		Size  uint32
  1368		Info  uint8
  1369		Other uint8
  1370		Shndx uint16
  1371	}
  1372	
  1373	const Sym32Size = 16
  1374	
  1375	func ST_BIND(info uint8) SymBind { return SymBind(info >> 4) }
  1376	func ST_TYPE(info uint8) SymType { return SymType(info & 0xF) }
  1377	func ST_INFO(bind SymBind, typ SymType) uint8 {
  1378		return uint8(bind)<<4 | uint8(typ)&0xf
  1379	}
  1380	func ST_VISIBILITY(other uint8) SymVis { return SymVis(other & 3) }
  1381	
  1382	/*
  1383	 * ELF64
  1384	 */
  1385	
  1386	// ELF64 file header.
  1387	type Header64 struct {
  1388		Ident     [EI_NIDENT]byte /* File identification. */
  1389		Type      uint16          /* File type. */
  1390		Machine   uint16          /* Machine architecture. */
  1391		Version   uint32          /* ELF format version. */
  1392		Entry     uint64          /* Entry point. */
  1393		Phoff     uint64          /* Program header file offset. */
  1394		Shoff     uint64          /* Section header file offset. */
  1395		Flags     uint32          /* Architecture-specific flags. */
  1396		Ehsize    uint16          /* Size of ELF header in bytes. */
  1397		Phentsize uint16          /* Size of program header entry. */
  1398		Phnum     uint16          /* Number of program header entries. */
  1399		Shentsize uint16          /* Size of section header entry. */
  1400		Shnum     uint16          /* Number of section header entries. */
  1401		Shstrndx  uint16          /* Section name strings section. */
  1402	}
  1403	
  1404	// ELF64 Section header.
  1405	type Section64 struct {
  1406		Name      uint32 /* Section name (index into the section header string table). */
  1407		Type      uint32 /* Section type. */
  1408		Flags     uint64 /* Section flags. */
  1409		Addr      uint64 /* Address in memory image. */
  1410		Off       uint64 /* Offset in file. */
  1411		Size      uint64 /* Size in bytes. */
  1412		Link      uint32 /* Index of a related section. */
  1413		Info      uint32 /* Depends on section type. */
  1414		Addralign uint64 /* Alignment in bytes. */
  1415		Entsize   uint64 /* Size of each entry in section. */
  1416	}
  1417	
  1418	// ELF64 Program header.
  1419	type Prog64 struct {
  1420		Type   uint32 /* Entry type. */
  1421		Flags  uint32 /* Access permission flags. */
  1422		Off    uint64 /* File offset of contents. */
  1423		Vaddr  uint64 /* Virtual address in memory image. */
  1424		Paddr  uint64 /* Physical address (not used). */
  1425		Filesz uint64 /* Size of contents in file. */
  1426		Memsz  uint64 /* Size of contents in memory. */
  1427		Align  uint64 /* Alignment in memory and file. */
  1428	}
  1429	
  1430	// ELF64 Dynamic structure.  The ".dynamic" section contains an array of them.
  1431	type Dyn64 struct {
  1432		Tag int64  /* Entry type. */
  1433		Val uint64 /* Integer/address value */
  1434	}
  1435	
  1436	/*
  1437	 * Relocation entries.
  1438	 */
  1439	
  1440	/* ELF64 relocations that don't need an addend field. */
  1441	type Rel64 struct {
  1442		Off  uint64 /* Location to be relocated. */
  1443		Info uint64 /* Relocation type and symbol index. */
  1444	}
  1445	
  1446	/* ELF64 relocations that need an addend field. */
  1447	type Rela64 struct {
  1448		Off    uint64 /* Location to be relocated. */
  1449		Info   uint64 /* Relocation type and symbol index. */
  1450		Addend int64  /* Addend. */
  1451	}
  1452	
  1453	func R_SYM64(info uint64) uint32    { return uint32(info >> 32) }
  1454	func R_TYPE64(info uint64) uint32   { return uint32(info) }
  1455	func R_INFO(sym, typ uint32) uint64 { return uint64(sym)<<32 | uint64(typ) }
  1456	
  1457	// ELF64 symbol table entries.
  1458	type Sym64 struct {
  1459		Name  uint32 /* String table index of name. */
  1460		Info  uint8  /* Type and binding information. */
  1461		Other uint8  /* Reserved (not used). */
  1462		Shndx uint16 /* Section index of symbol. */
  1463		Value uint64 /* Symbol value. */
  1464		Size  uint64 /* Size of associated object. */
  1465	}
  1466	
  1467	const Sym64Size = 24
  1468	
  1469	type intName struct {
  1470		i uint32
  1471		s string
  1472	}
  1473	
  1474	func stringName(i uint32, names []intName, goSyntax bool) string {
  1475		for _, n := range names {
  1476			if n.i == i {
  1477				if goSyntax {
  1478					return "elf." + n.s
  1479				}
  1480				return n.s
  1481			}
  1482		}
  1483	
  1484		// second pass - look for smaller to add with.
  1485		// assume sorted already
  1486		for j := len(names) - 1; j >= 0; j-- {
  1487			n := names[j]
  1488			if n.i < i {
  1489				s := n.s
  1490				if goSyntax {
  1491					s = "elf." + s
  1492				}
  1493				return s + "+" + strconv.FormatUint(uint64(i-n.i), 10)
  1494			}
  1495		}
  1496	
  1497		return strconv.FormatUint(uint64(i), 10)
  1498	}
  1499	
  1500	func flagName(i uint32, names []intName, goSyntax bool) string {
  1501		s := ""
  1502		for _, n := range names {
  1503			if n.i&i == n.i {
  1504				if len(s) > 0 {
  1505					s += "+"
  1506				}
  1507				if goSyntax {
  1508					s += "elf."
  1509				}
  1510				s += n.s
  1511				i -= n.i
  1512			}
  1513		}
  1514		if len(s) == 0 {
  1515			return "0x" + strconv.FormatUint(uint64(i), 16)
  1516		}
  1517		if i != 0 {
  1518			s += "+0x" + strconv.FormatUint(uint64(i), 16)
  1519		}
  1520		return s
  1521	}