elf.h 3.7 KB

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