readelf.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * Copyright (c) Christos Zoulas 2003.
  3. * All Rights Reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice immediately at the beginning of the file, without modification,
  10. * this list of conditions, and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. /*
  28. * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
  29. *
  30. * Provide elf data structures for non-elf machines, allowing file
  31. * non-elf hosts to determine if an elf binary is stripped.
  32. * Note: cobbled from the linux header file, with modifications
  33. */
  34. #ifndef __fake_elf_h__
  35. #define __fake_elf_h__
  36. #if HAVE_STDINT_H
  37. #include <stdint.h>
  38. #endif
  39. typedef uint32_t Elf32_Addr;
  40. typedef uint32_t Elf32_Off;
  41. typedef uint16_t Elf32_Half;
  42. typedef uint32_t Elf32_Word;
  43. typedef uint8_t Elf32_Char;
  44. typedef uint64_t Elf64_Addr;
  45. typedef uint64_t Elf64_Off;
  46. typedef uint64_t Elf64_Xword;
  47. typedef uint16_t Elf64_Half;
  48. typedef uint32_t Elf64_Word;
  49. typedef uint8_t Elf64_Char;
  50. #define EI_NIDENT 16
  51. typedef struct {
  52. Elf32_Word a_type; /* 32-bit id */
  53. Elf32_Word a_v; /* 32-bit id */
  54. } Aux32Info;
  55. typedef struct {
  56. Elf64_Xword a_type; /* 64-bit id */
  57. Elf64_Xword a_v; /* 64-bit id */
  58. } Aux64Info;
  59. #define AT_NULL 0 /* end of vector */
  60. #define AT_IGNORE 1 /* entry should be ignored */
  61. #define AT_EXECFD 2 /* file descriptor of program */
  62. #define AT_PHDR 3 /* program headers for program */
  63. #define AT_PHENT 4 /* size of program header entry */
  64. #define AT_PHNUM 5 /* number of program headers */
  65. #define AT_PAGESZ 6 /* system page size */
  66. #define AT_BASE 7 /* base address of interpreter */
  67. #define AT_FLAGS 8 /* flags */
  68. #define AT_ENTRY 9 /* entry point of program */
  69. #define AT_LINUX_NOTELF 10 /* program is not ELF */
  70. #define AT_LINUX_UID 11 /* real uid */
  71. #define AT_LINUX_EUID 12 /* effective uid */
  72. #define AT_LINUX_GID 13 /* real gid */
  73. #define AT_LINUX_EGID 14 /* effective gid */
  74. #define AT_LINUX_PLATFORM 15 /* string identifying CPU for optimizations */
  75. #define AT_LINUX_HWCAP 16 /* arch dependent hints at CPU capabilities */
  76. #define AT_LINUX_CLKTCK 17 /* frequency at which times() increments */
  77. /* AT_* values 18 through 22 are reserved */
  78. #define AT_LINUX_SECURE 23 /* secure mode boolean */
  79. #define AT_LINUX_BASE_PLATFORM 24 /* string identifying real platform, may
  80. * differ from AT_PLATFORM. */
  81. #define AT_LINUX_RANDOM 25 /* address of 16 random bytes */
  82. #define AT_LINUX_HWCAP2 26 /* extension of AT_HWCAP */
  83. #define AT_LINUX_EXECFN 31 /* filename of program */
  84. typedef struct {
  85. Elf32_Char e_ident[EI_NIDENT];
  86. Elf32_Half e_type;
  87. Elf32_Half e_machine;
  88. Elf32_Word e_version;
  89. Elf32_Addr e_entry; /* Entry point */
  90. Elf32_Off e_phoff;
  91. Elf32_Off e_shoff;
  92. Elf32_Word e_flags;
  93. Elf32_Half e_ehsize;
  94. Elf32_Half e_phentsize;
  95. Elf32_Half e_phnum;
  96. Elf32_Half e_shentsize;
  97. Elf32_Half e_shnum;
  98. Elf32_Half e_shstrndx;
  99. } Elf32_Ehdr;
  100. typedef struct {
  101. Elf64_Char e_ident[EI_NIDENT];
  102. Elf64_Half e_type;
  103. Elf64_Half e_machine;
  104. Elf64_Word e_version;
  105. Elf64_Addr e_entry; /* Entry point */
  106. Elf64_Off e_phoff;
  107. Elf64_Off e_shoff;
  108. Elf64_Word e_flags;
  109. Elf64_Half e_ehsize;
  110. Elf64_Half e_phentsize;
  111. Elf64_Half e_phnum;
  112. Elf64_Half e_shentsize;
  113. Elf64_Half e_shnum;
  114. Elf64_Half e_shstrndx;
  115. } Elf64_Ehdr;
  116. /* e_type */
  117. #define ET_REL 1
  118. #define ET_EXEC 2
  119. #define ET_DYN 3
  120. #define ET_CORE 4
  121. /* e_machine (used only for SunOS 5.x hardware capabilities) */
  122. #define EM_SPARC 2
  123. #define EM_386 3
  124. #define EM_SPARC32PLUS 18
  125. #define EM_SPARCV9 43
  126. #define EM_IA_64 50
  127. #define EM_AMD64 62
  128. /* sh_type */
  129. #define SHT_SYMTAB 2
  130. #define SHT_NOTE 7
  131. #define SHT_DYNSYM 11
  132. #define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
  133. /* elf type */
  134. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  135. #define ELFDATA2LSB 1
  136. #define ELFDATA2MSB 2
  137. /* elf class */
  138. #define ELFCLASSNONE 0
  139. #define ELFCLASS32 1
  140. #define ELFCLASS64 2
  141. /* magic number */
  142. #define EI_MAG0 0 /* e_ident[] indexes */
  143. #define EI_MAG1 1
  144. #define EI_MAG2 2
  145. #define EI_MAG3 3
  146. #define EI_CLASS 4
  147. #define EI_DATA 5
  148. #define EI_VERSION 6
  149. #define EI_PAD 7
  150. #define ELFMAG0 0x7f /* EI_MAG */
  151. #define ELFMAG1 'E'
  152. #define ELFMAG2 'L'
  153. #define ELFMAG3 'F'
  154. #define ELFMAG "\177ELF"
  155. #define OLFMAG1 'O'
  156. #define OLFMAG "\177OLF"
  157. typedef struct {
  158. Elf32_Word p_type;
  159. Elf32_Off p_offset;
  160. Elf32_Addr p_vaddr;
  161. Elf32_Addr p_paddr;
  162. Elf32_Word p_filesz;
  163. Elf32_Word p_memsz;
  164. Elf32_Word p_flags;
  165. Elf32_Word p_align;
  166. } Elf32_Phdr;
  167. typedef struct {
  168. Elf64_Word p_type;
  169. Elf64_Word p_flags;
  170. Elf64_Off p_offset;
  171. Elf64_Addr p_vaddr;
  172. Elf64_Addr p_paddr;
  173. Elf64_Xword p_filesz;
  174. Elf64_Xword p_memsz;
  175. Elf64_Xword p_align;
  176. } Elf64_Phdr;
  177. #define PT_NULL 0 /* p_type */
  178. #define PT_LOAD 1
  179. #define PT_DYNAMIC 2
  180. #define PT_INTERP 3
  181. #define PT_NOTE 4
  182. #define PT_SHLIB 5
  183. #define PT_PHDR 6
  184. #define PT_NUM 7
  185. typedef struct {
  186. Elf32_Word sh_name;
  187. Elf32_Word sh_type;
  188. Elf32_Word sh_flags;
  189. Elf32_Addr sh_addr;
  190. Elf32_Off sh_offset;
  191. Elf32_Word sh_size;
  192. Elf32_Word sh_link;
  193. Elf32_Word sh_info;
  194. Elf32_Word sh_addralign;
  195. Elf32_Word sh_entsize;
  196. } Elf32_Shdr;
  197. typedef struct {
  198. Elf64_Word sh_name;
  199. Elf64_Word sh_type;
  200. Elf64_Off sh_flags;
  201. Elf64_Addr sh_addr;
  202. Elf64_Off sh_offset;
  203. Elf64_Off sh_size;
  204. Elf64_Word sh_link;
  205. Elf64_Word sh_info;
  206. Elf64_Off sh_addralign;
  207. Elf64_Off sh_entsize;
  208. } Elf64_Shdr;
  209. #define NT_NETBSD_CORE_PROCINFO 1
  210. /* Note header in a PT_NOTE section */
  211. typedef struct elf_note {
  212. Elf32_Word n_namesz; /* Name size */
  213. Elf32_Word n_descsz; /* Content size */
  214. Elf32_Word n_type; /* Content type */
  215. } Elf32_Nhdr;
  216. typedef struct {
  217. Elf64_Word n_namesz;
  218. Elf64_Word n_descsz;
  219. Elf64_Word n_type;
  220. } Elf64_Nhdr;
  221. /* Notes used in ET_CORE */
  222. #define NT_PRSTATUS 1
  223. #define NT_PRFPREG 2
  224. #define NT_PRPSINFO 3
  225. #define NT_PRXREG 4
  226. #define NT_TASKSTRUCT 4
  227. #define NT_PLATFORM 5
  228. #define NT_AUXV 6
  229. /* Note types used in executables */
  230. /* NetBSD executables (name = "NetBSD") */
  231. #define NT_NETBSD_VERSION 1
  232. #define NT_NETBSD_EMULATION 2
  233. #define NT_FREEBSD_VERSION 1
  234. #define NT_OPENBSD_VERSION 1
  235. #define NT_DRAGONFLY_VERSION 1
  236. /*
  237. * GNU executables (name = "GNU")
  238. * word[0]: GNU OS tags
  239. * word[1]: major version
  240. * word[2]: minor version
  241. * word[3]: tiny version
  242. */
  243. #define NT_GNU_VERSION 1
  244. /* GNU OS tags */
  245. #define GNU_OS_LINUX 0
  246. #define GNU_OS_HURD 1
  247. #define GNU_OS_SOLARIS 2
  248. #define GNU_OS_KFREEBSD 3
  249. #define GNU_OS_KNETBSD 4
  250. /*
  251. * GNU Hardware capability information
  252. * word[0]: Number of entries
  253. * word[1]: Bitmask of enabled entries
  254. * Followed by a byte id, and a NUL terminated string per entry
  255. */
  256. #define NT_GNU_HWCAP 2
  257. /*
  258. * GNU Build ID generated by ld
  259. * 160 bit SHA1 [default]
  260. * 128 bit md5 or uuid
  261. */
  262. #define NT_GNU_BUILD_ID 3
  263. /*
  264. * NetBSD-specific note type: PaX.
  265. * There should be 1 NOTE per executable.
  266. * name: PaX\0
  267. * namesz: 4
  268. * desc:
  269. * word[0]: capability bitmask
  270. * descsz: 4
  271. */
  272. #define NT_NETBSD_PAX 3
  273. #define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */
  274. #define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
  275. #define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */
  276. #define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */
  277. #define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */
  278. #define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */
  279. /*
  280. * NetBSD-specific note type: MACHINE_ARCH.
  281. * There should be 1 NOTE per executable.
  282. * name: NetBSD\0
  283. * namesz: 7
  284. * desc: string
  285. * descsz: variable
  286. */
  287. #define NT_NETBSD_MARCH 5
  288. /*
  289. * NetBSD-specific note type: COMPILER MODEL.
  290. * There should be 1 NOTE per executable.
  291. * name: NetBSD\0
  292. * namesz: 7
  293. * desc: string
  294. * descsz: variable
  295. */
  296. #define NT_NETBSD_CMODEL 6
  297. #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
  298. #define ELFSIZE ARCH_ELFSIZE
  299. #endif
  300. /* SunOS 5.x hardware/software capabilities */
  301. typedef struct {
  302. Elf32_Word c_tag;
  303. union {
  304. Elf32_Word c_val;
  305. Elf32_Addr c_ptr;
  306. } c_un;
  307. } Elf32_Cap;
  308. typedef struct {
  309. Elf64_Xword c_tag;
  310. union {
  311. Elf64_Xword c_val;
  312. Elf64_Addr c_ptr;
  313. } c_un;
  314. } Elf64_Cap;
  315. /* SunOS 5.x hardware/software capability tags */
  316. #define CA_SUNW_NULL 0
  317. #define CA_SUNW_HW_1 1
  318. #define CA_SUNW_SF_1 2
  319. /* SunOS 5.x software capabilities */
  320. #define SF1_SUNW_FPKNWN 0x01
  321. #define SF1_SUNW_FPUSED 0x02
  322. #define SF1_SUNW_MASK 0x03
  323. /* SunOS 5.x hardware capabilities: sparc */
  324. #define AV_SPARC_MUL32 0x0001
  325. #define AV_SPARC_DIV32 0x0002
  326. #define AV_SPARC_FSMULD 0x0004
  327. #define AV_SPARC_V8PLUS 0x0008
  328. #define AV_SPARC_POPC 0x0010
  329. #define AV_SPARC_VIS 0x0020
  330. #define AV_SPARC_VIS2 0x0040
  331. #define AV_SPARC_ASI_BLK_INIT 0x0080
  332. #define AV_SPARC_FMAF 0x0100
  333. #define AV_SPARC_FJFMAU 0x4000
  334. #define AV_SPARC_IMA 0x8000
  335. /* SunOS 5.x hardware capabilities: 386 */
  336. #define AV_386_FPU 0x00000001
  337. #define AV_386_TSC 0x00000002
  338. #define AV_386_CX8 0x00000004
  339. #define AV_386_SEP 0x00000008
  340. #define AV_386_AMD_SYSC 0x00000010
  341. #define AV_386_CMOV 0x00000020
  342. #define AV_386_MMX 0x00000040
  343. #define AV_386_AMD_MMX 0x00000080
  344. #define AV_386_AMD_3DNow 0x00000100
  345. #define AV_386_AMD_3DNowx 0x00000200
  346. #define AV_386_FXSR 0x00000400
  347. #define AV_386_SSE 0x00000800
  348. #define AV_386_SSE2 0x00001000
  349. #define AV_386_PAUSE 0x00002000
  350. #define AV_386_SSE3 0x00004000
  351. #define AV_386_MON 0x00008000
  352. #define AV_386_CX16 0x00010000
  353. #define AV_386_AHF 0x00020000
  354. #define AV_386_TSCP 0x00040000
  355. #define AV_386_AMD_SSE4A 0x00080000
  356. #define AV_386_POPCNT 0x00100000
  357. #define AV_386_AMD_LZCNT 0x00200000
  358. #define AV_386_SSSE3 0x00400000
  359. #define AV_386_SSE4_1 0x00800000
  360. #define AV_386_SSE4_2 0x01000000
  361. #endif