elf64.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. * include/elf64.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_ELF64_H
  21. #define __INCLUDE_ELF64_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <stdint.h>
  26. /****************************************************************************
  27. * Pre-processor Definitions
  28. ****************************************************************************/
  29. /* See ELF-64 Object File Format: Version 1.5 Draft 2 */
  30. /* Definitions for Elf64_Rel*::r_info */
  31. #define ELF64_R_SYM(i) ((i) >> 32)
  32. #define ELF64_R_TYPE(i) ((i)&0xffffffffL)
  33. #define ELF64_R_INFO(s, t) (((s) << 32) + ((t)&0xffffffffL))
  34. #if 0
  35. #define ELF_R_SYM(i) ELF64_R_SYM(i)
  36. #endif
  37. /****************************************************************************
  38. * Public Type Definitions
  39. ****************************************************************************/
  40. /* Table 1: ELF-64 Data Types */
  41. typedef uint64_t Elf64_Addr; /* Unsigned program address */
  42. typedef uint64_t Elf64_Off; /* Unsigned file offset */
  43. typedef uint16_t Elf64_Half; /* Unsigned medium integer */
  44. typedef uint32_t Elf64_Word; /* Unsigned long integer */
  45. typedef int32_t Elf64_Sword; /* Signed integer */
  46. typedef uint64_t Elf64_Xword; /* Unsigned long integer */
  47. typedef int64_t Elf64_Sxword; /* Signed large integer */
  48. /* Figure 2: ELF-64 Header */
  49. typedef struct {
  50. unsigned char e_ident[EI_NIDENT]; /* ELF identification */
  51. Elf64_Half e_type; /* Object file type */
  52. Elf64_Half e_machine; /* Machine type */
  53. Elf64_Word e_version; /* Object file version */
  54. Elf64_Addr e_entry; /* Entry point address */
  55. Elf64_Off e_phoff; /* Program header offset */
  56. Elf64_Off e_shoff; /* Section header offset */
  57. Elf64_Word e_flags; /* Processor-specific flags */
  58. Elf64_Half e_ehsize; /* ELF header size */
  59. Elf64_Half e_phentsize; /* Size of program header entry */
  60. Elf64_Half e_phnum; /* Number of program header entry */
  61. Elf64_Half e_shentsize; /* Size of section header entry */
  62. Elf64_Half e_shnum; /* Number of section header entries */
  63. Elf64_Half e_shstrndx; /* Section name string table index */
  64. } Elf64_Ehdr;
  65. /* Figure 3: ELF-64 Section Header */
  66. typedef struct {
  67. Elf64_Word sh_name; /* Section name */
  68. Elf64_Word sh_type; /* Section type */
  69. Elf64_Xword sh_flags; /* Section attributes */
  70. Elf64_Addr sh_addr; /* Virtual address in memory */
  71. Elf64_Off sh_offset; /* Offset in file */
  72. Elf64_Xword sh_size; /* Size of section */
  73. Elf64_Word sh_link; /* Link to other section */
  74. Elf64_Word sh_info; /* Miscellaneous information */
  75. Elf64_Xword sh_addralign; /* Address alignment boundary */
  76. Elf64_Xword sh_entsize; /* Size of entries, if section has table */
  77. } Elf64_Shdr;
  78. /* Figure 4: ELF-64 Symbol Table Entry */
  79. typedef struct {
  80. Elf64_Word st_name; /* Symbol name */
  81. unsigned char st_info; /* Type and Binding attributes */
  82. unsigned char st_other; /* Reserved */
  83. Elf64_Half st_shndx; /* Section table index */
  84. Elf64_Addr st_value; /* Symbol value */
  85. Elf64_Xword st_size; /* Size of object (e.g., common) */
  86. } Elf64_Sym;
  87. /* Figure 5: ELF-64 Relocation Entries */
  88. typedef struct {
  89. Elf64_Addr r_offset; /* Address of reference */
  90. Elf64_Xword r_info; /* Symbol index and type of relocation */
  91. } Elf64_Rel;
  92. typedef struct {
  93. Elf64_Addr r_offset; /* Address of reference */
  94. Elf64_Xword r_info; /* Symbol index and type of relocation */
  95. Elf64_Sxword r_addend; /* Constant part of expression */
  96. } Elf64_Rela;
  97. /* Figure 6: ELF-64 Program Header Table Entry */
  98. typedef struct {
  99. Elf64_Word p_type; /* Type of segment */
  100. Elf64_Word p_flags; /* Segment attributes */
  101. Elf64_Off p_offset; /* Offset in file */
  102. Elf64_Addr p_vaddr; /* Virtual address in memory */
  103. Elf64_Addr p_paddr; /* Reserved */
  104. Elf64_Word p_filesz; /* Size of segment in file */
  105. Elf64_Word p_memsz; /* Size of segment in memory */
  106. Elf64_Word p_align; /* Alignment of segment */
  107. } Elf64_Phdr;
  108. /* Figure 7. Format of a Note Section */
  109. typedef struct {
  110. Elf64_Word n_namesz; /* Length of the note's name. */
  111. Elf64_Word n_descsz; /* Length of the note's descriptor. */
  112. Elf64_Word n_type; /* Type of the note. */
  113. } Elf64_Nhdr;
  114. /* Figure 8: Dynamic Table Structure */
  115. typedef struct {
  116. Elf64_Sxword d_tag;
  117. union {
  118. Elf64_Xword d_val;
  119. Elf64_Addr d_ptr;
  120. } d_un;
  121. } Elf64_Dyn;
  122. #if 0
  123. typedef Elf64_Addr Elf_Addr;
  124. typedef Elf64_Ehdr Elf_Ehdr;
  125. typedef Elf64_Rel Elf_Rel;
  126. typedef Elf64_Rela Elf_Rela;
  127. typedef Elf64_Nhdr Elf_Nhdr;
  128. typedef Elf64_Phdr Elf_Phdr;
  129. typedef Elf64_Sym Elf_Sym;
  130. typedef Elf64_Shdr Elf_Shdr;
  131. typedef Elf64_Word Elf_Word;
  132. #endif
  133. #endif /* __INCLUDE_ELF64_H */