Do not create $(bfdlibdir) and $(bfdincludedir) if !INSTALL_LIBBFD.
[binutils.git] / bfd / coff-rs6000.c
blobd1931538c145cb7a1ad9bb877d7fd8d745b119e8
1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 Free Software Foundation, Inc.
4 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
5 Archive support from Damon A. Permezel.
6 Contributed by IBM Corporation and Cygnus Support.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
25 #include "sysdep.h"
26 #include "bfd.h"
27 #include "bfdlink.h"
28 #include "libbfd.h"
29 #include "coff/internal.h"
30 #include "coff/xcoff.h"
31 #include "coff/rs6000.h"
32 #include "libcoff.h"
33 #include "libxcoff.h"
35 extern bfd_boolean _bfd_xcoff_mkobject
36 PARAMS ((bfd *));
37 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
38 PARAMS ((bfd *, bfd *));
39 extern bfd_boolean _bfd_xcoff_is_local_label_name
40 PARAMS ((bfd *, const char *));
41 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
42 PARAMS ((bfd *, bfd_reloc_code_real_type));
43 extern bfd_boolean _bfd_xcoff_slurp_armap
44 PARAMS ((bfd *));
45 extern const bfd_target *_bfd_xcoff_archive_p
46 PARAMS ((bfd *));
47 extern PTR _bfd_xcoff_read_ar_hdr
48 PARAMS ((bfd *));
49 extern bfd *_bfd_xcoff_openr_next_archived_file
50 PARAMS ((bfd *, bfd *));
51 extern int _bfd_xcoff_stat_arch_elt
52 PARAMS ((bfd *, struct stat *));
53 extern bfd_boolean _bfd_xcoff_write_armap
54 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
55 extern bfd_boolean _bfd_xcoff_write_archive_contents
56 PARAMS ((bfd *));
57 extern int _bfd_xcoff_sizeof_headers
58 PARAMS ((bfd *, struct bfd_link_info *));
59 extern void _bfd_xcoff_swap_sym_in
60 PARAMS ((bfd *, PTR, PTR));
61 extern unsigned int _bfd_xcoff_swap_sym_out
62 PARAMS ((bfd *, PTR, PTR));
63 extern void _bfd_xcoff_swap_aux_in
64 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
65 extern unsigned int _bfd_xcoff_swap_aux_out
66 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
67 static void xcoff_swap_reloc_in
68 PARAMS ((bfd *, PTR, PTR));
69 static unsigned int xcoff_swap_reloc_out
70 PARAMS ((bfd *, PTR, PTR));
72 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
73 void xcoff_rtype2howto
74 PARAMS ((arelent *, struct internal_reloc *));
76 /* coffcode.h needs these to be defined. */
77 #define RS6000COFF_C 1
79 #define SELECT_RELOC(internal, howto) \
80 { \
81 internal.r_type = howto->type; \
82 internal.r_size = \
83 ((howto->complain_on_overflow == complain_overflow_signed \
84 ? 0x80 \
85 : 0) \
86 | (howto->bitsize - 1)); \
89 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
90 #define COFF_LONG_FILENAMES
91 #define NO_COFF_SYMBOLS
92 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
93 #define coff_mkobject _bfd_xcoff_mkobject
94 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
95 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
96 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
97 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
98 #ifdef AIX_CORE
99 extern const bfd_target * rs6000coff_core_p
100 PARAMS ((bfd *abfd));
101 extern bfd_boolean rs6000coff_core_file_matches_executable_p
102 PARAMS ((bfd *cbfd, bfd *ebfd));
103 extern char *rs6000coff_core_file_failing_command
104 PARAMS ((bfd *abfd));
105 extern int rs6000coff_core_file_failing_signal
106 PARAMS ((bfd *abfd));
107 #define CORE_FILE_P rs6000coff_core_p
108 #define coff_core_file_failing_command \
109 rs6000coff_core_file_failing_command
110 #define coff_core_file_failing_signal \
111 rs6000coff_core_file_failing_signal
112 #define coff_core_file_matches_executable_p \
113 rs6000coff_core_file_matches_executable_p
114 #else
115 #define CORE_FILE_P _bfd_dummy_target
116 #define coff_core_file_failing_command \
117 _bfd_nocore_core_file_failing_command
118 #define coff_core_file_failing_signal \
119 _bfd_nocore_core_file_failing_signal
120 #define coff_core_file_matches_executable_p \
121 _bfd_nocore_core_file_matches_executable_p
122 #endif
123 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
124 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
125 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
126 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
127 #define coff_swap_reloc_in xcoff_swap_reloc_in
128 #define coff_swap_reloc_out xcoff_swap_reloc_out
129 #define NO_COFF_RELOCS
131 #ifndef bfd_pe_print_pdata
132 #define bfd_pe_print_pdata NULL
133 #endif
135 #include "coffcode.h"
137 /* The main body of code is in coffcode.h. */
139 static const char *normalize_filename
140 PARAMS ((bfd *));
141 static bfd_boolean xcoff_write_armap_old
142 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
143 static bfd_boolean xcoff_write_armap_big
144 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
145 static bfd_boolean xcoff_write_archive_contents_old
146 PARAMS ((bfd *));
147 static bfd_boolean xcoff_write_archive_contents_big
148 PARAMS ((bfd *));
149 static void xcoff_swap_ldhdr_in
150 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
151 static void xcoff_swap_ldhdr_out
152 PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
153 static void xcoff_swap_ldsym_in
154 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
155 static void xcoff_swap_ldsym_out
156 PARAMS ((bfd *, const struct internal_ldsym *, PTR));
157 static void xcoff_swap_ldrel_in
158 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
159 static void xcoff_swap_ldrel_out
160 PARAMS ((bfd *, const struct internal_ldrel *, PTR));
161 static bfd_boolean xcoff_ppc_relocate_section
162 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
163 struct internal_reloc *, struct internal_syment *, asection **));
164 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
165 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
166 const char *));
167 static asection *xcoff_create_csect_from_smclas
168 PARAMS ((bfd *, union internal_auxent *, const char *));
169 static bfd_boolean xcoff_is_lineno_count_overflow
170 PARAMS ((bfd *, bfd_vma));
171 static bfd_boolean xcoff_is_reloc_count_overflow
172 PARAMS ((bfd *, bfd_vma));
173 static bfd_vma xcoff_loader_symbol_offset
174 PARAMS ((bfd *, struct internal_ldhdr *));
175 static bfd_vma xcoff_loader_reloc_offset
176 PARAMS ((bfd *, struct internal_ldhdr *));
177 static bfd_boolean xcoff_generate_rtinit
178 PARAMS ((bfd *, const char *, const char *, bfd_boolean));
179 static bfd_boolean do_pad
180 PARAMS ((bfd *, unsigned int));
181 static bfd_boolean do_copy
182 PARAMS ((bfd *, bfd *));
184 /* Relocation functions */
185 static bfd_boolean xcoff_reloc_type_br
186 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
188 static bfd_boolean xcoff_complain_overflow_dont_func
189 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
190 static bfd_boolean xcoff_complain_overflow_bitfield_func
191 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
192 static bfd_boolean xcoff_complain_overflow_signed_func
193 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
194 static bfd_boolean xcoff_complain_overflow_unsigned_func
195 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
197 bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
198 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) =
200 xcoff_reloc_type_pos, /* R_POS (0x00) */
201 xcoff_reloc_type_neg, /* R_NEG (0x01) */
202 xcoff_reloc_type_rel, /* R_REL (0x02) */
203 xcoff_reloc_type_toc, /* R_TOC (0x03) */
204 xcoff_reloc_type_fail, /* R_RTB (0x04) */
205 xcoff_reloc_type_toc, /* R_GL (0x05) */
206 xcoff_reloc_type_toc, /* R_TCL (0x06) */
207 xcoff_reloc_type_fail, /* (0x07) */
208 xcoff_reloc_type_ba, /* R_BA (0x08) */
209 xcoff_reloc_type_fail, /* (0x09) */
210 xcoff_reloc_type_br, /* R_BR (0x0a) */
211 xcoff_reloc_type_fail, /* (0x0b) */
212 xcoff_reloc_type_pos, /* R_RL (0x0c) */
213 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
214 xcoff_reloc_type_fail, /* (0x0e) */
215 xcoff_reloc_type_noop, /* R_REF (0x0f) */
216 xcoff_reloc_type_fail, /* (0x10) */
217 xcoff_reloc_type_fail, /* (0x11) */
218 xcoff_reloc_type_toc, /* R_TRL (0x12) */
219 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
220 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
221 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
222 xcoff_reloc_type_ba, /* R_CAI (0x16) */
223 xcoff_reloc_type_crel, /* R_CREL (0x17) */
224 xcoff_reloc_type_ba, /* R_RBA (0x18) */
225 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
226 xcoff_reloc_type_br, /* R_RBR (0x1a) */
227 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
230 bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
231 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) =
233 xcoff_complain_overflow_dont_func,
234 xcoff_complain_overflow_bitfield_func,
235 xcoff_complain_overflow_signed_func,
236 xcoff_complain_overflow_unsigned_func,
239 /* Information about one member of an archive. */
240 struct member_layout {
241 /* The archive member that this structure describes. */
242 bfd *member;
244 /* The number of bytes of padding that must be inserted before the
245 start of the member in order to ensure that the section contents
246 are correctly aligned. */
247 unsigned int leading_padding;
249 /* The offset of MEMBER from the start of the archive (i.e. the end
250 of the leading padding). */
251 file_ptr offset;
253 /* The normalized name of MEMBER. */
254 const char *name;
256 /* The length of NAME, without padding. */
257 bfd_size_type namlen;
259 /* The length of NAME, with padding. */
260 bfd_size_type padded_namlen;
262 /* The size of MEMBER's header, including the name and magic sequence. */
263 bfd_size_type header_size;
265 /* The size of the MEMBER's contents. */
266 bfd_size_type contents_size;
268 /* The number of bytes of padding that must be inserted after MEMBER
269 in order to preserve even alignment. */
270 bfd_size_type trailing_padding;
273 /* A structure used for iterating over the members of an archive. */
274 struct archive_iterator {
275 /* The archive itself. */
276 bfd *archive;
278 /* Information about the current archive member. */
279 struct member_layout current;
281 /* Information about the next archive member. MEMBER is null if there
282 are no more archive members, in which case OFFSET is the offset of
283 the first unused byte. */
284 struct member_layout next;
287 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
288 OFFSET is the even-padded offset of MEMBER, not including any leading
289 padding needed for section alignment. */
291 static void
292 member_layout_init (struct member_layout *info, bfd *archive,
293 bfd *member, file_ptr offset)
295 info->member = member;
296 info->leading_padding = 0;
297 if (member)
299 info->name = normalize_filename (member);
300 info->namlen = strlen (info->name);
301 info->padded_namlen = info->namlen + (info->namlen & 1);
302 if (xcoff_big_format_p (archive))
303 info->header_size = SIZEOF_AR_HDR_BIG;
304 else
305 info->header_size = SIZEOF_AR_HDR;
306 info->header_size += info->padded_namlen + SXCOFFARFMAG;
307 info->contents_size = arelt_size (member);
308 info->trailing_padding = info->contents_size & 1;
310 if (bfd_check_format (member, bfd_object)
311 && bfd_get_flavour (member) == bfd_target_xcoff_flavour
312 && (member->flags & DYNAMIC) != 0)
313 info->leading_padding
314 = (-(offset + info->header_size)
315 & ((1 << bfd_xcoff_text_align_power (member)) - 1));
317 info->offset = offset + info->leading_padding;
320 /* Set up ITERATOR to iterate through archive ARCHIVE. */
322 static void
323 archive_iterator_begin (struct archive_iterator *iterator,
324 bfd *archive)
326 iterator->archive = archive;
327 member_layout_init (&iterator->next, archive, archive->archive_head,
328 xcoff_big_format_p (archive)
329 ? SIZEOF_AR_FILE_HDR_BIG
330 : SIZEOF_AR_FILE_HDR);
333 /* Make ITERATOR visit the first unvisited archive member. Return true
334 on success; return false if all members have been visited. */
336 static bfd_boolean
337 archive_iterator_next (struct archive_iterator *iterator)
339 if (!iterator->next.member)
340 return FALSE;
342 iterator->current = iterator->next;
343 member_layout_init (&iterator->next, iterator->archive,
344 iterator->current.member->archive_next,
345 iterator->current.offset
346 + iterator->current.header_size
347 + iterator->current.contents_size
348 + iterator->current.trailing_padding);
349 return TRUE;
352 /* We use our own tdata type. Its first field is the COFF tdata type,
353 so the COFF routines are compatible. */
355 bfd_boolean
356 _bfd_xcoff_mkobject (abfd)
357 bfd *abfd;
359 coff_data_type *coff;
360 bfd_size_type amt = sizeof (struct xcoff_tdata);
362 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
363 if (abfd->tdata.xcoff_obj_data == NULL)
364 return FALSE;
365 coff = coff_data (abfd);
366 coff->symbols = (coff_symbol_type *) NULL;
367 coff->conversion_table = (unsigned int *) NULL;
368 coff->raw_syments = (struct coff_ptr_struct *) NULL;
369 coff->relocbase = 0;
371 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
373 /* We set cputype to -1 to indicate that it has not been
374 initialized. */
375 xcoff_data (abfd)->cputype = -1;
377 xcoff_data (abfd)->csects = NULL;
378 xcoff_data (abfd)->debug_indices = NULL;
380 /* text section alignment is different than the default */
381 bfd_xcoff_text_align_power (abfd) = 2;
383 return TRUE;
386 /* Copy XCOFF data from one BFD to another. */
388 bfd_boolean
389 _bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
390 bfd *ibfd;
391 bfd *obfd;
393 struct xcoff_tdata *ix, *ox;
394 asection *sec;
396 if (ibfd->xvec != obfd->xvec)
397 return TRUE;
398 ix = xcoff_data (ibfd);
399 ox = xcoff_data (obfd);
400 ox->full_aouthdr = ix->full_aouthdr;
401 ox->toc = ix->toc;
402 if (ix->sntoc == 0)
403 ox->sntoc = 0;
404 else
406 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
407 if (sec == NULL)
408 ox->sntoc = 0;
409 else
410 ox->sntoc = sec->output_section->target_index;
412 if (ix->snentry == 0)
413 ox->snentry = 0;
414 else
416 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
417 if (sec == NULL)
418 ox->snentry = 0;
419 else
420 ox->snentry = sec->output_section->target_index;
422 bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
423 bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
424 ox->modtype = ix->modtype;
425 ox->cputype = ix->cputype;
426 ox->maxdata = ix->maxdata;
427 ox->maxstack = ix->maxstack;
428 return TRUE;
431 /* I don't think XCOFF really has a notion of local labels based on
432 name. This will mean that ld -X doesn't actually strip anything.
433 The AIX native linker does not have a -X option, and it ignores the
434 -x option. */
436 bfd_boolean
437 _bfd_xcoff_is_local_label_name (abfd, name)
438 bfd *abfd ATTRIBUTE_UNUSED;
439 const char *name ATTRIBUTE_UNUSED;
441 return FALSE;
444 void
445 _bfd_xcoff_swap_sym_in (abfd, ext1, in1)
446 bfd *abfd;
447 PTR ext1;
448 PTR in1;
450 SYMENT *ext = (SYMENT *)ext1;
451 struct internal_syment * in = (struct internal_syment *)in1;
453 if (ext->e.e_name[0] != 0)
455 memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
457 else
459 in->_n._n_n._n_zeroes = 0;
460 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
463 in->n_value = H_GET_32 (abfd, ext->e_value);
464 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
465 in->n_type = H_GET_16 (abfd, ext->e_type);
466 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
467 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
470 unsigned int
471 _bfd_xcoff_swap_sym_out (abfd, inp, extp)
472 bfd *abfd;
473 PTR inp;
474 PTR extp;
476 struct internal_syment *in = (struct internal_syment *)inp;
477 SYMENT *ext =(SYMENT *)extp;
479 if (in->_n._n_name[0] != 0)
481 memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
483 else
485 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
486 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
489 H_PUT_32 (abfd, in->n_value, ext->e_value);
490 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
491 H_PUT_16 (abfd, in->n_type, ext->e_type);
492 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
493 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
494 return bfd_coff_symesz (abfd);
497 void
498 _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
499 bfd *abfd;
500 PTR ext1;
501 int type;
502 int class;
503 int indx;
504 int numaux;
505 PTR in1;
507 AUXENT * ext = (AUXENT *)ext1;
508 union internal_auxent *in = (union internal_auxent *)in1;
510 switch (class)
512 case C_FILE:
513 if (ext->x_file.x_fname[0] == 0)
515 in->x_file.x_n.x_zeroes = 0;
516 in->x_file.x_n.x_offset =
517 H_GET_32 (abfd, ext->x_file.x_n.x_offset);
519 else
521 if (numaux > 1)
523 if (indx == 0)
524 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
525 numaux * sizeof (AUXENT));
527 else
529 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
532 goto end;
534 /* RS/6000 "csect" auxents */
535 case C_EXT:
536 case C_AIX_WEAKEXT:
537 case C_HIDEXT:
538 if (indx + 1 == numaux)
540 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
541 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
542 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
543 /* We don't have to hack bitfields in x_smtyp because it's
544 defined by shifts-and-ands, which are equivalent on all
545 byte orders. */
546 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
547 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
548 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
549 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
550 goto end;
552 break;
554 case C_STAT:
555 case C_LEAFSTAT:
556 case C_HIDDEN:
557 if (type == T_NULL)
559 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
560 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
561 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
562 /* PE defines some extra fields; we zero them out for
563 safety. */
564 in->x_scn.x_checksum = 0;
565 in->x_scn.x_associated = 0;
566 in->x_scn.x_comdat = 0;
568 goto end;
570 break;
573 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
574 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
576 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
578 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
579 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
580 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
581 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
583 else
585 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
586 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
587 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
588 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
589 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
590 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
591 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
592 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
595 if (ISFCN (type))
597 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
599 else
601 in->x_sym.x_misc.x_lnsz.x_lnno =
602 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
603 in->x_sym.x_misc.x_lnsz.x_size =
604 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
607 end: ;
608 /* The semicolon is because MSVC doesn't like labels at
609 end of block. */
613 unsigned int _bfd_xcoff_swap_aux_out
614 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
616 unsigned int
617 _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
618 bfd * abfd;
619 PTR inp;
620 int type;
621 int class;
622 int indx ATTRIBUTE_UNUSED;
623 int numaux ATTRIBUTE_UNUSED;
624 PTR extp;
626 union internal_auxent *in = (union internal_auxent *)inp;
627 AUXENT *ext = (AUXENT *)extp;
629 memset ((PTR)ext, 0, bfd_coff_auxesz (abfd));
630 switch (class)
632 case C_FILE:
633 if (in->x_file.x_fname[0] == 0)
635 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
636 H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
638 else
640 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
642 goto end;
644 /* RS/6000 "csect" auxents */
645 case C_EXT:
646 case C_AIX_WEAKEXT:
647 case C_HIDEXT:
648 if (indx + 1 == numaux)
650 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
651 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
652 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
653 /* We don't have to hack bitfields in x_smtyp because it's
654 defined by shifts-and-ands, which are equivalent on all
655 byte orders. */
656 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
657 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
658 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
659 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
660 goto end;
662 break;
664 case C_STAT:
665 case C_LEAFSTAT:
666 case C_HIDDEN:
667 if (type == T_NULL)
669 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
670 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
671 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
672 goto end;
674 break;
677 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
678 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
680 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
682 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
683 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
684 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
685 ext->x_sym.x_fcnary.x_fcn.x_endndx);
687 else
689 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
690 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
691 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
692 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
693 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
694 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
695 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
696 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
699 if (ISFCN (type))
700 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
701 else
703 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
704 ext->x_sym.x_misc.x_lnsz.x_lnno);
705 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
706 ext->x_sym.x_misc.x_lnsz.x_size);
709 end:
710 return bfd_coff_auxesz (abfd);
715 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
716 bitsize and whether they are signed or not, along with a
717 conventional type. This table is for the types, which are used for
718 different algorithms for putting in the reloc. Many of these
719 relocs need special_function entries, which I have not written. */
722 reloc_howto_type xcoff_howto_table[] =
724 /* Standard 32 bit relocation. */
725 HOWTO (R_POS, /* type */
726 0, /* rightshift */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
728 32, /* bitsize */
729 FALSE, /* pc_relative */
730 0, /* bitpos */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 0, /* special_function */
733 "R_POS", /* name */
734 TRUE, /* partial_inplace */
735 0xffffffff, /* src_mask */
736 0xffffffff, /* dst_mask */
737 FALSE), /* pcrel_offset */
739 /* 32 bit relocation, but store negative value. */
740 HOWTO (R_NEG, /* type */
741 0, /* rightshift */
742 -2, /* size (0 = byte, 1 = short, 2 = long) */
743 32, /* bitsize */
744 FALSE, /* pc_relative */
745 0, /* bitpos */
746 complain_overflow_bitfield, /* complain_on_overflow */
747 0, /* special_function */
748 "R_NEG", /* name */
749 TRUE, /* partial_inplace */
750 0xffffffff, /* src_mask */
751 0xffffffff, /* dst_mask */
752 FALSE), /* pcrel_offset */
754 /* 32 bit PC relative relocation. */
755 HOWTO (R_REL, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 32, /* bitsize */
759 TRUE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_signed, /* complain_on_overflow */
762 0, /* special_function */
763 "R_REL", /* name */
764 TRUE, /* partial_inplace */
765 0xffffffff, /* src_mask */
766 0xffffffff, /* dst_mask */
767 FALSE), /* pcrel_offset */
769 /* 16 bit TOC relative relocation. */
770 HOWTO (R_TOC, /* type */
771 0, /* rightshift */
772 1, /* size (0 = byte, 1 = short, 2 = long) */
773 16, /* bitsize */
774 FALSE, /* pc_relative */
775 0, /* bitpos */
776 complain_overflow_bitfield, /* complain_on_overflow */
777 0, /* special_function */
778 "R_TOC", /* name */
779 TRUE, /* partial_inplace */
780 0xffff, /* src_mask */
781 0xffff, /* dst_mask */
782 FALSE), /* pcrel_offset */
784 /* I don't really know what this is. */
785 HOWTO (R_RTB, /* type */
786 1, /* rightshift */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
788 32, /* bitsize */
789 FALSE, /* pc_relative */
790 0, /* bitpos */
791 complain_overflow_bitfield, /* complain_on_overflow */
792 0, /* special_function */
793 "R_RTB", /* name */
794 TRUE, /* partial_inplace */
795 0xffffffff, /* src_mask */
796 0xffffffff, /* dst_mask */
797 FALSE), /* pcrel_offset */
799 /* External TOC relative symbol. */
800 HOWTO (R_GL, /* type */
801 0, /* rightshift */
802 1, /* size (0 = byte, 1 = short, 2 = long) */
803 16, /* bitsize */
804 FALSE, /* pc_relative */
805 0, /* bitpos */
806 complain_overflow_bitfield, /* complain_on_overflow */
807 0, /* special_function */
808 "R_GL", /* name */
809 TRUE, /* partial_inplace */
810 0xffff, /* src_mask */
811 0xffff, /* dst_mask */
812 FALSE), /* pcrel_offset */
814 /* Local TOC relative symbol. */
815 HOWTO (R_TCL, /* type */
816 0, /* rightshift */
817 1, /* size (0 = byte, 1 = short, 2 = long) */
818 16, /* bitsize */
819 FALSE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_bitfield, /* complain_on_overflow */
822 0, /* special_function */
823 "R_TCL", /* name */
824 TRUE, /* partial_inplace */
825 0xffff, /* src_mask */
826 0xffff, /* dst_mask */
827 FALSE), /* pcrel_offset */
829 EMPTY_HOWTO (7),
831 /* Non modifiable absolute branch. */
832 HOWTO (R_BA, /* type */
833 0, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
835 26, /* bitsize */
836 FALSE, /* pc_relative */
837 0, /* bitpos */
838 complain_overflow_bitfield, /* complain_on_overflow */
839 0, /* special_function */
840 "R_BA_26", /* name */
841 TRUE, /* partial_inplace */
842 0x03fffffc, /* src_mask */
843 0x03fffffc, /* dst_mask */
844 FALSE), /* pcrel_offset */
846 EMPTY_HOWTO (9),
848 /* Non modifiable relative branch. */
849 HOWTO (R_BR, /* type */
850 0, /* rightshift */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
852 26, /* bitsize */
853 TRUE, /* pc_relative */
854 0, /* bitpos */
855 complain_overflow_signed, /* complain_on_overflow */
856 0, /* special_function */
857 "R_BR", /* name */
858 TRUE, /* partial_inplace */
859 0x03fffffc, /* src_mask */
860 0x03fffffc, /* dst_mask */
861 FALSE), /* pcrel_offset */
863 EMPTY_HOWTO (0xb),
865 /* Indirect load. */
866 HOWTO (R_RL, /* type */
867 0, /* rightshift */
868 1, /* size (0 = byte, 1 = short, 2 = long) */
869 16, /* bitsize */
870 FALSE, /* pc_relative */
871 0, /* bitpos */
872 complain_overflow_bitfield, /* complain_on_overflow */
873 0, /* special_function */
874 "R_RL", /* name */
875 TRUE, /* partial_inplace */
876 0xffff, /* src_mask */
877 0xffff, /* dst_mask */
878 FALSE), /* pcrel_offset */
880 /* Load address. */
881 HOWTO (R_RLA, /* type */
882 0, /* rightshift */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
884 16, /* bitsize */
885 FALSE, /* pc_relative */
886 0, /* bitpos */
887 complain_overflow_bitfield, /* complain_on_overflow */
888 0, /* special_function */
889 "R_RLA", /* name */
890 TRUE, /* partial_inplace */
891 0xffff, /* src_mask */
892 0xffff, /* dst_mask */
893 FALSE), /* pcrel_offset */
895 EMPTY_HOWTO (0xe),
897 /* Non-relocating reference. */
898 HOWTO (R_REF, /* type */
899 0, /* rightshift */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
901 32, /* bitsize */
902 FALSE, /* pc_relative */
903 0, /* bitpos */
904 complain_overflow_dont, /* complain_on_overflow */
905 0, /* special_function */
906 "R_REF", /* name */
907 FALSE, /* partial_inplace */
908 0, /* src_mask */
909 0, /* dst_mask */
910 FALSE), /* pcrel_offset */
912 EMPTY_HOWTO (0x10),
913 EMPTY_HOWTO (0x11),
915 /* TOC relative indirect load. */
916 HOWTO (R_TRL, /* type */
917 0, /* rightshift */
918 1, /* size (0 = byte, 1 = short, 2 = long) */
919 16, /* bitsize */
920 FALSE, /* pc_relative */
921 0, /* bitpos */
922 complain_overflow_bitfield, /* complain_on_overflow */
923 0, /* special_function */
924 "R_TRL", /* name */
925 TRUE, /* partial_inplace */
926 0xffff, /* src_mask */
927 0xffff, /* dst_mask */
928 FALSE), /* pcrel_offset */
930 /* TOC relative load address. */
931 HOWTO (R_TRLA, /* type */
932 0, /* rightshift */
933 1, /* size (0 = byte, 1 = short, 2 = long) */
934 16, /* bitsize */
935 FALSE, /* pc_relative */
936 0, /* bitpos */
937 complain_overflow_bitfield, /* complain_on_overflow */
938 0, /* special_function */
939 "R_TRLA", /* name */
940 TRUE, /* partial_inplace */
941 0xffff, /* src_mask */
942 0xffff, /* dst_mask */
943 FALSE), /* pcrel_offset */
945 /* Modifiable relative branch. */
946 HOWTO (R_RRTBI, /* type */
947 1, /* rightshift */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
949 32, /* bitsize */
950 FALSE, /* pc_relative */
951 0, /* bitpos */
952 complain_overflow_bitfield, /* complain_on_overflow */
953 0, /* special_function */
954 "R_RRTBI", /* name */
955 TRUE, /* partial_inplace */
956 0xffffffff, /* src_mask */
957 0xffffffff, /* dst_mask */
958 FALSE), /* pcrel_offset */
960 /* Modifiable absolute branch. */
961 HOWTO (R_RRTBA, /* type */
962 1, /* rightshift */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
964 32, /* bitsize */
965 FALSE, /* pc_relative */
966 0, /* bitpos */
967 complain_overflow_bitfield, /* complain_on_overflow */
968 0, /* special_function */
969 "R_RRTBA", /* name */
970 TRUE, /* partial_inplace */
971 0xffffffff, /* src_mask */
972 0xffffffff, /* dst_mask */
973 FALSE), /* pcrel_offset */
975 /* Modifiable call absolute indirect. */
976 HOWTO (R_CAI, /* type */
977 0, /* rightshift */
978 1, /* size (0 = byte, 1 = short, 2 = long) */
979 16, /* bitsize */
980 FALSE, /* pc_relative */
981 0, /* bitpos */
982 complain_overflow_bitfield, /* complain_on_overflow */
983 0, /* special_function */
984 "R_CAI", /* name */
985 TRUE, /* partial_inplace */
986 0xffff, /* src_mask */
987 0xffff, /* dst_mask */
988 FALSE), /* pcrel_offset */
990 /* Modifiable call relative. */
991 HOWTO (R_CREL, /* type */
992 0, /* rightshift */
993 1, /* size (0 = byte, 1 = short, 2 = long) */
994 16, /* bitsize */
995 FALSE, /* pc_relative */
996 0, /* bitpos */
997 complain_overflow_bitfield, /* complain_on_overflow */
998 0, /* special_function */
999 "R_CREL", /* name */
1000 TRUE, /* partial_inplace */
1001 0xffff, /* src_mask */
1002 0xffff, /* dst_mask */
1003 FALSE), /* pcrel_offset */
1005 /* Modifiable branch absolute. */
1006 HOWTO (R_RBA, /* type */
1007 0, /* rightshift */
1008 2, /* size (0 = byte, 1 = short, 2 = long) */
1009 26, /* bitsize */
1010 FALSE, /* pc_relative */
1011 0, /* bitpos */
1012 complain_overflow_bitfield, /* complain_on_overflow */
1013 0, /* special_function */
1014 "R_RBA", /* name */
1015 TRUE, /* partial_inplace */
1016 0x03fffffc, /* src_mask */
1017 0x03fffffc, /* dst_mask */
1018 FALSE), /* pcrel_offset */
1020 /* Modifiable branch absolute. */
1021 HOWTO (R_RBAC, /* type */
1022 0, /* rightshift */
1023 2, /* size (0 = byte, 1 = short, 2 = long) */
1024 32, /* bitsize */
1025 FALSE, /* pc_relative */
1026 0, /* bitpos */
1027 complain_overflow_bitfield, /* complain_on_overflow */
1028 0, /* special_function */
1029 "R_RBAC", /* name */
1030 TRUE, /* partial_inplace */
1031 0xffffffff, /* src_mask */
1032 0xffffffff, /* dst_mask */
1033 FALSE), /* pcrel_offset */
1035 /* Modifiable branch relative. */
1036 HOWTO (R_RBR, /* type */
1037 0, /* rightshift */
1038 2, /* size (0 = byte, 1 = short, 2 = long) */
1039 26, /* bitsize */
1040 FALSE, /* pc_relative */
1041 0, /* bitpos */
1042 complain_overflow_signed, /* complain_on_overflow */
1043 0, /* special_function */
1044 "R_RBR_26", /* name */
1045 TRUE, /* partial_inplace */
1046 0x03fffffc, /* src_mask */
1047 0x03fffffc, /* dst_mask */
1048 FALSE), /* pcrel_offset */
1050 /* Modifiable branch absolute. */
1051 HOWTO (R_RBRC, /* type */
1052 0, /* rightshift */
1053 1, /* size (0 = byte, 1 = short, 2 = long) */
1054 16, /* bitsize */
1055 FALSE, /* pc_relative */
1056 0, /* bitpos */
1057 complain_overflow_bitfield, /* complain_on_overflow */
1058 0, /* special_function */
1059 "R_RBRC", /* name */
1060 TRUE, /* partial_inplace */
1061 0xffff, /* src_mask */
1062 0xffff, /* dst_mask */
1063 FALSE), /* pcrel_offset */
1065 /* 16 bit Non modifiable absolute branch. */
1066 HOWTO (R_BA, /* type */
1067 0, /* rightshift */
1068 1, /* size (0 = byte, 1 = short, 2 = long) */
1069 16, /* bitsize */
1070 FALSE, /* pc_relative */
1071 0, /* bitpos */
1072 complain_overflow_bitfield, /* complain_on_overflow */
1073 0, /* special_function */
1074 "R_BA_16", /* name */
1075 TRUE, /* partial_inplace */
1076 0xfffc, /* src_mask */
1077 0xfffc, /* dst_mask */
1078 FALSE), /* pcrel_offset */
1080 /* Modifiable branch relative. */
1081 HOWTO (R_RBR, /* type */
1082 0, /* rightshift */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1084 16, /* bitsize */
1085 FALSE, /* pc_relative */
1086 0, /* bitpos */
1087 complain_overflow_signed, /* complain_on_overflow */
1088 0, /* special_function */
1089 "R_RBR_16", /* name */
1090 TRUE, /* partial_inplace */
1091 0xffff, /* src_mask */
1092 0xffff, /* dst_mask */
1093 FALSE), /* pcrel_offset */
1095 /* Modifiable branch relative. */
1096 HOWTO (R_RBA, /* type */
1097 0, /* rightshift */
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1099 16, /* bitsize */
1100 FALSE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_signed, /* complain_on_overflow */
1103 0, /* special_function */
1104 "R_RBA_16", /* name */
1105 TRUE, /* partial_inplace */
1106 0xffff, /* src_mask */
1107 0xffff, /* dst_mask */
1108 FALSE), /* pcrel_offset */
1112 void
1113 xcoff_rtype2howto (relent, internal)
1114 arelent *relent;
1115 struct internal_reloc *internal;
1117 if (internal->r_type > R_RBRC)
1118 abort ();
1120 /* Default howto layout works most of the time */
1121 relent->howto = &xcoff_howto_table[internal->r_type];
1123 /* Special case some 16 bit reloc */
1124 if (15 == (internal->r_size & 0x1f))
1126 if (R_BA == internal->r_type)
1127 relent->howto = &xcoff_howto_table[0x1c];
1128 else if (R_RBR == internal->r_type)
1129 relent->howto = &xcoff_howto_table[0x1d];
1130 else if (R_RBA == internal->r_type)
1131 relent->howto = &xcoff_howto_table[0x1e];
1134 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1135 relocation, as well as indicating whether it is signed or not.
1136 Doublecheck that the relocation information gathered from the
1137 type matches this information. The bitsize is not significant
1138 for R_REF relocs. */
1139 if (relent->howto->dst_mask != 0
1140 && (relent->howto->bitsize
1141 != ((unsigned int) internal->r_size & 0x1f) + 1))
1142 abort ();
1145 reloc_howto_type *
1146 _bfd_xcoff_reloc_type_lookup (abfd, code)
1147 bfd *abfd ATTRIBUTE_UNUSED;
1148 bfd_reloc_code_real_type code;
1150 switch (code)
1152 case BFD_RELOC_PPC_B26:
1153 return &xcoff_howto_table[0xa];
1154 case BFD_RELOC_PPC_BA16:
1155 return &xcoff_howto_table[0x1c];
1156 case BFD_RELOC_PPC_BA26:
1157 return &xcoff_howto_table[8];
1158 case BFD_RELOC_PPC_TOC16:
1159 return &xcoff_howto_table[3];
1160 case BFD_RELOC_32:
1161 case BFD_RELOC_CTOR:
1162 return &xcoff_howto_table[0];
1163 default:
1164 return NULL;
1168 static reloc_howto_type *
1169 _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1170 const char *r_name)
1172 unsigned int i;
1174 for (i = 0;
1175 i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
1176 i++)
1177 if (xcoff_howto_table[i].name != NULL
1178 && strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
1179 return &xcoff_howto_table[i];
1181 return NULL;
1184 /* XCOFF archive support. The original version of this code was by
1185 Damon A. Permezel. It was enhanced to permit cross support, and
1186 writing archive files, by Ian Lance Taylor, Cygnus Support.
1188 XCOFF uses its own archive format. Everything is hooked together
1189 with file offset links, so it is possible to rapidly update an
1190 archive in place. Of course, we don't do that. An XCOFF archive
1191 has a real file header, not just an ARMAG string. The structure of
1192 the file header and of each archive header appear below.
1194 An XCOFF archive also has a member table, which is a list of
1195 elements in the archive (you can get that by looking through the
1196 linked list, but you have to read a lot more of the file). The
1197 member table has a normal archive header with an empty name. It is
1198 normally (and perhaps must be) the second to last entry in the
1199 archive. The member table data is almost printable ASCII. It
1200 starts with a 12 character decimal string which is the number of
1201 entries in the table. For each entry it has a 12 character decimal
1202 string which is the offset in the archive of that member. These
1203 entries are followed by a series of null terminated strings which
1204 are the member names for each entry.
1206 Finally, an XCOFF archive has a global symbol table, which is what
1207 we call the armap. The global symbol table has a normal archive
1208 header with an empty name. It is normally (and perhaps must be)
1209 the last entry in the archive. The contents start with a four byte
1210 binary number which is the number of entries. This is followed by
1211 a that many four byte binary numbers; each is the file offset of an
1212 entry in the archive. These numbers are followed by a series of
1213 null terminated strings, which are symbol names.
1215 AIX 4.3 introduced a new archive format which can handle larger
1216 files and also 32- and 64-bit objects in the same archive. The
1217 things said above remain true except that there is now more than
1218 one global symbol table. The one is used to index 32-bit objects,
1219 the other for 64-bit objects.
1221 The new archives (recognizable by the new ARMAG string) has larger
1222 field lengths so that we cannot really share any code. Also we have
1223 to take care that we are not generating the new form of archives
1224 on AIX 4.2 or earlier systems. */
1226 /* XCOFF archives use this as a magic string. Note that both strings
1227 have the same length. */
1229 /* Set the magic for archive. */
1231 bfd_boolean
1232 bfd_xcoff_ar_archive_set_magic (abfd, magic)
1233 bfd *abfd ATTRIBUTE_UNUSED;
1234 char *magic ATTRIBUTE_UNUSED;
1236 /* Not supported yet. */
1237 return FALSE;
1238 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1241 /* Read in the armap of an XCOFF archive. */
1243 bfd_boolean
1244 _bfd_xcoff_slurp_armap (abfd)
1245 bfd *abfd;
1247 file_ptr off;
1248 size_t namlen;
1249 bfd_size_type sz;
1250 bfd_byte *contents, *cend;
1251 bfd_vma c, i;
1252 carsym *arsym;
1253 bfd_byte *p;
1255 if (xcoff_ardata (abfd) == NULL)
1257 bfd_has_map (abfd) = FALSE;
1258 return TRUE;
1261 if (! xcoff_big_format_p (abfd))
1263 /* This is for the old format. */
1264 struct xcoff_ar_hdr hdr;
1266 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1267 if (off == 0)
1269 bfd_has_map (abfd) = FALSE;
1270 return TRUE;
1273 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1274 return FALSE;
1276 /* The symbol table starts with a normal archive header. */
1277 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1278 != SIZEOF_AR_HDR)
1279 return FALSE;
1281 /* Skip the name (normally empty). */
1282 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1283 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1284 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1285 return FALSE;
1287 sz = strtol (hdr.size, (char **) NULL, 10);
1289 /* Read in the entire symbol table. */
1290 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1291 if (contents == NULL)
1292 return FALSE;
1293 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1294 return FALSE;
1296 /* The symbol table starts with a four byte count. */
1297 c = H_GET_32 (abfd, contents);
1299 if (c * 4 >= sz)
1301 bfd_set_error (bfd_error_bad_value);
1302 return FALSE;
1305 bfd_ardata (abfd)->symdefs =
1306 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1307 if (bfd_ardata (abfd)->symdefs == NULL)
1308 return FALSE;
1310 /* After the count comes a list of four byte file offsets. */
1311 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1312 i < c;
1313 ++i, ++arsym, p += 4)
1314 arsym->file_offset = H_GET_32 (abfd, p);
1316 else
1318 /* This is for the new format. */
1319 struct xcoff_ar_hdr_big hdr;
1321 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1322 if (off == 0)
1324 bfd_has_map (abfd) = FALSE;
1325 return TRUE;
1328 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1329 return FALSE;
1331 /* The symbol table starts with a normal archive header. */
1332 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1333 != SIZEOF_AR_HDR_BIG)
1334 return FALSE;
1336 /* Skip the name (normally empty). */
1337 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1338 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1339 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1340 return FALSE;
1342 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1343 machines) since the field width is 20 and there numbers with more
1344 than 32 bits can be represented. */
1345 sz = strtol (hdr.size, (char **) NULL, 10);
1347 /* Read in the entire symbol table. */
1348 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1349 if (contents == NULL)
1350 return FALSE;
1351 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1352 return FALSE;
1354 /* The symbol table starts with an eight byte count. */
1355 c = H_GET_64 (abfd, contents);
1357 if (c * 8 >= sz)
1359 bfd_set_error (bfd_error_bad_value);
1360 return FALSE;
1363 bfd_ardata (abfd)->symdefs =
1364 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1365 if (bfd_ardata (abfd)->symdefs == NULL)
1366 return FALSE;
1368 /* After the count comes a list of eight byte file offsets. */
1369 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1370 i < c;
1371 ++i, ++arsym, p += 8)
1372 arsym->file_offset = H_GET_64 (abfd, p);
1375 /* After the file offsets come null terminated symbol names. */
1376 cend = contents + sz;
1377 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1378 i < c;
1379 ++i, ++arsym, p += strlen ((char *) p) + 1)
1381 if (p >= cend)
1383 bfd_set_error (bfd_error_bad_value);
1384 return FALSE;
1386 arsym->name = (char *) p;
1389 bfd_ardata (abfd)->symdef_count = c;
1390 bfd_has_map (abfd) = TRUE;
1392 return TRUE;
1395 /* See if this is an XCOFF archive. */
1397 const bfd_target *
1398 _bfd_xcoff_archive_p (abfd)
1399 bfd *abfd;
1401 struct artdata *tdata_hold;
1402 char magic[SXCOFFARMAG];
1403 bfd_size_type amt = SXCOFFARMAG;
1405 if (bfd_bread ((PTR) magic, amt, abfd) != amt)
1407 if (bfd_get_error () != bfd_error_system_call)
1408 bfd_set_error (bfd_error_wrong_format);
1409 return NULL;
1412 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1413 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1415 bfd_set_error (bfd_error_wrong_format);
1416 return NULL;
1419 tdata_hold = bfd_ardata (abfd);
1421 amt = sizeof (struct artdata);
1422 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
1423 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1424 goto error_ret_restore;
1426 /* Cleared by bfd_zalloc above.
1427 bfd_ardata (abfd)->cache = NULL;
1428 bfd_ardata (abfd)->archive_head = NULL;
1429 bfd_ardata (abfd)->symdefs = NULL;
1430 bfd_ardata (abfd)->extended_names = NULL;
1431 bfd_ardata (abfd)->extended_names_size = 0; */
1433 /* Now handle the two formats. */
1434 if (magic[1] != 'b')
1436 /* This is the old format. */
1437 struct xcoff_ar_file_hdr hdr;
1439 /* Copy over the magic string. */
1440 memcpy (hdr.magic, magic, SXCOFFARMAG);
1442 /* Now read the rest of the file header. */
1443 amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
1444 if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
1446 if (bfd_get_error () != bfd_error_system_call)
1447 bfd_set_error (bfd_error_wrong_format);
1448 goto error_ret;
1451 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1452 (char **) NULL, 10);
1454 amt = SIZEOF_AR_FILE_HDR;
1455 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1456 if (bfd_ardata (abfd)->tdata == NULL)
1457 goto error_ret;
1459 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1461 else
1463 /* This is the new format. */
1464 struct xcoff_ar_file_hdr_big hdr;
1466 /* Copy over the magic string. */
1467 memcpy (hdr.magic, magic, SXCOFFARMAG);
1469 /* Now read the rest of the file header. */
1470 amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1471 if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
1473 if (bfd_get_error () != bfd_error_system_call)
1474 bfd_set_error (bfd_error_wrong_format);
1475 goto error_ret;
1478 bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
1479 (const char **) 0,
1480 10);
1482 amt = SIZEOF_AR_FILE_HDR_BIG;
1483 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1484 if (bfd_ardata (abfd)->tdata == NULL)
1485 goto error_ret;
1487 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1490 if (! _bfd_xcoff_slurp_armap (abfd))
1492 error_ret:
1493 bfd_release (abfd, bfd_ardata (abfd));
1494 error_ret_restore:
1495 bfd_ardata (abfd) = tdata_hold;
1496 return NULL;
1499 return abfd->xvec;
1502 /* Read the archive header in an XCOFF archive. */
1505 _bfd_xcoff_read_ar_hdr (abfd)
1506 bfd *abfd;
1508 bfd_size_type namlen;
1509 struct areltdata *ret;
1510 bfd_size_type amt = sizeof (struct areltdata);
1512 ret = (struct areltdata *) bfd_alloc (abfd, amt);
1513 if (ret == NULL)
1514 return NULL;
1516 if (! xcoff_big_format_p (abfd))
1518 struct xcoff_ar_hdr hdr;
1519 struct xcoff_ar_hdr *hdrp;
1521 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1522 != SIZEOF_AR_HDR)
1524 free (ret);
1525 return NULL;
1528 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1529 amt = SIZEOF_AR_HDR + namlen + 1;
1530 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1531 if (hdrp == NULL)
1533 free (ret);
1534 return NULL;
1536 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1537 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1539 free (ret);
1540 return NULL;
1542 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1544 ret->arch_header = (char *) hdrp;
1545 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1546 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1548 else
1550 struct xcoff_ar_hdr_big hdr;
1551 struct xcoff_ar_hdr_big *hdrp;
1553 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1554 != SIZEOF_AR_HDR_BIG)
1556 free (ret);
1557 return NULL;
1560 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1561 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1562 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1563 if (hdrp == NULL)
1565 free (ret);
1566 return NULL;
1568 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1569 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1571 free (ret);
1572 return NULL;
1574 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1576 ret->arch_header = (char *) hdrp;
1577 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1578 machines) since the field width is 20 and there numbers with more
1579 than 32 bits can be represented. */
1580 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1581 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1584 /* Skip over the XCOFFARFMAG at the end of the file name. */
1585 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1586 return NULL;
1588 return (PTR) ret;
1591 /* Open the next element in an XCOFF archive. */
1593 bfd *
1594 _bfd_xcoff_openr_next_archived_file (archive, last_file)
1595 bfd *archive;
1596 bfd *last_file;
1598 file_ptr filestart;
1600 if (xcoff_ardata (archive) == NULL)
1602 bfd_set_error (bfd_error_invalid_operation);
1603 return NULL;
1606 if (! xcoff_big_format_p (archive))
1608 if (last_file == NULL)
1609 filestart = bfd_ardata (archive)->first_file_filepos;
1610 else
1611 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1612 10);
1614 if (filestart == 0
1615 || filestart == strtol (xcoff_ardata (archive)->memoff,
1616 (char **) NULL, 10)
1617 || filestart == strtol (xcoff_ardata (archive)->symoff,
1618 (char **) NULL, 10))
1620 bfd_set_error (bfd_error_no_more_archived_files);
1621 return NULL;
1624 else
1626 if (last_file == NULL)
1627 filestart = bfd_ardata (archive)->first_file_filepos;
1628 else
1629 /* XXX These actually have to be a calls to strtoll (at least
1630 on 32-bit machines) since the fields's width is 20 and
1631 there numbers with more than 32 bits can be represented. */
1632 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1633 10);
1635 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1636 machines) since the fields's width is 20 and there numbers with more
1637 than 32 bits can be represented. */
1638 if (filestart == 0
1639 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1640 (char **) NULL, 10)
1641 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1642 (char **) NULL, 10))
1644 bfd_set_error (bfd_error_no_more_archived_files);
1645 return NULL;
1649 return _bfd_get_elt_at_filepos (archive, filestart);
1652 /* Stat an element in an XCOFF archive. */
1655 _bfd_xcoff_stat_arch_elt (abfd, s)
1656 bfd *abfd;
1657 struct stat *s;
1659 if (abfd->arelt_data == NULL)
1661 bfd_set_error (bfd_error_invalid_operation);
1662 return -1;
1665 if (! xcoff_big_format_p (abfd->my_archive))
1667 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1669 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1670 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1671 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1672 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1673 s->st_size = arch_eltdata (abfd)->parsed_size;
1675 else
1677 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1679 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1680 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1681 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1682 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1683 s->st_size = arch_eltdata (abfd)->parsed_size;
1686 return 0;
1689 /* Normalize a file name for inclusion in an archive. */
1691 static const char *
1692 normalize_filename (abfd)
1693 bfd *abfd;
1695 const char *file;
1696 const char *filename;
1698 file = bfd_get_filename (abfd);
1699 filename = strrchr (file, '/');
1700 if (filename != NULL)
1701 filename++;
1702 else
1703 filename = file;
1704 return filename;
1707 /* Write out an XCOFF armap. */
1709 static bfd_boolean
1710 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1711 bfd *abfd;
1712 unsigned int elength ATTRIBUTE_UNUSED;
1713 struct orl *map;
1714 unsigned int orl_count;
1715 int stridx;
1717 struct archive_iterator iterator;
1718 struct xcoff_ar_hdr hdr;
1719 char *p;
1720 unsigned char buf[4];
1721 unsigned int i;
1723 memset (&hdr, 0, sizeof hdr);
1724 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1725 sprintf (hdr.nextoff, "%d", 0);
1726 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1727 sprintf (hdr.date, "%d", 0);
1728 sprintf (hdr.uid, "%d", 0);
1729 sprintf (hdr.gid, "%d", 0);
1730 sprintf (hdr.mode, "%d", 0);
1731 sprintf (hdr.namlen, "%d", 0);
1733 /* We need spaces, not null bytes, in the header. */
1734 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1735 if (*p == '\0')
1736 *p = ' ';
1738 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1739 != SIZEOF_AR_HDR
1740 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1741 != SXCOFFARFMAG))
1742 return FALSE;
1744 H_PUT_32 (abfd, orl_count, buf);
1745 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1746 return FALSE;
1748 i = 0;
1749 archive_iterator_begin (&iterator, abfd);
1750 while (i < orl_count && archive_iterator_next (&iterator))
1751 while (map[i].u.abfd == iterator.current.member)
1753 H_PUT_32 (abfd, iterator.current.offset, buf);
1754 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1755 return FALSE;
1756 ++i;
1759 for (i = 0; i < orl_count; i++)
1761 const char *name;
1762 size_t namlen;
1764 name = *map[i].name;
1765 namlen = strlen (name);
1766 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1767 return FALSE;
1770 if ((stridx & 1) != 0)
1772 char b;
1774 b = '\0';
1775 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1776 return FALSE;
1779 return TRUE;
1782 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1783 #define FMT20 "%-20lld"
1784 #define FMT12 "%-12d"
1785 #define FMT12_OCTAL "%-12o"
1786 #define FMT4 "%-4d"
1787 #define PRINT20(d, v) \
1788 sprintf (buff20, FMT20, (long long)(v)), \
1789 memcpy ((void *) (d), buff20, 20)
1791 #define PRINT12(d, v) \
1792 sprintf (buff20, FMT12, (int)(v)), \
1793 memcpy ((void *) (d), buff20, 12)
1795 #define PRINT12_OCTAL(d, v) \
1796 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1797 memcpy ((void *) (d), buff20, 12)
1799 #define PRINT4(d, v) \
1800 sprintf (buff20, FMT4, (int)(v)), \
1801 memcpy ((void *) (d), buff20, 4)
1803 #define READ20(d, v) \
1804 buff20[20] = 0, \
1805 memcpy (buff20, (d), 20), \
1806 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1808 static bfd_boolean
1809 do_pad (abfd, number)
1810 bfd *abfd;
1811 unsigned int number;
1813 bfd_byte b = 0;
1815 /* Limit pad to <= 4096. */
1816 if (number > 4096)
1817 return FALSE;
1819 while (number--)
1820 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1821 return FALSE;
1823 return TRUE;
1826 static bfd_boolean
1827 do_copy (out_bfd, in_bfd)
1828 bfd *out_bfd;
1829 bfd *in_bfd;
1831 bfd_size_type remaining;
1832 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1834 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1835 return FALSE;
1837 remaining = arelt_size (in_bfd);
1839 while (remaining >= DEFAULT_BUFFERSIZE)
1841 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1842 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1843 return FALSE;
1845 remaining -= DEFAULT_BUFFERSIZE;
1848 if (remaining)
1850 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1851 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1852 return FALSE;
1855 return TRUE;
1858 static bfd_boolean
1859 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1860 bfd *abfd;
1861 unsigned int elength ATTRIBUTE_UNUSED;
1862 struct orl *map;
1863 unsigned int orl_count;
1864 int stridx;
1866 struct archive_iterator iterator;
1867 struct xcoff_ar_file_hdr_big *fhdr;
1868 bfd_vma i, sym_32, sym_64, str_32, str_64;
1869 const bfd_arch_info_type *arch_info;
1870 bfd *current_bfd;
1871 size_t string_length;
1872 file_ptr nextoff, prevoff;
1874 /* First, we look through the symbols and work out which are
1875 from 32-bit objects and which from 64-bit ones. */
1876 sym_32 = sym_64 = str_32 = str_64 = 0;
1878 i = 0;
1879 for (current_bfd = abfd->archive_head;
1880 current_bfd != NULL && i < orl_count;
1881 current_bfd = current_bfd->archive_next)
1883 arch_info = bfd_get_arch_info (current_bfd);
1884 while (map[i].u.abfd == current_bfd)
1886 string_length = strlen (*map[i].name) + 1;
1887 if (arch_info->bits_per_address == 64)
1889 sym_64++;
1890 str_64 += string_length;
1892 else
1894 sym_32++;
1895 str_32 += string_length;
1897 i++;
1901 /* A quick sanity check... */
1902 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1903 /* Explicit cast to int for compiler. */
1904 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1906 fhdr = xcoff_ardata_big (abfd);
1908 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1909 READ20 (fhdr->memoff, prevoff);
1910 READ20 (fhdr->symoff, nextoff);
1912 BFD_ASSERT (nextoff == bfd_tell (abfd));
1914 /* Write out the symbol table.
1915 Layout :
1917 standard big archive header
1918 0x0000 ar_size [0x14]
1919 0x0014 ar_nxtmem [0x14]
1920 0x0028 ar_prvmem [0x14]
1921 0x003C ar_date [0x0C]
1922 0x0048 ar_uid [0x0C]
1923 0x0054 ar_gid [0x0C]
1924 0x0060 ar_mod [0x0C]
1925 0x006C ar_namelen[0x04]
1926 0x0070 ar_fmag [SXCOFFARFMAG]
1928 Symbol table
1929 0x0072 num_syms [0x08], binary
1930 0x0078 offsets [0x08 * num_syms], binary
1931 0x0086 + 0x08 * num_syms names [??]
1932 ?? pad to even bytes.
1935 if (sym_32)
1937 struct xcoff_ar_hdr_big *hdr;
1938 char *symbol_table;
1939 char *st;
1941 bfd_vma symbol_table_size =
1942 SIZEOF_AR_HDR_BIG
1943 + SXCOFFARFMAG
1945 + 8 * sym_32
1946 + str_32 + (str_32 & 1);
1948 symbol_table = bfd_zmalloc (symbol_table_size);
1949 if (symbol_table == NULL)
1950 return FALSE;
1952 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1954 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1956 if (sym_64)
1957 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1958 else
1959 PRINT20 (hdr->nextoff, 0);
1961 PRINT20 (hdr->prevoff, prevoff);
1962 PRINT12 (hdr->date, 0);
1963 PRINT12 (hdr->uid, 0);
1964 PRINT12 (hdr->gid, 0);
1965 PRINT12 (hdr->mode, 0);
1966 PRINT4 (hdr->namlen, 0) ;
1968 st = symbol_table + SIZEOF_AR_HDR_BIG;
1969 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1970 st += SXCOFFARFMAG;
1972 bfd_h_put_64 (abfd, sym_32, st);
1973 st += 8;
1975 /* loop over the 32 bit offsets */
1976 i = 0;
1977 archive_iterator_begin (&iterator, abfd);
1978 while (i < orl_count && archive_iterator_next (&iterator))
1980 arch_info = bfd_get_arch_info (iterator.current.member);
1981 while (map[i].u.abfd == iterator.current.member)
1983 if (arch_info->bits_per_address == 32)
1985 bfd_h_put_64 (abfd, iterator.current.offset, st);
1986 st += 8;
1988 i++;
1992 /* loop over the 32 bit symbol names */
1993 i = 0;
1994 for (current_bfd = abfd->archive_head;
1995 current_bfd != NULL && i < orl_count;
1996 current_bfd = current_bfd->archive_next)
1998 arch_info = bfd_get_arch_info (current_bfd);
1999 while (map[i].u.abfd == current_bfd)
2001 if (arch_info->bits_per_address == 32)
2003 string_length = sprintf (st, "%s", *map[i].name);
2004 st += string_length + 1;
2006 i++;
2010 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2012 free (symbol_table);
2014 prevoff = nextoff;
2015 nextoff = nextoff + symbol_table_size;
2017 else
2018 PRINT20 (fhdr->symoff, 0);
2020 if (sym_64)
2022 struct xcoff_ar_hdr_big *hdr;
2023 char *symbol_table;
2024 char *st;
2026 bfd_vma symbol_table_size =
2027 SIZEOF_AR_HDR_BIG
2028 + SXCOFFARFMAG
2030 + 8 * sym_64
2031 + str_64 + (str_64 & 1);
2033 symbol_table = bfd_zmalloc (symbol_table_size);
2034 if (symbol_table == NULL)
2035 return FALSE;
2037 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
2039 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
2040 PRINT20 (hdr->nextoff, 0);
2041 PRINT20 (hdr->prevoff, prevoff);
2042 PRINT12 (hdr->date, 0);
2043 PRINT12 (hdr->uid, 0);
2044 PRINT12 (hdr->gid, 0);
2045 PRINT12 (hdr->mode, 0);
2046 PRINT4 (hdr->namlen, 0);
2048 st = symbol_table + SIZEOF_AR_HDR_BIG;
2049 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
2050 st += SXCOFFARFMAG;
2052 bfd_h_put_64 (abfd, sym_64, st);
2053 st += 8;
2055 /* loop over the 64 bit offsets */
2056 i = 0;
2057 archive_iterator_begin (&iterator, abfd);
2058 while (i < orl_count && archive_iterator_next (&iterator))
2060 arch_info = bfd_get_arch_info (iterator.current.member);
2061 while (map[i].u.abfd == iterator.current.member)
2063 if (arch_info->bits_per_address == 64)
2065 bfd_h_put_64 (abfd, iterator.current.offset, st);
2066 st += 8;
2068 i++;
2072 /* loop over the 64 bit symbol names */
2073 i = 0;
2074 for (current_bfd = abfd->archive_head;
2075 current_bfd != NULL && i < orl_count;
2076 current_bfd = current_bfd->archive_next)
2078 arch_info = bfd_get_arch_info (current_bfd);
2079 while (map[i].u.abfd == current_bfd)
2081 if (arch_info->bits_per_address == 64)
2083 string_length = sprintf (st, "%s", *map[i].name);
2084 st += string_length + 1;
2086 i++;
2090 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2092 free (symbol_table);
2094 PRINT20 (fhdr->symoff64, nextoff);
2096 else
2097 PRINT20 (fhdr->symoff64, 0);
2099 return TRUE;
2102 bfd_boolean
2103 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
2104 bfd *abfd;
2105 unsigned int elength ATTRIBUTE_UNUSED;
2106 struct orl *map;
2107 unsigned int orl_count;
2108 int stridx;
2110 if (! xcoff_big_format_p (abfd))
2111 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2112 else
2113 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2116 /* Write out an XCOFF archive. We always write an entire archive,
2117 rather than fussing with the freelist and so forth. */
2119 static bfd_boolean
2120 xcoff_write_archive_contents_old (abfd)
2121 bfd *abfd;
2123 struct archive_iterator iterator;
2124 struct xcoff_ar_file_hdr fhdr;
2125 bfd_size_type count;
2126 bfd_size_type total_namlen;
2127 file_ptr *offsets;
2128 bfd_boolean makemap;
2129 bfd_boolean hasobjects;
2130 file_ptr prevoff, nextoff;
2131 bfd *sub;
2132 size_t i;
2133 struct xcoff_ar_hdr ahdr;
2134 bfd_size_type size;
2135 char *p;
2136 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2138 memset (&fhdr, 0, sizeof fhdr);
2139 (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2140 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2141 sprintf (fhdr.freeoff, "%d", 0);
2143 count = 0;
2144 total_namlen = 0;
2145 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2147 ++count;
2148 total_namlen += strlen (normalize_filename (sub)) + 1;
2149 if (sub->arelt_data == NULL)
2151 sub->arelt_data = bfd_zalloc (sub, sizeof (struct areltdata));
2152 if (sub->arelt_data == NULL)
2153 return FALSE;
2155 if (arch_xhdr (sub) == NULL)
2157 struct xcoff_ar_hdr *ahdrp;
2158 struct stat s;
2160 if (stat (bfd_get_filename (sub), &s) != 0)
2162 bfd_set_error (bfd_error_system_call);
2163 return FALSE;
2166 ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
2167 if (ahdrp == NULL)
2168 return FALSE;
2170 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2171 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2172 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2173 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2174 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2176 arch_eltdata (sub)->arch_header = (char *) ahdrp;
2177 arch_eltdata (sub)->parsed_size = s.st_size;
2180 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2181 if (offsets == NULL)
2182 return FALSE;
2184 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2185 return FALSE;
2187 makemap = bfd_has_map (abfd);
2188 hasobjects = FALSE;
2189 prevoff = 0;
2190 for (archive_iterator_begin (&iterator, abfd), i = 0;
2191 archive_iterator_next (&iterator);
2192 i++)
2194 bfd_size_type namlen;
2195 struct xcoff_ar_hdr *ahdrp;
2197 if (makemap && ! hasobjects)
2199 if (bfd_check_format (iterator.current.member, bfd_object))
2200 hasobjects = TRUE;
2203 ahdrp = arch_xhdr (iterator.current.member);
2204 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2205 sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
2206 sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
2208 /* We need spaces, not null bytes, in the header. */
2209 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2210 if (*p == '\0')
2211 *p = ' ';
2213 if (!do_pad (abfd, iterator.current.leading_padding))
2214 return FALSE;
2216 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2217 namlen = iterator.current.padded_namlen;
2218 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
2219 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2220 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2221 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2222 || !do_copy (abfd, iterator.current.member)
2223 || !do_pad (abfd, iterator.current.trailing_padding))
2224 return FALSE;
2226 offsets[i] = iterator.current.offset;
2227 prevoff = iterator.current.offset;
2230 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2232 /* Write out the member table. */
2234 nextoff = iterator.next.offset;
2235 BFD_ASSERT (nextoff == bfd_tell (abfd));
2236 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2238 memset (&ahdr, 0, sizeof ahdr);
2239 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2240 + count * XCOFFARMAG_ELEMENT_SIZE
2241 + total_namlen));
2242 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2243 sprintf (ahdr.date, "%d", 0);
2244 sprintf (ahdr.uid, "%d", 0);
2245 sprintf (ahdr.gid, "%d", 0);
2246 sprintf (ahdr.mode, "%d", 0);
2247 sprintf (ahdr.namlen, "%d", 0);
2249 size = (SIZEOF_AR_HDR
2250 + XCOFFARMAG_ELEMENT_SIZE
2251 + count * XCOFFARMAG_ELEMENT_SIZE
2252 + total_namlen
2253 + SXCOFFARFMAG);
2255 prevoff = nextoff;
2256 nextoff += size + (size & 1);
2258 if (makemap && hasobjects)
2259 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2260 else
2261 sprintf (ahdr.nextoff, "%d", 0);
2263 /* We need spaces, not null bytes, in the header. */
2264 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2265 if (*p == '\0')
2266 *p = ' ';
2268 if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2269 != SIZEOF_AR_HDR)
2270 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2271 != SXCOFFARFMAG))
2272 return FALSE;
2274 sprintf (decbuf, "%-12ld", (long) count);
2275 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2276 != XCOFFARMAG_ELEMENT_SIZE)
2277 return FALSE;
2278 for (i = 0; i < (size_t) count; i++)
2280 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2281 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2282 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2283 return FALSE;
2285 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2287 const char *name;
2288 bfd_size_type namlen;
2290 name = normalize_filename (sub);
2291 namlen = strlen (name);
2292 if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
2293 return FALSE;
2296 if (! do_pad (abfd, size & 1))
2297 return FALSE;
2299 /* Write out the armap, if appropriate. */
2300 if (! makemap || ! hasobjects)
2301 sprintf (fhdr.symoff, "%d", 0);
2302 else
2304 BFD_ASSERT (nextoff == bfd_tell (abfd));
2305 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2306 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2307 if (! _bfd_compute_and_write_armap (abfd, 0))
2308 return FALSE;
2311 /* Write out the archive file header. */
2313 /* We need spaces, not null bytes, in the header. */
2314 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2315 if (*p == '\0')
2316 *p = ' ';
2318 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2319 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2320 != SIZEOF_AR_FILE_HDR))
2321 return FALSE;
2323 return TRUE;
2326 static bfd_boolean
2327 xcoff_write_archive_contents_big (abfd)
2328 bfd *abfd;
2330 struct xcoff_ar_file_hdr_big fhdr;
2331 bfd_size_type count;
2332 bfd_size_type total_namlen;
2333 file_ptr *offsets;
2334 bfd_boolean makemap;
2335 bfd_boolean hasobjects;
2336 file_ptr prevoff, nextoff;
2337 bfd *current_bfd;
2338 size_t i;
2339 struct xcoff_ar_hdr_big *hdr;
2340 bfd_size_type size;
2341 char *member_table, *mt;
2342 bfd_vma member_table_size;
2343 struct archive_iterator iterator;
2345 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2346 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2348 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2349 return FALSE;
2351 /* Calculate count and total_namlen. */
2352 makemap = bfd_has_map (abfd);
2353 hasobjects = FALSE;
2354 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2355 current_bfd != NULL;
2356 current_bfd = current_bfd->archive_next, count++)
2358 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2360 if (makemap
2361 && ! hasobjects
2362 && bfd_check_format (current_bfd, bfd_object))
2363 hasobjects = TRUE;
2365 if (current_bfd->arelt_data == NULL)
2367 size = sizeof (struct areltdata);
2368 current_bfd->arelt_data = bfd_zalloc (current_bfd, size);
2369 if (current_bfd->arelt_data == NULL)
2370 return FALSE;
2373 if (arch_xhdr_big (current_bfd) == NULL)
2375 struct xcoff_ar_hdr_big *ahdrp;
2376 struct stat s;
2378 /* XXX This should actually be a call to stat64 (at least on
2379 32-bit machines).
2380 XXX This call will fail if the original object is not found. */
2381 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2383 bfd_set_error (bfd_error_system_call);
2384 return FALSE;
2387 ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
2388 if (ahdrp == NULL)
2389 return FALSE;
2391 PRINT20 (ahdrp->size, s.st_size);
2392 PRINT12 (ahdrp->date, s.st_mtime);
2393 PRINT12 (ahdrp->uid, s.st_uid);
2394 PRINT12 (ahdrp->gid, s.st_gid);
2395 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2397 arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
2398 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2402 offsets = NULL;
2403 if (count)
2405 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2406 if (offsets == NULL)
2407 return FALSE;
2410 prevoff = 0;
2411 for (archive_iterator_begin (&iterator, abfd), i = 0;
2412 archive_iterator_next (&iterator);
2413 i++)
2415 bfd_size_type namlen;
2416 struct xcoff_ar_hdr_big *ahdrp;
2418 ahdrp = arch_xhdr_big (iterator.current.member);
2419 PRINT20 (ahdrp->prevoff, prevoff);
2420 PRINT4 (ahdrp->namlen, iterator.current.namlen);
2421 PRINT20 (ahdrp->nextoff, iterator.next.offset);
2423 if (!do_pad (abfd, iterator.current.leading_padding))
2424 return FALSE;
2426 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2427 namlen = iterator.current.padded_namlen;
2428 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2429 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2430 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2431 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2432 || !do_copy (abfd, iterator.current.member)
2433 || !do_pad (abfd, iterator.current.trailing_padding))
2434 return FALSE;
2436 offsets[i] = iterator.current.offset;
2437 prevoff = iterator.current.offset;
2440 if (count)
2442 PRINT20 (fhdr.firstmemoff, offsets[0]);
2443 PRINT20 (fhdr.lastmemoff, prevoff);
2446 /* Write out the member table.
2447 Layout :
2449 standard big archive header
2450 0x0000 ar_size [0x14]
2451 0x0014 ar_nxtmem [0x14]
2452 0x0028 ar_prvmem [0x14]
2453 0x003C ar_date [0x0C]
2454 0x0048 ar_uid [0x0C]
2455 0x0054 ar_gid [0x0C]
2456 0x0060 ar_mod [0x0C]
2457 0x006C ar_namelen[0x04]
2458 0x0070 ar_fmag [0x02]
2460 Member table
2461 0x0072 count [0x14]
2462 0x0086 offsets [0x14 * counts]
2463 0x0086 + 0x14 * counts names [??]
2464 ?? pad to even bytes.
2467 nextoff = iterator.next.offset;
2468 BFD_ASSERT (nextoff == bfd_tell (abfd));
2470 member_table_size = (SIZEOF_AR_HDR_BIG
2471 + SXCOFFARFMAG
2472 + XCOFFARMAGBIG_ELEMENT_SIZE
2473 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2474 + total_namlen);
2476 member_table_size += member_table_size & 1;
2477 member_table = bfd_zmalloc (member_table_size);
2478 if (member_table == NULL)
2479 return FALSE;
2481 hdr = (struct xcoff_ar_hdr_big *) member_table;
2483 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
2484 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2485 + total_namlen + (total_namlen & 1)));
2486 if (makemap && hasobjects)
2487 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2488 else
2489 PRINT20 (hdr->nextoff, 0);
2490 PRINT20 (hdr->prevoff, prevoff);
2491 PRINT12 (hdr->date, 0);
2492 PRINT12 (hdr->uid, 0);
2493 PRINT12 (hdr->gid, 0);
2494 PRINT12 (hdr->mode, 0);
2495 PRINT4 (hdr->namlen, 0);
2497 mt = member_table + SIZEOF_AR_HDR_BIG;
2498 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2499 mt += SXCOFFARFMAG;
2501 PRINT20 (mt, count);
2502 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2503 for (i = 0; i < (size_t) count; i++)
2505 PRINT20 (mt, offsets[i]);
2506 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2509 if (count)
2511 free (offsets);
2512 offsets = NULL;
2515 for (current_bfd = abfd->archive_head;
2516 current_bfd != NULL;
2517 current_bfd = current_bfd->archive_next)
2519 const char *name;
2520 size_t namlen;
2522 name = normalize_filename (current_bfd);
2523 namlen = sprintf (mt, "%s", name);
2524 mt += namlen + 1;
2527 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2528 return FALSE;
2530 free (member_table);
2532 PRINT20 (fhdr.memoff, nextoff);
2534 prevoff = nextoff;
2535 nextoff += member_table_size;
2537 /* Write out the armap, if appropriate. */
2539 if (! makemap || ! hasobjects)
2540 PRINT20 (fhdr.symoff, 0);
2541 else
2543 BFD_ASSERT (nextoff == bfd_tell (abfd));
2545 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2546 PRINT20 (fhdr.symoff, nextoff);
2548 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2549 if (! _bfd_compute_and_write_armap (abfd, 0))
2550 return FALSE;
2553 /* Write out the archive file header. */
2555 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2556 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2557 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2558 return FALSE;
2560 return TRUE;
2563 bfd_boolean
2564 _bfd_xcoff_write_archive_contents (abfd)
2565 bfd *abfd;
2567 if (! xcoff_big_format_p (abfd))
2568 return xcoff_write_archive_contents_old (abfd);
2569 else
2570 return xcoff_write_archive_contents_big (abfd);
2573 /* We can't use the usual coff_sizeof_headers routine, because AIX
2574 always uses an a.out header. */
2577 _bfd_xcoff_sizeof_headers (bfd *abfd,
2578 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2580 int size;
2582 size = FILHSZ;
2583 if (xcoff_data (abfd)->full_aouthdr)
2584 size += AOUTSZ;
2585 else
2586 size += SMALL_AOUTSZ;
2587 size += abfd->section_count * SCNHSZ;
2588 return size;
2591 /* Routines to swap information in the XCOFF .loader section. If we
2592 ever need to write an XCOFF loader, this stuff will need to be
2593 moved to another file shared by the linker (which XCOFF calls the
2594 ``binder'') and the loader. */
2596 /* Swap in the ldhdr structure. */
2598 static void
2599 xcoff_swap_ldhdr_in (abfd, s, dst)
2600 bfd *abfd;
2601 const PTR s;
2602 struct internal_ldhdr *dst;
2604 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2606 dst->l_version = bfd_get_32 (abfd, src->l_version);
2607 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2608 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2609 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2610 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2611 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2612 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2613 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2616 /* Swap out the ldhdr structure. */
2618 static void
2619 xcoff_swap_ldhdr_out (abfd, src, d)
2620 bfd *abfd;
2621 const struct internal_ldhdr *src;
2622 PTR d;
2624 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2626 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2627 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2628 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2629 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2630 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2631 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2632 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2633 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2636 /* Swap in the ldsym structure. */
2638 static void
2639 xcoff_swap_ldsym_in (abfd, s, dst)
2640 bfd *abfd;
2641 const PTR s;
2642 struct internal_ldsym *dst;
2644 const struct external_ldsym *src = (const struct external_ldsym *) s;
2646 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2647 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2648 } else {
2649 dst->_l._l_l._l_zeroes = 0;
2650 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2652 dst->l_value = bfd_get_32 (abfd, src->l_value);
2653 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2654 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2655 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2656 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2657 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2660 /* Swap out the ldsym structure. */
2662 static void
2663 xcoff_swap_ldsym_out (abfd, src, d)
2664 bfd *abfd;
2665 const struct internal_ldsym *src;
2666 PTR d;
2668 struct external_ldsym *dst = (struct external_ldsym *) d;
2670 if (src->_l._l_l._l_zeroes != 0)
2671 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2672 else
2674 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2675 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2676 dst->_l._l_l._l_offset);
2678 bfd_put_32 (abfd, src->l_value, dst->l_value);
2679 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2680 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2681 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2682 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2683 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2686 static void
2687 xcoff_swap_reloc_in (abfd, s, d)
2688 bfd *abfd;
2689 PTR s;
2690 PTR d;
2692 struct external_reloc *src = (struct external_reloc *) s;
2693 struct internal_reloc *dst = (struct internal_reloc *) d;
2695 memset (dst, 0, sizeof (struct internal_reloc));
2697 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2698 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2699 dst->r_size = bfd_get_8 (abfd, src->r_size);
2700 dst->r_type = bfd_get_8 (abfd, src->r_type);
2703 static unsigned int
2704 xcoff_swap_reloc_out (abfd, s, d)
2705 bfd *abfd;
2706 PTR s;
2707 PTR d;
2709 struct internal_reloc *src = (struct internal_reloc *) s;
2710 struct external_reloc *dst = (struct external_reloc *) d;
2712 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2713 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2714 bfd_put_8 (abfd, src->r_type, dst->r_type);
2715 bfd_put_8 (abfd, src->r_size, dst->r_size);
2717 return bfd_coff_relsz (abfd);
2720 /* Swap in the ldrel structure. */
2722 static void
2723 xcoff_swap_ldrel_in (abfd, s, dst)
2724 bfd *abfd;
2725 const PTR s;
2726 struct internal_ldrel *dst;
2728 const struct external_ldrel *src = (const struct external_ldrel *) s;
2730 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2731 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2732 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2733 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2736 /* Swap out the ldrel structure. */
2738 static void
2739 xcoff_swap_ldrel_out (abfd, src, d)
2740 bfd *abfd;
2741 const struct internal_ldrel *src;
2742 PTR d;
2744 struct external_ldrel *dst = (struct external_ldrel *) d;
2746 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2747 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2748 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2749 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2753 bfd_boolean
2754 xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
2755 val, addend, relocation, contents)
2756 bfd *input_bfd ATTRIBUTE_UNUSED;
2757 asection *input_section ATTRIBUTE_UNUSED;
2758 bfd *output_bfd ATTRIBUTE_UNUSED;
2759 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2760 struct internal_syment *sym ATTRIBUTE_UNUSED;
2761 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2762 bfd_vma val ATTRIBUTE_UNUSED;
2763 bfd_vma addend ATTRIBUTE_UNUSED;
2764 bfd_vma *relocation ATTRIBUTE_UNUSED;
2765 bfd_byte *contents ATTRIBUTE_UNUSED;
2767 return TRUE;
2770 bfd_boolean
2771 xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
2772 val, addend, relocation, contents)
2773 bfd *input_bfd;
2774 asection *input_section ATTRIBUTE_UNUSED;
2775 bfd *output_bfd ATTRIBUTE_UNUSED;
2776 struct internal_reloc *rel;
2777 struct internal_syment *sym ATTRIBUTE_UNUSED;
2778 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2779 bfd_vma val ATTRIBUTE_UNUSED;
2780 bfd_vma addend ATTRIBUTE_UNUSED;
2781 bfd_vma *relocation ATTRIBUTE_UNUSED;
2782 bfd_byte *contents ATTRIBUTE_UNUSED;
2784 (*_bfd_error_handler)
2785 (_("%s: unsupported relocation type 0x%02x"),
2786 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2787 bfd_set_error (bfd_error_bad_value);
2788 return FALSE;
2791 bfd_boolean
2792 xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
2793 val, addend, relocation, contents)
2794 bfd *input_bfd ATTRIBUTE_UNUSED;
2795 asection *input_section ATTRIBUTE_UNUSED;
2796 bfd *output_bfd ATTRIBUTE_UNUSED;
2797 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2798 struct internal_syment *sym ATTRIBUTE_UNUSED;
2799 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2800 bfd_vma val;
2801 bfd_vma addend;
2802 bfd_vma *relocation;
2803 bfd_byte *contents ATTRIBUTE_UNUSED;
2805 *relocation = val + addend;
2806 return TRUE;
2809 bfd_boolean
2810 xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
2811 val, addend, relocation, contents)
2812 bfd *input_bfd ATTRIBUTE_UNUSED;
2813 asection *input_section ATTRIBUTE_UNUSED;
2814 bfd *output_bfd ATTRIBUTE_UNUSED;
2815 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2816 struct internal_syment *sym ATTRIBUTE_UNUSED;
2817 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2818 bfd_vma val;
2819 bfd_vma addend;
2820 bfd_vma *relocation;
2821 bfd_byte *contents ATTRIBUTE_UNUSED;
2823 *relocation = addend - val;
2824 return TRUE;
2827 bfd_boolean
2828 xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
2829 val, addend, relocation, contents)
2830 bfd *input_bfd ATTRIBUTE_UNUSED;
2831 asection *input_section;
2832 bfd *output_bfd ATTRIBUTE_UNUSED;
2833 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2834 struct internal_syment *sym ATTRIBUTE_UNUSED;
2835 struct reloc_howto_struct *howto;
2836 bfd_vma val;
2837 bfd_vma addend;
2838 bfd_vma *relocation;
2839 bfd_byte *contents ATTRIBUTE_UNUSED;
2841 howto->pc_relative = TRUE;
2843 /* A PC relative reloc includes the section address. */
2844 addend += input_section->vma;
2846 *relocation = val + addend;
2847 *relocation -= (input_section->output_section->vma
2848 + input_section->output_offset);
2849 return TRUE;
2852 bfd_boolean
2853 xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
2854 val, addend, relocation, contents)
2855 bfd *input_bfd;
2856 asection *input_section ATTRIBUTE_UNUSED;
2857 bfd *output_bfd;
2858 struct internal_reloc *rel;
2859 struct internal_syment *sym;
2860 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2861 bfd_vma val;
2862 bfd_vma addend ATTRIBUTE_UNUSED;
2863 bfd_vma *relocation;
2864 bfd_byte *contents ATTRIBUTE_UNUSED;
2866 struct xcoff_link_hash_entry *h;
2868 if (0 > rel->r_symndx)
2869 return FALSE;
2871 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2873 if (h != NULL && h->smclas != XMC_TD)
2875 if (h->toc_section == NULL)
2877 (*_bfd_error_handler)
2878 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2879 bfd_get_filename (input_bfd), rel->r_vaddr,
2880 h->root.root.string);
2881 bfd_set_error (bfd_error_bad_value);
2882 return FALSE;
2885 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2886 val = (h->toc_section->output_section->vma
2887 + h->toc_section->output_offset);
2890 *relocation = ((val - xcoff_data (output_bfd)->toc)
2891 - (sym->n_value - xcoff_data (input_bfd)->toc));
2892 return TRUE;
2895 bfd_boolean
2896 xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
2897 val, addend, relocation, contents)
2898 bfd *input_bfd ATTRIBUTE_UNUSED;
2899 asection *input_section ATTRIBUTE_UNUSED;
2900 bfd *output_bfd ATTRIBUTE_UNUSED;
2901 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2902 struct internal_syment *sym ATTRIBUTE_UNUSED;
2903 struct reloc_howto_struct *howto;
2904 bfd_vma val;
2905 bfd_vma addend;
2906 bfd_vma *relocation;
2907 bfd_byte *contents ATTRIBUTE_UNUSED;
2909 howto->src_mask &= ~3;
2910 howto->dst_mask = howto->src_mask;
2912 *relocation = val + addend;
2914 return TRUE;
2917 static bfd_boolean
2918 xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
2919 val, addend, relocation, contents)
2920 bfd *input_bfd;
2921 asection *input_section;
2922 bfd *output_bfd ATTRIBUTE_UNUSED;
2923 struct internal_reloc *rel;
2924 struct internal_syment *sym ATTRIBUTE_UNUSED;
2925 struct reloc_howto_struct *howto;
2926 bfd_vma val;
2927 bfd_vma addend;
2928 bfd_vma *relocation;
2929 bfd_byte *contents;
2931 struct xcoff_link_hash_entry *h;
2932 bfd_vma section_offset;
2934 if (0 > rel->r_symndx)
2935 return FALSE;
2937 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2938 section_offset = rel->r_vaddr - input_section->vma;
2940 /* If we see an R_BR or R_RBR reloc which is jumping to global
2941 linkage code, and it is followed by an appropriate cror nop
2942 instruction, we replace the cror with lwz r2,20(r1). This
2943 restores the TOC after the glink code. Contrariwise, if the
2944 call is followed by a lwz r2,20(r1), but the call is not
2945 going to global linkage code, we can replace the load with a
2946 cror. */
2947 if (NULL != h
2948 && (bfd_link_hash_defined == h->root.type
2949 || bfd_link_hash_defweak == h->root.type)
2950 && section_offset + 8 <= input_section->size)
2952 bfd_byte *pnext;
2953 unsigned long next;
2955 pnext = contents + section_offset + 4;
2956 next = bfd_get_32 (input_bfd, pnext);
2958 /* The _ptrgl function is magic. It is used by the AIX
2959 compiler to call a function through a pointer. */
2960 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2962 if (next == 0x4def7b82 /* cror 15,15,15 */
2963 || next == 0x4ffffb82 /* cror 31,31,31 */
2964 || next == 0x60000000) /* ori r0,r0,0 */
2965 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
2968 else
2970 if (next == 0x80410014) /* lwz r2,20(r1) */
2971 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2974 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2976 /* Normally, this relocation is against a defined symbol. In the
2977 case where this is a partial link and the output section offset
2978 is greater than 2^25, the linker will return an invalid error
2979 message that the relocation has been truncated. Yes it has been
2980 truncated but no it not important. For this case, disable the
2981 overflow checking. */
2983 howto->complain_on_overflow = complain_overflow_dont;
2986 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2987 the value below will give the absolute target address. */
2988 *relocation = val + addend + rel->r_vaddr;
2990 howto->src_mask &= ~3;
2991 howto->dst_mask = howto->src_mask;
2993 if (h != NULL
2994 && (h->root.type == bfd_link_hash_defined
2995 || h->root.type == bfd_link_hash_defweak)
2996 && bfd_is_abs_section (h->root.u.def.section)
2997 && section_offset + 4 <= input_section->size)
2999 bfd_byte *ptr;
3000 bfd_vma insn;
3002 /* Turn the relative branch into an absolute one by setting the
3003 AA bit. */
3004 ptr = contents + section_offset;
3005 insn = bfd_get_32 (input_bfd, ptr);
3006 insn |= 2;
3007 bfd_put_32 (input_bfd, insn, ptr);
3009 /* Make the howto absolute too. */
3010 howto->pc_relative = FALSE;
3011 howto->complain_on_overflow = complain_overflow_bitfield;
3013 else
3015 /* Use a PC-relative howto and subtract the instruction's address
3016 from the target address we calculated above. */
3017 howto->pc_relative = TRUE;
3018 *relocation -= (input_section->output_section->vma
3019 + input_section->output_offset
3020 + section_offset);
3022 return TRUE;
3025 bfd_boolean
3026 xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
3027 val, addend, relocation, contents)
3028 bfd *input_bfd ATTRIBUTE_UNUSED;
3029 asection *input_section;
3030 bfd *output_bfd ATTRIBUTE_UNUSED;
3031 struct internal_reloc *rel ATTRIBUTE_UNUSED;
3032 struct internal_syment *sym ATTRIBUTE_UNUSED;
3033 struct reloc_howto_struct *howto;
3034 bfd_vma val ATTRIBUTE_UNUSED;
3035 bfd_vma addend;
3036 bfd_vma *relocation;
3037 bfd_byte *contents ATTRIBUTE_UNUSED;
3039 howto->pc_relative = TRUE;
3040 howto->src_mask &= ~3;
3041 howto->dst_mask = howto->src_mask;
3043 /* A PC relative reloc includes the section address. */
3044 addend += input_section->vma;
3046 *relocation = val + addend;
3047 *relocation -= (input_section->output_section->vma
3048 + input_section->output_offset);
3049 return TRUE;
3052 static bfd_boolean
3053 xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
3054 bfd *input_bfd ATTRIBUTE_UNUSED;
3055 bfd_vma val ATTRIBUTE_UNUSED;
3056 bfd_vma relocation ATTRIBUTE_UNUSED;
3057 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
3059 return FALSE;
3062 static bfd_boolean
3063 xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
3064 bfd *input_bfd;
3065 bfd_vma val;
3066 bfd_vma relocation;
3067 struct reloc_howto_struct *howto;
3069 bfd_vma addrmask, fieldmask, signmask, ss;
3070 bfd_vma a, b, sum;
3072 /* Get the values to be added together. For signed and unsigned
3073 relocations, we assume that all values should be truncated to
3074 the size of an address. For bitfields, all the bits matter.
3075 See also bfd_check_overflow. */
3076 fieldmask = N_ONES (howto->bitsize);
3077 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3078 a = relocation;
3079 b = val & howto->src_mask;
3081 /* Much like unsigned, except no trimming with addrmask. In
3082 addition, the sum overflows if there is a carry out of
3083 the bfd_vma, i.e., the sum is less than either input
3084 operand. */
3085 a >>= howto->rightshift;
3086 b >>= howto->bitpos;
3088 /* Bitfields are sometimes used for signed numbers; for
3089 example, a 13-bit field sometimes represents values in
3090 0..8191 and sometimes represents values in -4096..4095.
3091 If the field is signed and a is -4095 (0x1001) and b is
3092 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3093 0x1fff is 0x3000). It's not clear how to handle this
3094 everywhere, since there is not way to know how many bits
3095 are significant in the relocation, but the original code
3096 assumed that it was fully sign extended, and we will keep
3097 that assumption. */
3098 signmask = (fieldmask >> 1) + 1;
3100 if ((a & ~ fieldmask) != 0)
3102 /* Some bits out of the field are set. This might not
3103 be a problem: if this is a signed bitfield, it is OK
3104 iff all the high bits are set, including the sign
3105 bit. We'll try setting all but the most significant
3106 bit in the original relocation value: if this is all
3107 ones, we are OK, assuming a signed bitfield. */
3108 ss = (signmask << howto->rightshift) - 1;
3109 if ((ss | relocation) != ~ (bfd_vma) 0)
3110 return TRUE;
3111 a &= fieldmask;
3114 /* We just assume (b & ~ fieldmask) == 0. */
3116 /* We explicitly permit wrap around if this relocation
3117 covers the high bit of an address. The Linux kernel
3118 relies on it, and it is the only way to write assembler
3119 code which can run when loaded at a location 0x80000000
3120 away from the location at which it is linked. */
3121 if (howto->bitsize + howto->rightshift
3122 == bfd_arch_bits_per_address (input_bfd))
3123 return FALSE;
3125 sum = a + b;
3126 if (sum < a || (sum & ~ fieldmask) != 0)
3128 /* There was a carry out, or the field overflow. Test
3129 for signed operands again. Here is the overflow test
3130 is as for complain_overflow_signed. */
3131 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3132 return TRUE;
3135 return FALSE;
3138 static bfd_boolean
3139 xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
3140 bfd *input_bfd;
3141 bfd_vma val;
3142 bfd_vma relocation;
3143 struct reloc_howto_struct *howto;
3145 bfd_vma addrmask, fieldmask, signmask, ss;
3146 bfd_vma a, b, sum;
3148 /* Get the values to be added together. For signed and unsigned
3149 relocations, we assume that all values should be truncated to
3150 the size of an address. For bitfields, all the bits matter.
3151 See also bfd_check_overflow. */
3152 fieldmask = N_ONES (howto->bitsize);
3153 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3154 a = relocation;
3155 b = val & howto->src_mask;
3157 a = (a & addrmask) >> howto->rightshift;
3159 /* If any sign bits are set, all sign bits must be set.
3160 That is, A must be a valid negative address after
3161 shifting. */
3162 signmask = ~ (fieldmask >> 1);
3163 ss = a & signmask;
3164 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3165 return TRUE;
3167 /* We only need this next bit of code if the sign bit of B
3168 is below the sign bit of A. This would only happen if
3169 SRC_MASK had fewer bits than BITSIZE. Note that if
3170 SRC_MASK has more bits than BITSIZE, we can get into
3171 trouble; we would need to verify that B is in range, as
3172 we do for A above. */
3173 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3174 if ((b & signmask) != 0)
3176 /* Set all the bits above the sign bit. */
3177 b -= signmask <<= 1;
3180 b = (b & addrmask) >> howto->bitpos;
3182 /* Now we can do the addition. */
3183 sum = a + b;
3185 /* See if the result has the correct sign. Bits above the
3186 sign bit are junk now; ignore them. If the sum is
3187 positive, make sure we did not have all negative inputs;
3188 if the sum is negative, make sure we did not have all
3189 positive inputs. The test below looks only at the sign
3190 bits, and it really just
3191 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3193 signmask = (fieldmask >> 1) + 1;
3194 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3195 return TRUE;
3197 return FALSE;
3200 static bfd_boolean
3201 xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
3202 bfd *input_bfd;
3203 bfd_vma val;
3204 bfd_vma relocation;
3205 struct reloc_howto_struct *howto;
3207 bfd_vma addrmask, fieldmask;
3208 bfd_vma a, b, sum;
3210 /* Get the values to be added together. For signed and unsigned
3211 relocations, we assume that all values should be truncated to
3212 the size of an address. For bitfields, all the bits matter.
3213 See also bfd_check_overflow. */
3214 fieldmask = N_ONES (howto->bitsize);
3215 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3216 a = relocation;
3217 b = val & howto->src_mask;
3219 /* Checking for an unsigned overflow is relatively easy:
3220 trim the addresses and add, and trim the result as well.
3221 Overflow is normally indicated when the result does not
3222 fit in the field. However, we also need to consider the
3223 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3224 input is 0x80000000, and bfd_vma is only 32 bits; then we
3225 will get sum == 0, but there is an overflow, since the
3226 inputs did not fit in the field. Instead of doing a
3227 separate test, we can check for this by or-ing in the
3228 operands when testing for the sum overflowing its final
3229 field. */
3230 a = (a & addrmask) >> howto->rightshift;
3231 b = (b & addrmask) >> howto->bitpos;
3232 sum = (a + b) & addrmask;
3233 if ((a | b | sum) & ~ fieldmask)
3234 return TRUE;
3236 return FALSE;
3239 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3240 This is currently the only processor which uses XCOFF; I hope that
3241 will never change.
3243 I took the relocation type definitions from two documents:
3244 the PowerPC AIX Version 4 Application Binary Interface, First
3245 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3246 32-Bit Hardware Implementation (June 30, 1994). Differences
3247 between the documents are noted below.
3249 Unsupported r_type's
3251 R_RTB:
3252 R_RRTBI:
3253 R_RRTBA:
3255 These relocs are defined by the PowerPC ABI to be
3256 relative branches which use half of the difference
3257 between the symbol and the program counter. I can't
3258 quite figure out when this is useful. These relocs are
3259 not defined by the PowerOpen ABI.
3261 Supported r_type's
3263 R_POS:
3264 Simple positive relocation.
3266 R_NEG:
3267 Simple negative relocation.
3269 R_REL:
3270 Simple PC relative relocation.
3272 R_TOC:
3273 TOC relative relocation. The value in the instruction in
3274 the input file is the offset from the input file TOC to
3275 the desired location. We want the offset from the final
3276 TOC to the desired location. We have:
3277 isym = iTOC + in
3278 iinsn = in + o
3279 osym = oTOC + on
3280 oinsn = on + o
3281 so we must change insn by on - in.
3283 R_GL:
3284 GL linkage relocation. The value of this relocation
3285 is the address of the entry in the TOC section.
3287 R_TCL:
3288 Local object TOC address. I can't figure out the
3289 difference between this and case R_GL.
3291 R_TRL:
3292 TOC relative relocation. A TOC relative load instruction
3293 which may be changed to a load address instruction.
3294 FIXME: We don't currently implement this optimization.
3296 R_TRLA:
3297 TOC relative relocation. This is a TOC relative load
3298 address instruction which may be changed to a load
3299 instruction. FIXME: I don't know if this is the correct
3300 implementation.
3302 R_BA:
3303 Absolute branch. We don't want to mess with the lower
3304 two bits of the instruction.
3306 R_CAI:
3307 The PowerPC ABI defines this as an absolute call which
3308 may be modified to become a relative call. The PowerOpen
3309 ABI does not define this relocation type.
3311 R_RBA:
3312 Absolute branch which may be modified to become a
3313 relative branch.
3315 R_RBAC:
3316 The PowerPC ABI defines this as an absolute branch to a
3317 fixed address which may be modified to an absolute branch
3318 to a symbol. The PowerOpen ABI does not define this
3319 relocation type.
3321 R_RBRC:
3322 The PowerPC ABI defines this as an absolute branch to a
3323 fixed address which may be modified to a relative branch.
3324 The PowerOpen ABI does not define this relocation type.
3326 R_BR:
3327 Relative branch. We don't want to mess with the lower
3328 two bits of the instruction.
3330 R_CREL:
3331 The PowerPC ABI defines this as a relative call which may
3332 be modified to become an absolute call. The PowerOpen
3333 ABI does not define this relocation type.
3335 R_RBR:
3336 A relative branch which may be modified to become an
3337 absolute branch.
3339 R_RL:
3340 The PowerPC AIX ABI describes this as a load which may be
3341 changed to a load address. The PowerOpen ABI says this
3342 is the same as case R_POS.
3344 R_RLA:
3345 The PowerPC AIX ABI describes this as a load address
3346 which may be changed to a load. The PowerOpen ABI says
3347 this is the same as R_POS.
3350 bfd_boolean
3351 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
3352 input_section, contents, relocs, syms,
3353 sections)
3354 bfd *output_bfd;
3355 struct bfd_link_info *info;
3356 bfd *input_bfd;
3357 asection *input_section;
3358 bfd_byte *contents;
3359 struct internal_reloc *relocs;
3360 struct internal_syment *syms;
3361 asection **sections;
3363 struct internal_reloc *rel;
3364 struct internal_reloc *relend;
3366 rel = relocs;
3367 relend = rel + input_section->reloc_count;
3368 for (; rel < relend; rel++)
3370 long symndx;
3371 struct xcoff_link_hash_entry *h;
3372 struct internal_syment *sym;
3373 bfd_vma addend;
3374 bfd_vma val;
3375 struct reloc_howto_struct howto;
3376 bfd_vma relocation;
3377 bfd_vma value_to_relocate;
3378 bfd_vma address;
3379 bfd_byte *location;
3381 /* Relocation type R_REF is a special relocation type which is
3382 merely used to prevent garbage collection from occurring for
3383 the csect including the symbol which it references. */
3384 if (rel->r_type == R_REF)
3385 continue;
3387 /* howto */
3388 howto.type = rel->r_type;
3389 howto.rightshift = 0;
3390 howto.bitsize = (rel->r_size & 0x1f) + 1;
3391 howto.size = howto.bitsize > 16 ? 2 : 1;
3392 howto.pc_relative = FALSE;
3393 howto.bitpos = 0;
3394 howto.complain_on_overflow = (rel->r_size & 0x80
3395 ? complain_overflow_signed
3396 : complain_overflow_bitfield);
3397 howto.special_function = NULL;
3398 howto.name = "internal";
3399 howto.partial_inplace = TRUE;
3400 howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
3401 howto.pcrel_offset = FALSE;
3403 /* symbol */
3404 val = 0;
3405 addend = 0;
3406 h = NULL;
3407 sym = NULL;
3408 symndx = rel->r_symndx;
3410 if (-1 != symndx)
3412 asection *sec;
3414 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3415 sym = syms + symndx;
3416 addend = - sym->n_value;
3418 if (NULL == h)
3420 sec = sections[symndx];
3421 /* Hack to make sure we use the right TOC anchor value
3422 if this reloc is against the TOC anchor. */
3423 if (sec->name[3] == '0'
3424 && strcmp (sec->name, ".tc0") == 0)
3425 val = xcoff_data (output_bfd)->toc;
3426 else
3427 val = (sec->output_section->vma
3428 + sec->output_offset
3429 + sym->n_value
3430 - sec->vma);
3432 else
3434 if (info->unresolved_syms_in_objects != RM_IGNORE
3435 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3437 if (! ((*info->callbacks->undefined_symbol)
3438 (info, h->root.root.string,
3439 input_bfd, input_section,
3440 rel->r_vaddr - input_section->vma,
3441 (info->unresolved_syms_in_objects
3442 == RM_GENERATE_ERROR))))
3443 return FALSE;
3445 if (h->root.type == bfd_link_hash_defined
3446 || h->root.type == bfd_link_hash_defweak)
3448 sec = h->root.u.def.section;
3449 val = (h->root.u.def.value
3450 + sec->output_section->vma
3451 + sec->output_offset);
3453 else if (h->root.type == bfd_link_hash_common)
3455 sec = h->root.u.c.p->section;
3456 val = (sec->output_section->vma
3457 + sec->output_offset);
3460 else
3462 BFD_ASSERT (info->relocatable
3463 || (info->static_link
3464 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3465 || (h->flags & XCOFF_DEF_DYNAMIC) != 0
3466 || (h->flags & XCOFF_IMPORT) != 0);
3471 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3472 || !((*xcoff_calculate_relocation[rel->r_type])
3473 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3474 addend, &relocation, contents)))
3475 return FALSE;
3477 /* address */
3478 address = rel->r_vaddr - input_section->vma;
3479 location = contents + address;
3481 if (address > input_section->size)
3482 abort ();
3484 /* Get the value we are going to relocate. */
3485 if (1 == howto.size)
3486 value_to_relocate = bfd_get_16 (input_bfd, location);
3487 else
3488 value_to_relocate = bfd_get_32 (input_bfd, location);
3490 /* overflow.
3492 FIXME: We may drop bits during the addition
3493 which we don't check for. We must either check at every single
3494 operation, which would be tedious, or we must do the computations
3495 in a type larger than bfd_vma, which would be inefficient. */
3497 if ((unsigned int) howto.complain_on_overflow
3498 >= XCOFF_MAX_COMPLAIN_OVERFLOW)
3499 abort ();
3501 if (((*xcoff_complain_overflow[howto.complain_on_overflow])
3502 (input_bfd, value_to_relocate, relocation, &howto)))
3504 const char *name;
3505 char buf[SYMNMLEN + 1];
3506 char reloc_type_name[10];
3508 if (symndx == -1)
3510 name = "*ABS*";
3512 else if (h != NULL)
3514 name = NULL;
3516 else
3518 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3519 if (name == NULL)
3520 name = "UNKNOWN";
3522 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3524 if (! ((*info->callbacks->reloc_overflow)
3525 (info, (h ? &h->root : NULL), name, reloc_type_name,
3526 (bfd_vma) 0, input_bfd, input_section,
3527 rel->r_vaddr - input_section->vma)))
3528 return FALSE;
3531 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3532 value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
3533 | (((value_to_relocate & howto.src_mask)
3534 + relocation) & howto.dst_mask));
3536 /* Put the value back in the object file. */
3537 if (1 == howto.size)
3538 bfd_put_16 (input_bfd, value_to_relocate, location);
3539 else
3540 bfd_put_32 (input_bfd, value_to_relocate, location);
3543 return TRUE;
3546 static bfd_boolean
3547 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
3548 bfd *abfd ATTRIBUTE_UNUSED;
3549 struct xcoff_loader_info *ldinfo;
3550 struct internal_ldsym *ldsym;
3551 const char *name;
3553 size_t len;
3554 len = strlen (name);
3556 if (len <= SYMNMLEN)
3557 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3558 else
3560 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3562 bfd_size_type newalc;
3563 char *newstrings;
3565 newalc = ldinfo->string_alc * 2;
3566 if (newalc == 0)
3567 newalc = 32;
3568 while (ldinfo->string_size + len + 3 > newalc)
3569 newalc *= 2;
3571 newstrings = bfd_realloc (ldinfo->strings, newalc);
3572 if (newstrings == NULL)
3574 ldinfo->failed = TRUE;
3575 return FALSE;
3577 ldinfo->string_alc = newalc;
3578 ldinfo->strings = newstrings;
3581 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3582 ldinfo->strings + ldinfo->string_size);
3583 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3584 ldsym->_l._l_l._l_zeroes = 0;
3585 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3586 ldinfo->string_size += len + 3;
3589 return TRUE;
3592 static bfd_boolean
3593 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3594 struct internal_syment *sym,
3595 const char *name)
3597 if (strlen (name) <= SYMNMLEN)
3599 strncpy (sym->_n._n_name, name, SYMNMLEN);
3601 else
3603 bfd_boolean hash;
3604 bfd_size_type indx;
3606 hash = TRUE;
3607 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3608 hash = FALSE;
3609 indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
3610 if (indx == (bfd_size_type) -1)
3611 return FALSE;
3612 sym->_n._n_n._n_zeroes = 0;
3613 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3615 return TRUE;
3618 static asection *
3619 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
3620 bfd *abfd;
3621 union internal_auxent *aux;
3622 const char *symbol_name;
3624 asection *return_value = NULL;
3626 /* .sv64 = x_smclas == 17
3627 This is an invalid csect for 32 bit apps. */
3628 static const char *names[19] =
3630 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3631 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
3632 ".td", NULL, ".sv3264"
3635 if ((19 >= aux->x_csect.x_smclas)
3636 && (NULL != names[aux->x_csect.x_smclas]))
3638 return_value = bfd_make_section_anyway
3639 (abfd, names[aux->x_csect.x_smclas]);
3641 else
3643 (*_bfd_error_handler)
3644 (_("%B: symbol `%s' has unrecognized smclas %d"),
3645 abfd, symbol_name, aux->x_csect.x_smclas);
3646 bfd_set_error (bfd_error_bad_value);
3649 return return_value;
3652 static bfd_boolean
3653 xcoff_is_lineno_count_overflow (abfd, value)
3654 bfd *abfd ATTRIBUTE_UNUSED;
3655 bfd_vma value;
3657 if (0xffff <= value)
3658 return TRUE;
3660 return FALSE;
3663 static bfd_boolean
3664 xcoff_is_reloc_count_overflow (abfd, value)
3665 bfd *abfd ATTRIBUTE_UNUSED;
3666 bfd_vma value;
3668 if (0xffff <= value)
3669 return TRUE;
3671 return FALSE;
3674 static bfd_vma
3675 xcoff_loader_symbol_offset (abfd, ldhdr)
3676 bfd *abfd;
3677 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
3679 return bfd_xcoff_ldhdrsz (abfd);
3682 static bfd_vma
3683 xcoff_loader_reloc_offset (abfd, ldhdr)
3684 bfd *abfd;
3685 struct internal_ldhdr *ldhdr;
3687 return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
3690 static bfd_boolean
3691 xcoff_generate_rtinit (abfd, init, fini, rtld)
3692 bfd *abfd;
3693 const char *init;
3694 const char *fini;
3695 bfd_boolean rtld;
3697 bfd_byte filehdr_ext[FILHSZ];
3698 bfd_byte scnhdr_ext[SCNHSZ];
3699 bfd_byte syment_ext[SYMESZ * 10];
3700 bfd_byte reloc_ext[RELSZ * 3];
3701 bfd_byte *data_buffer;
3702 bfd_size_type data_buffer_size;
3703 bfd_byte *string_table = NULL, *st_tmp = NULL;
3704 bfd_size_type string_table_size;
3705 bfd_vma val;
3706 size_t initsz, finisz;
3707 struct internal_filehdr filehdr;
3708 struct internal_scnhdr scnhdr;
3709 struct internal_syment syment;
3710 union internal_auxent auxent;
3711 struct internal_reloc reloc;
3713 char *data_name = ".data";
3714 char *rtinit_name = "__rtinit";
3715 char *rtld_name = "__rtld";
3717 if (! bfd_xcoff_rtinit_size (abfd))
3718 return FALSE;
3720 initsz = (init == NULL ? 0 : 1 + strlen (init));
3721 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3723 /* file header */
3724 memset (filehdr_ext, 0, FILHSZ);
3725 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3726 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3727 filehdr.f_nscns = 1;
3728 filehdr.f_timdat = 0;
3729 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3730 filehdr.f_symptr = 0; /* set below */
3731 filehdr.f_opthdr = 0;
3732 filehdr.f_flags = 0;
3734 /* section header */
3735 memset (scnhdr_ext, 0, SCNHSZ);
3736 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3737 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3738 scnhdr.s_paddr = 0;
3739 scnhdr.s_vaddr = 0;
3740 scnhdr.s_size = 0; /* set below */
3741 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3742 scnhdr.s_relptr = 0; /* set below */
3743 scnhdr.s_lnnoptr = 0;
3744 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3745 scnhdr.s_nlnno = 0;
3746 scnhdr.s_flags = STYP_DATA;
3748 /* .data
3749 0x0000 0x00000000 : rtl
3750 0x0004 0x00000010 : offset to init, or 0
3751 0x0008 0x00000028 : offset to fini, or 0
3752 0x000C 0x0000000C : size of descriptor
3753 0x0010 0x00000000 : init, needs a reloc
3754 0x0014 0x00000040 : offset to init name
3755 0x0018 0x00000000 : flags, padded to a word
3756 0x001C 0x00000000 : empty init
3757 0x0020 0x00000000 :
3758 0x0024 0x00000000 :
3759 0x0028 0x00000000 : fini, needs a reloc
3760 0x002C 0x00000??? : offset to fini name
3761 0x0030 0x00000000 : flags, padded to a word
3762 0x0034 0x00000000 : empty fini
3763 0x0038 0x00000000 :
3764 0x003C 0x00000000 :
3765 0x0040 init name
3766 0x0040 + initsz fini name */
3768 data_buffer_size = 0x0040 + initsz + finisz;
3769 data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
3770 data_buffer = NULL;
3771 data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
3772 if (data_buffer == NULL)
3773 return FALSE;
3775 if (initsz)
3777 val = 0x10;
3778 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3779 val = 0x40;
3780 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3781 memcpy (&data_buffer[val], init, initsz);
3784 if (finisz)
3786 val = 0x28;
3787 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3788 val = 0x40 + initsz;
3789 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3790 memcpy (&data_buffer[val], fini, finisz);
3793 val = 0x0C;
3794 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3796 scnhdr.s_size = data_buffer_size;
3798 /* string table */
3799 string_table_size = 0;
3800 if (initsz > 9)
3801 string_table_size += initsz;
3802 if (finisz > 9)
3803 string_table_size += finisz;
3804 if (string_table_size)
3806 string_table_size += 4;
3807 string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
3808 if (string_table == NULL)
3809 return FALSE;
3811 val = string_table_size;
3812 bfd_h_put_32 (abfd, val, &string_table[0]);
3813 st_tmp = string_table + 4;
3816 /* symbols
3817 0. .data csect
3818 2. __rtinit
3819 4. init function
3820 6. fini function
3821 8. __rtld */
3822 memset (syment_ext, 0, 10 * SYMESZ);
3823 memset (reloc_ext, 0, 3 * RELSZ);
3825 /* .data csect */
3826 memset (&syment, 0, sizeof (struct internal_syment));
3827 memset (&auxent, 0, sizeof (union internal_auxent));
3828 memcpy (syment._n._n_name, data_name, strlen (data_name));
3829 syment.n_scnum = 1;
3830 syment.n_sclass = C_HIDEXT;
3831 syment.n_numaux = 1;
3832 auxent.x_csect.x_scnlen.l = data_buffer_size;
3833 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3834 auxent.x_csect.x_smclas = XMC_RW;
3835 bfd_coff_swap_sym_out (abfd, &syment,
3836 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3837 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3838 syment.n_numaux,
3839 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3840 filehdr.f_nsyms += 2;
3842 /* __rtinit */
3843 memset (&syment, 0, sizeof (struct internal_syment));
3844 memset (&auxent, 0, sizeof (union internal_auxent));
3845 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3846 syment.n_scnum = 1;
3847 syment.n_sclass = C_EXT;
3848 syment.n_numaux = 1;
3849 auxent.x_csect.x_smtyp = XTY_LD;
3850 auxent.x_csect.x_smclas = XMC_RW;
3851 bfd_coff_swap_sym_out (abfd, &syment,
3852 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3853 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3854 syment.n_numaux,
3855 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3856 filehdr.f_nsyms += 2;
3858 /* init */
3859 if (initsz)
3861 memset (&syment, 0, sizeof (struct internal_syment));
3862 memset (&auxent, 0, sizeof (union internal_auxent));
3864 if (initsz > 9)
3866 syment._n._n_n._n_offset = st_tmp - string_table;
3867 memcpy (st_tmp, init, initsz);
3868 st_tmp += initsz;
3870 else
3871 memcpy (syment._n._n_name, init, initsz - 1);
3873 syment.n_sclass = C_EXT;
3874 syment.n_numaux = 1;
3875 bfd_coff_swap_sym_out (abfd, &syment,
3876 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3877 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3878 syment.n_numaux,
3879 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3881 /* reloc */
3882 memset (&reloc, 0, sizeof (struct internal_reloc));
3883 reloc.r_vaddr = 0x0010;
3884 reloc.r_symndx = filehdr.f_nsyms;
3885 reloc.r_type = R_POS;
3886 reloc.r_size = 31;
3887 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3889 filehdr.f_nsyms += 2;
3890 scnhdr.s_nreloc += 1;
3893 /* fini */
3894 if (finisz)
3896 memset (&syment, 0, sizeof (struct internal_syment));
3897 memset (&auxent, 0, sizeof (union internal_auxent));
3899 if (finisz > 9)
3901 syment._n._n_n._n_offset = st_tmp - string_table;
3902 memcpy (st_tmp, fini, finisz);
3903 st_tmp += finisz;
3905 else
3906 memcpy (syment._n._n_name, fini, finisz - 1);
3908 syment.n_sclass = C_EXT;
3909 syment.n_numaux = 1;
3910 bfd_coff_swap_sym_out (abfd, &syment,
3911 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3912 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3913 syment.n_numaux,
3914 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3916 /* reloc */
3917 memset (&reloc, 0, sizeof (struct internal_reloc));
3918 reloc.r_vaddr = 0x0028;
3919 reloc.r_symndx = filehdr.f_nsyms;
3920 reloc.r_type = R_POS;
3921 reloc.r_size = 31;
3922 bfd_coff_swap_reloc_out (abfd, &reloc,
3923 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3925 filehdr.f_nsyms += 2;
3926 scnhdr.s_nreloc += 1;
3929 if (rtld)
3931 memset (&syment, 0, sizeof (struct internal_syment));
3932 memset (&auxent, 0, sizeof (union internal_auxent));
3933 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3934 syment.n_sclass = C_EXT;
3935 syment.n_numaux = 1;
3936 bfd_coff_swap_sym_out (abfd, &syment,
3937 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3938 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3939 syment.n_numaux,
3940 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3942 /* reloc */
3943 memset (&reloc, 0, sizeof (struct internal_reloc));
3944 reloc.r_vaddr = 0x0000;
3945 reloc.r_symndx = filehdr.f_nsyms;
3946 reloc.r_type = R_POS;
3947 reloc.r_size = 31;
3948 bfd_coff_swap_reloc_out (abfd, &reloc,
3949 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3951 filehdr.f_nsyms += 2;
3952 scnhdr.s_nreloc += 1;
3955 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3956 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3958 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3959 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3960 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3961 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3962 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3963 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3964 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3965 bfd_bwrite (string_table, string_table_size, abfd);
3967 free (data_buffer);
3968 data_buffer = NULL;
3970 return TRUE;
3974 static reloc_howto_type xcoff_dynamic_reloc =
3975 HOWTO (0, /* type */
3976 0, /* rightshift */
3977 2, /* size (0 = byte, 1 = short, 2 = long) */
3978 32, /* bitsize */
3979 FALSE, /* pc_relative */
3980 0, /* bitpos */
3981 complain_overflow_bitfield, /* complain_on_overflow */
3982 0, /* special_function */
3983 "R_POS", /* name */
3984 TRUE, /* partial_inplace */
3985 0xffffffff, /* src_mask */
3986 0xffffffff, /* dst_mask */
3987 FALSE); /* pcrel_offset */
3989 /* glink
3991 The first word of global linkage code must be modified by filling in
3992 the correct TOC offset. */
3994 static unsigned long xcoff_glink_code[9] =
3996 0x81820000, /* lwz r12,0(r2) */
3997 0x90410014, /* stw r2,20(r1) */
3998 0x800c0000, /* lwz r0,0(r12) */
3999 0x804c0004, /* lwz r2,4(r12) */
4000 0x7c0903a6, /* mtctr r0 */
4001 0x4e800420, /* bctr */
4002 0x00000000, /* start of traceback table */
4003 0x000c8000, /* traceback table */
4004 0x00000000, /* traceback table */
4008 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
4010 { /* COFF backend, defined in libcoff.h. */
4011 _bfd_xcoff_swap_aux_in,
4012 _bfd_xcoff_swap_sym_in,
4013 coff_swap_lineno_in,
4014 _bfd_xcoff_swap_aux_out,
4015 _bfd_xcoff_swap_sym_out,
4016 coff_swap_lineno_out,
4017 xcoff_swap_reloc_out,
4018 coff_swap_filehdr_out,
4019 coff_swap_aouthdr_out,
4020 coff_swap_scnhdr_out,
4021 FILHSZ,
4022 AOUTSZ,
4023 SCNHSZ,
4024 SYMESZ,
4025 AUXESZ,
4026 RELSZ,
4027 LINESZ,
4028 FILNMLEN,
4029 TRUE, /* _bfd_coff_long_filenames */
4030 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4031 3, /* _bfd_coff_default_section_alignment_power */
4032 FALSE, /* _bfd_coff_force_symnames_in_strings */
4033 2, /* _bfd_coff_debug_string_prefix_length */
4034 coff_swap_filehdr_in,
4035 coff_swap_aouthdr_in,
4036 coff_swap_scnhdr_in,
4037 xcoff_swap_reloc_in,
4038 coff_bad_format_hook,
4039 coff_set_arch_mach_hook,
4040 coff_mkobject_hook,
4041 styp_to_sec_flags,
4042 coff_set_alignment_hook,
4043 coff_slurp_symbol_table,
4044 symname_in_debug_hook,
4045 coff_pointerize_aux_hook,
4046 coff_print_aux,
4047 dummy_reloc16_extra_cases,
4048 dummy_reloc16_estimate,
4049 NULL, /* bfd_coff_sym_is_global */
4050 coff_compute_section_file_positions,
4051 NULL, /* _bfd_coff_start_final_link */
4052 xcoff_ppc_relocate_section,
4053 coff_rtype_to_howto,
4054 NULL, /* _bfd_coff_adjust_symndx */
4055 _bfd_generic_link_add_one_symbol,
4056 coff_link_output_has_begun,
4057 coff_final_link_postscript,
4058 NULL /* print_pdata. */
4061 0x01DF, /* magic number */
4062 bfd_arch_rs6000,
4063 bfd_mach_rs6k,
4065 /* Function pointers to xcoff specific swap routines. */
4066 xcoff_swap_ldhdr_in,
4067 xcoff_swap_ldhdr_out,
4068 xcoff_swap_ldsym_in,
4069 xcoff_swap_ldsym_out,
4070 xcoff_swap_ldrel_in,
4071 xcoff_swap_ldrel_out,
4073 /* Sizes. */
4074 LDHDRSZ,
4075 LDSYMSZ,
4076 LDRELSZ,
4077 12, /* _xcoff_function_descriptor_size */
4078 SMALL_AOUTSZ,
4080 /* Versions. */
4081 1, /* _xcoff_ldhdr_version */
4083 _bfd_xcoff_put_symbol_name,
4084 _bfd_xcoff_put_ldsymbol_name,
4085 &xcoff_dynamic_reloc,
4086 xcoff_create_csect_from_smclas,
4088 /* Lineno and reloc count overflow. */
4089 xcoff_is_lineno_count_overflow,
4090 xcoff_is_reloc_count_overflow,
4092 xcoff_loader_symbol_offset,
4093 xcoff_loader_reloc_offset,
4095 /* glink. */
4096 &xcoff_glink_code[0],
4097 36, /* _xcoff_glink_size */
4099 /* rtinit */
4100 64, /* _xcoff_rtinit_size */
4101 xcoff_generate_rtinit,
4104 /* The transfer vector that leads the outside world to all of the above. */
4105 const bfd_target rs6000coff_vec =
4107 "aixcoff-rs6000",
4108 bfd_target_xcoff_flavour,
4109 BFD_ENDIAN_BIG, /* data byte order is big */
4110 BFD_ENDIAN_BIG, /* header byte order is big */
4112 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4113 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4115 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4116 0, /* leading char */
4117 '/', /* ar_pad_char */
4118 15, /* ar_max_namelen */
4120 /* data */
4121 bfd_getb64,
4122 bfd_getb_signed_64,
4123 bfd_putb64,
4124 bfd_getb32,
4125 bfd_getb_signed_32,
4126 bfd_putb32,
4127 bfd_getb16,
4128 bfd_getb_signed_16,
4129 bfd_putb16,
4131 /* hdrs */
4132 bfd_getb64,
4133 bfd_getb_signed_64,
4134 bfd_putb64,
4135 bfd_getb32,
4136 bfd_getb_signed_32,
4137 bfd_putb32,
4138 bfd_getb16,
4139 bfd_getb_signed_16,
4140 bfd_putb16,
4142 { /* bfd_check_format */
4143 _bfd_dummy_target,
4144 coff_object_p,
4145 _bfd_xcoff_archive_p,
4146 CORE_FILE_P
4149 { /* bfd_set_format */
4150 bfd_false,
4151 coff_mkobject,
4152 _bfd_generic_mkarchive,
4153 bfd_false
4156 {/* bfd_write_contents */
4157 bfd_false,
4158 coff_write_object_contents,
4159 _bfd_xcoff_write_archive_contents,
4160 bfd_false
4163 /* Generic */
4164 bfd_true,
4165 bfd_true,
4166 coff_new_section_hook,
4167 _bfd_generic_get_section_contents,
4168 _bfd_generic_get_section_contents_in_window,
4170 /* Copy */
4171 _bfd_xcoff_copy_private_bfd_data,
4172 ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
4173 _bfd_generic_init_private_section_data,
4174 ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4175 ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4176 ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
4177 ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
4178 ((bfd_boolean (*) (bfd *, void * )) bfd_true),
4180 /* Core */
4181 coff_core_file_failing_command,
4182 coff_core_file_failing_signal,
4183 coff_core_file_matches_executable_p,
4185 /* Archive */
4186 _bfd_xcoff_slurp_armap,
4187 bfd_false,
4188 ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4189 bfd_dont_truncate_arname,
4190 _bfd_xcoff_write_armap,
4191 _bfd_xcoff_read_ar_hdr,
4192 _bfd_xcoff_openr_next_archived_file,
4193 _bfd_generic_get_elt_at_index,
4194 _bfd_xcoff_stat_arch_elt,
4195 bfd_true,
4197 /* Symbols */
4198 coff_get_symtab_upper_bound,
4199 coff_canonicalize_symtab,
4200 coff_make_empty_symbol,
4201 coff_print_symbol,
4202 coff_get_symbol_info,
4203 _bfd_xcoff_is_local_label_name,
4204 coff_bfd_is_target_special_symbol,
4205 coff_get_lineno,
4206 coff_find_nearest_line,
4207 _bfd_generic_find_line,
4208 coff_find_inliner_info,
4209 coff_bfd_make_debug_symbol,
4210 _bfd_generic_read_minisymbols,
4211 _bfd_generic_minisymbol_to_symbol,
4213 /* Reloc */
4214 coff_get_reloc_upper_bound,
4215 coff_canonicalize_reloc,
4216 _bfd_xcoff_reloc_type_lookup,
4217 _bfd_xcoff_reloc_name_lookup,
4219 /* Write */
4220 coff_set_arch_mach,
4221 coff_set_section_contents,
4223 /* Link */
4224 _bfd_xcoff_sizeof_headers,
4225 bfd_generic_get_relocated_section_contents,
4226 bfd_generic_relax_section,
4227 _bfd_xcoff_bfd_link_hash_table_create,
4228 _bfd_generic_link_hash_table_free,
4229 _bfd_xcoff_bfd_link_add_symbols,
4230 _bfd_generic_link_just_syms,
4231 _bfd_xcoff_bfd_final_link,
4232 _bfd_generic_link_split_section,
4233 bfd_generic_gc_sections,
4234 bfd_generic_merge_sections,
4235 bfd_generic_is_group_section,
4236 bfd_generic_discard_group,
4237 _bfd_generic_section_already_linked,
4238 _bfd_xcoff_define_common_symbol,
4240 /* Dynamic */
4241 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4242 _bfd_xcoff_canonicalize_dynamic_symtab,
4243 _bfd_nodynamic_get_synthetic_symtab,
4244 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4245 _bfd_xcoff_canonicalize_dynamic_reloc,
4247 /* Opposite endian version, none exists */
4248 NULL,
4250 (void *) &bfd_xcoff_backend_data,
4253 /* xcoff-powermac target
4254 Old target.
4255 Only difference between this target and the rs6000 target is the
4256 the default architecture and machine type used in coffcode.h
4258 PowerPC Macs use the same magic numbers as RS/6000
4259 (because that's how they were bootstrapped originally),
4260 but they are always PowerPC architecture. */
4261 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4263 { /* COFF backend, defined in libcoff.h. */
4264 _bfd_xcoff_swap_aux_in,
4265 _bfd_xcoff_swap_sym_in,
4266 coff_swap_lineno_in,
4267 _bfd_xcoff_swap_aux_out,
4268 _bfd_xcoff_swap_sym_out,
4269 coff_swap_lineno_out,
4270 xcoff_swap_reloc_out,
4271 coff_swap_filehdr_out,
4272 coff_swap_aouthdr_out,
4273 coff_swap_scnhdr_out,
4274 FILHSZ,
4275 AOUTSZ,
4276 SCNHSZ,
4277 SYMESZ,
4278 AUXESZ,
4279 RELSZ,
4280 LINESZ,
4281 FILNMLEN,
4282 TRUE, /* _bfd_coff_long_filenames */
4283 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4284 3, /* _bfd_coff_default_section_alignment_power */
4285 FALSE, /* _bfd_coff_force_symnames_in_strings */
4286 2, /* _bfd_coff_debug_string_prefix_length */
4287 coff_swap_filehdr_in,
4288 coff_swap_aouthdr_in,
4289 coff_swap_scnhdr_in,
4290 xcoff_swap_reloc_in,
4291 coff_bad_format_hook,
4292 coff_set_arch_mach_hook,
4293 coff_mkobject_hook,
4294 styp_to_sec_flags,
4295 coff_set_alignment_hook,
4296 coff_slurp_symbol_table,
4297 symname_in_debug_hook,
4298 coff_pointerize_aux_hook,
4299 coff_print_aux,
4300 dummy_reloc16_extra_cases,
4301 dummy_reloc16_estimate,
4302 NULL, /* bfd_coff_sym_is_global */
4303 coff_compute_section_file_positions,
4304 NULL, /* _bfd_coff_start_final_link */
4305 xcoff_ppc_relocate_section,
4306 coff_rtype_to_howto,
4307 NULL, /* _bfd_coff_adjust_symndx */
4308 _bfd_generic_link_add_one_symbol,
4309 coff_link_output_has_begun,
4310 coff_final_link_postscript,
4311 NULL /* print_pdata. */
4314 0x01DF, /* magic number */
4315 bfd_arch_powerpc,
4316 bfd_mach_ppc,
4318 /* Function pointers to xcoff specific swap routines. */
4319 xcoff_swap_ldhdr_in,
4320 xcoff_swap_ldhdr_out,
4321 xcoff_swap_ldsym_in,
4322 xcoff_swap_ldsym_out,
4323 xcoff_swap_ldrel_in,
4324 xcoff_swap_ldrel_out,
4326 /* Sizes. */
4327 LDHDRSZ,
4328 LDSYMSZ,
4329 LDRELSZ,
4330 12, /* _xcoff_function_descriptor_size */
4331 SMALL_AOUTSZ,
4333 /* Versions. */
4334 1, /* _xcoff_ldhdr_version */
4336 _bfd_xcoff_put_symbol_name,
4337 _bfd_xcoff_put_ldsymbol_name,
4338 &xcoff_dynamic_reloc,
4339 xcoff_create_csect_from_smclas,
4341 /* Lineno and reloc count overflow. */
4342 xcoff_is_lineno_count_overflow,
4343 xcoff_is_reloc_count_overflow,
4345 xcoff_loader_symbol_offset,
4346 xcoff_loader_reloc_offset,
4348 /* glink. */
4349 &xcoff_glink_code[0],
4350 36, /* _xcoff_glink_size */
4352 /* rtinit */
4353 0, /* _xcoff_rtinit_size */
4354 xcoff_generate_rtinit,
4357 /* The transfer vector that leads the outside world to all of the above. */
4358 const bfd_target pmac_xcoff_vec =
4360 "xcoff-powermac",
4361 bfd_target_xcoff_flavour,
4362 BFD_ENDIAN_BIG, /* data byte order is big */
4363 BFD_ENDIAN_BIG, /* header byte order is big */
4365 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4366 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4368 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4369 0, /* leading char */
4370 '/', /* ar_pad_char */
4371 15, /* ar_max_namelen */
4373 /* data */
4374 bfd_getb64,
4375 bfd_getb_signed_64,
4376 bfd_putb64,
4377 bfd_getb32,
4378 bfd_getb_signed_32,
4379 bfd_putb32,
4380 bfd_getb16,
4381 bfd_getb_signed_16,
4382 bfd_putb16,
4384 /* hdrs */
4385 bfd_getb64,
4386 bfd_getb_signed_64,
4387 bfd_putb64,
4388 bfd_getb32,
4389 bfd_getb_signed_32,
4390 bfd_putb32,
4391 bfd_getb16,
4392 bfd_getb_signed_16,
4393 bfd_putb16,
4395 { /* bfd_check_format */
4396 _bfd_dummy_target,
4397 coff_object_p,
4398 _bfd_xcoff_archive_p,
4399 CORE_FILE_P
4402 { /* bfd_set_format */
4403 bfd_false,
4404 coff_mkobject,
4405 _bfd_generic_mkarchive,
4406 bfd_false
4409 {/* bfd_write_contents */
4410 bfd_false,
4411 coff_write_object_contents,
4412 _bfd_xcoff_write_archive_contents,
4413 bfd_false
4416 /* Generic */
4417 bfd_true,
4418 bfd_true,
4419 coff_new_section_hook,
4420 _bfd_generic_get_section_contents,
4421 _bfd_generic_get_section_contents_in_window,
4423 /* Copy */
4424 _bfd_xcoff_copy_private_bfd_data,
4425 ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
4426 _bfd_generic_init_private_section_data,
4427 ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4428 ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4429 ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
4430 ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
4431 ((bfd_boolean (*) (bfd *, void * )) bfd_true),
4433 /* Core */
4434 coff_core_file_failing_command,
4435 coff_core_file_failing_signal,
4436 coff_core_file_matches_executable_p,
4438 /* Archive */
4439 _bfd_xcoff_slurp_armap,
4440 bfd_false,
4441 ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4442 bfd_dont_truncate_arname,
4443 _bfd_xcoff_write_armap,
4444 _bfd_xcoff_read_ar_hdr,
4445 _bfd_xcoff_openr_next_archived_file,
4446 _bfd_generic_get_elt_at_index,
4447 _bfd_xcoff_stat_arch_elt,
4448 bfd_true,
4450 /* Symbols */
4451 coff_get_symtab_upper_bound,
4452 coff_canonicalize_symtab,
4453 coff_make_empty_symbol,
4454 coff_print_symbol,
4455 coff_get_symbol_info,
4456 _bfd_xcoff_is_local_label_name,
4457 coff_bfd_is_target_special_symbol,
4458 coff_get_lineno,
4459 coff_find_nearest_line,
4460 _bfd_generic_find_line,
4461 coff_find_inliner_info,
4462 coff_bfd_make_debug_symbol,
4463 _bfd_generic_read_minisymbols,
4464 _bfd_generic_minisymbol_to_symbol,
4466 /* Reloc */
4467 coff_get_reloc_upper_bound,
4468 coff_canonicalize_reloc,
4469 _bfd_xcoff_reloc_type_lookup,
4470 _bfd_xcoff_reloc_name_lookup,
4472 /* Write */
4473 coff_set_arch_mach,
4474 coff_set_section_contents,
4476 /* Link */
4477 _bfd_xcoff_sizeof_headers,
4478 bfd_generic_get_relocated_section_contents,
4479 bfd_generic_relax_section,
4480 _bfd_xcoff_bfd_link_hash_table_create,
4481 _bfd_generic_link_hash_table_free,
4482 _bfd_xcoff_bfd_link_add_symbols,
4483 _bfd_generic_link_just_syms,
4484 _bfd_xcoff_bfd_final_link,
4485 _bfd_generic_link_split_section,
4486 bfd_generic_gc_sections,
4487 bfd_generic_merge_sections,
4488 bfd_generic_is_group_section,
4489 bfd_generic_discard_group,
4490 _bfd_generic_section_already_linked,
4491 _bfd_xcoff_define_common_symbol,
4493 /* Dynamic */
4494 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4495 _bfd_xcoff_canonicalize_dynamic_symtab,
4496 _bfd_nodynamic_get_synthetic_symtab,
4497 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4498 _bfd_xcoff_canonicalize_dynamic_reloc,
4500 /* Opposite endian version, none exists */
4501 NULL,
4503 (void *) &bfd_pmac_xcoff_backend_data,