libecoff.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* BFD ECOFF object file private structure.
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor, Cygnus Support.
  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. #include "bfdlink.h"
  18. #ifndef ECOFF_H
  19. #include "coff/ecoff.h"
  20. #endif
  21. /* This is the backend information kept for ECOFF files. This
  22. structure is constant for a particular backend. The first element
  23. is the COFF backend data structure, so that ECOFF targets can use
  24. the generic COFF code. */
  25. #define ecoff_backend(abfd) \
  26. ((struct ecoff_backend_data *) (abfd)->xvec->backend_data)
  27. struct ecoff_backend_data
  28. {
  29. /* COFF backend information. This must be the first field. */
  30. bfd_coff_backend_data coff;
  31. /* Supported architecture. */
  32. enum bfd_architecture arch;
  33. /* Initial portion of armap string. */
  34. const char *armap_start;
  35. /* The page boundary used to align sections in a demand-paged
  36. executable file. E.g., 0x1000. */
  37. bfd_vma round;
  38. /* TRUE if the .rdata section is part of the text segment, as on the
  39. Alpha. FALSE if .rdata is part of the data segment, as on the
  40. MIPS. */
  41. bool rdata_in_text;
  42. /* Bitsize of constructor entries. */
  43. unsigned int constructor_bitsize;
  44. /* Reloc to use for constructor entries. */
  45. reloc_howto_type *constructor_reloc;
  46. /* How to swap debugging information. */
  47. struct ecoff_debug_swap debug_swap;
  48. /* External reloc size. */
  49. bfd_size_type external_reloc_size;
  50. /* Reloc swapping functions. */
  51. void (*swap_reloc_in) (bfd *, void *, struct internal_reloc *);
  52. void (*swap_reloc_out) (bfd *, const struct internal_reloc *, void *);
  53. /* Backend reloc tweaking. */
  54. void (*adjust_reloc_in)
  55. (bfd *, const struct internal_reloc *, arelent *);
  56. void (*adjust_reloc_out)
  57. (bfd *, const arelent *, struct internal_reloc *);
  58. /* Relocate section contents while linking. */
  59. bool (*relocate_section)
  60. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, void *);
  61. /* Do final adjustments to filehdr and aouthdr. */
  62. bool (*adjust_headers)
  63. (bfd *, struct internal_filehdr *, struct internal_aouthdr *);
  64. /* Read an element from an archive at a given file position. This
  65. is needed because OSF/1 3.2 uses a weird archive format. */
  66. bfd *(*get_elt_at_filepos) (bfd *, file_ptr, struct bfd_link_info *);
  67. };
  68. /* ECOFF targets don't support COFF long section names, so this
  69. macro is provided to use as an initialiser for the related
  70. members of the embedded bfd_coff_backend_data struct. */
  71. #define ECOFF_NO_LONG_SECTION_NAMES (false), _bfd_ecoff_no_long_sections
  72. /* This is the target specific information kept for ECOFF files. */
  73. #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
  74. typedef struct ecoff_tdata
  75. {
  76. /* The reloc file position, set by
  77. ecoff_compute_section_file_positions. */
  78. file_ptr reloc_filepos;
  79. /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */
  80. file_ptr sym_filepos;
  81. /* The start and end of the text segment. Only valid for an
  82. existing file, not for one we are creating. */
  83. unsigned long text_start;
  84. unsigned long text_end;
  85. /* The cached gp value. This is used when relocating. */
  86. bfd_vma gp;
  87. /* The maximum size of objects to optimize using gp. This is
  88. typically set by the -G option to the compiler, assembler or
  89. linker. */
  90. unsigned int gp_size;
  91. /* The register masks. When linking, all the masks found in the
  92. input files are combined into the masks of the output file.
  93. These are not all used for all targets, but that's OK, because
  94. the relevant ones are the only ones swapped in and out. */
  95. unsigned long gprmask;
  96. unsigned long fprmask;
  97. unsigned long cprmask[4];
  98. /* The ECOFF symbolic debugging information. */
  99. struct ecoff_debug_info debug_info;
  100. /* The unswapped ECOFF symbolic information. */
  101. void * raw_syments;
  102. /* The canonical BFD symbols. */
  103. struct ecoff_symbol_struct *canonical_symbols;
  104. /* A mapping from external symbol numbers to entries in the linker
  105. hash table, used when linking. */
  106. struct ecoff_link_hash_entry **sym_hashes;
  107. /* A mapping from reloc symbol indices to sections, used when
  108. linking. */
  109. asection **symndx_to_section;
  110. /* TRUE if this BFD was written by the backend linker. */
  111. bool linker;
  112. /* TRUE if a warning that multiple global pointer values are
  113. needed in the output binary was issued already. */
  114. bool issued_multiple_gp_warning;
  115. /* Used by find_nearest_line entry point. The structure could be
  116. included directly in this one, but there's no point to wasting
  117. the memory just for the infrequently called find_nearest_line. */
  118. struct ecoff_find_line *find_line_info;
  119. /* Whether the .rdata section is in the text segment for this
  120. particular ECOFF file. This is not valid until
  121. ecoff_compute_section_file_positions is called. */
  122. bool rdata_in_text;
  123. } ecoff_data_type;
  124. /* Each canonical asymbol really looks like this. */
  125. typedef struct ecoff_symbol_struct
  126. {
  127. /* The actual symbol which the rest of BFD works with */
  128. asymbol symbol;
  129. /* The fdr for this symbol. */
  130. FDR *fdr;
  131. /* TRUE if this is a local symbol rather than an external one. */
  132. bool local;
  133. /* A pointer to the unswapped hidden information for this symbol.
  134. This is either a struct sym_ext or a struct ext_ext, depending on
  135. the value of the local field above. */
  136. void * native;
  137. } ecoff_symbol_type;
  138. /* We take the address of the first element of an asymbol to ensure that the
  139. macro is only ever applied to an asymbol. */
  140. #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
  141. /* We need to save the index of an external symbol when we write it
  142. out so that can set the symbol index correctly when we write out
  143. the relocs. */
  144. #define ecoff_get_sym_index(symbol) ((symbol)->udata.i)
  145. #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx))
  146. /* A pointer to this structure is put in the used_by_bfd pointer of
  147. a section to keep track of any per-section data.
  148. The user_by_bfd pointer will be NULL if the information was not
  149. needed. */
  150. struct ecoff_section_tdata
  151. {
  152. /* When producing an executable (i.e., final, non-relocatable link)
  153. on the Alpha, we may need to use multiple global pointer values
  154. to span the entire .lita section. In essence, we allow each
  155. input .lita section to have its own gp value. To support this,
  156. we need to keep track of the gp values that we picked for each
  157. input .lita section . */
  158. bfd_vma gp;
  159. };
  160. /* An accessor macro for the ecoff_section_tdata structure. */
  161. #define ecoff_section_data(abfd, sec) \
  162. ((struct ecoff_section_tdata *) (sec)->used_by_bfd)
  163. /* ECOFF linker hash table entries. */
  164. struct ecoff_link_hash_entry
  165. {
  166. struct bfd_link_hash_entry root;
  167. /* Symbol index in output file. */
  168. long indx;
  169. /* BFD that ext field value came from. */
  170. bfd *abfd;
  171. /* ECOFF external symbol information. */
  172. EXTR esym;
  173. /* Nonzero if this symbol has been written out. */
  174. char written;
  175. /* Nonzero if this symbol was referred to as small undefined. */
  176. char small;
  177. };
  178. /* ECOFF linker hash table. */
  179. struct ecoff_link_hash_table
  180. {
  181. struct bfd_link_hash_table root;
  182. };
  183. /* Make an ECOFF object. */
  184. extern bool _bfd_ecoff_mkobject (bfd *);
  185. /* Read in the ECOFF symbolic debugging information. */
  186. extern bool _bfd_ecoff_slurp_symbolic_info
  187. (bfd *, asection *, struct ecoff_debug_info *);
  188. /* Generic ECOFF BFD backend vectors. */
  189. extern bool _bfd_ecoff_write_object_contents (bfd *);
  190. #define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup
  191. #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  192. extern bool _bfd_ecoff_new_section_hook
  193. (bfd *, asection *);
  194. extern bool _bfd_ecoff_get_section_contents
  195. (bfd *, asection *, void * location, file_ptr, bfd_size_type);
  196. #define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section
  197. #define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
  198. extern bool _bfd_ecoff_bfd_copy_private_bfd_data
  199. (bfd *, bfd *);
  200. #define _bfd_ecoff_bfd_copy_private_section_data \
  201. _bfd_generic_bfd_copy_private_section_data
  202. #define _bfd_ecoff_bfd_copy_private_symbol_data \
  203. _bfd_generic_bfd_copy_private_symbol_data
  204. #define _bfd_ecoff_bfd_copy_private_header_data \
  205. _bfd_generic_bfd_copy_private_header_data
  206. #define _bfd_ecoff_bfd_print_private_bfd_data \
  207. _bfd_generic_bfd_print_private_bfd_data
  208. #define _bfd_ecoff_bfd_merge_private_bfd_data \
  209. _bfd_generic_bfd_merge_private_bfd_data
  210. #define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
  211. extern bool _bfd_ecoff_slurp_armap (bfd *);
  212. #define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
  213. #define _bfd_ecoff_construct_extended_name_table \
  214. _bfd_archive_bsd_construct_extended_name_table
  215. #define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname
  216. extern bool _bfd_ecoff_write_armap
  217. (bfd *, unsigned int, struct orl *, unsigned int, int);
  218. #define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr
  219. #define _bfd_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr
  220. #define _bfd_ecoff_openr_next_archived_file \
  221. bfd_generic_openr_next_archived_file
  222. #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index
  223. #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
  224. #define _bfd_ecoff_update_armap_timestamp _bfd_bool_bfd_true
  225. #define _bfd_ecoff_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
  226. extern long _bfd_ecoff_get_symtab_upper_bound (bfd *);
  227. extern long _bfd_ecoff_canonicalize_symtab (bfd *, asymbol **);
  228. extern asymbol *_bfd_ecoff_make_empty_symbol (bfd *);
  229. extern void _bfd_ecoff_print_symbol
  230. (bfd *, void *, asymbol *, bfd_print_symbol_type);
  231. extern void _bfd_ecoff_get_symbol_info
  232. (bfd *, asymbol *, symbol_info *);
  233. #define _bfd_ecoff_get_symbol_version_string \
  234. _bfd_nosymbols_get_symbol_version_string
  235. extern bool _bfd_ecoff_bfd_is_local_label_name
  236. (bfd *, const char *);
  237. #define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno
  238. extern bool _bfd_ecoff_find_nearest_line
  239. (bfd *, asymbol **, asection *, bfd_vma,
  240. const char **, const char **, unsigned int *, unsigned int *);
  241. #define _bfd_ecoff_find_line _bfd_nosymbols_find_line
  242. #define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  243. #define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols
  244. #define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
  245. #define _bfd_ecoff_find_inliner_info _bfd_nosymbols_find_inliner_info
  246. #define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
  247. extern long _bfd_ecoff_canonicalize_reloc
  248. (bfd *, asection *, arelent **, asymbol **);
  249. /* ecoff_bfd_reloc_type_lookup defined by backend. */
  250. extern bool _bfd_ecoff_set_arch_mach
  251. (bfd *, enum bfd_architecture, unsigned long);
  252. extern bool _bfd_ecoff_set_section_contents
  253. (bfd *, asection *, const void * location, file_ptr, bfd_size_type);
  254. extern int _bfd_ecoff_sizeof_headers (bfd *, struct bfd_link_info *);
  255. /* ecoff_bfd_get_relocated_section_contents defined by backend. */
  256. /* ecoff_bfd_relax_section defined by backend. */
  257. extern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create
  258. (bfd *);
  259. extern bool _bfd_ecoff_bfd_link_add_symbols
  260. (bfd *, struct bfd_link_info *);
  261. #define _bfd_ecoff_bfd_link_just_syms _bfd_generic_link_just_syms
  262. #define _bfd_ecoff_bfd_copy_link_hash_symbol_type \
  263. _bfd_generic_copy_link_hash_symbol_type
  264. extern bool _bfd_ecoff_bfd_final_link
  265. (bfd *, struct bfd_link_info *);
  266. /* Hook functions for the generic COFF section reading code. */
  267. extern void * _bfd_ecoff_mkobject_hook (bfd *, void *, void *);
  268. extern void _bfd_ecoff_set_alignment_hook
  269. (bfd *, asection *, void *);
  270. extern bool _bfd_ecoff_set_arch_mach_hook
  271. (bfd *, void *);
  272. extern bool _bfd_ecoff_no_long_sections
  273. (bfd *abfd, int enable);
  274. extern bool _bfd_ecoff_styp_to_sec_flags
  275. (bfd *, void *, const char *, asection *, flagword *);
  276. extern bool _bfd_ecoff_slurp_symbol_table (bfd *);
  277. /* ECOFF auxiliary information swapping routines. These are the same
  278. for all ECOFF targets, so they are defined in ecofflink.c. */
  279. extern void _bfd_ecoff_swap_tir_in
  280. (int, const struct tir_ext *, TIR *);
  281. extern void _bfd_ecoff_swap_tir_out
  282. (int, const TIR *, struct tir_ext *);
  283. extern void _bfd_ecoff_swap_rndx_in
  284. (int, const struct rndx_ext *, RNDXR *);
  285. extern void _bfd_ecoff_swap_rndx_out
  286. (int, const RNDXR *, struct rndx_ext *);