1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 FIXME: Can someone provide a transliteration of this name into ASCII?
6 Using the following chars caused a compiler warning on HIUX (so I replaced
7 them with octal escapes), and isn't useful without an understanding of what
9 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
11 Archive support from Damon A. Permezel.
12 Contributed by IBM Corporation and Cygnus Support.
14 This file is part of BFD, the Binary File Descriptor library.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #include "coff/internal.h"
35 #include "coff/xcoff.h"
36 #include "coff/rs6000.h"
40 extern const bfd_target
* rs6000coff_core_p ();
41 extern boolean
rs6000coff_core_file_matches_executable_p ();
42 extern char *rs6000coff_core_file_failing_command
PARAMS ((bfd
*abfd
));
43 extern int rs6000coff_core_file_failing_signal
PARAMS ((bfd
*abfd
));
44 extern boolean _bfd_xcoff_mkobject
PARAMS ((bfd
*));
45 extern boolean _bfd_xcoff_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
46 extern boolean _bfd_xcoff_is_local_label_name
PARAMS ((bfd
*, const char *));
47 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
48 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
49 extern boolean _bfd_xcoff_slurp_armap
PARAMS ((bfd
*));
50 extern const bfd_target
*_bfd_xcoff_archive_p
PARAMS ((bfd
*));
51 extern PTR _bfd_xcoff_read_ar_hdr
PARAMS ((bfd
*));
52 extern bfd
*_bfd_xcoff_openr_next_archived_file
PARAMS ((bfd
*, bfd
*));
53 extern int _bfd_xcoff_generic_stat_arch_elt
PARAMS ((bfd
*, struct stat
*));
54 extern boolean _bfd_xcoff_write_armap
55 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
56 extern boolean _bfd_xcoff_write_archive_contents
PARAMS ((bfd
*));
57 extern int _bfd_xcoff_sizeof_headers
PARAMS ((bfd
*, boolean
));
58 extern void _bfd_xcoff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
59 extern unsigned int _bfd_xcoff_swap_sym_out
PARAMS ((bfd
*, PTR
, PTR
));
60 extern void _bfd_xcoff_swap_aux_in
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
61 extern unsigned int _bfd_xcoff_swap_aux_out
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
63 /* Forward declare _bfd_xcoff_rtype2howto for coffcode.h macro */
64 void _bfd_xcoff_rtype2howto
PARAMS ((arelent
*, struct internal_reloc
*));
66 /* coffcode.h needs these to be defined */
67 #define RS6000COFF_C 1
69 #define SELECT_RELOC(internal, howto) \
71 internal.r_type = howto->type; \
73 ((howto->complain_on_overflow == complain_overflow_signed \
76 | (howto->bitsize - 1)); \
79 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
80 #define COFF_LONG_FILENAMES
81 #define NO_COFF_SYMBOLS
82 #define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst)
83 #define coff_mkobject _bfd_xcoff_mkobject
84 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
85 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
86 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
87 #define CORE_FILE_P rs6000coff_core_p
88 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
89 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
90 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
91 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
95 /* The main body of code is in coffcode.h. */
97 static const char *normalize_filename
PARAMS ((bfd
*));
99 /* We use our own tdata type. Its first field is the COFF tdata type,
100 so the COFF routines are compatible. */
103 _bfd_xcoff_mkobject (abfd
)
106 coff_data_type
*coff
;
108 abfd
->tdata
.xcoff_obj_data
=
109 ((struct xcoff_tdata
*)
110 bfd_zalloc (abfd
, sizeof (struct xcoff_tdata
)));
111 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
113 coff
= coff_data (abfd
);
114 coff
->symbols
= (coff_symbol_type
*) NULL
;
115 coff
->conversion_table
= (unsigned int *) NULL
;
116 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
119 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
121 /* We set cputype to -1 to indicate that it has not been
123 xcoff_data (abfd
)->cputype
= -1;
125 xcoff_data (abfd
)->csects
= NULL
;
126 xcoff_data (abfd
)->debug_indices
= NULL
;
128 /* text section alignment is different than the default */
129 /* xcoff_data (abfd)->text_align_power = 5; */
134 /* Copy XCOFF data from one BFD to another. */
137 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
141 struct xcoff_tdata
*ix
, *ox
;
144 if (ibfd
->xvec
!= obfd
->xvec
)
146 ix
= xcoff_data (ibfd
);
147 ox
= xcoff_data (obfd
);
148 ox
->full_aouthdr
= ix
->full_aouthdr
;
154 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
158 ox
->sntoc
= sec
->output_section
->target_index
;
160 if (ix
->snentry
== 0)
164 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
168 ox
->snentry
= sec
->output_section
->target_index
;
170 ox
->text_align_power
= ix
->text_align_power
;
171 ox
->data_align_power
= ix
->data_align_power
;
172 ox
->modtype
= ix
->modtype
;
173 ox
->cputype
= ix
->cputype
;
174 ox
->maxdata
= ix
->maxdata
;
175 ox
->maxstack
= ix
->maxstack
;
179 /* I don't think XCOFF really has a notion of local labels based on
180 name. This will mean that ld -X doesn't actually strip anything.
181 The AIX native linker does not have a -X option, and it ignores the
185 _bfd_xcoff_is_local_label_name (abfd
, name
)
186 bfd
*abfd ATTRIBUTE_UNUSED
;
187 const char *name ATTRIBUTE_UNUSED
;
195 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
200 SYMENT
*ext
= (SYMENT
*)ext1
;
201 struct internal_syment
*in
= (struct internal_syment
*)in1
;
203 if(ext
->e
.e_name
[0] != 0) {
204 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
206 in
->_n
._n_n
._n_zeroes
= 0;
207 in
->_n
._n_n
._n_offset
=
208 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
211 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
212 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
213 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
214 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
215 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
219 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
224 struct internal_syment
*in
= (struct internal_syment
*)inp
;
225 SYMENT
*ext
=(SYMENT
*)extp
;
227 if(in
->_n
._n_name
[0] != 0) {
228 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
230 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
231 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
,
232 (bfd_byte
*) ext
->e
.e
.e_offset
);
235 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
236 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
237 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
238 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
239 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
240 return bfd_coff_symesz (abfd
);
243 #define PUTWORD bfd_h_put_32
244 #define PUTHALF bfd_h_put_16
245 #define PUTBYTE bfd_h_put_8
246 #define GETWORD bfd_h_get_32
247 #define GETHALF bfd_h_get_16
248 #define GETBYTE bfd_h_get_8
251 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
260 AUXENT
*ext
= (AUXENT
*)ext1
;
261 union internal_auxent
*in
= (union internal_auxent
*)in1
;
265 if (ext
->x_file
.x_fname
[0] == 0) {
266 in
->x_file
.x_n
.x_zeroes
= 0;
267 in
->x_file
.x_n
.x_offset
=
268 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
273 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
274 numaux
* sizeof (AUXENT
));
278 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
283 /* RS/6000 "csect" auxents */
286 if (indx
+ 1 == numaux
)
288 in
->x_csect
.x_scnlen
.l
=
289 bfd_h_get_32 (abfd
, ext
->x_csect
.x_scnlen
);
290 in
->x_csect
.x_parmhash
= bfd_h_get_32 (abfd
,
291 ext
->x_csect
.x_parmhash
);
292 in
->x_csect
.x_snhash
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snhash
);
293 /* We don't have to hack bitfields in x_smtyp because it's
294 defined by shifts-and-ands, which are equivalent on all
296 in
->x_csect
.x_smtyp
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smtyp
);
297 in
->x_csect
.x_smclas
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smclas
);
298 in
->x_csect
.x_stab
= bfd_h_get_32 (abfd
, ext
->x_csect
.x_stab
);
299 in
->x_csect
.x_snstab
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snstab
);
307 if (type
== T_NULL
) {
308 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
,
309 (bfd_byte
*) ext
->x_scn
.x_scnlen
);
310 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
,
311 (bfd_byte
*) ext
->x_scn
.x_nreloc
);
312 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
,
313 (bfd_byte
*) ext
->x_scn
.x_nlinno
);
314 /* PE defines some extra fields; we zero them out for
316 in
->x_scn
.x_checksum
= 0;
317 in
->x_scn
.x_associated
= 0;
318 in
->x_scn
.x_comdat
= 0;
325 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
326 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
328 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
330 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, (bfd_byte
*)
331 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
332 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*)
333 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
337 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
338 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
339 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
340 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
341 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
342 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
343 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
344 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
347 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
350 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, (bfd_byte
*)
351 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
352 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, (bfd_byte
*)
353 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
357 /* the semicolon is because MSVC doesn't like labels at
365 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
370 int indx ATTRIBUTE_UNUSED
;
371 int numaux ATTRIBUTE_UNUSED
;
374 union internal_auxent
*in
= (union internal_auxent
*)inp
;
375 AUXENT
*ext
= (AUXENT
*)extp
;
377 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
381 if (in
->x_file
.x_fname
[0] == 0)
383 PUTWORD(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
385 in
->x_file
.x_n
.x_offset
,
386 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
390 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
394 /* RS/6000 "csect" auxents */
397 if (indx
+ 1 == numaux
)
399 PUTWORD (abfd
, in
->x_csect
.x_scnlen
.l
,ext
->x_csect
.x_scnlen
);
400 PUTWORD (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
401 PUTHALF (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
402 /* We don't have to hack bitfields in x_smtyp because it's
403 defined by shifts-and-ands, which are equivalent on all
405 PUTBYTE (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
406 PUTBYTE (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
407 PUTWORD (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
408 PUTHALF (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
416 if (type
== T_NULL
) {
417 bfd_h_put_32(abfd
, in
->x_scn
.x_scnlen
, (bfd_byte
*) ext
->x_scn
.x_scnlen
);
418 bfd_h_put_16(abfd
, in
->x_scn
.x_nreloc
, (bfd_byte
*) ext
->x_scn
.x_nreloc
);
419 bfd_h_put_16(abfd
, in
->x_scn
.x_nlinno
, (bfd_byte
*) ext
->x_scn
.x_nlinno
);
425 PUTWORD(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
426 bfd_h_put_16 (abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
428 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
430 bfd_h_put_32(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
431 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
432 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
433 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
437 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
438 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
439 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
440 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
441 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
442 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
443 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
444 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
448 PUTWORD (abfd
, in
->x_sym
.x_misc
.x_fsize
,
449 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
452 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
453 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
454 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
455 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
459 return bfd_coff_auxesz (abfd
);
464 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
465 bitsize and whether they are signed or not, along with a
466 conventional type. This table is for the types, which are used for
467 different algorithms for putting in the reloc. Many of these
468 relocs need special_function entries, which I have not written. */
471 reloc_howto_type xcoff_howto_table
[] =
473 /* Standard 32 bit relocation. */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 false, /* pc_relative */
480 complain_overflow_bitfield
, /* complain_on_overflow */
481 0, /* special_function */
483 true, /* partial_inplace */
484 0xffffffff, /* src_mask */
485 0xffffffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* 32 bit relocation, but store negative value. */
491 -2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 0, /* special_function */
498 true, /* partial_inplace */
499 0xffffffff, /* src_mask */
500 0xffffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* 32 bit PC relative relocation. */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 true, /* pc_relative */
510 complain_overflow_signed
, /* complain_on_overflow */
511 0, /* special_function */
513 true, /* partial_inplace */
514 0xffffffff, /* src_mask */
515 0xffffffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* 16 bit TOC relative relocation. */
521 1, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_bitfield
, /* complain_on_overflow */
526 0, /* special_function */
528 true, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 false), /* pcrel_offset */
533 /* I don't really know what this is. */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 false, /* pc_relative */
540 complain_overflow_bitfield
, /* complain_on_overflow */
541 0, /* special_function */
543 true, /* partial_inplace */
544 0xffffffff, /* src_mask */
545 0xffffffff, /* dst_mask */
546 false), /* pcrel_offset */
548 /* External TOC relative symbol. */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_bitfield
, /* complain_on_overflow */
556 0, /* special_function */
558 true, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 false), /* pcrel_offset */
563 /* Local TOC relative symbol. */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_bitfield
, /* complain_on_overflow */
571 0, /* special_function */
573 true, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
580 /* Non modifiable absolute branch. */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_bitfield
, /* complain_on_overflow */
588 0, /* special_function */
590 true, /* partial_inplace */
591 0x3fffffc, /* src_mask */
592 0x3fffffc, /* dst_mask */
593 false), /* pcrel_offset */
597 /* Non modifiable relative branch. */
598 HOWTO (0xa, /* type */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
602 true, /* pc_relative */
604 complain_overflow_signed
, /* complain_on_overflow */
605 0, /* special_function */
607 true, /* partial_inplace */
608 0x3fffffc, /* src_mask */
609 0x3fffffc, /* dst_mask */
610 false), /* pcrel_offset */
615 HOWTO (0xc, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield
, /* complain_on_overflow */
622 0, /* special_function */
624 true, /* partial_inplace */
625 0xffff, /* src_mask */
626 0xffff, /* dst_mask */
627 false), /* pcrel_offset */
630 HOWTO (0xd, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 false, /* pc_relative */
636 complain_overflow_bitfield
, /* complain_on_overflow */
637 0, /* special_function */
639 true, /* partial_inplace */
640 0xffff, /* src_mask */
641 0xffff, /* dst_mask */
642 false), /* pcrel_offset */
646 /* Non-relocating reference. */
647 HOWTO (0xf, /* type */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_bitfield
, /* complain_on_overflow */
654 0, /* special_function */
656 false, /* partial_inplace */
659 false), /* pcrel_offset */
664 /* TOC relative indirect load. */
665 HOWTO (0x12, /* type */
667 2, /* size (0 = byte, 1 = short, 2 = long) */
669 false, /* pc_relative */
671 complain_overflow_bitfield
, /* complain_on_overflow */
672 0, /* special_function */
674 true, /* partial_inplace */
675 0xffff, /* src_mask */
676 0xffff, /* dst_mask */
677 false), /* pcrel_offset */
679 /* TOC relative load address. */
680 HOWTO (0x13, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 false, /* pc_relative */
686 complain_overflow_bitfield
, /* complain_on_overflow */
687 0, /* special_function */
689 true, /* partial_inplace */
690 0xffff, /* src_mask */
691 0xffff, /* dst_mask */
692 false), /* pcrel_offset */
694 /* Modifiable relative branch. */
695 HOWTO (0x14, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_bitfield
, /* complain_on_overflow */
702 0, /* special_function */
703 "R_RRTBI", /* name */
704 true, /* partial_inplace */
705 0xffffffff, /* src_mask */
706 0xffffffff, /* dst_mask */
707 false), /* pcrel_offset */
709 /* Modifiable absolute branch. */
710 HOWTO (0x15, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 false, /* pc_relative */
716 complain_overflow_bitfield
, /* complain_on_overflow */
717 0, /* special_function */
718 "R_RRTBA", /* name */
719 true, /* partial_inplace */
720 0xffffffff, /* src_mask */
721 0xffffffff, /* dst_mask */
722 false), /* pcrel_offset */
724 /* Modifiable call absolute indirect. */
725 HOWTO (0x16, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 0, /* special_function */
734 true, /* partial_inplace */
735 0xffff, /* src_mask */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* Modifiable call relative. */
740 HOWTO (0x17, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 0, /* special_function */
749 true, /* partial_inplace */
750 0xffff, /* src_mask */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
754 /* Modifiable branch absolute. */
755 HOWTO (0x18, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_bitfield
, /* complain_on_overflow */
762 0, /* special_function */
764 true, /* partial_inplace */
765 0xffff, /* src_mask */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* Modifiable branch absolute. */
770 HOWTO (0x19, /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 false, /* pc_relative */
776 complain_overflow_bitfield
, /* complain_on_overflow */
777 0, /* special_function */
779 true, /* partial_inplace */
780 0xffff, /* src_mask */
781 0xffff, /* dst_mask */
782 false), /* pcrel_offset */
784 /* Modifiable branch relative. */
785 HOWTO (0x1a, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 false, /* pc_relative */
791 complain_overflow_signed
, /* complain_on_overflow */
792 0, /* special_function */
794 true, /* partial_inplace */
795 0xffff, /* src_mask */
796 0xffff, /* dst_mask */
797 false), /* pcrel_offset */
799 /* Modifiable branch absolute. */
800 HOWTO (0x1b, /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 false, /* pc_relative */
806 complain_overflow_bitfield
, /* complain_on_overflow */
807 0, /* special_function */
809 true, /* partial_inplace */
810 0xffff, /* src_mask */
811 0xffff, /* dst_mask */
812 false), /* pcrel_offset */
816 4, /* size (0 = byte, 1 = short, 2 = long) */
818 false, /* pc_relative */
820 complain_overflow_bitfield
, /* complain_on_overflow */
821 0, /* special_function */
823 true, /* partial_inplace */
824 MINUS_ONE
, /* src_mask */
825 MINUS_ONE
, /* dst_mask */
826 false) /* pcrel_offset */
831 _bfd_xcoff_rtype2howto (relent
, internal
)
833 struct internal_reloc
*internal
;
835 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
837 /* Check for relocs we don't know of. */
839 >= sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]))
841 if (internal
->r_type
!= relent
->howto
->type
)
844 /* The r_size field of an XCOFF reloc encodes the bitsize of the
845 relocation, as well as indicating whether it is signed or not.
846 Doublecheck that the relocation information gathered from the
847 type matches this information. The bitsize is not significant
849 if (relent
->howto
->dst_mask
!= 0
850 && (relent
->howto
->bitsize
851 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
854 if ((internal
->r_size
& 0x80) != 0
855 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
856 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
862 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
863 bfd
*abfd ATTRIBUTE_UNUSED
;
864 bfd_reloc_code_real_type code
;
868 case BFD_RELOC_PPC_B26
:
869 return &xcoff_howto_table
[0xa];
870 case BFD_RELOC_PPC_BA26
:
871 return &xcoff_howto_table
[8];
872 case BFD_RELOC_PPC_TOC16
:
873 return &xcoff_howto_table
[3];
876 return &xcoff_howto_table
[0];
878 return &xcoff_howto_table
[0x1c];
885 /* XCOFF archive support. The original version of this code was by
886 Damon A. Permezel. It was enhanced to permit cross support, and
887 writing archive files, by Ian Lance Taylor, Cygnus Support.
889 XCOFF uses its own archive format. Everything is hooked together
890 with file offset links, so it is possible to rapidly update an
891 archive in place. Of course, we don't do that. An XCOFF archive
892 has a real file header, not just an ARMAG string. The structure of
893 the file header and of each archive header appear below.
895 An XCOFF archive also has a member table, which is a list of
896 elements in the archive (you can get that by looking through the
897 linked list, but you have to read a lot more of the file). The
898 member table has a normal archive header with an empty name. It is
899 normally (and perhaps must be) the second to last entry in the
900 archive. The member table data is almost printable ASCII. It
901 starts with a 12 character decimal string which is the number of
902 entries in the table. For each entry it has a 12 character decimal
903 string which is the offset in the archive of that member. These
904 entries are followed by a series of null terminated strings which
905 are the member names for each entry.
907 Finally, an XCOFF archive has a global symbol table, which is what
908 we call the armap. The global symbol table has a normal archive
909 header with an empty name. It is normally (and perhaps must be)
910 the last entry in the archive. The contents start with a four byte
911 binary number which is the number of entries. This is followed by
912 a that many four byte binary numbers; each is the file offset of an
913 entry in the archive. These numbers are followed by a series of
914 null terminated strings, which are symbol names.
916 AIX 4.3 introduced a new archive format which can handle larger
917 files and also 32- and 64-bit objects in the same archive. The
918 things said above remain true except that there is now more than
919 one global symbol table. The one is used to index 32-bit objects,
920 the other for 64-bit objects.
922 The new archives (recognizable by the new ARMAG string) has larger
923 field lengths so that we cannot really share any code. Also we have
924 to take care that we are not generating the new form of archives
925 on AIX 4.2 or earlier systems. */
927 /* XCOFF archives use this as a magic string. Note that both strings
928 have the same length. */
932 /* Read in the armap of an XCOFF archive. */
935 _bfd_xcoff_slurp_armap (abfd
)
941 bfd_byte
*contents
, *cend
;
946 if (xcoff_ardata (abfd
) == NULL
)
948 bfd_has_map (abfd
) = false;
952 if (! xcoff_big_format_p (abfd
))
954 /* This is for the old format. */
955 struct xcoff_ar_hdr hdr
;
957 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
960 bfd_has_map (abfd
) = false;
964 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
967 /* The symbol table starts with a normal archive header. */
968 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
971 /* Skip the name (normally empty). */
972 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
973 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
976 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
978 /* Read in the entire symbol table. */
979 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
980 if (contents
== NULL
)
982 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
985 /* The symbol table starts with a four byte count. */
986 c
= bfd_h_get_32 (abfd
, contents
);
990 bfd_set_error (bfd_error_bad_value
);
994 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
995 bfd_alloc (abfd
, c
* sizeof (carsym
)));
996 if (bfd_ardata (abfd
)->symdefs
== NULL
)
999 /* After the count comes a list of four byte file offsets. */
1000 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1002 ++i
, ++arsym
, p
+= 4)
1003 arsym
->file_offset
= bfd_h_get_32 (abfd
, p
);
1007 /* This is for the new format. */
1008 struct xcoff_ar_hdr_big hdr
;
1010 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1013 bfd_has_map (abfd
) = false;
1017 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1020 /* The symbol table starts with a normal archive header. */
1021 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1022 != SIZEOF_AR_HDR_BIG
)
1025 /* Skip the name (normally empty). */
1026 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1027 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1030 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1031 machines) since the field width is 20 and there numbers with more
1032 than 32 bits can be represented. */
1033 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1035 /* Read in the entire symbol table. */
1036 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1037 if (contents
== NULL
)
1039 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1042 /* The symbol table starts with an eight byte count. */
1043 c
= bfd_h_get_64 (abfd
, contents
);
1047 bfd_set_error (bfd_error_bad_value
);
1051 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1052 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1053 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1056 /* After the count comes a list of eight byte file offsets. */
1057 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1059 ++i
, ++arsym
, p
+= 8)
1060 arsym
->file_offset
= bfd_h_get_64 (abfd
, p
);
1063 /* After the file offsets come null terminated symbol names. */
1064 cend
= contents
+ sz
;
1065 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1067 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1071 bfd_set_error (bfd_error_bad_value
);
1074 arsym
->name
= (char *) p
;
1077 bfd_ardata (abfd
)->symdef_count
= c
;
1078 bfd_has_map (abfd
) = true;
1083 /* See if this is an XCOFF archive. */
1086 _bfd_xcoff_archive_p (abfd
)
1089 char magic
[SXCOFFARMAG
];
1091 if (bfd_read ((PTR
) magic
, SXCOFFARMAG
, 1, abfd
) != SXCOFFARMAG
)
1093 if (bfd_get_error () != bfd_error_system_call
)
1094 bfd_set_error (bfd_error_wrong_format
);
1098 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1099 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1101 bfd_set_error (bfd_error_wrong_format
);
1105 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1106 involves a cast, we can't do it as the left operand of
1108 abfd
->tdata
.aout_ar_data
=
1109 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
1111 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1114 bfd_ardata (abfd
)->cache
= NULL
;
1115 bfd_ardata (abfd
)->archive_head
= NULL
;
1116 bfd_ardata (abfd
)->symdefs
= NULL
;
1117 bfd_ardata (abfd
)->extended_names
= NULL
;
1119 /* Now handle the two formats. */
1120 if (magic
[1] != 'b')
1122 /* This is the old format. */
1123 struct xcoff_ar_file_hdr hdr
;
1125 /* Copy over the magic string. */
1126 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1128 /* Now read the rest of the file header. */
1129 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, 1,
1130 abfd
) != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1132 if (bfd_get_error () != bfd_error_system_call
)
1133 bfd_set_error (bfd_error_wrong_format
);
1137 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1138 (char **) NULL
, 10);
1140 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR
);
1141 if (bfd_ardata (abfd
)->tdata
== NULL
)
1144 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1148 /* This is the new format. */
1149 struct xcoff_ar_file_hdr_big hdr
;
1151 /* Copy over the magic string. */
1152 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1154 /* Now read the rest of the file header. */
1155 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, 1,
1156 abfd
) != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1158 if (bfd_get_error () != bfd_error_system_call
)
1159 bfd_set_error (bfd_error_wrong_format
);
1163 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1164 machines) since the field width is 20 and there numbers with more
1165 than 32 bits can be represented. */
1166 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1167 (char **) NULL
, 10);
1169 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR_BIG
);
1170 if (bfd_ardata (abfd
)->tdata
== NULL
)
1173 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1176 if (! _bfd_xcoff_slurp_armap (abfd
))
1178 bfd_release (abfd
, bfd_ardata (abfd
));
1179 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1186 /* Read the archive header in an XCOFF archive. */
1189 _bfd_xcoff_read_ar_hdr (abfd
)
1193 struct areltdata
*ret
;
1195 ret
= (struct areltdata
*) bfd_alloc (abfd
, sizeof (struct areltdata
));
1199 if (! xcoff_big_format_p (abfd
))
1201 struct xcoff_ar_hdr hdr
;
1202 struct xcoff_ar_hdr
*hdrp
;
1204 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1210 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1211 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
,
1212 SIZEOF_AR_HDR
+ namlen
+ 1);
1218 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1219 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR
, 1, namlen
, abfd
) != namlen
)
1224 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1226 ret
->arch_header
= (char *) hdrp
;
1227 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1228 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1232 struct xcoff_ar_hdr_big hdr
;
1233 struct xcoff_ar_hdr_big
*hdrp
;
1235 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1236 != SIZEOF_AR_HDR_BIG
)
1242 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1243 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
,
1251 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1252 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, 1, namlen
, abfd
) != namlen
)
1257 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1259 ret
->arch_header
= (char *) hdrp
;
1260 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1261 machines) since the field width is 20 and there numbers with more
1262 than 32 bits can be represented. */
1263 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1264 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1267 /* Skip over the XCOFFARFMAG at the end of the file name. */
1268 if (bfd_seek (abfd
, (namlen
& 1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1274 /* Open the next element in an XCOFF archive. */
1277 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1283 if (xcoff_ardata (archive
) == NULL
)
1285 bfd_set_error (bfd_error_invalid_operation
);
1289 if (! xcoff_big_format_p (archive
))
1291 if (last_file
== NULL
)
1292 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1294 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1298 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1300 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1301 (char **) NULL
, 10))
1303 bfd_set_error (bfd_error_no_more_archived_files
);
1309 if (last_file
== NULL
)
1310 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1312 /* XXX These actually have to be a calls to strtoll (at least
1313 on 32-bit machines) since the fields's width is 20 and
1314 there numbers with more than 32 bits can be represented. */
1315 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1318 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1319 machines) since the fields's width is 20 and there numbers with more
1320 than 32 bits can be represented. */
1322 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1324 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1325 (char **) NULL
, 10))
1327 bfd_set_error (bfd_error_no_more_archived_files
);
1332 return _bfd_get_elt_at_filepos (archive
, filestart
);
1335 /* Stat an element in an XCOFF archive. */
1338 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1342 if (abfd
->arelt_data
== NULL
)
1344 bfd_set_error (bfd_error_invalid_operation
);
1348 if (! xcoff_big_format_p (abfd
))
1350 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1352 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1353 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1354 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1355 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1356 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1360 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1362 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1363 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1364 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1365 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1366 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1372 /* Normalize a file name for inclusion in an archive. */
1375 normalize_filename (abfd
)
1379 const char *filename
;
1381 file
= bfd_get_filename (abfd
);
1382 filename
= strrchr (file
, '/');
1383 if (filename
!= NULL
)
1390 /* Write out an XCOFF armap. */
1394 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1396 unsigned int elength ATTRIBUTE_UNUSED
;
1398 unsigned int orl_count
;
1401 struct xcoff_ar_hdr hdr
;
1403 unsigned char buf
[4];
1408 memset (&hdr
, 0, sizeof hdr
);
1409 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1410 sprintf (hdr
.nextoff
, "%d", 0);
1411 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1412 sprintf (hdr
.date
, "%d", 0);
1413 sprintf (hdr
.uid
, "%d", 0);
1414 sprintf (hdr
.gid
, "%d", 0);
1415 sprintf (hdr
.mode
, "%d", 0);
1416 sprintf (hdr
.namlen
, "%d", 0);
1418 /* We need spaces, not null bytes, in the header. */
1419 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1423 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
1424 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1427 bfd_h_put_32 (abfd
, orl_count
, buf
);
1428 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1431 sub
= abfd
->archive_head
;
1432 fileoff
= SIZEOF_AR_FILE_HDR
;
1434 while (sub
!= NULL
&& i
< orl_count
)
1438 while (((bfd
*) (map
[i
]).pos
) == sub
)
1440 bfd_h_put_32 (abfd
, fileoff
, buf
);
1441 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1445 namlen
= strlen (normalize_filename (sub
));
1446 namlen
= (namlen
+ 1) &~ 1;
1447 fileoff
+= (SIZEOF_AR_HDR
1450 + arelt_size (sub
));
1451 fileoff
= (fileoff
+ 1) &~ 1;
1455 for (i
= 0; i
< orl_count
; i
++)
1460 name
= *map
[i
].name
;
1461 namlen
= strlen (name
);
1462 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1466 if ((stridx
& 1) != 0)
1471 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1478 /* Write a single armap in the big format. */
1480 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1484 unsigned int orl_count
;
1485 unsigned int orl_ccount
;
1486 unsigned int stridx
;
1488 const char *prevoff
;
1491 struct xcoff_ar_hdr_big hdr
;
1493 unsigned char buf
[4];
1496 const bfd_arch_info_type
*arch_info
;
1500 memset (&hdr
, 0, sizeof hdr
);
1501 /* XXX This call actually should use %lld (at least on 32-bit
1502 machines) since the fields's width is 20 and there numbers with
1503 more than 32 bits can be represented. */
1504 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1506 sprintf (hdr
.nextoff
, "%d", 0);
1508 /* do explict cast to long to remove compiler warning */
1509 sprintf (hdr
.nextoff
, "%ld", (strtol (prevoff
, (char **) NULL
, 10)
1510 + (long) (4 + orl_ccount
* 4 + stridx
)));
1513 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1514 sprintf (hdr
.date
, "%d", 0);
1515 sprintf (hdr
.uid
, "%d", 0);
1516 sprintf (hdr
.gid
, "%d", 0);
1517 sprintf (hdr
.mode
, "%d", 0);
1518 sprintf (hdr
.namlen
, "%d", 0);
1520 /* We need spaces, not null bytes, in the header. */
1521 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1525 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1527 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
) != SIZEOF_AR_HDR_BIG
1528 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1531 bfd_h_put_32 (abfd
, orl_ccount
, buf
);
1532 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1535 sub
= abfd
->archive_head
;
1536 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1538 while (sub
!= NULL
&& i
< orl_count
)
1542 if ((bfd_arch_bits_per_address ((bfd
*) map
[i
].pos
) == 64) == bits64
)
1543 while (((bfd
*) (map
[i
]).pos
) == sub
)
1545 bfd_h_put_32 (abfd
, fileoff
, buf
);
1546 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1551 while (((bfd
*) (map
[i
]).pos
) == sub
)
1554 namlen
= strlen (normalize_filename (sub
));
1555 namlen
= (namlen
+ 1) &~ 1;
1556 fileoff
+= (SIZEOF_AR_HDR_BIG
1559 + arelt_size (sub
));
1560 fileoff
= (fileoff
+ 1) &~ 1;
1565 for (i
= 0; i
< orl_count
; i
++)
1569 bfd
*ob
= (bfd
*)map
[i
].pos
;
1571 if (ob
!= object_bfd
)
1572 arch_info
= bfd_get_arch_info (ob
);
1573 if ((arch_info
->bits_per_address
== 64) != bits64
)
1576 name
= *map
[i
].name
;
1577 namlen
= strlen (name
);
1578 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1582 if ((stridx
& 1) != 0)
1587 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1596 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1598 unsigned int elength ATTRIBUTE_UNUSED
;
1600 unsigned int orl_count
;
1604 unsigned int orl_count_32
, orl_count_64
;
1605 unsigned int stridx_32
, stridx_64
;
1606 const bfd_arch_info_type
*arch_info
;
1609 /* First, we look through the symbols and work out which are
1610 from 32-bit objects and which from 64-bit ones. */
1616 for (i
= 0; i
< orl_count
; i
++)
1618 bfd
*ob
= (bfd
*)map
[i
].pos
;
1620 if (ob
!= object_bfd
)
1621 arch_info
= bfd_get_arch_info (ob
);
1622 len
= strlen (*map
[i
].name
) + 1;
1623 if (arch_info
->bits_per_address
== 64)
1635 /* A quick sanity check... */
1636 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1637 /* explicit cast to int for compiler */
1638 BFD_ASSERT ((int)(stridx_64
+ stridx_32
) == stridx
);
1640 /* Now write out each map. */
1641 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1643 xcoff_ardata_big (abfd
)->memoff
,
1644 xcoff_ardata_big (abfd
)->symoff
))
1646 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1648 xcoff_ardata_big (abfd
)->symoff
,
1649 xcoff_ardata_big (abfd
)->symoff64
))
1657 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1659 unsigned int elength ATTRIBUTE_UNUSED
;
1661 unsigned int orl_count
;
1664 if (! xcoff_big_format_p (abfd
))
1665 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1667 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1670 /* Write out an XCOFF archive. We always write an entire archive,
1671 rather than fussing with the freelist and so forth. */
1674 xcoff_write_archive_contents_old (abfd
)
1677 struct xcoff_ar_file_hdr fhdr
;
1679 size_t total_namlen
;
1683 file_ptr prevoff
, nextoff
;
1686 struct xcoff_ar_hdr ahdr
;
1691 memset (&fhdr
, 0, sizeof fhdr
);
1692 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1693 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1694 sprintf (fhdr
.freeoff
, "%d", 0);
1698 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1701 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1703 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1704 if (offsets
== NULL
)
1707 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1710 makemap
= bfd_has_map (abfd
);
1713 nextoff
= SIZEOF_AR_FILE_HDR
;
1714 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1718 struct xcoff_ar_hdr
*ahdrp
;
1719 bfd_size_type remaining
;
1721 if (makemap
&& ! hasobjects
)
1723 if (bfd_check_format (sub
, bfd_object
))
1727 name
= normalize_filename (sub
);
1728 namlen
= strlen (name
);
1730 if (sub
->arelt_data
!= NULL
)
1731 ahdrp
= arch_xhdr (sub
);
1739 memset (&ahdr
, 0, sizeof ahdr
);
1741 if (stat (bfd_get_filename (sub
), &s
) != 0)
1743 bfd_set_error (bfd_error_system_call
);
1747 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1748 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1749 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1750 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1751 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1753 if (sub
->arelt_data
== NULL
)
1755 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
1756 if (sub
->arelt_data
== NULL
)
1760 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1763 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1764 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1766 /* If the length of the name is odd, we write out the null byte
1767 after the name as well. */
1768 namlen
= (namlen
+ 1) &~ 1;
1770 remaining
= arelt_size (sub
);
1771 size
= (SIZEOF_AR_HDR
1776 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1778 offsets
[i
] = nextoff
;
1781 nextoff
+= size
+ (size
& 1);
1783 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1785 /* We need spaces, not null bytes, in the header. */
1786 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1790 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1791 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
1792 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1796 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1798 while (remaining
!= 0)
1801 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1803 amt
= sizeof buffer
;
1804 if (amt
> remaining
)
1806 if (bfd_read (buffer
, 1, amt
, sub
) != amt
1807 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
1812 if ((size
& 1) != 0)
1817 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1822 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1824 /* Write out the member table. */
1826 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1827 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1829 memset (&ahdr
, 0, sizeof ahdr
);
1830 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1831 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1832 sprintf (ahdr
.date
, "%d", 0);
1833 sprintf (ahdr
.uid
, "%d", 0);
1834 sprintf (ahdr
.gid
, "%d", 0);
1835 sprintf (ahdr
.mode
, "%d", 0);
1836 sprintf (ahdr
.namlen
, "%d", 0);
1838 size
= (SIZEOF_AR_HDR
1845 nextoff
+= size
+ (size
& 1);
1847 if (makemap
&& hasobjects
)
1848 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
1850 sprintf (ahdr
.nextoff
, "%d", 0);
1852 /* We need spaces, not null bytes, in the header. */
1853 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
1857 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1858 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1862 sprintf (decbuf
, "%-12ld", (long) count
);
1863 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
1865 for (i
= 0; i
< count
; i
++)
1867 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
1868 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
1871 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1876 name
= normalize_filename (sub
);
1877 namlen
= strlen (name
);
1878 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1881 if ((size
& 1) != 0)
1886 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
1890 /* Write out the armap, if appropriate. */
1892 if (! makemap
|| ! hasobjects
)
1893 sprintf (fhdr
.symoff
, "%d", 0);
1896 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1897 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
1898 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
1899 if (! _bfd_compute_and_write_armap (abfd
, 0))
1903 /* Write out the archive file header. */
1905 /* We need spaces, not null bytes, in the header. */
1906 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
1910 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
1911 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR
, 1, abfd
) !=
1912 SIZEOF_AR_FILE_HDR
))
1919 xcoff_write_archive_contents_big (abfd
)
1922 struct xcoff_ar_file_hdr_big fhdr
;
1924 size_t total_namlen
;
1928 file_ptr prevoff
, nextoff
;
1931 struct xcoff_ar_hdr_big ahdr
;
1936 memset (&fhdr
, 0, sizeof fhdr
);
1937 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
1938 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
1939 sprintf (fhdr
.freeoff
, "%d", 0);
1943 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1946 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1948 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1949 if (offsets
== NULL
)
1952 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
1955 makemap
= bfd_has_map (abfd
);
1958 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
1959 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1963 struct xcoff_ar_hdr_big
*ahdrp
;
1964 bfd_size_type remaining
;
1966 if (makemap
&& ! hasobjects
)
1968 if (bfd_check_format (sub
, bfd_object
))
1972 name
= normalize_filename (sub
);
1973 namlen
= strlen (name
);
1975 if (sub
->arelt_data
!= NULL
)
1976 ahdrp
= arch_xhdr_big (sub
);
1984 memset (&ahdr
, 0, sizeof ahdr
);
1986 /* XXX This should actually be a call to stat64 (at least on
1987 32-bit machines). */
1988 if (stat (bfd_get_filename (sub
), &s
) != 0)
1990 bfd_set_error (bfd_error_system_call
);
1994 /* XXX This call actually should use %lld (at least on 32-bit
1995 machines) since the fields's width is 20 and there numbers with
1996 more than 32 bits can be represented. */
1997 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1998 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1999 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2000 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2001 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2003 if (sub
->arelt_data
== NULL
)
2005 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
2006 if (sub
->arelt_data
== NULL
)
2010 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2013 /* XXX These calls actually should use %lld (at least on 32-bit
2014 machines) since the fields's width is 20 and there numbers with
2015 more than 32 bits can be represented. */
2016 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2017 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2019 /* If the length of the name is odd, we write out the null byte
2020 after the name as well. */
2021 namlen
= (namlen
+ 1) &~ 1;
2023 remaining
= arelt_size (sub
);
2024 size
= (SIZEOF_AR_HDR_BIG
2029 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2031 offsets
[i
] = nextoff
;
2034 nextoff
+= size
+ (size
& 1);
2036 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2038 /* We need spaces, not null bytes, in the header. */
2039 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2043 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR_BIG
, abfd
)
2044 != SIZEOF_AR_HDR_BIG
2045 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
2046 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2050 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2052 while (remaining
!= 0)
2055 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2057 amt
= sizeof buffer
;
2058 if (amt
> remaining
)
2060 if (bfd_read (buffer
, 1, amt
, sub
) != amt
2061 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
2066 if ((size
& 1) != 0)
2071 if (bfd_write (&b
, 1, 1, abfd
) != 1)
2076 /* XXX This call actually should use %lld (at least on 32-bit
2077 machines) since the fields's width is 20 and there numbers with
2078 more than 32 bits can be represented. */
2079 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2081 /* Write out the member table. */
2083 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2084 /* XXX This call actually should use %lld (at least on 32-bit
2085 machines) since the fields's width is 20 and there numbers with
2086 more than 32 bits can be represented. */
2087 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2089 memset (&ahdr
, 0, sizeof ahdr
);
2090 /* XXX The next two calls actually should use %lld (at least on 32-bit
2091 machines) since the fields's width is 20 and there numbers with
2092 more than 32 bits can be represented. */
2093 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2094 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2095 sprintf (ahdr
.date
, "%d", 0);
2096 sprintf (ahdr
.uid
, "%d", 0);
2097 sprintf (ahdr
.gid
, "%d", 0);
2098 sprintf (ahdr
.mode
, "%d", 0);
2099 sprintf (ahdr
.namlen
, "%d", 0);
2101 size
= (SIZEOF_AR_HDR_BIG
2108 nextoff
+= size
+ (size
& 1);
2110 if (makemap
&& hasobjects
)
2111 /* XXX This call actually should use %lld (at least on 32-bit
2112 machines) since the fields's width is 20 and there numbers with
2113 more than 32 bits can be represented. */
2114 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2116 sprintf (ahdr
.nextoff
, "%d", 0);
2118 /* We need spaces, not null bytes, in the header. */
2119 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2123 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2124 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2128 sprintf (decbuf
, "%-12ld", (long) count
);
2129 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2131 for (i
= 0; i
< count
; i
++)
2133 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2134 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2137 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2142 name
= normalize_filename (sub
);
2143 namlen
= strlen (name
);
2144 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2147 if ((size
& 1) != 0)
2152 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2156 /* Write out the armap, if appropriate. */
2158 if (! makemap
|| ! hasobjects
)
2159 sprintf (fhdr
.symoff
, "%d", 0);
2162 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2163 /* XXX This call actually should use %lld (at least on 32-bit
2164 machines) since the fields's width is 20 and there numbers with
2165 more than 32 bits can be represented. */
2166 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2167 if (! _bfd_compute_and_write_armap (abfd
, 0))
2171 /* Write out the archive file header. */
2173 /* We need spaces, not null bytes, in the header. */
2174 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2178 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2179 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR_BIG
, 1, abfd
) !=
2180 SIZEOF_AR_FILE_HDR_BIG
))
2187 _bfd_xcoff_write_archive_contents (abfd
)
2190 if (! xcoff_big_format_p (abfd
))
2191 return xcoff_write_archive_contents_old (abfd
);
2193 return xcoff_write_archive_contents_big (abfd
);
2196 /* We can't use the usual coff_sizeof_headers routine, because AIX
2197 always uses an a.out header. */
2201 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2203 boolean reloc ATTRIBUTE_UNUSED
;
2208 if (xcoff_data (abfd
)->full_aouthdr
)
2211 size
+= SMALL_AOUTSZ
;
2212 size
+= abfd
->section_count
* SCNHSZ
;
2216 /* Routines to swap information in the XCOFF .loader section. If we
2217 ever need to write an XCOFF loader, this stuff will need to be
2218 moved to another file shared by the linker (which XCOFF calls the
2219 ``binder'') and the loader. */
2221 /* Swap in the ldhdr structure. */
2224 xcoff_swap_ldhdr_in (abfd
, src
, dst
)
2226 const struct external_ldhdr
*src
;
2227 struct internal_ldhdr
*dst
;
2229 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2230 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2231 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2232 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2233 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2234 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2235 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2236 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2239 /* Swap out the ldhdr structure. */
2242 xcoff_swap_ldhdr_out (abfd
, src
, dst
)
2244 const struct internal_ldhdr
*src
;
2245 struct external_ldhdr
*dst
;
2247 bfd_put_32 (abfd
, src
->l_version
, dst
->l_version
);
2248 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2249 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2250 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2251 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2252 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2253 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2254 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2257 /* Swap in the ldsym structure. */
2260 xcoff_swap_ldsym_in (abfd
, src
, dst
)
2262 const struct external_ldsym
*src
;
2263 struct internal_ldsym
*dst
;
2265 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2266 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2268 dst
->_l
._l_l
._l_zeroes
= 0;
2269 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2271 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2272 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2273 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2274 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2275 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2276 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2279 /* Swap out the ldsym structure. */
2282 xcoff_swap_ldsym_out (abfd
, src
, dst
)
2284 const struct internal_ldsym
*src
;
2285 struct external_ldsym
*dst
;
2288 if (src
->_l
._l_l
._l_zeroes
!= 0)
2289 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2292 bfd_put_32 (abfd
, 0, dst
->_l
._l_l
._l_zeroes
);
2293 bfd_put_32 (abfd
, src
->_l
._l_l
._l_offset
, dst
->_l
._l_l
._l_offset
);
2295 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2296 bfd_put_16 (abfd
, src
->l_scnum
, dst
->l_scnum
);
2297 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2298 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2299 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2300 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2303 /* Swap in the ldrel structure. */
2306 xcoff_swap_ldrel_in (abfd
, src
, dst
)
2308 const struct external_ldrel
*src
;
2309 struct internal_ldrel
*dst
;
2311 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2312 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2313 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2314 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2317 /* Swap out the ldrel structure. */
2320 xcoff_swap_ldrel_out (abfd
, src
, dst
)
2322 const struct internal_ldrel
*src
;
2323 struct external_ldrel
*dst
;
2325 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2326 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2327 bfd_put_16 (abfd
, src
->l_rtype
, dst
->l_rtype
);
2328 bfd_put_16 (abfd
, src
->l_rsecnm
, dst
->l_rsecnm
);
2333 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2334 This is currently the only processor which uses XCOFF; I hope that
2335 will never change. */
2338 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
2339 input_section
, contents
, relocs
, syms
,
2342 struct bfd_link_info
*info
;
2344 asection
*input_section
;
2346 struct internal_reloc
*relocs
;
2347 struct internal_syment
*syms
;
2348 asection
**sections
;
2350 struct internal_reloc
*rel
;
2351 struct internal_reloc
*relend
;
2354 relend
= rel
+ input_section
->reloc_count
;
2356 for (; rel
< relend
; rel
++)
2359 struct xcoff_link_hash_entry
*h
;
2360 struct internal_syment
*sym
;
2363 struct reloc_howto_struct howto
;
2364 bfd_reloc_status_type rstat
;
2366 /* Relocation type R_REF is a special relocation type which is
2367 merely used to prevent garbage collection from occurring for
2368 the csect including the symbol which it references. */
2369 if (rel
->r_type
== R_REF
)
2372 symndx
= rel
->r_symndx
;
2382 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
2383 sym
= syms
+ symndx
;
2384 addend
= - sym
->n_value
;
2388 /* We build the howto information on the fly. */
2390 howto
.type
= rel
->r_type
;
2391 howto
.rightshift
= 0;
2393 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
2394 howto
.pc_relative
= false;
2396 if ((rel
->r_size
& 0x80) != 0)
2397 howto
.complain_on_overflow
= complain_overflow_signed
;
2399 howto
.complain_on_overflow
= complain_overflow_bitfield
;
2400 howto
.special_function
= NULL
;
2401 howto
.name
= "internal";
2402 howto
.partial_inplace
= true;
2403 if (howto
.bitsize
== 32)
2404 howto
.src_mask
= howto
.dst_mask
= 0xffffffff;
2407 howto
.src_mask
= howto
.dst_mask
= (1 << howto
.bitsize
) - 1;
2408 if (howto
.bitsize
== 16)
2411 howto
.pcrel_offset
= false;
2421 sec
= bfd_abs_section_ptr
;
2426 sec
= sections
[symndx
];
2427 /* Hack to make sure we use the right TOC anchor value
2428 if this reloc is against the TOC anchor. */
2430 if (sec
->name
[3] == '0'
2431 && strcmp (sec
->name
, ".tc0") == 0) {
2433 val
= xcoff_data (output_bfd
)->toc
;
2436 val
= (sec
->output_section
->vma
2437 + sec
->output_offset
2446 if (h
->root
.type
== bfd_link_hash_defined
2447 || h
->root
.type
== bfd_link_hash_defweak
)
2451 sec
= h
->root
.u
.def
.section
;
2452 val
= (h
->root
.u
.def
.value
2453 + sec
->output_section
->vma
2454 + sec
->output_offset
);
2456 else if (h
->root
.type
== bfd_link_hash_common
)
2460 sec
= h
->root
.u
.c
.p
->section
;
2461 val
= (sec
->output_section
->vma
2462 + sec
->output_offset
);
2464 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2465 || (h
->flags
& XCOFF_IMPORT
) != 0)
2467 /* Every symbol in a shared object is defined somewhere. */
2470 else if (! info
->relocateable
)
2472 if (! ((*info
->callbacks
->undefined_symbol
)
2473 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2474 rel
->r_vaddr
- input_section
->vma
, true)))
2477 /* Don't try to process the reloc. It can't help, and
2478 it may generate another error. */
2483 /* I took the relocation type definitions from two documents:
2484 the PowerPC AIX Version 4 Application Binary Interface, First
2485 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2486 32-Bit Hardware Implementation (June 30, 1994). Differences
2487 between the documents are noted below. */
2489 switch (rel
->r_type
)
2494 /* These relocs are defined by the PowerPC ABI to be
2495 relative branches which use half of the difference
2496 between the symbol and the program counter. I can't
2497 quite figure out when this is useful. These relocs are
2498 not defined by the PowerOpen ABI. */
2500 (*_bfd_error_handler
)
2501 (_("%s: unsupported relocation type 0x%02x"),
2502 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2503 bfd_set_error (bfd_error_bad_value
);
2506 /* Simple positive relocation. */
2509 /* Simple negative relocation. */
2513 /* Simple PC relative relocation. */
2514 howto
.pc_relative
= true;
2517 /* TOC relative relocation. The value in the instruction in
2518 the input file is the offset from the input file TOC to
2519 the desired location. We want the offset from the final
2520 TOC to the desired location. We have:
2525 so we must change insn by on - in.
2528 /* Global linkage relocation. The value of this relocation
2529 is the address of the entry in the TOC section. */
2531 /* Local object TOC address. I can't figure out the
2532 difference between this and case R_GL. */
2534 /* TOC relative relocation. A TOC relative load instruction
2535 which may be changed to a load address instruction.
2536 FIXME: We don't currently implement this optimization. */
2538 /* TOC relative relocation. This is a TOC relative load
2539 address instruction which may be changed to a load
2540 instruction. FIXME: I don't know if this is the correct
2542 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2544 if (h
->toc_section
== NULL
)
2546 (*_bfd_error_handler
)
2547 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2548 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2549 h
->root
.root
.string
);
2550 bfd_set_error (bfd_error_bad_value
);
2554 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2555 val
= (h
->toc_section
->output_section
->vma
2556 + h
->toc_section
->output_offset
);
2559 val
= ((val
- xcoff_data (output_bfd
)->toc
)
2560 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2564 /* Absolute branch. We don't want to mess with the lower
2565 two bits of the instruction. */
2567 /* The PowerPC ABI defines this as an absolute call which
2568 may be modified to become a relative call. The PowerOpen
2569 ABI does not define this relocation type. */
2571 /* Absolute branch which may be modified to become a
2574 /* The PowerPC ABI defines this as an absolute branch to a
2575 fixed address which may be modified to an absolute branch
2576 to a symbol. The PowerOpen ABI does not define this
2579 /* The PowerPC ABI defines this as an absolute branch to a
2580 fixed address which may be modified to a relative branch.
2581 The PowerOpen ABI does not define this relocation type. */
2582 howto
.src_mask
&= ~3;
2583 howto
.dst_mask
= howto
.src_mask
;
2586 /* Relative branch. We don't want to mess with the lower
2587 two bits of the instruction. */
2589 /* The PowerPC ABI defines this as a relative call which may
2590 be modified to become an absolute call. The PowerOpen
2591 ABI does not define this relocation type. */
2593 /* A relative branch which may be modified to become an
2594 absolute branch. FIXME: We don't implement this,
2595 although we should for symbols of storage mapping class
2597 howto
.pc_relative
= true;
2598 howto
.src_mask
&= ~3;
2599 howto
.dst_mask
= howto
.src_mask
;
2602 /* The PowerPC AIX ABI describes this as a load which may be
2603 changed to a load address. The PowerOpen ABI says this
2604 is the same as case R_POS. */
2607 /* The PowerPC AIX ABI describes this as a load address
2608 which may be changed to a load. The PowerOpen ABI says
2609 this is the same as R_POS. */
2613 /* If we see an R_BR or R_RBR reloc which is jumping to global
2614 linkage code, and it is followed by an appropriate cror nop
2615 instruction, we replace the cror with lwz r2,20(r1). This
2616 restores the TOC after the glink code. Contrariwise, if the
2617 call is followed by a lwz r2,20(r1), but the call is not
2618 going to global linkage code, we can replace the load with a
2620 if ((rel
->r_type
== R_BR
|| rel
->r_type
== R_RBR
)
2622 && h
->root
.type
== bfd_link_hash_defined
2623 && (rel
->r_vaddr
- input_section
->vma
+ 8
2624 <= input_section
->_cooked_size
))
2629 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
2630 next
= bfd_get_32 (input_bfd
, pnext
);
2632 /* The _ptrgl function is magic. It is used by the AIX
2633 compiler to call a function through a pointer. */
2634 if (h
->smclas
== XMC_GL
2635 || strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2637 if (next
== 0x4def7b82 /* cror 15,15,15 */
2638 || next
== 0x4ffffb82 /* cror 31,31,31 */
2639 || next
== 0x60000000) /* ori r0,r0,0 */
2640 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r1,20(r1) */
2644 if (next
== 0x80410014) /* lwz r1,20(r1) */
2645 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2649 /* A PC relative reloc includes the section address. */
2650 if (howto
.pc_relative
)
2651 addend
+= input_section
->vma
;
2653 rstat
= _bfd_final_link_relocate (&howto
, input_bfd
, input_section
,
2655 rel
->r_vaddr
- input_section
->vma
,
2664 case bfd_reloc_overflow
:
2667 char buf
[SYMNMLEN
+ 1];
2668 char howto_name
[10];
2673 name
= h
->root
.root
.string
;
2677 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
2682 sprintf (howto_name
, "0x%02x", rel
->r_type
);
2684 if (! ((*info
->callbacks
->reloc_overflow
)
2685 (info
, name
, howto_name
, (bfd_vma
) 0, input_bfd
,
2686 input_section
, rel
->r_vaddr
- input_section
->vma
)))
2696 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
2697 bfd
*abfd ATTRIBUTE_UNUSED
;
2698 struct xcoff_loader_info
*ldinfo
;
2699 struct internal_ldsym
*ldsym
;
2703 len
= strlen (name
);
2705 if (len
<= SYMNMLEN
)
2706 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
2709 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
2712 bfd_byte
*newstrings
;
2714 newalc
= ldinfo
->string_alc
* 2;
2717 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
2720 newstrings
= ((bfd_byte
*)
2721 bfd_realloc ((PTR
) ldinfo
->strings
, newalc
));
2722 if (newstrings
== NULL
)
2724 ldinfo
->failed
= true;
2727 ldinfo
->string_alc
= newalc
;
2728 ldinfo
->strings
= newstrings
;
2731 bfd_put_16 (ldinfo
->output_bfd
, len
+ 1,
2732 ldinfo
->strings
+ ldinfo
->string_size
);
2733 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
2734 ldsym
->_l
._l_l
._l_zeroes
= 0;
2735 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
2736 ldinfo
->string_size
+= len
+ 3;
2743 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
2744 struct internal_syment
*sym
,
2747 if (strlen (name
) <= SYMNMLEN
) {
2748 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
2754 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
2756 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
2757 if (indx
== (bfd_size_type
) -1)
2759 sym
->_n
._n_n
._n_zeroes
= 0;
2760 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
2766 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
2768 union internal_auxent
*aux
;
2772 asection
*return_value
= NULL
;
2775 * .sv64 = x_smclas == 17
2776 * This is an invalid csect for 32 bit apps.
2778 static const char *names
[19] = {
2779 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2780 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
2781 ".td", NULL
, ".sv3264"
2784 if ((19 >= aux
->x_csect
.x_smclas
) &&
2785 (NULL
!= names
[aux
->x_csect
.x_smclas
])) {
2787 return_value
= bfd_make_section_anyway
2788 (abfd
, names
[aux
->x_csect
.x_smclas
]);
2792 (*_bfd_error_handler
)
2793 (_("%s: symbol `%s' has unrecognized smclas %d"),
2794 bfd_get_filename (abfd
), symbol_name
, aux
->x_csect
.x_smclas
);
2795 bfd_set_error (bfd_error_bad_value
);
2798 return return_value
;
2802 xcoff_is_lineno_count_overflow (abfd
, value
)
2803 bfd
*abfd ATTRIBUTE_UNUSED
;
2806 if (0xffff <= value
) {
2813 xcoff_is_reloc_count_overflow (abfd
, value
)
2814 bfd
*abfd ATTRIBUTE_UNUSED
;
2817 if (0xffff <= value
) {
2824 xcoff_loader_symbol_offset (abfd
, ldhdr
)
2826 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
2828 return bfd_xcoff_ldhdrsz(abfd
);
2832 xcoff_loader_reloc_offset (abfd
, ldhdr
)
2834 struct internal_ldhdr
*ldhdr
;
2836 return bfd_xcoff_ldhdrsz(abfd
) +
2837 (ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(abfd
));
2841 static reloc_howto_type xcoff_dynamic_reloc
=
2842 HOWTO (0, /* type */
2844 2, /* size (0 = byte, 1 = short, 2 = long) */
2846 false, /* pc_relative */
2848 complain_overflow_bitfield
, /* complain_on_overflow */
2849 0, /* special_function */
2851 true, /* partial_inplace */
2852 0xffffffff, /* src_mask */
2853 0xffffffff, /* dst_mask */
2854 false); /* pcrel_offset */
2859 * The first word of global linkage code must be modified by filling in
2860 * the correct TOC offset.
2862 static unsigned long xcoff_glink_code
[9] =
2864 0x81820000, /* lwz r12,0(r2) */
2865 0x90410014, /* stw r2,20(r1) */
2866 0x800c0000, /* lwz r0,0(r12) */
2867 0x804c0004, /* lwz r2,4(r12) */
2868 0x7c0903a6, /* mtctr r0 */
2869 0x4e800420, /* bctr */
2870 0x00000000, /* start of traceback table */
2871 0x000c8000, /* traceback table */
2872 0x00000000, /* traceback table */
2876 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
2878 { /* COFF backend, defined in libcoff.h */
2879 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
2880 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
2881 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
2882 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
2883 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
2884 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
2885 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
2886 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
2887 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
2888 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
2889 FILHSZ
, /* _bfd_filhsz */
2890 AOUTSZ
, /* _bfd_aoutsz */
2891 SCNHSZ
, /* _bfd_scnhsz */
2892 SYMESZ
, /* _bfd_symesz */
2893 AUXESZ
, /* _bfd_auxesz */
2894 RELSZ
, /* _bfd_relsz */
2895 LINESZ
, /* _bfd_linesz */
2896 FILNMLEN
, /* _bfd_filnmlen */
2897 true, /* _bfd_coff_long_filenames */
2898 false, /* _bfd_coff_long_section_names */
2899 (3), /* _bfd_coff_default_section_alignment_power */
2900 false, /* _bfd_coff_force_symnames_in_strings */
2901 2, /* _bfd_coff_debug_string_prefix_length */
2902 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
2903 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
2904 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
2905 coff_swap_reloc_in
, /* _bfd_reloc_in */
2906 coff_bad_format_hook
, /* _bfd_bad_format_hook */
2907 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
2908 coff_mkobject_hook
, /* _bfd_mkobject_hook */
2909 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
2910 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
2911 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
2912 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
2913 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
2914 coff_print_aux
, /* bfd_coff_print_aux */
2915 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
2916 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
2917 NULL
, /* bfd_coff_sym_is_global */
2918 /* _bfd_coff_compute_section_file_positions */
2919 coff_compute_section_file_positions
,
2920 NULL
, /* _bfd_coff_start_final_link */
2921 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
2922 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
2923 NULL
, /* _bfd_coff_addust_symndx */
2924 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
2925 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
2926 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
2929 0x01DF, /* magic number */
2930 bfd_arch_rs6000
, /* architecture */
2931 bfd_mach_rs6k
, /* machine */
2934 /* function pointers to xcoff specific swap routines */
2935 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
2936 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
2937 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
2938 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
2939 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
2940 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
2943 LDHDRSZ
, /* _xcoff_ldhdrsz */
2944 LDSYMSZ
, /* _xcoff_ldsymsz */
2945 LDRELSZ
, /* _xcoff_ldrelsz */
2946 12, /* _xcoff_function_descriptor_size */
2947 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
2950 1, /* _xcoff_ldhdr_version */
2952 /* xcoff vs xcoff64 putting symbol names */
2953 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
2954 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
2956 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
2958 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
2960 /* lineno and reloc count overflow */
2961 xcoff_is_lineno_count_overflow
,
2962 xcoff_is_reloc_count_overflow
,
2964 xcoff_loader_symbol_offset
,
2965 xcoff_loader_reloc_offset
,
2968 &xcoff_glink_code
[0],
2969 (36), /* _xcoff_glink_size */
2973 /* The transfer vector that leads the outside world to all of the above. */
2974 const bfd_target rs6000coff_vec
=
2977 bfd_target_xcoff_flavour
,
2978 BFD_ENDIAN_BIG
, /* data byte order is big */
2979 BFD_ENDIAN_BIG
, /* header byte order is big */
2981 (HAS_RELOC
| EXEC_P
| /* object flags */
2982 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
2983 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
2985 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2986 0, /* leading char */
2987 '/', /* ar_pad_char */
2988 15, /* ar_max_namelen??? FIXMEmgo */
2991 bfd_getb64
, /* bfd_getx64 */
2992 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
2993 bfd_putb64
, /* bfd_putx64 */
2994 bfd_getb32
, /* bfd_getx32 */
2995 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
2996 bfd_putb32
, /* bfd_putx32 */
2997 bfd_getb16
, /* bfd_getx16 */
2998 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
2999 bfd_putb16
, /* bfd_putx16 */
3002 bfd_getb64
, /* bfd_h_getx64 */
3003 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3004 bfd_putb64
, /* bfd_h_putx64 */
3005 bfd_getb32
, /* bfd_h_getx32 */
3006 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3007 bfd_putb32
, /* bfd_h_putx32 */
3008 bfd_getb16
, /* bfd_h_getx16 */
3009 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3010 bfd_putb16
, /* bfd_h_putx16 */
3012 { /* bfd_check_format */
3015 _bfd_xcoff_archive_p
,
3019 { /* bfd_set_format */
3022 _bfd_generic_mkarchive
,
3026 {/* bfd_write_contents */
3028 coff_write_object_contents
,
3029 _bfd_xcoff_write_archive_contents
,
3034 bfd_true
, /* _close_and_cleanup */
3035 bfd_true
, /* _bfd_free_cached_info */
3036 coff_new_section_hook
, /* _new_section_hook */
3037 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3038 /* _bfd_get_section_contents_in_window */
3039 _bfd_generic_get_section_contents_in_window
,
3042 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3043 /* _bfd_merge_private_bfd_data */
3044 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3045 /* _bfd_copy_pivate_section_data */
3046 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3047 /* _bfd_copy_private_symbol_data */
3048 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3049 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3050 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3053 rs6000coff_core_file_failing_command
, /* _core_file_failing_command */
3054 rs6000coff_core_file_failing_signal
, /* _core_file_failing_signal */
3055 /* _core_file_matches_executable_p */
3056 rs6000coff_core_file_matches_executable_p
,
3059 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3060 /* XCOFF archives do not have
3061 anything which corresponds to
3062 an extended name table. */
3063 bfd_false
, /* _slurp_extended_name_table */
3064 /* _construct_extended_name_table */
3065 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3066 bfd_dont_truncate_arname
, /* _truncate_arname */
3067 _bfd_xcoff_write_armap
, /* _write_armap */
3068 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3069 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3070 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3071 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3072 /* XCOFF archives do not have
3074 bfd_true
, /* _update_armap_timestamp */
3077 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3078 coff_get_symtab
, /* _get_symtab */
3079 coff_make_empty_symbol
, /* _make_empty_symbol */
3080 coff_print_symbol
, /* _print_symbol */
3081 coff_get_symbol_info
, /* _get_symbol_info */
3082 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3083 coff_get_lineno
, /* _get_lineno */
3084 coff_find_nearest_line
, /* _find_nearest_line */
3085 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3086 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3087 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3090 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3091 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3092 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3095 coff_set_arch_mach
, /* _set_arch_mach */
3096 coff_set_section_contents
, /* _set_section_contents */
3099 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3100 /* _bfd_get_relocated_section_contents */
3101 bfd_generic_get_relocated_section_contents
,
3102 bfd_generic_relax_section
, /* _bfd_relax_section */
3103 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3104 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3105 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3106 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3107 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3108 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3111 /* _get_dynamic_symtab_upper_bound */
3112 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3113 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3114 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3115 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3117 /* Opposite endian version, none exists */
3121 (void *) &bfd_xcoff_backend_data
,
3125 * xcoff-powermac target
3127 * Only difference between this target and the rs6000 target is the
3128 * the default architecture and machine type used in coffcode.h
3130 * PowerPC Macs use the same magic numbers as RS/6000
3131 * (because that's how they were bootstrapped originally),
3132 * but they are always PowerPC architecture.
3134 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
3136 { /* COFF backend, defined in libcoff.h */
3137 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3138 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3139 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3140 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3141 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3142 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3143 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3144 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3145 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3146 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3147 FILHSZ
, /* _bfd_filhsz */
3148 AOUTSZ
, /* _bfd_aoutsz */
3149 SCNHSZ
, /* _bfd_scnhsz */
3150 SYMESZ
, /* _bfd_symesz */
3151 AUXESZ
, /* _bfd_auxesz */
3152 RELSZ
, /* _bfd_relsz */
3153 LINESZ
, /* _bfd_linesz */
3154 FILNMLEN
, /* _bfd_filnmlen */
3155 true, /* _bfd_coff_long_filenames */
3156 false, /* _bfd_coff_long_section_names */
3157 (3), /* _bfd_coff_default_section_alignment_power */
3158 false, /* _bfd_coff_force_symnames_in_strings */
3159 2, /* _bfd_coff_debug_string_prefix_length */
3160 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3161 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3162 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3163 coff_swap_reloc_in
, /* _bfd_reloc_in */
3164 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3165 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3166 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3167 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3168 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3169 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3170 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3171 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3172 coff_print_aux
, /* bfd_coff_print_aux */
3173 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3174 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3175 NULL
, /* bfd_coff_sym_is_global */
3176 /* _bfd_coff_compute_section_file_positions */
3177 coff_compute_section_file_positions
,
3178 NULL
, /* _bfd_coff_start_final_link */
3179 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3180 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3181 NULL
, /* _bfd_coff_addust_symndx */
3182 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3183 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3184 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3187 0x01DF, /* magic number */
3188 bfd_arch_powerpc
, /* architecture */
3189 bfd_mach_ppc
, /* machine */
3191 /* function pointers to xcoff specific swap routines */
3192 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3193 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3194 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3195 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3196 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3197 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3200 LDHDRSZ
, /* _xcoff_ldhdrsz */
3201 LDSYMSZ
, /* _xcoff_ldsymsz */
3202 LDRELSZ
, /* _xcoff_ldrelsz */
3203 12, /* _xcoff_function_descriptor_size */
3204 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3207 1, /* _xcoff_ldhdr_version */
3209 /* xcoff vs xcoff64 putting symbol names */
3210 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3211 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3213 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
3215 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3217 /* lineno and reloc count overflow */
3218 xcoff_is_lineno_count_overflow
,
3219 xcoff_is_reloc_count_overflow
,
3221 xcoff_loader_symbol_offset
,
3222 xcoff_loader_reloc_offset
,
3225 &xcoff_glink_code
[0],
3226 (36), /* _xcoff_glink_size */
3230 /* The transfer vector that leads the outside world to all of the above. */
3231 const bfd_target pmac_xcoff_vec
=
3234 bfd_target_xcoff_flavour
,
3235 BFD_ENDIAN_BIG
, /* data byte order is big */
3236 BFD_ENDIAN_BIG
, /* header byte order is big */
3238 (HAS_RELOC
| EXEC_P
| /* object flags */
3239 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3240 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3242 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3243 0, /* leading char */
3244 '/', /* ar_pad_char */
3245 15, /* ar_max_namelen??? FIXMEmgo */
3248 bfd_getb64
, /* bfd_getx64 */
3249 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3250 bfd_putb64
, /* bfd_putx64 */
3251 bfd_getb32
, /* bfd_getx32 */
3252 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3253 bfd_putb32
, /* bfd_putx32 */
3254 bfd_getb16
, /* bfd_getx16 */
3255 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3256 bfd_putb16
, /* bfd_putx16 */
3259 bfd_getb64
, /* bfd_h_getx64 */
3260 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3261 bfd_putb64
, /* bfd_h_putx64 */
3262 bfd_getb32
, /* bfd_h_getx32 */
3263 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3264 bfd_putb32
, /* bfd_h_putx32 */
3265 bfd_getb16
, /* bfd_h_getx16 */
3266 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3267 bfd_putb16
, /* bfd_h_putx16 */
3269 { /* bfd_check_format */
3272 _bfd_xcoff_archive_p
,
3276 { /* bfd_set_format */
3279 _bfd_generic_mkarchive
,
3283 {/* bfd_write_contents */
3285 coff_write_object_contents
,
3286 _bfd_xcoff_write_archive_contents
,
3291 bfd_true
, /* _close_and_cleanup */
3292 bfd_true
, /* _bfd_free_cached_info */
3293 coff_new_section_hook
, /* _new_section_hook */
3294 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3295 /* _bfd_get_section_contents_in_window */
3296 _bfd_generic_get_section_contents_in_window
,
3299 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3300 /* _bfd_merge_private_bfd_data */
3301 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3302 /* _bfd_copy_pivate_section_data */
3303 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3304 /* _bfd_copy_private_symbol_data */
3305 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3306 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3307 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3310 rs6000coff_core_file_failing_command
, /* _core_file_failing_command */
3311 rs6000coff_core_file_failing_signal
, /* _core_file_failing_signal */
3312 /* _core_file_matches_executable_p */
3313 rs6000coff_core_file_matches_executable_p
,
3316 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3317 /* XCOFF archives do not have
3318 anything which corresponds to
3319 an extended name table. */
3320 bfd_false
, /* _slurp_extended_name_table */
3321 /* _construct_extended_name_table */
3322 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3323 bfd_dont_truncate_arname
, /* _truncate_arname */
3324 _bfd_xcoff_write_armap
, /* _write_armap */
3325 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3326 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3327 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3328 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3329 /* XCOFF archives do not have
3331 bfd_true
, /* _update_armap_timestamp */
3334 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3335 coff_get_symtab
, /* _get_symtab */
3336 coff_make_empty_symbol
, /* _make_empty_symbol */
3337 coff_print_symbol
, /* _print_symbol */
3338 coff_get_symbol_info
, /* _get_symbol_info */
3339 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3340 coff_get_lineno
, /* _get_lineno */
3341 coff_find_nearest_line
, /* _find_nearest_line */
3342 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3343 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3344 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3347 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3348 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3349 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3352 coff_set_arch_mach
, /* _set_arch_mach */
3353 coff_set_section_contents
, /* _set_section_contents */
3356 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3357 /* _bfd_get_relocated_section_contents */
3358 bfd_generic_get_relocated_section_contents
,
3359 bfd_generic_relax_section
, /* _bfd_relax_section */
3360 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3361 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3362 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3363 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3364 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3365 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3368 /* _get_dynamic_symtab_upper_bound */
3369 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3370 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3371 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3372 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3374 /* Opposite endian version, none exists */
3378 (void *) &bfd_pmac_xcoff_backend_data
,