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 boolean _bfd_xcoff_mkobject
PARAMS ((bfd
*));
41 extern boolean _bfd_xcoff_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
42 extern boolean _bfd_xcoff_is_local_label_name
PARAMS ((bfd
*, const char *));
43 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
44 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
45 extern boolean _bfd_xcoff_slurp_armap
PARAMS ((bfd
*));
46 extern const bfd_target
*_bfd_xcoff_archive_p
PARAMS ((bfd
*));
47 extern PTR _bfd_xcoff_read_ar_hdr
PARAMS ((bfd
*));
48 extern bfd
*_bfd_xcoff_openr_next_archived_file
PARAMS ((bfd
*, bfd
*));
49 extern int _bfd_xcoff_generic_stat_arch_elt
PARAMS ((bfd
*, struct stat
*));
50 extern boolean _bfd_xcoff_write_armap
51 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
52 extern boolean _bfd_xcoff_write_archive_contents
PARAMS ((bfd
*));
53 extern int _bfd_xcoff_sizeof_headers
PARAMS ((bfd
*, boolean
));
54 extern void _bfd_xcoff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
55 extern unsigned int _bfd_xcoff_swap_sym_out
PARAMS ((bfd
*, PTR
, PTR
));
56 extern void _bfd_xcoff_swap_aux_in
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
57 extern unsigned int _bfd_xcoff_swap_aux_out
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
59 /* Forward declare _bfd_xcoff_rtype2howto for coffcode.h macro */
60 void _bfd_xcoff_rtype2howto
PARAMS ((arelent
*, struct internal_reloc
*));
62 /* coffcode.h needs these to be defined */
63 #define RS6000COFF_C 1
65 #define SELECT_RELOC(internal, howto) \
67 internal.r_type = howto->type; \
69 ((howto->complain_on_overflow == complain_overflow_signed \
72 | (howto->bitsize - 1)); \
75 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
76 #define COFF_LONG_FILENAMES
77 #define NO_COFF_SYMBOLS
78 #define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst)
79 #define coff_mkobject _bfd_xcoff_mkobject
80 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
81 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
82 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
84 extern const bfd_target
* rs6000coff_core_p ();
85 extern boolean
rs6000coff_core_file_matches_executable_p ();
86 extern char *rs6000coff_core_file_failing_command
PARAMS ((bfd
*abfd
));
87 extern int rs6000coff_core_file_failing_signal
PARAMS ((bfd
*abfd
));
88 #define CORE_FILE_P rs6000coff_core_p
89 #define coff_core_file_failing_command \
90 rs6000coff_core_file_failing_command
91 #define coff_core_file_failing_signal \
92 rs6000coff_core_file_failing_signal
93 #define coff_core_file_matches_executable_p \
94 rs6000coff_core_file_matches_executable_p
96 #define CORE_FILE_P _bfd_dummy_target
97 #define coff_core_file_failing_command \
98 _bfd_nocore_core_file_failing_command
99 #define coff_core_file_failing_signal \
100 _bfd_nocore_core_file_failing_signal
101 #define coff_core_file_matches_executable_p \
102 _bfd_nocore_core_file_matches_executable_p
104 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
105 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
106 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
107 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
109 #include "coffcode.h"
111 /* The main body of code is in coffcode.h. */
113 static const char *normalize_filename
PARAMS ((bfd
*));
115 /* We use our own tdata type. Its first field is the COFF tdata type,
116 so the COFF routines are compatible. */
119 _bfd_xcoff_mkobject (abfd
)
122 coff_data_type
*coff
;
124 abfd
->tdata
.xcoff_obj_data
=
125 ((struct xcoff_tdata
*)
126 bfd_zalloc (abfd
, sizeof (struct xcoff_tdata
)));
127 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
129 coff
= coff_data (abfd
);
130 coff
->symbols
= (coff_symbol_type
*) NULL
;
131 coff
->conversion_table
= (unsigned int *) NULL
;
132 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
135 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
137 /* We set cputype to -1 to indicate that it has not been
139 xcoff_data (abfd
)->cputype
= -1;
141 xcoff_data (abfd
)->csects
= NULL
;
142 xcoff_data (abfd
)->debug_indices
= NULL
;
144 /* text section alignment is different than the default */
145 /* xcoff_data (abfd)->text_align_power = 5; */
150 /* Copy XCOFF data from one BFD to another. */
153 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
157 struct xcoff_tdata
*ix
, *ox
;
160 if (ibfd
->xvec
!= obfd
->xvec
)
162 ix
= xcoff_data (ibfd
);
163 ox
= xcoff_data (obfd
);
164 ox
->full_aouthdr
= ix
->full_aouthdr
;
170 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
174 ox
->sntoc
= sec
->output_section
->target_index
;
176 if (ix
->snentry
== 0)
180 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
184 ox
->snentry
= sec
->output_section
->target_index
;
186 ox
->text_align_power
= ix
->text_align_power
;
187 ox
->data_align_power
= ix
->data_align_power
;
188 ox
->modtype
= ix
->modtype
;
189 ox
->cputype
= ix
->cputype
;
190 ox
->maxdata
= ix
->maxdata
;
191 ox
->maxstack
= ix
->maxstack
;
195 /* I don't think XCOFF really has a notion of local labels based on
196 name. This will mean that ld -X doesn't actually strip anything.
197 The AIX native linker does not have a -X option, and it ignores the
201 _bfd_xcoff_is_local_label_name (abfd
, name
)
202 bfd
*abfd ATTRIBUTE_UNUSED
;
203 const char *name ATTRIBUTE_UNUSED
;
211 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
216 SYMENT
*ext
= (SYMENT
*)ext1
;
217 struct internal_syment
*in
= (struct internal_syment
*)in1
;
219 if(ext
->e
.e_name
[0] != 0) {
220 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
222 in
->_n
._n_n
._n_zeroes
= 0;
223 in
->_n
._n_n
._n_offset
=
224 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
227 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
228 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
229 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
230 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
231 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
235 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
240 struct internal_syment
*in
= (struct internal_syment
*)inp
;
241 SYMENT
*ext
=(SYMENT
*)extp
;
243 if(in
->_n
._n_name
[0] != 0) {
244 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
246 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
247 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
,
248 (bfd_byte
*) ext
->e
.e
.e_offset
);
251 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
252 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
253 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
254 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
255 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
256 return bfd_coff_symesz (abfd
);
259 #define PUTWORD bfd_h_put_32
260 #define PUTHALF bfd_h_put_16
261 #define PUTBYTE bfd_h_put_8
262 #define GETWORD bfd_h_get_32
263 #define GETHALF bfd_h_get_16
264 #define GETBYTE bfd_h_get_8
267 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
276 AUXENT
*ext
= (AUXENT
*)ext1
;
277 union internal_auxent
*in
= (union internal_auxent
*)in1
;
281 if (ext
->x_file
.x_fname
[0] == 0) {
282 in
->x_file
.x_n
.x_zeroes
= 0;
283 in
->x_file
.x_n
.x_offset
=
284 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
289 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
290 numaux
* sizeof (AUXENT
));
294 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
299 /* RS/6000 "csect" auxents */
302 if (indx
+ 1 == numaux
)
304 in
->x_csect
.x_scnlen
.l
=
305 bfd_h_get_32 (abfd
, ext
->x_csect
.x_scnlen
);
306 in
->x_csect
.x_parmhash
= bfd_h_get_32 (abfd
,
307 ext
->x_csect
.x_parmhash
);
308 in
->x_csect
.x_snhash
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snhash
);
309 /* We don't have to hack bitfields in x_smtyp because it's
310 defined by shifts-and-ands, which are equivalent on all
312 in
->x_csect
.x_smtyp
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smtyp
);
313 in
->x_csect
.x_smclas
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smclas
);
314 in
->x_csect
.x_stab
= bfd_h_get_32 (abfd
, ext
->x_csect
.x_stab
);
315 in
->x_csect
.x_snstab
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snstab
);
323 if (type
== T_NULL
) {
324 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
,
325 (bfd_byte
*) ext
->x_scn
.x_scnlen
);
326 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
,
327 (bfd_byte
*) ext
->x_scn
.x_nreloc
);
328 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
,
329 (bfd_byte
*) ext
->x_scn
.x_nlinno
);
330 /* PE defines some extra fields; we zero them out for
332 in
->x_scn
.x_checksum
= 0;
333 in
->x_scn
.x_associated
= 0;
334 in
->x_scn
.x_comdat
= 0;
341 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
342 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
344 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
346 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, (bfd_byte
*)
347 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
348 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*)
349 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
353 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
354 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
355 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
356 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
357 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
358 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
359 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
360 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
363 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
366 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, (bfd_byte
*)
367 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
368 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, (bfd_byte
*)
369 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
373 /* the semicolon is because MSVC doesn't like labels at
381 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
386 int indx ATTRIBUTE_UNUSED
;
387 int numaux ATTRIBUTE_UNUSED
;
390 union internal_auxent
*in
= (union internal_auxent
*)inp
;
391 AUXENT
*ext
= (AUXENT
*)extp
;
393 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
397 if (in
->x_file
.x_fname
[0] == 0)
399 PUTWORD(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
401 in
->x_file
.x_n
.x_offset
,
402 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
406 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
410 /* RS/6000 "csect" auxents */
413 if (indx
+ 1 == numaux
)
415 PUTWORD (abfd
, in
->x_csect
.x_scnlen
.l
,ext
->x_csect
.x_scnlen
);
416 PUTWORD (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
417 PUTHALF (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
418 /* We don't have to hack bitfields in x_smtyp because it's
419 defined by shifts-and-ands, which are equivalent on all
421 PUTBYTE (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
422 PUTBYTE (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
423 PUTWORD (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
424 PUTHALF (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
432 if (type
== T_NULL
) {
433 bfd_h_put_32(abfd
, in
->x_scn
.x_scnlen
, (bfd_byte
*) ext
->x_scn
.x_scnlen
);
434 bfd_h_put_16(abfd
, in
->x_scn
.x_nreloc
, (bfd_byte
*) ext
->x_scn
.x_nreloc
);
435 bfd_h_put_16(abfd
, in
->x_scn
.x_nlinno
, (bfd_byte
*) ext
->x_scn
.x_nlinno
);
441 PUTWORD(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
442 bfd_h_put_16 (abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
444 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
446 bfd_h_put_32(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
447 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
448 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
449 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
453 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
454 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
455 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
456 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
457 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
458 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
459 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
460 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
464 PUTWORD (abfd
, in
->x_sym
.x_misc
.x_fsize
,
465 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
468 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
469 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
470 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
471 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
475 return bfd_coff_auxesz (abfd
);
480 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
481 bitsize and whether they are signed or not, along with a
482 conventional type. This table is for the types, which are used for
483 different algorithms for putting in the reloc. Many of these
484 relocs need special_function entries, which I have not written. */
487 reloc_howto_type xcoff_howto_table
[] =
489 /* Standard 32 bit relocation. */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_bitfield
, /* complain_on_overflow */
497 0, /* special_function */
499 true, /* partial_inplace */
500 0xffffffff, /* src_mask */
501 0xffffffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* 32 bit relocation, but store negative value. */
507 -2, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield
, /* complain_on_overflow */
512 0, /* special_function */
514 true, /* partial_inplace */
515 0xffffffff, /* src_mask */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* 32 bit PC relative relocation. */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 true, /* pc_relative */
526 complain_overflow_signed
, /* complain_on_overflow */
527 0, /* special_function */
529 true, /* partial_inplace */
530 0xffffffff, /* src_mask */
531 0xffffffff, /* dst_mask */
532 false), /* pcrel_offset */
534 /* 16 bit TOC relative relocation. */
537 1, /* size (0 = byte, 1 = short, 2 = long) */
539 false, /* pc_relative */
541 complain_overflow_bitfield
, /* complain_on_overflow */
542 0, /* special_function */
544 true, /* partial_inplace */
545 0xffff, /* src_mask */
546 0xffff, /* dst_mask */
547 false), /* pcrel_offset */
549 /* I don't really know what this is. */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 false, /* pc_relative */
556 complain_overflow_bitfield
, /* complain_on_overflow */
557 0, /* special_function */
559 true, /* partial_inplace */
560 0xffffffff, /* src_mask */
561 0xffffffff, /* dst_mask */
562 false), /* pcrel_offset */
564 /* External TOC relative symbol. */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 false, /* pc_relative */
571 complain_overflow_bitfield
, /* complain_on_overflow */
572 0, /* special_function */
574 true, /* partial_inplace */
575 0xffff, /* src_mask */
576 0xffff, /* dst_mask */
577 false), /* pcrel_offset */
579 /* Local TOC relative symbol. */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 false, /* pc_relative */
586 complain_overflow_bitfield
, /* complain_on_overflow */
587 0, /* special_function */
589 true, /* partial_inplace */
590 0xffff, /* src_mask */
591 0xffff, /* dst_mask */
592 false), /* pcrel_offset */
596 /* Non modifiable absolute branch. */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 false, /* pc_relative */
603 complain_overflow_bitfield
, /* complain_on_overflow */
604 0, /* special_function */
606 true, /* partial_inplace */
607 0x3fffffc, /* src_mask */
608 0x3fffffc, /* dst_mask */
609 false), /* pcrel_offset */
613 /* Non modifiable relative branch. */
614 HOWTO (0xa, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 true, /* pc_relative */
620 complain_overflow_signed
, /* complain_on_overflow */
621 0, /* special_function */
623 true, /* partial_inplace */
624 0x3fffffc, /* src_mask */
625 0x3fffffc, /* dst_mask */
626 false), /* pcrel_offset */
631 HOWTO (0xc, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 false, /* pc_relative */
637 complain_overflow_bitfield
, /* complain_on_overflow */
638 0, /* special_function */
640 true, /* partial_inplace */
641 0xffff, /* src_mask */
642 0xffff, /* dst_mask */
643 false), /* pcrel_offset */
646 HOWTO (0xd, /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 false, /* pc_relative */
652 complain_overflow_bitfield
, /* complain_on_overflow */
653 0, /* special_function */
655 true, /* partial_inplace */
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
658 false), /* pcrel_offset */
662 /* Non-relocating reference. */
663 HOWTO (0xf, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_bitfield
, /* complain_on_overflow */
670 0, /* special_function */
672 false, /* partial_inplace */
675 false), /* pcrel_offset */
680 /* TOC relative indirect load. */
681 HOWTO (0x12, /* type */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
685 false, /* pc_relative */
687 complain_overflow_bitfield
, /* complain_on_overflow */
688 0, /* special_function */
690 true, /* partial_inplace */
691 0xffff, /* src_mask */
692 0xffff, /* dst_mask */
693 false), /* pcrel_offset */
695 /* TOC relative load address. */
696 HOWTO (0x13, /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 false, /* pc_relative */
702 complain_overflow_bitfield
, /* complain_on_overflow */
703 0, /* special_function */
705 true, /* partial_inplace */
706 0xffff, /* src_mask */
707 0xffff, /* dst_mask */
708 false), /* pcrel_offset */
710 /* Modifiable relative branch. */
711 HOWTO (0x14, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_bitfield
, /* complain_on_overflow */
718 0, /* special_function */
719 "R_RRTBI", /* name */
720 true, /* partial_inplace */
721 0xffffffff, /* src_mask */
722 0xffffffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* Modifiable absolute branch. */
726 HOWTO (0x15, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 false, /* pc_relative */
732 complain_overflow_bitfield
, /* complain_on_overflow */
733 0, /* special_function */
734 "R_RRTBA", /* name */
735 true, /* partial_inplace */
736 0xffffffff, /* src_mask */
737 0xffffffff, /* dst_mask */
738 false), /* pcrel_offset */
740 /* Modifiable call absolute indirect. */
741 HOWTO (0x16, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 false, /* pc_relative */
747 complain_overflow_bitfield
, /* complain_on_overflow */
748 0, /* special_function */
750 true, /* partial_inplace */
751 0xffff, /* src_mask */
752 0xffff, /* dst_mask */
753 false), /* pcrel_offset */
755 /* Modifiable call relative. */
756 HOWTO (0x17, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 false, /* pc_relative */
762 complain_overflow_bitfield
, /* complain_on_overflow */
763 0, /* special_function */
765 true, /* partial_inplace */
766 0xffff, /* src_mask */
767 0xffff, /* dst_mask */
768 false), /* pcrel_offset */
770 /* Modifiable branch absolute. */
771 HOWTO (0x18, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 false, /* pc_relative */
777 complain_overflow_bitfield
, /* complain_on_overflow */
778 0, /* special_function */
780 true, /* partial_inplace */
781 0xffff, /* src_mask */
782 0xffff, /* dst_mask */
783 false), /* pcrel_offset */
785 /* Modifiable branch absolute. */
786 HOWTO (0x19, /* type */
788 2, /* size (0 = byte, 1 = short, 2 = long) */
790 false, /* pc_relative */
792 complain_overflow_bitfield
, /* complain_on_overflow */
793 0, /* special_function */
795 true, /* partial_inplace */
796 0xffff, /* src_mask */
797 0xffff, /* dst_mask */
798 false), /* pcrel_offset */
800 /* Modifiable branch relative. */
801 HOWTO (0x1a, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_signed
, /* complain_on_overflow */
808 0, /* special_function */
810 true, /* partial_inplace */
811 0xffff, /* src_mask */
812 0xffff, /* dst_mask */
813 false), /* pcrel_offset */
815 /* Modifiable branch absolute. */
816 HOWTO (0x1b, /* type */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
820 false, /* pc_relative */
822 complain_overflow_bitfield
, /* complain_on_overflow */
823 0, /* special_function */
825 true, /* partial_inplace */
826 0xffff, /* src_mask */
827 0xffff, /* dst_mask */
828 false), /* pcrel_offset */
832 4, /* size (0 = byte, 1 = short, 2 = long) */
834 false, /* pc_relative */
836 complain_overflow_bitfield
, /* complain_on_overflow */
837 0, /* special_function */
839 true, /* partial_inplace */
840 MINUS_ONE
, /* src_mask */
841 MINUS_ONE
, /* dst_mask */
842 false) /* pcrel_offset */
847 _bfd_xcoff_rtype2howto (relent
, internal
)
849 struct internal_reloc
*internal
;
851 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
853 /* Check for relocs we don't know of. */
855 >= sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]))
857 if (internal
->r_type
!= relent
->howto
->type
)
860 /* The r_size field of an XCOFF reloc encodes the bitsize of the
861 relocation, as well as indicating whether it is signed or not.
862 Doublecheck that the relocation information gathered from the
863 type matches this information. The bitsize is not significant
865 if (relent
->howto
->dst_mask
!= 0
866 && (relent
->howto
->bitsize
867 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
870 if ((internal
->r_size
& 0x80) != 0
871 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
872 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
878 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
879 bfd
*abfd ATTRIBUTE_UNUSED
;
880 bfd_reloc_code_real_type code
;
884 case BFD_RELOC_PPC_B26
:
885 return &xcoff_howto_table
[0xa];
886 case BFD_RELOC_PPC_BA26
:
887 return &xcoff_howto_table
[8];
888 case BFD_RELOC_PPC_TOC16
:
889 return &xcoff_howto_table
[3];
892 return &xcoff_howto_table
[0];
894 return &xcoff_howto_table
[0x1c];
901 /* XCOFF archive support. The original version of this code was by
902 Damon A. Permezel. It was enhanced to permit cross support, and
903 writing archive files, by Ian Lance Taylor, Cygnus Support.
905 XCOFF uses its own archive format. Everything is hooked together
906 with file offset links, so it is possible to rapidly update an
907 archive in place. Of course, we don't do that. An XCOFF archive
908 has a real file header, not just an ARMAG string. The structure of
909 the file header and of each archive header appear below.
911 An XCOFF archive also has a member table, which is a list of
912 elements in the archive (you can get that by looking through the
913 linked list, but you have to read a lot more of the file). The
914 member table has a normal archive header with an empty name. It is
915 normally (and perhaps must be) the second to last entry in the
916 archive. The member table data is almost printable ASCII. It
917 starts with a 12 character decimal string which is the number of
918 entries in the table. For each entry it has a 12 character decimal
919 string which is the offset in the archive of that member. These
920 entries are followed by a series of null terminated strings which
921 are the member names for each entry.
923 Finally, an XCOFF archive has a global symbol table, which is what
924 we call the armap. The global symbol table has a normal archive
925 header with an empty name. It is normally (and perhaps must be)
926 the last entry in the archive. The contents start with a four byte
927 binary number which is the number of entries. This is followed by
928 a that many four byte binary numbers; each is the file offset of an
929 entry in the archive. These numbers are followed by a series of
930 null terminated strings, which are symbol names.
932 AIX 4.3 introduced a new archive format which can handle larger
933 files and also 32- and 64-bit objects in the same archive. The
934 things said above remain true except that there is now more than
935 one global symbol table. The one is used to index 32-bit objects,
936 the other for 64-bit objects.
938 The new archives (recognizable by the new ARMAG string) has larger
939 field lengths so that we cannot really share any code. Also we have
940 to take care that we are not generating the new form of archives
941 on AIX 4.2 or earlier systems. */
943 /* XCOFF archives use this as a magic string. Note that both strings
944 have the same length. */
948 /* Read in the armap of an XCOFF archive. */
951 _bfd_xcoff_slurp_armap (abfd
)
957 bfd_byte
*contents
, *cend
;
962 if (xcoff_ardata (abfd
) == NULL
)
964 bfd_has_map (abfd
) = false;
968 if (! xcoff_big_format_p (abfd
))
970 /* This is for the old format. */
971 struct xcoff_ar_hdr hdr
;
973 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
976 bfd_has_map (abfd
) = false;
980 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
983 /* The symbol table starts with a normal archive header. */
984 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
987 /* Skip the name (normally empty). */
988 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
989 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
992 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
994 /* Read in the entire symbol table. */
995 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
996 if (contents
== NULL
)
998 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1001 /* The symbol table starts with a four byte count. */
1002 c
= bfd_h_get_32 (abfd
, contents
);
1006 bfd_set_error (bfd_error_bad_value
);
1010 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1011 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1012 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1015 /* After the count comes a list of four byte file offsets. */
1016 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1018 ++i
, ++arsym
, p
+= 4)
1019 arsym
->file_offset
= bfd_h_get_32 (abfd
, p
);
1023 /* This is for the new format. */
1024 struct xcoff_ar_hdr_big hdr
;
1026 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1029 bfd_has_map (abfd
) = false;
1033 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1036 /* The symbol table starts with a normal archive header. */
1037 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1038 != SIZEOF_AR_HDR_BIG
)
1041 /* Skip the name (normally empty). */
1042 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1043 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1046 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1047 machines) since the field width is 20 and there numbers with more
1048 than 32 bits can be represented. */
1049 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1051 /* Read in the entire symbol table. */
1052 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1053 if (contents
== NULL
)
1055 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1058 /* The symbol table starts with an eight byte count. */
1059 c
= bfd_h_get_64 (abfd
, contents
);
1063 bfd_set_error (bfd_error_bad_value
);
1067 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1068 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1069 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1072 /* After the count comes a list of eight byte file offsets. */
1073 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1075 ++i
, ++arsym
, p
+= 8)
1076 arsym
->file_offset
= bfd_h_get_64 (abfd
, p
);
1079 /* After the file offsets come null terminated symbol names. */
1080 cend
= contents
+ sz
;
1081 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1083 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1087 bfd_set_error (bfd_error_bad_value
);
1090 arsym
->name
= (char *) p
;
1093 bfd_ardata (abfd
)->symdef_count
= c
;
1094 bfd_has_map (abfd
) = true;
1099 /* See if this is an XCOFF archive. */
1102 _bfd_xcoff_archive_p (abfd
)
1105 char magic
[SXCOFFARMAG
];
1107 if (bfd_read ((PTR
) magic
, SXCOFFARMAG
, 1, abfd
) != SXCOFFARMAG
)
1109 if (bfd_get_error () != bfd_error_system_call
)
1110 bfd_set_error (bfd_error_wrong_format
);
1114 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1115 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1117 bfd_set_error (bfd_error_wrong_format
);
1121 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1122 involves a cast, we can't do it as the left operand of
1124 abfd
->tdata
.aout_ar_data
=
1125 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
1127 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1130 bfd_ardata (abfd
)->cache
= NULL
;
1131 bfd_ardata (abfd
)->archive_head
= NULL
;
1132 bfd_ardata (abfd
)->symdefs
= NULL
;
1133 bfd_ardata (abfd
)->extended_names
= NULL
;
1135 /* Now handle the two formats. */
1136 if (magic
[1] != 'b')
1138 /* This is the old format. */
1139 struct xcoff_ar_file_hdr hdr
;
1141 /* Copy over the magic string. */
1142 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1144 /* Now read the rest of the file header. */
1145 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, 1,
1146 abfd
) != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1148 if (bfd_get_error () != bfd_error_system_call
)
1149 bfd_set_error (bfd_error_wrong_format
);
1153 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1154 (char **) NULL
, 10);
1156 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR
);
1157 if (bfd_ardata (abfd
)->tdata
== NULL
)
1160 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1164 /* This is the new format. */
1165 struct xcoff_ar_file_hdr_big hdr
;
1167 /* Copy over the magic string. */
1168 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1170 /* Now read the rest of the file header. */
1171 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, 1,
1172 abfd
) != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1174 if (bfd_get_error () != bfd_error_system_call
)
1175 bfd_set_error (bfd_error_wrong_format
);
1179 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1180 machines) since the field width is 20 and there numbers with more
1181 than 32 bits can be represented. */
1182 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1183 (char **) NULL
, 10);
1185 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR_BIG
);
1186 if (bfd_ardata (abfd
)->tdata
== NULL
)
1189 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1192 if (! _bfd_xcoff_slurp_armap (abfd
))
1194 bfd_release (abfd
, bfd_ardata (abfd
));
1195 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1202 /* Read the archive header in an XCOFF archive. */
1205 _bfd_xcoff_read_ar_hdr (abfd
)
1209 struct areltdata
*ret
;
1211 ret
= (struct areltdata
*) bfd_alloc (abfd
, sizeof (struct areltdata
));
1215 if (! xcoff_big_format_p (abfd
))
1217 struct xcoff_ar_hdr hdr
;
1218 struct xcoff_ar_hdr
*hdrp
;
1220 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1226 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1227 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
,
1228 SIZEOF_AR_HDR
+ namlen
+ 1);
1234 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1235 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR
, 1, namlen
, abfd
) != namlen
)
1240 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1242 ret
->arch_header
= (char *) hdrp
;
1243 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1244 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1248 struct xcoff_ar_hdr_big hdr
;
1249 struct xcoff_ar_hdr_big
*hdrp
;
1251 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1252 != SIZEOF_AR_HDR_BIG
)
1258 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1259 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
,
1267 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1268 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, 1, namlen
, abfd
) != namlen
)
1273 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1275 ret
->arch_header
= (char *) hdrp
;
1276 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1277 machines) since the field width is 20 and there numbers with more
1278 than 32 bits can be represented. */
1279 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1280 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1283 /* Skip over the XCOFFARFMAG at the end of the file name. */
1284 if (bfd_seek (abfd
, (namlen
& 1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1290 /* Open the next element in an XCOFF archive. */
1293 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1299 if (xcoff_ardata (archive
) == NULL
)
1301 bfd_set_error (bfd_error_invalid_operation
);
1305 if (! xcoff_big_format_p (archive
))
1307 if (last_file
== NULL
)
1308 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1310 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1314 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1316 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1317 (char **) NULL
, 10))
1319 bfd_set_error (bfd_error_no_more_archived_files
);
1325 if (last_file
== NULL
)
1326 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1328 /* XXX These actually have to be a calls to strtoll (at least
1329 on 32-bit machines) since the fields's width is 20 and
1330 there numbers with more than 32 bits can be represented. */
1331 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1334 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1335 machines) since the fields's width is 20 and there numbers with more
1336 than 32 bits can be represented. */
1338 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1340 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1341 (char **) NULL
, 10))
1343 bfd_set_error (bfd_error_no_more_archived_files
);
1348 return _bfd_get_elt_at_filepos (archive
, filestart
);
1351 /* Stat an element in an XCOFF archive. */
1354 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1358 if (abfd
->arelt_data
== NULL
)
1360 bfd_set_error (bfd_error_invalid_operation
);
1364 if (! xcoff_big_format_p (abfd
))
1366 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1368 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1369 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1370 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1371 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1372 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1376 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1378 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1379 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1380 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1381 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1382 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1388 /* Normalize a file name for inclusion in an archive. */
1391 normalize_filename (abfd
)
1395 const char *filename
;
1397 file
= bfd_get_filename (abfd
);
1398 filename
= strrchr (file
, '/');
1399 if (filename
!= NULL
)
1406 /* Write out an XCOFF armap. */
1410 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1412 unsigned int elength ATTRIBUTE_UNUSED
;
1414 unsigned int orl_count
;
1417 struct xcoff_ar_hdr hdr
;
1419 unsigned char buf
[4];
1424 memset (&hdr
, 0, sizeof hdr
);
1425 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1426 sprintf (hdr
.nextoff
, "%d", 0);
1427 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1428 sprintf (hdr
.date
, "%d", 0);
1429 sprintf (hdr
.uid
, "%d", 0);
1430 sprintf (hdr
.gid
, "%d", 0);
1431 sprintf (hdr
.mode
, "%d", 0);
1432 sprintf (hdr
.namlen
, "%d", 0);
1434 /* We need spaces, not null bytes, in the header. */
1435 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1439 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
1440 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1443 bfd_h_put_32 (abfd
, orl_count
, buf
);
1444 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1447 sub
= abfd
->archive_head
;
1448 fileoff
= SIZEOF_AR_FILE_HDR
;
1450 while (sub
!= NULL
&& i
< orl_count
)
1454 while (((bfd
*) (map
[i
]).pos
) == sub
)
1456 bfd_h_put_32 (abfd
, fileoff
, buf
);
1457 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1461 namlen
= strlen (normalize_filename (sub
));
1462 namlen
= (namlen
+ 1) &~ 1;
1463 fileoff
+= (SIZEOF_AR_HDR
1466 + arelt_size (sub
));
1467 fileoff
= (fileoff
+ 1) &~ 1;
1471 for (i
= 0; i
< orl_count
; i
++)
1476 name
= *map
[i
].name
;
1477 namlen
= strlen (name
);
1478 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1482 if ((stridx
& 1) != 0)
1487 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1494 /* Write a single armap in the big format. */
1496 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1500 unsigned int orl_count
;
1501 unsigned int orl_ccount
;
1502 unsigned int stridx
;
1504 const char *prevoff
;
1507 struct xcoff_ar_hdr_big hdr
;
1509 unsigned char buf
[4];
1512 const bfd_arch_info_type
*arch_info
;
1516 memset (&hdr
, 0, sizeof hdr
);
1517 /* XXX This call actually should use %lld (at least on 32-bit
1518 machines) since the fields's width is 20 and there numbers with
1519 more than 32 bits can be represented. */
1520 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1522 sprintf (hdr
.nextoff
, "%d", 0);
1524 /* do explict cast to long to remove compiler warning */
1525 sprintf (hdr
.nextoff
, "%ld", (strtol (prevoff
, (char **) NULL
, 10)
1526 + (long) (4 + orl_ccount
* 4 + stridx
)));
1529 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1530 sprintf (hdr
.date
, "%d", 0);
1531 sprintf (hdr
.uid
, "%d", 0);
1532 sprintf (hdr
.gid
, "%d", 0);
1533 sprintf (hdr
.mode
, "%d", 0);
1534 sprintf (hdr
.namlen
, "%d", 0);
1536 /* We need spaces, not null bytes, in the header. */
1537 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1541 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1543 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
) != SIZEOF_AR_HDR_BIG
1544 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1547 bfd_h_put_32 (abfd
, orl_ccount
, buf
);
1548 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1551 sub
= abfd
->archive_head
;
1552 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1554 while (sub
!= NULL
&& i
< orl_count
)
1558 if ((bfd_arch_bits_per_address ((bfd
*) map
[i
].pos
) == 64) == bits64
)
1559 while (((bfd
*) (map
[i
]).pos
) == sub
)
1561 bfd_h_put_32 (abfd
, fileoff
, buf
);
1562 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1567 while (((bfd
*) (map
[i
]).pos
) == sub
)
1570 namlen
= strlen (normalize_filename (sub
));
1571 namlen
= (namlen
+ 1) &~ 1;
1572 fileoff
+= (SIZEOF_AR_HDR_BIG
1575 + arelt_size (sub
));
1576 fileoff
= (fileoff
+ 1) &~ 1;
1581 for (i
= 0; i
< orl_count
; i
++)
1585 bfd
*ob
= (bfd
*)map
[i
].pos
;
1587 if (ob
!= object_bfd
)
1588 arch_info
= bfd_get_arch_info (ob
);
1589 if ((arch_info
->bits_per_address
== 64) != bits64
)
1592 name
= *map
[i
].name
;
1593 namlen
= strlen (name
);
1594 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1598 if ((stridx
& 1) != 0)
1603 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1612 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1614 unsigned int elength ATTRIBUTE_UNUSED
;
1616 unsigned int orl_count
;
1620 unsigned int orl_count_32
, orl_count_64
;
1621 unsigned int stridx_32
, stridx_64
;
1622 const bfd_arch_info_type
*arch_info
;
1625 /* First, we look through the symbols and work out which are
1626 from 32-bit objects and which from 64-bit ones. */
1632 for (i
= 0; i
< orl_count
; i
++)
1634 bfd
*ob
= (bfd
*)map
[i
].pos
;
1636 if (ob
!= object_bfd
)
1637 arch_info
= bfd_get_arch_info (ob
);
1638 len
= strlen (*map
[i
].name
) + 1;
1639 if (arch_info
->bits_per_address
== 64)
1651 /* A quick sanity check... */
1652 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1653 /* explicit cast to int for compiler */
1654 BFD_ASSERT ((int)(stridx_64
+ stridx_32
) == stridx
);
1656 /* Now write out each map. */
1657 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1659 xcoff_ardata_big (abfd
)->memoff
,
1660 xcoff_ardata_big (abfd
)->symoff
))
1662 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1664 xcoff_ardata_big (abfd
)->symoff
,
1665 xcoff_ardata_big (abfd
)->symoff64
))
1673 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1675 unsigned int elength ATTRIBUTE_UNUSED
;
1677 unsigned int orl_count
;
1680 if (! xcoff_big_format_p (abfd
))
1681 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1683 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1686 /* Write out an XCOFF archive. We always write an entire archive,
1687 rather than fussing with the freelist and so forth. */
1690 xcoff_write_archive_contents_old (abfd
)
1693 struct xcoff_ar_file_hdr fhdr
;
1695 size_t total_namlen
;
1699 file_ptr prevoff
, nextoff
;
1702 struct xcoff_ar_hdr ahdr
;
1707 memset (&fhdr
, 0, sizeof fhdr
);
1708 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1709 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1710 sprintf (fhdr
.freeoff
, "%d", 0);
1714 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1717 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1719 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1720 if (offsets
== NULL
)
1723 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1726 makemap
= bfd_has_map (abfd
);
1729 nextoff
= SIZEOF_AR_FILE_HDR
;
1730 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1734 struct xcoff_ar_hdr
*ahdrp
;
1735 bfd_size_type remaining
;
1737 if (makemap
&& ! hasobjects
)
1739 if (bfd_check_format (sub
, bfd_object
))
1743 name
= normalize_filename (sub
);
1744 namlen
= strlen (name
);
1746 if (sub
->arelt_data
!= NULL
)
1747 ahdrp
= arch_xhdr (sub
);
1755 memset (&ahdr
, 0, sizeof ahdr
);
1757 if (stat (bfd_get_filename (sub
), &s
) != 0)
1759 bfd_set_error (bfd_error_system_call
);
1763 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1764 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1765 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1766 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1767 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1769 if (sub
->arelt_data
== NULL
)
1771 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
1772 if (sub
->arelt_data
== NULL
)
1776 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1779 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1780 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1782 /* If the length of the name is odd, we write out the null byte
1783 after the name as well. */
1784 namlen
= (namlen
+ 1) &~ 1;
1786 remaining
= arelt_size (sub
);
1787 size
= (SIZEOF_AR_HDR
1792 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1794 offsets
[i
] = nextoff
;
1797 nextoff
+= size
+ (size
& 1);
1799 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1801 /* We need spaces, not null bytes, in the header. */
1802 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1806 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1807 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
1808 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1812 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1814 while (remaining
!= 0)
1817 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1819 amt
= sizeof buffer
;
1820 if (amt
> remaining
)
1822 if (bfd_read (buffer
, 1, amt
, sub
) != amt
1823 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
1828 if ((size
& 1) != 0)
1833 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1838 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1840 /* Write out the member table. */
1842 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1843 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1845 memset (&ahdr
, 0, sizeof ahdr
);
1846 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1847 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1848 sprintf (ahdr
.date
, "%d", 0);
1849 sprintf (ahdr
.uid
, "%d", 0);
1850 sprintf (ahdr
.gid
, "%d", 0);
1851 sprintf (ahdr
.mode
, "%d", 0);
1852 sprintf (ahdr
.namlen
, "%d", 0);
1854 size
= (SIZEOF_AR_HDR
1861 nextoff
+= size
+ (size
& 1);
1863 if (makemap
&& hasobjects
)
1864 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
1866 sprintf (ahdr
.nextoff
, "%d", 0);
1868 /* We need spaces, not null bytes, in the header. */
1869 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
1873 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1874 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1878 sprintf (decbuf
, "%-12ld", (long) count
);
1879 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
1881 for (i
= 0; i
< count
; i
++)
1883 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
1884 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
1887 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1892 name
= normalize_filename (sub
);
1893 namlen
= strlen (name
);
1894 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1897 if ((size
& 1) != 0)
1902 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
1906 /* Write out the armap, if appropriate. */
1908 if (! makemap
|| ! hasobjects
)
1909 sprintf (fhdr
.symoff
, "%d", 0);
1912 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1913 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
1914 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
1915 if (! _bfd_compute_and_write_armap (abfd
, 0))
1919 /* Write out the archive file header. */
1921 /* We need spaces, not null bytes, in the header. */
1922 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
1926 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
1927 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR
, 1, abfd
) !=
1928 SIZEOF_AR_FILE_HDR
))
1935 xcoff_write_archive_contents_big (abfd
)
1938 struct xcoff_ar_file_hdr_big fhdr
;
1940 size_t total_namlen
;
1944 file_ptr prevoff
, nextoff
;
1947 struct xcoff_ar_hdr_big ahdr
;
1952 memset (&fhdr
, 0, sizeof fhdr
);
1953 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
1954 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
1955 sprintf (fhdr
.freeoff
, "%d", 0);
1959 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1962 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1964 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1965 if (offsets
== NULL
)
1968 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
1971 makemap
= bfd_has_map (abfd
);
1974 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
1975 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1979 struct xcoff_ar_hdr_big
*ahdrp
;
1980 bfd_size_type remaining
;
1982 if (makemap
&& ! hasobjects
)
1984 if (bfd_check_format (sub
, bfd_object
))
1988 name
= normalize_filename (sub
);
1989 namlen
= strlen (name
);
1991 if (sub
->arelt_data
!= NULL
)
1992 ahdrp
= arch_xhdr_big (sub
);
2000 memset (&ahdr
, 0, sizeof ahdr
);
2002 /* XXX This should actually be a call to stat64 (at least on
2003 32-bit machines). */
2004 if (stat (bfd_get_filename (sub
), &s
) != 0)
2006 bfd_set_error (bfd_error_system_call
);
2010 /* XXX This call actually should use %lld (at least on 32-bit
2011 machines) since the fields's width is 20 and there numbers with
2012 more than 32 bits can be represented. */
2013 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2014 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2015 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2016 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2017 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2019 if (sub
->arelt_data
== NULL
)
2021 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
2022 if (sub
->arelt_data
== NULL
)
2026 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2029 /* XXX These calls actually should use %lld (at least on 32-bit
2030 machines) since the fields's width is 20 and there numbers with
2031 more than 32 bits can be represented. */
2032 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2033 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2035 /* If the length of the name is odd, we write out the null byte
2036 after the name as well. */
2037 namlen
= (namlen
+ 1) &~ 1;
2039 remaining
= arelt_size (sub
);
2040 size
= (SIZEOF_AR_HDR_BIG
2045 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2047 offsets
[i
] = nextoff
;
2050 nextoff
+= size
+ (size
& 1);
2052 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2054 /* We need spaces, not null bytes, in the header. */
2055 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2059 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR_BIG
, abfd
)
2060 != SIZEOF_AR_HDR_BIG
2061 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
2062 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2066 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2068 while (remaining
!= 0)
2071 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2073 amt
= sizeof buffer
;
2074 if (amt
> remaining
)
2076 if (bfd_read (buffer
, 1, amt
, sub
) != amt
2077 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
2082 if ((size
& 1) != 0)
2087 if (bfd_write (&b
, 1, 1, abfd
) != 1)
2092 /* XXX This call actually should use %lld (at least on 32-bit
2093 machines) since the fields's width is 20 and there numbers with
2094 more than 32 bits can be represented. */
2095 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2097 /* Write out the member table. */
2099 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2100 /* XXX This call actually should use %lld (at least on 32-bit
2101 machines) since the fields's width is 20 and there numbers with
2102 more than 32 bits can be represented. */
2103 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2105 memset (&ahdr
, 0, sizeof ahdr
);
2106 /* XXX The next two calls actually should use %lld (at least on 32-bit
2107 machines) since the fields's width is 20 and there numbers with
2108 more than 32 bits can be represented. */
2109 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2110 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2111 sprintf (ahdr
.date
, "%d", 0);
2112 sprintf (ahdr
.uid
, "%d", 0);
2113 sprintf (ahdr
.gid
, "%d", 0);
2114 sprintf (ahdr
.mode
, "%d", 0);
2115 sprintf (ahdr
.namlen
, "%d", 0);
2117 size
= (SIZEOF_AR_HDR_BIG
2124 nextoff
+= size
+ (size
& 1);
2126 if (makemap
&& hasobjects
)
2127 /* XXX This call actually should use %lld (at least on 32-bit
2128 machines) since the fields's width is 20 and there numbers with
2129 more than 32 bits can be represented. */
2130 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2132 sprintf (ahdr
.nextoff
, "%d", 0);
2134 /* We need spaces, not null bytes, in the header. */
2135 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2139 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2140 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2144 sprintf (decbuf
, "%-12ld", (long) count
);
2145 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2147 for (i
= 0; i
< count
; i
++)
2149 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2150 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2153 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2158 name
= normalize_filename (sub
);
2159 namlen
= strlen (name
);
2160 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2163 if ((size
& 1) != 0)
2168 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2172 /* Write out the armap, if appropriate. */
2174 if (! makemap
|| ! hasobjects
)
2175 sprintf (fhdr
.symoff
, "%d", 0);
2178 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2179 /* XXX This call actually should use %lld (at least on 32-bit
2180 machines) since the fields's width is 20 and there numbers with
2181 more than 32 bits can be represented. */
2182 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2183 if (! _bfd_compute_and_write_armap (abfd
, 0))
2187 /* Write out the archive file header. */
2189 /* We need spaces, not null bytes, in the header. */
2190 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2194 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2195 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR_BIG
, 1, abfd
) !=
2196 SIZEOF_AR_FILE_HDR_BIG
))
2203 _bfd_xcoff_write_archive_contents (abfd
)
2206 if (! xcoff_big_format_p (abfd
))
2207 return xcoff_write_archive_contents_old (abfd
);
2209 return xcoff_write_archive_contents_big (abfd
);
2212 /* We can't use the usual coff_sizeof_headers routine, because AIX
2213 always uses an a.out header. */
2217 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2219 boolean reloc ATTRIBUTE_UNUSED
;
2224 if (xcoff_data (abfd
)->full_aouthdr
)
2227 size
+= SMALL_AOUTSZ
;
2228 size
+= abfd
->section_count
* SCNHSZ
;
2232 /* Routines to swap information in the XCOFF .loader section. If we
2233 ever need to write an XCOFF loader, this stuff will need to be
2234 moved to another file shared by the linker (which XCOFF calls the
2235 ``binder'') and the loader. */
2237 /* Swap in the ldhdr structure. */
2240 xcoff_swap_ldhdr_in (abfd
, src
, dst
)
2242 const struct external_ldhdr
*src
;
2243 struct internal_ldhdr
*dst
;
2245 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2246 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2247 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2248 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2249 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2250 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2251 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2252 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2255 /* Swap out the ldhdr structure. */
2258 xcoff_swap_ldhdr_out (abfd
, src
, dst
)
2260 const struct internal_ldhdr
*src
;
2261 struct external_ldhdr
*dst
;
2263 bfd_put_32 (abfd
, src
->l_version
, dst
->l_version
);
2264 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2265 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2266 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2267 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2268 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2269 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2270 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2273 /* Swap in the ldsym structure. */
2276 xcoff_swap_ldsym_in (abfd
, src
, dst
)
2278 const struct external_ldsym
*src
;
2279 struct internal_ldsym
*dst
;
2281 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2282 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2284 dst
->_l
._l_l
._l_zeroes
= 0;
2285 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2287 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2288 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2289 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2290 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2291 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2292 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2295 /* Swap out the ldsym structure. */
2298 xcoff_swap_ldsym_out (abfd
, src
, dst
)
2300 const struct internal_ldsym
*src
;
2301 struct external_ldsym
*dst
;
2304 if (src
->_l
._l_l
._l_zeroes
!= 0)
2305 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2308 bfd_put_32 (abfd
, 0, dst
->_l
._l_l
._l_zeroes
);
2309 bfd_put_32 (abfd
, src
->_l
._l_l
._l_offset
, dst
->_l
._l_l
._l_offset
);
2311 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2312 bfd_put_16 (abfd
, src
->l_scnum
, dst
->l_scnum
);
2313 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2314 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2315 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2316 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2319 /* Swap in the ldrel structure. */
2322 xcoff_swap_ldrel_in (abfd
, src
, dst
)
2324 const struct external_ldrel
*src
;
2325 struct internal_ldrel
*dst
;
2327 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2328 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2329 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2330 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2333 /* Swap out the ldrel structure. */
2336 xcoff_swap_ldrel_out (abfd
, src
, dst
)
2338 const struct internal_ldrel
*src
;
2339 struct external_ldrel
*dst
;
2341 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2342 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2343 bfd_put_16 (abfd
, src
->l_rtype
, dst
->l_rtype
);
2344 bfd_put_16 (abfd
, src
->l_rsecnm
, dst
->l_rsecnm
);
2349 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2350 This is currently the only processor which uses XCOFF; I hope that
2351 will never change. */
2354 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
2355 input_section
, contents
, relocs
, syms
,
2358 struct bfd_link_info
*info
;
2360 asection
*input_section
;
2362 struct internal_reloc
*relocs
;
2363 struct internal_syment
*syms
;
2364 asection
**sections
;
2366 struct internal_reloc
*rel
;
2367 struct internal_reloc
*relend
;
2370 relend
= rel
+ input_section
->reloc_count
;
2372 for (; rel
< relend
; rel
++)
2375 struct xcoff_link_hash_entry
*h
;
2376 struct internal_syment
*sym
;
2379 struct reloc_howto_struct howto
;
2380 bfd_reloc_status_type rstat
;
2382 /* Relocation type R_REF is a special relocation type which is
2383 merely used to prevent garbage collection from occurring for
2384 the csect including the symbol which it references. */
2385 if (rel
->r_type
== R_REF
)
2388 symndx
= rel
->r_symndx
;
2398 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
2399 sym
= syms
+ symndx
;
2400 addend
= - sym
->n_value
;
2404 /* We build the howto information on the fly. */
2406 howto
.type
= rel
->r_type
;
2407 howto
.rightshift
= 0;
2409 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
2410 howto
.pc_relative
= false;
2412 if ((rel
->r_size
& 0x80) != 0)
2413 howto
.complain_on_overflow
= complain_overflow_signed
;
2415 howto
.complain_on_overflow
= complain_overflow_bitfield
;
2416 howto
.special_function
= NULL
;
2417 howto
.name
= "internal";
2418 howto
.partial_inplace
= true;
2419 if (howto
.bitsize
== 32)
2420 howto
.src_mask
= howto
.dst_mask
= 0xffffffff;
2423 howto
.src_mask
= howto
.dst_mask
= (1 << howto
.bitsize
) - 1;
2424 if (howto
.bitsize
== 16)
2427 howto
.pcrel_offset
= false;
2437 sec
= bfd_abs_section_ptr
;
2442 sec
= sections
[symndx
];
2443 /* Hack to make sure we use the right TOC anchor value
2444 if this reloc is against the TOC anchor. */
2446 if (sec
->name
[3] == '0'
2447 && strcmp (sec
->name
, ".tc0") == 0) {
2449 val
= xcoff_data (output_bfd
)->toc
;
2452 val
= (sec
->output_section
->vma
2453 + sec
->output_offset
2462 if (h
->root
.type
== bfd_link_hash_defined
2463 || h
->root
.type
== bfd_link_hash_defweak
)
2467 sec
= h
->root
.u
.def
.section
;
2468 val
= (h
->root
.u
.def
.value
2469 + sec
->output_section
->vma
2470 + sec
->output_offset
);
2472 else if (h
->root
.type
== bfd_link_hash_common
)
2476 sec
= h
->root
.u
.c
.p
->section
;
2477 val
= (sec
->output_section
->vma
2478 + sec
->output_offset
);
2480 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2481 || (h
->flags
& XCOFF_IMPORT
) != 0)
2483 /* Every symbol in a shared object is defined somewhere. */
2486 else if (! info
->relocateable
)
2488 if (! ((*info
->callbacks
->undefined_symbol
)
2489 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2490 rel
->r_vaddr
- input_section
->vma
, true)))
2493 /* Don't try to process the reloc. It can't help, and
2494 it may generate another error. */
2499 /* I took the relocation type definitions from two documents:
2500 the PowerPC AIX Version 4 Application Binary Interface, First
2501 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2502 32-Bit Hardware Implementation (June 30, 1994). Differences
2503 between the documents are noted below. */
2505 switch (rel
->r_type
)
2510 /* These relocs are defined by the PowerPC ABI to be
2511 relative branches which use half of the difference
2512 between the symbol and the program counter. I can't
2513 quite figure out when this is useful. These relocs are
2514 not defined by the PowerOpen ABI. */
2516 (*_bfd_error_handler
)
2517 (_("%s: unsupported relocation type 0x%02x"),
2518 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2519 bfd_set_error (bfd_error_bad_value
);
2522 /* Simple positive relocation. */
2525 /* Simple negative relocation. */
2529 /* Simple PC relative relocation. */
2530 howto
.pc_relative
= true;
2533 /* TOC relative relocation. The value in the instruction in
2534 the input file is the offset from the input file TOC to
2535 the desired location. We want the offset from the final
2536 TOC to the desired location. We have:
2541 so we must change insn by on - in.
2544 /* Global linkage relocation. The value of this relocation
2545 is the address of the entry in the TOC section. */
2547 /* Local object TOC address. I can't figure out the
2548 difference between this and case R_GL. */
2550 /* TOC relative relocation. A TOC relative load instruction
2551 which may be changed to a load address instruction.
2552 FIXME: We don't currently implement this optimization. */
2554 /* TOC relative relocation. This is a TOC relative load
2555 address instruction which may be changed to a load
2556 instruction. FIXME: I don't know if this is the correct
2558 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2560 if (h
->toc_section
== NULL
)
2562 (*_bfd_error_handler
)
2563 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2564 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2565 h
->root
.root
.string
);
2566 bfd_set_error (bfd_error_bad_value
);
2570 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2571 val
= (h
->toc_section
->output_section
->vma
2572 + h
->toc_section
->output_offset
);
2575 val
= ((val
- xcoff_data (output_bfd
)->toc
)
2576 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2580 /* Absolute branch. We don't want to mess with the lower
2581 two bits of the instruction. */
2583 /* The PowerPC ABI defines this as an absolute call which
2584 may be modified to become a relative call. The PowerOpen
2585 ABI does not define this relocation type. */
2587 /* Absolute branch which may be modified to become a
2590 /* The PowerPC ABI defines this as an absolute branch to a
2591 fixed address which may be modified to an absolute branch
2592 to a symbol. The PowerOpen ABI does not define this
2595 /* The PowerPC ABI defines this as an absolute branch to a
2596 fixed address which may be modified to a relative branch.
2597 The PowerOpen ABI does not define this relocation type. */
2598 howto
.src_mask
&= ~3;
2599 howto
.dst_mask
= howto
.src_mask
;
2602 /* Relative branch. We don't want to mess with the lower
2603 two bits of the instruction. */
2605 /* The PowerPC ABI defines this as a relative call which may
2606 be modified to become an absolute call. The PowerOpen
2607 ABI does not define this relocation type. */
2609 /* A relative branch which may be modified to become an
2610 absolute branch. FIXME: We don't implement this,
2611 although we should for symbols of storage mapping class
2613 howto
.pc_relative
= true;
2614 howto
.src_mask
&= ~3;
2615 howto
.dst_mask
= howto
.src_mask
;
2618 /* The PowerPC AIX ABI describes this as a load which may be
2619 changed to a load address. The PowerOpen ABI says this
2620 is the same as case R_POS. */
2623 /* The PowerPC AIX ABI describes this as a load address
2624 which may be changed to a load. The PowerOpen ABI says
2625 this is the same as R_POS. */
2629 /* If we see an R_BR or R_RBR reloc which is jumping to global
2630 linkage code, and it is followed by an appropriate cror nop
2631 instruction, we replace the cror with lwz r2,20(r1). This
2632 restores the TOC after the glink code. Contrariwise, if the
2633 call is followed by a lwz r2,20(r1), but the call is not
2634 going to global linkage code, we can replace the load with a
2636 if ((rel
->r_type
== R_BR
|| rel
->r_type
== R_RBR
)
2638 && h
->root
.type
== bfd_link_hash_defined
2639 && (rel
->r_vaddr
- input_section
->vma
+ 8
2640 <= input_section
->_cooked_size
))
2645 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
2646 next
= bfd_get_32 (input_bfd
, pnext
);
2648 /* The _ptrgl function is magic. It is used by the AIX
2649 compiler to call a function through a pointer. */
2650 if (h
->smclas
== XMC_GL
2651 || strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2653 if (next
== 0x4def7b82 /* cror 15,15,15 */
2654 || next
== 0x4ffffb82 /* cror 31,31,31 */
2655 || next
== 0x60000000) /* ori r0,r0,0 */
2656 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r1,20(r1) */
2660 if (next
== 0x80410014) /* lwz r1,20(r1) */
2661 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2665 /* A PC relative reloc includes the section address. */
2666 if (howto
.pc_relative
)
2667 addend
+= input_section
->vma
;
2669 rstat
= _bfd_final_link_relocate (&howto
, input_bfd
, input_section
,
2671 rel
->r_vaddr
- input_section
->vma
,
2680 case bfd_reloc_overflow
:
2683 char buf
[SYMNMLEN
+ 1];
2684 char howto_name
[10];
2689 name
= h
->root
.root
.string
;
2693 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
2698 sprintf (howto_name
, "0x%02x", rel
->r_type
);
2700 if (! ((*info
->callbacks
->reloc_overflow
)
2701 (info
, name
, howto_name
, (bfd_vma
) 0, input_bfd
,
2702 input_section
, rel
->r_vaddr
- input_section
->vma
)))
2712 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
2713 bfd
*abfd ATTRIBUTE_UNUSED
;
2714 struct xcoff_loader_info
*ldinfo
;
2715 struct internal_ldsym
*ldsym
;
2719 len
= strlen (name
);
2721 if (len
<= SYMNMLEN
)
2722 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
2725 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
2728 bfd_byte
*newstrings
;
2730 newalc
= ldinfo
->string_alc
* 2;
2733 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
2736 newstrings
= ((bfd_byte
*)
2737 bfd_realloc ((PTR
) ldinfo
->strings
, newalc
));
2738 if (newstrings
== NULL
)
2740 ldinfo
->failed
= true;
2743 ldinfo
->string_alc
= newalc
;
2744 ldinfo
->strings
= newstrings
;
2747 bfd_put_16 (ldinfo
->output_bfd
, len
+ 1,
2748 ldinfo
->strings
+ ldinfo
->string_size
);
2749 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
2750 ldsym
->_l
._l_l
._l_zeroes
= 0;
2751 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
2752 ldinfo
->string_size
+= len
+ 3;
2759 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
2760 struct internal_syment
*sym
,
2763 if (strlen (name
) <= SYMNMLEN
) {
2764 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
2770 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
2772 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
2773 if (indx
== (bfd_size_type
) -1)
2775 sym
->_n
._n_n
._n_zeroes
= 0;
2776 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
2782 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
2784 union internal_auxent
*aux
;
2788 asection
*return_value
= NULL
;
2791 * .sv64 = x_smclas == 17
2792 * This is an invalid csect for 32 bit apps.
2794 static const char *names
[19] = {
2795 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2796 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
2797 ".td", NULL
, ".sv3264"
2800 if ((19 >= aux
->x_csect
.x_smclas
) &&
2801 (NULL
!= names
[aux
->x_csect
.x_smclas
])) {
2803 return_value
= bfd_make_section_anyway
2804 (abfd
, names
[aux
->x_csect
.x_smclas
]);
2808 (*_bfd_error_handler
)
2809 (_("%s: symbol `%s' has unrecognized smclas %d"),
2810 bfd_get_filename (abfd
), symbol_name
, aux
->x_csect
.x_smclas
);
2811 bfd_set_error (bfd_error_bad_value
);
2814 return return_value
;
2818 xcoff_is_lineno_count_overflow (abfd
, value
)
2819 bfd
*abfd ATTRIBUTE_UNUSED
;
2822 if (0xffff <= value
) {
2829 xcoff_is_reloc_count_overflow (abfd
, value
)
2830 bfd
*abfd ATTRIBUTE_UNUSED
;
2833 if (0xffff <= value
) {
2840 xcoff_loader_symbol_offset (abfd
, ldhdr
)
2842 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
2844 return bfd_xcoff_ldhdrsz(abfd
);
2848 xcoff_loader_reloc_offset (abfd
, ldhdr
)
2850 struct internal_ldhdr
*ldhdr
;
2852 return bfd_xcoff_ldhdrsz(abfd
) +
2853 (ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(abfd
));
2857 static reloc_howto_type xcoff_dynamic_reloc
=
2858 HOWTO (0, /* type */
2860 2, /* size (0 = byte, 1 = short, 2 = long) */
2862 false, /* pc_relative */
2864 complain_overflow_bitfield
, /* complain_on_overflow */
2865 0, /* special_function */
2867 true, /* partial_inplace */
2868 0xffffffff, /* src_mask */
2869 0xffffffff, /* dst_mask */
2870 false); /* pcrel_offset */
2875 * The first word of global linkage code must be modified by filling in
2876 * the correct TOC offset.
2878 static unsigned long xcoff_glink_code
[9] =
2880 0x81820000, /* lwz r12,0(r2) */
2881 0x90410014, /* stw r2,20(r1) */
2882 0x800c0000, /* lwz r0,0(r12) */
2883 0x804c0004, /* lwz r2,4(r12) */
2884 0x7c0903a6, /* mtctr r0 */
2885 0x4e800420, /* bctr */
2886 0x00000000, /* start of traceback table */
2887 0x000c8000, /* traceback table */
2888 0x00000000, /* traceback table */
2892 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
2894 { /* COFF backend, defined in libcoff.h */
2895 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
2896 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
2897 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
2898 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
2899 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
2900 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
2901 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
2902 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
2903 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
2904 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
2905 FILHSZ
, /* _bfd_filhsz */
2906 AOUTSZ
, /* _bfd_aoutsz */
2907 SCNHSZ
, /* _bfd_scnhsz */
2908 SYMESZ
, /* _bfd_symesz */
2909 AUXESZ
, /* _bfd_auxesz */
2910 RELSZ
, /* _bfd_relsz */
2911 LINESZ
, /* _bfd_linesz */
2912 FILNMLEN
, /* _bfd_filnmlen */
2913 true, /* _bfd_coff_long_filenames */
2914 false, /* _bfd_coff_long_section_names */
2915 (3), /* _bfd_coff_default_section_alignment_power */
2916 false, /* _bfd_coff_force_symnames_in_strings */
2917 2, /* _bfd_coff_debug_string_prefix_length */
2918 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
2919 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
2920 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
2921 coff_swap_reloc_in
, /* _bfd_reloc_in */
2922 coff_bad_format_hook
, /* _bfd_bad_format_hook */
2923 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
2924 coff_mkobject_hook
, /* _bfd_mkobject_hook */
2925 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
2926 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
2927 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
2928 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
2929 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
2930 coff_print_aux
, /* bfd_coff_print_aux */
2931 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
2932 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
2933 NULL
, /* bfd_coff_sym_is_global */
2934 /* _bfd_coff_compute_section_file_positions */
2935 coff_compute_section_file_positions
,
2936 NULL
, /* _bfd_coff_start_final_link */
2937 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
2938 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
2939 NULL
, /* _bfd_coff_addust_symndx */
2940 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
2941 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
2942 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
2945 0x01DF, /* magic number */
2946 bfd_arch_rs6000
, /* architecture */
2947 bfd_mach_rs6k
, /* machine */
2950 /* function pointers to xcoff specific swap routines */
2951 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
2952 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
2953 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
2954 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
2955 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
2956 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
2959 LDHDRSZ
, /* _xcoff_ldhdrsz */
2960 LDSYMSZ
, /* _xcoff_ldsymsz */
2961 LDRELSZ
, /* _xcoff_ldrelsz */
2962 12, /* _xcoff_function_descriptor_size */
2963 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
2966 1, /* _xcoff_ldhdr_version */
2968 /* xcoff vs xcoff64 putting symbol names */
2969 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
2970 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
2972 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
2974 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
2976 /* lineno and reloc count overflow */
2977 xcoff_is_lineno_count_overflow
,
2978 xcoff_is_reloc_count_overflow
,
2980 xcoff_loader_symbol_offset
,
2981 xcoff_loader_reloc_offset
,
2984 &xcoff_glink_code
[0],
2985 (36), /* _xcoff_glink_size */
2989 /* The transfer vector that leads the outside world to all of the above. */
2990 const bfd_target rs6000coff_vec
=
2993 bfd_target_xcoff_flavour
,
2994 BFD_ENDIAN_BIG
, /* data byte order is big */
2995 BFD_ENDIAN_BIG
, /* header byte order is big */
2997 (HAS_RELOC
| EXEC_P
| /* object flags */
2998 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
2999 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3001 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3002 0, /* leading char */
3003 '/', /* ar_pad_char */
3004 15, /* ar_max_namelen??? FIXMEmgo */
3007 bfd_getb64
, /* bfd_getx64 */
3008 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3009 bfd_putb64
, /* bfd_putx64 */
3010 bfd_getb32
, /* bfd_getx32 */
3011 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3012 bfd_putb32
, /* bfd_putx32 */
3013 bfd_getb16
, /* bfd_getx16 */
3014 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3015 bfd_putb16
, /* bfd_putx16 */
3018 bfd_getb64
, /* bfd_h_getx64 */
3019 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3020 bfd_putb64
, /* bfd_h_putx64 */
3021 bfd_getb32
, /* bfd_h_getx32 */
3022 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3023 bfd_putb32
, /* bfd_h_putx32 */
3024 bfd_getb16
, /* bfd_h_getx16 */
3025 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3026 bfd_putb16
, /* bfd_h_putx16 */
3028 { /* bfd_check_format */
3031 _bfd_xcoff_archive_p
,
3035 { /* bfd_set_format */
3038 _bfd_generic_mkarchive
,
3042 {/* bfd_write_contents */
3044 coff_write_object_contents
,
3045 _bfd_xcoff_write_archive_contents
,
3050 bfd_true
, /* _close_and_cleanup */
3051 bfd_true
, /* _bfd_free_cached_info */
3052 coff_new_section_hook
, /* _new_section_hook */
3053 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3054 /* _bfd_get_section_contents_in_window */
3055 _bfd_generic_get_section_contents_in_window
,
3058 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3059 /* _bfd_merge_private_bfd_data */
3060 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3061 /* _bfd_copy_pivate_section_data */
3062 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3063 /* _bfd_copy_private_symbol_data */
3064 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3065 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3066 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3069 coff_core_file_failing_command
, /* _core_file_failing_command */
3070 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3071 /* _core_file_matches_executable_p */
3072 coff_core_file_matches_executable_p
,
3075 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3076 /* XCOFF archives do not have
3077 anything which corresponds to
3078 an extended name table. */
3079 bfd_false
, /* _slurp_extended_name_table */
3080 /* _construct_extended_name_table */
3081 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3082 bfd_dont_truncate_arname
, /* _truncate_arname */
3083 _bfd_xcoff_write_armap
, /* _write_armap */
3084 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3085 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3086 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3087 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3088 /* XCOFF archives do not have
3090 bfd_true
, /* _update_armap_timestamp */
3093 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3094 coff_get_symtab
, /* _get_symtab */
3095 coff_make_empty_symbol
, /* _make_empty_symbol */
3096 coff_print_symbol
, /* _print_symbol */
3097 coff_get_symbol_info
, /* _get_symbol_info */
3098 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3099 coff_get_lineno
, /* _get_lineno */
3100 coff_find_nearest_line
, /* _find_nearest_line */
3101 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3102 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3103 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3106 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3107 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3108 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3111 coff_set_arch_mach
, /* _set_arch_mach */
3112 coff_set_section_contents
, /* _set_section_contents */
3115 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3116 /* _bfd_get_relocated_section_contents */
3117 bfd_generic_get_relocated_section_contents
,
3118 bfd_generic_relax_section
, /* _bfd_relax_section */
3119 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3120 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3121 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3122 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3123 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3124 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3127 /* _get_dynamic_symtab_upper_bound */
3128 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3129 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3130 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3131 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3133 /* Opposite endian version, none exists */
3137 (void *) &bfd_xcoff_backend_data
,
3141 * xcoff-powermac target
3143 * Only difference between this target and the rs6000 target is the
3144 * the default architecture and machine type used in coffcode.h
3146 * PowerPC Macs use the same magic numbers as RS/6000
3147 * (because that's how they were bootstrapped originally),
3148 * but they are always PowerPC architecture.
3150 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
3152 { /* COFF backend, defined in libcoff.h */
3153 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3154 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3155 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3156 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3157 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3158 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3159 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3160 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3161 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3162 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3163 FILHSZ
, /* _bfd_filhsz */
3164 AOUTSZ
, /* _bfd_aoutsz */
3165 SCNHSZ
, /* _bfd_scnhsz */
3166 SYMESZ
, /* _bfd_symesz */
3167 AUXESZ
, /* _bfd_auxesz */
3168 RELSZ
, /* _bfd_relsz */
3169 LINESZ
, /* _bfd_linesz */
3170 FILNMLEN
, /* _bfd_filnmlen */
3171 true, /* _bfd_coff_long_filenames */
3172 false, /* _bfd_coff_long_section_names */
3173 (3), /* _bfd_coff_default_section_alignment_power */
3174 false, /* _bfd_coff_force_symnames_in_strings */
3175 2, /* _bfd_coff_debug_string_prefix_length */
3176 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3177 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3178 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3179 coff_swap_reloc_in
, /* _bfd_reloc_in */
3180 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3181 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3182 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3183 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3184 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3185 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3186 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3187 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3188 coff_print_aux
, /* bfd_coff_print_aux */
3189 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3190 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3191 NULL
, /* bfd_coff_sym_is_global */
3192 /* _bfd_coff_compute_section_file_positions */
3193 coff_compute_section_file_positions
,
3194 NULL
, /* _bfd_coff_start_final_link */
3195 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3196 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3197 NULL
, /* _bfd_coff_addust_symndx */
3198 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3199 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3200 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3203 0x01DF, /* magic number */
3204 bfd_arch_powerpc
, /* architecture */
3205 bfd_mach_ppc
, /* machine */
3207 /* function pointers to xcoff specific swap routines */
3208 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3209 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3210 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3211 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3212 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3213 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3216 LDHDRSZ
, /* _xcoff_ldhdrsz */
3217 LDSYMSZ
, /* _xcoff_ldsymsz */
3218 LDRELSZ
, /* _xcoff_ldrelsz */
3219 12, /* _xcoff_function_descriptor_size */
3220 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3223 1, /* _xcoff_ldhdr_version */
3225 /* xcoff vs xcoff64 putting symbol names */
3226 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3227 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3229 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
3231 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3233 /* lineno and reloc count overflow */
3234 xcoff_is_lineno_count_overflow
,
3235 xcoff_is_reloc_count_overflow
,
3237 xcoff_loader_symbol_offset
,
3238 xcoff_loader_reloc_offset
,
3241 &xcoff_glink_code
[0],
3242 (36), /* _xcoff_glink_size */
3246 /* The transfer vector that leads the outside world to all of the above. */
3247 const bfd_target pmac_xcoff_vec
=
3250 bfd_target_xcoff_flavour
,
3251 BFD_ENDIAN_BIG
, /* data byte order is big */
3252 BFD_ENDIAN_BIG
, /* header byte order is big */
3254 (HAS_RELOC
| EXEC_P
| /* object flags */
3255 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3256 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3258 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3259 0, /* leading char */
3260 '/', /* ar_pad_char */
3261 15, /* ar_max_namelen??? FIXMEmgo */
3264 bfd_getb64
, /* bfd_getx64 */
3265 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3266 bfd_putb64
, /* bfd_putx64 */
3267 bfd_getb32
, /* bfd_getx32 */
3268 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3269 bfd_putb32
, /* bfd_putx32 */
3270 bfd_getb16
, /* bfd_getx16 */
3271 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3272 bfd_putb16
, /* bfd_putx16 */
3275 bfd_getb64
, /* bfd_h_getx64 */
3276 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3277 bfd_putb64
, /* bfd_h_putx64 */
3278 bfd_getb32
, /* bfd_h_getx32 */
3279 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3280 bfd_putb32
, /* bfd_h_putx32 */
3281 bfd_getb16
, /* bfd_h_getx16 */
3282 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3283 bfd_putb16
, /* bfd_h_putx16 */
3285 { /* bfd_check_format */
3288 _bfd_xcoff_archive_p
,
3292 { /* bfd_set_format */
3295 _bfd_generic_mkarchive
,
3299 {/* bfd_write_contents */
3301 coff_write_object_contents
,
3302 _bfd_xcoff_write_archive_contents
,
3307 bfd_true
, /* _close_and_cleanup */
3308 bfd_true
, /* _bfd_free_cached_info */
3309 coff_new_section_hook
, /* _new_section_hook */
3310 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3311 /* _bfd_get_section_contents_in_window */
3312 _bfd_generic_get_section_contents_in_window
,
3315 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3316 /* _bfd_merge_private_bfd_data */
3317 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3318 /* _bfd_copy_pivate_section_data */
3319 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3320 /* _bfd_copy_private_symbol_data */
3321 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3322 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3323 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3326 coff_core_file_failing_command
, /* _core_file_failing_command */
3327 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3328 /* _core_file_matches_executable_p */
3329 coff_core_file_matches_executable_p
,
3332 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3333 /* XCOFF archives do not have
3334 anything which corresponds to
3335 an extended name table. */
3336 bfd_false
, /* _slurp_extended_name_table */
3337 /* _construct_extended_name_table */
3338 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3339 bfd_dont_truncate_arname
, /* _truncate_arname */
3340 _bfd_xcoff_write_armap
, /* _write_armap */
3341 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3342 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3343 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3344 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3345 /* XCOFF archives do not have
3347 bfd_true
, /* _update_armap_timestamp */
3350 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3351 coff_get_symtab
, /* _get_symtab */
3352 coff_make_empty_symbol
, /* _make_empty_symbol */
3353 coff_print_symbol
, /* _print_symbol */
3354 coff_get_symbol_info
, /* _get_symbol_info */
3355 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3356 coff_get_lineno
, /* _get_lineno */
3357 coff_find_nearest_line
, /* _find_nearest_line */
3358 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3359 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3360 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3363 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3364 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3365 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3368 coff_set_arch_mach
, /* _set_arch_mach */
3369 coff_set_section_contents
, /* _set_section_contents */
3372 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3373 /* _bfd_get_relocated_section_contents */
3374 bfd_generic_get_relocated_section_contents
,
3375 bfd_generic_relax_section
, /* _bfd_relax_section */
3376 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3377 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3378 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3379 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3380 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3381 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3384 /* _get_dynamic_symtab_upper_bound */
3385 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3386 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3387 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3388 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3390 /* Opposite endian version, none exists */
3394 (void *) &bfd_pmac_xcoff_backend_data
,