elf.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. #ifndef _LINUX_ELF_H
  2. #define _LINUX_ELF_H
  3. #include <linux/types.h>
  4. #include <linux/auxvec.h>
  5. #include <asm/elf.h>
  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. /* These constants define the different elf file types */
  43. #define ET_NONE 0
  44. #define ET_REL 1
  45. #define ET_EXEC 2
  46. #define ET_DYN 3
  47. #define ET_CORE 4
  48. #define ET_LOPROC 0xff00
  49. #define ET_HIPROC 0xffff
  50. /* These constants define the various ELF target machines */
  51. #define EM_NONE 0
  52. #define EM_M32 1
  53. #define EM_SPARC 2
  54. #define EM_386 3
  55. #define EM_68K 4
  56. #define EM_88K 5
  57. #define EM_486 6 /* Perhaps disused */
  58. #define EM_860 7
  59. #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
  60. #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
  61. #define EM_PARISC 15 /* HPPA */
  62. #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
  63. #define EM_PPC 20 /* PowerPC */
  64. #define EM_PPC64 21 /* PowerPC64 */
  65. #define EM_SH 42 /* SuperH */
  66. #define EM_SPARCV9 43 /* SPARC v9 64-bit */
  67. #define EM_IA_64 50 /* HP/Intel IA-64 */
  68. #define EM_X86_64 62 /* AMD x86-64 */
  69. #define EM_S390 22 /* IBM S/390 */
  70. #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
  71. #define EM_V850 87 /* NEC v850 */
  72. #define EM_M32R 88 /* Renesas M32R */
  73. #define EM_H8_300 46 /* Renesas H8/300,300H,H8S */
  74. /*
  75. * This is an interim value that we will use until the committee comes
  76. * up with a final number.
  77. */
  78. #define EM_ALPHA 0x9026
  79. /* Bogus old v850 magic number, used by old tools. */
  80. #define EM_CYGNUS_V850 0x9080
  81. /* Bogus old m32r magic number, used by old tools. */
  82. #define EM_CYGNUS_M32R 0x9041
  83. /*
  84. * This is the old interim value for S/390 architecture
  85. */
  86. #define EM_S390_OLD 0xA390
  87. #define EM_FRV 0x5441 /* Fujitsu FR-V */
  88. /* This is the info that is needed to parse the dynamic section of the file */
  89. #define DT_NULL 0
  90. #define DT_NEEDED 1
  91. #define DT_PLTRELSZ 2
  92. #define DT_PLTGOT 3
  93. #define DT_HASH 4
  94. #define DT_STRTAB 5
  95. #define DT_SYMTAB 6
  96. #define DT_RELA 7
  97. #define DT_RELASZ 8
  98. #define DT_RELAENT 9
  99. #define DT_STRSZ 10
  100. #define DT_SYMENT 11
  101. #define DT_INIT 12
  102. #define DT_FINI 13
  103. #define DT_SONAME 14
  104. #define DT_RPATH 15
  105. #define DT_SYMBOLIC 16
  106. #define DT_REL 17
  107. #define DT_RELSZ 18
  108. #define DT_RELENT 19
  109. #define DT_PLTREL 20
  110. #define DT_DEBUG 21
  111. #define DT_TEXTREL 22
  112. #define DT_JMPREL 23
  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 ELF_ST_BIND(x) ((x) >> 4)
  125. #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
  126. #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
  127. #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
  128. #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
  129. #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
  130. typedef struct dynamic{
  131. Elf32_Sword d_tag;
  132. union{
  133. Elf32_Sword d_val;
  134. Elf32_Addr d_ptr;
  135. } d_un;
  136. } Elf32_Dyn;
  137. typedef struct {
  138. Elf64_Sxword d_tag; /* entry tag value */
  139. union {
  140. Elf64_Xword d_val;
  141. Elf64_Addr d_ptr;
  142. } d_un;
  143. } Elf64_Dyn;
  144. /* The following are used with relocations */
  145. #define ELF32_R_SYM(x) ((x) >> 8)
  146. #define ELF32_R_TYPE(x) ((x) & 0xff)
  147. #define ELF64_R_SYM(i) ((i) >> 32)
  148. #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
  149. typedef struct elf32_rel {
  150. Elf32_Addr r_offset;
  151. Elf32_Word r_info;
  152. } Elf32_Rel;
  153. typedef struct elf64_rel {
  154. Elf64_Addr r_offset; /* Location at which to apply the action */
  155. Elf64_Xword r_info; /* index and type of relocation */
  156. } Elf64_Rel;
  157. typedef struct elf32_rela{
  158. Elf32_Addr r_offset;
  159. Elf32_Word r_info;
  160. Elf32_Sword r_addend;
  161. } Elf32_Rela;
  162. typedef struct elf64_rela {
  163. Elf64_Addr r_offset; /* Location at which to apply the action */
  164. Elf64_Xword r_info; /* index and type of relocation */
  165. Elf64_Sxword r_addend; /* Constant addend used to compute value */
  166. } Elf64_Rela;
  167. typedef struct elf32_sym{
  168. Elf32_Word st_name;
  169. Elf32_Addr st_value;
  170. Elf32_Word st_size;
  171. unsigned char st_info;
  172. unsigned char st_other;
  173. Elf32_Half st_shndx;
  174. } Elf32_Sym;
  175. typedef struct elf64_sym {
  176. Elf64_Word st_name; /* Symbol name, index in string tbl */
  177. unsigned char st_info; /* Type and binding attributes */
  178. unsigned char st_other; /* No defined meaning, 0 */
  179. Elf64_Half st_shndx; /* Associated section index */
  180. Elf64_Addr st_value; /* Value of the symbol */
  181. Elf64_Xword st_size; /* Associated symbol size */
  182. } Elf64_Sym;
  183. #define EI_NIDENT 16
  184. typedef struct elf32_hdr{
  185. unsigned char e_ident[EI_NIDENT];
  186. Elf32_Half e_type;
  187. Elf32_Half e_machine;
  188. Elf32_Word e_version;
  189. Elf32_Addr e_entry; /* Entry point */
  190. Elf32_Off e_phoff;
  191. Elf32_Off e_shoff;
  192. Elf32_Word e_flags;
  193. Elf32_Half e_ehsize;
  194. Elf32_Half e_phentsize;
  195. Elf32_Half e_phnum;
  196. Elf32_Half e_shentsize;
  197. Elf32_Half e_shnum;
  198. Elf32_Half e_shstrndx;
  199. } Elf32_Ehdr;
  200. typedef struct elf64_hdr {
  201. unsigned char e_ident[16]; /* ELF "magic number" */
  202. Elf64_Half e_type;
  203. Elf64_Half e_machine;
  204. Elf64_Word e_version;
  205. Elf64_Addr e_entry; /* Entry point virtual address */
  206. Elf64_Off e_phoff; /* Program header table file offset */
  207. Elf64_Off e_shoff; /* Section header table file offset */
  208. Elf64_Word e_flags;
  209. Elf64_Half e_ehsize;
  210. Elf64_Half e_phentsize;
  211. Elf64_Half e_phnum;
  212. Elf64_Half e_shentsize;
  213. Elf64_Half e_shnum;
  214. Elf64_Half e_shstrndx;
  215. } Elf64_Ehdr;
  216. /* These constants define the permissions on sections in the program
  217. header, p_flags. */
  218. #define PF_R 0x4
  219. #define PF_W 0x2
  220. #define PF_X 0x1
  221. typedef struct elf32_phdr{
  222. Elf32_Word p_type;
  223. Elf32_Off p_offset;
  224. Elf32_Addr p_vaddr;
  225. Elf32_Addr p_paddr;
  226. Elf32_Word p_filesz;
  227. Elf32_Word p_memsz;
  228. Elf32_Word p_flags;
  229. Elf32_Word p_align;
  230. } Elf32_Phdr;
  231. typedef struct elf64_phdr {
  232. Elf64_Word p_type;
  233. Elf64_Word p_flags;
  234. Elf64_Off p_offset; /* Segment file offset */
  235. Elf64_Addr p_vaddr; /* Segment virtual address */
  236. Elf64_Addr p_paddr; /* Segment physical address */
  237. Elf64_Xword p_filesz; /* Segment size in file */
  238. Elf64_Xword p_memsz; /* Segment size in memory */
  239. Elf64_Xword p_align; /* Segment alignment, file & memory */
  240. } Elf64_Phdr;
  241. /* sh_type */
  242. #define SHT_NULL 0
  243. #define SHT_PROGBITS 1
  244. #define SHT_SYMTAB 2
  245. #define SHT_STRTAB 3
  246. #define SHT_RELA 4
  247. #define SHT_HASH 5
  248. #define SHT_DYNAMIC 6
  249. #define SHT_NOTE 7
  250. #define SHT_NOBITS 8
  251. #define SHT_REL 9
  252. #define SHT_SHLIB 10
  253. #define SHT_DYNSYM 11
  254. #define SHT_NUM 12
  255. #define SHT_LOPROC 0x70000000
  256. #define SHT_HIPROC 0x7fffffff
  257. #define SHT_LOUSER 0x80000000
  258. #define SHT_HIUSER 0xffffffff
  259. /* sh_flags */
  260. #define SHF_WRITE 0x1
  261. #define SHF_ALLOC 0x2
  262. #define SHF_EXECINSTR 0x4
  263. #define SHF_MASKPROC 0xf0000000
  264. /* special section indexes */
  265. #define SHN_UNDEF 0
  266. #define SHN_LORESERVE 0xff00
  267. #define SHN_LOPROC 0xff00
  268. #define SHN_HIPROC 0xff1f
  269. #define SHN_ABS 0xfff1
  270. #define SHN_COMMON 0xfff2
  271. #define SHN_HIRESERVE 0xffff
  272. typedef struct {
  273. Elf32_Word sh_name;
  274. Elf32_Word sh_type;
  275. Elf32_Word sh_flags;
  276. Elf32_Addr sh_addr;
  277. Elf32_Off sh_offset;
  278. Elf32_Word sh_size;
  279. Elf32_Word sh_link;
  280. Elf32_Word sh_info;
  281. Elf32_Word sh_addralign;
  282. Elf32_Word sh_entsize;
  283. } Elf32_Shdr;
  284. typedef struct elf64_shdr {
  285. Elf64_Word sh_name; /* Section name, index in string tbl */
  286. Elf64_Word sh_type; /* Type of section */
  287. Elf64_Xword sh_flags; /* Miscellaneous section attributes */
  288. Elf64_Addr sh_addr; /* Section virtual addr at execution */
  289. Elf64_Off sh_offset; /* Section file offset */
  290. Elf64_Xword sh_size; /* Size of section in bytes */
  291. Elf64_Word sh_link; /* Index of another section */
  292. Elf64_Word sh_info; /* Additional section information */
  293. Elf64_Xword sh_addralign; /* Section alignment */
  294. Elf64_Xword sh_entsize; /* Entry size if section holds table */
  295. } Elf64_Shdr;
  296. #define EI_MAG0 0 /* e_ident[] indexes */
  297. #define EI_MAG1 1
  298. #define EI_MAG2 2
  299. #define EI_MAG3 3
  300. #define EI_CLASS 4
  301. #define EI_DATA 5
  302. #define EI_VERSION 6
  303. #define EI_OSABI 7
  304. #define EI_PAD 8
  305. #define ELFMAG0 0x7f /* EI_MAG */
  306. #define ELFMAG1 'E'
  307. #define ELFMAG2 'L'
  308. #define ELFMAG3 'F'
  309. #define ELFMAG "\177ELF"
  310. #define SELFMAG 4
  311. #define ELFCLASSNONE 0 /* EI_CLASS */
  312. #define ELFCLASS32 1
  313. #define ELFCLASS64 2
  314. #define ELFCLASSNUM 3
  315. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  316. #define ELFDATA2LSB 1
  317. #define ELFDATA2MSB 2
  318. #define EV_NONE 0 /* e_version, EI_VERSION */
  319. #define EV_CURRENT 1
  320. #define EV_NUM 2
  321. #define ELFOSABI_NONE 0
  322. #define ELFOSABI_LINUX 3
  323. #ifndef ELF_OSABI
  324. #define ELF_OSABI ELFOSABI_NONE
  325. #endif
  326. /* Notes used in ET_CORE */
  327. #define NT_PRSTATUS 1
  328. #define NT_PRFPREG 2
  329. #define NT_PRPSINFO 3
  330. #define NT_TASKSTRUCT 4
  331. #define NT_AUXV 6
  332. #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
  333. /* Note header in a PT_NOTE section */
  334. typedef struct elf32_note {
  335. Elf32_Word n_namesz; /* Name size */
  336. Elf32_Word n_descsz; /* Content size */
  337. Elf32_Word n_type; /* Content type */
  338. } Elf32_Nhdr;
  339. /* Note header in a PT_NOTE section */
  340. typedef struct elf64_note {
  341. Elf64_Word n_namesz; /* Name size */
  342. Elf64_Word n_descsz; /* Content size */
  343. Elf64_Word n_type; /* Content type */
  344. } Elf64_Nhdr;
  345. #if ELF_CLASS == ELFCLASS32
  346. extern Elf32_Dyn _DYNAMIC [];
  347. #define elfhdr elf32_hdr
  348. #define elf_phdr elf32_phdr
  349. #define elf_note elf32_note
  350. #else
  351. extern Elf64_Dyn _DYNAMIC [];
  352. #define elfhdr elf64_hdr
  353. #define elf_phdr elf64_phdr
  354. #define elf_note elf64_note
  355. #endif
  356. #endif /* _LINUX_ELF_H */