elf.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * Copyright (c) 1995, 1996, 2001, 2002
  3. * Erik Theisen. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*
  8. * This is the ELF ABI header file
  9. * formerly known as "elf_abi.h".
  10. */
  11. #ifndef _ELF_H
  12. #define _ELF_H
  13. #ifndef __ASSEMBLER__
  14. #include "compiler.h"
  15. /*
  16. * This version doesn't work for 64-bit ABIs - Erik.
  17. */
  18. /*
  19. * These typedefs need to be handled better.
  20. */
  21. typedef uint32_t Elf32_Addr; /* Unsigned program address */
  22. typedef uint32_t Elf32_Off; /* Unsigned file offset */
  23. typedef int32_t Elf32_Sword; /* Signed large integer */
  24. typedef uint32_t Elf32_Word; /* Unsigned large integer */
  25. typedef uint16_t Elf32_Half; /* Unsigned medium integer */
  26. /* 64-bit ELF base types. */
  27. typedef uint64_t Elf64_Addr;
  28. typedef uint16_t Elf64_Half;
  29. typedef int16_t Elf64_SHalf;
  30. typedef uint64_t Elf64_Off;
  31. typedef int32_t Elf64_Sword;
  32. typedef uint32_t Elf64_Word;
  33. typedef uint64_t Elf64_Xword;
  34. typedef int64_t Elf64_Sxword;
  35. /* e_ident[] identification indexes */
  36. #define EI_MAG0 0 /* file ID */
  37. #define EI_MAG1 1 /* file ID */
  38. #define EI_MAG2 2 /* file ID */
  39. #define EI_MAG3 3 /* file ID */
  40. #define EI_CLASS 4 /* file class */
  41. #define EI_DATA 5 /* data encoding */
  42. #define EI_VERSION 6 /* ELF header version */
  43. #define EI_OSABI 7 /* OS/ABI specific ELF extensions */
  44. #define EI_ABIVERSION 8 /* ABI target version */
  45. #define EI_PAD 9 /* start of pad bytes */
  46. #define EI_NIDENT 16 /* Size of e_ident[] */
  47. /* e_ident[] magic number */
  48. #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
  49. #define ELFMAG1 'E' /* e_ident[EI_MAG1] */
  50. #define ELFMAG2 'L' /* e_ident[EI_MAG2] */
  51. #define ELFMAG3 'F' /* e_ident[EI_MAG3] */
  52. #define ELFMAG "\177ELF" /* magic */
  53. #define SELFMAG 4 /* size of magic */
  54. /* e_ident[] file class */
  55. #define ELFCLASSNONE 0 /* invalid */
  56. #define ELFCLASS32 1 /* 32-bit objs */
  57. #define ELFCLASS64 2 /* 64-bit objs */
  58. #define ELFCLASSNUM 3 /* number of classes */
  59. /* e_ident[] data encoding */
  60. #define ELFDATANONE 0 /* invalid */
  61. #define ELFDATA2LSB 1 /* Little-Endian */
  62. #define ELFDATA2MSB 2 /* Big-Endian */
  63. #define ELFDATANUM 3 /* number of data encode defines */
  64. /* e_ident[] OS/ABI specific ELF extensions */
  65. #define ELFOSABI_NONE 0 /* No extension specified */
  66. #define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
  67. #define ELFOSABI_NETBSD 2 /* NetBSD */
  68. #define ELFOSABI_LINUX 3 /* Linux */
  69. #define ELFOSABI_SOLARIS 6 /* Sun Solaris */
  70. #define ELFOSABI_AIX 7 /* AIX */
  71. #define ELFOSABI_IRIX 8 /* IRIX */
  72. #define ELFOSABI_FREEBSD 9 /* FreeBSD */
  73. #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
  74. #define ELFOSABI_MODESTO 11 /* Novell Modesto */
  75. #define ELFOSABI_OPENBSD 12 /* OpenBSD */
  76. /* 64-255 Architecture-specific value range */
  77. /* e_ident[] ABI Version */
  78. #define ELFABIVERSION 0
  79. /* e_ident */
  80. #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
  81. (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
  82. (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
  83. (ehdr).e_ident[EI_MAG3] == ELFMAG3)
  84. /* ELF Header */
  85. typedef struct elfhdr{
  86. unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
  87. Elf32_Half e_type; /* object file type */
  88. Elf32_Half e_machine; /* machine */
  89. Elf32_Word e_version; /* object file version */
  90. Elf32_Addr e_entry; /* virtual entry point */
  91. Elf32_Off e_phoff; /* program header table offset */
  92. Elf32_Off e_shoff; /* section header table offset */
  93. Elf32_Word e_flags; /* processor-specific flags */
  94. Elf32_Half e_ehsize; /* ELF header size */
  95. Elf32_Half e_phentsize; /* program header entry size */
  96. Elf32_Half e_phnum; /* number of program header entries */
  97. Elf32_Half e_shentsize; /* section header entry size */
  98. Elf32_Half e_shnum; /* number of section header entries */
  99. Elf32_Half e_shstrndx; /* section header table's "section
  100. header string table" entry offset */
  101. } Elf32_Ehdr;
  102. /* e_type */
  103. #define ET_NONE 0 /* No file type */
  104. #define ET_REL 1 /* relocatable file */
  105. #define ET_EXEC 2 /* executable file */
  106. #define ET_DYN 3 /* shared object file */
  107. #define ET_CORE 4 /* core file */
  108. #define ET_NUM 5 /* number of types */
  109. #define ET_LOOS 0xfe00 /* reserved range for operating */
  110. #define ET_HIOS 0xfeff /* system specific e_type */
  111. #define ET_LOPROC 0xff00 /* reserved range for processor */
  112. #define ET_HIPROC 0xffff /* specific e_type */
  113. /* e_machine */
  114. #define EM_NONE 0 /* No Machine */
  115. #define EM_M32 1 /* AT&T WE 32100 */
  116. #define EM_SPARC 2 /* SPARC */
  117. #define EM_386 3 /* Intel 80386 */
  118. #define EM_68K 4 /* Motorola 68000 */
  119. #define EM_88K 5 /* Motorola 88000 */
  120. #if 0
  121. #define EM_486 6 /* RESERVED - was Intel 80486 */
  122. #endif
  123. #define EM_860 7 /* Intel 80860 */
  124. #define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
  125. #define EM_S370 9 /* IBM System/370 Processor */
  126. #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
  127. #if 0
  128. #define EM_SPARC64 11 /* RESERVED - was SPARC v9
  129. 64-bit unoffical */
  130. #endif
  131. /* RESERVED 11-14 for future use */
  132. #define EM_PARISC 15 /* HPPA */
  133. /* RESERVED 16 for future use */
  134. #define EM_VPP500 17 /* Fujitsu VPP500 */
  135. #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
  136. #define EM_960 19 /* Intel 80960 */
  137. #define EM_PPC 20 /* PowerPC */
  138. #define EM_PPC64 21 /* 64-bit PowerPC */
  139. #define EM_S390 22 /* IBM System/390 Processor */
  140. /* RESERVED 23-35 for future use */
  141. #define EM_V800 36 /* NEC V800 */
  142. #define EM_FR20 37 /* Fujitsu FR20 */
  143. #define EM_RH32 38 /* TRW RH-32 */
  144. #define EM_RCE 39 /* Motorola RCE */
  145. #define EM_ARM 40 /* Advanced Risc Machines ARM */
  146. #define EM_ALPHA 41 /* Digital Alpha */
  147. #define EM_SH 42 /* Hitachi SH */
  148. #define EM_SPARCV9 43 /* SPARC Version 9 */
  149. #define EM_TRICORE 44 /* Siemens TriCore embedded processor */
  150. #define EM_ARC 45 /* Argonaut RISC Core */
  151. #define EM_H8_300 46 /* Hitachi H8/300 */
  152. #define EM_H8_300H 47 /* Hitachi H8/300H */
  153. #define EM_H8S 48 /* Hitachi H8S */
  154. #define EM_H8_500 49 /* Hitachi H8/500 */
  155. #define EM_IA_64 50 /* Intel Merced */
  156. #define EM_MIPS_X 51 /* Stanford MIPS-X */
  157. #define EM_COLDFIRE 52 /* Motorola Coldfire */
  158. #define EM_68HC12 53 /* Motorola M68HC12 */
  159. #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
  160. #define EM_PCP 55 /* Siemens PCP */
  161. #define EM_NCPU 56 /* Sony nCPU embeeded RISC */
  162. #define EM_NDR1 57 /* Denso NDR1 microprocessor */
  163. #define EM_STARCORE 58 /* Motorola Start*Core processor */
  164. #define EM_ME16 59 /* Toyota ME16 processor */
  165. #define EM_ST100 60 /* STMicroelectronic ST100 processor */
  166. #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
  167. #define EM_X86_64 62 /* AMD x86-64 */
  168. #define EM_PDSP 63 /* Sony DSP Processor */
  169. /* RESERVED 64,65 for future use */
  170. #define EM_FX66 66 /* Siemens FX66 microcontroller */
  171. #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
  172. #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
  173. #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
  174. #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
  175. #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
  176. #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
  177. #define EM_SVX 73 /* Silicon Graphics SVx */
  178. #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
  179. #define EM_VAX 75 /* Digital VAX */
  180. #define EM_CHRIS 76 /* Axis Communications embedded proc. */
  181. #define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
  182. #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
  183. #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
  184. #define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
  185. #define EM_HUANY 81 /* Harvard University mach-indep objs */
  186. #define EM_PRISM 82 /* SiTera Prism */
  187. #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
  188. #define EM_FR30 84 /* Fujitsu FR30 */
  189. #define EM_D10V 85 /* Mitsubishi DV10V */
  190. #define EM_D30V 86 /* Mitsubishi DV30V */
  191. #define EM_V850 87 /* NEC v850 */
  192. #define EM_M32R 88 /* Mitsubishi M32R */
  193. #define EM_MN10300 89 /* Matsushita MN10200 */
  194. #define EM_MN10200 90 /* Matsushita MN10200 */
  195. #define EM_PJ 91 /* picoJava */
  196. #define EM_NUM 92 /* number of machine types */
  197. /* Version */
  198. #define EV_NONE 0 /* Invalid */
  199. #define EV_CURRENT 1 /* Current */
  200. #define EV_NUM 2 /* number of versions */
  201. /* Section Header */
  202. typedef struct {
  203. Elf32_Word sh_name; /* name - index into section header
  204. string table section */
  205. Elf32_Word sh_type; /* type */
  206. Elf32_Word sh_flags; /* flags */
  207. Elf32_Addr sh_addr; /* address */
  208. Elf32_Off sh_offset; /* file offset */
  209. Elf32_Word sh_size; /* section size */
  210. Elf32_Word sh_link; /* section header table index link */
  211. Elf32_Word sh_info; /* extra information */
  212. Elf32_Word sh_addralign; /* address alignment */
  213. Elf32_Word sh_entsize; /* section entry size */
  214. } Elf32_Shdr;
  215. /* Special Section Indexes */
  216. #define SHN_UNDEF 0 /* undefined */
  217. #define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
  218. #define SHN_LOPROC 0xff00 /* reserved range for processor */
  219. #define SHN_HIPROC 0xff1f /* specific section indexes */
  220. #define SHN_LOOS 0xff20 /* reserved range for operating */
  221. #define SHN_HIOS 0xff3f /* specific semantics */
  222. #define SHN_ABS 0xfff1 /* absolute value */
  223. #define SHN_COMMON 0xfff2 /* common symbol */
  224. #define SHN_XINDEX 0xffff /* Index is an extra table */
  225. #define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
  226. /* sh_type */
  227. #define SHT_NULL 0 /* inactive */
  228. #define SHT_PROGBITS 1 /* program defined information */
  229. #define SHT_SYMTAB 2 /* symbol table section */
  230. #define SHT_STRTAB 3 /* string table section */
  231. #define SHT_RELA 4 /* relocation section with addends*/
  232. #define SHT_HASH 5 /* symbol hash table section */
  233. #define SHT_DYNAMIC 6 /* dynamic section */
  234. #define SHT_NOTE 7 /* note section */
  235. #define SHT_NOBITS 8 /* no space section */
  236. #define SHT_REL 9 /* relation section without addends */
  237. #define SHT_SHLIB 10 /* reserved - purpose unknown */
  238. #define SHT_DYNSYM 11 /* dynamic symbol table section */
  239. #define SHT_INIT_ARRAY 14 /* Array of constructors */
  240. #define SHT_FINI_ARRAY 15 /* Array of destructors */
  241. #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
  242. #define SHT_GROUP 17 /* Section group */
  243. #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
  244. #define SHT_NUM 19 /* number of section types */
  245. #define SHT_LOOS 0x60000000 /* Start OS-specific */
  246. #define SHT_HIOS 0x6fffffff /* End OS-specific */
  247. #define SHT_LOPROC 0x70000000 /* reserved range for processor */
  248. #define SHT_HIPROC 0x7fffffff /* specific section header types */
  249. #define SHT_LOUSER 0x80000000 /* reserved range for application */
  250. #define SHT_HIUSER 0xffffffff /* specific indexes */
  251. /* Section names */
  252. #define ELF_BSS ".bss" /* uninitialized data */
  253. #define ELF_COMMENT ".comment" /* version control information */
  254. #define ELF_DATA ".data" /* initialized data */
  255. #define ELF_DATA1 ".data1" /* initialized data */
  256. #define ELF_DEBUG ".debug" /* debug */
  257. #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
  258. #define ELF_DYNSTR ".dynstr" /* dynamic string table */
  259. #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
  260. #define ELF_FINI ".fini" /* termination code */
  261. #define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
  262. #define ELF_GOT ".got" /* global offset table */
  263. #define ELF_HASH ".hash" /* symbol hash table */
  264. #define ELF_INIT ".init" /* initialization code */
  265. #define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
  266. #define ELF_INTERP ".interp" /* Pathname of program interpreter */
  267. #define ELF_LINE ".line" /* Symbolic line numnber information */
  268. #define ELF_NOTE ".note" /* Contains note section */
  269. #define ELF_PLT ".plt" /* Procedure linkage table */
  270. #define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
  271. #define ELF_REL_DATA ".rel.data" /* relocation data */
  272. #define ELF_REL_FINI ".rel.fini" /* relocation termination code */
  273. #define ELF_REL_INIT ".rel.init" /* relocation initialization code */
  274. #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
  275. #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
  276. #define ELF_REL_TEXT ".rel.text" /* relocation code */
  277. #define ELF_RODATA ".rodata" /* read-only data */
  278. #define ELF_RODATA1 ".rodata1" /* read-only data */
  279. #define ELF_SHSTRTAB ".shstrtab" /* section header string table */
  280. #define ELF_STRTAB ".strtab" /* string table */
  281. #define ELF_SYMTAB ".symtab" /* symbol table */
  282. #define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
  283. #define ELF_TBSS ".tbss" /* thread local uninit data */
  284. #define ELF_TDATA ".tdata" /* thread local init data */
  285. #define ELF_TDATA1 ".tdata1" /* thread local init data */
  286. #define ELF_TEXT ".text" /* code */
  287. /* Section Attribute Flags - sh_flags */
  288. #define SHF_WRITE 0x1 /* Writable */
  289. #define SHF_ALLOC 0x2 /* occupies memory */
  290. #define SHF_EXECINSTR 0x4 /* executable */
  291. #define SHF_MERGE 0x10 /* Might be merged */
  292. #define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
  293. #define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
  294. #define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
  295. #define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
  296. #define SHF_GROUP 0x200 /* Member of section group */
  297. #define SHF_TLS 0x400 /* Thread local storage */
  298. #define SHF_MASKOS 0x0ff00000 /* OS specific */
  299. #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
  300. /* specific section attributes */
  301. /* Section Group Flags */
  302. #define GRP_COMDAT 0x1 /* COMDAT group */
  303. #define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
  304. #define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
  305. /* Symbol Table Entry */
  306. typedef struct elf32_sym {
  307. Elf32_Word st_name; /* name - index into string table */
  308. Elf32_Addr st_value; /* symbol value */
  309. Elf32_Word st_size; /* symbol size */
  310. unsigned char st_info; /* type and binding */
  311. unsigned char st_other; /* 0 - no defined meaning */
  312. Elf32_Half st_shndx; /* section header index */
  313. } Elf32_Sym;
  314. /* Symbol table index */
  315. #define STN_UNDEF 0 /* undefined */
  316. /* Extract symbol info - st_info */
  317. #define ELF32_ST_BIND(x) ((x) >> 4)
  318. #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
  319. #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
  320. #define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
  321. /* Symbol Binding - ELF32_ST_BIND - st_info */
  322. #define STB_LOCAL 0 /* Local symbol */
  323. #define STB_GLOBAL 1 /* Global symbol */
  324. #define STB_WEAK 2 /* like global - lower precedence */
  325. #define STB_NUM 3 /* number of symbol bindings */
  326. #define STB_LOOS 10 /* reserved range for operating */
  327. #define STB_HIOS 12 /* system specific symbol bindings */
  328. #define STB_LOPROC 13 /* reserved range for processor */
  329. #define STB_HIPROC 15 /* specific symbol bindings */
  330. /* Symbol type - ELF32_ST_TYPE - st_info */
  331. #define STT_NOTYPE 0 /* not specified */
  332. #define STT_OBJECT 1 /* data object */
  333. #define STT_FUNC 2 /* function */
  334. #define STT_SECTION 3 /* section */
  335. #define STT_FILE 4 /* file */
  336. #define STT_NUM 5 /* number of symbol types */
  337. #define STT_TLS 6 /* Thread local storage symbol */
  338. #define STT_LOOS 10 /* reserved range for operating */
  339. #define STT_HIOS 12 /* system specific symbol types */
  340. #define STT_LOPROC 13 /* reserved range for processor */
  341. #define STT_HIPROC 15 /* specific symbol types */
  342. /* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
  343. #define STV_DEFAULT 0 /* Normal visibility rules */
  344. #define STV_INTERNAL 1 /* Processor specific hidden class */
  345. #define STV_HIDDEN 2 /* Symbol unavailable in other mods */
  346. #define STV_PROTECTED 3 /* Not preemptible, not exported */
  347. /* Relocation entry with implicit addend */
  348. typedef struct
  349. {
  350. Elf32_Addr r_offset; /* offset of relocation */
  351. Elf32_Word r_info; /* symbol table index and type */
  352. } Elf32_Rel;
  353. /* Relocation entry with explicit addend */
  354. typedef struct
  355. {
  356. Elf32_Addr r_offset; /* offset of relocation */
  357. Elf32_Word r_info; /* symbol table index and type */
  358. Elf32_Sword r_addend;
  359. } Elf32_Rela;
  360. typedef struct {
  361. Elf64_Addr r_offset; /* Location at which to apply the action */
  362. Elf64_Xword r_info; /* index and type of relocation */
  363. } Elf64_Rel;
  364. typedef struct {
  365. Elf64_Addr r_offset; /* Location at which to apply the action */
  366. Elf64_Xword r_info; /* index and type of relocation */
  367. Elf64_Sxword r_addend; /* Constant addend used to compute value */
  368. } Elf64_Rela;
  369. /* Extract relocation info - r_info */
  370. #define ELF32_R_SYM(i) ((i) >> 8)
  371. #define ELF32_R_TYPE(i) ((unsigned char) (i))
  372. #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
  373. /* Program Header */
  374. typedef struct {
  375. Elf32_Word p_type; /* segment type */
  376. Elf32_Off p_offset; /* segment offset */
  377. Elf32_Addr p_vaddr; /* virtual address of segment */
  378. Elf32_Addr p_paddr; /* physical address - ignored? */
  379. Elf32_Word p_filesz; /* number of bytes in file for seg. */
  380. Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
  381. Elf32_Word p_flags; /* flags */
  382. Elf32_Word p_align; /* memory alignment */
  383. } Elf32_Phdr;
  384. /* Segment types - p_type */
  385. #define PT_NULL 0 /* unused */
  386. #define PT_LOAD 1 /* loadable segment */
  387. #define PT_DYNAMIC 2 /* dynamic linking section */
  388. #define PT_INTERP 3 /* the RTLD */
  389. #define PT_NOTE 4 /* auxiliary information */
  390. #define PT_SHLIB 5 /* reserved - purpose undefined */
  391. #define PT_PHDR 6 /* program header */
  392. #define PT_TLS 7 /* Thread local storage template */
  393. #define PT_NUM 8 /* Number of segment types */
  394. #define PT_LOOS 0x60000000 /* reserved range for operating */
  395. #define PT_HIOS 0x6fffffff /* system specific segment types */
  396. #define PT_LOPROC 0x70000000 /* reserved range for processor */
  397. #define PT_HIPROC 0x7fffffff /* specific segment types */
  398. /* Segment flags - p_flags */
  399. #define PF_X 0x1 /* Executable */
  400. #define PF_W 0x2 /* Writable */
  401. #define PF_R 0x4 /* Readable */
  402. #define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
  403. #define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
  404. /* specific segment flags */
  405. /* Dynamic structure */
  406. typedef struct
  407. {
  408. Elf32_Sword d_tag; /* controls meaning of d_val */
  409. union
  410. {
  411. Elf32_Word d_val; /* Multiple meanings - see d_tag */
  412. Elf32_Addr d_ptr; /* program virtual address */
  413. } d_un;
  414. } Elf32_Dyn;
  415. extern Elf32_Dyn _DYNAMIC[];
  416. typedef struct {
  417. Elf64_Sxword d_tag; /* entry tag value */
  418. union {
  419. Elf64_Xword d_val;
  420. Elf64_Addr d_ptr;
  421. } d_un;
  422. } Elf64_Dyn;
  423. #define ELF64_R_SYM(i) ((i) >> 32)
  424. #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
  425. /* Dynamic Array Tags - d_tag */
  426. #define DT_NULL 0 /* marks end of _DYNAMIC array */
  427. #define DT_NEEDED 1 /* string table offset of needed lib */
  428. #define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
  429. #define DT_PLTGOT 3 /* address PLT/GOT */
  430. #define DT_HASH 4 /* address of symbol hash table */
  431. #define DT_STRTAB 5 /* address of string table */
  432. #define DT_SYMTAB 6 /* address of symbol table */
  433. #define DT_RELA 7 /* address of relocation table */
  434. #define DT_RELASZ 8 /* size of relocation table */
  435. #define DT_RELAENT 9 /* size of relocation entry */
  436. #define DT_STRSZ 10 /* size of string table */
  437. #define DT_SYMENT 11 /* size of symbol table entry */
  438. #define DT_INIT 12 /* address of initialization func. */
  439. #define DT_FINI 13 /* address of termination function */
  440. #define DT_SONAME 14 /* string table offset of shared obj */
  441. #define DT_RPATH 15 /* string table offset of library
  442. search path */
  443. #define DT_SYMBOLIC 16 /* start sym search in shared obj. */
  444. #define DT_REL 17 /* address of rel. tbl. w addends */
  445. #define DT_RELSZ 18 /* size of DT_REL relocation table */
  446. #define DT_RELENT 19 /* size of DT_REL relocation entry */
  447. #define DT_PLTREL 20 /* PLT referenced relocation entry */
  448. #define DT_DEBUG 21 /* bugger */
  449. #define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
  450. #define DT_JMPREL 23 /* add. of PLT's relocation entries */
  451. #define DT_BIND_NOW 24 /* Process relocations of object */
  452. #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
  453. #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
  454. #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
  455. #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
  456. #define DT_RUNPATH 29 /* Library search path */
  457. #define DT_FLAGS 30 /* Flags for the object being loaded */
  458. #define DT_ENCODING 32 /* Start of encoded range */
  459. #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
  460. #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
  461. #define DT_NUM 34 /* Number used. */
  462. #define DT_LOOS 0x60000000 /* reserved range for OS */
  463. #define DT_HIOS 0x6fffffff /* specific dynamic array tags */
  464. #define DT_LOPROC 0x70000000 /* reserved range for processor */
  465. #define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
  466. /* Dynamic Tag Flags - d_un.d_val */
  467. #define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
  468. #define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
  469. #define DF_TEXTREL 0x04 /* Object contains text relocations */
  470. #define DF_BIND_NOW 0x08 /* No lazy binding for this object */
  471. #define DF_STATIC_TLS 0x10 /* Static thread local storage */
  472. /* Standard ELF hashing function */
  473. unsigned long elf_hash(const unsigned char *name);
  474. #define ELF_TARG_VER 1 /* The ver for which this code is intended */
  475. #endif /* __ASSEMBLER */
  476. /*
  477. * XXX - PowerPC defines really don't belong in here,
  478. * but we'll put them in for simplicity.
  479. */
  480. /* Values for Elf32/64_Ehdr.e_flags. */
  481. #define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
  482. /* Cygnus local bits below */
  483. #define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
  484. #define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
  485. flag */
  486. /* PowerPC relocations defined by the ABIs */
  487. #define R_PPC_NONE 0
  488. #define R_PPC_ADDR32 1 /* 32bit absolute address */
  489. #define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
  490. #define R_PPC_ADDR16 3 /* 16bit absolute address */
  491. #define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
  492. #define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
  493. #define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
  494. #define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
  495. #define R_PPC_ADDR14_BRTAKEN 8
  496. #define R_PPC_ADDR14_BRNTAKEN 9
  497. #define R_PPC_REL24 10 /* PC relative 26 bit */
  498. #define R_PPC_REL14 11 /* PC relative 16 bit */
  499. #define R_PPC_REL14_BRTAKEN 12
  500. #define R_PPC_REL14_BRNTAKEN 13
  501. #define R_PPC_GOT16 14
  502. #define R_PPC_GOT16_LO 15
  503. #define R_PPC_GOT16_HI 16
  504. #define R_PPC_GOT16_HA 17
  505. #define R_PPC_PLTREL24 18
  506. #define R_PPC_COPY 19
  507. #define R_PPC_GLOB_DAT 20
  508. #define R_PPC_JMP_SLOT 21
  509. #define R_PPC_RELATIVE 22
  510. #define R_PPC_LOCAL24PC 23
  511. #define R_PPC_UADDR32 24
  512. #define R_PPC_UADDR16 25
  513. #define R_PPC_REL32 26
  514. #define R_PPC_PLT32 27
  515. #define R_PPC_PLTREL32 28
  516. #define R_PPC_PLT16_LO 29
  517. #define R_PPC_PLT16_HI 30
  518. #define R_PPC_PLT16_HA 31
  519. #define R_PPC_SDAREL16 32
  520. #define R_PPC_SECTOFF 33
  521. #define R_PPC_SECTOFF_LO 34
  522. #define R_PPC_SECTOFF_HI 35
  523. #define R_PPC_SECTOFF_HA 36
  524. /* Keep this the last entry. */
  525. #define R_PPC_NUM 37
  526. /* The remaining relocs are from the Embedded ELF ABI, and are not
  527. in the SVR4 ELF ABI. */
  528. #define R_PPC_EMB_NADDR32 101
  529. #define R_PPC_EMB_NADDR16 102
  530. #define R_PPC_EMB_NADDR16_LO 103
  531. #define R_PPC_EMB_NADDR16_HI 104
  532. #define R_PPC_EMB_NADDR16_HA 105
  533. #define R_PPC_EMB_SDAI16 106
  534. #define R_PPC_EMB_SDA2I16 107
  535. #define R_PPC_EMB_SDA2REL 108
  536. #define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
  537. #define R_PPC_EMB_MRKREF 110
  538. #define R_PPC_EMB_RELSEC16 111
  539. #define R_PPC_EMB_RELST_LO 112
  540. #define R_PPC_EMB_RELST_HI 113
  541. #define R_PPC_EMB_RELST_HA 114
  542. #define R_PPC_EMB_BIT_FLD 115
  543. #define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
  544. /* Diab tool relocations. */
  545. #define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
  546. #define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
  547. #define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
  548. #define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
  549. #define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
  550. #define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
  551. /* This is a phony reloc to handle any old fashioned TOC16 references
  552. that may still be in object files. */
  553. #define R_PPC_TOC16 255
  554. /* ARM relocs */
  555. #define R_ARM_NONE 0 /* No reloc */
  556. #define R_ARM_RELATIVE 23 /* Adjust by program base */
  557. /* AArch64 relocs */
  558. #define R_AARCH64_NONE 0 /* No relocation. */
  559. #define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */
  560. #ifndef __ASSEMBLER__
  561. int valid_elf_image(unsigned long addr);
  562. #endif
  563. #endif /* _ELF_H */