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
PARAMS ((bfd
*abfd
));
85 extern boolean rs6000coff_core_file_matches_executable_p
86 PARAMS ((bfd
*cbfd
, bfd
*ebfd
));
87 extern char *rs6000coff_core_file_failing_command
PARAMS ((bfd
*abfd
));
88 extern int rs6000coff_core_file_failing_signal
PARAMS ((bfd
*abfd
));
89 #define CORE_FILE_P rs6000coff_core_p
90 #define coff_core_file_failing_command \
91 rs6000coff_core_file_failing_command
92 #define coff_core_file_failing_signal \
93 rs6000coff_core_file_failing_signal
94 #define coff_core_file_matches_executable_p \
95 rs6000coff_core_file_matches_executable_p
97 #define CORE_FILE_P _bfd_dummy_target
98 #define coff_core_file_failing_command \
99 _bfd_nocore_core_file_failing_command
100 #define coff_core_file_failing_signal \
101 _bfd_nocore_core_file_failing_signal
102 #define coff_core_file_matches_executable_p \
103 _bfd_nocore_core_file_matches_executable_p
105 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
106 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
107 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
108 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
110 #include "coffcode.h"
112 /* The main body of code is in coffcode.h. */
114 static const char *normalize_filename
PARAMS ((bfd
*));
115 static boolean xcoff_write_armap_old
116 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
117 static boolean xcoff_write_armap_big
118 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
119 static boolean xcoff_write_archive_contents_old
PARAMS ((bfd
*));
120 static boolean xcoff_write_archive_contents_big
PARAMS ((bfd
*));
121 static void xcoff_swap_ldhdr_in
122 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
123 static void xcoff_swap_ldhdr_out
124 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
125 static void xcoff_swap_ldsym_in
126 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
127 static void xcoff_swap_ldsym_out
128 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
129 static void xcoff_swap_ldrel_in
130 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
131 static void xcoff_swap_ldrel_out
132 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
133 static boolean xcoff_ppc_relocate_section
134 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
135 struct internal_reloc
*, struct internal_syment
*, asection
**));
136 static boolean _bfd_xcoff_put_ldsymbol_name
137 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
139 static asection
*xcoff_create_csect_from_smclas
140 PARAMS ((bfd
*, union internal_auxent
*, const char *));
141 static boolean xcoff_is_lineno_count_overflow
PARAMS ((bfd
*, bfd_vma
));
142 static boolean xcoff_is_reloc_count_overflow
PARAMS ((bfd
*, bfd_vma
));
143 static bfd_vma xcoff_loader_symbol_offset
144 PARAMS ((bfd
*, struct internal_ldhdr
*));
145 static bfd_vma xcoff_loader_reloc_offset
146 PARAMS ((bfd
*, struct internal_ldhdr
*));
147 static boolean xcoff_generate_rtinit
148 PARAMS((bfd
*, const char *, const char *, boolean
));
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 */
860 HOWTO (0x1c, /* type */
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 */
874 /* 16 bit Non modifiable absolute branch. */
875 HOWTO (0x1d, /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 false, /* pc_relative */
881 complain_overflow_bitfield
, /* complain_on_overflow */
882 0, /* special_function */
884 true, /* partial_inplace */
885 0xfffc, /* src_mask */
886 0xfffc, /* dst_mask */
887 false), /* pcrel_offset */
891 _bfd_xcoff_rtype2howto (relent
, internal
)
893 struct internal_reloc
*internal
;
895 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
897 /* Check for relocs we don't know of. */
899 >= sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]))
901 if (internal
->r_type
!= relent
->howto
->type
)
904 /* The r_size field of an XCOFF reloc encodes the bitsize of the
905 relocation, as well as indicating whether it is signed or not.
906 Doublecheck that the relocation information gathered from the
907 type matches this information. The bitsize is not significant
909 if (relent
->howto
->dst_mask
!= 0
910 && (relent
->howto
->bitsize
911 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
914 if ((internal
->r_size
& 0x80) != 0
915 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
916 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
922 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
923 bfd
*abfd ATTRIBUTE_UNUSED
;
924 bfd_reloc_code_real_type code
;
928 case BFD_RELOC_PPC_B26
:
929 return &xcoff_howto_table
[0xa];
930 case BFD_RELOC_PPC_BA16
:
931 return &xcoff_howto_table
[0x1d];
932 case BFD_RELOC_PPC_BA26
:
933 return &xcoff_howto_table
[8];
934 case BFD_RELOC_PPC_TOC16
:
935 return &xcoff_howto_table
[3];
938 return &xcoff_howto_table
[0];
940 return &xcoff_howto_table
[0x1c];
947 /* XCOFF archive support. The original version of this code was by
948 Damon A. Permezel. It was enhanced to permit cross support, and
949 writing archive files, by Ian Lance Taylor, Cygnus Support.
951 XCOFF uses its own archive format. Everything is hooked together
952 with file offset links, so it is possible to rapidly update an
953 archive in place. Of course, we don't do that. An XCOFF archive
954 has a real file header, not just an ARMAG string. The structure of
955 the file header and of each archive header appear below.
957 An XCOFF archive also has a member table, which is a list of
958 elements in the archive (you can get that by looking through the
959 linked list, but you have to read a lot more of the file). The
960 member table has a normal archive header with an empty name. It is
961 normally (and perhaps must be) the second to last entry in the
962 archive. The member table data is almost printable ASCII. It
963 starts with a 12 character decimal string which is the number of
964 entries in the table. For each entry it has a 12 character decimal
965 string which is the offset in the archive of that member. These
966 entries are followed by a series of null terminated strings which
967 are the member names for each entry.
969 Finally, an XCOFF archive has a global symbol table, which is what
970 we call the armap. The global symbol table has a normal archive
971 header with an empty name. It is normally (and perhaps must be)
972 the last entry in the archive. The contents start with a four byte
973 binary number which is the number of entries. This is followed by
974 a that many four byte binary numbers; each is the file offset of an
975 entry in the archive. These numbers are followed by a series of
976 null terminated strings, which are symbol names.
978 AIX 4.3 introduced a new archive format which can handle larger
979 files and also 32- and 64-bit objects in the same archive. The
980 things said above remain true except that there is now more than
981 one global symbol table. The one is used to index 32-bit objects,
982 the other for 64-bit objects.
984 The new archives (recognizable by the new ARMAG string) has larger
985 field lengths so that we cannot really share any code. Also we have
986 to take care that we are not generating the new form of archives
987 on AIX 4.2 or earlier systems. */
989 /* XCOFF archives use this as a magic string. Note that both strings
990 have the same length. */
994 /* Read in the armap of an XCOFF archive. */
997 _bfd_xcoff_slurp_armap (abfd
)
1003 bfd_byte
*contents
, *cend
;
1008 if (xcoff_ardata (abfd
) == NULL
)
1010 bfd_has_map (abfd
) = false;
1014 if (! xcoff_big_format_p (abfd
))
1016 /* This is for the old format. */
1017 struct xcoff_ar_hdr hdr
;
1019 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1022 bfd_has_map (abfd
) = false;
1026 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1029 /* The symbol table starts with a normal archive header. */
1030 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1034 /* Skip the name (normally empty). */
1035 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1036 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1037 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1040 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1042 /* Read in the entire symbol table. */
1043 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1044 if (contents
== NULL
)
1046 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1049 /* The symbol table starts with a four byte count. */
1050 c
= H_GET_32 (abfd
, contents
);
1054 bfd_set_error (bfd_error_bad_value
);
1058 bfd_ardata (abfd
)->symdefs
=
1059 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1060 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1063 /* After the count comes a list of four byte file offsets. */
1064 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1066 ++i
, ++arsym
, p
+= 4)
1067 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1071 /* This is for the new format. */
1072 struct xcoff_ar_hdr_big hdr
;
1074 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1077 bfd_has_map (abfd
) = false;
1081 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1084 /* The symbol table starts with a normal archive header. */
1085 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1086 != SIZEOF_AR_HDR_BIG
)
1089 /* Skip the name (normally empty). */
1090 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1091 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1092 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1095 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1096 machines) since the field width is 20 and there numbers with more
1097 than 32 bits can be represented. */
1098 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1100 /* Read in the entire symbol table. */
1101 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1102 if (contents
== NULL
)
1104 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1107 /* The symbol table starts with an eight byte count. */
1108 c
= H_GET_64 (abfd
, contents
);
1112 bfd_set_error (bfd_error_bad_value
);
1116 bfd_ardata (abfd
)->symdefs
=
1117 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1118 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1121 /* After the count comes a list of eight byte file offsets. */
1122 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1124 ++i
, ++arsym
, p
+= 8)
1125 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1128 /* After the file offsets come null terminated symbol names. */
1129 cend
= contents
+ sz
;
1130 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1132 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1136 bfd_set_error (bfd_error_bad_value
);
1139 arsym
->name
= (char *) p
;
1142 bfd_ardata (abfd
)->symdef_count
= c
;
1143 bfd_has_map (abfd
) = true;
1148 /* See if this is an XCOFF archive. */
1151 _bfd_xcoff_archive_p (abfd
)
1154 char magic
[SXCOFFARMAG
];
1157 if (bfd_bread ((PTR
) magic
, (bfd_size_type
) SXCOFFARMAG
, abfd
) != SXCOFFARMAG
)
1159 if (bfd_get_error () != bfd_error_system_call
)
1160 bfd_set_error (bfd_error_wrong_format
);
1164 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1165 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1167 bfd_set_error (bfd_error_wrong_format
);
1171 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1172 involves a cast, we can't do it as the left operand of
1174 amt
= sizeof (struct artdata
);
1175 abfd
->tdata
.aout_ar_data
= (struct artdata
*) bfd_zalloc (abfd
, amt
);
1176 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1179 bfd_ardata (abfd
)->cache
= NULL
;
1180 bfd_ardata (abfd
)->archive_head
= NULL
;
1181 bfd_ardata (abfd
)->symdefs
= NULL
;
1182 bfd_ardata (abfd
)->extended_names
= NULL
;
1184 /* Now handle the two formats. */
1185 if (magic
[1] != 'b')
1187 /* This is the old format. */
1188 struct xcoff_ar_file_hdr hdr
;
1190 /* Copy over the magic string. */
1191 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1193 /* Now read the rest of the file header. */
1194 if (bfd_bread ((PTR
) &hdr
.memoff
,
1195 (bfd_size_type
) SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, abfd
)
1196 != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1198 if (bfd_get_error () != bfd_error_system_call
)
1199 bfd_set_error (bfd_error_wrong_format
);
1203 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1204 (char **) NULL
, 10);
1206 amt
= SIZEOF_AR_FILE_HDR
;
1207 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1208 if (bfd_ardata (abfd
)->tdata
== NULL
)
1211 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1215 /* This is the new format. */
1216 struct xcoff_ar_file_hdr_big hdr
;
1218 /* Copy over the magic string. */
1219 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1221 /* Now read the rest of the file header. */
1222 if (bfd_bread ((PTR
) &hdr
.memoff
,
1223 (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, abfd
)
1224 != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1226 if (bfd_get_error () != bfd_error_system_call
)
1227 bfd_set_error (bfd_error_wrong_format
);
1231 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1232 machines) since the field width is 20 and there numbers with more
1233 than 32 bits can be represented. */
1234 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1235 (char **) NULL
, 10);
1237 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1238 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1239 if (bfd_ardata (abfd
)->tdata
== NULL
)
1242 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1245 if (! _bfd_xcoff_slurp_armap (abfd
))
1247 bfd_release (abfd
, bfd_ardata (abfd
));
1248 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1255 /* Read the archive header in an XCOFF archive. */
1258 _bfd_xcoff_read_ar_hdr (abfd
)
1261 bfd_size_type namlen
;
1262 struct areltdata
*ret
;
1263 bfd_size_type amt
= sizeof (struct areltdata
);
1265 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1269 if (! xcoff_big_format_p (abfd
))
1271 struct xcoff_ar_hdr hdr
;
1272 struct xcoff_ar_hdr
*hdrp
;
1274 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1281 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1282 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1283 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1289 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1290 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1295 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1297 ret
->arch_header
= (char *) hdrp
;
1298 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1299 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1303 struct xcoff_ar_hdr_big hdr
;
1304 struct xcoff_ar_hdr_big
*hdrp
;
1306 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1307 != SIZEOF_AR_HDR_BIG
)
1313 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1314 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1315 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1321 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1322 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1327 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1329 ret
->arch_header
= (char *) hdrp
;
1330 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1331 machines) since the field width is 20 and there numbers with more
1332 than 32 bits can be represented. */
1333 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1334 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1337 /* Skip over the XCOFFARFMAG at the end of the file name. */
1338 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1344 /* Open the next element in an XCOFF archive. */
1347 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1353 if (xcoff_ardata (archive
) == NULL
)
1355 bfd_set_error (bfd_error_invalid_operation
);
1359 if (! xcoff_big_format_p (archive
))
1361 if (last_file
== NULL
)
1362 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1364 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1368 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1370 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1371 (char **) NULL
, 10))
1373 bfd_set_error (bfd_error_no_more_archived_files
);
1379 if (last_file
== NULL
)
1380 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1382 /* XXX These actually have to be a calls to strtoll (at least
1383 on 32-bit machines) since the fields's width is 20 and
1384 there numbers with more than 32 bits can be represented. */
1385 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1388 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1389 machines) since the fields's width is 20 and there numbers with more
1390 than 32 bits can be represented. */
1392 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1394 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1395 (char **) NULL
, 10))
1397 bfd_set_error (bfd_error_no_more_archived_files
);
1402 return _bfd_get_elt_at_filepos (archive
, filestart
);
1405 /* Stat an element in an XCOFF archive. */
1408 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1412 if (abfd
->arelt_data
== NULL
)
1414 bfd_set_error (bfd_error_invalid_operation
);
1418 if (! xcoff_big_format_p (abfd
))
1420 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1422 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1423 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1424 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1425 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1426 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1430 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1432 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1433 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1434 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1435 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1436 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1442 /* Normalize a file name for inclusion in an archive. */
1445 normalize_filename (abfd
)
1449 const char *filename
;
1451 file
= bfd_get_filename (abfd
);
1452 filename
= strrchr (file
, '/');
1453 if (filename
!= NULL
)
1460 /* Write out an XCOFF armap. */
1464 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1466 unsigned int elength ATTRIBUTE_UNUSED
;
1468 unsigned int orl_count
;
1471 struct xcoff_ar_hdr hdr
;
1473 unsigned char buf
[4];
1478 memset (&hdr
, 0, sizeof hdr
);
1479 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1480 sprintf (hdr
.nextoff
, "%d", 0);
1481 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1482 sprintf (hdr
.date
, "%d", 0);
1483 sprintf (hdr
.uid
, "%d", 0);
1484 sprintf (hdr
.gid
, "%d", 0);
1485 sprintf (hdr
.mode
, "%d", 0);
1486 sprintf (hdr
.namlen
, "%d", 0);
1488 /* We need spaces, not null bytes, in the header. */
1489 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1493 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1495 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1499 H_PUT_32 (abfd
, orl_count
, buf
);
1500 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1503 sub
= abfd
->archive_head
;
1504 fileoff
= SIZEOF_AR_FILE_HDR
;
1506 while (sub
!= NULL
&& i
< orl_count
)
1510 while (map
[i
].u
.abfd
== sub
)
1512 H_PUT_32 (abfd
, fileoff
, buf
);
1513 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1517 namlen
= strlen (normalize_filename (sub
));
1518 namlen
= (namlen
+ 1) &~ (size_t) 1;
1519 fileoff
+= (SIZEOF_AR_HDR
1522 + arelt_size (sub
));
1523 fileoff
= (fileoff
+ 1) &~ 1;
1527 for (i
= 0; i
< orl_count
; i
++)
1532 name
= *map
[i
].name
;
1533 namlen
= strlen (name
);
1534 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1538 if ((stridx
& 1) != 0)
1543 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1550 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1551 #define FMT20 "%-20lld"
1552 #define FMT12 "%-12d"
1553 #define FMT12_OCTAL "%-12o"
1555 #define PRINT20(d, v) \
1556 sprintf (buff20, FMT20, (long long)(v)), \
1557 memcpy ((void *) (d), buff20, 20)
1559 #define PRINT12(d, v) \
1560 sprintf (buff20, FMT12, (int)(v)), \
1561 memcpy ((void *) (d), buff20, 12)
1563 #define PRINT12_OCTAL(d, v) \
1564 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1565 memcpy ((void *) (d), buff20, 12)
1567 #define PRINT4(d, v) \
1568 sprintf (buff20, FMT4, (int)(v)), \
1569 memcpy ((void *) (d), buff20, 4)
1571 #define READ20(d, v) \
1573 memcpy (buff20, (d), 20), \
1574 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1577 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1579 unsigned int elength ATTRIBUTE_UNUSED
;
1581 unsigned int orl_count
;
1584 struct xcoff_ar_file_hdr_big
*fhdr
;
1585 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1586 const bfd_arch_info_type
*arch_info
= NULL
;
1588 size_t string_length
;
1589 ufile_ptr nextoff
, prevoff
;
1591 /* First, we look through the symbols and work out which are
1592 from 32-bit objects and which from 64-bit ones. */
1593 sym_32
= sym_64
= str_32
= str_64
= 0;
1595 current_bfd
= abfd
->archive_head
;
1596 if (current_bfd
!= NULL
)
1597 arch_info
= bfd_get_arch_info (current_bfd
);
1599 while (current_bfd
!= NULL
&& i
< orl_count
)
1601 while (map
[i
].u
.abfd
== current_bfd
)
1603 string_length
= strlen (*map
[i
].name
) + 1;
1605 if (arch_info
->bits_per_address
== 64)
1608 str_64
+= string_length
;
1613 str_32
+= string_length
;
1617 current_bfd
= current_bfd
->next
;
1618 if (current_bfd
!= NULL
)
1619 arch_info
= bfd_get_arch_info (current_bfd
);
1622 /* A quick sanity check... */
1623 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1624 /* Explicit cast to int for compiler. */
1625 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1627 fhdr
= xcoff_ardata_big (abfd
);
1629 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1630 READ20 (fhdr
->memoff
, prevoff
);
1631 READ20 (fhdr
->symoff
, nextoff
);
1633 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1635 /* Write out the symbol table.
1638 standard big archive header
1639 0x0000 ar_size [0x14]
1640 0x0014 ar_nxtmem [0x14]
1641 0x0028 ar_prvmem [0x14]
1642 0x003C ar_date [0x0C]
1643 0x0048 ar_uid [0x0C]
1644 0x0054 ar_gid [0x0C]
1645 0x0060 ar_mod [0x0C]
1646 0x006C ar_namelen[0x04]
1647 0x0070 ar_fmag [SXCOFFARFMAG]
1650 0x0072 num_syms [0x08], binary
1651 0x0078 offsets [0x08 * num_syms], binary
1652 0x0086 + 0x08 * num_syms names [??]
1653 ?? pad to even bytes.
1658 struct xcoff_ar_hdr_big
*hdr
;
1659 bfd_byte
*symbol_table
;
1663 bfd_vma symbol_table_size
=
1668 + str_32
+ (str_32
& 1);
1670 symbol_table
= NULL
;
1671 symbol_table
= (bfd_byte
*) bfd_malloc (symbol_table_size
);
1672 if (symbol_table
== NULL
)
1674 memset (symbol_table
, 0, symbol_table_size
);
1676 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1678 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1681 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1683 PRINT20 (hdr
->nextoff
, 0);
1685 PRINT20 (hdr
->prevoff
, prevoff
);
1686 PRINT12 (hdr
->date
, 0);
1687 PRINT12 (hdr
->uid
, 0);
1688 PRINT12 (hdr
->gid
, 0);
1689 PRINT12 (hdr
->mode
, 0);
1690 PRINT4 (hdr
->namlen
, 0) ;
1692 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1693 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1696 bfd_h_put_64 (abfd
, sym_32
, st
);
1699 /* loop over the 32 bit offsets */
1700 current_bfd
= abfd
->archive_head
;
1701 if (current_bfd
!= NULL
)
1702 arch_info
= bfd_get_arch_info (current_bfd
);
1703 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1705 while (current_bfd
!= NULL
&& i
< orl_count
)
1707 while (map
[i
].u
.abfd
== current_bfd
)
1709 if (arch_info
->bits_per_address
== 32)
1711 bfd_h_put_64 (abfd
, fileoff
, st
);
1716 string_length
= strlen (normalize_filename (current_bfd
));
1717 string_length
+= string_length
& 1;
1718 fileoff
+= (SIZEOF_AR_HDR_BIG
1721 + arelt_size (current_bfd
));
1722 fileoff
+= fileoff
& 1;
1723 current_bfd
= current_bfd
->next
;
1724 if (current_bfd
!= NULL
)
1725 arch_info
= bfd_get_arch_info (current_bfd
);
1728 /* loop over the 32 bit symbol names */
1729 current_bfd
= abfd
->archive_head
;
1730 if (current_bfd
!= NULL
)
1731 arch_info
= bfd_get_arch_info (current_bfd
);
1733 while (current_bfd
!= NULL
&& i
< orl_count
)
1735 while (map
[i
].u
.abfd
== current_bfd
)
1737 if (arch_info
->bits_per_address
== 32)
1739 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1740 st
+= string_length
+ 1;
1744 current_bfd
= current_bfd
->next
;
1745 if (current_bfd
!= NULL
)
1746 arch_info
= bfd_get_arch_info (current_bfd
);
1749 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1751 free (symbol_table
);
1752 symbol_table
= NULL
;
1755 nextoff
= nextoff
+ symbol_table_size
;
1758 PRINT20 (fhdr
->symoff
, 0);
1762 struct xcoff_ar_hdr_big
*hdr
;
1763 bfd_byte
*symbol_table
;
1767 bfd_vma symbol_table_size
=
1772 + str_64
+ (str_64
& 1);
1774 symbol_table
= NULL
;
1775 symbol_table
= (bfd_byte
*) bfd_malloc (symbol_table_size
);
1776 if (symbol_table
== NULL
)
1778 memset (symbol_table
, 0, symbol_table_size
);
1780 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1782 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1783 PRINT20 (hdr
->nextoff
, 0);
1784 PRINT20 (hdr
->prevoff
, prevoff
);
1785 PRINT12 (hdr
->date
, 0);
1786 PRINT12 (hdr
->uid
, 0);
1787 PRINT12 (hdr
->gid
, 0);
1788 PRINT12 (hdr
->mode
, 0);
1789 PRINT4 (hdr
->namlen
, 0);
1791 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1792 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1795 bfd_h_put_64 (abfd
, sym_64
, st
);
1798 /* loop over the 64 bit offsets */
1799 current_bfd
= abfd
->archive_head
;
1800 if (current_bfd
!= NULL
)
1801 arch_info
= bfd_get_arch_info (current_bfd
);
1802 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1804 while (current_bfd
!= NULL
&& i
< orl_count
)
1806 while (map
[i
].u
.abfd
== current_bfd
)
1808 if (arch_info
->bits_per_address
== 64)
1810 bfd_h_put_64 (abfd
, fileoff
, st
);
1815 string_length
= strlen (normalize_filename (current_bfd
));
1816 string_length
+= string_length
& 1;
1817 fileoff
+= (SIZEOF_AR_HDR_BIG
1820 + arelt_size (current_bfd
));
1821 fileoff
+= fileoff
& 1;
1822 current_bfd
= current_bfd
->next
;
1823 if (current_bfd
!= NULL
)
1824 arch_info
= bfd_get_arch_info (current_bfd
);
1827 /* loop over the 64 bit symbol names */
1828 current_bfd
= abfd
->archive_head
;
1829 if (current_bfd
!= NULL
)
1830 arch_info
= bfd_get_arch_info (current_bfd
);
1832 while (current_bfd
!= NULL
&& i
< orl_count
)
1834 while (map
[i
].u
.abfd
== current_bfd
)
1836 if (arch_info
->bits_per_address
== 64)
1838 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1839 st
+= string_length
+ 1;
1843 current_bfd
= current_bfd
->next
;
1844 if (current_bfd
!= NULL
)
1845 arch_info
= bfd_get_arch_info (current_bfd
);
1848 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1850 free (symbol_table
);
1851 symbol_table
= NULL
;
1853 PRINT20 (fhdr
->symoff64
, nextoff
);
1856 PRINT20 (fhdr
->symoff64
, 0);
1862 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1864 unsigned int elength ATTRIBUTE_UNUSED
;
1866 unsigned int orl_count
;
1869 if (! xcoff_big_format_p (abfd
))
1870 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1872 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1875 /* Write out an XCOFF archive. We always write an entire archive,
1876 rather than fussing with the freelist and so forth. */
1879 xcoff_write_archive_contents_old (abfd
)
1882 struct xcoff_ar_file_hdr fhdr
;
1883 bfd_size_type count
;
1884 bfd_size_type total_namlen
;
1888 ufile_ptr prevoff
, nextoff
;
1891 struct xcoff_ar_hdr ahdr
;
1894 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
1896 memset (&fhdr
, 0, sizeof fhdr
);
1897 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1898 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1899 sprintf (fhdr
.freeoff
, "%d", 0);
1903 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1906 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1908 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1909 if (offsets
== NULL
)
1912 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1915 makemap
= bfd_has_map (abfd
);
1918 nextoff
= SIZEOF_AR_FILE_HDR
;
1919 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1922 bfd_size_type namlen
;
1923 struct xcoff_ar_hdr
*ahdrp
;
1924 bfd_size_type remaining
;
1926 if (makemap
&& ! hasobjects
)
1928 if (bfd_check_format (sub
, bfd_object
))
1932 name
= normalize_filename (sub
);
1933 namlen
= strlen (name
);
1935 if (sub
->arelt_data
!= NULL
)
1936 ahdrp
= arch_xhdr (sub
);
1944 memset (&ahdr
, 0, sizeof ahdr
);
1946 if (stat (bfd_get_filename (sub
), &s
) != 0)
1948 bfd_set_error (bfd_error_system_call
);
1952 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1953 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1954 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1955 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1956 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1958 if (sub
->arelt_data
== NULL
)
1960 size
= sizeof (struct areltdata
);
1961 sub
->arelt_data
= bfd_alloc (sub
, size
);
1962 if (sub
->arelt_data
== NULL
)
1966 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1969 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1970 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1972 /* If the length of the name is odd, we write out the null byte
1973 after the name as well. */
1974 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
1976 remaining
= arelt_size (sub
);
1977 size
= (SIZEOF_AR_HDR
1982 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1984 offsets
[i
] = nextoff
;
1987 nextoff
+= size
+ (size
& 1);
1989 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1991 /* We need spaces, not null bytes, in the header. */
1992 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1996 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1998 || (bfd_bwrite ((PTR
) name
, namlen
, abfd
) != namlen
)
1999 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2003 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2005 while (remaining
!= 0)
2008 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2010 amt
= sizeof buffer
;
2011 if (amt
> remaining
)
2013 if (bfd_bread (buffer
, amt
, sub
) != amt
2014 || bfd_bwrite (buffer
, amt
, abfd
) != amt
)
2019 if ((size
& 1) != 0)
2024 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
2029 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2031 /* Write out the member table. */
2033 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2034 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2036 memset (&ahdr
, 0, sizeof ahdr
);
2037 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
+
2038 count
* XCOFFARMAG_ELEMENT_SIZE
+
2040 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2041 sprintf (ahdr
.date
, "%d", 0);
2042 sprintf (ahdr
.uid
, "%d", 0);
2043 sprintf (ahdr
.gid
, "%d", 0);
2044 sprintf (ahdr
.mode
, "%d", 0);
2045 sprintf (ahdr
.namlen
, "%d", 0);
2047 size
= (SIZEOF_AR_HDR
2048 + XCOFFARMAG_ELEMENT_SIZE
2049 + count
* XCOFFARMAG_ELEMENT_SIZE
2054 nextoff
+= size
+ (size
& 1);
2056 if (makemap
&& hasobjects
)
2057 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2059 sprintf (ahdr
.nextoff
, "%d", 0);
2061 /* We need spaces, not null bytes, in the header. */
2062 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2066 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2068 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2072 sprintf (decbuf
, "%-12ld", (long) count
);
2073 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2074 != XCOFFARMAG_ELEMENT_SIZE
)
2076 for (i
= 0; i
< (size_t) count
; i
++)
2078 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2079 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2080 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2083 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2086 bfd_size_type namlen
;
2088 name
= normalize_filename (sub
);
2089 namlen
= strlen (name
);
2090 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2093 if ((size
& 1) != 0)
2098 if (bfd_bwrite ((PTR
) &b
, (bfd_size_type
) 1, abfd
) != 1)
2102 /* Write out the armap, if appropriate. */
2103 if (! makemap
|| ! hasobjects
)
2104 sprintf (fhdr
.symoff
, "%d", 0);
2107 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2108 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2109 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2110 if (! _bfd_compute_and_write_armap (abfd
, 0))
2114 /* Write out the archive file header. */
2116 /* We need spaces, not null bytes, in the header. */
2117 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2121 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2122 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2123 != SIZEOF_AR_FILE_HDR
))
2130 xcoff_write_archive_contents_big (abfd
)
2133 struct xcoff_ar_file_hdr_big fhdr
;
2134 bfd_size_type count
;
2135 bfd_size_type total_namlen
;
2139 ufile_ptr prevoff
, nextoff
;
2142 struct xcoff_ar_hdr_big
*hdr
, ahdr
;
2144 bfd_byte
*member_table
, *mt
;
2145 bfd_vma member_table_size
;
2147 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2148 PRINT20 (fhdr
.firstmemoff
, SIZEOF_AR_FILE_HDR_BIG
);
2149 PRINT20 (fhdr
.freeoff
, 0);
2151 /* Calculate count and total_namlen */
2152 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2153 current_bfd
!= NULL
;
2154 current_bfd
= current_bfd
->next
, count
++)
2155 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2160 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2161 if (offsets
== NULL
)
2164 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2167 makemap
= bfd_has_map (abfd
);
2170 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2171 for (current_bfd
= abfd
->archive_head
, i
= 0;
2172 current_bfd
!= NULL
;
2173 current_bfd
= current_bfd
->next
, i
++)
2176 bfd_size_type namlen
;
2177 struct xcoff_ar_hdr_big
*ahdrp
;
2178 bfd_size_type remaining
;
2180 if (makemap
&& ! hasobjects
)
2182 if (bfd_check_format (current_bfd
, bfd_object
))
2186 name
= normalize_filename (current_bfd
);
2187 namlen
= strlen (name
);
2189 if (current_bfd
->arelt_data
!= NULL
)
2190 ahdrp
= arch_xhdr_big (current_bfd
);
2199 /* XXX This should actually be a call to stat64 (at least on
2201 XXX This call will fail if the original object is not found. */
2202 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2204 bfd_set_error (bfd_error_system_call
);
2208 PRINT20 (ahdrp
->size
, s
.st_size
);
2209 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2210 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2211 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2212 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2214 if (current_bfd
->arelt_data
== NULL
)
2216 size
= sizeof (struct areltdata
);
2217 current_bfd
->arelt_data
= bfd_alloc (current_bfd
, size
);
2218 if (current_bfd
->arelt_data
== NULL
)
2222 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2225 PRINT20 (ahdrp
->prevoff
, prevoff
);
2226 PRINT4 (ahdrp
->namlen
, namlen
);
2228 /* If the length of the name is odd, we write out the null byte
2229 after the name as well. */
2230 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2232 remaining
= arelt_size (current_bfd
);
2233 size
= (SIZEOF_AR_HDR_BIG
2238 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2240 offsets
[i
] = nextoff
;
2243 nextoff
+= size
+ (size
& 1);
2245 PRINT20 (ahdrp
->nextoff
, nextoff
);
2247 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
2248 != SIZEOF_AR_HDR_BIG
)
2249 || bfd_bwrite ((PTR
) name
, (bfd_size_type
) namlen
, abfd
) != namlen
2250 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
,
2251 abfd
) != SXCOFFARFMAG
))
2254 if (bfd_seek (current_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2256 while (remaining
!= 0)
2259 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2261 amt
= sizeof buffer
;
2262 if (amt
> remaining
)
2264 if (bfd_bread (buffer
, amt
, current_bfd
) != amt
2265 || bfd_bwrite (buffer
, amt
, abfd
) != amt
)
2270 if ((size
& 1) != 0)
2275 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
2280 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2282 /* Write out the member table.
2285 standard big archive header
2286 0x0000 ar_size [0x14]
2287 0x0014 ar_nxtmem [0x14]
2288 0x0028 ar_prvmem [0x14]
2289 0x003C ar_date [0x0C]
2290 0x0048 ar_uid [0x0C]
2291 0x0054 ar_gid [0x0C]
2292 0x0060 ar_mod [0x0C]
2293 0x006C ar_namelen[0x04]
2294 0x0070 ar_fmag [0x02]
2298 0x0086 offsets [0x14 * counts]
2299 0x0086 + 0x14 * counts names [??]
2300 ?? pad to even bytes.
2303 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2305 member_table_size
= (SIZEOF_AR_HDR_BIG
2307 + XCOFFARMAGBIG_ELEMENT_SIZE
2308 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2311 member_table_size
+= member_table_size
& 1;
2312 member_table
= NULL
;
2313 member_table
= (bfd_byte
*) bfd_malloc (member_table_size
);
2314 if (member_table
== NULL
)
2316 memset (member_table
, 0, member_table_size
);
2318 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2320 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
+
2321 count
* XCOFFARMAGBIG_ELEMENT_SIZE
+
2322 total_namlen
+ (total_namlen
& 1)));
2323 if (makemap
&& hasobjects
)
2324 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2326 PRINT20 (hdr
->nextoff
, 0);
2327 PRINT20 (hdr
->prevoff
, prevoff
);
2328 PRINT12 (hdr
->date
, 0);
2329 PRINT12 (hdr
->uid
, 0);
2330 PRINT12 (hdr
->gid
, 0);
2331 PRINT12 (hdr
->mode
, 0);
2332 PRINT4 (hdr
->namlen
, 0);
2334 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2335 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2338 PRINT20 (mt
, count
);
2339 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2340 for (i
= 0; i
< (size_t) count
; i
++)
2342 PRINT20 (mt
, offsets
[i
]);
2343 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2352 for (current_bfd
= abfd
->archive_head
; current_bfd
!= NULL
;
2353 current_bfd
= current_bfd
->next
)
2358 name
= normalize_filename (current_bfd
);
2359 namlen
= sprintf(mt
, "%s", name
);
2363 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2366 free (member_table
);
2367 member_table
= NULL
;
2369 PRINT20 (fhdr
.memoff
, nextoff
);
2372 nextoff
+= member_table_size
;
2374 /* Write out the armap, if appropriate. */
2376 if (! makemap
|| ! hasobjects
)
2377 PRINT20 (fhdr
.symoff
, 0);
2380 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2382 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2383 PRINT20 (fhdr
.symoff
, nextoff
);
2385 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2386 if (! _bfd_compute_and_write_armap (abfd
, 0))
2390 /* Write out the archive file header. */
2392 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2393 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2394 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2401 _bfd_xcoff_write_archive_contents (abfd
)
2404 if (! xcoff_big_format_p (abfd
))
2405 return xcoff_write_archive_contents_old (abfd
);
2407 return xcoff_write_archive_contents_big (abfd
);
2410 /* We can't use the usual coff_sizeof_headers routine, because AIX
2411 always uses an a.out header. */
2414 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2416 boolean reloc ATTRIBUTE_UNUSED
;
2421 if (xcoff_data (abfd
)->full_aouthdr
)
2424 size
+= SMALL_AOUTSZ
;
2425 size
+= abfd
->section_count
* SCNHSZ
;
2429 /* Routines to swap information in the XCOFF .loader section. If we
2430 ever need to write an XCOFF loader, this stuff will need to be
2431 moved to another file shared by the linker (which XCOFF calls the
2432 ``binder'') and the loader. */
2434 /* Swap in the ldhdr structure. */
2437 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2440 struct internal_ldhdr
*dst
;
2442 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2444 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2445 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2446 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2447 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2448 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2449 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2450 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2451 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2454 /* Swap out the ldhdr structure. */
2457 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2459 const struct internal_ldhdr
*src
;
2462 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2464 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2465 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2466 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2467 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2468 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2469 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2470 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2471 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2474 /* Swap in the ldsym structure. */
2477 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2480 struct internal_ldsym
*dst
;
2482 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2484 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2485 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2487 dst
->_l
._l_l
._l_zeroes
= 0;
2488 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2490 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2491 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2492 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2493 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2494 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2495 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2498 /* Swap out the ldsym structure. */
2501 xcoff_swap_ldsym_out (abfd
, src
, d
)
2503 const struct internal_ldsym
*src
;
2506 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2508 if (src
->_l
._l_l
._l_zeroes
!= 0)
2509 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2512 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2513 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2514 dst
->_l
._l_l
._l_offset
);
2516 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2517 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2518 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2519 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2520 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2521 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2524 /* Swap in the ldrel structure. */
2527 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2530 struct internal_ldrel
*dst
;
2532 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2534 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2535 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2536 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2537 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2540 /* Swap out the ldrel structure. */
2543 xcoff_swap_ldrel_out (abfd
, src
, d
)
2545 const struct internal_ldrel
*src
;
2548 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2550 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2551 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2552 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2553 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2558 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2559 This is currently the only processor which uses XCOFF; I hope that
2560 will never change. */
2563 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
2564 input_section
, contents
, relocs
, syms
,
2567 struct bfd_link_info
*info
;
2569 asection
*input_section
;
2571 struct internal_reloc
*relocs
;
2572 struct internal_syment
*syms
;
2573 asection
**sections
;
2575 struct internal_reloc
*rel
;
2576 struct internal_reloc
*relend
;
2579 relend
= rel
+ input_section
->reloc_count
;
2581 for (; rel
< relend
; rel
++)
2584 struct xcoff_link_hash_entry
*h
;
2585 struct internal_syment
*sym
;
2588 struct reloc_howto_struct howto
;
2589 bfd_reloc_status_type rstat
;
2591 /* Relocation type R_REF is a special relocation type which is
2592 merely used to prevent garbage collection from occurring for
2593 the csect including the symbol which it references. */
2594 if (rel
->r_type
== R_REF
)
2597 symndx
= rel
->r_symndx
;
2607 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
2608 sym
= syms
+ symndx
;
2609 addend
= - sym
->n_value
;
2613 /* We build the howto information on the fly. */
2615 howto
.type
= rel
->r_type
;
2616 howto
.rightshift
= 0;
2618 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
2619 howto
.pc_relative
= false;
2621 if ((rel
->r_size
& 0x80) != 0)
2622 howto
.complain_on_overflow
= complain_overflow_signed
;
2624 howto
.complain_on_overflow
= complain_overflow_bitfield
;
2625 howto
.special_function
= NULL
;
2626 howto
.name
= "internal";
2627 howto
.partial_inplace
= true;
2628 if (howto
.bitsize
== 32)
2629 howto
.src_mask
= howto
.dst_mask
= 0xffffffff;
2632 howto
.src_mask
= howto
.dst_mask
= (1 << howto
.bitsize
) - 1;
2633 if (howto
.bitsize
== 16)
2636 howto
.pcrel_offset
= false;
2646 sec
= bfd_abs_section_ptr
;
2651 sec
= sections
[symndx
];
2652 /* Hack to make sure we use the right TOC anchor value
2653 if this reloc is against the TOC anchor. */
2655 if (sec
->name
[3] == '0'
2656 && strcmp (sec
->name
, ".tc0") == 0)
2658 val
= xcoff_data (output_bfd
)->toc
;
2662 val
= (sec
->output_section
->vma
2663 + sec
->output_offset
2671 if (h
->root
.type
== bfd_link_hash_defined
2672 || h
->root
.type
== bfd_link_hash_defweak
)
2676 sec
= h
->root
.u
.def
.section
;
2677 val
= (h
->root
.u
.def
.value
2678 + sec
->output_section
->vma
2679 + sec
->output_offset
);
2681 else if (h
->root
.type
== bfd_link_hash_common
)
2685 sec
= h
->root
.u
.c
.p
->section
;
2686 val
= (sec
->output_section
->vma
2687 + sec
->output_offset
);
2689 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2690 || (h
->flags
& XCOFF_IMPORT
) != 0)
2692 /* Every symbol in a shared object is defined somewhere. */
2695 else if (! info
->relocateable
)
2697 if (! ((*info
->callbacks
->undefined_symbol
)
2698 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2699 rel
->r_vaddr
- input_section
->vma
, true)))
2702 /* Don't try to process the reloc. It can't help, and
2703 it may generate another error. */
2708 /* I took the relocation type definitions from two documents:
2709 the PowerPC AIX Version 4 Application Binary Interface, First
2710 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2711 32-Bit Hardware Implementation (June 30, 1994). Differences
2712 between the documents are noted below. */
2714 switch (rel
->r_type
)
2719 /* These relocs are defined by the PowerPC ABI to be
2720 relative branches which use half of the difference
2721 between the symbol and the program counter. I can't
2722 quite figure out when this is useful. These relocs are
2723 not defined by the PowerOpen ABI. */
2725 (*_bfd_error_handler
)
2726 (_("%s: unsupported relocation type 0x%02x"),
2727 bfd_archive_filename (input_bfd
), (unsigned int) rel
->r_type
);
2728 bfd_set_error (bfd_error_bad_value
);
2731 /* Simple positive relocation. */
2734 /* Simple negative relocation. */
2738 /* Simple PC relative relocation. */
2739 howto
.pc_relative
= true;
2742 /* TOC relative relocation. The value in the instruction in
2743 the input file is the offset from the input file TOC to
2744 the desired location. We want the offset from the final
2745 TOC to the desired location. We have:
2750 so we must change insn by on - in.
2753 /* Global linkage relocation. The value of this relocation
2754 is the address of the entry in the TOC section. */
2756 /* Local object TOC address. I can't figure out the
2757 difference between this and case R_GL. */
2759 /* TOC relative relocation. A TOC relative load instruction
2760 which may be changed to a load address instruction.
2761 FIXME: We don't currently implement this optimization. */
2763 /* TOC relative relocation. This is a TOC relative load
2764 address instruction which may be changed to a load
2765 instruction. FIXME: I don't know if this is the correct
2767 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2769 if (h
->toc_section
== NULL
)
2771 (*_bfd_error_handler
)
2772 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2773 bfd_archive_filename (input_bfd
), rel
->r_vaddr
,
2774 h
->root
.root
.string
);
2775 bfd_set_error (bfd_error_bad_value
);
2779 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2780 val
= (h
->toc_section
->output_section
->vma
2781 + h
->toc_section
->output_offset
);
2784 val
= ((val
- xcoff_data (output_bfd
)->toc
)
2785 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2789 /* Absolute branch. We don't want to mess with the lower
2790 two bits of the instruction. */
2792 /* The PowerPC ABI defines this as an absolute call which
2793 may be modified to become a relative call. The PowerOpen
2794 ABI does not define this relocation type. */
2796 /* Absolute branch which may be modified to become a
2799 /* The PowerPC ABI defines this as an absolute branch to a
2800 fixed address which may be modified to an absolute branch
2801 to a symbol. The PowerOpen ABI does not define this
2804 /* The PowerPC ABI defines this as an absolute branch to a
2805 fixed address which may be modified to a relative branch.
2806 The PowerOpen ABI does not define this relocation type. */
2807 howto
.src_mask
&= ~3;
2808 howto
.dst_mask
= howto
.src_mask
;
2811 /* Relative branch. We don't want to mess with the lower
2812 two bits of the instruction. */
2814 /* The PowerPC ABI defines this as a relative call which may
2815 be modified to become an absolute call. The PowerOpen
2816 ABI does not define this relocation type. */
2818 /* A relative branch which may be modified to become an
2819 absolute branch. FIXME: We don't implement this,
2820 although we should for symbols of storage mapping class
2822 howto
.pc_relative
= true;
2823 howto
.src_mask
&= ~3;
2824 howto
.dst_mask
= howto
.src_mask
;
2827 /* The PowerPC AIX ABI describes this as a load which may be
2828 changed to a load address. The PowerOpen ABI says this
2829 is the same as case R_POS. */
2832 /* The PowerPC AIX ABI describes this as a load address
2833 which may be changed to a load. The PowerOpen ABI says
2834 this is the same as R_POS. */
2838 /* If we see an R_BR or R_RBR reloc which is jumping to global
2839 linkage code, and it is followed by an appropriate cror nop
2840 instruction, we replace the cror with lwz r2,20(r1). This
2841 restores the TOC after the glink code. Contrariwise, if the
2842 call is followed by a lwz r2,20(r1), but the call is not
2843 going to global linkage code, we can replace the load with a
2845 if ((rel
->r_type
== R_BR
|| rel
->r_type
== R_RBR
)
2847 && h
->root
.type
== bfd_link_hash_defined
2848 && (rel
->r_vaddr
- input_section
->vma
+ 8
2849 <= input_section
->_cooked_size
))
2854 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
2855 next
= bfd_get_32 (input_bfd
, pnext
);
2857 /* The _ptrgl function is magic. It is used by the AIX
2858 compiler to call a function through a pointer. */
2859 if (h
->smclas
== XMC_GL
2860 || strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2862 if (next
== 0x4def7b82 /* cror 15,15,15 */
2863 || next
== 0x4ffffb82 /* cror 31,31,31 */
2864 || next
== 0x60000000) /* ori r0,r0,0 */
2865 bfd_put_32 (input_bfd
,
2866 (bfd_vma
) 0x80410014, /* lwz r1,20(r1) */
2871 if (next
== 0x80410014) /* lwz r1,20(r1) */
2872 bfd_put_32 (input_bfd
,
2873 (bfd_vma
) 0x60000000, /* ori r0,r0,0 */
2878 /* A PC relative reloc includes the section address. */
2879 if (howto
.pc_relative
)
2880 addend
+= input_section
->vma
;
2882 rstat
= _bfd_final_link_relocate (&howto
, input_bfd
, input_section
,
2884 rel
->r_vaddr
- input_section
->vma
,
2893 case bfd_reloc_overflow
:
2896 char buf
[SYMNMLEN
+ 1];
2897 char howto_name
[10];
2902 name
= h
->root
.root
.string
;
2905 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
2910 sprintf (howto_name
, "0x%02x", rel
->r_type
);
2912 if (! ((*info
->callbacks
->reloc_overflow
)
2913 (info
, name
, howto_name
, (bfd_vma
) 0, input_bfd
,
2914 input_section
, rel
->r_vaddr
- input_section
->vma
)))
2924 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
2925 bfd
*abfd ATTRIBUTE_UNUSED
;
2926 struct xcoff_loader_info
*ldinfo
;
2927 struct internal_ldsym
*ldsym
;
2931 len
= strlen (name
);
2933 if (len
<= SYMNMLEN
)
2934 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
2937 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
2939 bfd_size_type newalc
;
2940 bfd_byte
*newstrings
;
2942 newalc
= ldinfo
->string_alc
* 2;
2945 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
2948 newstrings
= ((bfd_byte
*)
2949 bfd_realloc ((PTR
) ldinfo
->strings
, newalc
));
2950 if (newstrings
== NULL
)
2952 ldinfo
->failed
= true;
2955 ldinfo
->string_alc
= newalc
;
2956 ldinfo
->strings
= newstrings
;
2959 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
2960 ldinfo
->strings
+ ldinfo
->string_size
);
2961 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
2962 ldsym
->_l
._l_l
._l_zeroes
= 0;
2963 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
2964 ldinfo
->string_size
+= len
+ 3;
2971 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
2972 struct internal_syment
*sym
,
2975 if (strlen (name
) <= SYMNMLEN
)
2977 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
2985 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
2987 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
2988 if (indx
== (bfd_size_type
) -1)
2990 sym
->_n
._n_n
._n_zeroes
= 0;
2991 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
2997 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
2999 union internal_auxent
*aux
;
3000 const char *symbol_name
;
3002 asection
*return_value
= NULL
;
3004 /* .sv64 = x_smclas == 17
3005 This is an invalid csect for 32 bit apps. */
3006 static const char *names
[19] =
3008 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3009 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3010 ".td", NULL
, ".sv3264"
3013 if ((19 >= aux
->x_csect
.x_smclas
) &&
3014 (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3016 return_value
= bfd_make_section_anyway
3017 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3021 (*_bfd_error_handler
)
3022 (_("%s: symbol `%s' has unrecognized smclas %d"),
3023 bfd_archive_filename (abfd
), symbol_name
, aux
->x_csect
.x_smclas
);
3024 bfd_set_error (bfd_error_bad_value
);
3027 return return_value
;
3031 xcoff_is_lineno_count_overflow (abfd
, value
)
3032 bfd
*abfd ATTRIBUTE_UNUSED
;
3035 if (0xffff <= value
)
3042 xcoff_is_reloc_count_overflow (abfd
, value
)
3043 bfd
*abfd ATTRIBUTE_UNUSED
;
3046 if (0xffff <= value
)
3053 xcoff_loader_symbol_offset (abfd
, ldhdr
)
3055 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
3057 return bfd_xcoff_ldhdrsz(abfd
);
3061 xcoff_loader_reloc_offset (abfd
, ldhdr
)
3063 struct internal_ldhdr
*ldhdr
;
3065 return bfd_xcoff_ldhdrsz(abfd
) +
3066 (ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(abfd
));
3070 xcoff_generate_rtinit (abfd
, init
, fini
, rtld
)
3076 bfd_byte filehdr_ext
[FILHSZ
];
3077 bfd_byte scnhdr_ext
[SCNHSZ
];
3078 bfd_byte syment_ext
[SYMESZ
* 10];
3079 bfd_byte reloc_ext
[RELSZ
* 3];
3080 bfd_byte
*data_buffer
;
3081 bfd_size_type data_buffer_size
;
3082 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3083 bfd_size_type string_table_size
;
3085 size_t initsz
, finisz
;
3086 struct internal_filehdr filehdr
;
3087 struct internal_scnhdr scnhdr
;
3088 struct internal_syment syment
;
3089 union internal_auxent auxent
;
3090 struct internal_reloc reloc
;
3092 char *data_name
= ".data";
3093 char *rtinit_name
= "__rtinit";
3094 char *rtld_name
= "__rtld";
3096 if (! bfd_xcoff_rtinit_size (abfd
))
3099 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3100 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3103 memset (filehdr_ext
, 0, FILHSZ
);
3104 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3105 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3106 filehdr
.f_nscns
= 1;
3107 filehdr
.f_timdat
= 0;
3108 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3109 filehdr
.f_symptr
= 0; /* set below */
3110 filehdr
.f_opthdr
= 0;
3111 filehdr
.f_flags
= 0;
3113 /* section header */
3114 memset (scnhdr_ext
, 0, SCNHSZ
);
3115 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3116 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3119 scnhdr
.s_size
= 0; /* set below */
3120 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3121 scnhdr
.s_relptr
= 0; /* set below */
3122 scnhdr
.s_lnnoptr
= 0;
3123 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3125 scnhdr
.s_flags
= STYP_DATA
;
3128 0x0000 0x00000000 : rtl
3129 0x0004 0x00000010 : offset to init, or 0
3130 0x0008 0x00000028 : offset to fini, or 0
3131 0x000C 0x0000000C : size of descriptor
3132 0x0010 0x00000000 : init, needs a reloc
3133 0x0014 0x00000040 : offset to init name
3134 0x0018 0x00000000 : flags, padded to a word
3135 0x001C 0x00000000 : empty init
3138 0x0028 0x00000000 : fini, needs a reloc
3139 0x002C 0x00000??? : offset to fini name
3140 0x0030 0x00000000 : flags, padded to a word
3141 0x0034 0x00000000 : empty fini
3145 0x0040 + initsz fini name */
3147 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3148 data_buffer_size
+= (data_buffer_size
& 7) ? 8 - (data_buffer_size
& 7) : 0;
3150 data_buffer
= (bfd_byte
*) bfd_malloc (data_buffer_size
);
3151 if (data_buffer
== NULL
)
3154 memset (data_buffer
, 0, data_buffer_size
);
3159 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3161 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3162 memcpy (&data_buffer
[val
], init
, initsz
);
3168 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3169 val
= 0x40 + initsz
;
3170 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3171 memcpy (&data_buffer
[val
], fini
, finisz
);
3175 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3177 scnhdr
.s_size
= data_buffer_size
;
3180 string_table_size
= 0;
3182 string_table_size
+= initsz
;
3184 string_table_size
+= finisz
;
3185 if (string_table_size
)
3187 string_table_size
+= 4;
3188 string_table
= (bfd_byte
*)bfd_malloc (string_table_size
);
3189 memset (string_table
, 0, string_table_size
);
3190 val
= string_table_size
;
3191 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3192 st_tmp
= string_table
+ 4;
3201 memset (syment_ext
, 0, 10 * SYMESZ
);
3202 memset (reloc_ext
, 0, 3 * RELSZ
);
3205 memset (&syment
, 0, sizeof (struct internal_syment
));
3206 memset (&auxent
, 0, sizeof (union internal_auxent
));
3207 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3209 syment
.n_sclass
= C_HIDEXT
;
3210 syment
.n_numaux
= 1;
3211 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3212 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3213 auxent
.x_csect
.x_smclas
= XMC_RW
;
3214 bfd_coff_swap_sym_out (abfd
, &syment
,
3215 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3216 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3218 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3219 filehdr
.f_nsyms
+= 2;
3222 memset (&syment
, 0, sizeof (struct internal_syment
));
3223 memset (&auxent
, 0, sizeof (union internal_auxent
));
3224 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3226 syment
.n_sclass
= C_EXT
;
3227 syment
.n_numaux
= 1;
3228 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3229 auxent
.x_csect
.x_smclas
= XMC_RW
;
3230 bfd_coff_swap_sym_out (abfd
, &syment
,
3231 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3232 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3234 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3235 filehdr
.f_nsyms
+= 2;
3240 memset (&syment
, 0, sizeof (struct internal_syment
));
3241 memset (&auxent
, 0, sizeof (union internal_auxent
));
3245 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3246 memcpy (st_tmp
, init
, initsz
);
3250 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3252 syment
.n_sclass
= C_EXT
;
3253 syment
.n_numaux
= 1;
3254 bfd_coff_swap_sym_out (abfd
, &syment
,
3255 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3256 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3258 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3261 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3262 reloc
.r_vaddr
= 0x0010;
3263 reloc
.r_symndx
= filehdr
.f_nsyms
;
3264 reloc
.r_type
= R_POS
;
3266 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3268 filehdr
.f_nsyms
+= 2;
3269 scnhdr
.s_nreloc
+= 1;
3275 memset (&syment
, 0, sizeof (struct internal_syment
));
3276 memset (&auxent
, 0, sizeof (union internal_auxent
));
3280 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3281 memcpy (st_tmp
, fini
, finisz
);
3285 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3287 syment
.n_sclass
= C_EXT
;
3288 syment
.n_numaux
= 1;
3289 bfd_coff_swap_sym_out (abfd
, &syment
,
3290 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3291 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3293 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3296 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3297 reloc
.r_vaddr
= 0x0028;
3298 reloc
.r_symndx
= filehdr
.f_nsyms
;
3299 reloc
.r_type
= R_POS
;
3301 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3302 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3304 filehdr
.f_nsyms
+= 2;
3305 scnhdr
.s_nreloc
+= 1;
3310 memset (&syment
, 0, sizeof (struct internal_syment
));
3311 memset (&auxent
, 0, sizeof (union internal_auxent
));
3312 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3313 syment
.n_sclass
= C_EXT
;
3314 syment
.n_numaux
= 1;
3315 bfd_coff_swap_sym_out (abfd
, &syment
,
3316 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3317 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3319 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3322 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3323 reloc
.r_vaddr
= 0x0000;
3324 reloc
.r_symndx
= filehdr
.f_nsyms
;
3325 reloc
.r_type
= R_POS
;
3327 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3328 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3330 filehdr
.f_nsyms
+= 2;
3331 scnhdr
.s_nreloc
+= 1;
3334 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3335 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3337 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3338 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3339 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3340 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3341 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3342 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3343 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3344 bfd_bwrite (string_table
, string_table_size
, abfd
);
3353 static reloc_howto_type xcoff_dynamic_reloc
=
3354 HOWTO (0, /* type */
3356 2, /* size (0 = byte, 1 = short, 2 = long) */
3358 false, /* pc_relative */
3360 complain_overflow_bitfield
, /* complain_on_overflow */
3361 0, /* special_function */
3363 true, /* partial_inplace */
3364 0xffffffff, /* src_mask */
3365 0xffffffff, /* dst_mask */
3366 false); /* pcrel_offset */
3370 The first word of global linkage code must be modified by filling in
3371 the correct TOC offset. */
3373 static unsigned long xcoff_glink_code
[9] =
3375 0x81820000, /* lwz r12,0(r2) */
3376 0x90410014, /* stw r2,20(r1) */
3377 0x800c0000, /* lwz r0,0(r12) */
3378 0x804c0004, /* lwz r2,4(r12) */
3379 0x7c0903a6, /* mtctr r0 */
3380 0x4e800420, /* bctr */
3381 0x00000000, /* start of traceback table */
3382 0x000c8000, /* traceback table */
3383 0x00000000, /* traceback table */
3387 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3389 { /* COFF backend, defined in libcoff.h. */
3390 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3391 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3392 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3393 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3394 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3395 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3396 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3397 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3398 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3399 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3400 FILHSZ
, /* _bfd_filhsz */
3401 AOUTSZ
, /* _bfd_aoutsz */
3402 SCNHSZ
, /* _bfd_scnhsz */
3403 SYMESZ
, /* _bfd_symesz */
3404 AUXESZ
, /* _bfd_auxesz */
3405 RELSZ
, /* _bfd_relsz */
3406 LINESZ
, /* _bfd_linesz */
3407 FILNMLEN
, /* _bfd_filnmlen */
3408 true, /* _bfd_coff_long_filenames */
3409 false, /* _bfd_coff_long_section_names */
3410 (3), /* _bfd_coff_default_section_alignment_power */
3411 false, /* _bfd_coff_force_symnames_in_strings */
3412 2, /* _bfd_coff_debug_string_prefix_length */
3413 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3414 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3415 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3416 coff_swap_reloc_in
, /* _bfd_reloc_in */
3417 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3418 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3419 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3420 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3421 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3422 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3423 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3424 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3425 coff_print_aux
, /* bfd_coff_print_aux */
3426 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3427 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3428 NULL
, /* bfd_coff_sym_is_global */
3429 coff_compute_section_file_positions
, /* _bfd_coff_compute_section_file_positions */
3430 NULL
, /* _bfd_coff_start_final_link */
3431 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3432 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3433 NULL
, /* _bfd_coff_addust_symndx */
3434 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3435 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3436 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3439 0x01DF, /* magic number */
3440 bfd_arch_rs6000
, /* architecture */
3441 bfd_mach_rs6k
, /* machine */
3443 /* Function pointers to xcoff specific swap routines. */
3444 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3445 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3446 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3447 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3448 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3449 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3452 LDHDRSZ
, /* _xcoff_ldhdrsz */
3453 LDSYMSZ
, /* _xcoff_ldsymsz */
3454 LDRELSZ
, /* _xcoff_ldrelsz */
3455 12, /* _xcoff_function_descriptor_size */
3456 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3459 1, /* _xcoff_ldhdr_version */
3461 /* Xcoff vs xcoff64 putting symbol names. */
3462 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3463 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3465 & xcoff_dynamic_reloc
, /* dynamic reloc howto */
3467 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3469 /* Lineno and reloc count overflow. */
3470 xcoff_is_lineno_count_overflow
,
3471 xcoff_is_reloc_count_overflow
,
3473 xcoff_loader_symbol_offset
,
3474 xcoff_loader_reloc_offset
,
3477 & xcoff_glink_code
[0],
3478 (36), /* _xcoff_glink_size */
3481 64, /* _xcoff_rtinit_size */
3482 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
3485 /* The transfer vector that leads the outside world to all of the above. */
3486 const bfd_target rs6000coff_vec
=
3489 bfd_target_xcoff_flavour
,
3490 BFD_ENDIAN_BIG
, /* data byte order is big */
3491 BFD_ENDIAN_BIG
, /* header byte order is big */
3493 (HAS_RELOC
| EXEC_P
| /* object flags */
3494 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3495 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3497 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3498 0, /* leading char */
3499 '/', /* ar_pad_char */
3500 15, /* ar_max_namelen??? FIXMEmgo */
3503 bfd_getb64
, /* bfd_getx64 */
3504 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3505 bfd_putb64
, /* bfd_putx64 */
3506 bfd_getb32
, /* bfd_getx32 */
3507 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3508 bfd_putb32
, /* bfd_putx32 */
3509 bfd_getb16
, /* bfd_getx16 */
3510 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3511 bfd_putb16
, /* bfd_putx16 */
3514 bfd_getb64
, /* bfd_h_getx64 */
3515 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3516 bfd_putb64
, /* bfd_h_putx64 */
3517 bfd_getb32
, /* bfd_h_getx32 */
3518 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3519 bfd_putb32
, /* bfd_h_putx32 */
3520 bfd_getb16
, /* bfd_h_getx16 */
3521 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3522 bfd_putb16
, /* bfd_h_putx16 */
3524 { /* bfd_check_format */
3527 _bfd_xcoff_archive_p
,
3531 { /* bfd_set_format */
3534 _bfd_generic_mkarchive
,
3538 {/* bfd_write_contents */
3540 coff_write_object_contents
,
3541 _bfd_xcoff_write_archive_contents
,
3546 bfd_true
, /* _close_and_cleanup */
3547 bfd_true
, /* _bfd_free_cached_info */
3548 coff_new_section_hook
, /* _new_section_hook */
3549 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3550 /* _bfd_get_section_contents_in_window */
3551 _bfd_generic_get_section_contents_in_window
,
3554 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3555 /* _bfd_merge_private_bfd_data */
3556 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3557 /* _bfd_copy_pivate_section_data */
3558 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3559 /* _bfd_copy_private_symbol_data */
3560 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3561 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3562 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3565 coff_core_file_failing_command
, /* _core_file_failing_command */
3566 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3567 /* _core_file_matches_executable_p */
3568 coff_core_file_matches_executable_p
,
3571 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3572 /* XCOFF archives do not have
3573 anything which corresponds to
3574 an extended name table. */
3575 bfd_false
, /* _slurp_extended_name_table */
3576 /* _construct_extended_name_table */
3577 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3578 bfd_dont_truncate_arname
, /* _truncate_arname */
3579 _bfd_xcoff_write_armap
, /* _write_armap */
3580 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3581 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3582 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3583 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3584 /* XCOFF archives do not have
3586 bfd_true
, /* _update_armap_timestamp */
3589 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3590 coff_get_symtab
, /* _get_symtab */
3591 coff_make_empty_symbol
, /* _make_empty_symbol */
3592 coff_print_symbol
, /* _print_symbol */
3593 coff_get_symbol_info
, /* _get_symbol_info */
3594 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3595 coff_get_lineno
, /* _get_lineno */
3596 coff_find_nearest_line
, /* _find_nearest_line */
3597 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3598 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3599 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3602 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3603 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3604 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3607 coff_set_arch_mach
, /* _set_arch_mach */
3608 coff_set_section_contents
, /* _set_section_contents */
3611 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3612 /* _bfd_get_relocated_section_contents */
3613 bfd_generic_get_relocated_section_contents
,
3614 bfd_generic_relax_section
, /* _bfd_relax_section */
3615 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3616 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3617 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3618 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3619 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3620 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3623 /* _get_dynamic_symtab_upper_bound */
3624 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3625 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3626 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3627 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3629 /* Opposite endian version, none exists */
3633 (void *) &bfd_xcoff_backend_data
,
3637 * xcoff-powermac target
3639 * Only difference between this target and the rs6000 target is the
3640 * the default architecture and machine type used in coffcode.h
3642 * PowerPC Macs use the same magic numbers as RS/6000
3643 * (because that's how they were bootstrapped originally),
3644 * but they are always PowerPC architecture.
3646 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
3648 { /* COFF backend, defined in libcoff.h */
3649 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3650 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3651 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3652 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3653 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3654 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3655 coff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3656 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3657 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3658 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3659 FILHSZ
, /* _bfd_filhsz */
3660 AOUTSZ
, /* _bfd_aoutsz */
3661 SCNHSZ
, /* _bfd_scnhsz */
3662 SYMESZ
, /* _bfd_symesz */
3663 AUXESZ
, /* _bfd_auxesz */
3664 RELSZ
, /* _bfd_relsz */
3665 LINESZ
, /* _bfd_linesz */
3666 FILNMLEN
, /* _bfd_filnmlen */
3667 true, /* _bfd_coff_long_filenames */
3668 false, /* _bfd_coff_long_section_names */
3669 (3), /* _bfd_coff_default_section_alignment_power */
3670 false, /* _bfd_coff_force_symnames_in_strings */
3671 2, /* _bfd_coff_debug_string_prefix_length */
3672 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3673 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3674 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3675 coff_swap_reloc_in
, /* _bfd_reloc_in */
3676 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3677 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3678 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3679 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3680 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3681 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3682 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3683 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3684 coff_print_aux
, /* bfd_coff_print_aux */
3685 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3686 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3687 NULL
, /* bfd_coff_sym_is_global */
3688 /* _bfd_coff_compute_section_file_positions */
3689 coff_compute_section_file_positions
,
3690 NULL
, /* _bfd_coff_start_final_link */
3691 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3692 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3693 NULL
, /* _bfd_coff_addust_symndx */
3694 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3695 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3696 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
3699 0x01DF, /* magic number */
3700 bfd_arch_powerpc
, /* architecture */
3701 bfd_mach_ppc
, /* machine */
3703 /* function pointers to xcoff specific swap routines */
3704 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
3705 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
3706 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
3707 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
3708 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
3709 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
3712 LDHDRSZ
, /* _xcoff_ldhdrsz */
3713 LDSYMSZ
, /* _xcoff_ldsymsz */
3714 LDRELSZ
, /* _xcoff_ldrelsz */
3715 12, /* _xcoff_function_descriptor_size */
3716 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
3719 1, /* _xcoff_ldhdr_version */
3721 /* xcoff vs xcoff64 putting symbol names */
3722 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
3723 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
3725 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
3727 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
3729 /* lineno and reloc count overflow */
3730 xcoff_is_lineno_count_overflow
,
3731 xcoff_is_reloc_count_overflow
,
3733 xcoff_loader_symbol_offset
,
3734 xcoff_loader_reloc_offset
,
3737 &xcoff_glink_code
[0],
3738 (36), /* _xcoff_glink_size */
3741 0, /* _xcoff_rtinit_size */
3742 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
3745 /* The transfer vector that leads the outside world to all of the above. */
3746 const bfd_target pmac_xcoff_vec
=
3749 bfd_target_xcoff_flavour
,
3750 BFD_ENDIAN_BIG
, /* data byte order is big */
3751 BFD_ENDIAN_BIG
, /* header byte order is big */
3753 (HAS_RELOC
| EXEC_P
| /* object flags */
3754 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
3755 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3757 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
3758 0, /* leading char */
3759 '/', /* ar_pad_char */
3760 15, /* ar_max_namelen??? FIXMEmgo */
3763 bfd_getb64
, /* bfd_getx64 */
3764 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
3765 bfd_putb64
, /* bfd_putx64 */
3766 bfd_getb32
, /* bfd_getx32 */
3767 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
3768 bfd_putb32
, /* bfd_putx32 */
3769 bfd_getb16
, /* bfd_getx16 */
3770 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
3771 bfd_putb16
, /* bfd_putx16 */
3774 bfd_getb64
, /* bfd_h_getx64 */
3775 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
3776 bfd_putb64
, /* bfd_h_putx64 */
3777 bfd_getb32
, /* bfd_h_getx32 */
3778 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
3779 bfd_putb32
, /* bfd_h_putx32 */
3780 bfd_getb16
, /* bfd_h_getx16 */
3781 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
3782 bfd_putb16
, /* bfd_h_putx16 */
3784 { /* bfd_check_format */
3787 _bfd_xcoff_archive_p
,
3791 { /* bfd_set_format */
3794 _bfd_generic_mkarchive
,
3798 {/* bfd_write_contents */
3800 coff_write_object_contents
,
3801 _bfd_xcoff_write_archive_contents
,
3806 bfd_true
, /* _close_and_cleanup */
3807 bfd_true
, /* _bfd_free_cached_info */
3808 coff_new_section_hook
, /* _new_section_hook */
3809 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
3810 /* _bfd_get_section_contents_in_window */
3811 _bfd_generic_get_section_contents_in_window
,
3814 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
3815 /* _bfd_merge_private_bfd_data */
3816 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
3817 /* _bfd_copy_pivate_section_data */
3818 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
3819 /* _bfd_copy_private_symbol_data */
3820 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
3821 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
3822 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
3825 coff_core_file_failing_command
, /* _core_file_failing_command */
3826 coff_core_file_failing_signal
, /* _core_file_failing_signal */
3827 /* _core_file_matches_executable_p */
3828 coff_core_file_matches_executable_p
,
3831 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
3832 /* XCOFF archives do not have
3833 anything which corresponds to
3834 an extended name table. */
3835 bfd_false
, /* _slurp_extended_name_table */
3836 /* _construct_extended_name_table */
3837 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
3838 bfd_dont_truncate_arname
, /* _truncate_arname */
3839 _bfd_xcoff_write_armap
, /* _write_armap */
3840 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
3841 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
3842 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
3843 _bfd_xcoff_generic_stat_arch_elt
, /* _generic_dtat_arch_elt */
3844 /* XCOFF archives do not have
3846 bfd_true
, /* _update_armap_timestamp */
3849 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
3850 coff_get_symtab
, /* _get_symtab */
3851 coff_make_empty_symbol
, /* _make_empty_symbol */
3852 coff_print_symbol
, /* _print_symbol */
3853 coff_get_symbol_info
, /* _get_symbol_info */
3854 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
3855 coff_get_lineno
, /* _get_lineno */
3856 coff_find_nearest_line
, /* _find_nearest_line */
3857 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
3858 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
3859 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
3862 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
3863 coff_canonicalize_reloc
, /* _cononicalize_reloc */
3864 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
3867 coff_set_arch_mach
, /* _set_arch_mach */
3868 coff_set_section_contents
, /* _set_section_contents */
3871 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
3872 /* _bfd_get_relocated_section_contents */
3873 bfd_generic_get_relocated_section_contents
,
3874 bfd_generic_relax_section
, /* _bfd_relax_section */
3875 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
3876 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
3877 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
3878 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
3879 bfd_generic_gc_sections
, /* _bfd_gc_sections */
3880 bfd_generic_merge_sections
, /* _bfd_merge_sections */
3883 /* _get_dynamic_symtab_upper_bound */
3884 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
3885 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
3886 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
3887 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
3889 /* Opposite endian version, none exists */
3893 (void *) &bfd_pmac_xcoff_backend_data
,