readelf.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #if SIZEOF_UINT64_T != 8
  45. #define USE_ARRAY_FOR_64BIT_TYPES
  46. typedef uint32_t Elf64_Addr[2];
  47. typedef uint32_t Elf64_Off[2];
  48. typedef uint32_t Elf64_Xword[2];
  49. #else
  50. typedef uint64_t Elf64_Addr;
  51. typedef uint64_t Elf64_Off;
  52. typedef uint64_t Elf64_Xword;
  53. #endif
  54. typedef uint16_t Elf64_Half;
  55. typedef uint32_t Elf64_Word;
  56. typedef uint8_t Elf64_Char;
  57. #define EI_NIDENT 16
  58. typedef struct {
  59. Elf32_Char e_ident[EI_NIDENT];
  60. Elf32_Half e_type;
  61. Elf32_Half e_machine;
  62. Elf32_Word e_version;
  63. Elf32_Addr e_entry; /* Entry point */
  64. Elf32_Off e_phoff;
  65. Elf32_Off e_shoff;
  66. Elf32_Word e_flags;
  67. Elf32_Half e_ehsize;
  68. Elf32_Half e_phentsize;
  69. Elf32_Half e_phnum;
  70. Elf32_Half e_shentsize;
  71. Elf32_Half e_shnum;
  72. Elf32_Half e_shstrndx;
  73. } Elf32_Ehdr;
  74. typedef struct {
  75. Elf64_Char e_ident[EI_NIDENT];
  76. Elf64_Half e_type;
  77. Elf64_Half e_machine;
  78. Elf64_Word e_version;
  79. Elf64_Addr e_entry; /* Entry point */
  80. Elf64_Off e_phoff;
  81. Elf64_Off e_shoff;
  82. Elf64_Word e_flags;
  83. Elf64_Half e_ehsize;
  84. Elf64_Half e_phentsize;
  85. Elf64_Half e_phnum;
  86. Elf64_Half e_shentsize;
  87. Elf64_Half e_shnum;
  88. Elf64_Half e_shstrndx;
  89. } Elf64_Ehdr;
  90. /* e_type */
  91. #define ET_EXEC 2
  92. #define ET_CORE 4
  93. /* sh_type */
  94. #define SHT_SYMTAB 2
  95. #define SHT_NOTE 7
  96. #define SHT_DYNSYM 11
  97. /* elf type */
  98. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  99. #define ELFDATA2LSB 1
  100. #define ELFDATA2MSB 2
  101. /* elf class */
  102. #define ELFCLASSNONE 0
  103. #define ELFCLASS32 1
  104. #define ELFCLASS64 2
  105. /* magic number */
  106. #define EI_MAG0 0 /* e_ident[] indexes */
  107. #define EI_MAG1 1
  108. #define EI_MAG2 2
  109. #define EI_MAG3 3
  110. #define EI_CLASS 4
  111. #define EI_DATA 5
  112. #define EI_VERSION 6
  113. #define EI_PAD 7
  114. #define ELFMAG0 0x7f /* EI_MAG */
  115. #define ELFMAG1 'E'
  116. #define ELFMAG2 'L'
  117. #define ELFMAG3 'F'
  118. #define ELFMAG "\177ELF"
  119. #define OLFMAG1 'O'
  120. #define OLFMAG "\177OLF"
  121. typedef struct {
  122. Elf32_Word p_type;
  123. Elf32_Off p_offset;
  124. Elf32_Addr p_vaddr;
  125. Elf32_Addr p_paddr;
  126. Elf32_Word p_filesz;
  127. Elf32_Word p_memsz;
  128. Elf32_Word p_flags;
  129. Elf32_Word p_align;
  130. } Elf32_Phdr;
  131. typedef struct {
  132. Elf64_Word p_type;
  133. Elf64_Word p_flags;
  134. Elf64_Off p_offset;
  135. Elf64_Addr p_vaddr;
  136. Elf64_Addr p_paddr;
  137. Elf64_Xword p_filesz;
  138. Elf64_Xword p_memsz;
  139. Elf64_Xword p_align;
  140. } Elf64_Phdr;
  141. #define PT_NULL 0 /* p_type */
  142. #define PT_LOAD 1
  143. #define PT_DYNAMIC 2
  144. #define PT_INTERP 3
  145. #define PT_NOTE 4
  146. #define PT_SHLIB 5
  147. #define PT_PHDR 6
  148. #define PT_NUM 7
  149. typedef struct {
  150. Elf32_Word sh_name;
  151. Elf32_Word sh_type;
  152. Elf32_Word sh_flags;
  153. Elf32_Addr sh_addr;
  154. Elf32_Off sh_offset;
  155. Elf32_Word sh_size;
  156. Elf32_Word sh_link;
  157. Elf32_Word sh_info;
  158. Elf32_Word sh_addralign;
  159. Elf32_Word sh_entsize;
  160. } Elf32_Shdr;
  161. typedef struct {
  162. Elf64_Word sh_name;
  163. Elf64_Word sh_type;
  164. Elf64_Off sh_flags;
  165. Elf64_Addr sh_addr;
  166. Elf64_Off sh_offset;
  167. Elf64_Off sh_size;
  168. Elf64_Word sh_link;
  169. Elf64_Word sh_info;
  170. Elf64_Off sh_addralign;
  171. Elf64_Off sh_entsize;
  172. } Elf64_Shdr;
  173. /* Notes used in ET_CORE */
  174. #define NT_PRSTATUS 1
  175. #define NT_PRFPREG 2
  176. #define NT_PRPSINFO 3
  177. #define NT_TASKSTRUCT 4
  178. #define NT_NETBSD_CORE_PROCINFO 1
  179. /* Note header in a PT_NOTE section */
  180. typedef struct elf_note {
  181. Elf32_Word n_namesz; /* Name size */
  182. Elf32_Word n_descsz; /* Content size */
  183. Elf32_Word n_type; /* Content type */
  184. } Elf32_Nhdr;
  185. typedef struct {
  186. Elf64_Word n_namesz;
  187. Elf64_Word n_descsz;
  188. Elf64_Word n_type;
  189. } Elf64_Nhdr;
  190. #define NT_PRSTATUS 1
  191. #define NT_PRFPREG 2
  192. #define NT_PRPSINFO 3
  193. #define NT_PRXREG 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. /* GNU executables (name = "GNU") */
  203. #define NT_GNU_VERSION 1
  204. /* GNU OS tags */
  205. #define GNU_OS_LINUX 0
  206. #define GNU_OS_HURD 1
  207. #define GNU_OS_SOLARIS 2
  208. #endif