* coff-rs6000.c: Add missing prototypes.
[binutils.git] / bfd / coff-rs6000.c
blob8a956839a0feb4057e55ffc73d58453445bbafd2
1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001
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
8 character set it is.
9 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
10 and John Gilmore.
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. */
30 #include "bfd.h"
31 #include "sysdep.h"
32 #include "bfdlink.h"
33 #include "libbfd.h"
34 #include "coff/internal.h"
35 #include "coff/xcoff.h"
36 #include "coff/rs6000.h"
37 #include "libcoff.h"
38 #include "libxcoff.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) \
66 { \
67 internal.r_type = howto->type; \
68 internal.r_size = \
69 ((howto->complain_on_overflow == complain_overflow_signed \
70 ? 0x80 \
71 : 0) \
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
83 #ifdef AIX_CORE
84 extern const bfd_target * rs6000coff_core_p ();
85 extern boolean rs6000coff_core_file_matches_executable_p ();
86 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
87 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
88 #define CORE_FILE_P rs6000coff_core_p
89 #define coff_core_file_failing_command \
90 rs6000coff_core_file_failing_command
91 #define coff_core_file_failing_signal \
92 rs6000coff_core_file_failing_signal
93 #define coff_core_file_matches_executable_p \
94 rs6000coff_core_file_matches_executable_p
95 #else
96 #define CORE_FILE_P _bfd_dummy_target
97 #define coff_core_file_failing_command \
98 _bfd_nocore_core_file_failing_command
99 #define coff_core_file_failing_signal \
100 _bfd_nocore_core_file_failing_signal
101 #define coff_core_file_matches_executable_p \
102 _bfd_nocore_core_file_matches_executable_p
103 #endif
104 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
105 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
106 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
107 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
109 #include "coffcode.h"
111 /* The main body of code is in coffcode.h. */
113 static const char *normalize_filename PARAMS ((bfd *));
114 static boolean xcoff_write_armap_old
115 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
116 static boolean xcoff_write_one_armap_big
117 PARAMS ((bfd *, struct orl *, unsigned int, unsigned int, unsigned int,
118 int, const char *, char *));
119 static boolean xcoff_write_armap_big
120 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
121 static boolean xcoff_write_archive_contents_old PARAMS ((bfd *));
122 static boolean xcoff_write_archive_contents_big PARAMS ((bfd *));
123 static void xcoff_swap_ldhdr_in
124 PARAMS ((bfd *, const struct external_ldhdr *, struct internal_ldhdr *));
125 static void xcoff_swap_ldhdr_out
126 PARAMS ((bfd *, const struct internal_ldhdr *, struct external_ldhdr *));
127 static void xcoff_swap_ldsym_in
128 PARAMS ((bfd *, const struct external_ldsym *, struct internal_ldsym *));
129 static void xcoff_swap_ldsym_out
130 PARAMS ((bfd *, const struct internal_ldsym *, struct external_ldsym *));
131 static void xcoff_swap_ldrel_in
132 PARAMS ((bfd *, const struct external_ldrel *, struct internal_ldrel *));
133 static void xcoff_swap_ldrel_out
134 PARAMS ((bfd *, const struct internal_ldrel *, struct external_ldrel *));
135 static boolean xcoff_ppc_relocate_section
136 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
137 struct internal_reloc *, struct internal_syment *, asection **));
138 static boolean _bfd_xcoff_put_ldsymbol_name
139 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
140 const char *));
141 static asection *xcoff_create_csect_from_smclas
142 PARAMS ((bfd *, union internal_auxent *, char *));
143 static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
144 static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
145 static bfd_vma xcoff_loader_symbol_offset
146 PARAMS ((bfd *, struct internal_ldhdr *));
147 static bfd_vma xcoff_loader_reloc_offset
148 PARAMS ((bfd *, struct internal_ldhdr *));
150 /* We use our own tdata type. Its first field is the COFF tdata type,
151 so the COFF routines are compatible. */
153 boolean
154 _bfd_xcoff_mkobject (abfd)
155 bfd *abfd;
157 coff_data_type *coff;
159 abfd->tdata.xcoff_obj_data =
160 ((struct xcoff_tdata *)
161 bfd_zalloc (abfd, sizeof (struct xcoff_tdata)));
162 if (abfd->tdata.xcoff_obj_data == NULL)
163 return false;
164 coff = coff_data (abfd);
165 coff->symbols = (coff_symbol_type *) NULL;
166 coff->conversion_table = (unsigned int *) NULL;
167 coff->raw_syments = (struct coff_ptr_struct *) NULL;
168 coff->relocbase = 0;
170 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
172 /* We set cputype to -1 to indicate that it has not been
173 initialized. */
174 xcoff_data (abfd)->cputype = -1;
176 xcoff_data (abfd)->csects = NULL;
177 xcoff_data (abfd)->debug_indices = NULL;
179 /* text section alignment is different than the default */
180 /* xcoff_data (abfd)->text_align_power = 5; */
182 return true;
185 /* Copy XCOFF data from one BFD to another. */
187 boolean
188 _bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
189 bfd *ibfd;
190 bfd *obfd;
192 struct xcoff_tdata *ix, *ox;
193 asection *sec;
195 if (ibfd->xvec != obfd->xvec)
196 return true;
197 ix = xcoff_data (ibfd);
198 ox = xcoff_data (obfd);
199 ox->full_aouthdr = ix->full_aouthdr;
200 ox->toc = ix->toc;
201 if (ix->sntoc == 0)
202 ox->sntoc = 0;
203 else
205 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
206 if (sec == NULL)
207 ox->sntoc = 0;
208 else
209 ox->sntoc = sec->output_section->target_index;
211 if (ix->snentry == 0)
212 ox->snentry = 0;
213 else
215 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
216 if (sec == NULL)
217 ox->snentry = 0;
218 else
219 ox->snentry = sec->output_section->target_index;
221 ox->text_align_power = ix->text_align_power;
222 ox->data_align_power = ix->data_align_power;
223 ox->modtype = ix->modtype;
224 ox->cputype = ix->cputype;
225 ox->maxdata = ix->maxdata;
226 ox->maxstack = ix->maxstack;
227 return true;
230 /* I don't think XCOFF really has a notion of local labels based on
231 name. This will mean that ld -X doesn't actually strip anything.
232 The AIX native linker does not have a -X option, and it ignores the
233 -x option. */
235 boolean
236 _bfd_xcoff_is_local_label_name (abfd, name)
237 bfd *abfd ATTRIBUTE_UNUSED;
238 const char *name ATTRIBUTE_UNUSED;
240 return false;
245 void
246 _bfd_xcoff_swap_sym_in (abfd, ext1, in1)
247 bfd *abfd;
248 PTR ext1;
249 PTR in1;
251 SYMENT *ext = (SYMENT *)ext1;
252 struct internal_syment *in = (struct internal_syment *)in1;
254 if(ext->e.e_name[0] != 0) {
255 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
256 } else {
257 in->_n._n_n._n_zeroes = 0;
258 in->_n._n_n._n_offset =
259 bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
262 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
263 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
264 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
265 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
266 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
269 unsigned int
270 _bfd_xcoff_swap_sym_out (abfd, inp, extp)
271 bfd *abfd;
272 PTR inp;
273 PTR extp;
275 struct internal_syment *in = (struct internal_syment *)inp;
276 SYMENT *ext =(SYMENT *)extp;
278 if(in->_n._n_name[0] != 0) {
279 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
280 } else {
281 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
282 bfd_h_put_32(abfd, in->_n._n_n._n_offset,
283 (bfd_byte *) ext->e.e.e_offset);
286 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
287 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
288 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
289 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
290 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
291 return bfd_coff_symesz (abfd);
294 #define PUTWORD bfd_h_put_32
295 #define PUTHALF bfd_h_put_16
296 #define PUTBYTE bfd_h_put_8
297 #define GETWORD bfd_h_get_32
298 #define GETHALF bfd_h_get_16
299 #define GETBYTE bfd_h_get_8
301 void
302 _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
303 bfd *abfd;
304 PTR ext1;
305 int type;
306 int class;
307 int indx;
308 int numaux;
309 PTR in1;
311 AUXENT *ext = (AUXENT *)ext1;
312 union internal_auxent *in = (union internal_auxent *)in1;
314 switch (class) {
315 case C_FILE:
316 if (ext->x_file.x_fname[0] == 0) {
317 in->x_file.x_n.x_zeroes = 0;
318 in->x_file.x_n.x_offset =
319 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
320 } else {
321 if (numaux > 1)
323 if (indx == 0)
324 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
325 numaux * sizeof (AUXENT));
327 else
329 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
332 goto end;
334 /* RS/6000 "csect" auxents */
335 case C_EXT:
336 case C_HIDEXT:
337 if (indx + 1 == numaux)
339 in->x_csect.x_scnlen.l =
340 bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
341 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
342 ext->x_csect.x_parmhash);
343 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
344 /* We don't have to hack bitfields in x_smtyp because it's
345 defined by shifts-and-ands, which are equivalent on all
346 byte orders. */
347 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
348 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
349 in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
350 in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
351 goto end;
353 break;
355 case C_STAT:
356 case C_LEAFSTAT:
357 case C_HIDDEN:
358 if (type == T_NULL) {
359 in->x_scn.x_scnlen = bfd_h_get_32(abfd,
360 (bfd_byte *) ext->x_scn.x_scnlen);
361 in->x_scn.x_nreloc = bfd_h_get_16(abfd,
362 (bfd_byte *) ext->x_scn.x_nreloc);
363 in->x_scn.x_nlinno = bfd_h_get_16(abfd,
364 (bfd_byte *) ext->x_scn.x_nlinno);
365 /* PE defines some extra fields; we zero them out for
366 safety. */
367 in->x_scn.x_checksum = 0;
368 in->x_scn.x_associated = 0;
369 in->x_scn.x_comdat = 0;
371 goto end;
373 break;
376 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
377 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
379 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
381 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *)
382 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
383 in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
384 ext->x_sym.x_fcnary.x_fcn.x_endndx);
386 else
388 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
389 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
390 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
391 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
392 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
393 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
394 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
395 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
397 if (ISFCN(type)) {
398 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
400 else {
401 in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_16(abfd, (bfd_byte *)
402 ext->x_sym.x_misc.x_lnsz.x_lnno);
403 in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
404 ext->x_sym.x_misc.x_lnsz.x_size);
407 end: ;
408 /* the semicolon is because MSVC doesn't like labels at
409 end of block. */
415 unsigned int
416 _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
417 bfd *abfd;
418 PTR inp;
419 int type;
420 int class;
421 int indx ATTRIBUTE_UNUSED;
422 int numaux ATTRIBUTE_UNUSED;
423 PTR extp;
425 union internal_auxent *in = (union internal_auxent *)inp;
426 AUXENT *ext = (AUXENT *)extp;
428 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
429 switch (class)
431 case C_FILE:
432 if (in->x_file.x_fname[0] == 0)
434 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
435 PUTWORD(abfd,
436 in->x_file.x_n.x_offset,
437 (bfd_byte *) ext->x_file.x_n.x_offset);
439 else
441 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
443 goto end;
445 /* RS/6000 "csect" auxents */
446 case C_EXT:
447 case C_HIDEXT:
448 if (indx + 1 == numaux)
450 PUTWORD (abfd, in->x_csect.x_scnlen.l,ext->x_csect.x_scnlen);
451 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
452 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
453 /* We don't have to hack bitfields in x_smtyp because it's
454 defined by shifts-and-ands, which are equivalent on all
455 byte orders. */
456 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
457 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
458 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
459 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
460 goto end;
462 break;
464 case C_STAT:
465 case C_LEAFSTAT:
466 case C_HIDDEN:
467 if (type == T_NULL) {
468 bfd_h_put_32(abfd, in->x_scn.x_scnlen, (bfd_byte *) ext->x_scn.x_scnlen);
469 bfd_h_put_16(abfd, in->x_scn.x_nreloc, (bfd_byte *) ext->x_scn.x_nreloc);
470 bfd_h_put_16(abfd, in->x_scn.x_nlinno, (bfd_byte *) ext->x_scn.x_nlinno);
471 goto end;
473 break;
476 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
477 bfd_h_put_16 (abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
479 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
481 bfd_h_put_32(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
482 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
483 PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
484 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
486 else
488 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
489 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
490 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
491 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
492 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
493 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
494 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
495 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
498 if (ISFCN (type))
499 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
500 (bfd_byte *) ext->x_sym.x_misc.x_fsize);
501 else
503 bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
504 (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno);
505 bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
506 (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size);
509 end:
510 return bfd_coff_auxesz (abfd);
515 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
516 bitsize and whether they are signed or not, along with a
517 conventional type. This table is for the types, which are used for
518 different algorithms for putting in the reloc. Many of these
519 relocs need special_function entries, which I have not written. */
522 reloc_howto_type xcoff_howto_table[] =
524 /* Standard 32 bit relocation. */
525 HOWTO (0, /* type */
526 0, /* rightshift */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
528 32, /* bitsize */
529 false, /* pc_relative */
530 0, /* bitpos */
531 complain_overflow_bitfield, /* complain_on_overflow */
532 0, /* special_function */
533 "R_POS", /* name */
534 true, /* partial_inplace */
535 0xffffffff, /* src_mask */
536 0xffffffff, /* dst_mask */
537 false), /* pcrel_offset */
539 /* 32 bit relocation, but store negative value. */
540 HOWTO (1, /* type */
541 0, /* rightshift */
542 -2, /* size (0 = byte, 1 = short, 2 = long) */
543 32, /* bitsize */
544 false, /* pc_relative */
545 0, /* bitpos */
546 complain_overflow_bitfield, /* complain_on_overflow */
547 0, /* special_function */
548 "R_NEG", /* name */
549 true, /* partial_inplace */
550 0xffffffff, /* src_mask */
551 0xffffffff, /* dst_mask */
552 false), /* pcrel_offset */
554 /* 32 bit PC relative relocation. */
555 HOWTO (2, /* type */
556 0, /* rightshift */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
558 32, /* bitsize */
559 true, /* pc_relative */
560 0, /* bitpos */
561 complain_overflow_signed, /* complain_on_overflow */
562 0, /* special_function */
563 "R_REL", /* name */
564 true, /* partial_inplace */
565 0xffffffff, /* src_mask */
566 0xffffffff, /* dst_mask */
567 false), /* pcrel_offset */
569 /* 16 bit TOC relative relocation. */
570 HOWTO (3, /* type */
571 0, /* rightshift */
572 1, /* size (0 = byte, 1 = short, 2 = long) */
573 16, /* bitsize */
574 false, /* pc_relative */
575 0, /* bitpos */
576 complain_overflow_bitfield, /* complain_on_overflow */
577 0, /* special_function */
578 "R_TOC", /* name */
579 true, /* partial_inplace */
580 0xffff, /* src_mask */
581 0xffff, /* dst_mask */
582 false), /* pcrel_offset */
584 /* I don't really know what this is. */
585 HOWTO (4, /* type */
586 1, /* rightshift */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
588 32, /* bitsize */
589 false, /* pc_relative */
590 0, /* bitpos */
591 complain_overflow_bitfield, /* complain_on_overflow */
592 0, /* special_function */
593 "R_RTB", /* name */
594 true, /* partial_inplace */
595 0xffffffff, /* src_mask */
596 0xffffffff, /* dst_mask */
597 false), /* pcrel_offset */
599 /* External TOC relative symbol. */
600 HOWTO (5, /* type */
601 0, /* rightshift */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
603 16, /* bitsize */
604 false, /* pc_relative */
605 0, /* bitpos */
606 complain_overflow_bitfield, /* complain_on_overflow */
607 0, /* special_function */
608 "R_GL", /* name */
609 true, /* partial_inplace */
610 0xffff, /* src_mask */
611 0xffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* Local TOC relative symbol. */
615 HOWTO (6, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 16, /* bitsize */
619 false, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_bitfield, /* complain_on_overflow */
622 0, /* special_function */
623 "R_TCL", /* name */
624 true, /* partial_inplace */
625 0xffff, /* src_mask */
626 0xffff, /* dst_mask */
627 false), /* pcrel_offset */
629 EMPTY_HOWTO (7),
631 /* Non modifiable absolute branch. */
632 HOWTO (8, /* type */
633 0, /* rightshift */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
635 26, /* bitsize */
636 false, /* pc_relative */
637 0, /* bitpos */
638 complain_overflow_bitfield, /* complain_on_overflow */
639 0, /* special_function */
640 "R_BA", /* name */
641 true, /* partial_inplace */
642 0x3fffffc, /* src_mask */
643 0x3fffffc, /* dst_mask */
644 false), /* pcrel_offset */
646 EMPTY_HOWTO (9),
648 /* Non modifiable relative branch. */
649 HOWTO (0xa, /* type */
650 0, /* rightshift */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
652 26, /* bitsize */
653 true, /* pc_relative */
654 0, /* bitpos */
655 complain_overflow_signed, /* complain_on_overflow */
656 0, /* special_function */
657 "R_BR", /* name */
658 true, /* partial_inplace */
659 0x3fffffc, /* src_mask */
660 0x3fffffc, /* dst_mask */
661 false), /* pcrel_offset */
663 EMPTY_HOWTO (0xb),
665 /* Indirect load. */
666 HOWTO (0xc, /* type */
667 0, /* rightshift */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
669 16, /* bitsize */
670 false, /* pc_relative */
671 0, /* bitpos */
672 complain_overflow_bitfield, /* complain_on_overflow */
673 0, /* special_function */
674 "R_RL", /* name */
675 true, /* partial_inplace */
676 0xffff, /* src_mask */
677 0xffff, /* dst_mask */
678 false), /* pcrel_offset */
680 /* Load address. */
681 HOWTO (0xd, /* type */
682 0, /* rightshift */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
684 16, /* bitsize */
685 false, /* pc_relative */
686 0, /* bitpos */
687 complain_overflow_bitfield, /* complain_on_overflow */
688 0, /* special_function */
689 "R_RLA", /* name */
690 true, /* partial_inplace */
691 0xffff, /* src_mask */
692 0xffff, /* dst_mask */
693 false), /* pcrel_offset */
695 EMPTY_HOWTO (0xe),
697 /* Non-relocating reference. */
698 HOWTO (0xf, /* type */
699 0, /* rightshift */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
701 32, /* bitsize */
702 false, /* pc_relative */
703 0, /* bitpos */
704 complain_overflow_bitfield, /* complain_on_overflow */
705 0, /* special_function */
706 "R_REF", /* name */
707 false, /* partial_inplace */
708 0, /* src_mask */
709 0, /* dst_mask */
710 false), /* pcrel_offset */
712 EMPTY_HOWTO (0x10),
713 EMPTY_HOWTO (0x11),
715 /* TOC relative indirect load. */
716 HOWTO (0x12, /* type */
717 0, /* rightshift */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
719 16, /* bitsize */
720 false, /* pc_relative */
721 0, /* bitpos */
722 complain_overflow_bitfield, /* complain_on_overflow */
723 0, /* special_function */
724 "R_TRL", /* name */
725 true, /* partial_inplace */
726 0xffff, /* src_mask */
727 0xffff, /* dst_mask */
728 false), /* pcrel_offset */
730 /* TOC relative load address. */
731 HOWTO (0x13, /* type */
732 0, /* rightshift */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
734 16, /* bitsize */
735 false, /* pc_relative */
736 0, /* bitpos */
737 complain_overflow_bitfield, /* complain_on_overflow */
738 0, /* special_function */
739 "R_TRLA", /* name */
740 true, /* partial_inplace */
741 0xffff, /* src_mask */
742 0xffff, /* dst_mask */
743 false), /* pcrel_offset */
745 /* Modifiable relative branch. */
746 HOWTO (0x14, /* type */
747 1, /* rightshift */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
749 32, /* bitsize */
750 false, /* pc_relative */
751 0, /* bitpos */
752 complain_overflow_bitfield, /* complain_on_overflow */
753 0, /* special_function */
754 "R_RRTBI", /* name */
755 true, /* partial_inplace */
756 0xffffffff, /* src_mask */
757 0xffffffff, /* dst_mask */
758 false), /* pcrel_offset */
760 /* Modifiable absolute branch. */
761 HOWTO (0x15, /* type */
762 1, /* rightshift */
763 2, /* size (0 = byte, 1 = short, 2 = long) */
764 32, /* bitsize */
765 false, /* pc_relative */
766 0, /* bitpos */
767 complain_overflow_bitfield, /* complain_on_overflow */
768 0, /* special_function */
769 "R_RRTBA", /* name */
770 true, /* partial_inplace */
771 0xffffffff, /* src_mask */
772 0xffffffff, /* dst_mask */
773 false), /* pcrel_offset */
775 /* Modifiable call absolute indirect. */
776 HOWTO (0x16, /* type */
777 0, /* rightshift */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
779 16, /* bitsize */
780 false, /* pc_relative */
781 0, /* bitpos */
782 complain_overflow_bitfield, /* complain_on_overflow */
783 0, /* special_function */
784 "R_CAI", /* name */
785 true, /* partial_inplace */
786 0xffff, /* src_mask */
787 0xffff, /* dst_mask */
788 false), /* pcrel_offset */
790 /* Modifiable call relative. */
791 HOWTO (0x17, /* type */
792 0, /* rightshift */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
794 16, /* bitsize */
795 false, /* pc_relative */
796 0, /* bitpos */
797 complain_overflow_bitfield, /* complain_on_overflow */
798 0, /* special_function */
799 "R_CREL", /* name */
800 true, /* partial_inplace */
801 0xffff, /* src_mask */
802 0xffff, /* dst_mask */
803 false), /* pcrel_offset */
805 /* Modifiable branch absolute. */
806 HOWTO (0x18, /* type */
807 0, /* rightshift */
808 2, /* size (0 = byte, 1 = short, 2 = long) */
809 26, /* bitsize */
810 false, /* pc_relative */
811 0, /* bitpos */
812 complain_overflow_bitfield, /* complain_on_overflow */
813 0, /* special_function */
814 "R_RBA", /* name */
815 true, /* partial_inplace */
816 0xffff, /* src_mask */
817 0xffff, /* dst_mask */
818 false), /* pcrel_offset */
820 /* Modifiable branch absolute. */
821 HOWTO (0x19, /* type */
822 0, /* rightshift */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
824 32, /* bitsize */
825 false, /* pc_relative */
826 0, /* bitpos */
827 complain_overflow_bitfield, /* complain_on_overflow */
828 0, /* special_function */
829 "R_RBAC", /* name */
830 true, /* partial_inplace */
831 0xffff, /* src_mask */
832 0xffff, /* dst_mask */
833 false), /* pcrel_offset */
835 /* Modifiable branch relative. */
836 HOWTO (0x1a, /* type */
837 0, /* rightshift */
838 2, /* size (0 = byte, 1 = short, 2 = long) */
839 26, /* bitsize */
840 false, /* pc_relative */
841 0, /* bitpos */
842 complain_overflow_signed, /* complain_on_overflow */
843 0, /* special_function */
844 "R_RBR", /* name */
845 true, /* partial_inplace */
846 0xffff, /* src_mask */
847 0xffff, /* dst_mask */
848 false), /* pcrel_offset */
850 /* Modifiable branch absolute. */
851 HOWTO (0x1b, /* type */
852 0, /* rightshift */
853 2, /* size (0 = byte, 1 = short, 2 = long) */
854 16, /* bitsize */
855 false, /* pc_relative */
856 0, /* bitpos */
857 complain_overflow_bitfield, /* complain_on_overflow */
858 0, /* special_function */
859 "R_RBRC", /* name */
860 true, /* partial_inplace */
861 0xffff, /* src_mask */
862 0xffff, /* dst_mask */
863 false), /* pcrel_offset */
865 HOWTO (0, /* type */
866 0, /* rightshift */
867 4, /* size (0 = byte, 1 = short, 2 = long) */
868 64, /* bitsize */
869 false, /* pc_relative */
870 0, /* bitpos */
871 complain_overflow_bitfield, /* complain_on_overflow */
872 0, /* special_function */
873 "R_POS", /* name */
874 true, /* partial_inplace */
875 MINUS_ONE, /* src_mask */
876 MINUS_ONE, /* dst_mask */
877 false) /* pcrel_offset */
881 void
882 _bfd_xcoff_rtype2howto (relent, internal)
883 arelent *relent;
884 struct internal_reloc *internal;
886 relent->howto = xcoff_howto_table + internal->r_type;
888 /* Check for relocs we don't know of. */
889 if (internal->r_type
890 >= sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]))
891 abort ();
892 if (internal->r_type != relent->howto->type)
893 abort ();
895 /* The r_size field of an XCOFF reloc encodes the bitsize of the
896 relocation, as well as indicating whether it is signed or not.
897 Doublecheck that the relocation information gathered from the
898 type matches this information. The bitsize is not significant
899 for R_REF relocs. */
900 if (relent->howto->dst_mask != 0
901 && (relent->howto->bitsize
902 != ((unsigned int) internal->r_size & 0x3f) + 1))
903 abort ();
904 #if 0
905 if ((internal->r_size & 0x80) != 0
906 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
907 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
908 abort ();
909 #endif
912 reloc_howto_type *
913 _bfd_xcoff_reloc_type_lookup (abfd, code)
914 bfd *abfd ATTRIBUTE_UNUSED;
915 bfd_reloc_code_real_type code;
917 switch (code)
919 case BFD_RELOC_PPC_B26:
920 return &xcoff_howto_table[0xa];
921 case BFD_RELOC_PPC_BA26:
922 return &xcoff_howto_table[8];
923 case BFD_RELOC_PPC_TOC16:
924 return &xcoff_howto_table[3];
925 case BFD_RELOC_32:
926 case BFD_RELOC_CTOR:
927 return &xcoff_howto_table[0];
928 case BFD_RELOC_64:
929 return &xcoff_howto_table[0x1c];
930 default:
931 return NULL;
936 /* XCOFF archive support. The original version of this code was by
937 Damon A. Permezel. It was enhanced to permit cross support, and
938 writing archive files, by Ian Lance Taylor, Cygnus Support.
940 XCOFF uses its own archive format. Everything is hooked together
941 with file offset links, so it is possible to rapidly update an
942 archive in place. Of course, we don't do that. An XCOFF archive
943 has a real file header, not just an ARMAG string. The structure of
944 the file header and of each archive header appear below.
946 An XCOFF archive also has a member table, which is a list of
947 elements in the archive (you can get that by looking through the
948 linked list, but you have to read a lot more of the file). The
949 member table has a normal archive header with an empty name. It is
950 normally (and perhaps must be) the second to last entry in the
951 archive. The member table data is almost printable ASCII. It
952 starts with a 12 character decimal string which is the number of
953 entries in the table. For each entry it has a 12 character decimal
954 string which is the offset in the archive of that member. These
955 entries are followed by a series of null terminated strings which
956 are the member names for each entry.
958 Finally, an XCOFF archive has a global symbol table, which is what
959 we call the armap. The global symbol table has a normal archive
960 header with an empty name. It is normally (and perhaps must be)
961 the last entry in the archive. The contents start with a four byte
962 binary number which is the number of entries. This is followed by
963 a that many four byte binary numbers; each is the file offset of an
964 entry in the archive. These numbers are followed by a series of
965 null terminated strings, which are symbol names.
967 AIX 4.3 introduced a new archive format which can handle larger
968 files and also 32- and 64-bit objects in the same archive. The
969 things said above remain true except that there is now more than
970 one global symbol table. The one is used to index 32-bit objects,
971 the other for 64-bit objects.
973 The new archives (recognizable by the new ARMAG string) has larger
974 field lengths so that we cannot really share any code. Also we have
975 to take care that we are not generating the new form of archives
976 on AIX 4.2 or earlier systems. */
978 /* XCOFF archives use this as a magic string. Note that both strings
979 have the same length. */
983 /* Read in the armap of an XCOFF archive. */
985 boolean
986 _bfd_xcoff_slurp_armap (abfd)
987 bfd *abfd;
989 file_ptr off;
990 size_t namlen;
991 bfd_size_type sz;
992 bfd_byte *contents, *cend;
993 bfd_vma c, i;
994 carsym *arsym;
995 bfd_byte *p;
997 if (xcoff_ardata (abfd) == NULL)
999 bfd_has_map (abfd) = false;
1000 return true;
1003 if (! xcoff_big_format_p (abfd))
1005 /* This is for the old format. */
1006 struct xcoff_ar_hdr hdr;
1008 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1009 if (off == 0)
1011 bfd_has_map (abfd) = false;
1012 return true;
1015 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1016 return false;
1018 /* The symbol table starts with a normal archive header. */
1019 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
1020 return false;
1022 /* Skip the name (normally empty). */
1023 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1024 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1025 return false;
1027 sz = strtol (hdr.size, (char **) NULL, 10);
1029 /* Read in the entire symbol table. */
1030 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1031 if (contents == NULL)
1032 return false;
1033 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
1034 return false;
1036 /* The symbol table starts with a four byte count. */
1037 c = bfd_h_get_32 (abfd, contents);
1039 if (c * 4 >= sz)
1041 bfd_set_error (bfd_error_bad_value);
1042 return false;
1045 bfd_ardata (abfd)->symdefs = ((carsym *)
1046 bfd_alloc (abfd, c * sizeof (carsym)));
1047 if (bfd_ardata (abfd)->symdefs == NULL)
1048 return false;
1050 /* After the count comes a list of four byte file offsets. */
1051 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1052 i < c;
1053 ++i, ++arsym, p += 4)
1054 arsym->file_offset = bfd_h_get_32 (abfd, p);
1056 else
1058 /* This is for the new format. */
1059 struct xcoff_ar_hdr_big hdr;
1061 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1062 if (off == 0)
1064 bfd_has_map (abfd) = false;
1065 return true;
1068 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1069 return false;
1071 /* The symbol table starts with a normal archive header. */
1072 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
1073 != SIZEOF_AR_HDR_BIG)
1074 return false;
1076 /* Skip the name (normally empty). */
1077 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1078 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1079 return false;
1081 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1082 machines) since the field width is 20 and there numbers with more
1083 than 32 bits can be represented. */
1084 sz = strtol (hdr.size, (char **) NULL, 10);
1086 /* Read in the entire symbol table. */
1087 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1088 if (contents == NULL)
1089 return false;
1090 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
1091 return false;
1093 /* The symbol table starts with an eight byte count. */
1094 c = bfd_h_get_64 (abfd, contents);
1096 if (c * 8 >= sz)
1098 bfd_set_error (bfd_error_bad_value);
1099 return false;
1102 bfd_ardata (abfd)->symdefs = ((carsym *)
1103 bfd_alloc (abfd, c * sizeof (carsym)));
1104 if (bfd_ardata (abfd)->symdefs == NULL)
1105 return false;
1107 /* After the count comes a list of eight byte file offsets. */
1108 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1109 i < c;
1110 ++i, ++arsym, p += 8)
1111 arsym->file_offset = bfd_h_get_64 (abfd, p);
1114 /* After the file offsets come null terminated symbol names. */
1115 cend = contents + sz;
1116 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1117 i < c;
1118 ++i, ++arsym, p += strlen ((char *) p) + 1)
1120 if (p >= cend)
1122 bfd_set_error (bfd_error_bad_value);
1123 return false;
1125 arsym->name = (char *) p;
1128 bfd_ardata (abfd)->symdef_count = c;
1129 bfd_has_map (abfd) = true;
1131 return true;
1134 /* See if this is an XCOFF archive. */
1136 const bfd_target *
1137 _bfd_xcoff_archive_p (abfd)
1138 bfd *abfd;
1140 char magic[SXCOFFARMAG];
1142 if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG)
1144 if (bfd_get_error () != bfd_error_system_call)
1145 bfd_set_error (bfd_error_wrong_format);
1146 return NULL;
1149 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1150 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1152 bfd_set_error (bfd_error_wrong_format);
1153 return NULL;
1156 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1157 involves a cast, we can't do it as the left operand of
1158 assignment. */
1159 abfd->tdata.aout_ar_data =
1160 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
1162 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1163 return NULL;
1165 bfd_ardata (abfd)->cache = NULL;
1166 bfd_ardata (abfd)->archive_head = NULL;
1167 bfd_ardata (abfd)->symdefs = NULL;
1168 bfd_ardata (abfd)->extended_names = NULL;
1170 /* Now handle the two formats. */
1171 if (magic[1] != 'b')
1173 /* This is the old format. */
1174 struct xcoff_ar_file_hdr hdr;
1176 /* Copy over the magic string. */
1177 memcpy (hdr.magic, magic, SXCOFFARMAG);
1179 /* Now read the rest of the file header. */
1180 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1,
1181 abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
1183 if (bfd_get_error () != bfd_error_system_call)
1184 bfd_set_error (bfd_error_wrong_format);
1185 return NULL;
1188 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1189 (char **) NULL, 10);
1191 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
1192 if (bfd_ardata (abfd)->tdata == NULL)
1193 return NULL;
1195 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1197 else
1199 /* This is the new format. */
1200 struct xcoff_ar_file_hdr_big hdr;
1202 /* Copy over the magic string. */
1203 memcpy (hdr.magic, magic, SXCOFFARMAG);
1205 /* Now read the rest of the file header. */
1206 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
1207 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1209 if (bfd_get_error () != bfd_error_system_call)
1210 bfd_set_error (bfd_error_wrong_format);
1211 return NULL;
1214 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1215 machines) since the field width is 20 and there numbers with more
1216 than 32 bits can be represented. */
1217 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1218 (char **) NULL, 10);
1220 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
1221 if (bfd_ardata (abfd)->tdata == NULL)
1222 return NULL;
1224 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1227 if (! _bfd_xcoff_slurp_armap (abfd))
1229 bfd_release (abfd, bfd_ardata (abfd));
1230 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1231 return NULL;
1234 return abfd->xvec;
1237 /* Read the archive header in an XCOFF archive. */
1240 _bfd_xcoff_read_ar_hdr (abfd)
1241 bfd *abfd;
1243 size_t namlen;
1244 struct areltdata *ret;
1246 ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
1247 if (ret == NULL)
1248 return NULL;
1250 if (! xcoff_big_format_p (abfd))
1252 struct xcoff_ar_hdr hdr;
1253 struct xcoff_ar_hdr *hdrp;
1255 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
1257 free (ret);
1258 return NULL;
1261 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1262 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd,
1263 SIZEOF_AR_HDR + namlen + 1);
1264 if (hdrp == NULL)
1266 free (ret);
1267 return NULL;
1269 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1270 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
1272 free (ret);
1273 return NULL;
1275 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1277 ret->arch_header = (char *) hdrp;
1278 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1279 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1281 else
1283 struct xcoff_ar_hdr_big hdr;
1284 struct xcoff_ar_hdr_big *hdrp;
1286 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
1287 != SIZEOF_AR_HDR_BIG)
1289 free (ret);
1290 return NULL;
1293 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1294 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd,
1295 SIZEOF_AR_HDR_BIG
1296 + namlen + 1);
1297 if (hdrp == NULL)
1299 free (ret);
1300 return NULL;
1302 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1303 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen)
1305 free (ret);
1306 return NULL;
1308 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1310 ret->arch_header = (char *) hdrp;
1311 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1312 machines) since the field width is 20 and there numbers with more
1313 than 32 bits can be represented. */
1314 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1315 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1318 /* Skip over the XCOFFARFMAG at the end of the file name. */
1319 if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1320 return NULL;
1322 return (PTR) ret;
1325 /* Open the next element in an XCOFF archive. */
1327 bfd *
1328 _bfd_xcoff_openr_next_archived_file (archive, last_file)
1329 bfd *archive;
1330 bfd *last_file;
1332 file_ptr filestart;
1334 if (xcoff_ardata (archive) == NULL)
1336 bfd_set_error (bfd_error_invalid_operation);
1337 return NULL;
1340 if (! xcoff_big_format_p (archive))
1342 if (last_file == NULL)
1343 filestart = bfd_ardata (archive)->first_file_filepos;
1344 else
1345 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1346 10);
1348 if (filestart == 0
1349 || filestart == strtol (xcoff_ardata (archive)->memoff,
1350 (char **) NULL, 10)
1351 || filestart == strtol (xcoff_ardata (archive)->symoff,
1352 (char **) NULL, 10))
1354 bfd_set_error (bfd_error_no_more_archived_files);
1355 return NULL;
1358 else
1360 if (last_file == NULL)
1361 filestart = bfd_ardata (archive)->first_file_filepos;
1362 else
1363 /* XXX These actually have to be a calls to strtoll (at least
1364 on 32-bit machines) since the fields's width is 20 and
1365 there numbers with more than 32 bits can be represented. */
1366 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1367 10);
1369 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1370 machines) since the fields's width is 20 and there numbers with more
1371 than 32 bits can be represented. */
1372 if (filestart == 0
1373 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1374 (char **) NULL, 10)
1375 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1376 (char **) NULL, 10))
1378 bfd_set_error (bfd_error_no_more_archived_files);
1379 return NULL;
1383 return _bfd_get_elt_at_filepos (archive, filestart);
1386 /* Stat an element in an XCOFF archive. */
1389 _bfd_xcoff_generic_stat_arch_elt (abfd, s)
1390 bfd *abfd;
1391 struct stat *s;
1393 if (abfd->arelt_data == NULL)
1395 bfd_set_error (bfd_error_invalid_operation);
1396 return -1;
1399 if (! xcoff_big_format_p (abfd))
1401 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1403 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1404 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1405 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1406 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1407 s->st_size = arch_eltdata (abfd)->parsed_size;
1409 else
1411 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1413 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1414 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1415 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1416 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1417 s->st_size = arch_eltdata (abfd)->parsed_size;
1420 return 0;
1423 /* Normalize a file name for inclusion in an archive. */
1425 static const char *
1426 normalize_filename (abfd)
1427 bfd *abfd;
1429 const char *file;
1430 const char *filename;
1432 file = bfd_get_filename (abfd);
1433 filename = strrchr (file, '/');
1434 if (filename != NULL)
1435 filename++;
1436 else
1437 filename = file;
1438 return filename;
1441 /* Write out an XCOFF armap. */
1443 /*ARGSUSED*/
1444 static boolean
1445 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1446 bfd *abfd;
1447 unsigned int elength ATTRIBUTE_UNUSED;
1448 struct orl *map;
1449 unsigned int orl_count;
1450 int stridx;
1452 struct xcoff_ar_hdr hdr;
1453 char *p;
1454 unsigned char buf[4];
1455 bfd *sub;
1456 file_ptr fileoff;
1457 unsigned int i;
1459 memset (&hdr, 0, sizeof hdr);
1460 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1461 sprintf (hdr.nextoff, "%d", 0);
1462 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
1463 sprintf (hdr.date, "%d", 0);
1464 sprintf (hdr.uid, "%d", 0);
1465 sprintf (hdr.gid, "%d", 0);
1466 sprintf (hdr.mode, "%d", 0);
1467 sprintf (hdr.namlen, "%d", 0);
1469 /* We need spaces, not null bytes, in the header. */
1470 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1471 if (*p == '\0')
1472 *p = ' ';
1474 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
1475 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
1476 return false;
1478 bfd_h_put_32 (abfd, orl_count, buf);
1479 if (bfd_write (buf, 1, 4, abfd) != 4)
1480 return false;
1482 sub = abfd->archive_head;
1483 fileoff = SIZEOF_AR_FILE_HDR;
1484 i = 0;
1485 while (sub != NULL && i < orl_count)
1487 size_t namlen;
1489 while (((bfd *) (map[i]).pos) == sub)
1491 bfd_h_put_32 (abfd, fileoff, buf);
1492 if (bfd_write (buf, 1, 4, abfd) != 4)
1493 return false;
1494 ++i;
1496 namlen = strlen (normalize_filename (sub));
1497 namlen = (namlen + 1) &~ 1;
1498 fileoff += (SIZEOF_AR_HDR
1499 + namlen
1500 + SXCOFFARFMAG
1501 + arelt_size (sub));
1502 fileoff = (fileoff + 1) &~ 1;
1503 sub = sub->next;
1506 for (i = 0; i < orl_count; i++)
1508 const char *name;
1509 size_t namlen;
1511 name = *map[i].name;
1512 namlen = strlen (name);
1513 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1514 return false;
1517 if ((stridx & 1) != 0)
1519 char b;
1521 b = '\0';
1522 if (bfd_write (&b, 1, 1, abfd) != 1)
1523 return false;
1526 return true;
1529 /* Write a single armap in the big format. */
1530 static boolean
1531 xcoff_write_one_armap_big (abfd, map, orl_count, orl_ccount, stridx, bits64,
1532 prevoff, nextoff)
1533 bfd *abfd;
1534 struct orl *map;
1535 unsigned int orl_count;
1536 unsigned int orl_ccount;
1537 unsigned int stridx;
1538 int bits64;
1539 const char *prevoff;
1540 char *nextoff;
1542 struct xcoff_ar_hdr_big hdr;
1543 char *p;
1544 unsigned char buf[4];
1545 bfd *sub;
1546 file_ptr fileoff;
1547 const bfd_arch_info_type *arch_info;
1548 bfd *object_bfd;
1549 unsigned int i;
1551 memset (&hdr, 0, sizeof hdr);
1552 /* XXX This call actually should use %lld (at least on 32-bit
1553 machines) since the fields's width is 20 and there numbers with
1554 more than 32 bits can be represented. */
1555 sprintf (hdr.size, "%ld", (long) (4 + orl_ccount * 4 + stridx));
1556 if (bits64) {
1557 sprintf (hdr.nextoff, "%d", 0);
1558 } else {
1559 /* do explict cast to long to remove compiler warning */
1560 sprintf (hdr.nextoff, "%ld", (strtol (prevoff, (char **) NULL, 10)
1561 + (long) (4 + orl_ccount * 4 + stridx)));
1564 memcpy (hdr.prevoff, prevoff, sizeof (hdr.prevoff));
1565 sprintf (hdr.date, "%d", 0);
1566 sprintf (hdr.uid, "%d", 0);
1567 sprintf (hdr.gid, "%d", 0);
1568 sprintf (hdr.mode, "%d", 0);
1569 sprintf (hdr.namlen, "%d", 0);
1571 /* We need spaces, not null bytes, in the header. */
1572 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++)
1573 if (*p == '\0')
1574 *p = ' ';
1576 memcpy (nextoff, hdr.nextoff, sizeof (hdr.nextoff));
1578 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG
1579 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
1580 return false;
1582 bfd_h_put_32 (abfd, orl_ccount, buf);
1583 if (bfd_write (buf, 1, 4, abfd) != 4)
1584 return false;
1586 sub = abfd->archive_head;
1587 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1588 i = 0;
1589 while (sub != NULL && i < orl_count)
1591 size_t namlen;
1593 if ((bfd_arch_bits_per_address ((bfd *) map[i].pos) == 64) == bits64)
1594 while (((bfd *) (map[i]).pos) == sub)
1596 bfd_h_put_32 (abfd, fileoff, buf);
1597 if (bfd_write (buf, 1, 4, abfd) != 4)
1598 return false;
1599 i++;
1601 else
1602 while (((bfd *) (map[i]).pos) == sub)
1603 i++;
1605 namlen = strlen (normalize_filename (sub));
1606 namlen = (namlen + 1) &~ 1;
1607 fileoff += (SIZEOF_AR_HDR_BIG
1608 + namlen
1609 + SXCOFFARFMAG
1610 + arelt_size (sub));
1611 fileoff = (fileoff + 1) &~ 1;
1612 sub = sub->next;
1615 object_bfd = NULL;
1616 for (i = 0; i < orl_count; i++)
1618 const char *name;
1619 size_t namlen;
1620 bfd *ob = (bfd *)map[i].pos;
1622 if (ob != object_bfd)
1623 arch_info = bfd_get_arch_info (ob);
1624 if ((arch_info->bits_per_address == 64) != bits64)
1625 continue;
1627 name = *map[i].name;
1628 namlen = strlen (name);
1629 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1630 return false;
1633 if ((stridx & 1) != 0)
1635 char b;
1637 b = '\0';
1638 if (bfd_write (&b, 1, 1, abfd) != 1)
1639 return false;
1642 return true;
1645 /*ARGSUSED*/
1646 static boolean
1647 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1648 bfd *abfd;
1649 unsigned int elength ATTRIBUTE_UNUSED;
1650 struct orl *map;
1651 unsigned int orl_count;
1652 int stridx;
1654 unsigned int i;
1655 unsigned int orl_count_32, orl_count_64;
1656 unsigned int stridx_32, stridx_64;
1657 const bfd_arch_info_type *arch_info;
1658 bfd *object_bfd;
1660 /* First, we look through the symbols and work out which are
1661 from 32-bit objects and which from 64-bit ones. */
1662 orl_count_32 = 0;
1663 orl_count_64 = 0;
1664 stridx_32 = 0;
1665 stridx_64 = 0;
1666 object_bfd = NULL;
1667 for (i = 0; i < orl_count; i++)
1669 bfd *ob = (bfd *)map[i].pos;
1670 unsigned int len;
1671 if (ob != object_bfd)
1672 arch_info = bfd_get_arch_info (ob);
1673 len = strlen (*map[i].name) + 1;
1674 if (arch_info->bits_per_address == 64)
1676 orl_count_64++;
1677 stridx_64 += len;
1679 else
1681 orl_count_32++;
1682 stridx_32 += len;
1684 object_bfd = ob;
1686 /* A quick sanity check... */
1687 BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count);
1688 /* explicit cast to int for compiler */
1689 BFD_ASSERT ((int)(stridx_64 + stridx_32) == stridx);
1691 /* Now write out each map. */
1692 if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32,
1693 stridx_32, false,
1694 xcoff_ardata_big (abfd)->memoff,
1695 xcoff_ardata_big (abfd)->symoff))
1696 return false;
1697 if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64,
1698 stridx_64, true,
1699 xcoff_ardata_big (abfd)->symoff,
1700 xcoff_ardata_big (abfd)->symoff64))
1701 return false;
1703 return true;
1706 /*ARGSUSED*/
1707 boolean
1708 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
1709 bfd *abfd;
1710 unsigned int elength ATTRIBUTE_UNUSED;
1711 struct orl *map;
1712 unsigned int orl_count;
1713 int stridx;
1715 if (! xcoff_big_format_p (abfd))
1716 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
1717 else
1718 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
1721 /* Write out an XCOFF archive. We always write an entire archive,
1722 rather than fussing with the freelist and so forth. */
1724 static boolean
1725 xcoff_write_archive_contents_old (abfd)
1726 bfd *abfd;
1728 struct xcoff_ar_file_hdr fhdr;
1729 size_t count;
1730 size_t total_namlen;
1731 file_ptr *offsets;
1732 boolean makemap;
1733 boolean hasobjects;
1734 file_ptr prevoff, nextoff;
1735 bfd *sub;
1736 unsigned int i;
1737 struct xcoff_ar_hdr ahdr;
1738 bfd_size_type size;
1739 char *p;
1740 char decbuf[13];
1742 memset (&fhdr, 0, sizeof fhdr);
1743 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
1744 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
1745 sprintf (fhdr.freeoff, "%d", 0);
1747 count = 0;
1748 total_namlen = 0;
1749 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1751 ++count;
1752 total_namlen += strlen (normalize_filename (sub)) + 1;
1754 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
1755 if (offsets == NULL)
1756 return false;
1758 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
1759 return false;
1761 makemap = bfd_has_map (abfd);
1762 hasobjects = false;
1763 prevoff = 0;
1764 nextoff = SIZEOF_AR_FILE_HDR;
1765 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
1767 const char *name;
1768 size_t namlen;
1769 struct xcoff_ar_hdr *ahdrp;
1770 bfd_size_type remaining;
1772 if (makemap && ! hasobjects)
1774 if (bfd_check_format (sub, bfd_object))
1775 hasobjects = true;
1778 name = normalize_filename (sub);
1779 namlen = strlen (name);
1781 if (sub->arelt_data != NULL)
1782 ahdrp = arch_xhdr (sub);
1783 else
1784 ahdrp = NULL;
1786 if (ahdrp == NULL)
1788 struct stat s;
1790 memset (&ahdr, 0, sizeof ahdr);
1791 ahdrp = &ahdr;
1792 if (stat (bfd_get_filename (sub), &s) != 0)
1794 bfd_set_error (bfd_error_system_call);
1795 return false;
1798 sprintf (ahdrp->size, "%ld", (long) s.st_size);
1799 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
1800 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
1801 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
1802 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
1804 if (sub->arelt_data == NULL)
1806 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
1807 if (sub->arelt_data == NULL)
1808 return false;
1811 arch_eltdata (sub)->parsed_size = s.st_size;
1814 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
1815 sprintf (ahdrp->namlen, "%ld", (long) namlen);
1817 /* If the length of the name is odd, we write out the null byte
1818 after the name as well. */
1819 namlen = (namlen + 1) &~ 1;
1821 remaining = arelt_size (sub);
1822 size = (SIZEOF_AR_HDR
1823 + namlen
1824 + SXCOFFARFMAG
1825 + remaining);
1827 BFD_ASSERT (nextoff == bfd_tell (abfd));
1829 offsets[i] = nextoff;
1831 prevoff = nextoff;
1832 nextoff += size + (size & 1);
1834 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
1836 /* We need spaces, not null bytes, in the header. */
1837 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
1838 if (*p == '\0')
1839 *p = ' ';
1841 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1842 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
1843 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1844 != SXCOFFARFMAG))
1845 return false;
1847 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
1848 return false;
1849 while (remaining != 0)
1851 bfd_size_type amt;
1852 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1854 amt = sizeof buffer;
1855 if (amt > remaining)
1856 amt = remaining;
1857 if (bfd_read (buffer, 1, amt, sub) != amt
1858 || bfd_write (buffer, 1, amt, abfd) != amt)
1859 return false;
1860 remaining -= amt;
1863 if ((size & 1) != 0)
1865 bfd_byte b;
1867 b = '\0';
1868 if (bfd_write (&b, 1, 1, abfd) != 1)
1869 return false;
1873 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
1875 /* Write out the member table. */
1877 BFD_ASSERT (nextoff == bfd_tell (abfd));
1878 sprintf (fhdr.memoff, "%ld", (long) nextoff);
1880 memset (&ahdr, 0, sizeof ahdr);
1881 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
1882 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
1883 sprintf (ahdr.date, "%d", 0);
1884 sprintf (ahdr.uid, "%d", 0);
1885 sprintf (ahdr.gid, "%d", 0);
1886 sprintf (ahdr.mode, "%d", 0);
1887 sprintf (ahdr.namlen, "%d", 0);
1889 size = (SIZEOF_AR_HDR
1890 + 12
1891 + count * 12
1892 + total_namlen
1893 + SXCOFFARFMAG);
1895 prevoff = nextoff;
1896 nextoff += size + (size & 1);
1898 if (makemap && hasobjects)
1899 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
1900 else
1901 sprintf (ahdr.nextoff, "%d", 0);
1903 /* We need spaces, not null bytes, in the header. */
1904 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
1905 if (*p == '\0')
1906 *p = ' ';
1908 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1909 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1910 != SXCOFFARFMAG))
1911 return false;
1913 sprintf (decbuf, "%-12ld", (long) count);
1914 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1915 return false;
1916 for (i = 0; i < count; i++)
1918 sprintf (decbuf, "%-12ld", (long) offsets[i]);
1919 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1920 return false;
1922 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1924 const char *name;
1925 size_t namlen;
1927 name = normalize_filename (sub);
1928 namlen = strlen (name);
1929 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
1930 return false;
1932 if ((size & 1) != 0)
1934 bfd_byte b;
1936 b = '\0';
1937 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
1938 return false;
1941 /* Write out the armap, if appropriate. */
1943 if (! makemap || ! hasobjects)
1944 sprintf (fhdr.symoff, "%d", 0);
1945 else
1947 BFD_ASSERT (nextoff == bfd_tell (abfd));
1948 sprintf (fhdr.symoff, "%ld", (long) nextoff);
1949 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
1950 if (! _bfd_compute_and_write_armap (abfd, 0))
1951 return false;
1954 /* Write out the archive file header. */
1956 /* We need spaces, not null bytes, in the header. */
1957 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
1958 if (*p == '\0')
1959 *p = ' ';
1961 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1962 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
1963 SIZEOF_AR_FILE_HDR))
1964 return false;
1966 return true;
1969 static boolean
1970 xcoff_write_archive_contents_big (abfd)
1971 bfd *abfd;
1973 struct xcoff_ar_file_hdr_big fhdr;
1974 size_t count;
1975 size_t total_namlen;
1976 file_ptr *offsets;
1977 boolean makemap;
1978 boolean hasobjects;
1979 file_ptr prevoff, nextoff;
1980 bfd *sub;
1981 unsigned int i;
1982 struct xcoff_ar_hdr_big ahdr;
1983 bfd_size_type size;
1984 char *p;
1985 char decbuf[13];
1987 memset (&fhdr, 0, sizeof fhdr);
1988 strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
1989 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG);
1990 sprintf (fhdr.freeoff, "%d", 0);
1992 count = 0;
1993 total_namlen = 0;
1994 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1996 ++count;
1997 total_namlen += strlen (normalize_filename (sub)) + 1;
1999 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2000 if (offsets == NULL)
2001 return false;
2003 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2004 return false;
2006 makemap = bfd_has_map (abfd);
2007 hasobjects = false;
2008 prevoff = 0;
2009 nextoff = SIZEOF_AR_FILE_HDR_BIG;
2010 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
2012 const char *name;
2013 size_t namlen;
2014 struct xcoff_ar_hdr_big *ahdrp;
2015 bfd_size_type remaining;
2017 if (makemap && ! hasobjects)
2019 if (bfd_check_format (sub, bfd_object))
2020 hasobjects = true;
2023 name = normalize_filename (sub);
2024 namlen = strlen (name);
2026 if (sub->arelt_data != NULL)
2027 ahdrp = arch_xhdr_big (sub);
2028 else
2029 ahdrp = NULL;
2031 if (ahdrp == NULL)
2033 struct stat s;
2035 memset (&ahdr, 0, sizeof ahdr);
2036 ahdrp = &ahdr;
2037 /* XXX This should actually be a call to stat64 (at least on
2038 32-bit machines). */
2039 if (stat (bfd_get_filename (sub), &s) != 0)
2041 bfd_set_error (bfd_error_system_call);
2042 return false;
2045 /* XXX This call actually should use %lld (at least on 32-bit
2046 machines) since the fields's width is 20 and there numbers with
2047 more than 32 bits can be represented. */
2048 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2049 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2050 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2051 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2052 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2054 if (sub->arelt_data == NULL)
2056 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
2057 if (sub->arelt_data == NULL)
2058 return false;
2061 arch_eltdata (sub)->parsed_size = s.st_size;
2064 /* XXX These calls actually should use %lld (at least on 32-bit
2065 machines) since the fields's width is 20 and there numbers with
2066 more than 32 bits can be represented. */
2067 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2068 sprintf (ahdrp->namlen, "%ld", (long) namlen);
2070 /* If the length of the name is odd, we write out the null byte
2071 after the name as well. */
2072 namlen = (namlen + 1) &~ 1;
2074 remaining = arelt_size (sub);
2075 size = (SIZEOF_AR_HDR_BIG
2076 + namlen
2077 + SXCOFFARFMAG
2078 + remaining);
2080 BFD_ASSERT (nextoff == bfd_tell (abfd));
2082 offsets[i] = nextoff;
2084 prevoff = nextoff;
2085 nextoff += size + (size & 1);
2087 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
2089 /* We need spaces, not null bytes, in the header. */
2090 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++)
2091 if (*p == '\0')
2092 *p = ' ';
2094 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd)
2095 != SIZEOF_AR_HDR_BIG
2096 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
2097 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
2098 != SXCOFFARFMAG))
2099 return false;
2101 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
2102 return false;
2103 while (remaining != 0)
2105 bfd_size_type amt;
2106 bfd_byte buffer[DEFAULT_BUFFERSIZE];
2108 amt = sizeof buffer;
2109 if (amt > remaining)
2110 amt = remaining;
2111 if (bfd_read (buffer, 1, amt, sub) != amt
2112 || bfd_write (buffer, 1, amt, abfd) != amt)
2113 return false;
2114 remaining -= amt;
2117 if ((size & 1) != 0)
2119 bfd_byte b;
2121 b = '\0';
2122 if (bfd_write (&b, 1, 1, abfd) != 1)
2123 return false;
2127 /* XXX This call actually should use %lld (at least on 32-bit
2128 machines) since the fields's width is 20 and there numbers with
2129 more than 32 bits can be represented. */
2130 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2132 /* Write out the member table. */
2134 BFD_ASSERT (nextoff == bfd_tell (abfd));
2135 /* XXX This call actually should use %lld (at least on 32-bit
2136 machines) since the fields's width is 20 and there numbers with
2137 more than 32 bits can be represented. */
2138 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2140 memset (&ahdr, 0, sizeof ahdr);
2141 /* XXX The next two calls actually should use %lld (at least on 32-bit
2142 machines) since the fields's width is 20 and there numbers with
2143 more than 32 bits can be represented. */
2144 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
2145 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2146 sprintf (ahdr.date, "%d", 0);
2147 sprintf (ahdr.uid, "%d", 0);
2148 sprintf (ahdr.gid, "%d", 0);
2149 sprintf (ahdr.mode, "%d", 0);
2150 sprintf (ahdr.namlen, "%d", 0);
2152 size = (SIZEOF_AR_HDR_BIG
2153 + 12
2154 + count * 12
2155 + total_namlen
2156 + SXCOFFARFMAG);
2158 prevoff = nextoff;
2159 nextoff += size + (size & 1);
2161 if (makemap && hasobjects)
2162 /* XXX This call actually should use %lld (at least on 32-bit
2163 machines) since the fields's width is 20 and there numbers with
2164 more than 32 bits can be represented. */
2165 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2166 else
2167 sprintf (ahdr.nextoff, "%d", 0);
2169 /* We need spaces, not null bytes, in the header. */
2170 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++)
2171 if (*p == '\0')
2172 *p = ' ';
2174 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2175 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
2176 != SXCOFFARFMAG))
2177 return false;
2179 sprintf (decbuf, "%-12ld", (long) count);
2180 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
2181 return false;
2182 for (i = 0; i < count; i++)
2184 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2185 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
2186 return false;
2188 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2190 const char *name;
2191 size_t namlen;
2193 name = normalize_filename (sub);
2194 namlen = strlen (name);
2195 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
2196 return false;
2198 if ((size & 1) != 0)
2200 bfd_byte b;
2202 b = '\0';
2203 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
2204 return false;
2207 /* Write out the armap, if appropriate. */
2209 if (! makemap || ! hasobjects)
2210 sprintf (fhdr.symoff, "%d", 0);
2211 else
2213 BFD_ASSERT (nextoff == bfd_tell (abfd));
2214 /* XXX This call actually should use %lld (at least on 32-bit
2215 machines) since the fields's width is 20 and there numbers with
2216 more than 32 bits can be represented. */
2217 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2218 if (! _bfd_compute_and_write_armap (abfd, 0))
2219 return false;
2222 /* Write out the archive file header. */
2224 /* We need spaces, not null bytes, in the header. */
2225 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++)
2226 if (*p == '\0')
2227 *p = ' ';
2229 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2230 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) !=
2231 SIZEOF_AR_FILE_HDR_BIG))
2232 return false;
2234 return true;
2237 boolean
2238 _bfd_xcoff_write_archive_contents (abfd)
2239 bfd *abfd;
2241 if (! xcoff_big_format_p (abfd))
2242 return xcoff_write_archive_contents_old (abfd);
2243 else
2244 return xcoff_write_archive_contents_big (abfd);
2247 /* We can't use the usual coff_sizeof_headers routine, because AIX
2248 always uses an a.out header. */
2250 /*ARGSUSED*/
2252 _bfd_xcoff_sizeof_headers (abfd, reloc)
2253 bfd *abfd;
2254 boolean reloc ATTRIBUTE_UNUSED;
2256 int size;
2258 size = FILHSZ;
2259 if (xcoff_data (abfd)->full_aouthdr)
2260 size += AOUTSZ;
2261 else
2262 size += SMALL_AOUTSZ;
2263 size += abfd->section_count * SCNHSZ;
2264 return size;
2267 /* Routines to swap information in the XCOFF .loader section. If we
2268 ever need to write an XCOFF loader, this stuff will need to be
2269 moved to another file shared by the linker (which XCOFF calls the
2270 ``binder'') and the loader. */
2272 /* Swap in the ldhdr structure. */
2274 static void
2275 xcoff_swap_ldhdr_in (abfd, src, dst)
2276 bfd *abfd;
2277 const struct external_ldhdr *src;
2278 struct internal_ldhdr *dst;
2280 dst->l_version = bfd_get_32 (abfd, src->l_version);
2281 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2282 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2283 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2284 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2285 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2286 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2287 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2290 /* Swap out the ldhdr structure. */
2292 static void
2293 xcoff_swap_ldhdr_out (abfd, src, dst)
2294 bfd *abfd;
2295 const struct internal_ldhdr *src;
2296 struct external_ldhdr *dst;
2298 bfd_put_32 (abfd, src->l_version, dst->l_version);
2299 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2300 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2301 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2302 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2303 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2304 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2305 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2308 /* Swap in the ldsym structure. */
2310 static void
2311 xcoff_swap_ldsym_in (abfd, src, dst)
2312 bfd *abfd;
2313 const struct external_ldsym *src;
2314 struct internal_ldsym *dst;
2316 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2317 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2318 } else {
2319 dst->_l._l_l._l_zeroes = 0;
2320 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2322 dst->l_value = bfd_get_32 (abfd, src->l_value);
2323 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2324 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2325 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2326 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2327 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2330 /* Swap out the ldsym structure. */
2332 static void
2333 xcoff_swap_ldsym_out (abfd, src, dst)
2334 bfd *abfd;
2335 const struct internal_ldsym *src;
2336 struct external_ldsym *dst;
2339 if (src->_l._l_l._l_zeroes != 0)
2340 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2341 else
2343 bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes);
2344 bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset);
2346 bfd_put_32 (abfd, src->l_value, dst->l_value);
2347 bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
2348 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2349 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2350 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2351 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2354 /* Swap in the ldrel structure. */
2356 static void
2357 xcoff_swap_ldrel_in (abfd, src, dst)
2358 bfd *abfd;
2359 const struct external_ldrel *src;
2360 struct internal_ldrel *dst;
2362 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2363 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2364 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2365 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2368 /* Swap out the ldrel structure. */
2370 static void
2371 xcoff_swap_ldrel_out (abfd, src, dst)
2372 bfd *abfd;
2373 const struct internal_ldrel *src;
2374 struct external_ldrel *dst;
2376 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2377 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2378 bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
2379 bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
2384 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2385 This is currently the only processor which uses XCOFF; I hope that
2386 will never change. */
2388 static boolean
2389 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
2390 input_section, contents, relocs, syms,
2391 sections)
2392 bfd *output_bfd;
2393 struct bfd_link_info *info;
2394 bfd *input_bfd;
2395 asection *input_section;
2396 bfd_byte *contents;
2397 struct internal_reloc *relocs;
2398 struct internal_syment *syms;
2399 asection **sections;
2401 struct internal_reloc *rel;
2402 struct internal_reloc *relend;
2404 rel = relocs;
2405 relend = rel + input_section->reloc_count;
2407 for (; rel < relend; rel++)
2409 long symndx;
2410 struct xcoff_link_hash_entry *h;
2411 struct internal_syment *sym;
2412 bfd_vma addend;
2413 bfd_vma val;
2414 struct reloc_howto_struct howto;
2415 bfd_reloc_status_type rstat;
2417 /* Relocation type R_REF is a special relocation type which is
2418 merely used to prevent garbage collection from occurring for
2419 the csect including the symbol which it references. */
2420 if (rel->r_type == R_REF)
2421 continue;
2423 symndx = rel->r_symndx;
2425 if (symndx == -1)
2427 h = NULL;
2428 sym = NULL;
2429 addend = 0;
2431 else
2433 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
2434 sym = syms + symndx;
2435 addend = - sym->n_value;
2439 /* We build the howto information on the fly. */
2441 howto.type = rel->r_type;
2442 howto.rightshift = 0;
2443 howto.size = 2;
2444 howto.bitsize = (rel->r_size & 0x1f) + 1;
2445 howto.pc_relative = false;
2446 howto.bitpos = 0;
2447 if ((rel->r_size & 0x80) != 0)
2448 howto.complain_on_overflow = complain_overflow_signed;
2449 else
2450 howto.complain_on_overflow = complain_overflow_bitfield;
2451 howto.special_function = NULL;
2452 howto.name = "internal";
2453 howto.partial_inplace = true;
2454 if (howto.bitsize == 32)
2455 howto.src_mask = howto.dst_mask = 0xffffffff;
2456 else
2458 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
2459 if (howto.bitsize == 16)
2460 howto.size = 1;
2462 howto.pcrel_offset = false;
2464 val = 0;
2466 if (h == NULL)
2468 asection *sec;
2470 if (symndx == -1)
2472 sec = bfd_abs_section_ptr;
2473 val = 0;
2475 else
2477 sec = sections[symndx];
2478 /* Hack to make sure we use the right TOC anchor value
2479 if this reloc is against the TOC anchor. */
2481 if (sec->name[3] == '0'
2482 && strcmp (sec->name, ".tc0") == 0) {
2484 val = xcoff_data (output_bfd)->toc;
2485 } else {
2487 val = (sec->output_section->vma
2488 + sec->output_offset
2489 + sym->n_value
2490 - sec->vma);
2495 else
2497 if (h->root.type == bfd_link_hash_defined
2498 || h->root.type == bfd_link_hash_defweak)
2500 asection *sec;
2502 sec = h->root.u.def.section;
2503 val = (h->root.u.def.value
2504 + sec->output_section->vma
2505 + sec->output_offset);
2507 else if (h->root.type == bfd_link_hash_common)
2509 asection *sec;
2511 sec = h->root.u.c.p->section;
2512 val = (sec->output_section->vma
2513 + sec->output_offset);
2515 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
2516 || (h->flags & XCOFF_IMPORT) != 0)
2518 /* Every symbol in a shared object is defined somewhere. */
2519 val = 0;
2521 else if (! info->relocateable)
2523 if (! ((*info->callbacks->undefined_symbol)
2524 (info, h->root.root.string, input_bfd, input_section,
2525 rel->r_vaddr - input_section->vma, true)))
2526 return false;
2528 /* Don't try to process the reloc. It can't help, and
2529 it may generate another error. */
2530 continue;
2534 /* I took the relocation type definitions from two documents:
2535 the PowerPC AIX Version 4 Application Binary Interface, First
2536 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2537 32-Bit Hardware Implementation (June 30, 1994). Differences
2538 between the documents are noted below. */
2540 switch (rel->r_type)
2542 case R_RTB:
2543 case R_RRTBI:
2544 case R_RRTBA:
2545 /* These relocs are defined by the PowerPC ABI to be
2546 relative branches which use half of the difference
2547 between the symbol and the program counter. I can't
2548 quite figure out when this is useful. These relocs are
2549 not defined by the PowerOpen ABI. */
2550 default:
2551 (*_bfd_error_handler)
2552 (_("%s: unsupported relocation type 0x%02x"),
2553 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2554 bfd_set_error (bfd_error_bad_value);
2555 return false;
2556 case R_POS:
2557 /* Simple positive relocation. */
2558 break;
2559 case R_NEG:
2560 /* Simple negative relocation. */
2561 val = - val;
2562 break;
2563 case R_REL:
2564 /* Simple PC relative relocation. */
2565 howto.pc_relative = true;
2566 break;
2567 case R_TOC:
2568 /* TOC relative relocation. The value in the instruction in
2569 the input file is the offset from the input file TOC to
2570 the desired location. We want the offset from the final
2571 TOC to the desired location. We have:
2572 isym = iTOC + in
2573 iinsn = in + o
2574 osym = oTOC + on
2575 oinsn = on + o
2576 so we must change insn by on - in.
2578 case R_GL:
2579 /* Global linkage relocation. The value of this relocation
2580 is the address of the entry in the TOC section. */
2581 case R_TCL:
2582 /* Local object TOC address. I can't figure out the
2583 difference between this and case R_GL. */
2584 case R_TRL:
2585 /* TOC relative relocation. A TOC relative load instruction
2586 which may be changed to a load address instruction.
2587 FIXME: We don't currently implement this optimization. */
2588 case R_TRLA:
2589 /* TOC relative relocation. This is a TOC relative load
2590 address instruction which may be changed to a load
2591 instruction. FIXME: I don't know if this is the correct
2592 implementation. */
2593 if (h != NULL && h->smclas != XMC_TD)
2595 if (h->toc_section == NULL)
2597 (*_bfd_error_handler)
2598 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2599 bfd_get_filename (input_bfd), rel->r_vaddr,
2600 h->root.root.string);
2601 bfd_set_error (bfd_error_bad_value);
2602 return false;
2605 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2606 val = (h->toc_section->output_section->vma
2607 + h->toc_section->output_offset);
2610 val = ((val - xcoff_data (output_bfd)->toc)
2611 - (sym->n_value - xcoff_data (input_bfd)->toc));
2612 addend = 0;
2613 break;
2614 case R_BA:
2615 /* Absolute branch. We don't want to mess with the lower
2616 two bits of the instruction. */
2617 case R_CAI:
2618 /* The PowerPC ABI defines this as an absolute call which
2619 may be modified to become a relative call. The PowerOpen
2620 ABI does not define this relocation type. */
2621 case R_RBA:
2622 /* Absolute branch which may be modified to become a
2623 relative branch. */
2624 case R_RBAC:
2625 /* The PowerPC ABI defines this as an absolute branch to a
2626 fixed address which may be modified to an absolute branch
2627 to a symbol. The PowerOpen ABI does not define this
2628 relocation type. */
2629 case R_RBRC:
2630 /* The PowerPC ABI defines this as an absolute branch to a
2631 fixed address which may be modified to a relative branch.
2632 The PowerOpen ABI does not define this relocation type. */
2633 howto.src_mask &= ~3;
2634 howto.dst_mask = howto.src_mask;
2635 break;
2636 case R_BR:
2637 /* Relative branch. We don't want to mess with the lower
2638 two bits of the instruction. */
2639 case R_CREL:
2640 /* The PowerPC ABI defines this as a relative call which may
2641 be modified to become an absolute call. The PowerOpen
2642 ABI does not define this relocation type. */
2643 case R_RBR:
2644 /* A relative branch which may be modified to become an
2645 absolute branch. FIXME: We don't implement this,
2646 although we should for symbols of storage mapping class
2647 XMC_XO. */
2648 howto.pc_relative = true;
2649 howto.src_mask &= ~3;
2650 howto.dst_mask = howto.src_mask;
2651 break;
2652 case R_RL:
2653 /* The PowerPC AIX ABI describes this as a load which may be
2654 changed to a load address. The PowerOpen ABI says this
2655 is the same as case R_POS. */
2656 break;
2657 case R_RLA:
2658 /* The PowerPC AIX ABI describes this as a load address
2659 which may be changed to a load. The PowerOpen ABI says
2660 this is the same as R_POS. */
2661 break;
2664 /* If we see an R_BR or R_RBR reloc which is jumping to global
2665 linkage code, and it is followed by an appropriate cror nop
2666 instruction, we replace the cror with lwz r2,20(r1). This
2667 restores the TOC after the glink code. Contrariwise, if the
2668 call is followed by a lwz r2,20(r1), but the call is not
2669 going to global linkage code, we can replace the load with a
2670 cror. */
2671 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
2672 && h != NULL
2673 && h->root.type == bfd_link_hash_defined
2674 && (rel->r_vaddr - input_section->vma + 8
2675 <= input_section->_cooked_size))
2677 bfd_byte *pnext;
2678 unsigned long next;
2680 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2681 next = bfd_get_32 (input_bfd, pnext);
2683 /* The _ptrgl function is magic. It is used by the AIX
2684 compiler to call a function through a pointer. */
2685 if (h->smclas == XMC_GL
2686 || strcmp (h->root.root.string, "._ptrgl") == 0)
2688 if (next == 0x4def7b82 /* cror 15,15,15 */
2689 || next == 0x4ffffb82 /* cror 31,31,31 */
2690 || next == 0x60000000) /* ori r0,r0,0 */
2691 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2693 else
2695 if (next == 0x80410014) /* lwz r1,20(r1) */
2696 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2700 /* A PC relative reloc includes the section address. */
2701 if (howto.pc_relative)
2702 addend += input_section->vma;
2704 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
2705 contents,
2706 rel->r_vaddr - input_section->vma,
2707 val, addend);
2709 switch (rstat)
2711 default:
2712 abort ();
2713 case bfd_reloc_ok:
2714 break;
2715 case bfd_reloc_overflow:
2717 const char *name;
2718 char buf[SYMNMLEN + 1];
2719 char howto_name[10];
2721 if (symndx == -1)
2722 name = "*ABS*";
2723 else if (h != NULL)
2724 name = h->root.root.string;
2725 else
2728 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
2730 if (name == NULL)
2731 return false;
2733 sprintf (howto_name, "0x%02x", rel->r_type);
2735 if (! ((*info->callbacks->reloc_overflow)
2736 (info, name, howto_name, (bfd_vma) 0, input_bfd,
2737 input_section, rel->r_vaddr - input_section->vma)))
2738 return false;
2743 return true;
2746 static boolean
2747 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
2748 bfd *abfd ATTRIBUTE_UNUSED;
2749 struct xcoff_loader_info *ldinfo;
2750 struct internal_ldsym *ldsym;
2751 const char *name;
2753 size_t len;
2754 len = strlen (name);
2756 if (len <= SYMNMLEN)
2757 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
2758 else
2760 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
2762 size_t newalc;
2763 bfd_byte *newstrings;
2765 newalc = ldinfo->string_alc * 2;
2766 if (newalc == 0)
2767 newalc = 32;
2768 while (ldinfo->string_size + len + 3 > newalc)
2769 newalc *= 2;
2771 newstrings = ((bfd_byte *)
2772 bfd_realloc ((PTR) ldinfo->strings, newalc));
2773 if (newstrings == NULL)
2775 ldinfo->failed = true;
2776 return false;
2778 ldinfo->string_alc = newalc;
2779 ldinfo->strings = newstrings;
2782 bfd_put_16 (ldinfo->output_bfd, len + 1,
2783 ldinfo->strings + ldinfo->string_size);
2784 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
2785 ldsym->_l._l_l._l_zeroes = 0;
2786 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
2787 ldinfo->string_size += len + 3;
2790 return true;
2793 static boolean
2794 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
2795 struct internal_syment *sym,
2796 const char *name) {
2798 if (strlen (name) <= SYMNMLEN) {
2799 strncpy (sym->_n._n_name, name, SYMNMLEN);
2800 } else {
2801 boolean hash;
2802 bfd_size_type indx;
2804 hash = true;
2805 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
2806 hash = false;
2807 indx = _bfd_stringtab_add (strtab, name, hash, false);
2808 if (indx == (bfd_size_type) -1)
2809 return false;
2810 sym->_n._n_n._n_zeroes = 0;
2811 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
2813 return true;
2816 static asection *
2817 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
2818 bfd *abfd;
2819 union internal_auxent *aux;
2820 char *symbol_name;
2823 asection *return_value = NULL;
2826 * .sv64 = x_smclas == 17
2827 * This is an invalid csect for 32 bit apps.
2829 static const char *names[19] = {
2830 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2831 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
2832 ".td", NULL, ".sv3264"
2835 if ((19 >= aux->x_csect.x_smclas) &&
2836 (NULL != names[aux->x_csect.x_smclas])) {
2838 return_value = bfd_make_section_anyway
2839 (abfd, names[aux->x_csect.x_smclas]);
2842 } else {
2843 (*_bfd_error_handler)
2844 (_("%s: symbol `%s' has unrecognized smclas %d"),
2845 bfd_get_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2846 bfd_set_error (bfd_error_bad_value);
2849 return return_value;
2852 static boolean
2853 xcoff_is_lineno_count_overflow (abfd, value)
2854 bfd *abfd ATTRIBUTE_UNUSED;
2855 bfd_vma value;
2857 if (0xffff <= value) {
2858 return true;
2860 return false;
2863 static boolean
2864 xcoff_is_reloc_count_overflow (abfd, value)
2865 bfd *abfd ATTRIBUTE_UNUSED;
2866 bfd_vma value;
2868 if (0xffff <= value) {
2869 return true;
2871 return false;
2874 static bfd_vma
2875 xcoff_loader_symbol_offset (abfd, ldhdr)
2876 bfd *abfd;
2877 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
2879 return bfd_xcoff_ldhdrsz(abfd);
2882 static bfd_vma
2883 xcoff_loader_reloc_offset (abfd, ldhdr)
2884 bfd *abfd;
2885 struct internal_ldhdr *ldhdr;
2887 return bfd_xcoff_ldhdrsz(abfd) +
2888 (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd));
2892 static reloc_howto_type xcoff_dynamic_reloc =
2893 HOWTO (0, /* type */
2894 0, /* rightshift */
2895 2, /* size (0 = byte, 1 = short, 2 = long) */
2896 32, /* bitsize */
2897 false, /* pc_relative */
2898 0, /* bitpos */
2899 complain_overflow_bitfield, /* complain_on_overflow */
2900 0, /* special_function */
2901 "R_POS", /* name */
2902 true, /* partial_inplace */
2903 0xffffffff, /* src_mask */
2904 0xffffffff, /* dst_mask */
2905 false); /* pcrel_offset */
2908 * glink
2910 * The first word of global linkage code must be modified by filling in
2911 * the correct TOC offset.
2913 static unsigned long xcoff_glink_code[9] =
2915 0x81820000, /* lwz r12,0(r2) */
2916 0x90410014, /* stw r2,20(r1) */
2917 0x800c0000, /* lwz r0,0(r12) */
2918 0x804c0004, /* lwz r2,4(r12) */
2919 0x7c0903a6, /* mtctr r0 */
2920 0x4e800420, /* bctr */
2921 0x00000000, /* start of traceback table */
2922 0x000c8000, /* traceback table */
2923 0x00000000, /* traceback table */
2927 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2929 { /* COFF backend, defined in libcoff.h */
2930 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
2931 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
2932 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2933 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
2934 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
2935 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
2936 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2937 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2938 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2939 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2940 FILHSZ, /* _bfd_filhsz */
2941 AOUTSZ, /* _bfd_aoutsz */
2942 SCNHSZ, /* _bfd_scnhsz */
2943 SYMESZ, /* _bfd_symesz */
2944 AUXESZ, /* _bfd_auxesz */
2945 RELSZ, /* _bfd_relsz */
2946 LINESZ, /* _bfd_linesz */
2947 FILNMLEN, /* _bfd_filnmlen */
2948 true, /* _bfd_coff_long_filenames */
2949 false, /* _bfd_coff_long_section_names */
2950 (3), /* _bfd_coff_default_section_alignment_power */
2951 false, /* _bfd_coff_force_symnames_in_strings */
2952 2, /* _bfd_coff_debug_string_prefix_length */
2953 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2954 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2955 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2956 coff_swap_reloc_in, /* _bfd_reloc_in */
2957 coff_bad_format_hook, /* _bfd_bad_format_hook */
2958 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2959 coff_mkobject_hook, /* _bfd_mkobject_hook */
2960 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2961 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2962 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2963 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2964 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2965 coff_print_aux, /* bfd_coff_print_aux */
2966 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2967 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2968 NULL, /* bfd_coff_sym_is_global */
2969 /* _bfd_coff_compute_section_file_positions */
2970 coff_compute_section_file_positions,
2971 NULL , /* _bfd_coff_start_final_link */
2972 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
2973 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2974 NULL , /* _bfd_coff_addust_symndx */
2975 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2976 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2977 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2980 0x01DF, /* magic number */
2981 bfd_arch_rs6000, /* architecture */
2982 bfd_mach_rs6k, /* machine */
2985 /* function pointers to xcoff specific swap routines */
2986 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2987 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2988 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
2989 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
2990 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
2991 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
2993 /* sizes */
2994 LDHDRSZ, /* _xcoff_ldhdrsz */
2995 LDSYMSZ, /* _xcoff_ldsymsz */
2996 LDRELSZ, /* _xcoff_ldrelsz */
2997 12, /* _xcoff_function_descriptor_size */
2998 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3000 /* versions */
3001 1, /* _xcoff_ldhdr_version */
3003 /* xcoff vs xcoff64 putting symbol names */
3004 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3005 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3007 &xcoff_dynamic_reloc, /* dynamic reloc howto */
3009 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3011 /* lineno and reloc count overflow */
3012 xcoff_is_lineno_count_overflow,
3013 xcoff_is_reloc_count_overflow,
3015 xcoff_loader_symbol_offset,
3016 xcoff_loader_reloc_offset,
3018 /* glink */
3019 &xcoff_glink_code[0],
3020 (36), /* _xcoff_glink_size */
3024 /* The transfer vector that leads the outside world to all of the above. */
3025 const bfd_target rs6000coff_vec =
3027 "aixcoff-rs6000",
3028 bfd_target_xcoff_flavour,
3029 BFD_ENDIAN_BIG, /* data byte order is big */
3030 BFD_ENDIAN_BIG, /* header byte order is big */
3032 (HAS_RELOC | EXEC_P | /* object flags */
3033 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3034 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3036 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3037 0, /* leading char */
3038 '/', /* ar_pad_char */
3039 15, /* ar_max_namelen??? FIXMEmgo */
3041 /* data */
3042 bfd_getb64, /* bfd_getx64 */
3043 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3044 bfd_putb64, /* bfd_putx64 */
3045 bfd_getb32, /* bfd_getx32 */
3046 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3047 bfd_putb32, /* bfd_putx32 */
3048 bfd_getb16, /* bfd_getx16 */
3049 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3050 bfd_putb16, /* bfd_putx16 */
3052 /* hdrs */
3053 bfd_getb64, /* bfd_h_getx64 */
3054 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3055 bfd_putb64, /* bfd_h_putx64 */
3056 bfd_getb32, /* bfd_h_getx32 */
3057 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3058 bfd_putb32, /* bfd_h_putx32 */
3059 bfd_getb16, /* bfd_h_getx16 */
3060 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3061 bfd_putb16, /* bfd_h_putx16 */
3063 { /* bfd_check_format */
3064 _bfd_dummy_target,
3065 coff_object_p,
3066 _bfd_xcoff_archive_p,
3067 CORE_FILE_P
3070 { /* bfd_set_format */
3071 bfd_false,
3072 coff_mkobject,
3073 _bfd_generic_mkarchive,
3074 bfd_false
3077 {/* bfd_write_contents */
3078 bfd_false,
3079 coff_write_object_contents,
3080 _bfd_xcoff_write_archive_contents,
3081 bfd_false
3084 /* Generic */
3085 bfd_true, /* _close_and_cleanup */
3086 bfd_true, /* _bfd_free_cached_info */
3087 coff_new_section_hook, /* _new_section_hook */
3088 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3089 /* _bfd_get_section_contents_in_window */
3090 _bfd_generic_get_section_contents_in_window,
3092 /* Copy */
3093 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3094 /* _bfd_merge_private_bfd_data */
3095 ((boolean (*) (bfd *, bfd *)) bfd_true),
3096 /* _bfd_copy_pivate_section_data */
3097 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3098 /* _bfd_copy_private_symbol_data */
3099 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3100 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3101 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3103 /* Core */
3104 coff_core_file_failing_command, /* _core_file_failing_command */
3105 coff_core_file_failing_signal, /* _core_file_failing_signal */
3106 /* _core_file_matches_executable_p */
3107 coff_core_file_matches_executable_p,
3109 /* Archive */
3110 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3111 /* XCOFF archives do not have
3112 anything which corresponds to
3113 an extended name table. */
3114 bfd_false, /* _slurp_extended_name_table */
3115 /* _construct_extended_name_table */
3116 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3117 bfd_dont_truncate_arname, /* _truncate_arname */
3118 _bfd_xcoff_write_armap, /* _write_armap */
3119 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3120 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3121 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3122 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3123 /* XCOFF archives do not have
3124 a timestamp. */
3125 bfd_true, /* _update_armap_timestamp */
3127 /* Symbols */
3128 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3129 coff_get_symtab, /* _get_symtab */
3130 coff_make_empty_symbol, /* _make_empty_symbol */
3131 coff_print_symbol, /* _print_symbol */
3132 coff_get_symbol_info, /* _get_symbol_info */
3133 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3134 coff_get_lineno, /* _get_lineno */
3135 coff_find_nearest_line, /* _find_nearest_line */
3136 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3137 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3138 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3140 /* Reloc */
3141 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3142 coff_canonicalize_reloc, /* _cononicalize_reloc */
3143 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3145 /* Write */
3146 coff_set_arch_mach, /* _set_arch_mach */
3147 coff_set_section_contents, /* _set_section_contents */
3149 /* Link */
3150 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3151 /* _bfd_get_relocated_section_contents */
3152 bfd_generic_get_relocated_section_contents,
3153 bfd_generic_relax_section, /* _bfd_relax_section */
3154 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3155 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3156 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3157 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3158 bfd_generic_gc_sections, /* _bfd_gc_sections */
3159 bfd_generic_merge_sections, /* _bfd_merge_sections */
3161 /* Dynamic */
3162 /* _get_dynamic_symtab_upper_bound */
3163 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3164 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3165 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3166 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3168 /* Opposite endian version, none exists */
3169 NULL,
3171 /* back end data */
3172 (void *) &bfd_xcoff_backend_data,
3176 * xcoff-powermac target
3177 * Old target.
3178 * Only difference between this target and the rs6000 target is the
3179 * the default architecture and machine type used in coffcode.h
3181 * PowerPC Macs use the same magic numbers as RS/6000
3182 * (because that's how they were bootstrapped originally),
3183 * but they are always PowerPC architecture.
3185 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
3187 { /* COFF backend, defined in libcoff.h */
3188 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
3189 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
3190 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
3191 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
3192 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
3193 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
3194 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
3195 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
3196 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
3197 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
3198 FILHSZ, /* _bfd_filhsz */
3199 AOUTSZ, /* _bfd_aoutsz */
3200 SCNHSZ, /* _bfd_scnhsz */
3201 SYMESZ, /* _bfd_symesz */
3202 AUXESZ, /* _bfd_auxesz */
3203 RELSZ, /* _bfd_relsz */
3204 LINESZ, /* _bfd_linesz */
3205 FILNMLEN, /* _bfd_filnmlen */
3206 true, /* _bfd_coff_long_filenames */
3207 false, /* _bfd_coff_long_section_names */
3208 (3), /* _bfd_coff_default_section_alignment_power */
3209 false, /* _bfd_coff_force_symnames_in_strings */
3210 2, /* _bfd_coff_debug_string_prefix_length */
3211 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
3212 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
3213 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
3214 coff_swap_reloc_in, /* _bfd_reloc_in */
3215 coff_bad_format_hook, /* _bfd_bad_format_hook */
3216 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
3217 coff_mkobject_hook, /* _bfd_mkobject_hook */
3218 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
3219 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
3220 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
3221 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
3222 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
3223 coff_print_aux, /* bfd_coff_print_aux */
3224 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
3225 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
3226 NULL, /* bfd_coff_sym_is_global */
3227 /* _bfd_coff_compute_section_file_positions */
3228 coff_compute_section_file_positions,
3229 NULL , /* _bfd_coff_start_final_link */
3230 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
3231 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
3232 NULL , /* _bfd_coff_addust_symndx */
3233 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3234 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3235 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3238 0x01DF, /* magic number */
3239 bfd_arch_powerpc, /* architecture */
3240 bfd_mach_ppc, /* machine */
3242 /* function pointers to xcoff specific swap routines */
3243 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
3244 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
3245 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3246 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3247 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3248 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3250 /* sizes */
3251 LDHDRSZ, /* _xcoff_ldhdrsz */
3252 LDSYMSZ, /* _xcoff_ldsymsz */
3253 LDRELSZ, /* _xcoff_ldrelsz */
3254 12, /* _xcoff_function_descriptor_size */
3255 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3257 /* versions */
3258 1, /* _xcoff_ldhdr_version */
3260 /* xcoff vs xcoff64 putting symbol names */
3261 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3262 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3264 &xcoff_dynamic_reloc, /* dynamic reloc howto */
3266 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3268 /* lineno and reloc count overflow */
3269 xcoff_is_lineno_count_overflow,
3270 xcoff_is_reloc_count_overflow,
3272 xcoff_loader_symbol_offset,
3273 xcoff_loader_reloc_offset,
3275 /* glink */
3276 &xcoff_glink_code[0],
3277 (36), /* _xcoff_glink_size */
3281 /* The transfer vector that leads the outside world to all of the above. */
3282 const bfd_target pmac_xcoff_vec =
3284 "xcoff-powermac",
3285 bfd_target_xcoff_flavour,
3286 BFD_ENDIAN_BIG, /* data byte order is big */
3287 BFD_ENDIAN_BIG, /* header byte order is big */
3289 (HAS_RELOC | EXEC_P | /* object flags */
3290 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3291 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3293 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3294 0, /* leading char */
3295 '/', /* ar_pad_char */
3296 15, /* ar_max_namelen??? FIXMEmgo */
3298 /* data */
3299 bfd_getb64, /* bfd_getx64 */
3300 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3301 bfd_putb64, /* bfd_putx64 */
3302 bfd_getb32, /* bfd_getx32 */
3303 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3304 bfd_putb32, /* bfd_putx32 */
3305 bfd_getb16, /* bfd_getx16 */
3306 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3307 bfd_putb16, /* bfd_putx16 */
3309 /* hdrs */
3310 bfd_getb64, /* bfd_h_getx64 */
3311 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3312 bfd_putb64, /* bfd_h_putx64 */
3313 bfd_getb32, /* bfd_h_getx32 */
3314 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3315 bfd_putb32, /* bfd_h_putx32 */
3316 bfd_getb16, /* bfd_h_getx16 */
3317 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3318 bfd_putb16, /* bfd_h_putx16 */
3320 { /* bfd_check_format */
3321 _bfd_dummy_target,
3322 coff_object_p,
3323 _bfd_xcoff_archive_p,
3324 CORE_FILE_P
3327 { /* bfd_set_format */
3328 bfd_false,
3329 coff_mkobject,
3330 _bfd_generic_mkarchive,
3331 bfd_false
3334 {/* bfd_write_contents */
3335 bfd_false,
3336 coff_write_object_contents,
3337 _bfd_xcoff_write_archive_contents,
3338 bfd_false
3341 /* Generic */
3342 bfd_true, /* _close_and_cleanup */
3343 bfd_true, /* _bfd_free_cached_info */
3344 coff_new_section_hook, /* _new_section_hook */
3345 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3346 /* _bfd_get_section_contents_in_window */
3347 _bfd_generic_get_section_contents_in_window,
3349 /* Copy */
3350 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3351 /* _bfd_merge_private_bfd_data */
3352 ((boolean (*) (bfd *, bfd *)) bfd_true),
3353 /* _bfd_copy_pivate_section_data */
3354 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3355 /* _bfd_copy_private_symbol_data */
3356 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3357 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3358 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3360 /* Core */
3361 coff_core_file_failing_command, /* _core_file_failing_command */
3362 coff_core_file_failing_signal, /* _core_file_failing_signal */
3363 /* _core_file_matches_executable_p */
3364 coff_core_file_matches_executable_p,
3366 /* Archive */
3367 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3368 /* XCOFF archives do not have
3369 anything which corresponds to
3370 an extended name table. */
3371 bfd_false, /* _slurp_extended_name_table */
3372 /* _construct_extended_name_table */
3373 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3374 bfd_dont_truncate_arname, /* _truncate_arname */
3375 _bfd_xcoff_write_armap, /* _write_armap */
3376 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3377 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3378 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3379 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3380 /* XCOFF archives do not have
3381 a timestamp. */
3382 bfd_true, /* _update_armap_timestamp */
3384 /* Symbols */
3385 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3386 coff_get_symtab, /* _get_symtab */
3387 coff_make_empty_symbol, /* _make_empty_symbol */
3388 coff_print_symbol, /* _print_symbol */
3389 coff_get_symbol_info, /* _get_symbol_info */
3390 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3391 coff_get_lineno, /* _get_lineno */
3392 coff_find_nearest_line, /* _find_nearest_line */
3393 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3394 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3395 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3397 /* Reloc */
3398 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3399 coff_canonicalize_reloc, /* _cononicalize_reloc */
3400 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3402 /* Write */
3403 coff_set_arch_mach, /* _set_arch_mach */
3404 coff_set_section_contents, /* _set_section_contents */
3406 /* Link */
3407 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3408 /* _bfd_get_relocated_section_contents */
3409 bfd_generic_get_relocated_section_contents,
3410 bfd_generic_relax_section, /* _bfd_relax_section */
3411 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3412 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3413 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3414 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3415 bfd_generic_gc_sections, /* _bfd_gc_sections */
3416 bfd_generic_merge_sections, /* _bfd_merge_sections */
3418 /* Dynamic */
3419 /* _get_dynamic_symtab_upper_bound */
3420 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3421 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3422 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3423 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3425 /* Opposite endian version, none exists */
3426 NULL,
3428 /* back end data */
3429 (void *) &bfd_pmac_xcoff_backend_data,