elf.h 10.0 KB

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