elf.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #ifdef HARVEY32
  13. typedef struct {
  14. unsigned char ident[16]; /* ident bytes */
  15. unsigned short type; /* file type */
  16. unsigned short machine; /* target machine */
  17. int version; /* file version */
  18. uint32_t elfentry; /* start address */
  19. uint32_t phoff; /* phdr file offset */
  20. uint32_t shoff; /* shdr file offset */
  21. int flags; /* file flags */
  22. unsigned short ehsize; /* sizeof ehdr */
  23. unsigned short phentsize; /* sizeof phdr */
  24. unsigned short phnum; /* number phdrs */
  25. unsigned short shentsize; /* sizeof shdr */
  26. unsigned short shnum; /* number shdrs */
  27. unsigned short shstrndx; /* shdr string index */
  28. } Ehdr;
  29. #endif
  30. typedef struct {
  31. uint8_t ident[16]; /* ident bytes */
  32. uint16_t type; /* file type */
  33. uint16_t machine; /* target machine */
  34. uint32_t version; /* file version */
  35. uint64_t elfentry; /* start address */
  36. uint64_t phoff; /* phdr file offset */
  37. uint64_t shoff; /* shdr file offset */
  38. uint32_t flags; /* file flags */
  39. uint16_t ehsize; /* sizeof ehdr */
  40. uint16_t phentsize; /* sizeof phdr */
  41. uint16_t phnum; /* number phdrs */
  42. uint16_t shentsize; /* sizeof shdr */
  43. uint16_t shnum; /* number shdrs */
  44. uint16_t shstrndx; /* shdr string index */
  45. } E64hdr;
  46. typedef struct {
  47. int type; /* entry type */
  48. uint32_t offset; /* file offset */
  49. uint32_t vaddr; /* virtual address */
  50. uint32_t paddr; /* physical address */
  51. int filesz; /* file size */
  52. uint32_t memsz; /* memory size */
  53. int flags; /* entry flags */
  54. int align; /* memory/file alignment */
  55. } Phdr;
  56. typedef struct {
  57. uint32_t type; /* entry type */
  58. uint32_t flags; /* entry flags */
  59. uint64_t offset; /* file offset */
  60. uint64_t vaddr; /* virtual address */
  61. uint64_t paddr; /* physical address */
  62. uint64_t filesz; /* file size */
  63. uint64_t memsz; /* memory size */
  64. uint64_t align; /* memory/file alignment */
  65. } P64hdr;
  66. typedef struct {
  67. uint32_t name; /* section name */
  68. uint32_t type; /* SHT_... */
  69. uint32_t flags; /* SHF_... */
  70. uint32_t addr; /* virtual address */
  71. uint32_t offset; /* file offset */
  72. uint32_t size; /* section size */
  73. uint32_t link; /* misc info */
  74. uint32_t info; /* misc info */
  75. uint32_t addralign; /* memory alignment */
  76. uint32_t entsize; /* entry size if table */
  77. } Shdr;
  78. typedef struct {
  79. uint32_t name; /* section name */
  80. uint32_t type; /* SHT_... */
  81. uint64_t flags; /* SHF_... */
  82. uint64_t addr; /* virtual address */
  83. uint64_t offset; /* file offset */
  84. uint64_t size; /* section size */
  85. uint32_t link; /* misc info */
  86. uint32_t info; /* misc info */
  87. uint64_t addralign; /* memory alignment */
  88. uint64_t entsize; /* entry size if table */
  89. } S64hdr;
  90. enum {
  91. /* Ehdr codes */
  92. MAG0 = 0, /* ident[] indexes */
  93. MAG1 = 1,
  94. MAG2 = 2,
  95. MAG3 = 3,
  96. CLASS = 4,
  97. DATA = 5,
  98. VERSION = 6,
  99. ELFCLASSNONE = 0, /* ident[CLASS] */
  100. ELFCLASS32 = 1,
  101. ELFCLASS64 = 2,
  102. ELFCLASSNUM = 3,
  103. ELFDATANONE = 0, /* ident[DATA] */
  104. ELFDATA2LSB = 1,
  105. ELFDATA2MSB = 2,
  106. ELFDATANUM = 3,
  107. NOETYPE = 0, /* type */
  108. REL = 1,
  109. EXEC = 2,
  110. DYN = 3,
  111. CORE = 4,
  112. NONE = 0, /* machine */
  113. M32 = 1, /* AT&T WE 32100 */
  114. SPARC = 2, /* Sun SPARC */
  115. I386 = 3, /* Intel 80386 */
  116. M68K = 4, /* Motorola 68000 */
  117. M88K = 5, /* Motorola 88000 */
  118. I486 = 6, /* Intel 80486 */
  119. I860 = 7, /* Intel i860 */
  120. MIPS = 8, /* Mips R2000 */
  121. S370 = 9, /* Amdhal */
  122. MIPSR4K = 10, /* Mips R4000 */
  123. SPARC64 = 18, /* Sun SPARC v9 */
  124. POWER = 20, /* PowerPC */
  125. POWER64 = 21, /* PowerPC64 */
  126. ARM = 40, /* ARM */
  127. AMD64 = 62, /* Amd64 */
  128. ARM64 = 183, /* ARM64 */
  129. NO_VERSION = 0, /* version, ident[VERSION] */
  130. CURRENT = 1,
  131. /* Phdr Codes */
  132. NOPTYPE = 0, /* type */
  133. LOAD = 1,
  134. DYNAMIC = 2,
  135. INTERP = 3,
  136. NOTE = 4,
  137. SHLIB = 5,
  138. PHDR = 6,
  139. R = 0x4, /* flags */
  140. W = 0x2,
  141. X = 0x1,
  142. /* Shdr Codes */
  143. Progbits = 1, /* section types */
  144. Strtab = 3,
  145. Nobits = 8,
  146. Swrite = 1, /* section attributes */
  147. Salloc = 2,
  148. Sexec = 4,
  149. };
  150. #define ELF_MAG ((0x7f<<24) | ('E'<<16) | ('L'<<8) | 'F')