elf.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_ELF_H
  3. #define _UAPI_LINUX_ELF_H
  4. #include <linux/types.h>
  5. #include <linux/elf-em.h>
  6. /* 32-bit ELF base types. */
  7. typedef __u32 Elf32_Addr;
  8. typedef __u16 Elf32_Half;
  9. typedef __u32 Elf32_Off;
  10. typedef __s32 Elf32_Sword;
  11. typedef __u32 Elf32_Word;
  12. /* 64-bit ELF base types. */
  13. typedef __u64 Elf64_Addr;
  14. typedef __u16 Elf64_Half;
  15. typedef __s16 Elf64_SHalf;
  16. typedef __u64 Elf64_Off;
  17. typedef __s32 Elf64_Sword;
  18. typedef __u32 Elf64_Word;
  19. typedef __u64 Elf64_Xword;
  20. typedef __s64 Elf64_Sxword;
  21. /* These constants are for the segment types stored in the image headers */
  22. #define PT_NULL 0
  23. #define PT_LOAD 1
  24. #define PT_DYNAMIC 2
  25. #define PT_INTERP 3
  26. #define PT_NOTE 4
  27. #define PT_SHLIB 5
  28. #define PT_PHDR 6
  29. #define PT_TLS 7 /* Thread local storage segment */
  30. #define PT_LOOS 0x60000000 /* OS-specific */
  31. #define PT_HIOS 0x6fffffff /* OS-specific */
  32. #define PT_LOPROC 0x70000000
  33. #define PT_HIPROC 0x7fffffff
  34. #define PT_GNU_EH_FRAME 0x6474e550
  35. #define PT_GNU_STACK (PT_LOOS + 0x474e551)
  36. /*
  37. * Extended Numbering
  38. *
  39. * If the real number of program header table entries is larger than
  40. * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
  41. * section header at index 0, and PN_XNUM is set to e_phnum
  42. * field. Otherwise, the section header at index 0 is zero
  43. * initialized, if it exists.
  44. *
  45. * Specifications are available in:
  46. *
  47. * - Oracle: Linker and Libraries.
  48. * Part No: 817–1984–19, August 2011.
  49. * http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
  50. *
  51. * - System V ABI AMD64 Architecture Processor Supplement
  52. * Draft Version 0.99.4,
  53. * January 13, 2010.
  54. * http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf
  55. */
  56. #define PN_XNUM 0xffff
  57. /* These constants define the different elf file types */
  58. #define ET_NONE 0
  59. #define ET_REL 1
  60. #define ET_EXEC 2
  61. #define ET_DYN 3
  62. #define ET_CORE 4
  63. #define ET_LOPROC 0xff00
  64. #define ET_HIPROC 0xffff
  65. /* This is the info that is needed to parse the dynamic section of the file */
  66. #define DT_NULL 0
  67. #define DT_NEEDED 1
  68. #define DT_PLTRELSZ 2
  69. #define DT_PLTGOT 3
  70. #define DT_HASH 4
  71. #define DT_STRTAB 5
  72. #define DT_SYMTAB 6
  73. #define DT_RELA 7
  74. #define DT_RELASZ 8
  75. #define DT_RELAENT 9
  76. #define DT_STRSZ 10
  77. #define DT_SYMENT 11
  78. #define DT_INIT 12
  79. #define DT_FINI 13
  80. #define DT_SONAME 14
  81. #define DT_RPATH 15
  82. #define DT_SYMBOLIC 16
  83. #define DT_REL 17
  84. #define DT_RELSZ 18
  85. #define DT_RELENT 19
  86. #define DT_PLTREL 20
  87. #define DT_DEBUG 21
  88. #define DT_TEXTREL 22
  89. #define DT_JMPREL 23
  90. #define DT_ENCODING 32
  91. #define OLD_DT_LOOS 0x60000000
  92. #define DT_LOOS 0x6000000d
  93. #define DT_HIOS 0x6ffff000
  94. #define DT_VALRNGLO 0x6ffffd00
  95. #define DT_VALRNGHI 0x6ffffdff
  96. #define DT_ADDRRNGLO 0x6ffffe00
  97. #define DT_ADDRRNGHI 0x6ffffeff
  98. #define DT_VERSYM 0x6ffffff0
  99. #define DT_RELACOUNT 0x6ffffff9
  100. #define DT_RELCOUNT 0x6ffffffa
  101. #define DT_FLAGS_1 0x6ffffffb
  102. #define DT_VERDEF 0x6ffffffc
  103. #define DT_VERDEFNUM 0x6ffffffd
  104. #define DT_VERNEED 0x6ffffffe
  105. #define DT_VERNEEDNUM 0x6fffffff
  106. #define OLD_DT_HIOS 0x6fffffff
  107. #define DT_LOPROC 0x70000000
  108. #define DT_HIPROC 0x7fffffff
  109. /* This info is needed when parsing the symbol table */
  110. #define STB_LOCAL 0
  111. #define STB_GLOBAL 1
  112. #define STB_WEAK 2
  113. #define STT_NOTYPE 0
  114. #define STT_OBJECT 1
  115. #define STT_FUNC 2
  116. #define STT_SECTION 3
  117. #define STT_FILE 4
  118. #define STT_COMMON 5
  119. #define STT_TLS 6
  120. #define ELF_ST_BIND(x) ((x) >> 4)
  121. #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
  122. #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
  123. #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
  124. #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
  125. #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
  126. typedef struct dynamic{
  127. Elf32_Sword d_tag;
  128. union{
  129. Elf32_Sword d_val;
  130. Elf32_Addr d_ptr;
  131. } d_un;
  132. } Elf32_Dyn;
  133. typedef struct {
  134. Elf64_Sxword d_tag; /* entry tag value */
  135. union {
  136. Elf64_Xword d_val;
  137. Elf64_Addr d_ptr;
  138. } d_un;
  139. } Elf64_Dyn;
  140. /* The following are used with relocations */
  141. #define ELF32_R_SYM(x) ((x) >> 8)
  142. #define ELF32_R_TYPE(x) ((x) & 0xff)
  143. #define ELF64_R_SYM(i) ((i) >> 32)
  144. #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
  145. typedef struct elf32_rel {
  146. Elf32_Addr r_offset;
  147. Elf32_Word r_info;
  148. } Elf32_Rel;
  149. typedef struct elf64_rel {
  150. Elf64_Addr r_offset; /* Location at which to apply the action */
  151. Elf64_Xword r_info; /* index and type of relocation */
  152. } Elf64_Rel;
  153. typedef struct elf32_rela{
  154. Elf32_Addr r_offset;
  155. Elf32_Word r_info;
  156. Elf32_Sword r_addend;
  157. } Elf32_Rela;
  158. typedef struct elf64_rela {
  159. Elf64_Addr r_offset; /* Location at which to apply the action */
  160. Elf64_Xword r_info; /* index and type of relocation */
  161. Elf64_Sxword r_addend; /* Constant addend used to compute value */
  162. } Elf64_Rela;
  163. typedef struct elf32_sym{
  164. Elf32_Word st_name;
  165. Elf32_Addr st_value;
  166. Elf32_Word st_size;
  167. unsigned char st_info;
  168. unsigned char st_other;
  169. Elf32_Half st_shndx;
  170. } Elf32_Sym;
  171. typedef struct elf64_sym {
  172. Elf64_Word st_name; /* Symbol name, index in string tbl */
  173. unsigned char st_info; /* Type and binding attributes */
  174. unsigned char st_other; /* No defined meaning, 0 */
  175. Elf64_Half st_shndx; /* Associated section index */
  176. Elf64_Addr st_value; /* Value of the symbol */
  177. Elf64_Xword st_size; /* Associated symbol size */
  178. } Elf64_Sym;
  179. #define EI_NIDENT 16
  180. typedef struct elf32_hdr{
  181. unsigned char e_ident[EI_NIDENT];
  182. Elf32_Half e_type;
  183. Elf32_Half e_machine;
  184. Elf32_Word e_version;
  185. Elf32_Addr e_entry; /* Entry point */
  186. Elf32_Off e_phoff;
  187. Elf32_Off e_shoff;
  188. Elf32_Word e_flags;
  189. Elf32_Half e_ehsize;
  190. Elf32_Half e_phentsize;
  191. Elf32_Half e_phnum;
  192. Elf32_Half e_shentsize;
  193. Elf32_Half e_shnum;
  194. Elf32_Half e_shstrndx;
  195. } Elf32_Ehdr;
  196. typedef struct elf64_hdr {
  197. unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
  198. Elf64_Half e_type;
  199. Elf64_Half e_machine;
  200. Elf64_Word e_version;
  201. Elf64_Addr e_entry; /* Entry point virtual address */
  202. Elf64_Off e_phoff; /* Program header table file offset */
  203. Elf64_Off e_shoff; /* Section header table file offset */
  204. Elf64_Word e_flags;
  205. Elf64_Half e_ehsize;
  206. Elf64_Half e_phentsize;
  207. Elf64_Half e_phnum;
  208. Elf64_Half e_shentsize;
  209. Elf64_Half e_shnum;
  210. Elf64_Half e_shstrndx;
  211. } Elf64_Ehdr;
  212. /* These constants define the permissions on sections in the program
  213. header, p_flags. */
  214. #define PF_R 0x4
  215. #define PF_W 0x2
  216. #define PF_X 0x1
  217. typedef struct elf32_phdr{
  218. Elf32_Word p_type;
  219. Elf32_Off p_offset;
  220. Elf32_Addr p_vaddr;
  221. Elf32_Addr p_paddr;
  222. Elf32_Word p_filesz;
  223. Elf32_Word p_memsz;
  224. Elf32_Word p_flags;
  225. Elf32_Word p_align;
  226. } Elf32_Phdr;
  227. typedef struct elf64_phdr {
  228. Elf64_Word p_type;
  229. Elf64_Word p_flags;
  230. Elf64_Off p_offset; /* Segment file offset */
  231. Elf64_Addr p_vaddr; /* Segment virtual address */
  232. Elf64_Addr p_paddr; /* Segment physical address */
  233. Elf64_Xword p_filesz; /* Segment size in file */
  234. Elf64_Xword p_memsz; /* Segment size in memory */
  235. Elf64_Xword p_align; /* Segment alignment, file & memory */
  236. } Elf64_Phdr;
  237. /* sh_type */
  238. #define SHT_NULL 0
  239. #define SHT_PROGBITS 1
  240. #define SHT_SYMTAB 2
  241. #define SHT_STRTAB 3
  242. #define SHT_RELA 4
  243. #define SHT_HASH 5
  244. #define SHT_DYNAMIC 6
  245. #define SHT_NOTE 7
  246. #define SHT_NOBITS 8
  247. #define SHT_REL 9
  248. #define SHT_SHLIB 10
  249. #define SHT_DYNSYM 11
  250. #define SHT_NUM 12
  251. #define SHT_LOPROC 0x70000000
  252. #define SHT_HIPROC 0x7fffffff
  253. #define SHT_LOUSER 0x80000000
  254. #define SHT_HIUSER 0xffffffff
  255. /* sh_flags */
  256. #define SHF_WRITE 0x1
  257. #define SHF_ALLOC 0x2
  258. #define SHF_EXECINSTR 0x4
  259. #define SHF_RELA_LIVEPATCH 0x00100000
  260. #define SHF_RO_AFTER_INIT 0x00200000
  261. #define SHF_MASKPROC 0xf0000000
  262. /* special section indexes */
  263. #define SHN_UNDEF 0
  264. #define SHN_LORESERVE 0xff00
  265. #define SHN_LOPROC 0xff00
  266. #define SHN_HIPROC 0xff1f
  267. #define SHN_LIVEPATCH 0xff20
  268. #define SHN_ABS 0xfff1
  269. #define SHN_COMMON 0xfff2
  270. #define SHN_HIRESERVE 0xffff
  271. typedef struct elf32_shdr {
  272. Elf32_Word sh_name;
  273. Elf32_Word sh_type;
  274. Elf32_Word sh_flags;
  275. Elf32_Addr sh_addr;
  276. Elf32_Off sh_offset;
  277. Elf32_Word sh_size;
  278. Elf32_Word sh_link;
  279. Elf32_Word sh_info;
  280. Elf32_Word sh_addralign;
  281. Elf32_Word sh_entsize;
  282. } Elf32_Shdr;
  283. typedef struct elf64_shdr {
  284. Elf64_Word sh_name; /* Section name, index in string tbl */
  285. Elf64_Word sh_type; /* Type of section */
  286. Elf64_Xword sh_flags; /* Miscellaneous section attributes */
  287. Elf64_Addr sh_addr; /* Section virtual addr at execution */
  288. Elf64_Off sh_offset; /* Section file offset */
  289. Elf64_Xword sh_size; /* Size of section in bytes */
  290. Elf64_Word sh_link; /* Index of another section */
  291. Elf64_Word sh_info; /* Additional section information */
  292. Elf64_Xword sh_addralign; /* Section alignment */
  293. Elf64_Xword sh_entsize; /* Entry size if section holds table */
  294. } Elf64_Shdr;
  295. #define EI_MAG0 0 /* e_ident[] indexes */
  296. #define EI_MAG1 1
  297. #define EI_MAG2 2
  298. #define EI_MAG3 3
  299. #define EI_CLASS 4
  300. #define EI_DATA 5
  301. #define EI_VERSION 6
  302. #define EI_OSABI 7
  303. #define EI_PAD 8
  304. #define ELFMAG0 0x7f /* EI_MAG */
  305. #define ELFMAG1 'E'
  306. #define ELFMAG2 'L'
  307. #define ELFMAG3 'F'
  308. #define ELFMAG "\177ELF"
  309. #define SELFMAG 4
  310. #define ELFCLASSNONE 0 /* EI_CLASS */
  311. #define ELFCLASS32 1
  312. #define ELFCLASS64 2
  313. #define ELFCLASSNUM 3
  314. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  315. #define ELFDATA2LSB 1
  316. #define ELFDATA2MSB 2
  317. #define EV_NONE 0 /* e_version, EI_VERSION */
  318. #define EV_CURRENT 1
  319. #define EV_NUM 2
  320. #define ELFOSABI_NONE 0
  321. #define ELFOSABI_LINUX 3
  322. #ifndef ELF_OSABI
  323. #define ELF_OSABI ELFOSABI_NONE
  324. #endif
  325. /*
  326. * Notes used in ET_CORE. Architectures export some of the arch register sets
  327. * using the corresponding note types via the PTRACE_GETREGSET and
  328. * PTRACE_SETREGSET requests.
  329. */
  330. #define NT_PRSTATUS 1
  331. #define NT_PRFPREG 2
  332. #define NT_PRPSINFO 3
  333. #define NT_TASKSTRUCT 4
  334. #define NT_AUXV 6
  335. /*
  336. * Note to userspace developers: size of NT_SIGINFO note may increase
  337. * in the future to accomodate more fields, don't assume it is fixed!
  338. */
  339. #define NT_SIGINFO 0x53494749
  340. #define NT_FILE 0x46494c45
  341. #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
  342. #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
  343. #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
  344. #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
  345. #define NT_PPC_TAR 0x103 /* Target Address Register */
  346. #define NT_PPC_PPR 0x104 /* Program Priority Register */
  347. #define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
  348. #define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
  349. #define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
  350. #define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
  351. #define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
  352. #define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
  353. #define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
  354. #define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
  355. #define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address Register */
  356. #define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority Register */
  357. #define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control Register */
  358. #define NT_PPC_PKEY 0x110 /* Memory Protection Keys registers */
  359. #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
  360. #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
  361. #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
  362. #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
  363. #define NT_S390_TIMER 0x301 /* s390 timer register */
  364. #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
  365. #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
  366. #define NT_S390_CTRS 0x304 /* s390 control registers */
  367. #define NT_S390_PREFIX 0x305 /* s390 prefix register */
  368. #define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
  369. #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
  370. #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
  371. #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */
  372. #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
  373. #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers */
  374. #define NT_S390_GS_BC 0x30c /* s390 guarded storage broadcast control block */
  375. #define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */
  376. #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
  377. #define NT_ARM_TLS 0x401 /* ARM TLS register */
  378. #define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
  379. #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
  380. #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
  381. #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension registers */
  382. #define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */
  383. #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */
  384. #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */
  385. #define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */
  386. /* Note header in a PT_NOTE section */
  387. typedef struct elf32_note {
  388. Elf32_Word n_namesz; /* Name size */
  389. Elf32_Word n_descsz; /* Content size */
  390. Elf32_Word n_type; /* Content type */
  391. } Elf32_Nhdr;
  392. /* Note header in a PT_NOTE section */
  393. typedef struct elf64_note {
  394. Elf64_Word n_namesz; /* Name size */
  395. Elf64_Word n_descsz; /* Content size */
  396. Elf64_Word n_type; /* Content type */
  397. } Elf64_Nhdr;
  398. #endif /* _UAPI_LINUX_ELF_H */