1
0

elf.h 4.3 KB

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