readelf.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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_Char e_ident[EI_NIDENT];
  53. Elf32_Half e_type;
  54. Elf32_Half e_machine;
  55. Elf32_Word e_version;
  56. Elf32_Addr e_entry; /* Entry point */
  57. Elf32_Off e_phoff;
  58. Elf32_Off e_shoff;
  59. Elf32_Word e_flags;
  60. Elf32_Half e_ehsize;
  61. Elf32_Half e_phentsize;
  62. Elf32_Half e_phnum;
  63. Elf32_Half e_shentsize;
  64. Elf32_Half e_shnum;
  65. Elf32_Half e_shstrndx;
  66. } Elf32_Ehdr;
  67. typedef struct {
  68. Elf64_Char e_ident[EI_NIDENT];
  69. Elf64_Half e_type;
  70. Elf64_Half e_machine;
  71. Elf64_Word e_version;
  72. Elf64_Addr e_entry; /* Entry point */
  73. Elf64_Off e_phoff;
  74. Elf64_Off e_shoff;
  75. Elf64_Word e_flags;
  76. Elf64_Half e_ehsize;
  77. Elf64_Half e_phentsize;
  78. Elf64_Half e_phnum;
  79. Elf64_Half e_shentsize;
  80. Elf64_Half e_shnum;
  81. Elf64_Half e_shstrndx;
  82. } Elf64_Ehdr;
  83. /* e_type */
  84. #define ET_REL 1
  85. #define ET_EXEC 2
  86. #define ET_DYN 3
  87. #define ET_CORE 4
  88. /* e_machine (used only for SunOS 5.x hardware capabilities) */
  89. #define EM_SPARC 2
  90. #define EM_386 3
  91. #define EM_SPARC32PLUS 18
  92. #define EM_SPARCV9 43
  93. #define EM_IA_64 50
  94. #define EM_AMD64 62
  95. /* sh_type */
  96. #define SHT_SYMTAB 2
  97. #define SHT_NOTE 7
  98. #define SHT_DYNSYM 11
  99. #define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
  100. /* elf type */
  101. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  102. #define ELFDATA2LSB 1
  103. #define ELFDATA2MSB 2
  104. /* elf class */
  105. #define ELFCLASSNONE 0
  106. #define ELFCLASS32 1
  107. #define ELFCLASS64 2
  108. /* magic number */
  109. #define EI_MAG0 0 /* e_ident[] indexes */
  110. #define EI_MAG1 1
  111. #define EI_MAG2 2
  112. #define EI_MAG3 3
  113. #define EI_CLASS 4
  114. #define EI_DATA 5
  115. #define EI_VERSION 6
  116. #define EI_PAD 7
  117. #define ELFMAG0 0x7f /* EI_MAG */
  118. #define ELFMAG1 'E'
  119. #define ELFMAG2 'L'
  120. #define ELFMAG3 'F'
  121. #define ELFMAG "\177ELF"
  122. #define OLFMAG1 'O'
  123. #define OLFMAG "\177OLF"
  124. typedef struct {
  125. Elf32_Word p_type;
  126. Elf32_Off p_offset;
  127. Elf32_Addr p_vaddr;
  128. Elf32_Addr p_paddr;
  129. Elf32_Word p_filesz;
  130. Elf32_Word p_memsz;
  131. Elf32_Word p_flags;
  132. Elf32_Word p_align;
  133. } Elf32_Phdr;
  134. typedef struct {
  135. Elf64_Word p_type;
  136. Elf64_Word p_flags;
  137. Elf64_Off p_offset;
  138. Elf64_Addr p_vaddr;
  139. Elf64_Addr p_paddr;
  140. Elf64_Xword p_filesz;
  141. Elf64_Xword p_memsz;
  142. Elf64_Xword p_align;
  143. } Elf64_Phdr;
  144. #define PT_NULL 0 /* p_type */
  145. #define PT_LOAD 1
  146. #define PT_DYNAMIC 2
  147. #define PT_INTERP 3
  148. #define PT_NOTE 4
  149. #define PT_SHLIB 5
  150. #define PT_PHDR 6
  151. #define PT_NUM 7
  152. typedef struct {
  153. Elf32_Word sh_name;
  154. Elf32_Word sh_type;
  155. Elf32_Word sh_flags;
  156. Elf32_Addr sh_addr;
  157. Elf32_Off sh_offset;
  158. Elf32_Word sh_size;
  159. Elf32_Word sh_link;
  160. Elf32_Word sh_info;
  161. Elf32_Word sh_addralign;
  162. Elf32_Word sh_entsize;
  163. } Elf32_Shdr;
  164. typedef struct {
  165. Elf64_Word sh_name;
  166. Elf64_Word sh_type;
  167. Elf64_Off sh_flags;
  168. Elf64_Addr sh_addr;
  169. Elf64_Off sh_offset;
  170. Elf64_Off sh_size;
  171. Elf64_Word sh_link;
  172. Elf64_Word sh_info;
  173. Elf64_Off sh_addralign;
  174. Elf64_Off sh_entsize;
  175. } Elf64_Shdr;
  176. #define NT_NETBSD_CORE_PROCINFO 1
  177. /* Note header in a PT_NOTE section */
  178. typedef struct elf_note {
  179. Elf32_Word n_namesz; /* Name size */
  180. Elf32_Word n_descsz; /* Content size */
  181. Elf32_Word n_type; /* Content type */
  182. } Elf32_Nhdr;
  183. typedef struct {
  184. Elf64_Word n_namesz;
  185. Elf64_Word n_descsz;
  186. Elf64_Word n_type;
  187. } Elf64_Nhdr;
  188. /* Notes used in ET_CORE */
  189. #define NT_PRSTATUS 1
  190. #define NT_PRFPREG 2
  191. #define NT_PRPSINFO 3
  192. #define NT_PRXREG 4
  193. #define NT_TASKSTRUCT 4
  194. #define NT_PLATFORM 5
  195. #define NT_AUXV 6
  196. /* Note types used in executables */
  197. /* NetBSD executables (name = "NetBSD") */
  198. #define NT_NETBSD_VERSION 1
  199. #define NT_NETBSD_EMULATION 2
  200. #define NT_FREEBSD_VERSION 1
  201. #define NT_OPENBSD_VERSION 1
  202. #define NT_DRAGONFLY_VERSION 1
  203. /*
  204. * GNU executables (name = "GNU")
  205. * word[0]: GNU OS tags
  206. * word[1]: major version
  207. * word[2]: minor version
  208. * word[3]: tiny version
  209. */
  210. #define NT_GNU_VERSION 1
  211. /* GNU OS tags */
  212. #define GNU_OS_LINUX 0
  213. #define GNU_OS_HURD 1
  214. #define GNU_OS_SOLARIS 2
  215. #define GNU_OS_KFREEBSD 3
  216. #define GNU_OS_KNETBSD 4
  217. /*
  218. * GNU Hardware capability information
  219. * word[0]: Number of entries
  220. * word[1]: Bitmask of enabled entries
  221. * Followed by a byte id, and a NUL terminated string per entry
  222. */
  223. #define NT_GNU_HWCAP 2
  224. /*
  225. * GNU Build ID generated by ld
  226. * 160 bit SHA1 [default]
  227. * 128 bit md5 or uuid
  228. */
  229. #define NT_GNU_BUILD_ID 3
  230. /*
  231. * NetBSD-specific note type: PaX.
  232. * There should be 1 NOTE per executable.
  233. * name: PaX\0
  234. * namesz: 4
  235. * desc:
  236. * word[0]: capability bitmask
  237. * descsz: 4
  238. */
  239. #define NT_NETBSD_PAX 3
  240. #define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */
  241. #define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
  242. #define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */
  243. #define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */
  244. #define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */
  245. #define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */
  246. /*
  247. * NetBSD-specific note type: MACHINE_ARCH.
  248. * There should be 1 NOTE per executable.
  249. * name: NetBSD\0
  250. * namesz: 7
  251. * desc: string
  252. * descsz: variable
  253. */
  254. #define NT_NETBSD_MARCH 5
  255. /*
  256. * NetBSD-specific note type: COMPILER MODEL.
  257. * There should be 1 NOTE per executable.
  258. * name: NetBSD\0
  259. * namesz: 7
  260. * desc: string
  261. * descsz: variable
  262. */
  263. #define NT_NETBSD_CMODEL 6
  264. #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
  265. #define ELFSIZE ARCH_ELFSIZE
  266. #endif
  267. /* SunOS 5.x hardware/software capabilities */
  268. typedef struct {
  269. Elf32_Word c_tag;
  270. union {
  271. Elf32_Word c_val;
  272. Elf32_Addr c_ptr;
  273. } c_un;
  274. } Elf32_Cap;
  275. typedef struct {
  276. Elf64_Xword c_tag;
  277. union {
  278. Elf64_Xword c_val;
  279. Elf64_Addr c_ptr;
  280. } c_un;
  281. } Elf64_Cap;
  282. /* SunOS 5.x hardware/software capability tags */
  283. #define CA_SUNW_NULL 0
  284. #define CA_SUNW_HW_1 1
  285. #define CA_SUNW_SF_1 2
  286. /* SunOS 5.x software capabilities */
  287. #define SF1_SUNW_FPKNWN 0x01
  288. #define SF1_SUNW_FPUSED 0x02
  289. #define SF1_SUNW_MASK 0x03
  290. /* SunOS 5.x hardware capabilities: sparc */
  291. #define AV_SPARC_MUL32 0x0001
  292. #define AV_SPARC_DIV32 0x0002
  293. #define AV_SPARC_FSMULD 0x0004
  294. #define AV_SPARC_V8PLUS 0x0008
  295. #define AV_SPARC_POPC 0x0010
  296. #define AV_SPARC_VIS 0x0020
  297. #define AV_SPARC_VIS2 0x0040
  298. #define AV_SPARC_ASI_BLK_INIT 0x0080
  299. #define AV_SPARC_FMAF 0x0100
  300. #define AV_SPARC_FJFMAU 0x4000
  301. #define AV_SPARC_IMA 0x8000
  302. /* SunOS 5.x hardware capabilities: 386 */
  303. #define AV_386_FPU 0x00000001
  304. #define AV_386_TSC 0x00000002
  305. #define AV_386_CX8 0x00000004
  306. #define AV_386_SEP 0x00000008
  307. #define AV_386_AMD_SYSC 0x00000010
  308. #define AV_386_CMOV 0x00000020
  309. #define AV_386_MMX 0x00000040
  310. #define AV_386_AMD_MMX 0x00000080
  311. #define AV_386_AMD_3DNow 0x00000100
  312. #define AV_386_AMD_3DNowx 0x00000200
  313. #define AV_386_FXSR 0x00000400
  314. #define AV_386_SSE 0x00000800
  315. #define AV_386_SSE2 0x00001000
  316. #define AV_386_PAUSE 0x00002000
  317. #define AV_386_SSE3 0x00004000
  318. #define AV_386_MON 0x00008000
  319. #define AV_386_CX16 0x00010000
  320. #define AV_386_AHF 0x00020000
  321. #define AV_386_TSCP 0x00040000
  322. #define AV_386_AMD_SSE4A 0x00080000
  323. #define AV_386_POPCNT 0x00100000
  324. #define AV_386_AMD_LZCNT 0x00200000
  325. #define AV_386_SSSE3 0x00400000
  326. #define AV_386_SSE4_1 0x00800000
  327. #define AV_386_SSE4_2 0x01000000
  328. #endif