1 /* BFD XCOFF object file private structure.
2 Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 Written by Tom Rix, Redhat.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
25 /* This is the backend information kept for XCOFF files. This
26 structure is constant for a particular backend. The first element
27 is the COFF backend data structure, so that XCOFF targets can use
28 the generic COFF code. */
30 struct xcoff_backend_data_rec
32 /* COFF backend information. */
33 bfd_coff_backend_data coff
;
36 unsigned short _xcoff_magic_number
;
38 /* Architecture and machine for coff_set_arch_mach_hook. */
39 enum bfd_architecture _xcoff_architecture
;
42 /* Function pointers to xcoff specific swap routines. */
43 void (* _xcoff_swap_ldhdr_in
) (bfd
*, const void *, struct internal_ldhdr
*);
44 void (* _xcoff_swap_ldhdr_out
)(bfd
*, const struct internal_ldhdr
*, void *);
45 void (* _xcoff_swap_ldsym_in
) (bfd
*, const void *, struct internal_ldsym
*);
46 void (* _xcoff_swap_ldsym_out
)(bfd
*, const struct internal_ldsym
*, void *);
47 void (* _xcoff_swap_ldrel_in
) (bfd
*, const void *, struct internal_ldrel
*);
48 void (* _xcoff_swap_ldrel_out
)(bfd
*, const struct internal_ldrel
*, void *);
50 /* Size of the external struct. */
51 unsigned int _xcoff_ldhdrsz
;
52 unsigned int _xcoff_ldsymsz
;
53 unsigned int _xcoff_ldrelsz
;
55 /* Size an entry in a descriptor section. */
56 unsigned int _xcoff_function_descriptor_size
;
58 /* Size of the small aout file header. */
59 unsigned int _xcoff_small_aout_header_size
;
64 unsigned long _xcoff_ldhdr_version
;
66 bool (* _xcoff_put_symbol_name
)
67 (struct bfd_link_info
*, struct bfd_strtab_hash
*,
68 struct internal_syment
*, const char *);
70 bool (* _xcoff_put_ldsymbol_name
)
71 (bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
74 reloc_howto_type
*_xcoff_dynamic_reloc
;
76 asection
* (* _xcoff_create_csect_from_smclas
)
77 (bfd
*, union internal_auxent
*, const char *);
79 /* Line number and relocation overflow.
80 XCOFF32 overflows to another section when the line number or the
81 relocation count exceeds 0xffff. XCOFF64 does not overflow. */
82 bool (*_xcoff_is_lineno_count_overflow
) (bfd
*, bfd_vma
);
83 bool (*_xcoff_is_reloc_count_overflow
) (bfd
*, bfd_vma
);
85 /* Loader section symbol and relocation table offset
86 XCOFF32 is after the .loader header
87 XCOFF64 is offset in .loader header. */
88 bfd_vma (*_xcoff_loader_symbol_offset
) (bfd
*, struct internal_ldhdr
*);
89 bfd_vma (*_xcoff_loader_reloc_offset
) (bfd
*, struct internal_ldhdr
*);
91 /* Global linkage. The first word of global linkage code must be be
92 modified by filling in the correct TOC offset. */
93 const unsigned long *_xcoff_glink_code
;
95 /* Size of the global link code in bytes of the xcoff_glink_code table. */
96 unsigned long _xcoff_glink_size
;
99 unsigned int _xcoff_rtinit_size
;
100 bool (*_xcoff_generate_rtinit
)
101 (bfd
*, const char *, const char *, bool);
103 /* Stubs code generation.
104 The code part is an array which might need to be modified by
106 The size is in bytes. */
107 const unsigned long *_xcoff_stub_indirect_call_code
;
108 unsigned long _xcoff_stub_indirect_call_size
;
109 const unsigned long *_xcoff_stub_shared_call_code
;
110 unsigned long _xcoff_stub_shared_call_size
;
113 /* Look up an entry in an XCOFF link hash table. */
114 #define xcoff_link_hash_lookup(table, string, create, copy, follow) \
115 ((struct xcoff_link_hash_entry *) \
116 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy),\
119 /* Traverse an XCOFF link hash table. */
120 #define xcoff_link_hash_traverse(table, func, info) \
121 (bfd_link_hash_traverse \
123 (bool (*) (struct bfd_link_hash_entry *, void *)) (func), \
126 /* Get the XCOFF link hash table from the info structure. This is
128 #define xcoff_hash_table(p) ((struct xcoff_link_hash_table *) ((p)->hash))
131 #define xcoff_backend(abfd) \
132 ((struct xcoff_backend_data_rec *) (abfd)->xvec->backend_data)
134 #define bfd_xcoff_magic_number(a) ((xcoff_backend (a)->_xcoff_magic_number))
135 #define bfd_xcoff_architecture(a) ((xcoff_backend (a)->_xcoff_architecture))
136 #define bfd_xcoff_machine(a) ((xcoff_backend (a)->_xcoff_machine))
138 #define bfd_xcoff_swap_ldhdr_in(a, b, c) \
139 ((xcoff_backend (a)->_xcoff_swap_ldhdr_in) ((a), (b), (c)))
141 #define bfd_xcoff_swap_ldhdr_out(a, b, c) \
142 ((xcoff_backend (a)->_xcoff_swap_ldhdr_out) ((a), (b), (c)))
144 #define bfd_xcoff_swap_ldsym_in(a, b, c) \
145 ((xcoff_backend (a)->_xcoff_swap_ldsym_in) ((a), (b), (c)))
147 #define bfd_xcoff_swap_ldsym_out(a, b, c) \
148 ((xcoff_backend (a)->_xcoff_swap_ldsym_out) ((a), (b), (c)))
150 #define bfd_xcoff_swap_ldrel_in(a, b, c) \
151 ((xcoff_backend (a)->_xcoff_swap_ldrel_in) ((a), (b), (c)))
153 #define bfd_xcoff_swap_ldrel_out(a, b, c) \
154 ((xcoff_backend (a)->_xcoff_swap_ldrel_out) ((a), (b), (c)))
156 #define bfd_xcoff_ldhdrsz(a) ((xcoff_backend (a)->_xcoff_ldhdrsz))
157 #define bfd_xcoff_ldsymsz(a) ((xcoff_backend (a)->_xcoff_ldsymsz))
158 #define bfd_xcoff_ldrelsz(a) ((xcoff_backend (a)->_xcoff_ldrelsz))
159 #define bfd_xcoff_function_descriptor_size(a) \
160 ((xcoff_backend (a)->_xcoff_function_descriptor_size))
161 #define bfd_xcoff_small_aout_header_size(a) \
162 ((xcoff_backend (a)->_xcoff_small_aout_header_size))
164 #define bfd_xcoff_ldhdr_version(a) ((xcoff_backend (a)->_xcoff_ldhdr_version))
166 #define bfd_xcoff_put_symbol_name(a, b, c, d, e) \
167 ((xcoff_backend (a)->_xcoff_put_symbol_name) ((b), (c), (d), (e)))
169 #define bfd_xcoff_put_ldsymbol_name(a, b, c, d) \
170 ((xcoff_backend (a)->_xcoff_put_ldsymbol_name) ((a), (b), (c), (d)))
172 /* Get the XCOFF hash table entries for a BFD. */
173 #define obj_xcoff_sym_hashes(bfd) \
174 ((struct xcoff_link_hash_entry **) obj_coff_sym_hashes (bfd))
176 #define bfd_xcoff_dynamic_reloc_howto(a) \
177 ((xcoff_backend (a)->_xcoff_dynamic_reloc))
179 #define bfd_xcoff_create_csect_from_smclas(a, b, c) \
180 ((xcoff_backend (a)->_xcoff_create_csect_from_smclas((a), (b), (c))))
182 #define bfd_xcoff_is_lineno_count_overflow(a, b) \
183 ((xcoff_backend (a)->_xcoff_is_lineno_count_overflow((a), (b))))
185 #define bfd_xcoff_is_reloc_count_overflow(a, b) \
186 ((xcoff_backend (a)->_xcoff_is_reloc_count_overflow((a), (b))))
188 #define bfd_xcoff_loader_symbol_offset(a, b) \
189 ((xcoff_backend (a)->_xcoff_loader_symbol_offset((a), (b))))
191 #define bfd_xcoff_loader_reloc_offset(a, b) \
192 ((xcoff_backend (a)->_xcoff_loader_reloc_offset((a), (b))))
194 #define bfd_xcoff_glink_code(a, b) ((xcoff_backend (a)->_xcoff_glink_code[(b)]))
195 #define bfd_xcoff_glink_code_size(a) ((xcoff_backend (a)->_xcoff_glink_size))
197 #define bfd_xcoff_stub_indirect_call_code(a, b) ((xcoff_backend (a)->_xcoff_stub_indirect_call_code[(b)]))
198 #define bfd_xcoff_stub_indirect_call_size(a) ((xcoff_backend (a)->_xcoff_stub_indirect_call_size))
199 #define bfd_xcoff_stub_shared_call_code(a, b) ((xcoff_backend (a)->_xcoff_stub_shared_call_code[(b)]))
200 #define bfd_xcoff_stub_shared_call_size(a) ((xcoff_backend (a)->_xcoff_stub_shared_call_size))
202 /* Check for the magic number U803XTOCMAGIC or U64_TOCMAGIC for 64 bit
204 #define bfd_xcoff_is_xcoff64(a) \
205 ( (0x01EF == (bfd_xcoff_magic_number (a))) \
206 || (0x01F7 == (bfd_xcoff_magic_number (a))))
208 /* Check for the magic number U802TOMAGIC for 32 bit targets. */
209 #define bfd_xcoff_is_xcoff32(a) (0x01DF == (bfd_xcoff_magic_number (a)))
211 #define bfd_xcoff_rtinit_size(a) ((xcoff_backend (a)->_xcoff_rtinit_size))
212 #define bfd_xcoff_generate_rtinit(a, b, c, d) ((xcoff_backend (a)->_xcoff_generate_rtinit ((a), (b), (c), (d))))
214 /* Accessor macros for tdata. */
215 #define bfd_xcoff_text_align_power(a) ((xcoff_data (a)->text_align_power))
216 #define bfd_xcoff_data_align_power(a) ((xcoff_data (a)->data_align_power))
218 /* xcoff*_ppc_relocate_section macros */
219 #define XCOFF_MAX_CALCULATE_RELOCATION (0x32)
220 #define XCOFF_MAX_COMPLAIN_OVERFLOW (4)
221 /* N_ONES produces N one bits, without overflowing machine arithmetic. */
225 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
227 typedef bool xcoff_reloc_function (bfd
*, asection
*, bfd
*,
228 struct internal_reloc
*,
229 struct internal_syment
*,
230 struct reloc_howto_struct
*,
232 bfd_vma
*, bfd_byte
*,
233 struct bfd_link_info
*);
235 typedef bool xcoff_complain_function (bfd
*, bfd_vma
, bfd_vma
,
236 struct reloc_howto_struct
*);
238 extern xcoff_reloc_function
*const xcoff_calculate_relocation
[];
239 extern xcoff_complain_function
*const xcoff_complain_overflow
[];
241 #define XCOFF_NO_LONG_SECTION_NAMES (false), bfd_coff_set_long_section_names_disallowed
243 /* Relocation functions */
244 extern xcoff_reloc_function xcoff_reloc_type_noop
;
245 extern xcoff_reloc_function xcoff_reloc_type_fail
;
246 extern xcoff_reloc_function xcoff_reloc_type_pos
;
247 extern xcoff_reloc_function xcoff_reloc_type_neg
;
248 extern xcoff_reloc_function xcoff_reloc_type_rel
;
249 extern xcoff_reloc_function xcoff_reloc_type_toc
;
250 extern xcoff_reloc_function xcoff_reloc_type_ba
;
251 extern xcoff_reloc_function xcoff_reloc_type_crel
;
252 extern xcoff_reloc_function xcoff_reloc_type_tls
;
254 /* Structure to describe dwarf sections.
255 Useful to convert from XCOFF section name to flag and vice-versa.
256 Also mark if section has a length field at the beginning. */
257 struct xcoff_dwsect_name
{
258 /* A XCOFF dwarf section is identified by its name. */
261 /* Corresponding XCOFF section name. */
262 const char *xcoff_name
;
264 /* Corresponding DWARF section name. */
265 const char *dwarf_name
;
267 /* True if size must be prepended. */
271 /* Number of entries in the array. The number is known and public so that user
272 can 'extend' this array by index. */
273 #define XCOFF_DWSECT_NBR_NAMES 11
275 /* The dwarf sections array. */
276 extern const struct xcoff_dwsect_name
277 xcoff_dwsect_names
[XCOFF_DWSECT_NBR_NAMES
];
279 /* Structure and functions needed by backend in order to handle
280 stubs created in xcofflink.c. */
285 xcoff_stub_indirect_call
,
286 xcoff_stub_shared_call
289 struct xcoff_stub_hash_entry
291 /* Base hash table entry structure. */
292 struct bfd_hash_entry root
;
294 enum xcoff_stub_type stub_type
;
296 /* The hash table entry of the stub's csect. */
297 struct xcoff_link_hash_entry
*hcsect
;
299 /* Offset in the stub's csect. */
302 /* The target's section. */
303 asection
*target_section
;
305 /* The target's hash table entry. */
306 struct xcoff_link_hash_entry
*htarget
;
310 extern enum xcoff_stub_type bfd_xcoff_type_of_stub
311 (asection
*, const struct internal_reloc
*, bfd_vma
,
312 struct xcoff_link_hash_entry
*);
314 extern struct xcoff_stub_hash_entry
*bfd_xcoff_get_stub_entry
315 (asection
*, struct xcoff_link_hash_entry
*, struct bfd_link_info
*);
317 #endif /* LIBXCOFF_H */