ELF.h revision 13534672deffb571d90f2c2f0a237c67d5aa0594
19a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//===-- llvm/Support/ELF.h - ELF constants and data structures --*- C++ -*-===//
29a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//
39a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//                     The LLVM Compiler Infrastructure
49a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//
59a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// This file is distributed under the University of Illinois Open Source
69a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// License. See LICENSE.TXT for details.
79a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//
89a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//===----------------------------------------------------------------------===//
99a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//
109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// This header contains common, non-processor-specific data structures and
11e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org// constants for the ELF file format.
12e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org//
139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// The details of the ELF32 bits in this file are largely based on the Tool
14e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org// Interface Standard (TIS) Executable and Linking Format (ELF) Specification
159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Version 1.2, May 1995. The ELF64 stuff is based on ELF-64 Object File Format
1649d62206ededc5905d6121d42fdcce8ed665b2c0kjellander@webrtc.org// Version 1.5, Draft 2, May 1998 as well as OpenBSD header files.
17774b3d38a4a0f1a8ec08972a3c543cb5d607ce13henrike@webrtc.org//
189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//===----------------------------------------------------------------------===//
199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#ifndef LLVM_SUPPORT_ELF_H
219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#define LLVM_SUPPORT_ELF_H
229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "llvm/System/DataTypes.h"
249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include <cstring>
259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgnamespace llvm {
279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgnamespace ELF {
299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint32_t Elf32_Addr; // Program address
319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint16_t Elf32_Half;
329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint32_t Elf32_Off;  // File offset
339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef int32_t  Elf32_Sword;
349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint32_t Elf32_Word;
359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint64_t Elf64_Addr;
379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint64_t Elf64_Off;
389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef int32_t  Elf64_Shalf;
399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef int32_t  Elf64_Sword;
409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint32_t Elf64_Word;
419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef int64_t  Elf64_Sxword;
429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint64_t Elf64_Xword;
439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint32_t Elf64_Half;
449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgtypedef uint16_t Elf64_Quarter;
459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Object file magic string.
479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgstatic const char ElfMagic[] = { 0x7f, 'E', 'L', 'F', '\0' };
489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// e_ident size and indices.
509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgenum {
519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_MAG0       = 0,          // File identification index.
529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_MAG1       = 1,          // File identification index.
539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_MAG2       = 2,          // File identification index.
549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_MAG3       = 3,          // File identification index.
559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_CLASS      = 4,          // File class.
569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_DATA       = 5,          // Data encoding.
579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_VERSION    = 6,          // File version.
589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_OSABI      = 7,          // OS/ABI identification.
599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_ABIVERSION = 8,          // ABI version.
609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_PAD        = 9,          // Start of padding bytes.
619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  EI_NIDENT     = 16          // Number of bytes in e_ident.
629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgstruct Elf32_Ehdr {
659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  unsigned char e_ident[EI_NIDENT]; // ELF Identification bytes
669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_type;      // Type of file (see ET_* below)
679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_machine;   // Required architecture for this file (see EM_*)
689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Word    e_version;   // Must be equal to 1
699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Addr    e_entry;     // Address to jump to in order to start program
709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Off     e_phoff;     // Program header table's file offset, in bytes
719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Off     e_shoff;     // Section header table's file offset, in bytes
729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Word    e_flags;     // Processor-specific flags
739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_ehsize;    // Size of ELF header, in bytes
749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_phentsize; // Size of an entry in the program header table
759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_phnum;     // Number of entries in the program header table
769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_shentsize; // Size of an entry in the section header table
779a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_shnum;     // Number of entries in the section header table
789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf32_Half    e_shstrndx;  // Sect hdr table index of sect name string table
799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  bool checkMagic() const {
809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return (memcmp(e_ident, ElfMagic, strlen(ElfMagic))) == 0;
819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  unsigned char getFileClass() const { return e_ident[EI_CLASS]; }
839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  unsigned char getDataEncoding() const { return e_ident[EI_DATA]; }
849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// 64-bit ELF header. Fields are the same as for ELF32, but with different
879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// types (see above).
889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgstruct Elf64_Ehdr {
899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  unsigned char e_ident[EI_NIDENT];
909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Quarter e_type;
919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Quarter e_machine;
929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Half    e_version;
939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Addr    e_entry;
949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Off     e_phoff;
959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Off     e_shoff;
969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Half    e_flags;
979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Quarter e_ehsize;
989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  Elf64_Quarter e_phentsize;
99e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org  Elf64_Quarter e_phnum;
100  Elf64_Quarter e_shentsize;
101  Elf64_Quarter e_shnum;
102  Elf64_Quarter e_shstrndx;
103  bool checkMagic() const {
104    return (memcmp(e_ident, ElfMagic, strlen(ElfMagic))) == 0;
105  }
106  unsigned char getFileClass() const { return e_ident[EI_CLASS]; }
107  unsigned char getDataEncoding() const { return e_ident[EI_DATA]; }
108};
109
110// File types
111enum {
112  ET_NONE   = 0,      // No file type
113  ET_REL    = 1,      // Relocatable file
114  ET_EXEC   = 2,      // Executable file
115  ET_DYN    = 3,      // Shared object file
116  ET_CORE   = 4,      // Core file
117  ET_LOPROC = 0xff00, // Beginning of processor-specific codes
118  ET_HIPROC = 0xffff  // Processor-specific
119};
120
121// Versioning
122enum {
123  EV_NONE = 0,
124  EV_CURRENT = 1
125};
126
127// Machine architectures
128enum {
129  EM_NONE = 0,      // No machine
130  EM_M32 = 1,       // AT&T WE 32100
131  EM_SPARC = 2,     // SPARC
132  EM_386 = 3,       // Intel 386
133  EM_68K = 4,       // Motorola 68000
134  EM_88K = 5,       // Motorola 88000
135  EM_486 = 6,       // Intel 486 (deprecated)
136  EM_860 = 7,       // Intel 80860
137  EM_MIPS = 8,      // MIPS R3000
138  EM_PPC = 20,      // PowerPC
139  EM_PPC64 = 21,    // PowerPC64
140  EM_ARM = 40,      // ARM
141  EM_ALPHA = 41,    // DEC Alpha
142  EM_SPARCV9 = 43,  // SPARC V9
143  EM_X86_64 = 62,   // AMD64
144  EM_MBLAZE = 47787 // Xilinx MicroBlaze
145};
146
147// Object file classes.
148enum {
149  ELFCLASS32 = 1, // 32-bit object file
150  ELFCLASS64 = 2  // 64-bit object file
151};
152
153// Object file byte orderings.
154enum {
155  ELFDATANONE = 0, // Invalid data encoding.
156  ELFDATA2LSB = 1, // Little-endian object file
157  ELFDATA2MSB = 2  // Big-endian object file
158};
159
160// OS ABI identification.
161enum {
162  ELFOSABI_NONE = 0,          // UNIX System V ABI
163  ELFOSABI_HPUX = 1,          // HP-UX operating system
164  ELFOSABI_NETBSD = 2,        // NetBSD
165  ELFOSABI_LINUX = 3,         // GNU/Linux
166  ELFOSABI_HURD = 4,          // GNU/Hurd
167  ELFOSABI_SOLARIS = 6,       // Solaris
168  ELFOSABI_AIX = 7,           // AIX
169  ELFOSABI_IRIX = 8,          // IRIX
170  ELFOSABI_FREEBSD = 9,       // FreeBSD
171  ELFOSABI_TRU64 = 10,        // TRU64 UNIX
172  ELFOSABI_MODESTO = 11,      // Novell Modesto
173  ELFOSABI_OPENBSD = 12,      // OpenBSD
174  ELFOSABI_OPENVMS = 13,      // OpenVMS
175  ELFOSABI_NSK = 14,          // Hewlett-Packard Non-Stop Kernel
176  ELFOSABI_AROS = 15,         // AROS
177  ELFOSABI_FENIXOS = 16,      // FenixOS
178  ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000
179  ELFOSABI_C6000_LINUX = 65,  // Linux TMS320C6000
180  ELFOSABI_ARM = 97,          // ARM
181  ELFOSABI_STANDALONE = 255   // Standalone (embedded) application
182};
183
184// X86_64 relocations.
185enum {
186  R_X86_64_NONE       = 0,
187  R_X86_64_64         = 1,
188  R_X86_64_PC32       = 2,
189  R_X86_64_GOT32      = 3,
190  R_X86_64_PLT32      = 4,
191  R_X86_64_COPY       = 5,
192  R_X86_64_GLOB_DAT   = 6,
193  R_X86_64_JUMP_SLOT  = 7,
194  R_X86_64_RELATIVE   = 8,
195  R_X86_64_GOTPCREL   = 9,
196  R_X86_64_32         = 10,
197  R_X86_64_32S        = 11,
198  R_X86_64_16         = 12,
199  R_X86_64_PC16       = 13,
200  R_X86_64_8          = 14,
201  R_X86_64_PC8        = 15,
202  R_X86_64_DTPMOD64   = 16,
203  R_X86_64_DTPOFF64   = 17,
204  R_X86_64_TPOFF64    = 18,
205  R_X86_64_TLSGD      = 19,
206  R_X86_64_TLSLD      = 20,
207  R_X86_64_DTPOFF32   = 21,
208  R_X86_64_GOTTPOFF   = 22,
209  R_X86_64_TPOFF32    = 23,
210  R_X86_64_PC64       = 24,
211  R_X86_64_GOTOFF64   = 25,
212  R_X86_64_GOTPC32    = 26,
213  R_X86_64_SIZE32     = 32,
214  R_X86_64_SIZE64     = 33,
215  R_X86_64_GOTPC32_TLSDESC = 34,
216  R_X86_64_TLSDESC_CALL    = 35,
217  R_X86_64_TLSDESC    = 36
218};
219
220// i386 relocations.
221// TODO: this is just a subset
222enum {
223  R_386_NONE          = 0,
224  R_386_32            = 1,
225  R_386_PC32          = 2,
226  R_386_GOT32         = 3,
227  R_386_PLT32         = 4,
228  R_386_COPY          = 5,
229  R_386_GLOB_DAT      = 6,
230  R_386_JUMP_SLOT     = 7,
231  R_386_RELATIVE      = 8,
232  R_386_GOTOFF        = 9,
233  R_386_GOTPC         = 10,
234  R_386_32PLT         = 11,
235  R_386_TLS_TPOFF     = 14,
236  R_386_TLS_IE        = 15,
237  R_386_TLS_GOTIE     = 16,
238  R_386_TLS_LE        = 17,
239  R_386_TLS_GD        = 18,
240  R_386_TLS_LDM       = 19,
241  R_386_16            = 20,
242  R_386_PC16          = 21,
243  R_386_8             = 22,
244  R_386_PC8           = 23,
245  R_386_TLS_GD_32     = 24,
246  R_386_TLS_GD_PUSH   = 25,
247  R_386_TLS_GD_CALL   = 26,
248  R_386_TLS_GD_POP    = 27,
249  R_386_TLS_LDM_32    = 28,
250  R_386_TLS_LDM_PUSH  = 29,
251  R_386_TLS_LDM_CALL  = 30,
252  R_386_TLS_LDM_POP   = 31,
253  R_386_TLS_LDO_32    = 32,
254  R_386_TLS_IE_32     = 33,
255  R_386_TLS_LE_32     = 34,
256  R_386_TLS_DTPMOD32  = 35,
257  R_386_TLS_DTPOFF32  = 36,
258  R_386_TLS_TPOFF32   = 37,
259  R_386_TLS_GOTDESC   = 39,
260  R_386_TLS_DESC_CALL = 40,
261  R_386_TLS_DESC      = 41,
262  R_386_IRELATIVE     = 42,
263  R_386_NUM           = 43
264};
265
266// MBlaze relocations.
267enum {
268  R_MICROBLAZE_NONE           = 0,
269  R_MICROBLAZE_32             = 1,
270  R_MICROBLAZE_32_PCREL       = 2,
271  R_MICROBLAZE_64_PCREL       = 3,
272  R_MICROBLAZE_32_PCREL_LO    = 4,
273  R_MICROBLAZE_64             = 5,
274  R_MICROBLAZE_32_LO          = 6,
275  R_MICROBLAZE_SRO32          = 7,
276  R_MICROBLAZE_SRW32          = 8,
277  R_MICROBLAZE_64_NONE        = 9,
278  R_MICROBLAZE_32_SYM_OP_SYM  = 10,
279  R_MICROBLAZE_GNU_VTINHERIT  = 11,
280  R_MICROBLAZE_GNU_VTENTRY    = 12,
281  R_MICROBLAZE_GOTPC_64       = 13,
282  R_MICROBLAZE_GOT_64         = 14,
283  R_MICROBLAZE_PLT_64         = 15,
284  R_MICROBLAZE_REL            = 16,
285  R_MICROBLAZE_JUMP_SLOT      = 17,
286  R_MICROBLAZE_GLOB_DAT       = 18,
287  R_MICROBLAZE_GOTOFF_64      = 19,
288  R_MICROBLAZE_GOTOFF_32      = 20,
289  R_MICROBLAZE_COPY           = 21
290};
291
292// ELF Relocation types for ARM
293// Meets 2.08 ABI Specs.
294
295enum {
296  R_ARM_NONE                  = 0x00,
297  R_ARM_PC24                  = 0x01,
298  R_ARM_ABS32                 = 0x02,
299  R_ARM_REL32                 = 0x03,
300  R_ARM_LDR_PC_G0             = 0x04,
301  R_ARM_ABS16                 = 0x05,
302  R_ARM_ABS12                 = 0x06,
303  R_ARM_THM_ABS5              = 0x07,
304  R_ARM_ABS8                  = 0x08,
305  R_ARM_SBREL32               = 0x09,
306  R_ARM_THM_CALL              = 0x0a,
307  R_ARM_THM_PC8               = 0x0b,
308  R_ARM_BREL_ADJ              = 0x0c,
309  R_ARM_TLS_DESC              = 0x0d,
310  R_ARM_THM_SWI8              = 0x0e,
311  R_ARM_XPC25                 = 0x0f,
312  R_ARM_THM_XPC22             = 0x10,
313  R_ARM_TLS_DTPMOD32          = 0x11,
314  R_ARM_TLS_DTPOFF32          = 0x12,
315  R_ARM_TLS_TPOFF32           = 0x13,
316  R_ARM_COPY                  = 0x14,
317  R_ARM_GLOB_DAT              = 0x15,
318  R_ARM_JUMP_SLOT             = 0x16,
319  R_ARM_RELATIVE              = 0x17,
320  R_ARM_GOTOFF32              = 0x18,
321  R_ARM_BASE_PREL             = 0x19,
322  R_ARM_GOT_BREL              = 0x1a,
323  R_ARM_PLT32                 = 0x1b,
324  R_ARM_CALL                  = 0x1c,
325  R_ARM_JUMP24                = 0x1d,
326  R_ARM_THM_JUMP24            = 0x1e,
327  R_ARM_BASE_ABS              = 0x1f,
328  R_ARM_ALU_PCREL_7_0         = 0x20,
329  R_ARM_ALU_PCREL_15_8        = 0x21,
330  R_ARM_ALU_PCREL_23_15       = 0x22,
331  R_ARM_LDR_SBREL_11_0_NC     = 0x23,
332  R_ARM_ALU_SBREL_19_12_NC    = 0x24,
333  R_ARM_ALU_SBREL_27_20_CK    = 0x25,
334  R_ARM_TARGET1               = 0x26,
335  R_ARM_SBREL31               = 0x27,
336  R_ARM_V4BX                  = 0x28,
337  R_ARM_TARGET2               = 0x29,
338  R_ARM_PREL31                = 0x2a,
339  R_ARM_MOVW_ABS_NC           = 0x2b,
340  R_ARM_MOVT_ABS              = 0x2c,
341  R_ARM_MOVW_PREL_NC          = 0x2d,
342  R_ARM_MOVT_PREL             = 0x2e,
343  R_ARM_THM_MOVW_ABS_NC       = 0x2f,
344  R_ARM_THM_MOVT_ABS          = 0x30,
345  R_ARM_THM_MOVW_PREL_NC      = 0x31,
346  R_ARM_THM_MOVT_PREL         = 0x32,
347  R_ARM_THM_JUMP19            = 0x33,
348  R_ARM_THM_JUMP6             = 0x34,
349  R_ARM_THM_ALU_PREL_11_0     = 0x35,
350  R_ARM_THM_PC12              = 0x36,
351  R_ARM_ABS32_NOI             = 0x37,
352  R_ARM_REL32_NOI             = 0x38,
353  R_ARM_ALU_PC_G0_NC          = 0x39,
354  R_ARM_ALU_PC_G0             = 0x3a,
355  R_ARM_ALU_PC_G1_NC          = 0x3b,
356  R_ARM_ALU_PC_G1             = 0x3c,
357  R_ARM_ALU_PC_G2             = 0x3d,
358  R_ARM_LDR_PC_G1             = 0x3e,
359  R_ARM_LDR_PC_G2             = 0x3f,
360  R_ARM_LDRS_PC_G0            = 0x40,
361  R_ARM_LDRS_PC_G1            = 0x41,
362  R_ARM_LDRS_PC_G2            = 0x42,
363  R_ARM_LDC_PC_G0             = 0x43,
364  R_ARM_LDC_PC_G1             = 0x44,
365  R_ARM_LDC_PC_G2             = 0x45,
366  R_ARM_ALU_SB_G0_NC          = 0x46,
367  R_ARM_ALU_SB_G0             = 0x47,
368  R_ARM_ALU_SB_G1_NC          = 0x48,
369  R_ARM_ALU_SB_G1             = 0x49,
370  R_ARM_ALU_SB_G2             = 0x4a,
371  R_ARM_LDR_SB_G0             = 0x4b,
372  R_ARM_LDR_SB_G1             = 0x4c,
373  R_ARM_LDR_SB_G2             = 0x4d,
374  R_ARM_LDRS_SB_G0            = 0x4e,
375  R_ARM_LDRS_SB_G1            = 0x4f,
376  R_ARM_LDRS_SB_G2            = 0x50,
377  R_ARM_LDC_SB_G0             = 0x51,
378  R_ARM_LDC_SB_G1             = 0x52,
379  R_ARM_LDC_SB_G2             = 0x53,
380  R_ARM_MOVW_BREL_NC          = 0x54,
381  R_ARM_MOVT_BREL             = 0x55,
382  R_ARM_MOVW_BREL             = 0x56,
383  R_ARM_THM_MOVW_BREL_NC      = 0x57,
384  R_ARM_THM_MOVT_BREL         = 0x58,
385  R_ARM_THM_MOVW_BREL         = 0x59,
386  R_ARM_TLS_GOTDESC           = 0x5a,
387  R_ARM_TLS_CALL              = 0x5b,
388  R_ARM_TLS_DESCSEQ           = 0x5c,
389  R_ARM_THM_TLS_CALL          = 0x5d,
390  R_ARM_PLT32_ABS             = 0x5e,
391  R_ARM_GOT_ABS               = 0x5f,
392  R_ARM_GOT_PREL              = 0x60,
393  R_ARM_GOT_BREL12            = 0x61,
394  R_ARM_GOTOFF12              = 0x62,
395  R_ARM_GOTRELAX              = 0x63,
396  R_ARM_GNU_VTENTRY           = 0x64,
397  R_ARM_GNU_VTINHERIT         = 0x65,
398  R_ARM_THM_JUMP11            = 0x66,
399  R_ARM_THM_JUMP8             = 0x67,
400  R_ARM_TLS_GD32              = 0x68,
401  R_ARM_TLS_LDM32             = 0x69,
402  R_ARM_TLS_LDO32             = 0x6a,
403  R_ARM_TLS_IE32              = 0x6b,
404  R_ARM_TLS_LE32              = 0x6c,
405  R_ARM_TLS_LDO12             = 0x6d,
406  R_ARM_TLS_LE12              = 0x6e,
407  R_ARM_TLS_IE12GP            = 0x6f,
408  R_ARM_PRIVATE_0             = 0x70,
409  R_ARM_PRIVATE_1             = 0x71,
410  R_ARM_PRIVATE_2             = 0x72,
411  R_ARM_PRIVATE_3             = 0x73,
412  R_ARM_PRIVATE_4             = 0x74,
413  R_ARM_PRIVATE_5             = 0x75,
414  R_ARM_PRIVATE_6             = 0x76,
415  R_ARM_PRIVATE_7             = 0x77,
416  R_ARM_PRIVATE_8             = 0x78,
417  R_ARM_PRIVATE_9             = 0x79,
418  R_ARM_PRIVATE_10            = 0x7a,
419  R_ARM_PRIVATE_11            = 0x7b,
420  R_ARM_PRIVATE_12            = 0x7c,
421  R_ARM_PRIVATE_13            = 0x7d,
422  R_ARM_PRIVATE_14            = 0x7e,
423  R_ARM_PRIVATE_15            = 0x7f,
424  R_ARM_ME_TOO                = 0x80,
425  R_ARM_THM_TLS_DESCSEQ16     = 0x81,
426  R_ARM_THM_TLS_DESCSEQ32     = 0x82
427};
428
429
430
431// Section header.
432struct Elf32_Shdr {
433  Elf32_Word sh_name;      // Section name (index into string table)
434  Elf32_Word sh_type;      // Section type (SHT_*)
435  Elf32_Word sh_flags;     // Section flags (SHF_*)
436  Elf32_Addr sh_addr;      // Address where section is to be loaded
437  Elf32_Off  sh_offset;    // File offset of section data, in bytes
438  Elf32_Word sh_size;      // Size of section, in bytes
439  Elf32_Word sh_link;      // Section type-specific header table index link
440  Elf32_Word sh_info;      // Section type-specific extra information
441  Elf32_Word sh_addralign; // Section address alignment
442  Elf32_Word sh_entsize;   // Size of records contained within the section
443};
444
445// Section header for ELF64 - same fields as ELF32, different types.
446struct Elf64_Shdr {
447  Elf64_Half  sh_name;
448  Elf64_Half  sh_type;
449  Elf64_Xword sh_flags;
450  Elf64_Addr  sh_addr;
451  Elf64_Off   sh_offset;
452  Elf64_Xword sh_size;
453  Elf64_Half  sh_link;
454  Elf64_Half  sh_info;
455  Elf64_Xword sh_addralign;
456  Elf64_Xword sh_entsize;
457};
458
459// Special section indices.
460enum {
461  SHN_UNDEF     = 0,      // Undefined, missing, irrelevant, or meaningless
462  SHN_LORESERVE = 0xff00, // Lowest reserved index
463  SHN_LOPROC    = 0xff00, // Lowest processor-specific index
464  SHN_HIPROC    = 0xff1f, // Highest processor-specific index
465  SHN_ABS       = 0xfff1, // Symbol has absolute value; does not need relocation
466  SHN_COMMON    = 0xfff2, // FORTRAN COMMON or C external global variables
467  SHN_XINDEX    = 0xffff, // Mark that the index is >= SHN_LORESERVE
468  SHN_HIRESERVE = 0xffff  // Highest reserved index
469};
470
471// Section types.
472enum {
473  SHT_NULL          = 0,  // No associated section (inactive entry).
474  SHT_PROGBITS      = 1,  // Program-defined contents.
475  SHT_SYMTAB        = 2,  // Symbol table.
476  SHT_STRTAB        = 3,  // String table.
477  SHT_RELA          = 4,  // Relocation entries; explicit addends.
478  SHT_HASH          = 5,  // Symbol hash table.
479  SHT_DYNAMIC       = 6,  // Information for dynamic linking.
480  SHT_NOTE          = 7,  // Information about the file.
481  SHT_NOBITS        = 8,  // Data occupies no space in the file.
482  SHT_REL           = 9,  // Relocation entries; no explicit addends.
483  SHT_SHLIB         = 10, // Reserved.
484  SHT_DYNSYM        = 11, // Symbol table.
485  SHT_INIT_ARRAY    = 14, // Pointers to initialisation functions.
486  SHT_FINI_ARRAY    = 15, // Pointers to termination functions.
487  SHT_PREINIT_ARRAY = 16, // Pointers to pre-init functions.
488  SHT_GROUP         = 17, // Section group.
489  SHT_SYMTAB_SHNDX  = 18, // Indicies for SHN_XINDEX entries.
490  SHT_LOOS          = 0x60000000, // Lowest operating system-specific type.
491  SHT_HIOS          = 0x6fffffff, // Highest operating system-specific type.
492  SHT_LOPROC        = 0x70000000, // Lowest processor architecture-specific type.
493  // Fixme: All this is duplicated in MCSectionELF. Why??
494  // Exception Index table
495  SHT_ARM_EXIDX           = 0x70000001U,
496  // BPABI DLL dynamic linking pre-emption map
497  SHT_ARM_PREEMPTMAP      = 0x70000002U,
498  //  Object file compatibility attributes
499  SHT_ARM_ATTRIBUTES      = 0x70000003U,
500  SHT_ARM_DEBUGOVERLAY    = 0x70000004U,
501  SHT_ARM_OVERLAYSECTION  = 0x70000005U,
502
503  SHT_HIPROC        = 0x7fffffff, // Highest processor architecture-specific type.
504  SHT_LOUSER        = 0x80000000, // Lowest type reserved for applications.
505  SHT_HIUSER        = 0xffffffff  // Highest type reserved for applications.
506};
507
508// Section flags.
509enum {
510  SHF_WRITE     = 0x1, // Section data should be writable during execution.
511  SHF_ALLOC     = 0x2, // Section occupies memory during program execution.
512  SHF_EXECINSTR = 0x4, // Section contains executable machine instructions.
513  SHF_MASKPROC  = 0xf0000000 // Bits indicating processor-specific flags.
514};
515
516// Section Group Flags
517enum {
518  GRP_COMDAT = 0x1,
519  GRP_MASKOS = 0x0ff00000,
520  GRP_MASKPROC = 0xf0000000
521};
522
523// Symbol table entries for ELF32.
524struct Elf32_Sym {
525  Elf32_Word    st_name;  // Symbol name (index into string table)
526  Elf32_Addr    st_value; // Value or address associated with the symbol
527  Elf32_Word    st_size;  // Size of the symbol
528  unsigned char st_info;  // Symbol's type and binding attributes
529  unsigned char st_other; // Must be zero; reserved
530  Elf32_Half    st_shndx; // Which section (header table index) it's defined in
531
532  // These accessors and mutators correspond to the ELF32_ST_BIND,
533  // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
534  unsigned char getBinding() const { return st_info >> 4; }
535  unsigned char getType() const { return st_info & 0x0f; }
536  void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
537  void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
538  void setBindingAndType(unsigned char b, unsigned char t) {
539    st_info = (b << 4) + (t & 0x0f);
540  }
541};
542
543// Symbol table entries for ELF64.
544struct Elf64_Sym {
545  Elf64_Word      st_name;  // Symbol name (index into string table)
546  unsigned char   st_info;  // Symbol's type and binding attributes
547  unsigned char   st_other; // Must be zero; reserved
548  Elf64_Half      st_shndx; // Which section (header table index) it's defined in
549  Elf64_Addr      st_value; // Value or address associated with the symbol
550  Elf64_Xword     st_size;  // Size of the symbol
551
552  // These accessors and mutators are identical to those defined for ELF32
553  // symbol table entries.
554  unsigned char getBinding() const { return st_info >> 4; }
555  unsigned char getType() const { return st_info & 0x0f; }
556  void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
557  void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
558  void setBindingAndType(unsigned char b, unsigned char t) {
559    st_info = (b << 4) + (t & 0x0f);
560  }
561};
562
563// The size (in bytes) of symbol table entries.
564enum {
565  SYMENTRY_SIZE32 = 16, // 32-bit symbol entry size
566  SYMENTRY_SIZE64 = 24  // 64-bit symbol entry size.
567};
568
569// Symbol bindings.
570enum {
571  STB_LOCAL = 0,   // Local symbol, not visible outside obj file containing def
572  STB_GLOBAL = 1,  // Global symbol, visible to all object files being combined
573  STB_WEAK = 2,    // Weak symbol, like global but lower-precedence
574  STB_LOPROC = 13, // Lowest processor-specific binding type
575  STB_HIPROC = 15  // Highest processor-specific binding type
576};
577
578// Symbol types.
579enum {
580  STT_NOTYPE  = 0,   // Symbol's type is not specified
581  STT_OBJECT  = 1,   // Symbol is a data object (variable, array, etc.)
582  STT_FUNC    = 2,   // Symbol is executable code (function, etc.)
583  STT_SECTION = 3,   // Symbol refers to a section
584  STT_FILE    = 4,   // Local, absolute symbol that refers to a file
585  STT_COMMON  = 5,   // An uninitialised common block
586  STT_TLS     = 6,   // Thread local data object
587  STT_LOPROC  = 13,  // Lowest processor-specific symbol type
588  STT_HIPROC  = 15   // Highest processor-specific symbol type
589};
590
591enum {
592  STV_DEFAULT   = 0,  // Visibility is specified by binding type
593  STV_INTERNAL  = 1,  // Defined by processor supplements
594  STV_HIDDEN    = 2,  // Not visible to other components
595  STV_PROTECTED = 3   // Visible in other components but not preemptable
596};
597
598// Relocation entry, without explicit addend.
599struct Elf32_Rel {
600  Elf32_Addr r_offset; // Location (file byte offset, or program virtual addr)
601  Elf32_Word r_info;   // Symbol table index and type of relocation to apply
602
603  // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
604  // and ELF32_R_INFO macros defined in the ELF specification:
605  Elf32_Word getSymbol() const { return (r_info >> 8); }
606  unsigned char getType() const { return (unsigned char) (r_info & 0x0ff); }
607  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
608  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
609  void setSymbolAndType(Elf32_Word s, unsigned char t) {
610    r_info = (s << 8) + t;
611  }
612};
613
614// Relocation entry with explicit addend.
615struct Elf32_Rela {
616  Elf32_Addr  r_offset; // Location (file byte offset, or program virtual addr)
617  Elf32_Word  r_info;   // Symbol table index and type of relocation to apply
618  Elf32_Sword r_addend; // Compute value for relocatable field by adding this
619
620  // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
621  // and ELF32_R_INFO macros defined in the ELF specification:
622  Elf32_Word getSymbol() const { return (r_info >> 8); }
623  unsigned char getType() const { return (unsigned char) (r_info & 0x0ff); }
624  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
625  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
626  void setSymbolAndType(Elf32_Word s, unsigned char t) {
627    r_info = (s << 8) + t;
628  }
629};
630
631// Relocation entry, without explicit addend.
632struct Elf64_Rel {
633  Elf64_Addr r_offset; // Location (file byte offset, or program virtual addr).
634  Elf64_Xword r_info;   // Symbol table index and type of relocation to apply.
635
636  // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
637  // and ELF64_R_INFO macros defined in the ELF specification:
638  Elf64_Xword getSymbol() const { return (r_info >> 32); }
639  unsigned char getType() const {
640    return (unsigned char) (r_info & 0xffffffffL);
641  }
642  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
643  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
644  void setSymbolAndType(Elf64_Xword s, unsigned char t) {
645    r_info = (s << 32) + (t&0xffffffffL);
646  }
647};
648
649// Relocation entry with explicit addend.
650struct Elf64_Rela {
651  Elf64_Addr  r_offset; // Location (file byte offset, or program virtual addr).
652  Elf64_Xword  r_info;   // Symbol table index and type of relocation to apply.
653  Elf64_Sxword r_addend; // Compute value for relocatable field by adding this.
654
655  // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
656  // and ELF64_R_INFO macros defined in the ELF specification:
657  Elf64_Xword getSymbol() const { return (r_info >> 32); }
658  unsigned char getType() const {
659    return (unsigned char) (r_info & 0xffffffffL);
660  }
661  void setSymbol(Elf64_Xword s) { setSymbolAndType(s, getType()); }
662  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
663  void setSymbolAndType(Elf64_Xword s, unsigned char t) {
664    r_info = (s << 32) + (t&0xffffffffL);
665  }
666};
667
668// Program header for ELF32.
669struct Elf32_Phdr {
670  Elf32_Word p_type;   // Type of segment
671  Elf32_Off  p_offset; // File offset where segment is located, in bytes
672  Elf32_Addr p_vaddr;  // Virtual address of beginning of segment
673  Elf32_Addr p_paddr;  // Physical address of beginning of segment (OS-specific)
674  Elf32_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
675  Elf32_Word p_memsz;  // Num. of bytes in mem image of segment (may be zero)
676  Elf32_Word p_flags;  // Segment flags
677  Elf32_Word p_align;  // Segment alignment constraint
678};
679
680// Program header for ELF64.
681struct Elf64_Phdr {
682  Elf64_Word   p_type;   // Type of segment
683  Elf64_Word   p_flags;  // Segment flags
684  Elf64_Off    p_offset; // File offset where segment is located, in bytes
685  Elf64_Addr   p_vaddr;  // Virtual address of beginning of segment
686  Elf64_Addr   p_paddr;  // Physical address of beginning of segment (OS-specific)
687  Elf64_Xword  p_filesz; // Num. of bytes in file image of segment (may be zero)
688  Elf64_Xword  p_memsz;  // Num. of bytes in mem image of segment (may be zero)
689  Elf64_Xword  p_align;  // Segment alignment constraint
690};
691
692// Segment types.
693enum {
694  PT_NULL    = 0, // Unused segment.
695  PT_LOAD    = 1, // Loadable segment.
696  PT_DYNAMIC = 2, // Dynamic linking information.
697  PT_INTERP  = 3, // Interpreter pathname.
698  PT_NOTE    = 4, // Auxiliary information.
699  PT_SHLIB   = 5, // Reserved.
700  PT_PHDR    = 6, // The program header table itself.
701  PT_LOPROC  = 0x70000000, // Lowest processor-specific program hdr entry type.
702  PT_HIPROC  = 0x7fffffff  // Highest processor-specific program hdr entry type.
703};
704
705// Segment flag bits.
706enum {
707  PF_X        = 1,         // Execute
708  PF_W        = 2,         // Write
709  PF_R        = 4,         // Read
710  PF_MASKPROC = 0xf0000000 // Unspecified
711};
712
713// Dynamic table entry for ELF32.
714struct Elf32_Dyn
715{
716  Elf32_Sword d_tag;            // Type of dynamic table entry.
717  union
718  {
719      Elf32_Word d_val;         // Integer value of entry.
720      Elf32_Addr d_ptr;         // Pointer value of entry.
721  } d_un;
722};
723
724// Dynamic table entry for ELF64.
725struct Elf64_Dyn
726{
727  Elf64_Sxword d_tag;           // Type of dynamic table entry.
728  union
729  {
730      Elf64_Xword d_val;        // Integer value of entry.
731      Elf64_Addr  d_ptr;        // Pointer value of entry.
732  } d_un;
733};
734
735// Dynamic table entry tags.
736enum {
737  DT_NULL         = 0,        // Marks end of dynamic array.
738  DT_NEEDED       = 1,        // String table offset of needed library.
739  DT_PLTRELSZ     = 2,        // Size of relocation entries in PLT.
740  DT_PLTGOT       = 3,        // Address associated with linkage table.
741  DT_HASH         = 4,        // Address of symbolic hash table.
742  DT_STRTAB       = 5,        // Address of dynamic string table.
743  DT_SYMTAB       = 6,        // Address of dynamic symbol table.
744  DT_RELA         = 7,        // Address of relocation table (Rela entries).
745  DT_RELASZ       = 8,        // Size of Rela relocation table.
746  DT_RELAENT      = 9,        // Size of a Rela relocation entry.
747  DT_STRSZ        = 10,       // Total size of the string table.
748  DT_SYMENT       = 11,       // Size of a symbol table entry.
749  DT_INIT         = 12,       // Address of initialization function.
750  DT_FINI         = 13,       // Address of termination function.
751  DT_SONAME       = 14,       // String table offset of a shared objects name.
752  DT_RPATH        = 15,       // String table offset of library search path.
753  DT_SYMBOLIC     = 16,       // Changes symbol resolution algorithm.
754  DT_REL          = 17,       // Address of relocation table (Rel entries).
755  DT_RELSZ        = 18,       // Size of Rel relocation table.
756  DT_RELENT       = 19,       // Size of a Rel relocation entry.
757  DT_PLTREL       = 20,       // Type of relocation entry used for linking.
758  DT_DEBUG        = 21,       // Reserved for debugger.
759  DT_TEXTREL      = 22,       // Relocations exist for non-writable segements.
760  DT_JMPREL       = 23,       // Address of relocations associated with PLT.
761  DT_BIND_NOW     = 24,       // Process all relocations before execution.
762  DT_INIT_ARRAY   = 25,       // Pointer to array of initialization functions.
763  DT_FINI_ARRAY   = 26,       // Pointer to array of termination functions.
764  DT_INIT_ARRAYSZ = 27,       // Size of DT_INIT_ARRAY.
765  DT_FINI_ARRAYSZ = 28,       // Size of DT_FINI_ARRAY.
766  DT_LOOS         = 0x60000000, // Start of environment specific tags.
767  DT_HIOS         = 0x6FFFFFFF, // End of environment specific tags.
768  DT_LOPROC       = 0x70000000, // Start of processor specific tags.
769  DT_HIPROC       = 0x7FFFFFFF  // End of processor specific tags.
770};
771
772} // end namespace ELF
773
774} // end namespace llvm
775
776#endif
777