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
*));
114 static boolean xcoff_write_armap_old
115 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
116 static boolean xcoff_write_one_armap_big
117 PARAMS ((bfd
*, struct orl
*, unsigned int, unsigned int, unsigned int,
118 int, const char *, char *));
119 static boolean xcoff_write_armap_big
120 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
121 static boolean xcoff_write_archive_contents_old
PARAMS ((bfd
*));
122 static boolean xcoff_write_archive_contents_big
PARAMS ((bfd
*));
123 static void xcoff_swap_ldhdr_in
124 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
125 static void xcoff_swap_ldhdr_out
126 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
127 static void xcoff_swap_ldsym_in
128 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
129 static void xcoff_swap_ldsym_out
130 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
131 static void xcoff_swap_ldrel_in
132 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
133 static void xcoff_swap_ldrel_out
134 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
135 static boolean xcoff_ppc_relocate_section
136 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
137 struct internal_reloc
*, struct internal_syment
*, asection
**));
138 static boolean _bfd_xcoff_put_ldsymbol_name
139 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
141 static asection
*xcoff_create_csect_from_smclas
142 PARAMS ((bfd
*, union internal_auxent
*, const char *));
143 static boolean xcoff_is_lineno_count_overflow
PARAMS ((bfd
*, bfd_vma
));
144 static boolean xcoff_is_reloc_count_overflow
PARAMS ((bfd
*, bfd_vma
));
145 static bfd_vma xcoff_loader_symbol_offset
146 PARAMS ((bfd
*, struct internal_ldhdr
*));
147 static bfd_vma xcoff_loader_reloc_offset
148 PARAMS ((bfd
*, struct internal_ldhdr
*));
150 /* We use our own tdata type. Its first field is the COFF tdata type,
151 so the COFF routines are compatible. */
154 _bfd_xcoff_mkobject (abfd
)
157 coff_data_type
*coff
;
158 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
160 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
161 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
163 coff
= coff_data (abfd
);
164 coff
->symbols
= (coff_symbol_type
*) NULL
;
165 coff
->conversion_table
= (unsigned int *) NULL
;
166 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
169 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
171 /* We set cputype to -1 to indicate that it has not been
173 xcoff_data (abfd
)->cputype
= -1;
175 xcoff_data (abfd
)->csects
= NULL
;
176 xcoff_data (abfd
)->debug_indices
= NULL
;
178 /* text section alignment is different than the default */
179 /* xcoff_data (abfd)->text_align_power = 5; */
184 /* Copy XCOFF data from one BFD to another. */
187 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
191 struct xcoff_tdata
*ix
, *ox
;
194 if (ibfd
->xvec
!= obfd
->xvec
)
196 ix
= xcoff_data (ibfd
);
197 ox
= xcoff_data (obfd
);
198 ox
->full_aouthdr
= ix
->full_aouthdr
;
204 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
208 ox
->sntoc
= sec
->output_section
->target_index
;
210 if (ix
->snentry
== 0)
214 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
218 ox
->snentry
= sec
->output_section
->target_index
;
220 ox
->text_align_power
= ix
->text_align_power
;
221 ox
->data_align_power
= ix
->data_align_power
;
222 ox
->modtype
= ix
->modtype
;
223 ox
->cputype
= ix
->cputype
;
224 ox
->maxdata
= ix
->maxdata
;
225 ox
->maxstack
= ix
->maxstack
;
229 /* I don't think XCOFF really has a notion of local labels based on
230 name. This will mean that ld -X doesn't actually strip anything.
231 The AIX native linker does not have a -X option, and it ignores the
235 _bfd_xcoff_is_local_label_name (abfd
, name
)
236 bfd
*abfd ATTRIBUTE_UNUSED
;
237 const char *name ATTRIBUTE_UNUSED
;
243 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
248 SYMENT
*ext
= (SYMENT
*)ext1
;
249 struct internal_syment
* in
= (struct internal_syment
*)in1
;
251 if (ext
->e
.e_name
[0] != 0)
253 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
257 in
->_n
._n_n
._n_zeroes
= 0;
258 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
261 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
262 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
263 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
264 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
265 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
269 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
274 struct internal_syment
*in
= (struct internal_syment
*)inp
;
275 SYMENT
*ext
=(SYMENT
*)extp
;
277 if (in
->_n
._n_name
[0] != 0)
279 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
283 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
284 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
287 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
288 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
289 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
290 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
291 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
292 return bfd_coff_symesz (abfd
);
296 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
305 AUXENT
* ext
= (AUXENT
*)ext1
;
306 union internal_auxent
*in
= (union internal_auxent
*)in1
;
311 if (ext
->x_file
.x_fname
[0] == 0)
313 in
->x_file
.x_n
.x_zeroes
= 0;
314 in
->x_file
.x_n
.x_offset
=
315 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
322 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
323 numaux
* sizeof (AUXENT
));
327 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
332 /* RS/6000 "csect" auxents */
335 if (indx
+ 1 == numaux
)
337 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
338 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
339 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
340 /* We don't have to hack bitfields in x_smtyp because it's
341 defined by shifts-and-ands, which are equivalent on all
343 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
344 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
345 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
346 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
356 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
357 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
358 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
359 /* PE defines some extra fields; we zero them out for
361 in
->x_scn
.x_checksum
= 0;
362 in
->x_scn
.x_associated
= 0;
363 in
->x_scn
.x_comdat
= 0;
370 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
371 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
373 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
375 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
376 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
377 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
378 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
382 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
383 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
384 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
385 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
386 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
387 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
388 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
389 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
394 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
398 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
399 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
400 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
401 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
405 /* The semicolon is because MSVC doesn't like labels at
410 unsigned int _bfd_xcoff_swap_aux_out
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
413 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
418 int indx ATTRIBUTE_UNUSED
;
419 int numaux ATTRIBUTE_UNUSED
;
422 union internal_auxent
*in
= (union internal_auxent
*)inp
;
423 AUXENT
*ext
= (AUXENT
*)extp
;
425 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
429 if (in
->x_file
.x_fname
[0] == 0)
431 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
432 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
436 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
440 /* RS/6000 "csect" auxents */
443 if (indx
+ 1 == numaux
)
445 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
446 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
447 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
448 /* We don't have to hack bitfields in x_smtyp because it's
449 defined by shifts-and-ands, which are equivalent on all
451 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
452 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
453 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
454 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
464 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
465 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
466 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
472 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
473 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
475 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
477 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
478 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
479 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
480 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
484 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
485 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
486 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
487 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
488 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
489 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
490 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
491 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
495 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
498 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
499 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
500 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
501 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
505 return bfd_coff_auxesz (abfd
);
510 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
511 bitsize and whether they are signed or not, along with a
512 conventional type. This table is for the types, which are used for
513 different algorithms for putting in the reloc. Many of these
514 relocs need special_function entries, which I have not written. */
517 reloc_howto_type xcoff_howto_table
[] =
519 /* Standard 32 bit relocation. */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 false, /* pc_relative */
526 complain_overflow_bitfield
, /* complain_on_overflow */
527 0, /* special_function */
529 true, /* partial_inplace */
530 0xffffffff, /* src_mask */
531 0xffffffff, /* dst_mask */
532 false), /* pcrel_offset */
534 /* 32 bit relocation, but store negative value. */
537 -2, /* 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 0xffffffff, /* src_mask */
546 0xffffffff, /* dst_mask */
547 false), /* pcrel_offset */
549 /* 32 bit PC relative relocation. */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 true, /* pc_relative */
556 complain_overflow_signed
, /* complain_on_overflow */
557 0, /* special_function */
559 true, /* partial_inplace */
560 0xffffffff, /* src_mask */
561 0xffffffff, /* dst_mask */
562 false), /* pcrel_offset */
564 /* 16 bit TOC relative relocation. */
567 1, /* 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 /* I don't really know what this is. */
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 0xffffffff, /* src_mask */
591 0xffffffff, /* dst_mask */
592 false), /* pcrel_offset */
594 /* External TOC relative symbol. */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 0, /* special_function */
604 true, /* partial_inplace */
605 0xffff, /* src_mask */
606 0xffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* Local TOC relative symbol. */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_bitfield
, /* complain_on_overflow */
617 0, /* special_function */
619 true, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 false), /* pcrel_offset */
626 /* Non modifiable absolute branch. */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 0, /* special_function */
636 true, /* partial_inplace */
637 0x3fffffc, /* src_mask */
638 0x3fffffc, /* dst_mask */
639 false), /* pcrel_offset */
643 /* Non modifiable relative branch. */
644 HOWTO (0xa, /* type */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
648 true, /* pc_relative */
650 complain_overflow_signed
, /* complain_on_overflow */
651 0, /* special_function */
653 true, /* partial_inplace */
654 0x3fffffc, /* src_mask */
655 0x3fffffc, /* dst_mask */
656 false), /* pcrel_offset */
661 HOWTO (0xc, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 false, /* pc_relative */
667 complain_overflow_bitfield
, /* complain_on_overflow */
668 0, /* special_function */
670 true, /* partial_inplace */
671 0xffff, /* src_mask */
672 0xffff, /* dst_mask */
673 false), /* pcrel_offset */
676 HOWTO (0xd, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 false, /* pc_relative */
682 complain_overflow_bitfield
, /* complain_on_overflow */
683 0, /* special_function */
685 true, /* partial_inplace */
686 0xffff, /* src_mask */
687 0xffff, /* dst_mask */
688 false), /* pcrel_offset */
692 /* Non-relocating reference. */
693 HOWTO (0xf, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 false, /* pc_relative */
699 complain_overflow_bitfield
, /* complain_on_overflow */
700 0, /* special_function */
702 false, /* partial_inplace */
705 false), /* pcrel_offset */
710 /* TOC relative indirect load. */
711 HOWTO (0x12, /* 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 */
720 true, /* partial_inplace */
721 0xffff, /* src_mask */
722 0xffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* TOC relative load address. */
726 HOWTO (0x13, /* 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 */
735 true, /* partial_inplace */
736 0xffff, /* src_mask */
737 0xffff, /* dst_mask */
738 false), /* pcrel_offset */
740 /* Modifiable relative branch. */
741 HOWTO (0x14, /* 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 */
749 "R_RRTBI", /* name */
750 true, /* partial_inplace */
751 0xffffffff, /* src_mask */
752 0xffffffff, /* dst_mask */
753 false), /* pcrel_offset */
755 /* Modifiable absolute branch. */
756 HOWTO (0x15, /* 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 */
764 "R_RRTBA", /* name */
765 true, /* partial_inplace */
766 0xffffffff, /* src_mask */
767 0xffffffff, /* dst_mask */
768 false), /* pcrel_offset */
770 /* Modifiable call absolute indirect. */
771 HOWTO (0x16, /* 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 call relative. */
786 HOWTO (0x17, /* 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 absolute. */
801 HOWTO (0x18, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_bitfield
, /* 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 (0x19, /* 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 */
830 /* Modifiable branch relative. */
831 HOWTO (0x1a, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 0, /* special_function */
840 true, /* partial_inplace */
841 0xffff, /* src_mask */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
845 /* Modifiable branch absolute. */
846 HOWTO (0x1b, /* type */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
850 false, /* pc_relative */
852 complain_overflow_bitfield
, /* complain_on_overflow */
853 0, /* special_function */
855 true, /* partial_inplace */
856 0xffff, /* src_mask */
857 0xffff, /* dst_mask */
858 false), /* pcrel_offset */
862 4, /* size (0 = byte, 1 = short, 2 = long) */
864 false, /* pc_relative */
866 complain_overflow_bitfield
, /* complain_on_overflow */
867 0, /* special_function */
869 true, /* partial_inplace */
870 MINUS_ONE
, /* src_mask */
871 MINUS_ONE
, /* dst_mask */
872 false) /* pcrel_offset */
877 _bfd_xcoff_rtype2howto (relent
, internal
)
879 struct internal_reloc
*internal
;
881 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
883 /* Check for relocs we don't know of. */
885 >= sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]))
887 if (internal
->r_type
!= relent
->howto
->type
)
890 /* The r_size field of an XCOFF reloc encodes the bitsize of the
891 relocation, as well as indicating whether it is signed or not.
892 Doublecheck that the relocation information gathered from the
893 type matches this information. The bitsize is not significant
895 if (relent
->howto
->dst_mask
!= 0
896 && (relent
->howto
->bitsize
897 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
900 if ((internal
->r_size
& 0x80) != 0
901 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
902 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
908 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
909 bfd
*abfd ATTRIBUTE_UNUSED
;
910 bfd_reloc_code_real_type code
;
914 case BFD_RELOC_PPC_B26
:
915 return &xcoff_howto_table
[0xa];
916 case BFD_RELOC_PPC_BA26
:
917 return &xcoff_howto_table
[8];
918 case BFD_RELOC_PPC_TOC16
:
919 return &xcoff_howto_table
[3];
922 return &xcoff_howto_table
[0];
924 return &xcoff_howto_table
[0x1c];
931 /* XCOFF archive support. The original version of this code was by
932 Damon A. Permezel. It was enhanced to permit cross support, and
933 writing archive files, by Ian Lance Taylor, Cygnus Support.
935 XCOFF uses its own archive format. Everything is hooked together
936 with file offset links, so it is possible to rapidly update an
937 archive in place. Of course, we don't do that. An XCOFF archive
938 has a real file header, not just an ARMAG string. The structure of
939 the file header and of each archive header appear below.
941 An XCOFF archive also has a member table, which is a list of
942 elements in the archive (you can get that by looking through the
943 linked list, but you have to read a lot more of the file). The
944 member table has a normal archive header with an empty name. It is
945 normally (and perhaps must be) the second to last entry in the
946 archive. The member table data is almost printable ASCII. It
947 starts with a 12 character decimal string which is the number of
948 entries in the table. For each entry it has a 12 character decimal
949 string which is the offset in the archive of that member. These
950 entries are followed by a series of null terminated strings which
951 are the member names for each entry.
953 Finally, an XCOFF archive has a global symbol table, which is what
954 we call the armap. The global symbol table has a normal archive
955 header with an empty name. It is normally (and perhaps must be)
956 the last entry in the archive. The contents start with a four byte
957 binary number which is the number of entries. This is followed by
958 a that many four byte binary numbers; each is the file offset of an
959 entry in the archive. These numbers are followed by a series of
960 null terminated strings, which are symbol names.
962 AIX 4.3 introduced a new archive format which can handle larger
963 files and also 32- and 64-bit objects in the same archive. The
964 things said above remain true except that there is now more than
965 one global symbol table. The one is used to index 32-bit objects,
966 the other for 64-bit objects.
968 The new archives (recognizable by the new ARMAG string) has larger
969 field lengths so that we cannot really share any code. Also we have
970 to take care that we are not generating the new form of archives
971 on AIX 4.2 or earlier systems. */
973 /* XCOFF archives use this as a magic string. Note that both strings
974 have the same length. */
978 /* Read in the armap of an XCOFF archive. */
981 _bfd_xcoff_slurp_armap (abfd
)
987 bfd_byte
*contents
, *cend
;
992 if (xcoff_ardata (abfd
) == NULL
)
994 bfd_has_map (abfd
) = false;
998 if (! xcoff_big_format_p (abfd
))
1000 /* This is for the old format. */
1001 struct xcoff_ar_hdr hdr
;
1003 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1006 bfd_has_map (abfd
) = false;
1010 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1013 /* The symbol table starts with a normal archive header. */
1014 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1018 /* Skip the name (normally empty). */
1019 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1020 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1021 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1024 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1026 /* Read in the entire symbol table. */
1027 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1028 if (contents
== NULL
)
1030 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1033 /* The symbol table starts with a four byte count. */
1034 c
= H_GET_32 (abfd
, contents
);
1038 bfd_set_error (bfd_error_bad_value
);
1042 bfd_ardata (abfd
)->symdefs
=
1043 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1044 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1047 /* After the count comes a list of four byte file offsets. */
1048 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1050 ++i
, ++arsym
, p
+= 4)
1051 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1055 /* This is for the new format. */
1056 struct xcoff_ar_hdr_big hdr
;
1058 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1061 bfd_has_map (abfd
) = false;
1065 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1068 /* The symbol table starts with a normal archive header. */
1069 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1070 != SIZEOF_AR_HDR_BIG
)
1073 /* Skip the name (normally empty). */
1074 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1075 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1076 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1079 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1080 machines) since the field width is 20 and there numbers with more
1081 than 32 bits can be represented. */
1082 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1084 /* Read in the entire symbol table. */
1085 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1086 if (contents
== NULL
)
1088 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1091 /* The symbol table starts with an eight byte count. */
1092 c
= H_GET_64 (abfd
, contents
);
1096 bfd_set_error (bfd_error_bad_value
);
1100 bfd_ardata (abfd
)->symdefs
=
1101 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1102 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1105 /* After the count comes a list of eight byte file offsets. */
1106 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1108 ++i
, ++arsym
, p
+= 8)
1109 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1112 /* After the file offsets come null terminated symbol names. */
1113 cend
= contents
+ sz
;
1114 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1116 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1120 bfd_set_error (bfd_error_bad_value
);
1123 arsym
->name
= (char *) p
;
1126 bfd_ardata (abfd
)->symdef_count
= c
;
1127 bfd_has_map (abfd
) = true;
1132 /* See if this is an XCOFF archive. */
1135 _bfd_xcoff_archive_p (abfd
)
1138 char magic
[SXCOFFARMAG
];
1141 if (bfd_bread ((PTR
) magic
, (bfd_size_type
) SXCOFFARMAG
, abfd
) != SXCOFFARMAG
)
1143 if (bfd_get_error () != bfd_error_system_call
)
1144 bfd_set_error (bfd_error_wrong_format
);
1148 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1149 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1151 bfd_set_error (bfd_error_wrong_format
);
1155 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1156 involves a cast, we can't do it as the left operand of
1158 amt
= sizeof (struct artdata
);
1159 abfd
->tdata
.aout_ar_data
= (struct artdata
*) bfd_zalloc (abfd
, amt
);
1160 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1163 bfd_ardata (abfd
)->cache
= NULL
;
1164 bfd_ardata (abfd
)->archive_head
= NULL
;
1165 bfd_ardata (abfd
)->symdefs
= NULL
;
1166 bfd_ardata (abfd
)->extended_names
= NULL
;
1168 /* Now handle the two formats. */
1169 if (magic
[1] != 'b')
1171 /* This is the old format. */
1172 struct xcoff_ar_file_hdr hdr
;
1174 /* Copy over the magic string. */
1175 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1177 /* Now read the rest of the file header. */
1178 if (bfd_bread ((PTR
) &hdr
.memoff
,
1179 (bfd_size_type
) SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, abfd
)
1180 != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1182 if (bfd_get_error () != bfd_error_system_call
)
1183 bfd_set_error (bfd_error_wrong_format
);
1187 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1188 (char **) NULL
, 10);
1190 amt
= SIZEOF_AR_FILE_HDR
;
1191 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1192 if (bfd_ardata (abfd
)->tdata
== NULL
)
1195 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1199 /* This is the new format. */
1200 struct xcoff_ar_file_hdr_big hdr
;
1202 /* Copy over the magic string. */
1203 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1205 /* Now read the rest of the file header. */
1206 if (bfd_bread ((PTR
) &hdr
.memoff
,
1207 (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, abfd
)
1208 != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1210 if (bfd_get_error () != bfd_error_system_call
)
1211 bfd_set_error (bfd_error_wrong_format
);
1215 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1216 machines) since the field width is 20 and there numbers with more
1217 than 32 bits can be represented. */
1218 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1219 (char **) NULL
, 10);
1221 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1222 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1223 if (bfd_ardata (abfd
)->tdata
== NULL
)
1226 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1229 if (! _bfd_xcoff_slurp_armap (abfd
))
1231 bfd_release (abfd
, bfd_ardata (abfd
));
1232 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1239 /* Read the archive header in an XCOFF archive. */
1242 _bfd_xcoff_read_ar_hdr (abfd
)
1245 bfd_size_type namlen
;
1246 struct areltdata
*ret
;
1247 bfd_size_type amt
= sizeof (struct areltdata
);
1249 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1253 if (! xcoff_big_format_p (abfd
))
1255 struct xcoff_ar_hdr hdr
;
1256 struct xcoff_ar_hdr
*hdrp
;
1258 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1265 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1266 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1267 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1273 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1274 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1279 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1281 ret
->arch_header
= (char *) hdrp
;
1282 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1283 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1287 struct xcoff_ar_hdr_big hdr
;
1288 struct xcoff_ar_hdr_big
*hdrp
;
1290 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1291 != SIZEOF_AR_HDR_BIG
)
1297 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1298 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1299 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1305 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1306 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1311 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1313 ret
->arch_header
= (char *) hdrp
;
1314 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1315 machines) since the field width is 20 and there numbers with more
1316 than 32 bits can be represented. */
1317 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1318 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1321 /* Skip over the XCOFFARFMAG at the end of the file name. */
1322 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1328 /* Open the next element in an XCOFF archive. */
1331 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1337 if (xcoff_ardata (archive
) == NULL
)
1339 bfd_set_error (bfd_error_invalid_operation
);
1343 if (! xcoff_big_format_p (archive
))
1345 if (last_file
== NULL
)
1346 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1348 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1352 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1354 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1355 (char **) NULL
, 10))
1357 bfd_set_error (bfd_error_no_more_archived_files
);
1363 if (last_file
== NULL
)
1364 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1366 /* XXX These actually have to be a calls to strtoll (at least
1367 on 32-bit machines) since the fields's width is 20 and
1368 there numbers with more than 32 bits can be represented. */
1369 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1372 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1373 machines) since the fields's width is 20 and there numbers with more
1374 than 32 bits can be represented. */
1376 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1378 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1379 (char **) NULL
, 10))
1381 bfd_set_error (bfd_error_no_more_archived_files
);
1386 return _bfd_get_elt_at_filepos (archive
, filestart
);
1389 /* Stat an element in an XCOFF archive. */
1392 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1396 if (abfd
->arelt_data
== NULL
)
1398 bfd_set_error (bfd_error_invalid_operation
);
1402 if (! xcoff_big_format_p (abfd
))
1404 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1406 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1407 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1408 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1409 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1410 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1414 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1416 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1417 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1418 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1419 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1420 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1426 /* Normalize a file name for inclusion in an archive. */
1429 normalize_filename (abfd
)
1433 const char *filename
;
1435 file
= bfd_get_filename (abfd
);
1436 filename
= strrchr (file
, '/');
1437 if (filename
!= NULL
)
1444 /* Write out an XCOFF armap. */
1448 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1450 unsigned int elength ATTRIBUTE_UNUSED
;
1452 unsigned int orl_count
;
1455 struct xcoff_ar_hdr hdr
;
1457 unsigned char buf
[4];
1462 memset (&hdr
, 0, sizeof hdr
);
1463 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1464 sprintf (hdr
.nextoff
, "%d", 0);
1465 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1466 sprintf (hdr
.date
, "%d", 0);
1467 sprintf (hdr
.uid
, "%d", 0);
1468 sprintf (hdr
.gid
, "%d", 0);
1469 sprintf (hdr
.mode
, "%d", 0);
1470 sprintf (hdr
.namlen
, "%d", 0);
1472 /* We need spaces, not null bytes, in the header. */
1473 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1477 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1479 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1483 H_PUT_32 (abfd
, orl_count
, buf
);
1484 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1487 sub
= abfd
->archive_head
;
1488 fileoff
= SIZEOF_AR_FILE_HDR
;
1490 while (sub
!= NULL
&& i
< orl_count
)
1494 while (map
[i
].u
.abfd
== sub
)
1496 H_PUT_32 (abfd
, fileoff
, buf
);
1497 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1501 namlen
= strlen (normalize_filename (sub
));
1502 namlen
= (namlen
+ 1) &~ (size_t) 1;
1503 fileoff
+= (SIZEOF_AR_HDR
1506 + arelt_size (sub
));
1507 fileoff
= (fileoff
+ 1) &~ 1;
1511 for (i
= 0; i
< orl_count
; i
++)
1516 name
= *map
[i
].name
;
1517 namlen
= strlen (name
);
1518 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1522 if ((stridx
& 1) != 0)
1527 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1534 /* Write a single armap in the big format. */
1537 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1541 unsigned int orl_count
;
1542 unsigned int orl_ccount
;
1543 unsigned int stridx
;
1545 const char *prevoff
;
1548 struct xcoff_ar_hdr_big hdr
;
1550 unsigned char buf
[4];
1553 const bfd_arch_info_type
*arch_info
= NULL
;
1557 memset (&hdr
, 0, sizeof hdr
);
1558 /* XXX This call actually should use %lld (at least on 32-bit
1559 machines) since the fields's width is 20 and there numbers with
1560 more than 32 bits can be represented. */
1561 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1564 sprintf (hdr
.nextoff
, "%d", 0);
1568 /* Do explict cast to long to remove compiler warning. */
1569 sprintf (hdr
.nextoff
, "%ld", (strtol (prevoff
, (char **) NULL
, 10)
1570 + (long) (4 + orl_ccount
* 4 + stridx
)));
1573 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1574 sprintf (hdr
.date
, "%d", 0);
1575 sprintf (hdr
.uid
, "%d", 0);
1576 sprintf (hdr
.gid
, "%d", 0);
1577 sprintf (hdr
.mode
, "%d", 0);
1578 sprintf (hdr
.namlen
, "%d", 0);
1580 /* We need spaces, not null bytes, in the header. */
1581 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1585 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1587 if ((bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1588 != SIZEOF_AR_HDR_BIG
)
1589 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1593 H_PUT_32 (abfd
, orl_ccount
, buf
);
1594 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1597 sub
= abfd
->archive_head
;
1598 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1600 while (sub
!= NULL
&& i
< orl_count
)
1604 if ((bfd_arch_bits_per_address (map
[i
].u
.abfd
) == 64) == bits64
)
1605 while (map
[i
].u
.abfd
== sub
)
1607 H_PUT_32 (abfd
, fileoff
, buf
);
1608 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1613 while (map
[i
].u
.abfd
== sub
)
1616 namlen
= strlen (normalize_filename (sub
));
1617 namlen
= (namlen
+ 1) &~ (size_t) 1;
1618 fileoff
+= (SIZEOF_AR_HDR_BIG
1621 + arelt_size (sub
));
1622 fileoff
= (fileoff
+ 1) &~ 1;
1627 for (i
= 0; i
< orl_count
; i
++)
1631 bfd
*ob
= map
[i
].u
.abfd
;
1633 if (ob
!= object_bfd
)
1634 arch_info
= bfd_get_arch_info (ob
);
1635 if ((arch_info
->bits_per_address
== 64) != bits64
)
1638 name
= *map
[i
].name
;
1639 namlen
= strlen (name
);
1640 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1644 if ((stridx
& 1) != 0)
1649 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1657 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1659 unsigned int elength ATTRIBUTE_UNUSED
;
1661 unsigned int orl_count
;
1665 unsigned int orl_count_32
, orl_count_64
;
1666 unsigned int stridx_32
, stridx_64
;
1667 const bfd_arch_info_type
*arch_info
= NULL
;
1670 /* First, we look through the symbols and work out which are
1671 from 32-bit objects and which from 64-bit ones. */
1677 for (i
= 0; i
< orl_count
; i
++)
1679 bfd
*ob
= map
[i
].u
.abfd
;
1681 if (ob
!= object_bfd
)
1682 arch_info
= bfd_get_arch_info (ob
);
1683 len
= strlen (*map
[i
].name
) + 1;
1684 if (arch_info
->bits_per_address
== 64)
1696 /* A quick sanity check... */
1697 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1698 /* Explicit cast to int for compiler. */
1699 BFD_ASSERT ((int)(stridx_64
+ stridx_32
) == stridx
);
1701 /* Now write out each map. */
1702 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1704 xcoff_ardata_big (abfd
)->memoff
,
1705 xcoff_ardata_big (abfd
)->symoff
))
1707 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1709 xcoff_ardata_big (abfd
)->symoff
,
1710 xcoff_ardata_big (abfd
)->symoff64
))
1717 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1719 unsigned int elength ATTRIBUTE_UNUSED
;
1721 unsigned int orl_count
;
1724 if (! xcoff_big_format_p (abfd
))
1725 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1727 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1730 /* Write out an XCOFF archive. We always write an entire archive,
1731 rather than fussing with the freelist and so forth. */
1734 xcoff_write_archive_contents_old (abfd
)
1737 struct xcoff_ar_file_hdr fhdr
;
1738 bfd_size_type count
;
1739 bfd_size_type total_namlen
;
1743 ufile_ptr prevoff
, nextoff
;
1746 struct xcoff_ar_hdr ahdr
;
1751 memset (&fhdr
, 0, sizeof fhdr
);
1752 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1753 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1754 sprintf (fhdr
.freeoff
, "%d", 0);
1758 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1761 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1763 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1764 if (offsets
== NULL
)
1767 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1770 makemap
= bfd_has_map (abfd
);
1773 nextoff
= SIZEOF_AR_FILE_HDR
;
1774 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1777 bfd_size_type namlen
;
1778 struct xcoff_ar_hdr
*ahdrp
;
1779 bfd_size_type remaining
;
1781 if (makemap
&& ! hasobjects
)
1783 if (bfd_check_format (sub
, bfd_object
))
1787 name
= normalize_filename (sub
);
1788 namlen
= strlen (name
);
1790 if (sub
->arelt_data
!= NULL
)
1791 ahdrp
= arch_xhdr (sub
);
1799 memset (&ahdr
, 0, sizeof ahdr
);
1801 if (stat (bfd_get_filename (sub
), &s
) != 0)
1803 bfd_set_error (bfd_error_system_call
);
1807 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1808 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1809 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1810 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1811 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1813 if (sub
->arelt_data
== NULL
)
1815 size
= sizeof (struct areltdata
);
1816 sub
->arelt_data
= bfd_alloc (sub
, size
);
1817 if (sub
->arelt_data
== NULL
)
1821 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1824 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1825 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1827 /* If the length of the name is odd, we write out the null byte
1828 after the name as well. */
1829 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
1831 remaining
= arelt_size (sub
);
1832 size
= (SIZEOF_AR_HDR
1837 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1839 offsets
[i
] = nextoff
;
1842 nextoff
+= size
+ (size
& 1);
1844 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1846 /* We need spaces, not null bytes, in the header. */
1847 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1851 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1853 || (bfd_bwrite ((PTR
) name
, namlen
, abfd
) != namlen
)
1854 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1858 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1860 while (remaining
!= 0)
1863 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1865 amt
= sizeof buffer
;
1866 if (amt
> remaining
)
1868 if (bfd_bread (buffer
, amt
, sub
) != amt
1869 || bfd_bwrite (buffer
, amt
, abfd
) != amt
)
1874 if ((size
& 1) != 0)
1879 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1884 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1886 /* Write out the member table. */
1888 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1889 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1891 memset (&ahdr
, 0, sizeof ahdr
);
1892 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1893 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1894 sprintf (ahdr
.date
, "%d", 0);
1895 sprintf (ahdr
.uid
, "%d", 0);
1896 sprintf (ahdr
.gid
, "%d", 0);
1897 sprintf (ahdr
.mode
, "%d", 0);
1898 sprintf (ahdr
.namlen
, "%d", 0);
1900 size
= (SIZEOF_AR_HDR
1907 nextoff
+= size
+ (size
& 1);
1909 if (makemap
&& hasobjects
)
1910 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
1912 sprintf (ahdr
.nextoff
, "%d", 0);
1914 /* We need spaces, not null bytes, in the header. */
1915 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
1919 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1921 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1925 sprintf (decbuf
, "%-12ld", (long) count
);
1926 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) 12, abfd
) != 12)
1928 for (i
= 0; i
< (size_t) count
; i
++)
1930 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
1931 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) 12, abfd
) != 12)
1934 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1937 bfd_size_type namlen
;
1939 name
= normalize_filename (sub
);
1940 namlen
= strlen (name
);
1941 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
1944 if ((size
& 1) != 0)
1949 if (bfd_bwrite ((PTR
) &b
, (bfd_size_type
) 1, abfd
) != 1)
1953 /* Write out the armap, if appropriate. */
1955 if (! makemap
|| ! hasobjects
)
1956 sprintf (fhdr
.symoff
, "%d", 0);
1959 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1960 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
1961 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
1962 if (! _bfd_compute_and_write_armap (abfd
, 0))
1966 /* Write out the archive file header. */
1968 /* We need spaces, not null bytes, in the header. */
1969 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
1973 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
1974 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
1975 != SIZEOF_AR_FILE_HDR
))
1982 xcoff_write_archive_contents_big (abfd
)
1985 struct xcoff_ar_file_hdr_big fhdr
;
1986 bfd_size_type count
;
1987 bfd_size_type total_namlen
;
1991 ufile_ptr prevoff
, nextoff
;
1994 struct xcoff_ar_hdr_big ahdr
;
1999 memset (&fhdr
, 0, sizeof fhdr
);
2000 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2001 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
2002 sprintf (fhdr
.freeoff
, "%d", 0);
2006 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2009 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2011 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2012 if (offsets
== NULL
)
2015 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2018 makemap
= bfd_has_map (abfd
);
2021 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2022 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
2025 bfd_size_type namlen
;
2026 struct xcoff_ar_hdr_big
*ahdrp
;
2027 bfd_size_type remaining
;
2029 if (makemap
&& ! hasobjects
)
2031 if (bfd_check_format (sub
, bfd_object
))
2035 name
= normalize_filename (sub
);
2036 namlen
= strlen (name
);
2038 if (sub
->arelt_data
!= NULL
)
2039 ahdrp
= arch_xhdr_big (sub
);
2047 memset (&ahdr
, 0, sizeof ahdr
);
2049 /* XXX This should actually be a call to stat64 (at least on
2050 32-bit machines). */
2051 if (stat (bfd_get_filename (sub
), &s
) != 0)
2053 bfd_set_error (bfd_error_system_call
);
2057 /* XXX This call actually should use %lld (at least on 32-bit
2058 machines) since the fields's width is 20 and there numbers with
2059 more than 32 bits can be represented. */
2060 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2061 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2062 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2063 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2064 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2066 if (sub
->arelt_data
== NULL
)
2068 size
= sizeof (struct areltdata
);
2069 sub
->arelt_data
= bfd_alloc (sub
, size
);
2070 if (sub
->arelt_data
== NULL
)
2074 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2077 /* XXX These calls actually should use %lld (at least on 32-bit
2078 machines) since the fields's width is 20 and there numbers with
2079 more than 32 bits can be represented. */
2080 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2081 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2083 /* If the length of the name is odd, we write out the null byte
2084 after the name as well. */
2085 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2087 remaining
= arelt_size (sub
);
2088 size
= (SIZEOF_AR_HDR_BIG
2093 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2095 offsets
[i
] = nextoff
;
2098 nextoff
+= size
+ (size
& 1);
2100 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2102 /* We need spaces, not null bytes, in the header. */
2103 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2107 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
2108 != SIZEOF_AR_HDR_BIG
)
2109 || bfd_bwrite ((PTR
) name
, (bfd_size_type
) namlen
, abfd
) != namlen
2110 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2114 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2116 while (remaining
!= 0)
2119 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2121 amt
= sizeof buffer
;
2122 if (amt
> remaining
)
2124 if (bfd_bread (buffer
, amt
, sub
) != amt
2125 || bfd_bwrite (buffer
, amt
, abfd
) != amt
)
2130 if ((size
& 1) != 0)
2135 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
2140 /* XXX This call actually should use %lld (at least on 32-bit
2141 machines) since the fields's width is 20 and there numbers with
2142 more than 32 bits can be represented. */
2143 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2145 /* Write out the member table. */
2147 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2148 /* XXX This call actually should use %lld (at least on 32-bit
2149 machines) since the fields's width is 20 and there numbers with
2150 more than 32 bits can be represented. */
2151 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2153 memset (&ahdr
, 0, sizeof ahdr
);
2154 /* XXX The next two calls actually should use %lld (at least on 32-bit
2155 machines) since the fields's width is 20 and there numbers with
2156 more than 32 bits can be represented. */
2157 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2158 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2159 sprintf (ahdr
.date
, "%d", 0);
2160 sprintf (ahdr
.uid
, "%d", 0);
2161 sprintf (ahdr
.gid
, "%d", 0);
2162 sprintf (ahdr
.mode
, "%d", 0);
2163 sprintf (ahdr
.namlen
, "%d", 0);
2165 size
= (SIZEOF_AR_HDR_BIG
2172 nextoff
+= size
+ (size
& 1);
2174 if (makemap
&& hasobjects
)
2175 /* XXX This call actually should use %lld (at least on 32-bit
2176 machines) since the fields's width is 20 and there numbers with
2177 more than 32 bits can be represented. */
2178 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2180 sprintf (ahdr
.nextoff
, "%d", 0);
2182 /* We need spaces, not null bytes, in the header. */
2183 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2187 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
2188 != SIZEOF_AR_HDR_BIG
)
2189 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2193 sprintf (decbuf
, "%-12ld", (long) count
);
2194 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) 12, abfd
) != 12)
2196 for (i
= 0; i
< (size_t) count
; i
++)
2198 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2199 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) 12, abfd
) != 12)
2202 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2207 name
= normalize_filename (sub
);
2208 namlen
= strlen (name
);
2209 if (bfd_bwrite ((PTR
) name
, (bfd_size_type
) (namlen
+ 1), abfd
)
2213 if ((size
& 1) != 0)
2218 if (bfd_bwrite ((PTR
) &b
, (bfd_size_type
) 1, abfd
) != 1)
2222 /* Write out the armap, if appropriate. */
2224 if (! makemap
|| ! hasobjects
)
2225 sprintf (fhdr
.symoff
, "%d", 0);
2228 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2229 /* XXX This call actually should use %lld (at least on 32-bit
2230 machines) since the fields's width is 20 and there numbers with
2231 more than 32 bits can be represented. */
2232 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2233 if (! _bfd_compute_and_write_armap (abfd
, 0))
2237 /* Write out the archive file header. */
2239 /* We need spaces, not null bytes, in the header. */
2240 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2244 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2245 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
, abfd
)
2246 != SIZEOF_AR_FILE_HDR_BIG
))
2253 _bfd_xcoff_write_archive_contents (abfd
)
2256 if (! xcoff_big_format_p (abfd
))
2257 return xcoff_write_archive_contents_old (abfd
);
2259 return xcoff_write_archive_contents_big (abfd
);
2262 /* We can't use the usual coff_sizeof_headers routine, because AIX
2263 always uses an a.out header. */
2266 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2268 boolean reloc ATTRIBUTE_UNUSED
;
2273 if (xcoff_data (abfd
)->full_aouthdr
)
2276 size
+= SMALL_AOUTSZ
;
2277 size
+= abfd
->section_count
* SCNHSZ
;
2281 /* Routines to swap information in the XCOFF .loader section. If we
2282 ever need to write an XCOFF loader, this stuff will need to be
2283 moved to another file shared by the linker (which XCOFF calls the
2284 ``binder'') and the loader. */
2286 /* Swap in the ldhdr structure. */
2289 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2292 struct internal_ldhdr
*dst
;
2294 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2296 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2297 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2298 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2299 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2300 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2301 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2302 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2303 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2306 /* Swap out the ldhdr structure. */
2309 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2311 const struct internal_ldhdr
*src
;
2314 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2316 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2317 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2318 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2319 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2320 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2321 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2322 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2323 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2326 /* Swap in the ldsym structure. */
2329 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2332 struct internal_ldsym
*dst
;
2334 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2336 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2337 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2339 dst
->_l
._l_l
._l_zeroes
= 0;
2340 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2342 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2343 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2344 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2345 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2346 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2347 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2350 /* Swap out the ldsym structure. */
2353 xcoff_swap_ldsym_out (abfd
, src
, d
)
2355 const struct internal_ldsym
*src
;
2358 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2360 if (src
->_l
._l_l
._l_zeroes
!= 0)
2361 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2364 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2365 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2366 dst
->_l
._l_l
._l_offset
);
2368 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2369 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2370 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2371 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2372 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2373 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2376 /* Swap in the ldrel structure. */
2379 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2382 struct internal_ldrel
*dst
;
2384 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2386 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2387 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2388 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2389 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2392 /* Swap out the ldrel structure. */
2395 xcoff_swap_ldrel_out (abfd
, src
, d
)
2397 const struct internal_ldrel
*src
;
2400 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2402 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2403 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2404 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2405 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2410 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2411 This is currently the only processor which uses XCOFF; I hope that
2412 will never change. */
2415 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
2416 input_section
, contents
, relocs
, syms
,
2419 struct bfd_link_info
*info
;
2421 asection
*input_section
;
2423 struct internal_reloc
*relocs
;
2424 struct internal_syment
*syms
;
2425 asection
**sections
;
2427 struct internal_reloc
*rel
;
2428 struct internal_reloc
*relend
;
2431 relend
= rel
+ input_section
->reloc_count
;
2433 for (; rel
< relend
; rel
++)
2436 struct xcoff_link_hash_entry
*h
;
2437 struct internal_syment
*sym
;
2440 struct reloc_howto_struct howto
;
2441 bfd_reloc_status_type rstat
;
2443 /* Relocation type R_REF is a special relocation type which is
2444 merely used to prevent garbage collection from occurring for
2445 the csect including the symbol which it references. */
2446 if (rel
->r_type
== R_REF
)
2449 symndx
= rel
->r_symndx
;
2459 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
2460 sym
= syms
+ symndx
;
2461 addend
= - sym
->n_value
;
2465 /* We build the howto information on the fly. */
2467 howto
.type
= rel
->r_type
;
2468 howto
.rightshift
= 0;
2470 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
2471 howto
.pc_relative
= false;
2473 if ((rel
->r_size
& 0x80) != 0)
2474 howto
.complain_on_overflow
= complain_overflow_signed
;
2476 howto
.complain_on_overflow
= complain_overflow_bitfield
;
2477 howto
.special_function
= NULL
;
2478 howto
.name
= "internal";
2479 howto
.partial_inplace
= true;
2480 if (howto
.bitsize
== 32)
2481 howto
.src_mask
= howto
.dst_mask
= 0xffffffff;
2484 howto
.src_mask
= howto
.dst_mask
= (1 << howto
.bitsize
) - 1;
2485 if (howto
.bitsize
== 16)
2488 howto
.pcrel_offset
= false;
2498 sec
= bfd_abs_section_ptr
;
2503 sec
= sections
[symndx
];
2504 /* Hack to make sure we use the right TOC anchor value
2505 if this reloc is against the TOC anchor. */
2507 if (sec
->name
[3] == '0'
2508 && strcmp (sec
->name
, ".tc0") == 0)
2510 val
= xcoff_data (output_bfd
)->toc
;
2514 val
= (sec
->output_section
->vma
2515 + sec
->output_offset
2523 if (h
->root
.type
== bfd_link_hash_defined
2524 || h
->root
.type
== bfd_link_hash_defweak
)
2528 sec
= h
->root
.u
.def
.section
;
2529 val
= (h
->root
.u
.def
.value
2530 + sec
->output_section
->vma
2531 + sec
->output_offset
);
2533 else if (h
->root
.type
== bfd_link_hash_common
)
2537 sec
= h
->root
.u
.c
.p
->section
;
2538 val
= (sec
->output_section
->vma
2539 + sec
->output_offset
);
2541 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2542 || (h
->flags
& XCOFF_IMPORT
) != 0)
2544 /* Every symbol in a shared object is defined somewhere. */
2547 else if (! info
->relocateable
)
2549 if (! ((*info
->callbacks
->undefined_symbol
)
2550 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2551 rel
->r_vaddr
- input_section
->vma
, true)))
2554 /* Don't try to process the reloc. It can't help, and
2555 it may generate another error. */
2560 /* I took the relocation type definitions from two documents:
2561 the PowerPC AIX Version 4 Application Binary Interface, First
2562 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2563 32-Bit Hardware Implementation (June 30, 1994). Differences
2564 between the documents are noted below. */
2566 switch (rel
->r_type
)
2571 /* These relocs are defined by the PowerPC ABI to be
2572 relative branches which use half of the difference
2573 between the symbol and the program counter. I can't
2574 quite figure out when this is useful. These relocs are
2575 not defined by the PowerOpen ABI. */
2577 (*_bfd_error_handler
)
2578 (_("%s: unsupported relocation type 0x%02x"),
2579 bfd_archive_filename (input_bfd
), (unsigned int) rel
->r_type
);
2580 bfd_set_error (bfd_error_bad_value
);
2583 /* Simple positive relocation. */
2586 /* Simple negative relocation. */
2590 /* Simple PC relative relocation. */
2591 howto
.pc_relative
= true;
2594 /* TOC relative relocation. The value in the instruction in
2595 the input file is the offset from the input file TOC to
2596 the desired location. We want the offset from the final
2597 TOC to the desired location. We have:
2602 so we must change insn by on - in.
2605 /* Global linkage relocation. The value of this relocation
2606 is the address of the entry in the TOC section. */
2608 /* Local object TOC address. I can't figure out the
2609 difference between this and case R_GL. */
2611 /* TOC relative relocation. A TOC relative load instruction
2612 which may be changed to a load address instruction.
2613 FIXME: We don't currently implement this optimization. */
2615 /* TOC relative relocation. This is a TOC relative load
2616 address instruction which may be changed to a load
2617 instruction. FIXME: I don't know if this is the correct
2619 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2621 if (h
->toc_section
== NULL
)
2623 (*_bfd_error_handler
)
2624 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2625 bfd_archive_filename (input_bfd
), rel
->r_vaddr
,
2626 h
->root
.root
.string
);
2627 bfd_set_error (bfd_error_bad_value
);
2631 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2632 val
= (h
->toc_section
->output_section
->vma
2633 + h
->toc_section
->output_offset
);
2636 val
= ((val
- xcoff_data (output_bfd
)->toc
)
2637 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2641 /* Absolute branch. We don't want to mess with the lower
2642 two bits of the instruction. */
2644 /* The PowerPC ABI defines this as an absolute call which
2645 may be modified to become a relative call. The PowerOpen
2646 ABI does not define this relocation type. */
2648 /* Absolute branch which may be modified to become a
2651 /* The PowerPC ABI defines this as an absolute branch to a
2652 fixed address which may be modified to an absolute branch
2653 to a symbol. The PowerOpen ABI does not define this
2656 /* The PowerPC ABI defines this as an absolute branch to a
2657 fixed address which may be modified to a relative branch.
2658 The PowerOpen ABI does not define this relocation type. */
2659 howto
.src_mask
&= ~3;
2660 howto
.dst_mask
= howto
.src_mask
;
2663 /* Relative branch. We don't want to mess with the lower
2664 two bits of the instruction. */
2666 /* The PowerPC ABI defines this as a relative call which may
2667 be modified to become an absolute call. The PowerOpen
2668 ABI does not define this relocation type. */
2670 /* A relative branch which may be modified to become an
2671 absolute branch. FIXME: We don't implement this,
2672 although we should for symbols of storage mapping class
2674 howto
.pc_relative
= true;
2675 howto
.src_mask
&= ~3;
2676 howto
.dst_mask
= howto
.src_mask
;
2679 /* The PowerPC AIX ABI describes this as a load which may be
2680 changed to a load address. The PowerOpen ABI says this
2681 is the same as case R_POS. */
2684 /* The PowerPC AIX ABI describes this as a load address
2685 which may be changed to a load. The PowerOpen ABI says
2686 this is the same as R_POS. */
2690 /* If we see an R_BR or R_RBR reloc which is jumping to global
2691 linkage code, and it is followed by an appropriate cror nop
2692 instruction, we replace the cror with lwz r2,20(r1). This
2693 restores the TOC after the glink code. Contrariwise, if the
2694 call is followed by a lwz r2,20(r1), but the call is not
2695 going to global linkage code, we can replace the load with a
2697 if ((rel
->r_type
== R_BR
|| rel
->r_type
== R_RBR
)
2699 && h
->root
.type
== bfd_link_hash_defined
2700 && (rel
->r_vaddr
- input_section
->vma
+ 8
2701 <= input_section
->_cooked_size
))
2706 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
2707 next
= bfd_get_32 (input_bfd
, pnext
);
2709 /* The _ptrgl function is magic. It is used by the AIX
2710 compiler to call a function through a pointer. */
2711 if (h
->smclas
== XMC_GL
2712 || strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2714 if (next
== 0x4def7b82 /* cror 15,15,15 */
2715 || next
== 0x4ffffb82 /* cror 31,31,31 */
2716 || next
== 0x60000000) /* ori r0,r0,0 */
2717 bfd_put_32 (input_bfd
,
2718 (bfd_vma
) 0x80410014, /* lwz r1,20(r1) */
2723 if (next
== 0x80410014) /* lwz r1,20(r1) */
2724 bfd_put_32 (input_bfd
,
2725 (bfd_vma
) 0x60000000, /* ori r0,r0,0 */
2730 /* A PC relative reloc includes the section address. */
2731 if (howto
.pc_relative
)
2732 addend
+= input_section
->vma
;
2734 rstat
= _bfd_final_link_relocate (&howto
, input_bfd
, input_section
,
2736 rel
->r_vaddr
- input_section
->vma
,
2745 case bfd_reloc_overflow
:
2748 char buf
[SYMNMLEN
+ 1];
2749 char howto_name
[10];
2754 name
= h
->root
.root
.string
;
2757 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
2762 sprintf (howto_name
, "0x%02x", rel
->r_type
);
2764 if (! ((*info
->callbacks
->reloc_overflow
)
2765 (info
, name
, howto_name
, (bfd_vma
) 0, input_bfd
,
2766 input_section
, rel
->r_vaddr
- input_section
->vma
)))
2776 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
2777 bfd
*abfd ATTRIBUTE_UNUSED
;
2778 struct xcoff_loader_info
*ldinfo
;
2779 struct internal_ldsym
*ldsym
;
2783 len
= strlen (name
);
2785 if (len
<= SYMNMLEN
)
2786 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
2789 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
2791 bfd_size_type newalc
;
2792 bfd_byte
*newstrings
;
2794 newalc
= ldinfo
->string_alc
* 2;
2797 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
2800 newstrings
= ((bfd_byte
*)
2801 bfd_realloc ((PTR
) ldinfo
->strings
, newalc
));
2802 if (newstrings
== NULL
)
2804 ldinfo
->failed
= true;
2807 ldinfo
->string_alc
= newalc
;
2808 ldinfo
->strings
= newstrings
;
2811 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
2812 ldinfo
->strings
+ ldinfo
->string_size
);
2813 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
2814 ldsym
->_l
._l_l
._l_zeroes
= 0;
2815 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
2816 ldinfo
->string_size
+= len
+ 3;
2823 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
2824 struct internal_syment
*sym
,
2827 if (strlen (name
) <= SYMNMLEN
)
2829 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
2837 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
2839 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
2840 if (indx
== (bfd_size_type
) -1)
2842 sym
->_n
._n_n
._n_zeroes
= 0;
2843 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
2849 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
2851 union internal_auxent
*aux
;
2852 const char *symbol_name
;
2854 asection
*return_value
= NULL
;
2856 /* .sv64 = x_smclas == 17
2857 This is an invalid csect for 32 bit apps. */
2858 static const char *names
[19] =
2860 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2861 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
2862 ".td", NULL
, ".sv3264"
2865 if ((19 >= aux
->x_csect
.x_smclas
) &&
2866 (NULL
!= names
[aux
->x_csect
.x_smclas
]))
2868 return_value
= bfd_make_section_anyway
2869 (abfd
, names
[aux
->x_csect
.x_smclas
]);
2873 (*_bfd_error_handler
)
2874 (_("%s: symbol `%s' has unrecognized smclas %d"),
2875 bfd_archive_filename (abfd
), symbol_name
, aux
->x_csect
.x_smclas
);
2876 bfd_set_error (bfd_error_bad_value
);
2879 return return_value
;
2883 xcoff_is_lineno_count_overflow (abfd
, value
)
2884 bfd
*abfd ATTRIBUTE_UNUSED
;
2887 if (0xffff <= value
)
2894 xcoff_is_reloc_count_overflow (abfd
, value
)
2895 bfd
*abfd ATTRIBUTE_UNUSED
;
2898 if (0xffff <= value
)
2905 xcoff_loader_symbol_offset (abfd
, ldhdr
)
2907 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
2909 return bfd_xcoff_ldhdrsz(abfd
);
2913 xcoff_loader_reloc_offset (abfd
, ldhdr
)
2915 struct internal_ldhdr
*ldhdr
;
2917 return bfd_xcoff_ldhdrsz(abfd
) +
2918 (ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(abfd
));
2922 xcoff_generate_rtinit (abfd
, init
, fini
)
2927 bfd_byte filehdr_ext
[FILHSZ
];
2928 bfd_byte scnhdr_ext
[SCNHSZ
];
2929 bfd_byte syment_ext
[SYMESZ
* 8];
2930 bfd_byte reloc_ext
[RELSZ
* 2];
2931 bfd_byte
*data_buffer
;
2932 bfd_size_type data_buffer_size
;
2933 bfd_byte
*string_table
, *st_tmp
;
2934 bfd_size_type string_table_size
;
2936 size_t initsz
, finisz
;
2937 struct internal_filehdr filehdr
;
2938 struct internal_scnhdr scnhdr
;
2939 struct internal_syment syment
;
2940 union internal_auxent auxent
;
2941 struct internal_reloc reloc
;
2943 char *data_name
= ".data";
2944 char *rtinit_name
= "__rtinit";
2946 if (! bfd_xcoff_rtinit_size (abfd
)
2947 || (init
== NULL
&& fini
== NULL
))
2950 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
2951 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
2954 memset (filehdr_ext
, 0, FILHSZ
);
2955 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
2956 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
2957 filehdr
.f_nscns
= 1;
2958 filehdr
.f_timdat
= 0;
2959 filehdr
.f_nsyms
= 0; /* at least 6, no more than 8 */
2960 filehdr
.f_symptr
= 0; /* set below */
2961 filehdr
.f_opthdr
= 0;
2962 filehdr
.f_flags
= 0;
2964 /* section header */
2965 memset (scnhdr_ext
, 0, SCNHSZ
);
2966 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
2967 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
2970 scnhdr
.s_size
= 0; /* set below */
2971 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
2972 scnhdr
.s_relptr
= 0; /* set below */
2973 scnhdr
.s_lnnoptr
= 0;
2974 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
2976 scnhdr
.s_flags
= STYP_DATA
;
2979 0x0000 0x00000000 : rtl
2980 0x0004 0x00000010 : offset to init, or 0
2981 0x0008 0x00000028 : offset to fini, or 0
2982 0x000C 0x0000000C : size of descriptor
2983 0x0010 0x00000000 : init, needs a reloc
2984 0x0014 0x00000040 : offset to init name
2985 0x0018 0x00000000 : flags, padded to a word
2986 0x001C 0x00000000 : empty init
2989 0x0028 0x00000000 : fini, needs a reloc
2990 0x002C 0x00000??? : offset to fini name
2991 0x0030 0x00000000 : flags, padded to a word
2992 0x0034 0x00000000 : empty fini
2996 0x0040 + initsz fini name */
2998 data_buffer_size
= 0x0040 + initsz
+ finisz
;
2999 data_buffer_size
+= (data_buffer_size
& 7) ? 8 - (data_buffer_size
& 7) : 0;
3000 data_buffer
= (bfd_byte
*)bfd_malloc (data_buffer_size
);
3001 memset (data_buffer
, 0, data_buffer_size
);
3006 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3008 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3009 memcpy (&data_buffer
[val
], init
, initsz
);
3015 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3016 val
= 0x40 + initsz
;
3017 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3018 memcpy (&data_buffer
[val
], fini
, finisz
);
3022 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3024 scnhdr
.s_size
= data_buffer_size
;
3027 string_table_size
= 0;
3029 string_table_size
+= initsz
;
3031 string_table_size
+= finisz
;
3032 if (string_table_size
)
3034 string_table_size
+= 4;
3035 string_table
= (bfd_byte
*)bfd_malloc (string_table_size
);
3036 memset (string_table
, 0, string_table_size
);
3037 val
= string_table_size
;
3038 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3039 st_tmp
= string_table
+ 4;
3047 memset (syment_ext
, 0, 8 * SYMESZ
);
3048 memset (reloc_ext
, 0, 2 * RELSZ
);
3051 memset (&syment
, 0, sizeof (struct internal_syment
));
3052 memset (&auxent
, 0, sizeof (union internal_auxent
));
3053 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3055 syment
.n_sclass
= C_HIDEXT
;
3056 syment
.n_numaux
= 1;
3057 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3058 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3059 auxent
.x_csect
.x_smclas
= XMC_RW
;
3060 bfd_coff_swap_sym_out (abfd
, &syment
,
3061 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3062 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3064 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3065 filehdr
.f_nsyms
+= 2;
3068 memset (&syment
, 0, sizeof (struct internal_syment
));
3069 memset (&auxent
, 0, sizeof (union internal_auxent
));
3070 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3072 syment
.n_sclass
= C_EXT
;
3073 syment
.n_numaux
= 1;
3074 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3075 auxent
.x_csect
.x_smclas
= XMC_RW
;
3076 bfd_coff_swap_sym_out (abfd
, &syment
,
3077 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3078 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3080 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3081 filehdr
.f_nsyms
+= 2;
3086 memset (&syment
, 0, sizeof (struct internal_syment
));
3087 memset (&auxent
, 0, sizeof (union internal_auxent
));
3091 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3092 memcpy (st_tmp
, init
, initsz
);
3096 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3098 syment
.n_sclass
= C_EXT
;
3099 syment
.n_numaux
= 1;
3100 bfd_coff_swap_sym_out (abfd
, &syment
,
3101 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3102 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3104 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3107 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3108 reloc
.r_vaddr
= 0x0010;
3109 reloc
.r_symndx
= filehdr
.f_nsyms
;
3110 reloc
.r_type
= R_POS
;
3112 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3114 filehdr
.f_nsyms
+= 2;
3115 scnhdr
.s_nreloc
+= 1;
3121 memset (&syment
, 0, sizeof (struct internal_syment
));
3122 memset (&auxent
, 0, sizeof (union internal_auxent
));
3126 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3127 memcpy (st_tmp
, fini
, finisz
);
3131 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3133 syment
.n_sclass
= C_EXT
;
3134 syment
.n_numaux
= 1;
3135 bfd_coff_swap_sym_out (abfd
, &syment
,
3136 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3137 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3139 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3142 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3143 reloc
.r_vaddr
= 0x0028;
3144 reloc
.r_symndx
= filehdr
.f_nsyms
;
3145 reloc
.r_type
= R_POS
;
3147 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3148 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3150 filehdr
.f_nsyms
+= 2;
3151 scnhdr
.s_nreloc
+= 1;
3154 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3155 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3157 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3158 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3159 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3160 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3161 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3162 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3163 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3164 bfd_bwrite (string_table
, string_table_size
, abfd
);
3170 static reloc_howto_type xcoff_dynamic_reloc
=
3171 HOWTO (0, /* type */
3173 2, /* size (0 = byte, 1 = short, 2 = long) */
3175 false, /* pc_relative */
3177 complain_overflow_bitfield
, /* complain_on_overflow */
3178 0, /* special_function */
3180 true, /* partial_inplace */
3181 0xffffffff, /* src_mask */
3182 0xffffffff, /* dst_mask */
3183 false); /* pcrel_offset */
3187 The first word of global linkage code must be modified by filling in
3188 the correct TOC offset. */
3190 static unsigned long xcoff_glink_code
[9] =
3192 0x81820000, /* lwz r12,0(r2) */
3193 0x90410014, /* stw r2,20(r1) */
3194 0x800c0000, /* lwz r0,0(r12) */
3195 0x804c0004, /* lwz r2,4(r12) */
3196 0x7c0903a6, /* mtctr r0 */
3197 0x4e800420, /* bctr */
3198 0x00000000, /* start of traceback table */
3199 0x000c8000, /* traceback table */
3200 0x00000000, /* traceback table */
3204 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3206 { /* COFF backend, defined in libcoff.h. */
3207 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3208 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3209 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3210 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3211 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3212 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3213 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3214 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3215 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3216 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3217 FILHSZ
, /* _bfd_filhsz */
3218 AOUTSZ
, /* _bfd_aoutsz */
3219 SCNHSZ
, /* _bfd_scnhsz */
3220 SYMESZ
, /* _bfd_symesz */
3221 AUXESZ
, /* _bfd_auxesz */
3222 RELSZ
, /* _bfd_relsz */
3223 LINESZ
, /* _bfd_linesz */
3224 FILNMLEN
, /* _bfd_filnmlen */
3225 true, /* _bfd_coff_long_filenames */
3226 false, /* _bfd_coff_long_section_names */
3227 (3), /* _bfd_coff_default_section_alignment_power */
3228 false, /* _bfd_coff_force_symnames_in_strings */
3229 2, /* _bfd_coff_debug_string_prefix_length */
3230 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3231 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3232 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3233 coff_swap_reloc_in
, /* _bfd_reloc_in */
3234 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3235 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3236 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3237 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3238 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3239 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3240 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3241 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3242 coff_print_aux
, /* bfd_coff_print_aux */
3243 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3244 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3245 NULL
, /* bfd_coff_sym_is_global */
3246 coff_compute_section_file_positions
, /* _bfd_coff_compute_section_file_positions */
3247 NULL
, /* _bfd_coff_start_final_link */
3248 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3249 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3250 NULL
, /* _bfd_coff_addust_symndx */
3251 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3252 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3253 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3256 0x01DF, /* magic number */
3257 bfd_arch_rs6000
, /* architecture */
3258 bfd_mach_rs6k
, /* machine */
3260 /* Function pointers to xcoff specific swap routines. */
3261 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3262 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3263 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3264 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3265 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3266 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3269 LDHDRSZ
, /* _xcoff_ldhdrsz */
3270 LDSYMSZ
, /* _xcoff_ldsymsz */
3271 LDRELSZ
, /* _xcoff_ldrelsz */
3272 12, /* _xcoff_function_descriptor_size */
3273 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3276 1, /* _xcoff_ldhdr_version */
3278 /* Xcoff vs xcoff64 putting symbol names. */
3279 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3280 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3282 & xcoff_dynamic_reloc
, /* dynamic reloc howto */
3284 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3286 /* Lineno and reloc count overflow. */
3287 xcoff_is_lineno_count_overflow
,
3288 xcoff_is_reloc_count_overflow
,
3290 xcoff_loader_symbol_offset
,
3291 xcoff_loader_reloc_offset
,
3294 & xcoff_glink_code
[0],
3295 (36), /* _xcoff_glink_size */
3298 64, /* _xcoff_rtinit_size */
3299 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
3302 /* The transfer vector that leads the outside world to all of the above. */
3303 const bfd_target rs6000coff_vec
=
3306 bfd_target_xcoff_flavour
,
3307 BFD_ENDIAN_BIG
, /* data byte order is big */
3308 BFD_ENDIAN_BIG
, /* header byte order is big */
3310 (HAS_RELOC
| EXEC_P
| /* object flags */
3311 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3312 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3314 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3315 0, /* leading char */
3316 '/', /* ar_pad_char */
3317 15, /* ar_max_namelen??? FIXMEmgo */
3320 bfd_getb64
, /* bfd_getx64 */
3321 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3322 bfd_putb64
, /* bfd_putx64 */
3323 bfd_getb32
, /* bfd_getx32 */
3324 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3325 bfd_putb32
, /* bfd_putx32 */
3326 bfd_getb16
, /* bfd_getx16 */
3327 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3328 bfd_putb16
, /* bfd_putx16 */
3331 bfd_getb64
, /* bfd_h_getx64 */
3332 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3333 bfd_putb64
, /* bfd_h_putx64 */
3334 bfd_getb32
, /* bfd_h_getx32 */
3335 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3336 bfd_putb32
, /* bfd_h_putx32 */
3337 bfd_getb16
, /* bfd_h_getx16 */
3338 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3339 bfd_putb16
, /* bfd_h_putx16 */
3341 { /* bfd_check_format */
3344 _bfd_xcoff_archive_p
,
3348 { /* bfd_set_format */
3351 _bfd_generic_mkarchive
,
3355 {/* bfd_write_contents */
3357 coff_write_object_contents
,
3358 _bfd_xcoff_write_archive_contents
,
3363 bfd_true
, /* _close_and_cleanup */
3364 bfd_true
, /* _bfd_free_cached_info */
3365 coff_new_section_hook
, /* _new_section_hook */
3366 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3367 /* _bfd_get_section_contents_in_window */
3368 _bfd_generic_get_section_contents_in_window
,
3371 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3372 /* _bfd_merge_private_bfd_data */
3373 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3374 /* _bfd_copy_pivate_section_data */
3375 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3376 /* _bfd_copy_private_symbol_data */
3377 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3378 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3379 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3382 coff_core_file_failing_command
, /* _core_file_failing_command */
3383 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3384 /* _core_file_matches_executable_p */
3385 coff_core_file_matches_executable_p
,
3388 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3389 /* XCOFF archives do not have
3390 anything which corresponds to
3391 an extended name table. */
3392 bfd_false
, /* _slurp_extended_name_table */
3393 /* _construct_extended_name_table */
3394 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3395 bfd_dont_truncate_arname
, /* _truncate_arname */
3396 _bfd_xcoff_write_armap
, /* _write_armap */
3397 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3398 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3399 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3400 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3401 /* XCOFF archives do not have
3403 bfd_true
, /* _update_armap_timestamp */
3406 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3407 coff_get_symtab
, /* _get_symtab */
3408 coff_make_empty_symbol
, /* _make_empty_symbol */
3409 coff_print_symbol
, /* _print_symbol */
3410 coff_get_symbol_info
, /* _get_symbol_info */
3411 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3412 coff_get_lineno
, /* _get_lineno */
3413 coff_find_nearest_line
, /* _find_nearest_line */
3414 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3415 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3416 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3419 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3420 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3421 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3424 coff_set_arch_mach
, /* _set_arch_mach */
3425 coff_set_section_contents
, /* _set_section_contents */
3428 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3429 /* _bfd_get_relocated_section_contents */
3430 bfd_generic_get_relocated_section_contents
,
3431 bfd_generic_relax_section
, /* _bfd_relax_section */
3432 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3433 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3434 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3435 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3436 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3437 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3440 /* _get_dynamic_symtab_upper_bound */
3441 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3442 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3443 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3444 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3446 /* Opposite endian version, none exists */
3450 (void *) &bfd_xcoff_backend_data
,
3454 * xcoff-powermac target
3456 * Only difference between this target and the rs6000 target is the
3457 * the default architecture and machine type used in coffcode.h
3459 * PowerPC Macs use the same magic numbers as RS/6000
3460 * (because that's how they were bootstrapped originally),
3461 * but they are always PowerPC architecture.
3463 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
3465 { /* COFF backend, defined in libcoff.h */
3466 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3467 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3468 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3469 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3470 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3471 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3472 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3473 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3474 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3475 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3476 FILHSZ
, /* _bfd_filhsz */
3477 AOUTSZ
, /* _bfd_aoutsz */
3478 SCNHSZ
, /* _bfd_scnhsz */
3479 SYMESZ
, /* _bfd_symesz */
3480 AUXESZ
, /* _bfd_auxesz */
3481 RELSZ
, /* _bfd_relsz */
3482 LINESZ
, /* _bfd_linesz */
3483 FILNMLEN
, /* _bfd_filnmlen */
3484 true, /* _bfd_coff_long_filenames */
3485 false, /* _bfd_coff_long_section_names */
3486 (3), /* _bfd_coff_default_section_alignment_power */
3487 false, /* _bfd_coff_force_symnames_in_strings */
3488 2, /* _bfd_coff_debug_string_prefix_length */
3489 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3490 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3491 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3492 coff_swap_reloc_in
, /* _bfd_reloc_in */
3493 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3494 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3495 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3496 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3497 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3498 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3499 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3500 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3501 coff_print_aux
, /* bfd_coff_print_aux */
3502 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3503 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3504 NULL
, /* bfd_coff_sym_is_global */
3505 /* _bfd_coff_compute_section_file_positions */
3506 coff_compute_section_file_positions
,
3507 NULL
, /* _bfd_coff_start_final_link */
3508 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3509 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3510 NULL
, /* _bfd_coff_addust_symndx */
3511 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3512 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3513 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3516 0x01DF, /* magic number */
3517 bfd_arch_powerpc
, /* architecture */
3518 bfd_mach_ppc
, /* machine */
3520 /* function pointers to xcoff specific swap routines */
3521 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3522 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3523 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3524 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3525 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3526 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3529 LDHDRSZ
, /* _xcoff_ldhdrsz */
3530 LDSYMSZ
, /* _xcoff_ldsymsz */
3531 LDRELSZ
, /* _xcoff_ldrelsz */
3532 12, /* _xcoff_function_descriptor_size */
3533 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3536 1, /* _xcoff_ldhdr_version */
3538 /* xcoff vs xcoff64 putting symbol names */
3539 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3540 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3542 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
3544 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3546 /* lineno and reloc count overflow */
3547 xcoff_is_lineno_count_overflow
,
3548 xcoff_is_reloc_count_overflow
,
3550 xcoff_loader_symbol_offset
,
3551 xcoff_loader_reloc_offset
,
3554 &xcoff_glink_code
[0],
3555 (36), /* _xcoff_glink_size */
3558 0, /* _xcoff_rtinit_size */
3559 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
3563 /* The transfer vector that leads the outside world to all of the above. */
3564 const bfd_target pmac_xcoff_vec
=
3567 bfd_target_xcoff_flavour
,
3568 BFD_ENDIAN_BIG
, /* data byte order is big */
3569 BFD_ENDIAN_BIG
, /* header byte order is big */
3571 (HAS_RELOC
| EXEC_P
| /* object flags */
3572 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3573 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3575 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3576 0, /* leading char */
3577 '/', /* ar_pad_char */
3578 15, /* ar_max_namelen??? FIXMEmgo */
3581 bfd_getb64
, /* bfd_getx64 */
3582 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3583 bfd_putb64
, /* bfd_putx64 */
3584 bfd_getb32
, /* bfd_getx32 */
3585 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3586 bfd_putb32
, /* bfd_putx32 */
3587 bfd_getb16
, /* bfd_getx16 */
3588 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3589 bfd_putb16
, /* bfd_putx16 */
3592 bfd_getb64
, /* bfd_h_getx64 */
3593 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3594 bfd_putb64
, /* bfd_h_putx64 */
3595 bfd_getb32
, /* bfd_h_getx32 */
3596 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3597 bfd_putb32
, /* bfd_h_putx32 */
3598 bfd_getb16
, /* bfd_h_getx16 */
3599 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3600 bfd_putb16
, /* bfd_h_putx16 */
3602 { /* bfd_check_format */
3605 _bfd_xcoff_archive_p
,
3609 { /* bfd_set_format */
3612 _bfd_generic_mkarchive
,
3616 {/* bfd_write_contents */
3618 coff_write_object_contents
,
3619 _bfd_xcoff_write_archive_contents
,
3624 bfd_true
, /* _close_and_cleanup */
3625 bfd_true
, /* _bfd_free_cached_info */
3626 coff_new_section_hook
, /* _new_section_hook */
3627 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3628 /* _bfd_get_section_contents_in_window */
3629 _bfd_generic_get_section_contents_in_window
,
3632 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3633 /* _bfd_merge_private_bfd_data */
3634 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3635 /* _bfd_copy_pivate_section_data */
3636 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3637 /* _bfd_copy_private_symbol_data */
3638 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3639 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3640 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3643 coff_core_file_failing_command
, /* _core_file_failing_command */
3644 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3645 /* _core_file_matches_executable_p */
3646 coff_core_file_matches_executable_p
,
3649 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3650 /* XCOFF archives do not have
3651 anything which corresponds to
3652 an extended name table. */
3653 bfd_false
, /* _slurp_extended_name_table */
3654 /* _construct_extended_name_table */
3655 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3656 bfd_dont_truncate_arname
, /* _truncate_arname */
3657 _bfd_xcoff_write_armap
, /* _write_armap */
3658 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3659 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3660 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3661 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3662 /* XCOFF archives do not have
3664 bfd_true
, /* _update_armap_timestamp */
3667 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3668 coff_get_symtab
, /* _get_symtab */
3669 coff_make_empty_symbol
, /* _make_empty_symbol */
3670 coff_print_symbol
, /* _print_symbol */
3671 coff_get_symbol_info
, /* _get_symbol_info */
3672 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3673 coff_get_lineno
, /* _get_lineno */
3674 coff_find_nearest_line
, /* _find_nearest_line */
3675 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3676 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3677 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3680 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3681 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3682 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3685 coff_set_arch_mach
, /* _set_arch_mach */
3686 coff_set_section_contents
, /* _set_section_contents */
3689 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3690 /* _bfd_get_relocated_section_contents */
3691 bfd_generic_get_relocated_section_contents
,
3692 bfd_generic_relax_section
, /* _bfd_relax_section */
3693 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3694 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3695 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3696 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3697 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3698 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3701 /* _get_dynamic_symtab_upper_bound */
3702 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3703 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3704 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3705 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3707 /* Opposite endian version, none exists */
3711 (void *) &bfd_pmac_xcoff_backend_data
,