elf.h 12 KB

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