arc-plt.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* ARC-specific header file for PLT support.
  2. Copyright (C) 2016-2022 Free Software Foundation, Inc.
  3. Contributed by Cupertino Miranda (cmiranda@synopsys.com).
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #ifndef ARC_PLT_H
  18. #define ARC_PLT_H
  19. /* Instructions appear in memory as a sequence of half-words (16 bit);
  20. individual half-words are represented on the target in target byte order.
  21. We use 'unsigned short' on the host to represent the PLT templates,
  22. and translate to target byte order as we copy to the target. */
  23. typedef uint16_t insn_hword;
  24. enum plt_reloc_symbol
  25. {
  26. LAST_RELOC = 0,
  27. SGOT = 1,
  28. RELATIVE = (1 << 8),
  29. RELATIVE_INSN_32 = (1 << 9),
  30. RELATIVE_INSN_24 = (1 << 10),
  31. MIDDLE_ENDIAN = (1 << 11)
  32. };
  33. #define IS_RELATIVE(S) ((S & (RELATIVE | RELATIVE_INSN_24 | RELATIVE_INSN_32)) != 0)
  34. #define IS_INSN_32(S) ((S & RELATIVE_INSN_32) != 0)
  35. #define IS_INSN_24(S) ((S & RELATIVE_INSN_24) != 0)
  36. #define IS_MIDDLE_ENDIAN(S) ((S & MIDDLE_ENDIAN) != 0)
  37. #define SYM_ONLY(S) (S & 0xFF)
  38. struct plt_reloc
  39. {
  40. bfd_vma offset;
  41. bfd_vma size;
  42. bfd_vma mask;
  43. enum plt_reloc_symbol symbol;
  44. bfd_vma addend;
  45. };
  46. #define PLT_TYPE_START(NAME) NAME,
  47. #define PLT_TYPE_END(NAME)
  48. #define PLT_ENTRY(...)
  49. #define PLT_ELEM(...)
  50. #define ENTRY_RELOC(...)
  51. #define ELEM_RELOC(...)
  52. enum plt_types_enum
  53. {
  54. PLT_START = -1,
  55. #include "arc-plt.def"
  56. PLT_MAX
  57. };
  58. #undef PLT_TYPE_START
  59. #undef PLT_TYPE_END
  60. #undef PLT_ENTRY
  61. #undef PLT_ELEM
  62. #undef ENTRY_RELOC
  63. #undef ELEM_RELOC
  64. typedef insn_hword insn_hword_array[];
  65. struct plt_version_t
  66. {
  67. const insn_hword_array *entry;
  68. const bfd_vma entry_size;
  69. const insn_hword_array *elem;
  70. const bfd_vma elem_size;
  71. const struct plt_reloc *entry_relocs;
  72. const struct plt_reloc *elem_relocs;
  73. };
  74. #define PLT_TYPE_START(NAME) \
  75. const insn_hword NAME##_plt_entry[] = {
  76. #define PLT_TYPE_END(NAME) };
  77. #define PLT_ENTRY(...) __VA_ARGS__,
  78. #define PLT_ELEM(...)
  79. #define ENTRY_RELOC(...)
  80. #define ELEM_RELOC(...)
  81. #include "arc-plt.def"
  82. #undef PLT_TYPE_START
  83. #undef PLT_TYPE_END
  84. #undef PLT_ENTRY
  85. #undef PLT_ELEM
  86. #undef ENTRY_RELOC
  87. #undef ELEM_RELOC
  88. #define PLT_TYPE_START(NAME) \
  89. const struct plt_reloc NAME##_plt_entry_relocs[] = {
  90. #define PLT_TYPE_END(NAME) \
  91. {0, 0, 0, LAST_RELOC, 0} \
  92. };
  93. #define PLT_ENTRY(...)
  94. #define PLT_ELEM(...)
  95. #define ENTRY_RELOC(...) { __VA_ARGS__ },
  96. #define ELEM_RELOC(...)
  97. #include "arc-plt.def"
  98. #undef PLT_TYPE_START
  99. #undef PLT_TYPE_END
  100. #undef PLT_ENTRY
  101. #undef PLT_ELEM
  102. #undef ENTRY_RELOC
  103. #undef ELEM_RELOC
  104. #define PLT_TYPE_START(NAME) \
  105. const insn_hword NAME##_plt_elem[] = {
  106. #define PLT_TYPE_END(NAME) };
  107. #define PLT_ENTRY(...)
  108. #define PLT_ELEM(...) __VA_ARGS__,
  109. #define ENTRY_RELOC(...)
  110. #define ELEM_RELOC(...)
  111. #include "arc-plt.def"
  112. #undef PLT_TYPE_START
  113. #undef PLT_TYPE_END
  114. #undef PLT_ENTRY
  115. #undef PLT_ELEM
  116. #undef ENTRY_RELOC
  117. #undef ELEM_RELOC
  118. #define PLT_TYPE_START(NAME) \
  119. const struct plt_reloc NAME##_plt_elem_relocs[] = {
  120. #define PLT_TYPE_END(NAME) \
  121. {0, 0, 0, LAST_RELOC, 0} \
  122. };
  123. #define PLT_ENTRY(...)
  124. #define PLT_ELEM(...)
  125. #define ENTRY_RELOC(...)
  126. #define ELEM_RELOC(...) { __VA_ARGS__ },
  127. #include "arc-plt.def"
  128. #undef PLT_TYPE_START
  129. #undef PLT_TYPE_END
  130. #undef PLT_ENTRY
  131. #undef PLT_ELEM
  132. #undef ENTRY_RELOC
  133. #undef ELEM_RELOC
  134. #define PLT_TYPE_START(NAME) \
  135. { \
  136. .entry = &NAME##_plt_entry, \
  137. .entry_size = sizeof (NAME##_plt_entry), \
  138. .elem = &NAME##_plt_elem, \
  139. .elem_size = sizeof (NAME##_plt_elem), \
  140. .entry_relocs = NAME##_plt_entry_relocs, \
  141. .elem_relocs = NAME##_plt_elem_relocs
  142. #define PLT_TYPE_END(NAME) },
  143. #define PLT_ENTRY(...)
  144. #define PLT_ELEM(...)
  145. #define ENTRY_RELOC(...)
  146. #define ELEM_RELOC(...)
  147. const struct plt_version_t plt_versions[PLT_MAX] = {
  148. #include "arc-plt.def"
  149. };
  150. #undef PLT_TYPE_START
  151. #undef PLT_TYPE_END
  152. #undef PLT_ENTRY
  153. #undef PLT_ELEM
  154. #undef ENTRY_RELOC
  155. #undef ELEM_RELOC
  156. #endif /* ARC_PLT_H */