elf.h 3.7 KB

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