libxcoff.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* BFD XCOFF object file private structure.
  2. Copyright (C) 2001-2022 Free Software Foundation, Inc.
  3. Written by Tom Rix, Redhat.
  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 LIBXCOFF_H
  18. #define LIBXCOFF_H
  19. /* This is the backend information kept for XCOFF files. This
  20. structure is constant for a particular backend. The first element
  21. is the COFF backend data structure, so that XCOFF targets can use
  22. the generic COFF code. */
  23. struct xcoff_backend_data_rec
  24. {
  25. /* COFF backend information. */
  26. bfd_coff_backend_data coff;
  27. /* Magic number. */
  28. unsigned short _xcoff_magic_number;
  29. /* Architecture and machine for coff_set_arch_mach_hook. */
  30. enum bfd_architecture _xcoff_architecture;
  31. long _xcoff_machine;
  32. /* Function pointers to xcoff specific swap routines. */
  33. void (* _xcoff_swap_ldhdr_in) (bfd *, const void *, struct internal_ldhdr *);
  34. void (* _xcoff_swap_ldhdr_out)(bfd *, const struct internal_ldhdr *, void *);
  35. void (* _xcoff_swap_ldsym_in) (bfd *, const void *, struct internal_ldsym *);
  36. void (* _xcoff_swap_ldsym_out)(bfd *, const struct internal_ldsym *, void *);
  37. void (* _xcoff_swap_ldrel_in) (bfd *, const void *, struct internal_ldrel *);
  38. void (* _xcoff_swap_ldrel_out)(bfd *, const struct internal_ldrel *, void *);
  39. /* Size of the external struct. */
  40. unsigned int _xcoff_ldhdrsz;
  41. unsigned int _xcoff_ldsymsz;
  42. unsigned int _xcoff_ldrelsz;
  43. /* Size an entry in a descriptor section. */
  44. unsigned int _xcoff_function_descriptor_size;
  45. /* Size of the small aout file header. */
  46. unsigned int _xcoff_small_aout_header_size;
  47. /* Loader version
  48. 1 : XCOFF32
  49. 2 : XCOFF64. */
  50. unsigned long _xcoff_ldhdr_version;
  51. bool (* _xcoff_put_symbol_name)
  52. (struct bfd_link_info *, struct bfd_strtab_hash *,
  53. struct internal_syment *, const char *);
  54. bool (* _xcoff_put_ldsymbol_name)
  55. (bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
  56. const char *);
  57. reloc_howto_type *_xcoff_dynamic_reloc;
  58. asection * (* _xcoff_create_csect_from_smclas)
  59. (bfd *, union internal_auxent *, const char *);
  60. /* Line number and relocation overflow.
  61. XCOFF32 overflows to another section when the line number or the
  62. relocation count exceeds 0xffff. XCOFF64 does not overflow. */
  63. bool (*_xcoff_is_lineno_count_overflow) (bfd *, bfd_vma);
  64. bool (*_xcoff_is_reloc_count_overflow) (bfd *, bfd_vma);
  65. /* Loader section symbol and relocation table offset
  66. XCOFF32 is after the .loader header
  67. XCOFF64 is offset in .loader header. */
  68. bfd_vma (*_xcoff_loader_symbol_offset) (bfd *, struct internal_ldhdr *);
  69. bfd_vma (*_xcoff_loader_reloc_offset) (bfd *, struct internal_ldhdr *);
  70. /* Global linkage. The first word of global linkage code must be be
  71. modified by filling in the correct TOC offset. */
  72. const unsigned long *_xcoff_glink_code;
  73. /* Size of the global link code in bytes of the xcoff_glink_code table. */
  74. unsigned long _xcoff_glink_size;
  75. /* rtinit. */
  76. unsigned int _xcoff_rtinit_size;
  77. bool (*_xcoff_generate_rtinit)
  78. (bfd *, const char *, const char *, bool);
  79. };
  80. /* Look up an entry in an XCOFF link hash table. */
  81. #define xcoff_link_hash_lookup(table, string, create, copy, follow) \
  82. ((struct xcoff_link_hash_entry *) \
  83. bfd_link_hash_lookup (&(table)->root, (string), (create), (copy),\
  84. (follow)))
  85. /* Traverse an XCOFF link hash table. */
  86. #define xcoff_link_hash_traverse(table, func, info) \
  87. (bfd_link_hash_traverse \
  88. (&(table)->root, \
  89. (bool (*) (struct bfd_link_hash_entry *, void *)) (func), \
  90. (info)))
  91. /* Get the XCOFF link hash table from the info structure. This is
  92. just a cast. */
  93. #define xcoff_hash_table(p) ((struct xcoff_link_hash_table *) ((p)->hash))
  94. #define xcoff_backend(abfd) \
  95. ((struct xcoff_backend_data_rec *) (abfd)->xvec->backend_data)
  96. #define bfd_xcoff_magic_number(a) ((xcoff_backend (a)->_xcoff_magic_number))
  97. #define bfd_xcoff_architecture(a) ((xcoff_backend (a)->_xcoff_architecture))
  98. #define bfd_xcoff_machine(a) ((xcoff_backend (a)->_xcoff_machine))
  99. #define bfd_xcoff_swap_ldhdr_in(a, b, c) \
  100. ((xcoff_backend (a)->_xcoff_swap_ldhdr_in) ((a), (b), (c)))
  101. #define bfd_xcoff_swap_ldhdr_out(a, b, c) \
  102. ((xcoff_backend (a)->_xcoff_swap_ldhdr_out) ((a), (b), (c)))
  103. #define bfd_xcoff_swap_ldsym_in(a, b, c) \
  104. ((xcoff_backend (a)->_xcoff_swap_ldsym_in) ((a), (b), (c)))
  105. #define bfd_xcoff_swap_ldsym_out(a, b, c) \
  106. ((xcoff_backend (a)->_xcoff_swap_ldsym_out) ((a), (b), (c)))
  107. #define bfd_xcoff_swap_ldrel_in(a, b, c) \
  108. ((xcoff_backend (a)->_xcoff_swap_ldrel_in) ((a), (b), (c)))
  109. #define bfd_xcoff_swap_ldrel_out(a, b, c) \
  110. ((xcoff_backend (a)->_xcoff_swap_ldrel_out) ((a), (b), (c)))
  111. #define bfd_xcoff_ldhdrsz(a) ((xcoff_backend (a)->_xcoff_ldhdrsz))
  112. #define bfd_xcoff_ldsymsz(a) ((xcoff_backend (a)->_xcoff_ldsymsz))
  113. #define bfd_xcoff_ldrelsz(a) ((xcoff_backend (a)->_xcoff_ldrelsz))
  114. #define bfd_xcoff_function_descriptor_size(a) \
  115. ((xcoff_backend (a)->_xcoff_function_descriptor_size))
  116. #define bfd_xcoff_small_aout_header_size(a) \
  117. ((xcoff_backend (a)->_xcoff_small_aout_header_size))
  118. #define bfd_xcoff_ldhdr_version(a) ((xcoff_backend (a)->_xcoff_ldhdr_version))
  119. #define bfd_xcoff_put_symbol_name(a, b, c, d, e) \
  120. ((xcoff_backend (a)->_xcoff_put_symbol_name) ((b), (c), (d), (e)))
  121. #define bfd_xcoff_put_ldsymbol_name(a, b, c, d) \
  122. ((xcoff_backend (a)->_xcoff_put_ldsymbol_name) ((a), (b), (c), (d)))
  123. /* Get the XCOFF hash table entries for a BFD. */
  124. #define obj_xcoff_sym_hashes(bfd) \
  125. ((struct xcoff_link_hash_entry **) obj_coff_sym_hashes (bfd))
  126. #define bfd_xcoff_dynamic_reloc_howto(a) \
  127. ((xcoff_backend (a)->_xcoff_dynamic_reloc))
  128. #define bfd_xcoff_create_csect_from_smclas(a, b, c) \
  129. ((xcoff_backend (a)->_xcoff_create_csect_from_smclas((a), (b), (c))))
  130. #define bfd_xcoff_is_lineno_count_overflow(a, b) \
  131. ((xcoff_backend (a)->_xcoff_is_lineno_count_overflow((a), (b))))
  132. #define bfd_xcoff_is_reloc_count_overflow(a, b) \
  133. ((xcoff_backend (a)->_xcoff_is_reloc_count_overflow((a), (b))))
  134. #define bfd_xcoff_loader_symbol_offset(a, b) \
  135. ((xcoff_backend (a)->_xcoff_loader_symbol_offset((a), (b))))
  136. #define bfd_xcoff_loader_reloc_offset(a, b) \
  137. ((xcoff_backend (a)->_xcoff_loader_reloc_offset((a), (b))))
  138. #define bfd_xcoff_glink_code(a, b) ((xcoff_backend (a)->_xcoff_glink_code[(b)]))
  139. #define bfd_xcoff_glink_code_size(a) ((xcoff_backend (a)->_xcoff_glink_size))
  140. /* Check for the magic number U803XTOCMAGIC or U64_TOCMAGIC for 64 bit
  141. targets. */
  142. #define bfd_xcoff_is_xcoff64(a) \
  143. ( (0x01EF == (bfd_xcoff_magic_number (a))) \
  144. || (0x01F7 == (bfd_xcoff_magic_number (a))))
  145. /* Check for the magic number U802TOMAGIC for 32 bit targets. */
  146. #define bfd_xcoff_is_xcoff32(a) (0x01DF == (bfd_xcoff_magic_number (a)))
  147. #define bfd_xcoff_rtinit_size(a) ((xcoff_backend (a)->_xcoff_rtinit_size))
  148. #define bfd_xcoff_generate_rtinit(a, b, c, d) ((xcoff_backend (a)->_xcoff_generate_rtinit ((a), (b), (c), (d))))
  149. /* Accessor macros for tdata. */
  150. #define bfd_xcoff_text_align_power(a) ((xcoff_data (a)->text_align_power))
  151. #define bfd_xcoff_data_align_power(a) ((xcoff_data (a)->data_align_power))
  152. /* xcoff*_ppc_relocate_section macros */
  153. #define XCOFF_MAX_CALCULATE_RELOCATION (0x32)
  154. #define XCOFF_MAX_COMPLAIN_OVERFLOW (4)
  155. /* N_ONES produces N one bits, without overflowing machine arithmetic. */
  156. #ifdef N_ONES
  157. #undef N_ONES
  158. #endif
  159. #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
  160. typedef bool xcoff_reloc_function (bfd *, asection *, bfd *,
  161. struct internal_reloc *,
  162. struct internal_syment *,
  163. struct reloc_howto_struct *,
  164. bfd_vma, bfd_vma,
  165. bfd_vma *, bfd_byte *);
  166. typedef bool xcoff_complain_function (bfd *, bfd_vma, bfd_vma,
  167. struct reloc_howto_struct *);
  168. extern xcoff_reloc_function *const xcoff_calculate_relocation[];
  169. extern xcoff_complain_function *const xcoff_complain_overflow[];
  170. #define XCOFF_NO_LONG_SECTION_NAMES (false), bfd_coff_set_long_section_names_disallowed
  171. /* Relocation functions */
  172. extern xcoff_reloc_function xcoff_reloc_type_noop;
  173. extern xcoff_reloc_function xcoff_reloc_type_fail;
  174. extern xcoff_reloc_function xcoff_reloc_type_pos;
  175. extern xcoff_reloc_function xcoff_reloc_type_neg;
  176. extern xcoff_reloc_function xcoff_reloc_type_rel;
  177. extern xcoff_reloc_function xcoff_reloc_type_toc;
  178. extern xcoff_reloc_function xcoff_reloc_type_ba;
  179. extern xcoff_reloc_function xcoff_reloc_type_crel;
  180. extern xcoff_reloc_function xcoff_reloc_type_tls;
  181. /* Structure to describe dwarf sections.
  182. Useful to convert from XCOFF section name to flag and vice-versa.
  183. Also mark if section has a length field at the beginning. */
  184. struct xcoff_dwsect_name {
  185. /* A XCOFF dwarf section is identified by its name. */
  186. unsigned int flag;
  187. /* Corresponding XCOFF section name. */
  188. const char *xcoff_name;
  189. /* Corresponding DWARF section name. */
  190. const char *dwarf_name;
  191. /* True if size must be prepended. */
  192. bool def_size;
  193. };
  194. /* Number of entries in the array. The number is known and public so that user
  195. can 'extend' this array by index. */
  196. #define XCOFF_DWSECT_NBR_NAMES 11
  197. /* The dwarf sections array. */
  198. extern const struct xcoff_dwsect_name
  199. xcoff_dwsect_names[XCOFF_DWSECT_NBR_NAMES];
  200. #endif /* LIBXCOFF_H */