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