elf.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Definitions needed for accessing ELF headers
  11. */
  12. typedef struct {
  13. u8 ident[16]; /* ident bytes */
  14. u16 type; /* file type */
  15. u16 machine; /* target machine */
  16. u32 version; /* file version */
  17. u64 elfentry; /* start address */
  18. u64 phoff; /* phdr file offset */
  19. u64 shoff; /* shdr file offset */
  20. u32 flags; /* file flags */
  21. u16 ehsize; /* sizeof ehdr */
  22. u16 phentsize; /* sizeof phdr */
  23. u16 phnum; /* number phdrs */
  24. u16 shentsize; /* sizeof shdr */
  25. u16 shnum; /* number shdrs */
  26. u16 shstrndx; /* shdr string index */
  27. } E64hdr;
  28. typedef struct {
  29. int type; /* entry type */
  30. u32 offset; /* file offset */
  31. u32 vaddr; /* virtual address */
  32. u32 paddr; /* physical address */
  33. int filesz; /* file size */
  34. u32 memsz; /* memory size */
  35. int flags; /* entry flags */
  36. int align; /* memory/file alignment */
  37. } Phdr;
  38. typedef struct {
  39. u32 type; /* entry type */
  40. u32 flags; /* entry flags */
  41. u64 offset; /* file offset */
  42. u64 vaddr; /* virtual address */
  43. u64 paddr; /* physical address */
  44. u64 filesz; /* file size */
  45. u64 memsz; /* memory size */
  46. u64 align; /* memory/file alignment */
  47. } P64hdr;
  48. typedef struct {
  49. u32 name; /* section name */
  50. u32 type; /* SHT_... */
  51. u32 flags; /* SHF_... */
  52. u32 addr; /* virtual address */
  53. u32 offset; /* file offset */
  54. u32 size; /* section size */
  55. u32 link; /* misc info */
  56. u32 info; /* misc info */
  57. u32 addralign; /* memory alignment */
  58. u32 entsize; /* entry size if table */
  59. } Shdr;
  60. typedef struct {
  61. u32 name; /* section name */
  62. u32 type; /* SHT_... */
  63. u64 flags; /* SHF_... */
  64. u64 addr; /* virtual address */
  65. u64 offset; /* file offset */
  66. u64 size; /* section size */
  67. u32 link; /* misc info */
  68. u32 info; /* misc info */
  69. u64 addralign; /* memory alignment */
  70. u64 entsize; /* entry size if table */
  71. } S64hdr;
  72. typedef struct {
  73. u32 st_name; /* Symbol name */
  74. u8 st_info; /* Type and Binding attributes */
  75. u8 st_other; /* Reserved */
  76. u16 st_shndx; /* Section table index */
  77. u64 st_value; /* Symbol value */
  78. u64 st_size; /* Size of object (e.g., common) */
  79. } E64Sym;
  80. typedef struct Sym {
  81. i64 value;
  82. u32 sig;
  83. char type;
  84. char *name;
  85. } Sym;
  86. enum {
  87. /* Ehdr codes */
  88. MAG0 = 0, /* ident[] indexes */
  89. MAG1 = 1,
  90. MAG2 = 2,
  91. MAG3 = 3,
  92. CLASS = 4,
  93. DATA = 5,
  94. VERSION = 6,
  95. ELFCLASSNONE = 0, /* ident[CLASS] */
  96. ELFCLASS32 = 1,
  97. ELFCLASS64 = 2,
  98. ELFCLASSNUM = 3,
  99. ELFDATANONE = 0, /* ident[DATA] */
  100. ELFDATA2LSB = 1,
  101. ELFDATA2MSB = 2,
  102. ELFDATANUM = 3,
  103. NOETYPE = 0, /* type */
  104. REL = 1,
  105. EXEC = 2,
  106. DYN = 3,
  107. CORE = 4,
  108. NONE = 0, /* machine */
  109. M32 = 1, /* AT&T WE 32100 */
  110. SPARC = 2, /* Sun SPARC */
  111. I386 = 3, /* Intel 80386 */
  112. M68K = 4, /* Motorola 68000 */
  113. M88K = 5, /* Motorola 88000 */
  114. I486 = 6, /* Intel 80486 */
  115. I860 = 7, /* Intel i860 */
  116. MIPS = 8, /* Mips R2000 */
  117. S370 = 9, /* Amdhal */
  118. MIPSR4K = 10, /* Mips R4000 */
  119. SPARC64 = 18, /* Sun SPARC v9 */
  120. POWER = 20, /* PowerPC */
  121. POWER64 = 21, /* PowerPC64 */
  122. ARM = 40, /* ARM */
  123. AMD64 = 62, /* Amd64 */
  124. ARM64 = 183, /* ARM64 */
  125. NO_VERSION = 0, /* version, ident[VERSION] */
  126. CURRENT = 1,
  127. /* Phdr Codes */
  128. NOPTYPE = 0, /* type */
  129. LOAD = 1,
  130. DYNAMIC = 2,
  131. INTERP = 3,
  132. NOTE = 4,
  133. SHLIB = 5,
  134. PHDR = 6,
  135. R = 0x4, /* flags */
  136. W = 0x2,
  137. X = 0x1,
  138. /* Shdr Codes */
  139. SHT_PROGBITS = 1, /* section types */
  140. SHT_SYMTAB = 2,
  141. SHT_STRTAB = 3,
  142. SHT_NOBITS = 8,
  143. Swrite = 1, /* section attributes */
  144. Salloc = 2,
  145. Sexec = 4,
  146. STB_LOCAL = 0, /* Symbol bindings */
  147. STB_GLOBAL = 1,
  148. STB_WEAK = 2,
  149. STB_LOOS = 10,
  150. STB_HIOS = 12,
  151. STB_LOPROC = 13,
  152. STB_HIPROC = 15,
  153. STT_NOTYPE = 0, /* Symbol types */
  154. STT_OBJECT = 1,
  155. STT_FUNC = 2,
  156. STT_SECTION = 3,
  157. STT_FILE = 4,
  158. STT_LOOS = 10,
  159. STT_HIOS = 12,
  160. STT_LOPROC = 13,
  161. STT_HIPROC = 15,
  162. SHN_UNDEF = 0,
  163. };
  164. #define ELF_MAG ((0x7f<<24) | ('E'<<16) | ('L'<<8) | 'F')