* libieee.h (common_header_type): Add last_byte field.
[binutils.git] / bfd / coff-rs6000.c
blob645e47e4bee8a966ec7a334fd838e8d15093a58c
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 PTR, struct internal_ldhdr *));
125 static void xcoff_swap_ldhdr_out
126 PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
127 static void xcoff_swap_ldsym_in
128 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
129 static void xcoff_swap_ldsym_out
130 PARAMS ((bfd *, const struct internal_ldsym *, PTR));
131 static void xcoff_swap_ldrel_in
132 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
133 static void xcoff_swap_ldrel_out
134 PARAMS ((bfd *, const struct internal_ldrel *, PTR));
135 static boolean xcoff_ppc_relocate_section
136 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
137 struct internal_reloc *, struct internal_syment *, asection **));
138 static boolean _bfd_xcoff_put_ldsymbol_name
139 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
140 const char *));
141 static asection *xcoff_create_csect_from_smclas
142 PARAMS ((bfd *, union internal_auxent *, const char *));
143 static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
144 static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
145 static bfd_vma xcoff_loader_symbol_offset
146 PARAMS ((bfd *, struct internal_ldhdr *));
147 static bfd_vma xcoff_loader_reloc_offset
148 PARAMS ((bfd *, struct internal_ldhdr *));
150 /* We use our own tdata type. Its first field is the COFF tdata type,
151 so the COFF routines are compatible. */
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, s, dst)
2276 bfd *abfd;
2277 const PTR s;
2278 struct internal_ldhdr *dst;
2280 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2282 dst->l_version = bfd_get_32 (abfd, src->l_version);
2283 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2284 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2285 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2286 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2287 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2288 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2289 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2292 /* Swap out the ldhdr structure. */
2294 static void
2295 xcoff_swap_ldhdr_out (abfd, src, d)
2296 bfd *abfd;
2297 const struct internal_ldhdr *src;
2298 PTR d;
2300 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2302 bfd_put_32 (abfd, src->l_version, dst->l_version);
2303 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2304 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2305 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2306 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2307 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2308 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2309 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2312 /* Swap in the ldsym structure. */
2314 static void
2315 xcoff_swap_ldsym_in (abfd, s, dst)
2316 bfd *abfd;
2317 const PTR s;
2318 struct internal_ldsym *dst;
2320 const struct external_ldsym *src = (const struct external_ldsym *) s;
2322 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2323 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2324 } else {
2325 dst->_l._l_l._l_zeroes = 0;
2326 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2328 dst->l_value = bfd_get_32 (abfd, src->l_value);
2329 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2330 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2331 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2332 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2333 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2336 /* Swap out the ldsym structure. */
2338 static void
2339 xcoff_swap_ldsym_out (abfd, src, d)
2340 bfd *abfd;
2341 const struct internal_ldsym *src;
2342 PTR d;
2344 struct external_ldsym *dst = (struct external_ldsym *) d;
2346 if (src->_l._l_l._l_zeroes != 0)
2347 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2348 else
2350 bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes);
2351 bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset);
2353 bfd_put_32 (abfd, src->l_value, dst->l_value);
2354 bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
2355 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2356 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2357 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2358 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2361 /* Swap in the ldrel structure. */
2363 static void
2364 xcoff_swap_ldrel_in (abfd, s, dst)
2365 bfd *abfd;
2366 const PTR s;
2367 struct internal_ldrel *dst;
2369 const struct external_ldrel *src = (const struct external_ldrel *) s;
2371 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2372 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2373 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2374 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2377 /* Swap out the ldrel structure. */
2379 static void
2380 xcoff_swap_ldrel_out (abfd, src, d)
2381 bfd *abfd;
2382 const struct internal_ldrel *src;
2383 PTR d;
2385 struct external_ldrel *dst = (struct external_ldrel *) d;
2387 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2388 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2389 bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
2390 bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
2395 /* This is the relocation function for the RS/6000/POWER/PowerPC.
2396 This is currently the only processor which uses XCOFF; I hope that
2397 will never change. */
2399 static boolean
2400 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
2401 input_section, contents, relocs, syms,
2402 sections)
2403 bfd *output_bfd;
2404 struct bfd_link_info *info;
2405 bfd *input_bfd;
2406 asection *input_section;
2407 bfd_byte *contents;
2408 struct internal_reloc *relocs;
2409 struct internal_syment *syms;
2410 asection **sections;
2412 struct internal_reloc *rel;
2413 struct internal_reloc *relend;
2415 rel = relocs;
2416 relend = rel + input_section->reloc_count;
2418 for (; rel < relend; rel++)
2420 long symndx;
2421 struct xcoff_link_hash_entry *h;
2422 struct internal_syment *sym;
2423 bfd_vma addend;
2424 bfd_vma val;
2425 struct reloc_howto_struct howto;
2426 bfd_reloc_status_type rstat;
2428 /* Relocation type R_REF is a special relocation type which is
2429 merely used to prevent garbage collection from occurring for
2430 the csect including the symbol which it references. */
2431 if (rel->r_type == R_REF)
2432 continue;
2434 symndx = rel->r_symndx;
2436 if (symndx == -1)
2438 h = NULL;
2439 sym = NULL;
2440 addend = 0;
2442 else
2444 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
2445 sym = syms + symndx;
2446 addend = - sym->n_value;
2450 /* We build the howto information on the fly. */
2452 howto.type = rel->r_type;
2453 howto.rightshift = 0;
2454 howto.size = 2;
2455 howto.bitsize = (rel->r_size & 0x1f) + 1;
2456 howto.pc_relative = false;
2457 howto.bitpos = 0;
2458 if ((rel->r_size & 0x80) != 0)
2459 howto.complain_on_overflow = complain_overflow_signed;
2460 else
2461 howto.complain_on_overflow = complain_overflow_bitfield;
2462 howto.special_function = NULL;
2463 howto.name = "internal";
2464 howto.partial_inplace = true;
2465 if (howto.bitsize == 32)
2466 howto.src_mask = howto.dst_mask = 0xffffffff;
2467 else
2469 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
2470 if (howto.bitsize == 16)
2471 howto.size = 1;
2473 howto.pcrel_offset = false;
2475 val = 0;
2477 if (h == NULL)
2479 asection *sec;
2481 if (symndx == -1)
2483 sec = bfd_abs_section_ptr;
2484 val = 0;
2486 else
2488 sec = sections[symndx];
2489 /* Hack to make sure we use the right TOC anchor value
2490 if this reloc is against the TOC anchor. */
2492 if (sec->name[3] == '0'
2493 && strcmp (sec->name, ".tc0") == 0) {
2495 val = xcoff_data (output_bfd)->toc;
2496 } else {
2498 val = (sec->output_section->vma
2499 + sec->output_offset
2500 + sym->n_value
2501 - sec->vma);
2506 else
2508 if (h->root.type == bfd_link_hash_defined
2509 || h->root.type == bfd_link_hash_defweak)
2511 asection *sec;
2513 sec = h->root.u.def.section;
2514 val = (h->root.u.def.value
2515 + sec->output_section->vma
2516 + sec->output_offset);
2518 else if (h->root.type == bfd_link_hash_common)
2520 asection *sec;
2522 sec = h->root.u.c.p->section;
2523 val = (sec->output_section->vma
2524 + sec->output_offset);
2526 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
2527 || (h->flags & XCOFF_IMPORT) != 0)
2529 /* Every symbol in a shared object is defined somewhere. */
2530 val = 0;
2532 else if (! info->relocateable)
2534 if (! ((*info->callbacks->undefined_symbol)
2535 (info, h->root.root.string, input_bfd, input_section,
2536 rel->r_vaddr - input_section->vma, true)))
2537 return false;
2539 /* Don't try to process the reloc. It can't help, and
2540 it may generate another error. */
2541 continue;
2545 /* I took the relocation type definitions from two documents:
2546 the PowerPC AIX Version 4 Application Binary Interface, First
2547 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2548 32-Bit Hardware Implementation (June 30, 1994). Differences
2549 between the documents are noted below. */
2551 switch (rel->r_type)
2553 case R_RTB:
2554 case R_RRTBI:
2555 case R_RRTBA:
2556 /* These relocs are defined by the PowerPC ABI to be
2557 relative branches which use half of the difference
2558 between the symbol and the program counter. I can't
2559 quite figure out when this is useful. These relocs are
2560 not defined by the PowerOpen ABI. */
2561 default:
2562 (*_bfd_error_handler)
2563 (_("%s: unsupported relocation type 0x%02x"),
2564 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2565 bfd_set_error (bfd_error_bad_value);
2566 return false;
2567 case R_POS:
2568 /* Simple positive relocation. */
2569 break;
2570 case R_NEG:
2571 /* Simple negative relocation. */
2572 val = - val;
2573 break;
2574 case R_REL:
2575 /* Simple PC relative relocation. */
2576 howto.pc_relative = true;
2577 break;
2578 case R_TOC:
2579 /* TOC relative relocation. The value in the instruction in
2580 the input file is the offset from the input file TOC to
2581 the desired location. We want the offset from the final
2582 TOC to the desired location. We have:
2583 isym = iTOC + in
2584 iinsn = in + o
2585 osym = oTOC + on
2586 oinsn = on + o
2587 so we must change insn by on - in.
2589 case R_GL:
2590 /* Global linkage relocation. The value of this relocation
2591 is the address of the entry in the TOC section. */
2592 case R_TCL:
2593 /* Local object TOC address. I can't figure out the
2594 difference between this and case R_GL. */
2595 case R_TRL:
2596 /* TOC relative relocation. A TOC relative load instruction
2597 which may be changed to a load address instruction.
2598 FIXME: We don't currently implement this optimization. */
2599 case R_TRLA:
2600 /* TOC relative relocation. This is a TOC relative load
2601 address instruction which may be changed to a load
2602 instruction. FIXME: I don't know if this is the correct
2603 implementation. */
2604 if (h != NULL && h->smclas != XMC_TD)
2606 if (h->toc_section == NULL)
2608 (*_bfd_error_handler)
2609 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2610 bfd_get_filename (input_bfd), rel->r_vaddr,
2611 h->root.root.string);
2612 bfd_set_error (bfd_error_bad_value);
2613 return false;
2616 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2617 val = (h->toc_section->output_section->vma
2618 + h->toc_section->output_offset);
2621 val = ((val - xcoff_data (output_bfd)->toc)
2622 - (sym->n_value - xcoff_data (input_bfd)->toc));
2623 addend = 0;
2624 break;
2625 case R_BA:
2626 /* Absolute branch. We don't want to mess with the lower
2627 two bits of the instruction. */
2628 case R_CAI:
2629 /* The PowerPC ABI defines this as an absolute call which
2630 may be modified to become a relative call. The PowerOpen
2631 ABI does not define this relocation type. */
2632 case R_RBA:
2633 /* Absolute branch which may be modified to become a
2634 relative branch. */
2635 case R_RBAC:
2636 /* The PowerPC ABI defines this as an absolute branch to a
2637 fixed address which may be modified to an absolute branch
2638 to a symbol. The PowerOpen ABI does not define this
2639 relocation type. */
2640 case R_RBRC:
2641 /* The PowerPC ABI defines this as an absolute branch to a
2642 fixed address which may be modified to a relative branch.
2643 The PowerOpen ABI does not define this relocation type. */
2644 howto.src_mask &= ~3;
2645 howto.dst_mask = howto.src_mask;
2646 break;
2647 case R_BR:
2648 /* Relative branch. We don't want to mess with the lower
2649 two bits of the instruction. */
2650 case R_CREL:
2651 /* The PowerPC ABI defines this as a relative call which may
2652 be modified to become an absolute call. The PowerOpen
2653 ABI does not define this relocation type. */
2654 case R_RBR:
2655 /* A relative branch which may be modified to become an
2656 absolute branch. FIXME: We don't implement this,
2657 although we should for symbols of storage mapping class
2658 XMC_XO. */
2659 howto.pc_relative = true;
2660 howto.src_mask &= ~3;
2661 howto.dst_mask = howto.src_mask;
2662 break;
2663 case R_RL:
2664 /* The PowerPC AIX ABI describes this as a load which may be
2665 changed to a load address. The PowerOpen ABI says this
2666 is the same as case R_POS. */
2667 break;
2668 case R_RLA:
2669 /* The PowerPC AIX ABI describes this as a load address
2670 which may be changed to a load. The PowerOpen ABI says
2671 this is the same as R_POS. */
2672 break;
2675 /* If we see an R_BR or R_RBR reloc which is jumping to global
2676 linkage code, and it is followed by an appropriate cror nop
2677 instruction, we replace the cror with lwz r2,20(r1). This
2678 restores the TOC after the glink code. Contrariwise, if the
2679 call is followed by a lwz r2,20(r1), but the call is not
2680 going to global linkage code, we can replace the load with a
2681 cror. */
2682 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
2683 && h != NULL
2684 && h->root.type == bfd_link_hash_defined
2685 && (rel->r_vaddr - input_section->vma + 8
2686 <= input_section->_cooked_size))
2688 bfd_byte *pnext;
2689 unsigned long next;
2691 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2692 next = bfd_get_32 (input_bfd, pnext);
2694 /* The _ptrgl function is magic. It is used by the AIX
2695 compiler to call a function through a pointer. */
2696 if (h->smclas == XMC_GL
2697 || strcmp (h->root.root.string, "._ptrgl") == 0)
2699 if (next == 0x4def7b82 /* cror 15,15,15 */
2700 || next == 0x4ffffb82 /* cror 31,31,31 */
2701 || next == 0x60000000) /* ori r0,r0,0 */
2702 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2704 else
2706 if (next == 0x80410014) /* lwz r1,20(r1) */
2707 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2711 /* A PC relative reloc includes the section address. */
2712 if (howto.pc_relative)
2713 addend += input_section->vma;
2715 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
2716 contents,
2717 rel->r_vaddr - input_section->vma,
2718 val, addend);
2720 switch (rstat)
2722 default:
2723 abort ();
2724 case bfd_reloc_ok:
2725 break;
2726 case bfd_reloc_overflow:
2728 const char *name;
2729 char buf[SYMNMLEN + 1];
2730 char howto_name[10];
2732 if (symndx == -1)
2733 name = "*ABS*";
2734 else if (h != NULL)
2735 name = h->root.root.string;
2736 else
2739 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
2741 if (name == NULL)
2742 return false;
2744 sprintf (howto_name, "0x%02x", rel->r_type);
2746 if (! ((*info->callbacks->reloc_overflow)
2747 (info, name, howto_name, (bfd_vma) 0, input_bfd,
2748 input_section, rel->r_vaddr - input_section->vma)))
2749 return false;
2754 return true;
2757 static boolean
2758 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
2759 bfd *abfd ATTRIBUTE_UNUSED;
2760 struct xcoff_loader_info *ldinfo;
2761 struct internal_ldsym *ldsym;
2762 const char *name;
2764 size_t len;
2765 len = strlen (name);
2767 if (len <= SYMNMLEN)
2768 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
2769 else
2771 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
2773 size_t newalc;
2774 bfd_byte *newstrings;
2776 newalc = ldinfo->string_alc * 2;
2777 if (newalc == 0)
2778 newalc = 32;
2779 while (ldinfo->string_size + len + 3 > newalc)
2780 newalc *= 2;
2782 newstrings = ((bfd_byte *)
2783 bfd_realloc ((PTR) ldinfo->strings, newalc));
2784 if (newstrings == NULL)
2786 ldinfo->failed = true;
2787 return false;
2789 ldinfo->string_alc = newalc;
2790 ldinfo->strings = newstrings;
2793 bfd_put_16 (ldinfo->output_bfd, len + 1,
2794 ldinfo->strings + ldinfo->string_size);
2795 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
2796 ldsym->_l._l_l._l_zeroes = 0;
2797 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
2798 ldinfo->string_size += len + 3;
2801 return true;
2804 static boolean
2805 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
2806 struct internal_syment *sym,
2807 const char *name) {
2809 if (strlen (name) <= SYMNMLEN) {
2810 strncpy (sym->_n._n_name, name, SYMNMLEN);
2811 } else {
2812 boolean hash;
2813 bfd_size_type indx;
2815 hash = true;
2816 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
2817 hash = false;
2818 indx = _bfd_stringtab_add (strtab, name, hash, false);
2819 if (indx == (bfd_size_type) -1)
2820 return false;
2821 sym->_n._n_n._n_zeroes = 0;
2822 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
2824 return true;
2827 static asection *
2828 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
2829 bfd *abfd;
2830 union internal_auxent *aux;
2831 const char *symbol_name;
2834 asection *return_value = NULL;
2837 * .sv64 = x_smclas == 17
2838 * This is an invalid csect for 32 bit apps.
2840 static const char *names[19] = {
2841 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2842 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
2843 ".td", NULL, ".sv3264"
2846 if ((19 >= aux->x_csect.x_smclas) &&
2847 (NULL != names[aux->x_csect.x_smclas])) {
2849 return_value = bfd_make_section_anyway
2850 (abfd, names[aux->x_csect.x_smclas]);
2853 } else {
2854 (*_bfd_error_handler)
2855 (_("%s: symbol `%s' has unrecognized smclas %d"),
2856 bfd_get_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2857 bfd_set_error (bfd_error_bad_value);
2860 return return_value;
2863 static boolean
2864 xcoff_is_lineno_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 boolean
2875 xcoff_is_reloc_count_overflow (abfd, value)
2876 bfd *abfd ATTRIBUTE_UNUSED;
2877 bfd_vma value;
2879 if (0xffff <= value) {
2880 return true;
2882 return false;
2885 static bfd_vma
2886 xcoff_loader_symbol_offset (abfd, ldhdr)
2887 bfd *abfd;
2888 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
2890 return bfd_xcoff_ldhdrsz(abfd);
2893 static bfd_vma
2894 xcoff_loader_reloc_offset (abfd, ldhdr)
2895 bfd *abfd;
2896 struct internal_ldhdr *ldhdr;
2898 return bfd_xcoff_ldhdrsz(abfd) +
2899 (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd));
2903 static reloc_howto_type xcoff_dynamic_reloc =
2904 HOWTO (0, /* type */
2905 0, /* rightshift */
2906 2, /* size (0 = byte, 1 = short, 2 = long) */
2907 32, /* bitsize */
2908 false, /* pc_relative */
2909 0, /* bitpos */
2910 complain_overflow_bitfield, /* complain_on_overflow */
2911 0, /* special_function */
2912 "R_POS", /* name */
2913 true, /* partial_inplace */
2914 0xffffffff, /* src_mask */
2915 0xffffffff, /* dst_mask */
2916 false); /* pcrel_offset */
2919 * glink
2921 * The first word of global linkage code must be modified by filling in
2922 * the correct TOC offset.
2924 static unsigned long xcoff_glink_code[9] =
2926 0x81820000, /* lwz r12,0(r2) */
2927 0x90410014, /* stw r2,20(r1) */
2928 0x800c0000, /* lwz r0,0(r12) */
2929 0x804c0004, /* lwz r2,4(r12) */
2930 0x7c0903a6, /* mtctr r0 */
2931 0x4e800420, /* bctr */
2932 0x00000000, /* start of traceback table */
2933 0x000c8000, /* traceback table */
2934 0x00000000, /* traceback table */
2938 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2940 { /* COFF backend, defined in libcoff.h */
2941 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
2942 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
2943 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2944 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
2945 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
2946 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
2947 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2948 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2949 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2950 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2951 FILHSZ, /* _bfd_filhsz */
2952 AOUTSZ, /* _bfd_aoutsz */
2953 SCNHSZ, /* _bfd_scnhsz */
2954 SYMESZ, /* _bfd_symesz */
2955 AUXESZ, /* _bfd_auxesz */
2956 RELSZ, /* _bfd_relsz */
2957 LINESZ, /* _bfd_linesz */
2958 FILNMLEN, /* _bfd_filnmlen */
2959 true, /* _bfd_coff_long_filenames */
2960 false, /* _bfd_coff_long_section_names */
2961 (3), /* _bfd_coff_default_section_alignment_power */
2962 false, /* _bfd_coff_force_symnames_in_strings */
2963 2, /* _bfd_coff_debug_string_prefix_length */
2964 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2965 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2966 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2967 coff_swap_reloc_in, /* _bfd_reloc_in */
2968 coff_bad_format_hook, /* _bfd_bad_format_hook */
2969 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2970 coff_mkobject_hook, /* _bfd_mkobject_hook */
2971 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2972 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2973 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2974 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2975 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2976 coff_print_aux, /* bfd_coff_print_aux */
2977 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2978 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2979 NULL, /* bfd_coff_sym_is_global */
2980 /* _bfd_coff_compute_section_file_positions */
2981 coff_compute_section_file_positions,
2982 NULL , /* _bfd_coff_start_final_link */
2983 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
2984 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2985 NULL , /* _bfd_coff_addust_symndx */
2986 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2987 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2988 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2991 0x01DF, /* magic number */
2992 bfd_arch_rs6000, /* architecture */
2993 bfd_mach_rs6k, /* machine */
2996 /* function pointers to xcoff specific swap routines */
2997 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2998 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2999 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3000 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3001 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3002 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3004 /* sizes */
3005 LDHDRSZ, /* _xcoff_ldhdrsz */
3006 LDSYMSZ, /* _xcoff_ldsymsz */
3007 LDRELSZ, /* _xcoff_ldrelsz */
3008 12, /* _xcoff_function_descriptor_size */
3009 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3011 /* versions */
3012 1, /* _xcoff_ldhdr_version */
3014 /* xcoff vs xcoff64 putting symbol names */
3015 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3016 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3018 &xcoff_dynamic_reloc, /* dynamic reloc howto */
3020 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3022 /* lineno and reloc count overflow */
3023 xcoff_is_lineno_count_overflow,
3024 xcoff_is_reloc_count_overflow,
3026 xcoff_loader_symbol_offset,
3027 xcoff_loader_reloc_offset,
3029 /* glink */
3030 &xcoff_glink_code[0],
3031 (36), /* _xcoff_glink_size */
3035 /* The transfer vector that leads the outside world to all of the above. */
3036 const bfd_target rs6000coff_vec =
3038 "aixcoff-rs6000",
3039 bfd_target_xcoff_flavour,
3040 BFD_ENDIAN_BIG, /* data byte order is big */
3041 BFD_ENDIAN_BIG, /* header byte order is big */
3043 (HAS_RELOC | EXEC_P | /* object flags */
3044 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3045 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3047 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3048 0, /* leading char */
3049 '/', /* ar_pad_char */
3050 15, /* ar_max_namelen??? FIXMEmgo */
3052 /* data */
3053 bfd_getb64, /* bfd_getx64 */
3054 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3055 bfd_putb64, /* bfd_putx64 */
3056 bfd_getb32, /* bfd_getx32 */
3057 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3058 bfd_putb32, /* bfd_putx32 */
3059 bfd_getb16, /* bfd_getx16 */
3060 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3061 bfd_putb16, /* bfd_putx16 */
3063 /* hdrs */
3064 bfd_getb64, /* bfd_h_getx64 */
3065 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3066 bfd_putb64, /* bfd_h_putx64 */
3067 bfd_getb32, /* bfd_h_getx32 */
3068 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3069 bfd_putb32, /* bfd_h_putx32 */
3070 bfd_getb16, /* bfd_h_getx16 */
3071 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3072 bfd_putb16, /* bfd_h_putx16 */
3074 { /* bfd_check_format */
3075 _bfd_dummy_target,
3076 coff_object_p,
3077 _bfd_xcoff_archive_p,
3078 CORE_FILE_P
3081 { /* bfd_set_format */
3082 bfd_false,
3083 coff_mkobject,
3084 _bfd_generic_mkarchive,
3085 bfd_false
3088 {/* bfd_write_contents */
3089 bfd_false,
3090 coff_write_object_contents,
3091 _bfd_xcoff_write_archive_contents,
3092 bfd_false
3095 /* Generic */
3096 bfd_true, /* _close_and_cleanup */
3097 bfd_true, /* _bfd_free_cached_info */
3098 coff_new_section_hook, /* _new_section_hook */
3099 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3100 /* _bfd_get_section_contents_in_window */
3101 _bfd_generic_get_section_contents_in_window,
3103 /* Copy */
3104 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3105 /* _bfd_merge_private_bfd_data */
3106 ((boolean (*) (bfd *, bfd *)) bfd_true),
3107 /* _bfd_copy_pivate_section_data */
3108 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3109 /* _bfd_copy_private_symbol_data */
3110 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3111 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3112 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3114 /* Core */
3115 coff_core_file_failing_command, /* _core_file_failing_command */
3116 coff_core_file_failing_signal, /* _core_file_failing_signal */
3117 /* _core_file_matches_executable_p */
3118 coff_core_file_matches_executable_p,
3120 /* Archive */
3121 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3122 /* XCOFF archives do not have
3123 anything which corresponds to
3124 an extended name table. */
3125 bfd_false, /* _slurp_extended_name_table */
3126 /* _construct_extended_name_table */
3127 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3128 bfd_dont_truncate_arname, /* _truncate_arname */
3129 _bfd_xcoff_write_armap, /* _write_armap */
3130 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3131 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3132 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3133 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3134 /* XCOFF archives do not have
3135 a timestamp. */
3136 bfd_true, /* _update_armap_timestamp */
3138 /* Symbols */
3139 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3140 coff_get_symtab, /* _get_symtab */
3141 coff_make_empty_symbol, /* _make_empty_symbol */
3142 coff_print_symbol, /* _print_symbol */
3143 coff_get_symbol_info, /* _get_symbol_info */
3144 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3145 coff_get_lineno, /* _get_lineno */
3146 coff_find_nearest_line, /* _find_nearest_line */
3147 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3148 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3149 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3151 /* Reloc */
3152 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3153 coff_canonicalize_reloc, /* _cononicalize_reloc */
3154 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3156 /* Write */
3157 coff_set_arch_mach, /* _set_arch_mach */
3158 coff_set_section_contents, /* _set_section_contents */
3160 /* Link */
3161 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3162 /* _bfd_get_relocated_section_contents */
3163 bfd_generic_get_relocated_section_contents,
3164 bfd_generic_relax_section, /* _bfd_relax_section */
3165 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3166 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3167 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3168 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3169 bfd_generic_gc_sections, /* _bfd_gc_sections */
3170 bfd_generic_merge_sections, /* _bfd_merge_sections */
3172 /* Dynamic */
3173 /* _get_dynamic_symtab_upper_bound */
3174 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3175 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3176 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3177 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3179 /* Opposite endian version, none exists */
3180 NULL,
3182 /* back end data */
3183 (void *) &bfd_xcoff_backend_data,
3187 * xcoff-powermac target
3188 * Old target.
3189 * Only difference between this target and the rs6000 target is the
3190 * the default architecture and machine type used in coffcode.h
3192 * PowerPC Macs use the same magic numbers as RS/6000
3193 * (because that's how they were bootstrapped originally),
3194 * but they are always PowerPC architecture.
3196 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
3198 { /* COFF backend, defined in libcoff.h */
3199 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
3200 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
3201 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
3202 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
3203 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
3204 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
3205 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
3206 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
3207 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
3208 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
3209 FILHSZ, /* _bfd_filhsz */
3210 AOUTSZ, /* _bfd_aoutsz */
3211 SCNHSZ, /* _bfd_scnhsz */
3212 SYMESZ, /* _bfd_symesz */
3213 AUXESZ, /* _bfd_auxesz */
3214 RELSZ, /* _bfd_relsz */
3215 LINESZ, /* _bfd_linesz */
3216 FILNMLEN, /* _bfd_filnmlen */
3217 true, /* _bfd_coff_long_filenames */
3218 false, /* _bfd_coff_long_section_names */
3219 (3), /* _bfd_coff_default_section_alignment_power */
3220 false, /* _bfd_coff_force_symnames_in_strings */
3221 2, /* _bfd_coff_debug_string_prefix_length */
3222 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
3223 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
3224 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
3225 coff_swap_reloc_in, /* _bfd_reloc_in */
3226 coff_bad_format_hook, /* _bfd_bad_format_hook */
3227 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
3228 coff_mkobject_hook, /* _bfd_mkobject_hook */
3229 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
3230 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
3231 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
3232 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
3233 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
3234 coff_print_aux, /* bfd_coff_print_aux */
3235 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
3236 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
3237 NULL, /* bfd_coff_sym_is_global */
3238 /* _bfd_coff_compute_section_file_positions */
3239 coff_compute_section_file_positions,
3240 NULL , /* _bfd_coff_start_final_link */
3241 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
3242 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
3243 NULL , /* _bfd_coff_addust_symndx */
3244 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3245 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3246 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3249 0x01DF, /* magic number */
3250 bfd_arch_powerpc, /* architecture */
3251 bfd_mach_ppc, /* machine */
3253 /* function pointers to xcoff specific swap routines */
3254 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
3255 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
3256 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3257 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3258 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3259 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3261 /* sizes */
3262 LDHDRSZ, /* _xcoff_ldhdrsz */
3263 LDSYMSZ, /* _xcoff_ldsymsz */
3264 LDRELSZ, /* _xcoff_ldrelsz */
3265 12, /* _xcoff_function_descriptor_size */
3266 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3268 /* versions */
3269 1, /* _xcoff_ldhdr_version */
3271 /* xcoff vs xcoff64 putting symbol names */
3272 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3273 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3275 &xcoff_dynamic_reloc, /* dynamic reloc howto */
3277 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3279 /* lineno and reloc count overflow */
3280 xcoff_is_lineno_count_overflow,
3281 xcoff_is_reloc_count_overflow,
3283 xcoff_loader_symbol_offset,
3284 xcoff_loader_reloc_offset,
3286 /* glink */
3287 &xcoff_glink_code[0],
3288 (36), /* _xcoff_glink_size */
3292 /* The transfer vector that leads the outside world to all of the above. */
3293 const bfd_target pmac_xcoff_vec =
3295 "xcoff-powermac",
3296 bfd_target_xcoff_flavour,
3297 BFD_ENDIAN_BIG, /* data byte order is big */
3298 BFD_ENDIAN_BIG, /* header byte order is big */
3300 (HAS_RELOC | EXEC_P | /* object flags */
3301 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3302 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3304 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3305 0, /* leading char */
3306 '/', /* ar_pad_char */
3307 15, /* ar_max_namelen??? FIXMEmgo */
3309 /* data */
3310 bfd_getb64, /* bfd_getx64 */
3311 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3312 bfd_putb64, /* bfd_putx64 */
3313 bfd_getb32, /* bfd_getx32 */
3314 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3315 bfd_putb32, /* bfd_putx32 */
3316 bfd_getb16, /* bfd_getx16 */
3317 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3318 bfd_putb16, /* bfd_putx16 */
3320 /* hdrs */
3321 bfd_getb64, /* bfd_h_getx64 */
3322 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3323 bfd_putb64, /* bfd_h_putx64 */
3324 bfd_getb32, /* bfd_h_getx32 */
3325 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3326 bfd_putb32, /* bfd_h_putx32 */
3327 bfd_getb16, /* bfd_h_getx16 */
3328 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3329 bfd_putb16, /* bfd_h_putx16 */
3331 { /* bfd_check_format */
3332 _bfd_dummy_target,
3333 coff_object_p,
3334 _bfd_xcoff_archive_p,
3335 CORE_FILE_P
3338 { /* bfd_set_format */
3339 bfd_false,
3340 coff_mkobject,
3341 _bfd_generic_mkarchive,
3342 bfd_false
3345 {/* bfd_write_contents */
3346 bfd_false,
3347 coff_write_object_contents,
3348 _bfd_xcoff_write_archive_contents,
3349 bfd_false
3352 /* Generic */
3353 bfd_true, /* _close_and_cleanup */
3354 bfd_true, /* _bfd_free_cached_info */
3355 coff_new_section_hook, /* _new_section_hook */
3356 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3357 /* _bfd_get_section_contents_in_window */
3358 _bfd_generic_get_section_contents_in_window,
3360 /* Copy */
3361 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3362 /* _bfd_merge_private_bfd_data */
3363 ((boolean (*) (bfd *, bfd *)) bfd_true),
3364 /* _bfd_copy_pivate_section_data */
3365 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3366 /* _bfd_copy_private_symbol_data */
3367 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3368 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3369 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3371 /* Core */
3372 coff_core_file_failing_command, /* _core_file_failing_command */
3373 coff_core_file_failing_signal, /* _core_file_failing_signal */
3374 /* _core_file_matches_executable_p */
3375 coff_core_file_matches_executable_p,
3377 /* Archive */
3378 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3379 /* XCOFF archives do not have
3380 anything which corresponds to
3381 an extended name table. */
3382 bfd_false, /* _slurp_extended_name_table */
3383 /* _construct_extended_name_table */
3384 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3385 bfd_dont_truncate_arname, /* _truncate_arname */
3386 _bfd_xcoff_write_armap, /* _write_armap */
3387 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3388 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3389 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3390 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3391 /* XCOFF archives do not have
3392 a timestamp. */
3393 bfd_true, /* _update_armap_timestamp */
3395 /* Symbols */
3396 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3397 coff_get_symtab, /* _get_symtab */
3398 coff_make_empty_symbol, /* _make_empty_symbol */
3399 coff_print_symbol, /* _print_symbol */
3400 coff_get_symbol_info, /* _get_symbol_info */
3401 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3402 coff_get_lineno, /* _get_lineno */
3403 coff_find_nearest_line, /* _find_nearest_line */
3404 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3405 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3406 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3408 /* Reloc */
3409 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3410 coff_canonicalize_reloc, /* _cononicalize_reloc */
3411 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3413 /* Write */
3414 coff_set_arch_mach, /* _set_arch_mach */
3415 coff_set_section_contents, /* _set_section_contents */
3417 /* Link */
3418 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3419 /* _bfd_get_relocated_section_contents */
3420 bfd_generic_get_relocated_section_contents,
3421 bfd_generic_relax_section, /* _bfd_relax_section */
3422 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3423 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3424 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3425 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3426 bfd_generic_gc_sections, /* _bfd_gc_sections */
3427 bfd_generic_merge_sections, /* _bfd_merge_sections */
3429 /* Dynamic */
3430 /* _get_dynamic_symtab_upper_bound */
3431 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3432 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3433 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3434 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3436 /* Opposite endian version, none exists */
3437 NULL,
3439 /* back end data */
3440 (void *) &bfd_pmac_xcoff_backend_data,