elf32.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. * include/elf32.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_ELF32_H
  21. #define __INCLUDE_ELF32_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <stdint.h>
  26. /****************************************************************************
  27. * Pre-processor Definitions
  28. ****************************************************************************/
  29. #define ELF32_ST_BIND(i) ((i) >> 4)
  30. #define ELF32_ST_TYPE(i) ((i)&0xf)
  31. #define ELF32_ST_INFO(b, t) (((b) << 4) | ((t)&0xf))
  32. /* Definitions for Elf32_Rel*::r_info */
  33. #define ELF32_R_SYM(i) ((i) >> 8)
  34. #define ELF32_R_TYPE(i) ((i)&0xff)
  35. #define ELF32_R_INFO(s, t) (((s) << 8) | ((t)&0xff))
  36. #if 0
  37. #define ELF_R_SYM(i) ELF32_R_SYM(i)
  38. #endif
  39. /****************************************************************************
  40. * Public Type Definitions
  41. ****************************************************************************/
  42. /* Figure 4.2: 32-Bit Data Types */
  43. typedef uint32_t Elf32_Addr; /* Unsigned program address */
  44. typedef uint16_t Elf32_Half; /* Unsigned medium integer */
  45. typedef uint32_t Elf32_Off; /* Unsigned file offset */
  46. typedef int32_t Elf32_Sword; /* Signed large integer */
  47. typedef uint32_t Elf32_Word; /* Unsigned large integer */
  48. /* Figure 4-3: ELF Header */
  49. typedef struct {
  50. unsigned char e_ident[EI_NIDENT];
  51. Elf32_Half e_type;
  52. Elf32_Half e_machine;
  53. Elf32_Word e_version;
  54. Elf32_Addr e_entry;
  55. Elf32_Off e_phoff;
  56. Elf32_Off e_shoff;
  57. Elf32_Word e_flags;
  58. Elf32_Half e_ehsize;
  59. Elf32_Half e_phentsize;
  60. Elf32_Half e_phnum;
  61. Elf32_Half e_shentsize;
  62. Elf32_Half e_shnum;
  63. Elf32_Half e_shstrndx;
  64. } Elf32_Ehdr;
  65. /* Figure 4-8: Section Header */
  66. typedef struct {
  67. Elf32_Word sh_name;
  68. Elf32_Word sh_type;
  69. Elf32_Word sh_flags;
  70. Elf32_Addr sh_addr;
  71. Elf32_Off sh_offset;
  72. Elf32_Word sh_size;
  73. Elf32_Word sh_link;
  74. Elf32_Word sh_info;
  75. Elf32_Word sh_addralign;
  76. Elf32_Word sh_entsize;
  77. } Elf32_Shdr;
  78. /* Figure 4-15: Symbol Table Entry */
  79. typedef struct {
  80. Elf32_Word st_name;
  81. Elf32_Addr st_value;
  82. Elf32_Word st_size;
  83. unsigned char st_info;
  84. unsigned char st_other;
  85. Elf32_Half st_shndx;
  86. } Elf32_Sym;
  87. /* Figure 4-19: Relocation Entries */
  88. typedef struct {
  89. Elf32_Addr r_offset;
  90. Elf32_Word r_info;
  91. } Elf32_Rel;
  92. typedef struct {
  93. Elf32_Addr r_offset;
  94. Elf32_Word r_info;
  95. Elf32_Sword r_addend;
  96. } Elf32_Rela;
  97. /* Figure 5-1: Program Header */
  98. typedef struct {
  99. Elf32_Word p_type;
  100. Elf32_Off p_offset;
  101. Elf32_Addr p_vaddr;
  102. Elf32_Addr p_paddr;
  103. Elf32_Word p_filesz;
  104. Elf32_Word p_memsz;
  105. Elf32_Word p_flags;
  106. Elf32_Word p_align;
  107. } Elf32_Phdr;
  108. /* Figure 5-7: Note Information */
  109. typedef struct {
  110. Elf32_Word n_namesz; /* Length of the note's name. */
  111. Elf32_Word n_descsz; /* Length of the note's descriptor. */
  112. Elf32_Word n_type; /* Type of the note. */
  113. } Elf32_Nhdr;
  114. /* Figure 5-9: Dynamic Structure */
  115. typedef struct {
  116. Elf32_Sword d_tag;
  117. union {
  118. Elf32_Word d_val;
  119. Elf32_Addr d_ptr;
  120. } d_un;
  121. } Elf32_Dyn;
  122. #if 0
  123. typedef Elf32_Addr Elf_Addr;
  124. typedef Elf32_Ehdr Elf_Ehdr;
  125. typedef Elf32_Rel Elf_Rel;
  126. typedef Elf32_Rela Elf_Rela;
  127. typedef Elf32_Nhdr Elf_Nhdr;
  128. typedef Elf32_Phdr Elf_Phdr;
  129. typedef Elf32_Sym Elf_Sym;
  130. typedef Elf32_Shdr Elf_Shdr;
  131. typedef Elf32_Word Elf_Word;
  132. #endif
  133. #endif /* __INCLUDE_ELF32_H */