elf.h 11 KB

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