elf.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /****************************************************************************
  2. * include/elf.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_ELF_H
  21. #define __INCLUDE_ELF_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <stdint.h>
  26. #define EI_NIDENT 16 /* Size of e_ident[] */
  27. /* NOTE: elf64.h and elf32.h refer EI_NIDENT defined above */
  28. #include "elf64.h"
  29. #include "elf32.h"
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /* Values for Elf_Ehdr::e_type */
  34. #define ET_NONE 0 /* No file type */
  35. #define ET_REL 1 /* Relocatable file */
  36. #define ET_EXEC 2 /* Executable file */
  37. #define ET_DYN 3 /* Shared object file */
  38. #define ET_CORE 4 /* Core file */
  39. #define ET_LOPROC 0xff00 /* Processor-specific */
  40. #define ET_HIPROC 0xffff /* Processor-specific */
  41. /* Values for Elf_Ehdr::e_machine (most of this were not included in the
  42. * original SCO document but have been gleaned from elsewhere).
  43. */
  44. #define EM_NONE 0 /* No machine */
  45. #define EM_M32 1 /* AT&T WE 32100 */
  46. #define EM_SPARC 2 /* SPARC */
  47. #define EM_386 3 /* Intel 80386 */
  48. #define EM_68K 4 /* Motorola 68000 */
  49. #define EM_88K 5 /* Motorola 88000 */
  50. #define EM_486 6 /* Intel 486+ */
  51. #define EM_860 7 /* Intel 80860 */
  52. #define EM_MIPS 8 /* MIPS R3000 Big-Endian */
  53. #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
  54. #define EM_PARISC 15 /* HPPA */
  55. #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
  56. #define EM_PPC 20 /* PowerPC */
  57. #define EM_PPC64 21 /* PowerPC64 */
  58. #define EM_ARM 40 /* ARM */
  59. #define EM_SH 42 /* SuperH */
  60. #define EM_SPARCV9 43 /* SPARC v9 64-bit */
  61. #define EM_H8_300 46
  62. #define EM_IA_64 50 /* HP/Intel IA-64 */
  63. #define EM_X86_64 62 /* AMD x86-64 */
  64. #define EM_S390 22 /* IBM S/390 */
  65. #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
  66. #define EM_V850 87 /* NEC v850 */
  67. #define EM_M32R 88 /* Renesas M32R */
  68. #define EM_XTENSA 94 /* Tensilica Xtensa */
  69. #define EM_RISCV 243 /* RISC-V */
  70. #define EM_ALPHA 0x9026
  71. #define EM_CYGNUS_V850 0x9080
  72. #define EM_CYGNUS_M32R 0x9041
  73. #define EM_S390_OLD 0xa390
  74. #define EM_FRV 0x5441
  75. /* Values for Elf_Ehdr::e_version */
  76. #define EV_NONE 0 /* Invalid version */
  77. #define EV_CURRENT 1 /* The current version */
  78. /* Table 2. Ehe ELF identifier */
  79. #define EI_MAG0 0 /* File identification */
  80. #define EI_MAG1 1
  81. #define EI_MAG2 2
  82. #define EI_MAG3 3
  83. #define EI_CLASS 4 /* File class */
  84. #define EI_DATA 5 /* Data encoding */
  85. #define EI_VERSION 6 /* File version */
  86. #define EI_OSABI 7 /* OS ABI */
  87. #define EI_PAD 8 /* Start of padding bytes */
  88. /* EI_NIDENT is defined in "Included Files" section */
  89. #define EI_MAGIC_SIZE 4
  90. #define EI_MAGIC \
  91. { \
  92. 0x7f, 'E', 'L', 'F' \
  93. }
  94. #define ELFMAG0 0x7f /* EI_MAG */
  95. #define ELFMAG1 'E'
  96. #define ELFMAG2 'L'
  97. #define ELFMAG3 'F'
  98. #define ELFMAG "\177ELF"
  99. /* Table 3. Values for EI_CLASS */
  100. #define ELFCLASSNONE 0 /* Invalid class */
  101. #define ELFCLASS32 1 /* 32-bit objects */
  102. #define ELFCLASS64 2 /* 64-bit objects */
  103. /* Table 4. Values for EI_DATA */
  104. #define ELFDATANONE 0 /* Invalid data encoding */
  105. #define ELFDATA2LSB \
  106. 1 /* Least significant byte occupying the lowest address \
  107. */
  108. #define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */
  109. /* Table 6. Values for EI_OSABI */
  110. #define ELFOSABI_NONE 0 /* UNIX System V ABI */
  111. #define ELFOSABI_SYSV 0 /* Alias. */
  112. #define ELFOSABI_HPUX 1 /* HP-UX */
  113. #define ELFOSABI_NETBSD 2 /* NetBSD. */
  114. #define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */
  115. #define ELFOSABI_LINUX ELFOSABI_GNU
  116. /* Compatibility alias. */
  117. #define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
  118. #define ELFOSABI_AIX 7 /* IBM AIX. */
  119. #define ELFOSABI_IRIX 8 /* SGI Irix. */
  120. #define ELFOSABI_FREEBSD 9 /* FreeBSD. */
  121. #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
  122. #define ELFOSABI_MODESTO 11 /* Novell Modesto. */
  123. #define ELFOSABI_OPENBSD 12 /* OpenBSD. */
  124. #define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
  125. #define ELFOSABI_ARM 97 /* ARM */
  126. #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
  127. #ifndef ELF_OSABI
  128. #define ELF_OSABI ELFOSABI_NONE
  129. #endif
  130. /* Table 7: Special Section Indexes */
  131. #define SHN_UNDEF 0
  132. #define SHN_LOPROC 0xff00
  133. #define SHN_HIPROC 0xff1f
  134. #define SHN_ABS 0xfff1
  135. #define SHN_COMMON 0xfff2
  136. /* Figure 4-9: Section Types, sh_type */
  137. #define SHT_NULL 0
  138. #define SHT_PROGBITS 1
  139. #define SHT_SYMTAB 2
  140. #define SHT_STRTAB 3
  141. #define SHT_RELA 4
  142. #define SHT_HASH 5
  143. #define SHT_DYNAMIC 6
  144. #define SHT_NOTE 7
  145. #define SHT_NOBITS 8
  146. #define SHT_REL 9
  147. #define SHT_SHLIB 10
  148. #define SHT_DYNSYM 11
  149. #define SHT_LOPROC 0x70000000
  150. #define SHT_HIPROC 0x7fffffff
  151. #define SHT_LOUSER 0x80000000
  152. #define SHT_HIUSER 0xffffffff
  153. /* Figure 4-11: Section Attribute Flags, sh_flags */
  154. #define SHF_WRITE 1
  155. #define SHF_ALLOC 2
  156. #define SHF_EXECINSTR 4
  157. #define SHF_MASKPROC 0xf0000000
  158. /* Figure 4-16: Symbol Binding, ELF_ST_BIND */
  159. #define STB_LOCAL 0
  160. #define STB_GLOBAL 1
  161. #define STB_WEAK 2
  162. #define STB_LOPROC 13
  163. #define STB_HIPROC 15
  164. /* Figure 4-17: Symbol Types, ELF_ST_TYPE */
  165. #define STT_NOTYPE 0
  166. #define STT_OBJECT 1
  167. #define STT_FUNC 2
  168. #define STT_SECTION 3
  169. #define STT_FILE 4
  170. #define STT_LOPROC 13
  171. #define STT_HIPROC 15
  172. /* Figure 5-2: Segment Types, p_type */
  173. #define PT_NULL 0
  174. #define PT_LOAD 1
  175. #define PT_DYNAMIC 2
  176. #define PT_INTERP 3
  177. #define PT_NOTE 4
  178. #define PT_SHLIB 5
  179. #define PT_PHDR 6
  180. #define PT_LOPROC 0x70000000
  181. #define PT_HIPROC 0x7fffffff
  182. /* Figure 5-3: Segment Flag Bits, p_flags */
  183. #define PF_X 1 /* Execute */
  184. #define PF_W 2 /* Write */
  185. #define PF_R 4 /* Read */
  186. #define PF_MASKPROC 0xf0000000 /* Unspecified */
  187. /* Figure 5-10: Dynamic Array Tags, d_tag */
  188. #define DT_NULL 0 /* d_un=ignored */
  189. #define DT_NEEDED 1 /* d_un=d_val */
  190. #define DT_PLTRELSZ 2 /* d_un=d_val */
  191. #define DT_PLTGOT 3 /* d_un=d_ptr */
  192. #define DT_HASH 4 /* d_un=d_ptr */
  193. #define DT_STRTAB 5 /* d_un=d_ptr */
  194. #define DT_SYMTAB 6 /* d_un=d_ptr */
  195. #define DT_RELA 7 /* d_un=d_ptr */
  196. #define DT_RELASZ 8 /* d_un=d_val */
  197. #define DT_RELAENT 9 /* d_un=d_val */
  198. #define DT_STRSZ 10 /* d_un=d_val */
  199. #define DT_SYMENT 11 /* d_un=d_val */
  200. #define DT_INIT 12 /* d_un=d_ptr */
  201. #define DT_FINI 13 /* d_un=d_ptr */
  202. #define DT_SONAME 14 /* d_un=d_val */
  203. #define DT_RPATH 15 /* d_un=d_val */
  204. #define DT_SYMBOLIC 16 /* d_un=ignored */
  205. #define DT_REL 17 /* d_un=d_ptr */
  206. #define DT_RELSZ 18 /* d_un=d_val */
  207. #define DT_RELENT 19 /* d_un=d_val */
  208. #define DT_PLTREL 20 /* d_un=d_val */
  209. #define DT_DEBUG 21 /* d_un=d_ptr */
  210. #define DT_TEXTREL 22 /* d_un=ignored */
  211. #define DT_JMPREL 23 /* d_un=d_ptr */
  212. #define DT_BINDNOW 24 /* d_un=ignored */
  213. #define DT_LOPROC 0x70000000 /* d_un=unspecified */
  214. #define DT_HIPROC 0x7fffffff /* d_un= unspecified */
  215. /* Legal values for note segment descriptor types for core files. */
  216. #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
  217. #define NT_PRFPREG 2 /* Contains copy of fpregset struct. */
  218. #define NT_FPREGSET 2 /* Contains copy of fpregset struct */
  219. #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
  220. #define NT_PRXREG 4 /* Contains copy of prxregset struct */
  221. #define NT_TASKSTRUCT 4 /* Contains copy of task structure */
  222. #define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */
  223. #define NT_AUXV 6 /* Contains copy of auxv array */
  224. #define NT_GWINDOWS 7 /* Contains copy of gwindows struct */
  225. #define NT_ASRS 8 /* Contains copy of asrset struct */
  226. #define NT_PSTATUS 10 /* Contains copy of pstatus struct */
  227. #define NT_PSINFO 13 /* Contains copy of psinfo struct */
  228. #define NT_PRCRED 14 /* Contains copy of prcred struct */
  229. #define NT_UTSNAME 15 /* Contains copy of utsname struct */
  230. #define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */
  231. #define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */
  232. #define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */
  233. #define NT_SIGINFO 0x53494749
  234. /* Contains copy of siginfo_t,
  235. * size might increase
  236. */
  237. #define NT_FILE 0x46494c45
  238. /* Contains information about mapped
  239. * files
  240. */
  241. #define NT_PRXFPREG 0x46e62b7f
  242. /* Contains copy of user_fxsr_struct */
  243. #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
  244. #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
  245. #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
  246. #define NT_PPC_TAR 0x103 /* Target Address Register */
  247. #define NT_PPC_PPR 0x104 /* Program Priority Register */
  248. #define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
  249. #define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
  250. #define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
  251. #define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
  252. #define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
  253. #define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
  254. #define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
  255. #define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
  256. #define NT_PPC_TM_CTAR \
  257. 0x10d /* TM checkpointed Target Address \
  258. * Register \
  259. */
  260. #define NT_PPC_TM_CPPR \
  261. 0x10e /* TM checkpointed Program Priority \
  262. * Register \
  263. */
  264. #define NT_PPC_TM_CDSCR \
  265. 0x10f /* TM checkpointed Data Stream Control \
  266. * Register \
  267. */
  268. #define NT_PPC_PKEY \
  269. 0x110 /* Memory Protection Keys \
  270. * registers. \
  271. */
  272. #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
  273. #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
  274. #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
  275. #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
  276. #define NT_S390_TIMER 0x301 /* s390 timer register */
  277. #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
  278. #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
  279. #define NT_S390_CTRS 0x304 /* s390 control registers */
  280. #define NT_S390_PREFIX 0x305 /* s390 prefix register */
  281. #define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
  282. #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
  283. #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
  284. #define NT_S390_VXRS_LOW \
  285. 0x309 /* s390 vector registers 0-15 \
  286. * upper half. \
  287. */
  288. #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31. */
  289. #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers. */
  290. #define NT_S390_GS_BC \
  291. 0x30c /* s390 guarded storage \
  292. * broadcast control block. \
  293. */
  294. #define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */
  295. #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
  296. #define NT_ARM_TLS 0x401 /* ARM TLS register */
  297. #define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
  298. #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
  299. #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
  300. #define NT_ARM_SVE \
  301. 0x405 /* ARM Scalable Vector Extension \
  302. * registers \
  303. */
  304. #define NT_ARM_PAC_MASK \
  305. 0x406 /* ARM pointer authentication \
  306. * code masks. \
  307. */
  308. #define NT_ARM_PACA_KEYS \
  309. 0x407 /* ARM pointer authentication \
  310. * address keys. \
  311. */
  312. #define NT_ARM_PACG_KEYS \
  313. 0x408 /* ARM pointer authentication \
  314. * generic key. \
  315. */
  316. #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
  317. #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers. */
  318. #define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode. */
  319. #define NT_MIPS_MSA 0x802 /* MIPS SIMD registers. */
  320. /* Legal values for the note segment descriptor types for object files. */
  321. #define NT_VERSION 1 /* Contains a version string. */
  322. #endif /* __INCLUDE_ELF_H */