elf.h 11 KB

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