fix compile time warning message
[deliverable/binutils-gdb.git] / bfd / coff-rs6000.c
CommitLineData
252b5132 1/* BFD back-end for IBM RS/6000 "XCOFF" files.
7898deda
NC
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001
5f771d47 4 Free Software Foundation, Inc.
252b5132
RH
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.
c5930ee6 9 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
252b5132
RH
10 and John Gilmore.
11 Archive support from Damon A. Permezel.
12 Contributed by IBM Corporation and Cygnus Support.
13
14This file is part of BFD, the Binary File Descriptor library.
15
16This program is free software; you can redistribute it and/or modify
17it under the terms of the GNU General Public License as published by
18the Free Software Foundation; either version 2 of the License, or
19(at your option) any later version.
20
21This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, write to the Free Software
28Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29
252b5132
RH
30#include "bfd.h"
31#include "sysdep.h"
beb1bf64 32#include "bfdlink.h"
252b5132
RH
33#include "libbfd.h"
34#include "coff/internal.h"
beb1bf64 35#include "coff/xcoff.h"
252b5132
RH
36#include "coff/rs6000.h"
37#include "libcoff.h"
beb1bf64
TR
38#include "libxcoff.h"
39
beb1bf64
TR
40extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
41extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
42extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
43extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
44 PARAMS ((bfd *, bfd_reloc_code_real_type));
45extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
46extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *));
47extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
48extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
49extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
50extern boolean _bfd_xcoff_write_armap
51 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
52extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
53extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
54extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
55extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
56extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
57extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
58
f4ffd778 59/* Forward declare _bfd_xcoff_rtype2howto for coffcode.h macro. */
beb1bf64
TR
60void _bfd_xcoff_rtype2howto PARAMS ((arelent *, struct internal_reloc *));
61
f4ffd778 62/* coffcode.h needs these to be defined. */
beb1bf64
TR
63#define RS6000COFF_C 1
64
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)); \
73 }
74
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
b55039f4
L
83#ifdef AIX_CORE
84extern const bfd_target * rs6000coff_core_p ();
85extern boolean rs6000coff_core_file_matches_executable_p ();
86extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
87extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
beb1bf64 88#define CORE_FILE_P rs6000coff_core_p
b55039f4
L
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
beb1bf64
TR
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
108
109#include "coffcode.h"
14958a43 110
252b5132
RH
111/* The main body of code is in coffcode.h. */
112
252b5132 113static const char *normalize_filename PARAMS ((bfd *));
a7b97311
AM
114static boolean xcoff_write_armap_old
115 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
116static boolean xcoff_write_one_armap_big
117 PARAMS ((bfd *, struct orl *, unsigned int, unsigned int, unsigned int,
118 int, const char *, char *));
119static boolean xcoff_write_armap_big
120 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
121static boolean xcoff_write_archive_contents_old PARAMS ((bfd *));
122static boolean xcoff_write_archive_contents_big PARAMS ((bfd *));
123static void xcoff_swap_ldhdr_in
814fa6ab 124 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
a7b97311 125static void xcoff_swap_ldhdr_out
814fa6ab 126 PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
a7b97311 127static void xcoff_swap_ldsym_in
814fa6ab 128 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
a7b97311 129static void xcoff_swap_ldsym_out
814fa6ab 130 PARAMS ((bfd *, const struct internal_ldsym *, PTR));
a7b97311 131static void xcoff_swap_ldrel_in
814fa6ab 132 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
a7b97311 133static void xcoff_swap_ldrel_out
814fa6ab 134 PARAMS ((bfd *, const struct internal_ldrel *, PTR));
a7b97311
AM
135static boolean xcoff_ppc_relocate_section
136 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
137 struct internal_reloc *, struct internal_syment *, asection **));
138static boolean _bfd_xcoff_put_ldsymbol_name
139 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
140 const char *));
141static asection *xcoff_create_csect_from_smclas
814fa6ab 142 PARAMS ((bfd *, union internal_auxent *, const char *));
a7b97311
AM
143static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
144static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
145static bfd_vma xcoff_loader_symbol_offset
146 PARAMS ((bfd *, struct internal_ldhdr *));
147static bfd_vma xcoff_loader_reloc_offset
148 PARAMS ((bfd *, struct internal_ldhdr *));
14958a43 149
252b5132
RH
150/* We use our own tdata type. Its first field is the COFF tdata type,
151 so the COFF routines are compatible. */
152
7f6d05e8
CP
153boolean
154_bfd_xcoff_mkobject (abfd)
252b5132
RH
155 bfd *abfd;
156{
157 coff_data_type *coff;
158
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;
169
170 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
171
172 /* We set cputype to -1 to indicate that it has not been
173 initialized. */
174 xcoff_data (abfd)->cputype = -1;
175
176 xcoff_data (abfd)->csects = NULL;
177 xcoff_data (abfd)->debug_indices = NULL;
178
beb1bf64
TR
179 /* text section alignment is different than the default */
180 /* xcoff_data (abfd)->text_align_power = 5; */
181
252b5132
RH
182 return true;
183}
184
185/* Copy XCOFF data from one BFD to another. */
186
7f6d05e8
CP
187boolean
188_bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
252b5132
RH
189 bfd *ibfd;
190 bfd *obfd;
191{
192 struct xcoff_tdata *ix, *ox;
193 asection *sec;
194
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
204 {
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;
210 }
211 if (ix->snentry == 0)
212 ox->snentry = 0;
213 else
214 {
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;
220 }
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;
228}
229
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. */
234
7f6d05e8
CP
235boolean
236_bfd_xcoff_is_local_label_name (abfd, name)
5f771d47
ILT
237 bfd *abfd ATTRIBUTE_UNUSED;
238 const char *name ATTRIBUTE_UNUSED;
252b5132
RH
239{
240 return false;
241}
7f6d05e8 242\f
beb1bf64
TR
243
244
14958a43
CP
245void
246_bfd_xcoff_swap_sym_in (abfd, ext1, in1)
7f6d05e8
CP
247 bfd *abfd;
248 PTR ext1;
249 PTR in1;
250{
251 SYMENT *ext = (SYMENT *)ext1;
f4ffd778 252 struct internal_syment * in = (struct internal_syment *)in1;
7f6d05e8 253
f4ffd778
NC
254 if (ext->e.e_name[0] != 0)
255 {
256 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
257 }
258 else
259 {
260 in->_n._n_n._n_zeroes = 0;
261 in->_n._n_n._n_offset =
262 bfd_h_get_32 (abfd, (bfd_byte *) ext->e.e.e_offset);
263 }
7f6d05e8 264
f4ffd778
NC
265 in->n_value = bfd_h_get_32 (abfd, (bfd_byte *) ext->e_value);
266 in->n_scnum = bfd_h_get_16 (abfd, (bfd_byte *) ext->e_scnum);
267 in->n_type = bfd_h_get_16 (abfd, (bfd_byte *) ext->e_type);
268 in->n_sclass = bfd_h_get_8 (abfd, ext->e_sclass);
269 in->n_numaux = bfd_h_get_8 (abfd, ext->e_numaux);
7f6d05e8
CP
270}
271
14958a43
CP
272unsigned int
273_bfd_xcoff_swap_sym_out (abfd, inp, extp)
7f6d05e8
CP
274 bfd *abfd;
275 PTR inp;
276 PTR extp;
277{
278 struct internal_syment *in = (struct internal_syment *)inp;
279 SYMENT *ext =(SYMENT *)extp;
280
f4ffd778
NC
281 if (in->_n._n_name[0] != 0)
282 {
283 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
284 }
285 else
286 {
287 bfd_h_put_32 (abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
288 bfd_h_put_32 (abfd, in->_n._n_n._n_offset,
289 (bfd_byte *) ext->e.e.e_offset);
290 }
7f6d05e8 291
f4ffd778
NC
292 bfd_h_put_32 (abfd, in->n_value , (bfd_byte *) ext->e_value);
293 bfd_h_put_16 (abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
294 bfd_h_put_16 (abfd, in->n_type , (bfd_byte *) ext->e_type);
295 bfd_h_put_8 (abfd, in->n_sclass , ext->e_sclass);
296 bfd_h_put_8 (abfd, in->n_numaux , ext->e_numaux);
7f6d05e8
CP
297 return bfd_coff_symesz (abfd);
298}
299
300#define PUTWORD bfd_h_put_32
301#define PUTHALF bfd_h_put_16
302#define PUTBYTE bfd_h_put_8
303#define GETWORD bfd_h_get_32
304#define GETHALF bfd_h_get_16
305#define GETBYTE bfd_h_get_8
306
14958a43
CP
307void
308_bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
7f6d05e8
CP
309 bfd *abfd;
310 PTR ext1;
311 int type;
312 int class;
313 int indx;
314 int numaux;
315 PTR in1;
316{
f4ffd778 317 AUXENT * ext = (AUXENT *)ext1;
7f6d05e8
CP
318 union internal_auxent *in = (union internal_auxent *)in1;
319
f4ffd778
NC
320 switch (class)
321 {
7f6d05e8 322 case C_FILE:
f4ffd778
NC
323 if (ext->x_file.x_fname[0] == 0)
324 {
7f6d05e8 325 in->x_file.x_n.x_zeroes = 0;
beb1bf64 326 in->x_file.x_n.x_offset =
f4ffd778
NC
327 bfd_h_get_32 (abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
328 }
329 else
330 {
331 if (numaux > 1)
332 {
333 if (indx == 0)
334 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
335 numaux * sizeof (AUXENT));
336 }
337 else
338 {
339 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
340 }
341 }
7f6d05e8
CP
342 goto end;
343
344 /* RS/6000 "csect" auxents */
345 case C_EXT:
346 case C_HIDEXT:
347 if (indx + 1 == numaux)
348 {
beb1bf64 349 in->x_csect.x_scnlen.l =
7f6d05e8
CP
350 bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
351 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
352 ext->x_csect.x_parmhash);
353 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
354 /* We don't have to hack bitfields in x_smtyp because it's
355 defined by shifts-and-ands, which are equivalent on all
356 byte orders. */
357 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
358 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
359 in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
360 in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
361 goto end;
362 }
363 break;
364
365 case C_STAT:
366 case C_LEAFSTAT:
367 case C_HIDDEN:
f4ffd778
NC
368 if (type == T_NULL)
369 {
beb1bf64 370 in->x_scn.x_scnlen = bfd_h_get_32(abfd,
7f6d05e8 371 (bfd_byte *) ext->x_scn.x_scnlen);
beb1bf64 372 in->x_scn.x_nreloc = bfd_h_get_16(abfd,
7f6d05e8 373 (bfd_byte *) ext->x_scn.x_nreloc);
beb1bf64 374 in->x_scn.x_nlinno = bfd_h_get_16(abfd,
7f6d05e8
CP
375 (bfd_byte *) ext->x_scn.x_nlinno);
376 /* PE defines some extra fields; we zero them out for
377 safety. */
378 in->x_scn.x_checksum = 0;
379 in->x_scn.x_associated = 0;
380 in->x_scn.x_comdat = 0;
381
382 goto end;
383 }
384 break;
385 }
386
387 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
388 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
389
390 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
391 {
392 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *)
393 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
394 in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
395 ext->x_sym.x_fcnary.x_fcn.x_endndx);
396 }
397 else
398 {
399 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
400 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
401 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
402 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
403 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
404 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
405 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
406 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
407 }
7f6d05e8 408
f4ffd778
NC
409 if (ISFCN (type))
410 {
411 in->x_sym.x_misc.x_fsize = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
412 }
413 else
414 {
415 in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_16 (abfd, (bfd_byte *)
416 ext->x_sym.x_misc.x_lnsz.x_lnno);
417 in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16 (abfd, (bfd_byte *)
418 ext->x_sym.x_misc.x_lnsz.x_size);
419 }
7f6d05e8 420
f4ffd778
NC
421 end: ;
422 /* The semicolon is because MSVC doesn't like labels at
423 end of block. */
7f6d05e8
CP
424}
425
beb1bf64
TR
426
427
14958a43
CP
428unsigned int
429_bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
7f6d05e8
CP
430 bfd *abfd;
431 PTR inp;
432 int type;
433 int class;
434 int indx ATTRIBUTE_UNUSED;
435 int numaux ATTRIBUTE_UNUSED;
436 PTR extp;
437{
438 union internal_auxent *in = (union internal_auxent *)inp;
439 AUXENT *ext = (AUXENT *)extp;
440
441 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
442 switch (class)
443 {
f4ffd778
NC
444 case C_FILE:
445 if (in->x_file.x_fname[0] == 0)
446 {
447 PUTWORD (abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
448 PUTWORD (abfd,
449 in->x_file.x_n.x_offset,
450 (bfd_byte *) ext->x_file.x_n.x_offset);
451 }
452 else
453 {
454 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
455 }
7f6d05e8 456 goto end;
f4ffd778
NC
457
458 /* RS/6000 "csect" auxents */
459 case C_EXT:
460 case C_HIDEXT:
461 if (indx + 1 == numaux)
462 {
463 PUTWORD (abfd, in->x_csect.x_scnlen.l,ext->x_csect.x_scnlen);
464 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
465 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
466 /* We don't have to hack bitfields in x_smtyp because it's
467 defined by shifts-and-ands, which are equivalent on all
468 byte orders. */
469 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
470 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
471 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
472 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
473 goto end;
474 }
475 break;
476
477 case C_STAT:
478 case C_LEAFSTAT:
479 case C_HIDDEN:
480 if (type == T_NULL)
481 {
482 bfd_h_put_32(abfd, in->x_scn.x_scnlen, (bfd_byte *) ext->x_scn.x_scnlen);
483 bfd_h_put_16(abfd, in->x_scn.x_nreloc, (bfd_byte *) ext->x_scn.x_nreloc);
484 bfd_h_put_16(abfd, in->x_scn.x_nlinno, (bfd_byte *) ext->x_scn.x_nlinno);
485 goto end;
486 }
487 break;
7f6d05e8 488 }
7f6d05e8 489
f4ffd778 490 PUTWORD (abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
492055e6 491 bfd_h_put_16 (abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
7f6d05e8
CP
492
493 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
494 {
f4ffd778
NC
495 bfd_h_put_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
496 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
497 PUTWORD (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
498 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
7f6d05e8
CP
499 }
500 else
501 {
502 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
503 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
504 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
505 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
506 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
507 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
508 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
509 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
510 }
511
512 if (ISFCN (type))
513 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
514 (bfd_byte *) ext->x_sym.x_misc.x_fsize);
515 else
516 {
f4ffd778
NC
517 bfd_h_put_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
518 (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno);
519 bfd_h_put_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
520 (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size);
7f6d05e8
CP
521 }
522
523end:
524 return bfd_coff_auxesz (abfd);
525}
beb1bf64
TR
526
527
252b5132
RH
528\f
529/* The XCOFF reloc table. Actually, XCOFF relocations specify the
530 bitsize and whether they are signed or not, along with a
531 conventional type. This table is for the types, which are used for
532 different algorithms for putting in the reloc. Many of these
533 relocs need special_function entries, which I have not written. */
534
7f6d05e8
CP
535
536reloc_howto_type xcoff_howto_table[] =
252b5132
RH
537{
538 /* Standard 32 bit relocation. */
c5930ee6
KH
539 HOWTO (0, /* type */
540 0, /* rightshift */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
542 32, /* bitsize */
543 false, /* pc_relative */
544 0, /* bitpos */
252b5132 545 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
546 0, /* special_function */
547 "R_POS", /* name */
548 true, /* partial_inplace */
549 0xffffffff, /* src_mask */
550 0xffffffff, /* dst_mask */
252b5132
RH
551 false), /* pcrel_offset */
552
553 /* 32 bit relocation, but store negative value. */
c5930ee6
KH
554 HOWTO (1, /* type */
555 0, /* rightshift */
556 -2, /* size (0 = byte, 1 = short, 2 = long) */
557 32, /* bitsize */
558 false, /* pc_relative */
559 0, /* bitpos */
252b5132 560 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
561 0, /* special_function */
562 "R_NEG", /* name */
563 true, /* partial_inplace */
564 0xffffffff, /* src_mask */
565 0xffffffff, /* dst_mask */
252b5132
RH
566 false), /* pcrel_offset */
567
568 /* 32 bit PC relative relocation. */
c5930ee6
KH
569 HOWTO (2, /* type */
570 0, /* rightshift */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
572 32, /* bitsize */
573 true, /* pc_relative */
574 0, /* bitpos */
252b5132 575 complain_overflow_signed, /* complain_on_overflow */
c5930ee6
KH
576 0, /* special_function */
577 "R_REL", /* name */
578 true, /* partial_inplace */
579 0xffffffff, /* src_mask */
580 0xffffffff, /* dst_mask */
252b5132 581 false), /* pcrel_offset */
c5930ee6 582
252b5132 583 /* 16 bit TOC relative relocation. */
c5930ee6
KH
584 HOWTO (3, /* type */
585 0, /* rightshift */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
587 16, /* bitsize */
588 false, /* pc_relative */
589 0, /* bitpos */
252b5132 590 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
591 0, /* special_function */
592 "R_TOC", /* name */
593 true, /* partial_inplace */
594 0xffff, /* src_mask */
595 0xffff, /* dst_mask */
252b5132 596 false), /* pcrel_offset */
c5930ee6 597
252b5132 598 /* I don't really know what this is. */
c5930ee6
KH
599 HOWTO (4, /* type */
600 1, /* rightshift */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
602 32, /* bitsize */
603 false, /* pc_relative */
604 0, /* bitpos */
252b5132 605 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
606 0, /* special_function */
607 "R_RTB", /* name */
608 true, /* partial_inplace */
609 0xffffffff, /* src_mask */
610 0xffffffff, /* dst_mask */
252b5132 611 false), /* pcrel_offset */
c5930ee6 612
252b5132 613 /* External TOC relative symbol. */
c5930ee6
KH
614 HOWTO (5, /* type */
615 0, /* rightshift */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
617 16, /* bitsize */
618 false, /* pc_relative */
619 0, /* bitpos */
252b5132 620 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
621 0, /* special_function */
622 "R_GL", /* name */
623 true, /* partial_inplace */
624 0xffff, /* src_mask */
625 0xffff, /* dst_mask */
252b5132 626 false), /* pcrel_offset */
c5930ee6 627
252b5132 628 /* Local TOC relative symbol. */
c5930ee6
KH
629 HOWTO (6, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 16, /* bitsize */
633 false, /* pc_relative */
634 0, /* bitpos */
252b5132 635 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
636 0, /* special_function */
637 "R_TCL", /* name */
638 true, /* partial_inplace */
639 0xffff, /* src_mask */
640 0xffff, /* dst_mask */
252b5132 641 false), /* pcrel_offset */
c5930ee6 642
5f771d47 643 EMPTY_HOWTO (7),
c5930ee6 644
252b5132 645 /* Non modifiable absolute branch. */
c5930ee6
KH
646 HOWTO (8, /* type */
647 0, /* rightshift */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
649 26, /* bitsize */
650 false, /* pc_relative */
651 0, /* bitpos */
252b5132 652 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
653 0, /* special_function */
654 "R_BA", /* name */
655 true, /* partial_inplace */
656 0x3fffffc, /* src_mask */
657 0x3fffffc, /* dst_mask */
252b5132 658 false), /* pcrel_offset */
c5930ee6 659
5f771d47 660 EMPTY_HOWTO (9),
252b5132
RH
661
662 /* Non modifiable relative branch. */
c5930ee6
KH
663 HOWTO (0xa, /* type */
664 0, /* rightshift */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
666 26, /* bitsize */
667 true, /* pc_relative */
668 0, /* bitpos */
252b5132 669 complain_overflow_signed, /* complain_on_overflow */
c5930ee6
KH
670 0, /* special_function */
671 "R_BR", /* name */
672 true, /* partial_inplace */
673 0x3fffffc, /* src_mask */
674 0x3fffffc, /* dst_mask */
252b5132 675 false), /* pcrel_offset */
c5930ee6 676
5f771d47 677 EMPTY_HOWTO (0xb),
252b5132
RH
678
679 /* Indirect load. */
c5930ee6
KH
680 HOWTO (0xc, /* type */
681 0, /* rightshift */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
683 16, /* bitsize */
684 false, /* pc_relative */
685 0, /* bitpos */
252b5132 686 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
687 0, /* special_function */
688 "R_RL", /* name */
689 true, /* partial_inplace */
690 0xffff, /* src_mask */
691 0xffff, /* dst_mask */
252b5132 692 false), /* pcrel_offset */
c5930ee6 693
252b5132 694 /* Load address. */
c5930ee6
KH
695 HOWTO (0xd, /* type */
696 0, /* rightshift */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
698 16, /* bitsize */
699 false, /* pc_relative */
700 0, /* bitpos */
252b5132 701 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
702 0, /* special_function */
703 "R_RLA", /* name */
704 true, /* partial_inplace */
705 0xffff, /* src_mask */
706 0xffff, /* dst_mask */
252b5132 707 false), /* pcrel_offset */
c5930ee6 708
5f771d47 709 EMPTY_HOWTO (0xe),
c5930ee6 710
252b5132 711 /* Non-relocating reference. */
c5930ee6
KH
712 HOWTO (0xf, /* type */
713 0, /* rightshift */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
715 32, /* bitsize */
716 false, /* pc_relative */
717 0, /* bitpos */
252b5132 718 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
719 0, /* special_function */
720 "R_REF", /* name */
721 false, /* partial_inplace */
722 0, /* src_mask */
723 0, /* dst_mask */
252b5132 724 false), /* pcrel_offset */
c5930ee6 725
5f771d47
ILT
726 EMPTY_HOWTO (0x10),
727 EMPTY_HOWTO (0x11),
c5930ee6 728
252b5132 729 /* TOC relative indirect load. */
c5930ee6
KH
730 HOWTO (0x12, /* type */
731 0, /* rightshift */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 false, /* pc_relative */
735 0, /* bitpos */
252b5132 736 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
737 0, /* special_function */
738 "R_TRL", /* name */
739 true, /* partial_inplace */
740 0xffff, /* src_mask */
741 0xffff, /* dst_mask */
252b5132 742 false), /* pcrel_offset */
c5930ee6 743
252b5132 744 /* TOC relative load address. */
c5930ee6
KH
745 HOWTO (0x13, /* type */
746 0, /* rightshift */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
748 16, /* bitsize */
749 false, /* pc_relative */
750 0, /* bitpos */
252b5132 751 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
752 0, /* special_function */
753 "R_TRLA", /* name */
754 true, /* partial_inplace */
755 0xffff, /* src_mask */
756 0xffff, /* dst_mask */
252b5132 757 false), /* pcrel_offset */
c5930ee6 758
252b5132 759 /* Modifiable relative branch. */
c5930ee6
KH
760 HOWTO (0x14, /* type */
761 1, /* rightshift */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
763 32, /* bitsize */
764 false, /* pc_relative */
765 0, /* bitpos */
252b5132 766 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
767 0, /* special_function */
768 "R_RRTBI", /* name */
769 true, /* partial_inplace */
770 0xffffffff, /* src_mask */
771 0xffffffff, /* dst_mask */
252b5132 772 false), /* pcrel_offset */
c5930ee6 773
252b5132 774 /* Modifiable absolute branch. */
c5930ee6
KH
775 HOWTO (0x15, /* type */
776 1, /* rightshift */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
778 32, /* bitsize */
779 false, /* pc_relative */
780 0, /* bitpos */
252b5132 781 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
782 0, /* special_function */
783 "R_RRTBA", /* name */
784 true, /* partial_inplace */
785 0xffffffff, /* src_mask */
786 0xffffffff, /* dst_mask */
252b5132 787 false), /* pcrel_offset */
c5930ee6 788
252b5132 789 /* Modifiable call absolute indirect. */
c5930ee6
KH
790 HOWTO (0x16, /* type */
791 0, /* rightshift */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
793 16, /* bitsize */
794 false, /* pc_relative */
795 0, /* bitpos */
252b5132 796 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
797 0, /* special_function */
798 "R_CAI", /* name */
799 true, /* partial_inplace */
800 0xffff, /* src_mask */
801 0xffff, /* dst_mask */
252b5132 802 false), /* pcrel_offset */
c5930ee6 803
252b5132 804 /* Modifiable call relative. */
c5930ee6
KH
805 HOWTO (0x17, /* type */
806 0, /* rightshift */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
808 16, /* bitsize */
809 false, /* pc_relative */
810 0, /* bitpos */
252b5132 811 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
812 0, /* special_function */
813 "R_CREL", /* name */
814 true, /* partial_inplace */
815 0xffff, /* src_mask */
816 0xffff, /* dst_mask */
252b5132 817 false), /* pcrel_offset */
c5930ee6 818
252b5132 819 /* Modifiable branch absolute. */
c5930ee6
KH
820 HOWTO (0x18, /* type */
821 0, /* rightshift */
822 2, /* size (0 = byte, 1 = short, 2 = long) */
823 26, /* bitsize */
824 false, /* pc_relative */
825 0, /* bitpos */
252b5132 826 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
827 0, /* special_function */
828 "R_RBA", /* name */
829 true, /* partial_inplace */
830 0xffff, /* src_mask */
831 0xffff, /* dst_mask */
252b5132 832 false), /* pcrel_offset */
c5930ee6 833
252b5132 834 /* Modifiable branch absolute. */
c5930ee6
KH
835 HOWTO (0x19, /* type */
836 0, /* rightshift */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
838 32, /* bitsize */
839 false, /* pc_relative */
840 0, /* bitpos */
252b5132 841 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
842 0, /* special_function */
843 "R_RBAC", /* name */
844 true, /* partial_inplace */
845 0xffff, /* src_mask */
846 0xffff, /* dst_mask */
252b5132 847 false), /* pcrel_offset */
c5930ee6 848
252b5132 849 /* Modifiable branch relative. */
c5930ee6
KH
850 HOWTO (0x1a, /* type */
851 0, /* rightshift */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
853 26, /* bitsize */
854 false, /* pc_relative */
855 0, /* bitpos */
252b5132 856 complain_overflow_signed, /* complain_on_overflow */
c5930ee6
KH
857 0, /* special_function */
858 "R_RBR", /* name */
859 true, /* partial_inplace */
860 0xffff, /* src_mask */
861 0xffff, /* dst_mask */
252b5132 862 false), /* pcrel_offset */
c5930ee6 863
252b5132 864 /* Modifiable branch absolute. */
c5930ee6
KH
865 HOWTO (0x1b, /* type */
866 0, /* rightshift */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
868 16, /* bitsize */
869 false, /* pc_relative */
870 0, /* bitpos */
252b5132 871 complain_overflow_bitfield, /* complain_on_overflow */
c5930ee6
KH
872 0, /* special_function */
873 "R_RBRC", /* name */
874 true, /* partial_inplace */
875 0xffff, /* src_mask */
876 0xffff, /* dst_mask */
7f6d05e8 877 false), /* pcrel_offset */
beb1bf64 878
7f6d05e8
CP
879 HOWTO (0, /* type */
880 0, /* rightshift */
881 4, /* size (0 = byte, 1 = short, 2 = long) */
882 64, /* bitsize */
883 false, /* pc_relative */
884 0, /* bitpos */
885 complain_overflow_bitfield, /* complain_on_overflow */
886 0, /* special_function */
887 "R_POS", /* name */
888 true, /* partial_inplace */
889 MINUS_ONE, /* src_mask */
890 MINUS_ONE, /* dst_mask */
252b5132 891 false) /* pcrel_offset */
7f6d05e8 892
252b5132
RH
893};
894
7f6d05e8
CP
895void
896_bfd_xcoff_rtype2howto (relent, internal)
252b5132
RH
897 arelent *relent;
898 struct internal_reloc *internal;
899{
900 relent->howto = xcoff_howto_table + internal->r_type;
901
beb1bf64
TR
902 /* Check for relocs we don't know of. */
903 if (internal->r_type
904 >= sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]))
905 abort ();
906 if (internal->r_type != relent->howto->type)
907 abort ();
5ea1af0d 908
252b5132
RH
909 /* The r_size field of an XCOFF reloc encodes the bitsize of the
910 relocation, as well as indicating whether it is signed or not.
911 Doublecheck that the relocation information gathered from the
c5930ee6
KH
912 type matches this information. The bitsize is not significant
913 for R_REF relocs. */
914 if (relent->howto->dst_mask != 0
beb1bf64 915 && (relent->howto->bitsize
c5930ee6 916 != ((unsigned int) internal->r_size & 0x3f) + 1))
252b5132
RH
917 abort ();
918#if 0
919 if ((internal->r_size & 0x80) != 0
920 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
921 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
922 abort ();
923#endif
924}
925
7f6d05e8
CP
926reloc_howto_type *
927_bfd_xcoff_reloc_type_lookup (abfd, code)
5f771d47 928 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
929 bfd_reloc_code_real_type code;
930{
931 switch (code)
932 {
933 case BFD_RELOC_PPC_B26:
934 return &xcoff_howto_table[0xa];
935 case BFD_RELOC_PPC_BA26:
936 return &xcoff_howto_table[8];
937 case BFD_RELOC_PPC_TOC16:
938 return &xcoff_howto_table[3];
939 case BFD_RELOC_32:
940 case BFD_RELOC_CTOR:
941 return &xcoff_howto_table[0];
7f6d05e8
CP
942 case BFD_RELOC_64:
943 return &xcoff_howto_table[0x1c];
252b5132
RH
944 default:
945 return NULL;
946 }
947}
beb1bf64 948
252b5132
RH
949\f
950/* XCOFF archive support. The original version of this code was by
951 Damon A. Permezel. It was enhanced to permit cross support, and
952 writing archive files, by Ian Lance Taylor, Cygnus Support.
953
954 XCOFF uses its own archive format. Everything is hooked together
955 with file offset links, so it is possible to rapidly update an
956 archive in place. Of course, we don't do that. An XCOFF archive
957 has a real file header, not just an ARMAG string. The structure of
958 the file header and of each archive header appear below.
959
960 An XCOFF archive also has a member table, which is a list of
961 elements in the archive (you can get that by looking through the
962 linked list, but you have to read a lot more of the file). The
963 member table has a normal archive header with an empty name. It is
964 normally (and perhaps must be) the second to last entry in the
965 archive. The member table data is almost printable ASCII. It
966 starts with a 12 character decimal string which is the number of
967 entries in the table. For each entry it has a 12 character decimal
968 string which is the offset in the archive of that member. These
969 entries are followed by a series of null terminated strings which
970 are the member names for each entry.
971
972 Finally, an XCOFF archive has a global symbol table, which is what
973 we call the armap. The global symbol table has a normal archive
974 header with an empty name. It is normally (and perhaps must be)
975 the last entry in the archive. The contents start with a four byte
976 binary number which is the number of entries. This is followed by
977 a that many four byte binary numbers; each is the file offset of an
978 entry in the archive. These numbers are followed by a series of
5ea1af0d
GK
979 null terminated strings, which are symbol names.
980
981 AIX 4.3 introduced a new archive format which can handle larger
982 files and also 32- and 64-bit objects in the same archive. The
983 things said above remain true except that there is now more than
984 one global symbol table. The one is used to index 32-bit objects,
985 the other for 64-bit objects.
986
987 The new archives (recognizable by the new ARMAG string) has larger
988 field lengths so that we cannot really share any code. Also we have
989 to take care that we are not generating the new form of archives
990 on AIX 4.2 or earlier systems. */
252b5132 991
5ea1af0d
GK
992/* XCOFF archives use this as a magic string. Note that both strings
993 have the same length. */
252b5132 994
252b5132 995
252b5132 996
252b5132
RH
997/* Read in the armap of an XCOFF archive. */
998
7f6d05e8
CP
999boolean
1000_bfd_xcoff_slurp_armap (abfd)
252b5132
RH
1001 bfd *abfd;
1002{
1003 file_ptr off;
252b5132
RH
1004 size_t namlen;
1005 bfd_size_type sz;
1006 bfd_byte *contents, *cend;
31612ca6 1007 bfd_vma c, i;
252b5132
RH
1008 carsym *arsym;
1009 bfd_byte *p;
1010
1011 if (xcoff_ardata (abfd) == NULL)
1012 {
1013 bfd_has_map (abfd) = false;
1014 return true;
1015 }
1016
5ea1af0d 1017 if (! xcoff_big_format_p (abfd))
252b5132 1018 {
5ea1af0d
GK
1019 /* This is for the old format. */
1020 struct xcoff_ar_hdr hdr;
1021
1022 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1023 if (off == 0)
1024 {
1025 bfd_has_map (abfd) = false;
1026 return true;
1027 }
1028
1029 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1030 return false;
1031
1032 /* The symbol table starts with a normal archive header. */
1033 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
1034 return false;
1035
1036 /* Skip the name (normally empty). */
1037 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1038 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1039 return false;
1040
1041 sz = strtol (hdr.size, (char **) NULL, 10);
31612ca6
GK
1042
1043 /* Read in the entire symbol table. */
1044 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1045 if (contents == NULL)
1046 return false;
1047 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
1048 return false;
1049
1050 /* The symbol table starts with a four byte count. */
1051 c = bfd_h_get_32 (abfd, contents);
beb1bf64 1052
31612ca6
GK
1053 if (c * 4 >= sz)
1054 {
1055 bfd_set_error (bfd_error_bad_value);
1056 return false;
1057 }
beb1bf64 1058
31612ca6
GK
1059 bfd_ardata (abfd)->symdefs = ((carsym *)
1060 bfd_alloc (abfd, c * sizeof (carsym)));
1061 if (bfd_ardata (abfd)->symdefs == NULL)
1062 return false;
beb1bf64 1063
31612ca6
GK
1064 /* After the count comes a list of four byte file offsets. */
1065 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1066 i < c;
1067 ++i, ++arsym, p += 4)
1068 arsym->file_offset = bfd_h_get_32 (abfd, p);
252b5132 1069 }
5ea1af0d
GK
1070 else
1071 {
1072 /* This is for the new format. */
1073 struct xcoff_ar_hdr_big hdr;
252b5132 1074
5ea1af0d
GK
1075 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1076 if (off == 0)
1077 {
1078 bfd_has_map (abfd) = false;
1079 return true;
1080 }
252b5132 1081
5ea1af0d
GK
1082 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1083 return false;
252b5132 1084
5ea1af0d
GK
1085 /* The symbol table starts with a normal archive header. */
1086 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
1087 != SIZEOF_AR_HDR_BIG)
1088 return false;
1089
1090 /* Skip the name (normally empty). */
1091 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1092 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1093 return false;
1094
1095 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1096 machines) since the field width is 20 and there numbers with more
1097 than 32 bits can be represented. */
1098 sz = strtol (hdr.size, (char **) NULL, 10);
252b5132 1099
31612ca6
GK
1100 /* Read in the entire symbol table. */
1101 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1102 if (contents == NULL)
1103 return false;
1104 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
1105 return false;
252b5132 1106
31612ca6
GK
1107 /* The symbol table starts with an eight byte count. */
1108 c = bfd_h_get_64 (abfd, contents);
252b5132 1109
31612ca6
GK
1110 if (c * 8 >= sz)
1111 {
1112 bfd_set_error (bfd_error_bad_value);
1113 return false;
1114 }
beb1bf64 1115
31612ca6
GK
1116 bfd_ardata (abfd)->symdefs = ((carsym *)
1117 bfd_alloc (abfd, c * sizeof (carsym)));
1118 if (bfd_ardata (abfd)->symdefs == NULL)
1119 return false;
beb1bf64 1120
31612ca6
GK
1121 /* After the count comes a list of eight byte file offsets. */
1122 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1123 i < c;
1124 ++i, ++arsym, p += 8)
1125 arsym->file_offset = bfd_h_get_64 (abfd, p);
252b5132
RH
1126 }
1127
252b5132
RH
1128 /* After the file offsets come null terminated symbol names. */
1129 cend = contents + sz;
1130 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1131 i < c;
1132 ++i, ++arsym, p += strlen ((char *) p) + 1)
1133 {
1134 if (p >= cend)
1135 {
1136 bfd_set_error (bfd_error_bad_value);
1137 return false;
1138 }
1139 arsym->name = (char *) p;
1140 }
1141
1142 bfd_ardata (abfd)->symdef_count = c;
1143 bfd_has_map (abfd) = true;
1144
1145 return true;
1146}
1147
1148/* See if this is an XCOFF archive. */
1149
7f6d05e8
CP
1150const bfd_target *
1151_bfd_xcoff_archive_p (abfd)
252b5132
RH
1152 bfd *abfd;
1153{
5ea1af0d 1154 char magic[SXCOFFARMAG];
252b5132 1155
5ea1af0d 1156 if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG)
252b5132
RH
1157 {
1158 if (bfd_get_error () != bfd_error_system_call)
1159 bfd_set_error (bfd_error_wrong_format);
1160 return NULL;
1161 }
1162
5ea1af0d
GK
1163 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1164 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
252b5132
RH
1165 {
1166 bfd_set_error (bfd_error_wrong_format);
1167 return NULL;
1168 }
1169
1170 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1171 involves a cast, we can't do it as the left operand of
1172 assignment. */
1173 abfd->tdata.aout_ar_data =
1174 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
1175
1176 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1177 return NULL;
1178
252b5132
RH
1179 bfd_ardata (abfd)->cache = NULL;
1180 bfd_ardata (abfd)->archive_head = NULL;
1181 bfd_ardata (abfd)->symdefs = NULL;
1182 bfd_ardata (abfd)->extended_names = NULL;
1183
5ea1af0d
GK
1184 /* Now handle the two formats. */
1185 if (magic[1] != 'b')
1186 {
1187 /* This is the old format. */
1188 struct xcoff_ar_file_hdr hdr;
252b5132 1189
5ea1af0d
GK
1190 /* Copy over the magic string. */
1191 memcpy (hdr.magic, magic, SXCOFFARMAG);
1192
1193 /* Now read the rest of the file header. */
1194 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1,
1195 abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
1196 {
1197 if (bfd_get_error () != bfd_error_system_call)
1198 bfd_set_error (bfd_error_wrong_format);
1199 return NULL;
1200 }
1201
1202 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1203 (char **) NULL, 10);
1204
1205 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
1206 if (bfd_ardata (abfd)->tdata == NULL)
1207 return NULL;
1208
1209 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1210 }
1211 else
1212 {
1213 /* This is the new format. */
1214 struct xcoff_ar_file_hdr_big hdr;
1215
1216 /* Copy over the magic string. */
1217 memcpy (hdr.magic, magic, SXCOFFARMAG);
1218
1219 /* Now read the rest of the file header. */
1220 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
1221 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1222 {
1223 if (bfd_get_error () != bfd_error_system_call)
1224 bfd_set_error (bfd_error_wrong_format);
1225 return NULL;
1226 }
1227
1228 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1229 machines) since the field width is 20 and there numbers with more
1230 than 32 bits can be represented. */
1231 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1232 (char **) NULL, 10);
1233
1234 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
1235 if (bfd_ardata (abfd)->tdata == NULL)
1236 return NULL;
1237
1238 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1239 }
252b5132 1240
7f6d05e8 1241 if (! _bfd_xcoff_slurp_armap (abfd))
252b5132
RH
1242 {
1243 bfd_release (abfd, bfd_ardata (abfd));
1244 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1245 return NULL;
1246 }
1247
1248 return abfd->xvec;
1249}
1250
1251/* Read the archive header in an XCOFF archive. */
1252
7f6d05e8
CP
1253PTR
1254_bfd_xcoff_read_ar_hdr (abfd)
252b5132
RH
1255 bfd *abfd;
1256{
252b5132 1257 size_t namlen;
252b5132
RH
1258 struct areltdata *ret;
1259
252b5132
RH
1260 ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
1261 if (ret == NULL)
1262 return NULL;
5ea1af0d
GK
1263
1264 if (! xcoff_big_format_p (abfd))
1265 {
1266 struct xcoff_ar_hdr hdr;
1267 struct xcoff_ar_hdr *hdrp;
1268
1269 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
1270 {
1271 free (ret);
1272 return NULL;
1273 }
1274
1275 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1276 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd,
1277 SIZEOF_AR_HDR + namlen + 1);
1278 if (hdrp == NULL)
1279 {
1280 free (ret);
1281 return NULL;
1282 }
1283 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1284 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
1285 {
1286 free (ret);
1287 return NULL;
1288 }
1289 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1290
1291 ret->arch_header = (char *) hdrp;
1292 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1293 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1294 }
1295 else
1296 {
1297 struct xcoff_ar_hdr_big hdr;
1298 struct xcoff_ar_hdr_big *hdrp;
1299
1300 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
1301 != SIZEOF_AR_HDR_BIG)
1302 {
1303 free (ret);
1304 return NULL;
1305 }
1306
1307 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1308 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd,
1309 SIZEOF_AR_HDR_BIG
1310 + namlen + 1);
1311 if (hdrp == NULL)
1312 {
1313 free (ret);
1314 return NULL;
1315 }
1316 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1317 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen)
1318 {
1319 free (ret);
1320 return NULL;
1321 }
1322 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1323
1324 ret->arch_header = (char *) hdrp;
1325 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1326 machines) since the field width is 20 and there numbers with more
1327 than 32 bits can be represented. */
1328 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1329 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1330 }
252b5132
RH
1331
1332 /* Skip over the XCOFFARFMAG at the end of the file name. */
1333 if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1334 return NULL;
1335
1336 return (PTR) ret;
1337}
1338
1339/* Open the next element in an XCOFF archive. */
1340
7f6d05e8
CP
1341bfd *
1342_bfd_xcoff_openr_next_archived_file (archive, last_file)
252b5132
RH
1343 bfd *archive;
1344 bfd *last_file;
1345{
1346 file_ptr filestart;
1347
1348 if (xcoff_ardata (archive) == NULL)
1349 {
1350 bfd_set_error (bfd_error_invalid_operation);
1351 return NULL;
1352 }
1353
5ea1af0d
GK
1354 if (! xcoff_big_format_p (archive))
1355 {
1356 if (last_file == NULL)
1357 filestart = bfd_ardata (archive)->first_file_filepos;
1358 else
1359 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1360 10);
1361
1362 if (filestart == 0
1363 || filestart == strtol (xcoff_ardata (archive)->memoff,
1364 (char **) NULL, 10)
1365 || filestart == strtol (xcoff_ardata (archive)->symoff,
1366 (char **) NULL, 10))
1367 {
1368 bfd_set_error (bfd_error_no_more_archived_files);
1369 return NULL;
1370 }
1371 }
252b5132 1372 else
252b5132 1373 {
5ea1af0d
GK
1374 if (last_file == NULL)
1375 filestart = bfd_ardata (archive)->first_file_filepos;
1376 else
1377 /* XXX These actually have to be a calls to strtoll (at least
1378 on 32-bit machines) since the fields's width is 20 and
1379 there numbers with more than 32 bits can be represented. */
1380 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1381 10);
1382
1383 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1384 machines) since the fields's width is 20 and there numbers with more
1385 than 32 bits can be represented. */
1386 if (filestart == 0
1387 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1388 (char **) NULL, 10)
1389 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1390 (char **) NULL, 10))
1391 {
1392 bfd_set_error (bfd_error_no_more_archived_files);
1393 return NULL;
1394 }
252b5132
RH
1395 }
1396
1397 return _bfd_get_elt_at_filepos (archive, filestart);
1398}
1399
1400/* Stat an element in an XCOFF archive. */
1401
7f6d05e8
CP
1402int
1403_bfd_xcoff_generic_stat_arch_elt (abfd, s)
252b5132
RH
1404 bfd *abfd;
1405 struct stat *s;
1406{
252b5132
RH
1407 if (abfd->arelt_data == NULL)
1408 {
1409 bfd_set_error (bfd_error_invalid_operation);
1410 return -1;
1411 }
1412
5ea1af0d
GK
1413 if (! xcoff_big_format_p (abfd))
1414 {
1415 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1416
1417 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1418 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1419 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1420 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1421 s->st_size = arch_eltdata (abfd)->parsed_size;
1422 }
1423 else
1424 {
1425 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
252b5132 1426
5ea1af0d
GK
1427 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1428 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1429 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1430 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1431 s->st_size = arch_eltdata (abfd)->parsed_size;
1432 }
252b5132
RH
1433
1434 return 0;
1435}
1436
1437/* Normalize a file name for inclusion in an archive. */
1438
1439static const char *
1440normalize_filename (abfd)
1441 bfd *abfd;
1442{
1443 const char *file;
1444 const char *filename;
1445
1446 file = bfd_get_filename (abfd);
1447 filename = strrchr (file, '/');
1448 if (filename != NULL)
1449 filename++;
1450 else
1451 filename = file;
1452 return filename;
1453}
1454
1455/* Write out an XCOFF armap. */
1456
beb1bf64 1457/*ARGSUSED*/
252b5132 1458static boolean
5ea1af0d 1459xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
252b5132 1460 bfd *abfd;
5f771d47 1461 unsigned int elength ATTRIBUTE_UNUSED;
252b5132
RH
1462 struct orl *map;
1463 unsigned int orl_count;
1464 int stridx;
1465{
1466 struct xcoff_ar_hdr hdr;
1467 char *p;
1468 unsigned char buf[4];
1469 bfd *sub;
1470 file_ptr fileoff;
1471 unsigned int i;
1472
1473 memset (&hdr, 0, sizeof hdr);
1474 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1475 sprintf (hdr.nextoff, "%d", 0);
1476 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
1477 sprintf (hdr.date, "%d", 0);
1478 sprintf (hdr.uid, "%d", 0);
1479 sprintf (hdr.gid, "%d", 0);
1480 sprintf (hdr.mode, "%d", 0);
1481 sprintf (hdr.namlen, "%d", 0);
1482
1483 /* We need spaces, not null bytes, in the header. */
1484 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1485 if (*p == '\0')
1486 *p = ' ';
1487
1488 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
1489 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
1490 return false;
5ea1af0d 1491
252b5132
RH
1492 bfd_h_put_32 (abfd, orl_count, buf);
1493 if (bfd_write (buf, 1, 4, abfd) != 4)
1494 return false;
1495
1496 sub = abfd->archive_head;
1497 fileoff = SIZEOF_AR_FILE_HDR;
1498 i = 0;
1499 while (sub != NULL && i < orl_count)
1500 {
1501 size_t namlen;
1502
1503 while (((bfd *) (map[i]).pos) == sub)
1504 {
1505 bfd_h_put_32 (abfd, fileoff, buf);
1506 if (bfd_write (buf, 1, 4, abfd) != 4)
1507 return false;
1508 ++i;
1509 }
1510 namlen = strlen (normalize_filename (sub));
1511 namlen = (namlen + 1) &~ 1;
1512 fileoff += (SIZEOF_AR_HDR
1513 + namlen
1514 + SXCOFFARFMAG
1515 + arelt_size (sub));
1516 fileoff = (fileoff + 1) &~ 1;
1517 sub = sub->next;
1518 }
1519
1520 for (i = 0; i < orl_count; i++)
1521 {
1522 const char *name;
1523 size_t namlen;
1524
1525 name = *map[i].name;
1526 namlen = strlen (name);
1527 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1528 return false;
1529 }
1530
1531 if ((stridx & 1) != 0)
1532 {
1533 char b;
1534
1535 b = '\0';
1536 if (bfd_write (&b, 1, 1, abfd) != 1)
1537 return false;
1538 }
1539
1540 return true;
1541}
1542
1a6df346 1543/* Write a single armap in the big format. */
f4ffd778 1544
252b5132 1545static boolean
1a6df346
GK
1546xcoff_write_one_armap_big (abfd, map, orl_count, orl_ccount, stridx, bits64,
1547 prevoff, nextoff)
252b5132 1548 bfd *abfd;
5ea1af0d
GK
1549 struct orl *map;
1550 unsigned int orl_count;
1a6df346
GK
1551 unsigned int orl_ccount;
1552 unsigned int stridx;
1553 int bits64;
1554 const char *prevoff;
1555 char *nextoff;
252b5132 1556{
5ea1af0d
GK
1557 struct xcoff_ar_hdr_big hdr;
1558 char *p;
1559 unsigned char buf[4];
252b5132 1560 bfd *sub;
5ea1af0d 1561 file_ptr fileoff;
f4ffd778 1562 const bfd_arch_info_type *arch_info = NULL;
1a6df346 1563 bfd *object_bfd;
252b5132 1564 unsigned int i;
252b5132 1565
5ea1af0d
GK
1566 memset (&hdr, 0, sizeof hdr);
1567 /* XXX This call actually should use %lld (at least on 32-bit
1568 machines) since the fields's width is 20 and there numbers with
1569 more than 32 bits can be represented. */
1a6df346 1570 sprintf (hdr.size, "%ld", (long) (4 + orl_ccount * 4 + stridx));
f4ffd778
NC
1571 if (bits64)
1572 {
1573 sprintf (hdr.nextoff, "%d", 0);
1574 }
1575 else
1576 {
1577 /* Do explict cast to long to remove compiler warning. */
1578 sprintf (hdr.nextoff, "%ld", (strtol (prevoff, (char **) NULL, 10)
1579 + (long) (4 + orl_ccount * 4 + stridx)));
1580 }
beb1bf64 1581
1a6df346 1582 memcpy (hdr.prevoff, prevoff, sizeof (hdr.prevoff));
5ea1af0d
GK
1583 sprintf (hdr.date, "%d", 0);
1584 sprintf (hdr.uid, "%d", 0);
1585 sprintf (hdr.gid, "%d", 0);
1586 sprintf (hdr.mode, "%d", 0);
1587 sprintf (hdr.namlen, "%d", 0);
252b5132 1588
5ea1af0d
GK
1589 /* We need spaces, not null bytes, in the header. */
1590 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++)
1591 if (*p == '\0')
1592 *p = ' ';
1593
1a6df346
GK
1594 memcpy (nextoff, hdr.nextoff, sizeof (hdr.nextoff));
1595
5ea1af0d
GK
1596 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG
1597 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
252b5132
RH
1598 return false;
1599
1a6df346 1600 bfd_h_put_32 (abfd, orl_ccount, buf);
5ea1af0d 1601 if (bfd_write (buf, 1, 4, abfd) != 4)
252b5132
RH
1602 return false;
1603
5ea1af0d
GK
1604 sub = abfd->archive_head;
1605 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1606 i = 0;
1607 while (sub != NULL && i < orl_count)
252b5132 1608 {
5ea1af0d
GK
1609 size_t namlen;
1610
1a6df346
GK
1611 if ((bfd_arch_bits_per_address ((bfd *) map[i].pos) == 64) == bits64)
1612 while (((bfd *) (map[i]).pos) == sub)
1613 {
1614 bfd_h_put_32 (abfd, fileoff, buf);
1615 if (bfd_write (buf, 1, 4, abfd) != 4)
1616 return false;
1617 i++;
1618 }
1619 else
1620 while (((bfd *) (map[i]).pos) == sub)
1621 i++;
1622
5ea1af0d
GK
1623 namlen = strlen (normalize_filename (sub));
1624 namlen = (namlen + 1) &~ 1;
1625 fileoff += (SIZEOF_AR_HDR_BIG
1626 + namlen
1627 + SXCOFFARFMAG
1628 + arelt_size (sub));
1629 fileoff = (fileoff + 1) &~ 1;
1630 sub = sub->next;
1631 }
1632
1a6df346 1633 object_bfd = NULL;
5ea1af0d
GK
1634 for (i = 0; i < orl_count; i++)
1635 {
1636 const char *name;
1637 size_t namlen;
1a6df346
GK
1638 bfd *ob = (bfd *)map[i].pos;
1639
1640 if (ob != object_bfd)
1641 arch_info = bfd_get_arch_info (ob);
beb1bf64 1642 if ((arch_info->bits_per_address == 64) != bits64)
1a6df346 1643 continue;
5ea1af0d
GK
1644
1645 name = *map[i].name;
1646 namlen = strlen (name);
1647 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1648 return false;
1649 }
1650
1651 if ((stridx & 1) != 0)
1652 {
1653 char b;
1654
1655 b = '\0';
1656 if (bfd_write (&b, 1, 1, abfd) != 1)
1657 return false;
1658 }
1659
1660 return true;
1661}
1662
1a6df346
GK
1663static boolean
1664xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1665 bfd *abfd;
1666 unsigned int elength ATTRIBUTE_UNUSED;
1667 struct orl *map;
1668 unsigned int orl_count;
1669 int stridx;
1670{
1671 unsigned int i;
1672 unsigned int orl_count_32, orl_count_64;
1673 unsigned int stridx_32, stridx_64;
f4ffd778 1674 const bfd_arch_info_type *arch_info = NULL;
1a6df346
GK
1675 bfd *object_bfd;
1676
1677 /* First, we look through the symbols and work out which are
1678 from 32-bit objects and which from 64-bit ones. */
1679 orl_count_32 = 0;
1680 orl_count_64 = 0;
1681 stridx_32 = 0;
1682 stridx_64 = 0;
1683 object_bfd = NULL;
1684 for (i = 0; i < orl_count; i++)
1685 {
1686 bfd *ob = (bfd *)map[i].pos;
1687 unsigned int len;
1688 if (ob != object_bfd)
1689 arch_info = bfd_get_arch_info (ob);
1690 len = strlen (*map[i].name) + 1;
beb1bf64 1691 if (arch_info->bits_per_address == 64)
1a6df346
GK
1692 {
1693 orl_count_64++;
1694 stridx_64 += len;
1695 }
1696 else
1697 {
1698 orl_count_32++;
1699 stridx_32 += len;
1700 }
1701 object_bfd = ob;
1702 }
beb1bf64 1703 /* A quick sanity check... */
1a6df346 1704 BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count);
f4ffd778 1705 /* Explicit cast to int for compiler. */
beb1bf64 1706 BFD_ASSERT ((int)(stridx_64 + stridx_32) == stridx);
1a6df346
GK
1707
1708 /* Now write out each map. */
1709 if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32,
beb1bf64 1710 stridx_32, false,
1a6df346
GK
1711 xcoff_ardata_big (abfd)->memoff,
1712 xcoff_ardata_big (abfd)->symoff))
1713 return false;
1714 if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64,
1715 stridx_64, true,
1716 xcoff_ardata_big (abfd)->symoff,
1717 xcoff_ardata_big (abfd)->symoff64))
1718 return false;
beb1bf64 1719
1a6df346
GK
1720 return true;
1721}
1722
7f6d05e8
CP
1723boolean
1724_bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
5ea1af0d
GK
1725 bfd *abfd;
1726 unsigned int elength ATTRIBUTE_UNUSED;
1727 struct orl *map;
1728 unsigned int orl_count;
1729 int stridx;
1730{
1731 if (! xcoff_big_format_p (abfd))
1732 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
1733 else
1734 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
1735}
1736
1737/* Write out an XCOFF archive. We always write an entire archive,
1738 rather than fussing with the freelist and so forth. */
1739
1740static boolean
1741xcoff_write_archive_contents_old (abfd)
1742 bfd *abfd;
1743{
1744 struct xcoff_ar_file_hdr fhdr;
1745 size_t count;
1746 size_t total_namlen;
1747 file_ptr *offsets;
1748 boolean makemap;
1749 boolean hasobjects;
1750 file_ptr prevoff, nextoff;
1751 bfd *sub;
1752 unsigned int i;
1753 struct xcoff_ar_hdr ahdr;
1754 bfd_size_type size;
1755 char *p;
1756 char decbuf[13];
1757
1758 memset (&fhdr, 0, sizeof fhdr);
1759 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
1760 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
1761 sprintf (fhdr.freeoff, "%d", 0);
1762
1763 count = 0;
1764 total_namlen = 0;
1765 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1766 {
1767 ++count;
1768 total_namlen += strlen (normalize_filename (sub)) + 1;
1769 }
1770 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
1771 if (offsets == NULL)
1772 return false;
1773
1774 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
1775 return false;
1776
1777 makemap = bfd_has_map (abfd);
1778 hasobjects = false;
1779 prevoff = 0;
1780 nextoff = SIZEOF_AR_FILE_HDR;
1781 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
1782 {
1783 const char *name;
252b5132
RH
1784 size_t namlen;
1785 struct xcoff_ar_hdr *ahdrp;
1786 bfd_size_type remaining;
1787
1788 if (makemap && ! hasobjects)
1789 {
1790 if (bfd_check_format (sub, bfd_object))
1791 hasobjects = true;
1792 }
1793
1794 name = normalize_filename (sub);
1795 namlen = strlen (name);
1796
1797 if (sub->arelt_data != NULL)
1798 ahdrp = arch_xhdr (sub);
1799 else
1800 ahdrp = NULL;
1801
1802 if (ahdrp == NULL)
1803 {
1804 struct stat s;
1805
1806 memset (&ahdr, 0, sizeof ahdr);
1807 ahdrp = &ahdr;
1808 if (stat (bfd_get_filename (sub), &s) != 0)
1809 {
1810 bfd_set_error (bfd_error_system_call);
1811 return false;
1812 }
1813
1814 sprintf (ahdrp->size, "%ld", (long) s.st_size);
1815 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
1816 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
1817 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
1818 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
1819
1820 if (sub->arelt_data == NULL)
1821 {
1822 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
1823 if (sub->arelt_data == NULL)
1824 return false;
1825 }
1826
1827 arch_eltdata (sub)->parsed_size = s.st_size;
1828 }
1829
1830 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
1831 sprintf (ahdrp->namlen, "%ld", (long) namlen);
1832
1833 /* If the length of the name is odd, we write out the null byte
1834 after the name as well. */
1835 namlen = (namlen + 1) &~ 1;
1836
1837 remaining = arelt_size (sub);
1838 size = (SIZEOF_AR_HDR
1839 + namlen
1840 + SXCOFFARFMAG
1841 + remaining);
1842
1843 BFD_ASSERT (nextoff == bfd_tell (abfd));
1844
1845 offsets[i] = nextoff;
1846
1847 prevoff = nextoff;
1848 nextoff += size + (size & 1);
1849
1850 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
1851
1852 /* We need spaces, not null bytes, in the header. */
1853 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
1854 if (*p == '\0')
1855 *p = ' ';
1856
1857 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1858 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
1859 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1860 != SXCOFFARFMAG))
1861 return false;
1862
1863 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
1864 return false;
1865 while (remaining != 0)
1866 {
1867 bfd_size_type amt;
1868 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1869
1870 amt = sizeof buffer;
1871 if (amt > remaining)
1872 amt = remaining;
1873 if (bfd_read (buffer, 1, amt, sub) != amt
1874 || bfd_write (buffer, 1, amt, abfd) != amt)
1875 return false;
1876 remaining -= amt;
1877 }
1878
1879 if ((size & 1) != 0)
1880 {
1881 bfd_byte b;
1882
1883 b = '\0';
1884 if (bfd_write (&b, 1, 1, abfd) != 1)
1885 return false;
1886 }
1887 }
1888
1889 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
1890
1891 /* Write out the member table. */
1892
1893 BFD_ASSERT (nextoff == bfd_tell (abfd));
1894 sprintf (fhdr.memoff, "%ld", (long) nextoff);
1895
1896 memset (&ahdr, 0, sizeof ahdr);
1897 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
1898 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
1899 sprintf (ahdr.date, "%d", 0);
1900 sprintf (ahdr.uid, "%d", 0);
1901 sprintf (ahdr.gid, "%d", 0);
1902 sprintf (ahdr.mode, "%d", 0);
1903 sprintf (ahdr.namlen, "%d", 0);
1904
1905 size = (SIZEOF_AR_HDR
1906 + 12
1907 + count * 12
1908 + total_namlen
1909 + SXCOFFARFMAG);
1910
1911 prevoff = nextoff;
1912 nextoff += size + (size & 1);
1913
1914 if (makemap && hasobjects)
1915 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
1916 else
1917 sprintf (ahdr.nextoff, "%d", 0);
1918
1919 /* We need spaces, not null bytes, in the header. */
1920 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
1921 if (*p == '\0')
1922 *p = ' ';
1923
1924 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1925 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1926 != SXCOFFARFMAG))
1927 return false;
1928
1929 sprintf (decbuf, "%-12ld", (long) count);
1930 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1931 return false;
1932 for (i = 0; i < count; i++)
1933 {
1934 sprintf (decbuf, "%-12ld", (long) offsets[i]);
1935 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1936 return false;
1937 }
1938 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1939 {
1940 const char *name;
1941 size_t namlen;
1942
1943 name = normalize_filename (sub);
1944 namlen = strlen (name);
1945 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
1946 return false;
1947 }
1948 if ((size & 1) != 0)
1949 {
1950 bfd_byte b;
1951
1952 b = '\0';
1953 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
1954 return false;
1955 }
1956
1957 /* Write out the armap, if appropriate. */
1958
1959 if (! makemap || ! hasobjects)
1960 sprintf (fhdr.symoff, "%d", 0);
1961 else
1962 {
1963 BFD_ASSERT (nextoff == bfd_tell (abfd));
1964 sprintf (fhdr.symoff, "%ld", (long) nextoff);
1965 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
1966 if (! _bfd_compute_and_write_armap (abfd, 0))
1967 return false;
1968 }
1969
1970 /* Write out the archive file header. */
1971
1972 /* We need spaces, not null bytes, in the header. */
1973 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
1974 if (*p == '\0')
1975 *p = ' ';
1976
1977 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1978 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
1979 SIZEOF_AR_FILE_HDR))
1980 return false;
1981
1982 return true;
1983}
5ea1af0d
GK
1984
1985static boolean
1986xcoff_write_archive_contents_big (abfd)
1987 bfd *abfd;
1988{
1989 struct xcoff_ar_file_hdr_big fhdr;
1990 size_t count;
1991 size_t total_namlen;
1992 file_ptr *offsets;
1993 boolean makemap;
1994 boolean hasobjects;
1995 file_ptr prevoff, nextoff;
1996 bfd *sub;
1997 unsigned int i;
1998 struct xcoff_ar_hdr_big ahdr;
1999 bfd_size_type size;
2000 char *p;
2001 char decbuf[13];
2002
2003 memset (&fhdr, 0, sizeof fhdr);
2004 strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2005 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG);
2006 sprintf (fhdr.freeoff, "%d", 0);
2007
2008 count = 0;
2009 total_namlen = 0;
2010 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2011 {
2012 ++count;
2013 total_namlen += strlen (normalize_filename (sub)) + 1;
2014 }
2015 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2016 if (offsets == NULL)
2017 return false;
2018
2019 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2020 return false;
2021
2022 makemap = bfd_has_map (abfd);
2023 hasobjects = false;
2024 prevoff = 0;
2025 nextoff = SIZEOF_AR_FILE_HDR_BIG;
2026 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
2027 {
2028 const char *name;
2029 size_t namlen;
2030 struct xcoff_ar_hdr_big *ahdrp;
2031 bfd_size_type remaining;
2032
2033 if (makemap && ! hasobjects)
2034 {
2035 if (bfd_check_format (sub, bfd_object))
2036 hasobjects = true;
2037 }
2038
2039 name = normalize_filename (sub);
2040 namlen = strlen (name);
2041
2042 if (sub->arelt_data != NULL)
2043 ahdrp = arch_xhdr_big (sub);
2044 else
2045 ahdrp = NULL;
2046
2047 if (ahdrp == NULL)
2048 {
2049 struct stat s;
2050
2051 memset (&ahdr, 0, sizeof ahdr);
2052 ahdrp = &ahdr;
2053 /* XXX This should actually be a call to stat64 (at least on
2054 32-bit machines). */
2055 if (stat (bfd_get_filename (sub), &s) != 0)
2056 {
2057 bfd_set_error (bfd_error_system_call);
2058 return false;
2059 }
2060
2061 /* XXX This call actually should use %lld (at least on 32-bit
2062 machines) since the fields's width is 20 and there numbers with
2063 more than 32 bits can be represented. */
2064 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2065 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2066 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2067 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2068 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2069
2070 if (sub->arelt_data == NULL)
2071 {
2072 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
2073 if (sub->arelt_data == NULL)
2074 return false;
2075 }
2076
2077 arch_eltdata (sub)->parsed_size = s.st_size;
2078 }
2079
2080 /* XXX These calls actually should use %lld (at least on 32-bit
2081 machines) since the fields's width is 20 and there numbers with
2082 more than 32 bits can be represented. */
2083 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2084 sprintf (ahdrp->namlen, "%ld", (long) namlen);
2085
2086 /* If the length of the name is odd, we write out the null byte
2087 after the name as well. */
2088 namlen = (namlen + 1) &~ 1;
2089
2090 remaining = arelt_size (sub);
2091 size = (SIZEOF_AR_HDR_BIG
2092 + namlen
2093 + SXCOFFARFMAG
2094 + remaining);
2095
2096 BFD_ASSERT (nextoff == bfd_tell (abfd));
2097
2098 offsets[i] = nextoff;
2099
2100 prevoff = nextoff;
2101 nextoff += size + (size & 1);
2102
2103 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
2104
2105 /* We need spaces, not null bytes, in the header. */
2106 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++)
2107 if (*p == '\0')
2108 *p = ' ';
2109
2110 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd)
2111 != SIZEOF_AR_HDR_BIG
2112 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
2113 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
2114 != SXCOFFARFMAG))
2115 return false;
2116
2117 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
2118 return false;
2119 while (remaining != 0)
2120 {
2121 bfd_size_type amt;
2122 bfd_byte buffer[DEFAULT_BUFFERSIZE];
2123
2124 amt = sizeof buffer;
2125 if (amt > remaining)
2126 amt = remaining;
2127 if (bfd_read (buffer, 1, amt, sub) != amt
2128 || bfd_write (buffer, 1, amt, abfd) != amt)
2129 return false;
2130 remaining -= amt;
2131 }
2132
2133 if ((size & 1) != 0)
2134 {
2135 bfd_byte b;
2136
2137 b = '\0';
2138 if (bfd_write (&b, 1, 1, abfd) != 1)
2139 return false;
2140 }
2141 }
2142
2143 /* XXX This call actually should use %lld (at least on 32-bit
2144 machines) since the fields's width is 20 and there numbers with
2145 more than 32 bits can be represented. */
2146 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2147
2148 /* Write out the member table. */
2149
2150 BFD_ASSERT (nextoff == bfd_tell (abfd));
2151 /* XXX This call actually should use %lld (at least on 32-bit
2152 machines) since the fields's width is 20 and there numbers with
2153 more than 32 bits can be represented. */
2154 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2155
2156 memset (&ahdr, 0, sizeof ahdr);
2157 /* XXX The next two calls actually should use %lld (at least on 32-bit
2158 machines) since the fields's width is 20 and there numbers with
2159 more than 32 bits can be represented. */
2160 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
2161 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2162 sprintf (ahdr.date, "%d", 0);
2163 sprintf (ahdr.uid, "%d", 0);
2164 sprintf (ahdr.gid, "%d", 0);
2165 sprintf (ahdr.mode, "%d", 0);
2166 sprintf (ahdr.namlen, "%d", 0);
2167
2168 size = (SIZEOF_AR_HDR_BIG
2169 + 12
2170 + count * 12
2171 + total_namlen
2172 + SXCOFFARFMAG);
2173
2174 prevoff = nextoff;
2175 nextoff += size + (size & 1);
2176
2177 if (makemap && hasobjects)
2178 /* XXX This call actually should use %lld (at least on 32-bit
2179 machines) since the fields's width is 20 and there numbers with
2180 more than 32 bits can be represented. */
2181 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2182 else
2183 sprintf (ahdr.nextoff, "%d", 0);
2184
2185 /* We need spaces, not null bytes, in the header. */
2186 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++)
2187 if (*p == '\0')
2188 *p = ' ';
2189
2190 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2191 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
2192 != SXCOFFARFMAG))
2193 return false;
2194
2195 sprintf (decbuf, "%-12ld", (long) count);
2196 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
2197 return false;
2198 for (i = 0; i < count; i++)
2199 {
2200 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2201 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
2202 return false;
2203 }
2204 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2205 {
2206 const char *name;
2207 size_t namlen;
2208
2209 name = normalize_filename (sub);
2210 namlen = strlen (name);
2211 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
2212 return false;
2213 }
2214 if ((size & 1) != 0)
2215 {
2216 bfd_byte b;
2217
2218 b = '\0';
2219 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
2220 return false;
2221 }
2222
2223 /* Write out the armap, if appropriate. */
2224
2225 if (! makemap || ! hasobjects)
2226 sprintf (fhdr.symoff, "%d", 0);
2227 else
2228 {
2229 BFD_ASSERT (nextoff == bfd_tell (abfd));
2230 /* XXX This call actually should use %lld (at least on 32-bit
2231 machines) since the fields's width is 20 and there numbers with
2232 more than 32 bits can be represented. */
5ea1af0d
GK
2233 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2234 if (! _bfd_compute_and_write_armap (abfd, 0))
2235 return false;
2236 }
2237
2238 /* Write out the archive file header. */
2239
2240 /* We need spaces, not null bytes, in the header. */
2241 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++)
2242 if (*p == '\0')
2243 *p = ' ';
2244
2245 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2246 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) !=
2247 SIZEOF_AR_FILE_HDR_BIG))
2248 return false;
2249
2250 return true;
2251}
2252
7f6d05e8
CP
2253boolean
2254_bfd_xcoff_write_archive_contents (abfd)
5ea1af0d
GK
2255 bfd *abfd;
2256{
2257 if (! xcoff_big_format_p (abfd))
2258 return xcoff_write_archive_contents_old (abfd);
2259 else
2260 return xcoff_write_archive_contents_big (abfd);
2261}
252b5132
RH
2262\f
2263/* We can't use the usual coff_sizeof_headers routine, because AIX
2264 always uses an a.out header. */
2265
7f6d05e8 2266int
252b5132
RH
2267_bfd_xcoff_sizeof_headers (abfd, reloc)
2268 bfd *abfd;
5f771d47 2269 boolean reloc ATTRIBUTE_UNUSED;
252b5132
RH
2270{
2271 int size;
2272
2273 size = FILHSZ;
2274 if (xcoff_data (abfd)->full_aouthdr)
2275 size += AOUTSZ;
2276 else
2277 size += SMALL_AOUTSZ;
2278 size += abfd->section_count * SCNHSZ;
2279 return size;
2280}
beb1bf64
TR
2281\f
2282/* Routines to swap information in the XCOFF .loader section. If we
2283 ever need to write an XCOFF loader, this stuff will need to be
2284 moved to another file shared by the linker (which XCOFF calls the
2285 ``binder'') and the loader. */
2286
2287/* Swap in the ldhdr structure. */
2288
2289static void
814fa6ab 2290xcoff_swap_ldhdr_in (abfd, s, dst)
beb1bf64 2291 bfd *abfd;
814fa6ab 2292 const PTR s;
beb1bf64
TR
2293 struct internal_ldhdr *dst;
2294{
814fa6ab
AM
2295 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2296
beb1bf64
TR
2297 dst->l_version = bfd_get_32 (abfd, src->l_version);
2298 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2299 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2300 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2301 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2302 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2303 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2304 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2305}
2306
2307/* Swap out the ldhdr structure. */
2308
2309static void
814fa6ab 2310xcoff_swap_ldhdr_out (abfd, src, d)
beb1bf64
TR
2311 bfd *abfd;
2312 const struct internal_ldhdr *src;
814fa6ab 2313 PTR d;
beb1bf64 2314{
814fa6ab
AM
2315 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2316
beb1bf64
TR
2317 bfd_put_32 (abfd, src->l_version, dst->l_version);
2318 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2319 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2320 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2321 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2322 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2323 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2324 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2325}
2326
2327/* Swap in the ldsym structure. */
2328
2329static void
814fa6ab 2330xcoff_swap_ldsym_in (abfd, s, dst)
beb1bf64 2331 bfd *abfd;
814fa6ab 2332 const PTR s;
beb1bf64
TR
2333 struct internal_ldsym *dst;
2334{
814fa6ab
AM
2335 const struct external_ldsym *src = (const struct external_ldsym *) s;
2336
beb1bf64
TR
2337 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2338 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2339 } else {
2340 dst->_l._l_l._l_zeroes = 0;
2341 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2342 }
2343 dst->l_value = bfd_get_32 (abfd, src->l_value);
2344 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2345 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2346 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2347 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2348 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2349}
2350
2351/* Swap out the ldsym structure. */
2352
2353static void
814fa6ab 2354xcoff_swap_ldsym_out (abfd, src, d)
beb1bf64
TR
2355 bfd *abfd;
2356 const struct internal_ldsym *src;
814fa6ab 2357 PTR d;
beb1bf64 2358{
814fa6ab 2359 struct external_ldsym *dst = (struct external_ldsym *) d;
beb1bf64
TR
2360
2361 if (src->_l._l_l._l_zeroes != 0)
2362 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2363 else
2364 {
2365 bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes);
2366 bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset);
2367 }
2368 bfd_put_32 (abfd, src->l_value, dst->l_value);
2369 bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
2370 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2371 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2372 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2373 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2374}
2375
2376/* Swap in the ldrel structure. */
2377
2378static void
814fa6ab 2379xcoff_swap_ldrel_in (abfd, s, dst)
beb1bf64 2380 bfd *abfd;
814fa6ab 2381 const PTR s;
beb1bf64
TR
2382 struct internal_ldrel *dst;
2383{
814fa6ab
AM
2384 const struct external_ldrel *src = (const struct external_ldrel *) s;
2385
beb1bf64
TR
2386 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2387 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2388 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2389 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2390}
2391
2392/* Swap out the ldrel structure. */
2393
2394static void
814fa6ab 2395xcoff_swap_ldrel_out (abfd, src, d)
beb1bf64
TR
2396 bfd *abfd;
2397 const struct internal_ldrel *src;
814fa6ab 2398 PTR d;
beb1bf64 2399{
814fa6ab
AM
2400 struct external_ldrel *dst = (struct external_ldrel *) d;
2401
beb1bf64
TR
2402 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2403 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2404 bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
2405 bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
2406}
2407\f
2408
2409
2410/* This is the relocation function for the RS/6000/POWER/PowerPC.
2411 This is currently the only processor which uses XCOFF; I hope that
2412 will never change. */
2413
a7b97311 2414static boolean
beb1bf64
TR
2415xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
2416 input_section, contents, relocs, syms,
2417 sections)
2418 bfd *output_bfd;
2419 struct bfd_link_info *info;
2420 bfd *input_bfd;
2421 asection *input_section;
2422 bfd_byte *contents;
2423 struct internal_reloc *relocs;
2424 struct internal_syment *syms;
2425 asection **sections;
2426{
2427 struct internal_reloc *rel;
2428 struct internal_reloc *relend;
2429
2430 rel = relocs;
2431 relend = rel + input_section->reloc_count;
2432
2433 for (; rel < relend; rel++)
2434 {
2435 long symndx;
2436 struct xcoff_link_hash_entry *h;
2437 struct internal_syment *sym;
2438 bfd_vma addend;
2439 bfd_vma val;
2440 struct reloc_howto_struct howto;
2441 bfd_reloc_status_type rstat;
2442
2443 /* Relocation type R_REF is a special relocation type which is
2444 merely used to prevent garbage collection from occurring for
2445 the csect including the symbol which it references. */
2446 if (rel->r_type == R_REF)
2447 continue;
2448
2449 symndx = rel->r_symndx;
2450
2451 if (symndx == -1)
2452 {
2453 h = NULL;
2454 sym = NULL;
2455 addend = 0;
2456 }
2457 else
2458 {
2459 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
2460 sym = syms + symndx;
2461 addend = - sym->n_value;
2462
2463 }
2464
2465 /* We build the howto information on the fly. */
2466
2467 howto.type = rel->r_type;
2468 howto.rightshift = 0;
2469 howto.size = 2;
2470 howto.bitsize = (rel->r_size & 0x1f) + 1;
2471 howto.pc_relative = false;
2472 howto.bitpos = 0;
2473 if ((rel->r_size & 0x80) != 0)
2474 howto.complain_on_overflow = complain_overflow_signed;
2475 else
2476 howto.complain_on_overflow = complain_overflow_bitfield;
2477 howto.special_function = NULL;
2478 howto.name = "internal";
2479 howto.partial_inplace = true;
2480 if (howto.bitsize == 32)
2481 howto.src_mask = howto.dst_mask = 0xffffffff;
2482 else
2483 {
2484 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
2485 if (howto.bitsize == 16)
2486 howto.size = 1;
2487 }
2488 howto.pcrel_offset = false;
2489
2490 val = 0;
2491
2492 if (h == NULL)
2493 {
2494 asection *sec;
2495
2496 if (symndx == -1)
2497 {
2498 sec = bfd_abs_section_ptr;
2499 val = 0;
2500 }
2501 else
2502 {
2503 sec = sections[symndx];
2504 /* Hack to make sure we use the right TOC anchor value
2505 if this reloc is against the TOC anchor. */
2506
2507 if (sec->name[3] == '0'
f4ffd778
NC
2508 && strcmp (sec->name, ".tc0") == 0)
2509 {
2510 val = xcoff_data (output_bfd)->toc;
2511 }
2512 else
2513 {
2514 val = (sec->output_section->vma
2515 + sec->output_offset
2516 + sym->n_value
2517 - sec->vma);
2518 }
beb1bf64
TR
2519 }
2520 }
2521 else
2522 {
2523 if (h->root.type == bfd_link_hash_defined
2524 || h->root.type == bfd_link_hash_defweak)
2525 {
2526 asection *sec;
2527
2528 sec = h->root.u.def.section;
2529 val = (h->root.u.def.value
2530 + sec->output_section->vma
2531 + sec->output_offset);
2532 }
2533 else if (h->root.type == bfd_link_hash_common)
2534 {
2535 asection *sec;
2536
2537 sec = h->root.u.c.p->section;
2538 val = (sec->output_section->vma
2539 + sec->output_offset);
2540 }
2541 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
2542 || (h->flags & XCOFF_IMPORT) != 0)
2543 {
2544 /* Every symbol in a shared object is defined somewhere. */
2545 val = 0;
2546 }
2547 else if (! info->relocateable)
2548 {
2549 if (! ((*info->callbacks->undefined_symbol)
2550 (info, h->root.root.string, input_bfd, input_section,
2551 rel->r_vaddr - input_section->vma, true)))
2552 return false;
2553
2554 /* Don't try to process the reloc. It can't help, and
2555 it may generate another error. */
2556 continue;
2557 }
2558 }
2559
2560 /* I took the relocation type definitions from two documents:
2561 the PowerPC AIX Version 4 Application Binary Interface, First
2562 Edition (April 1992), and the PowerOpen ABI, Big-Endian
2563 32-Bit Hardware Implementation (June 30, 1994). Differences
2564 between the documents are noted below. */
2565
2566 switch (rel->r_type)
2567 {
2568 case R_RTB:
2569 case R_RRTBI:
2570 case R_RRTBA:
2571 /* These relocs are defined by the PowerPC ABI to be
2572 relative branches which use half of the difference
2573 between the symbol and the program counter. I can't
2574 quite figure out when this is useful. These relocs are
2575 not defined by the PowerOpen ABI. */
2576 default:
2577 (*_bfd_error_handler)
2578 (_("%s: unsupported relocation type 0x%02x"),
2579 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2580 bfd_set_error (bfd_error_bad_value);
2581 return false;
2582 case R_POS:
2583 /* Simple positive relocation. */
2584 break;
2585 case R_NEG:
2586 /* Simple negative relocation. */
2587 val = - val;
2588 break;
2589 case R_REL:
2590 /* Simple PC relative relocation. */
2591 howto.pc_relative = true;
2592 break;
2593 case R_TOC:
2594 /* TOC relative relocation. The value in the instruction in
2595 the input file is the offset from the input file TOC to
2596 the desired location. We want the offset from the final
2597 TOC to the desired location. We have:
2598 isym = iTOC + in
2599 iinsn = in + o
2600 osym = oTOC + on
2601 oinsn = on + o
2602 so we must change insn by on - in.
2603 */
2604 case R_GL:
2605 /* Global linkage relocation. The value of this relocation
2606 is the address of the entry in the TOC section. */
2607 case R_TCL:
2608 /* Local object TOC address. I can't figure out the
2609 difference between this and case R_GL. */
2610 case R_TRL:
2611 /* TOC relative relocation. A TOC relative load instruction
2612 which may be changed to a load address instruction.
2613 FIXME: We don't currently implement this optimization. */
2614 case R_TRLA:
2615 /* TOC relative relocation. This is a TOC relative load
2616 address instruction which may be changed to a load
2617 instruction. FIXME: I don't know if this is the correct
2618 implementation. */
2619 if (h != NULL && h->smclas != XMC_TD)
2620 {
2621 if (h->toc_section == NULL)
2622 {
2623 (*_bfd_error_handler)
2624 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2625 bfd_get_filename (input_bfd), rel->r_vaddr,
2626 h->root.root.string);
2627 bfd_set_error (bfd_error_bad_value);
2628 return false;
2629 }
2630
2631 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2632 val = (h->toc_section->output_section->vma
2633 + h->toc_section->output_offset);
2634 }
2635
2636 val = ((val - xcoff_data (output_bfd)->toc)
2637 - (sym->n_value - xcoff_data (input_bfd)->toc));
2638 addend = 0;
2639 break;
2640 case R_BA:
2641 /* Absolute branch. We don't want to mess with the lower
2642 two bits of the instruction. */
2643 case R_CAI:
2644 /* The PowerPC ABI defines this as an absolute call which
2645 may be modified to become a relative call. The PowerOpen
2646 ABI does not define this relocation type. */
2647 case R_RBA:
2648 /* Absolute branch which may be modified to become a
2649 relative branch. */
2650 case R_RBAC:
2651 /* The PowerPC ABI defines this as an absolute branch to a
2652 fixed address which may be modified to an absolute branch
2653 to a symbol. The PowerOpen ABI does not define this
2654 relocation type. */
2655 case R_RBRC:
2656 /* The PowerPC ABI defines this as an absolute branch to a
2657 fixed address which may be modified to a relative branch.
2658 The PowerOpen ABI does not define this relocation type. */
2659 howto.src_mask &= ~3;
2660 howto.dst_mask = howto.src_mask;
2661 break;
2662 case R_BR:
2663 /* Relative branch. We don't want to mess with the lower
2664 two bits of the instruction. */
2665 case R_CREL:
2666 /* The PowerPC ABI defines this as a relative call which may
2667 be modified to become an absolute call. The PowerOpen
2668 ABI does not define this relocation type. */
2669 case R_RBR:
2670 /* A relative branch which may be modified to become an
2671 absolute branch. FIXME: We don't implement this,
2672 although we should for symbols of storage mapping class
2673 XMC_XO. */
2674 howto.pc_relative = true;
2675 howto.src_mask &= ~3;
2676 howto.dst_mask = howto.src_mask;
2677 break;
2678 case R_RL:
2679 /* The PowerPC AIX ABI describes this as a load which may be
2680 changed to a load address. The PowerOpen ABI says this
2681 is the same as case R_POS. */
2682 break;
2683 case R_RLA:
2684 /* The PowerPC AIX ABI describes this as a load address
2685 which may be changed to a load. The PowerOpen ABI says
2686 this is the same as R_POS. */
2687 break;
2688 }
2689
2690 /* If we see an R_BR or R_RBR reloc which is jumping to global
2691 linkage code, and it is followed by an appropriate cror nop
2692 instruction, we replace the cror with lwz r2,20(r1). This
2693 restores the TOC after the glink code. Contrariwise, if the
2694 call is followed by a lwz r2,20(r1), but the call is not
2695 going to global linkage code, we can replace the load with a
2696 cror. */
2697 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
2698 && h != NULL
2699 && h->root.type == bfd_link_hash_defined
2700 && (rel->r_vaddr - input_section->vma + 8
2701 <= input_section->_cooked_size))
2702 {
2703 bfd_byte *pnext;
2704 unsigned long next;
2705
2706 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2707 next = bfd_get_32 (input_bfd, pnext);
2708
2709 /* The _ptrgl function is magic. It is used by the AIX
2710 compiler to call a function through a pointer. */
2711 if (h->smclas == XMC_GL
2712 || strcmp (h->root.root.string, "._ptrgl") == 0)
2713 {
2714 if (next == 0x4def7b82 /* cror 15,15,15 */
2715 || next == 0x4ffffb82 /* cror 31,31,31 */
2716 || next == 0x60000000) /* ori r0,r0,0 */
2717 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2718 }
2719 else
2720 {
2721 if (next == 0x80410014) /* lwz r1,20(r1) */
2722 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2723 }
2724 }
2725
2726 /* A PC relative reloc includes the section address. */
2727 if (howto.pc_relative)
2728 addend += input_section->vma;
2729
2730 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
2731 contents,
2732 rel->r_vaddr - input_section->vma,
2733 val, addend);
2734
2735 switch (rstat)
2736 {
2737 default:
2738 abort ();
2739 case bfd_reloc_ok:
2740 break;
2741 case bfd_reloc_overflow:
2742 {
2743 const char *name;
2744 char buf[SYMNMLEN + 1];
2745 char howto_name[10];
2746
2747 if (symndx == -1)
2748 name = "*ABS*";
2749 else if (h != NULL)
2750 name = h->root.root.string;
2751 else
2752 {
beb1bf64
TR
2753 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
2754
2755 if (name == NULL)
2756 return false;
2757 }
2758 sprintf (howto_name, "0x%02x", rel->r_type);
2759
2760 if (! ((*info->callbacks->reloc_overflow)
2761 (info, name, howto_name, (bfd_vma) 0, input_bfd,
2762 input_section, rel->r_vaddr - input_section->vma)))
2763 return false;
2764 }
2765 }
2766 }
2767
2768 return true;
2769}
2770
2771static boolean
2772_bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
2773 bfd *abfd ATTRIBUTE_UNUSED;
2774 struct xcoff_loader_info *ldinfo;
2775 struct internal_ldsym *ldsym;
2776 const char *name;
2777{
2778 size_t len;
2779 len = strlen (name);
2780
2781 if (len <= SYMNMLEN)
2782 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
2783 else
2784 {
2785 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
2786 {
2787 size_t newalc;
2788 bfd_byte *newstrings;
2789
2790 newalc = ldinfo->string_alc * 2;
2791 if (newalc == 0)
2792 newalc = 32;
2793 while (ldinfo->string_size + len + 3 > newalc)
2794 newalc *= 2;
2795
2796 newstrings = ((bfd_byte *)
2797 bfd_realloc ((PTR) ldinfo->strings, newalc));
2798 if (newstrings == NULL)
2799 {
2800 ldinfo->failed = true;
2801 return false;
2802 }
2803 ldinfo->string_alc = newalc;
2804 ldinfo->strings = newstrings;
2805 }
2806
2807 bfd_put_16 (ldinfo->output_bfd, len + 1,
2808 ldinfo->strings + ldinfo->string_size);
2809 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
2810 ldsym->_l._l_l._l_zeroes = 0;
2811 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
2812 ldinfo->string_size += len + 3;
2813 }
2814
2815 return true;
2816}
2817
2818static boolean
2819_bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
2820 struct internal_syment *sym,
f4ffd778
NC
2821 const char *name)
2822{
2823 if (strlen (name) <= SYMNMLEN)
2824 {
2825 strncpy (sym->_n._n_name, name, SYMNMLEN);
2826 }
2827 else
2828 {
2829 boolean hash;
2830 bfd_size_type indx;
2831
2832 hash = true;
2833 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
2834 hash = false;
2835 indx = _bfd_stringtab_add (strtab, name, hash, false);
2836 if (indx == (bfd_size_type) -1)
2837 return false;
2838 sym->_n._n_n._n_zeroes = 0;
2839 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
2840 }
beb1bf64
TR
2841 return true;
2842}
2843
2844static asection *
2845xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
2846 bfd *abfd;
2847 union internal_auxent *aux;
814fa6ab 2848 const char *symbol_name;
beb1bf64 2849{
beb1bf64
TR
2850 asection *return_value = NULL;
2851
f4ffd778
NC
2852 /* .sv64 = x_smclas == 17
2853 This is an invalid csect for 32 bit apps. */
2854 static const char *names[19] =
2855 {
beb1bf64
TR
2856 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2857 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
2858 ".td", NULL, ".sv3264"
2859 };
2860
2861 if ((19 >= aux->x_csect.x_smclas) &&
f4ffd778
NC
2862 (NULL != names[aux->x_csect.x_smclas]))
2863 {
2864 return_value = bfd_make_section_anyway
2865 (abfd, names[aux->x_csect.x_smclas]);
2866 }
2867 else
2868 {
2869 (*_bfd_error_handler)
2870 (_("%s: symbol `%s' has unrecognized smclas %d"),
2871 bfd_get_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2872 bfd_set_error (bfd_error_bad_value);
2873 }
beb1bf64
TR
2874
2875 return return_value;
2876}
2877
a7b97311 2878static boolean
beb1bf64
TR
2879xcoff_is_lineno_count_overflow (abfd, value)
2880 bfd *abfd ATTRIBUTE_UNUSED;
2881 bfd_vma value;
2882{
f4ffd778 2883 if (0xffff <= value)
beb1bf64 2884 return true;
f4ffd778 2885
beb1bf64
TR
2886 return false;
2887}
2888
a7b97311 2889static boolean
beb1bf64
TR
2890xcoff_is_reloc_count_overflow (abfd, value)
2891 bfd *abfd ATTRIBUTE_UNUSED;
2892 bfd_vma value;
2893{
f4ffd778 2894 if (0xffff <= value)
beb1bf64 2895 return true;
f4ffd778 2896
beb1bf64
TR
2897 return false;
2898}
2899
a7b97311 2900static bfd_vma
beb1bf64
TR
2901xcoff_loader_symbol_offset (abfd, ldhdr)
2902 bfd *abfd;
f4ffd778 2903 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
beb1bf64
TR
2904{
2905 return bfd_xcoff_ldhdrsz(abfd);
2906}
2907
a7b97311 2908static bfd_vma
beb1bf64
TR
2909xcoff_loader_reloc_offset (abfd, ldhdr)
2910 bfd *abfd;
f4ffd778 2911 struct internal_ldhdr *ldhdr;
beb1bf64
TR
2912{
2913 return bfd_xcoff_ldhdrsz(abfd) +
2914 (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd));
2915}
2916
2917
2918static reloc_howto_type xcoff_dynamic_reloc =
2919HOWTO (0, /* type */
2920 0, /* rightshift */
2921 2, /* size (0 = byte, 1 = short, 2 = long) */
2922 32, /* bitsize */
2923 false, /* pc_relative */
2924 0, /* bitpos */
2925 complain_overflow_bitfield, /* complain_on_overflow */
2926 0, /* special_function */
2927 "R_POS", /* name */
2928 true, /* partial_inplace */
2929 0xffffffff, /* src_mask */
2930 0xffffffff, /* dst_mask */
2931 false); /* pcrel_offset */
2932
f4ffd778
NC
2933/* glink
2934
2935 The first word of global linkage code must be modified by filling in
2936 the correct TOC offset. */
2937
beb1bf64 2938static unsigned long xcoff_glink_code[9] =
f4ffd778
NC
2939 {
2940 0x81820000, /* lwz r12,0(r2) */
2941 0x90410014, /* stw r2,20(r1) */
2942 0x800c0000, /* lwz r0,0(r12) */
2943 0x804c0004, /* lwz r2,4(r12) */
2944 0x7c0903a6, /* mtctr r0 */
2945 0x4e800420, /* bctr */
2946 0x00000000, /* start of traceback table */
2947 0x000c8000, /* traceback table */
2948 0x00000000, /* traceback table */
2949 };
beb1bf64
TR
2950
2951
2952static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
f4ffd778
NC
2953 {
2954 { /* COFF backend, defined in libcoff.h. */
2955 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
2956 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
2957 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2958 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
2959 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
2960 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
2961 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2962 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2963 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2964 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2965 FILHSZ, /* _bfd_filhsz */
2966 AOUTSZ, /* _bfd_aoutsz */
2967 SCNHSZ, /* _bfd_scnhsz */
2968 SYMESZ, /* _bfd_symesz */
2969 AUXESZ, /* _bfd_auxesz */
2970 RELSZ, /* _bfd_relsz */
2971 LINESZ, /* _bfd_linesz */
2972 FILNMLEN, /* _bfd_filnmlen */
2973 true, /* _bfd_coff_long_filenames */
2974 false, /* _bfd_coff_long_section_names */
2975 (3), /* _bfd_coff_default_section_alignment_power */
2976 false, /* _bfd_coff_force_symnames_in_strings */
2977 2, /* _bfd_coff_debug_string_prefix_length */
2978 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2979 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2980 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2981 coff_swap_reloc_in, /* _bfd_reloc_in */
2982 coff_bad_format_hook, /* _bfd_bad_format_hook */
2983 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2984 coff_mkobject_hook, /* _bfd_mkobject_hook */
2985 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2986 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2987 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2988 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2989 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2990 coff_print_aux, /* bfd_coff_print_aux */
2991 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2992 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2993 NULL, /* bfd_coff_sym_is_global */
2994 coff_compute_section_file_positions, /* _bfd_coff_compute_section_file_positions */
2995 NULL , /* _bfd_coff_start_final_link */
2996 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
2997 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2998 NULL , /* _bfd_coff_addust_symndx */
2999 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3000 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3001 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3002 },
3003
3004 0x01DF, /* magic number */
3005 bfd_arch_rs6000, /* architecture */
3006 bfd_mach_rs6k, /* machine */
beb1bf64 3007
f4ffd778
NC
3008 /* Function pointers to xcoff specific swap routines. */
3009 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
3010 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
3011 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3012 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3013 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3014 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3015
3016 /* Sizes. */
3017 LDHDRSZ, /* _xcoff_ldhdrsz */
3018 LDSYMSZ, /* _xcoff_ldsymsz */
3019 LDRELSZ, /* _xcoff_ldrelsz */
3020 12, /* _xcoff_function_descriptor_size */
3021 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3022
3023 /* Versions. */
3024 1, /* _xcoff_ldhdr_version */
3025
3026 /* Xcoff vs xcoff64 putting symbol names. */
3027 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3028 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3029
3030 & xcoff_dynamic_reloc, /* dynamic reloc howto */
3031
3032 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3033
3034 /* Lineno and reloc count overflow. */
3035 xcoff_is_lineno_count_overflow,
3036 xcoff_is_reloc_count_overflow,
3037
3038 xcoff_loader_symbol_offset,
3039 xcoff_loader_reloc_offset,
3040
3041 /* glink. */
3042 & xcoff_glink_code[0],
3043 (36), /* _xcoff_glink_size */
beb1bf64
TR
3044};
3045
3046/* The transfer vector that leads the outside world to all of the above. */
3047const bfd_target rs6000coff_vec =
3048{
3049 "aixcoff-rs6000",
3050 bfd_target_xcoff_flavour,
3051 BFD_ENDIAN_BIG, /* data byte order is big */
3052 BFD_ENDIAN_BIG, /* header byte order is big */
3053
3054 (HAS_RELOC | EXEC_P | /* object flags */
3055 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3056 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3057
3058 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3059 0, /* leading char */
3060 '/', /* ar_pad_char */
3061 15, /* ar_max_namelen??? FIXMEmgo */
3062
3063 /* data */
3064 bfd_getb64, /* bfd_getx64 */
3065 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3066 bfd_putb64, /* bfd_putx64 */
3067 bfd_getb32, /* bfd_getx32 */
3068 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3069 bfd_putb32, /* bfd_putx32 */
3070 bfd_getb16, /* bfd_getx16 */
3071 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3072 bfd_putb16, /* bfd_putx16 */
3073
3074 /* hdrs */
3075 bfd_getb64, /* bfd_h_getx64 */
3076 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3077 bfd_putb64, /* bfd_h_putx64 */
3078 bfd_getb32, /* bfd_h_getx32 */
3079 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3080 bfd_putb32, /* bfd_h_putx32 */
3081 bfd_getb16, /* bfd_h_getx16 */
3082 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3083 bfd_putb16, /* bfd_h_putx16 */
3084
3085 { /* bfd_check_format */
3086 _bfd_dummy_target,
3087 coff_object_p,
3088 _bfd_xcoff_archive_p,
3089 CORE_FILE_P
3090 },
3091
3092 { /* bfd_set_format */
3093 bfd_false,
3094 coff_mkobject,
3095 _bfd_generic_mkarchive,
3096 bfd_false
3097 },
3098
3099 {/* bfd_write_contents */
3100 bfd_false,
3101 coff_write_object_contents,
3102 _bfd_xcoff_write_archive_contents,
3103 bfd_false
3104 },
3105
3106 /* Generic */
3107 bfd_true, /* _close_and_cleanup */
3108 bfd_true, /* _bfd_free_cached_info */
3109 coff_new_section_hook, /* _new_section_hook */
3110 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3111 /* _bfd_get_section_contents_in_window */
3112 _bfd_generic_get_section_contents_in_window,
3113
3114 /* Copy */
3115 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3116 /* _bfd_merge_private_bfd_data */
3117 ((boolean (*) (bfd *, bfd *)) bfd_true),
3118 /* _bfd_copy_pivate_section_data */
3119 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3120 /* _bfd_copy_private_symbol_data */
3121 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3122 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3123 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3124
3125 /* Core */
b55039f4
L
3126 coff_core_file_failing_command, /* _core_file_failing_command */
3127 coff_core_file_failing_signal, /* _core_file_failing_signal */
beb1bf64 3128 /* _core_file_matches_executable_p */
b55039f4 3129 coff_core_file_matches_executable_p,
beb1bf64
TR
3130
3131 /* Archive */
3132 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3133 /* XCOFF archives do not have
3134 anything which corresponds to
3135 an extended name table. */
3136 bfd_false, /* _slurp_extended_name_table */
3137 /* _construct_extended_name_table */
3138 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3139 bfd_dont_truncate_arname, /* _truncate_arname */
3140 _bfd_xcoff_write_armap, /* _write_armap */
3141 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3142 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3143 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3144 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3145 /* XCOFF archives do not have
3146 a timestamp. */
3147 bfd_true, /* _update_armap_timestamp */
3148
3149 /* Symbols */
3150 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3151 coff_get_symtab, /* _get_symtab */
3152 coff_make_empty_symbol, /* _make_empty_symbol */
3153 coff_print_symbol, /* _print_symbol */
3154 coff_get_symbol_info, /* _get_symbol_info */
3155 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3156 coff_get_lineno, /* _get_lineno */
3157 coff_find_nearest_line, /* _find_nearest_line */
3158 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3159 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3160 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3161
3162 /* Reloc */
3163 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3164 coff_canonicalize_reloc, /* _cononicalize_reloc */
3165 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3166
3167 /* Write */
3168 coff_set_arch_mach, /* _set_arch_mach */
3169 coff_set_section_contents, /* _set_section_contents */
3170
3171 /* Link */
3172 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3173 /* _bfd_get_relocated_section_contents */
3174 bfd_generic_get_relocated_section_contents,
3175 bfd_generic_relax_section, /* _bfd_relax_section */
3176 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3177 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3178 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3179 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3180 bfd_generic_gc_sections, /* _bfd_gc_sections */
3181 bfd_generic_merge_sections, /* _bfd_merge_sections */
3182
3183 /* Dynamic */
3184 /* _get_dynamic_symtab_upper_bound */
3185 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3186 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3187 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3188 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3189
3190 /* Opposite endian version, none exists */
3191 NULL,
3192
3193 /* back end data */
3194 (void *) &bfd_xcoff_backend_data,
3195};
3196
3197/*
3198 * xcoff-powermac target
3199 * Old target.
3200 * Only difference between this target and the rs6000 target is the
3201 * the default architecture and machine type used in coffcode.h
3202 *
3203 * PowerPC Macs use the same magic numbers as RS/6000
3204 * (because that's how they were bootstrapped originally),
3205 * but they are always PowerPC architecture.
3206 */
3207static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
3208{
3209 { /* COFF backend, defined in libcoff.h */
3210 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
3211 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
3212 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
3213 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
3214 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
3215 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
3216 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
3217 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
3218 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
3219 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
3220 FILHSZ, /* _bfd_filhsz */
3221 AOUTSZ, /* _bfd_aoutsz */
3222 SCNHSZ, /* _bfd_scnhsz */
3223 SYMESZ, /* _bfd_symesz */
3224 AUXESZ, /* _bfd_auxesz */
3225 RELSZ, /* _bfd_relsz */
3226 LINESZ, /* _bfd_linesz */
3227 FILNMLEN, /* _bfd_filnmlen */
3228 true, /* _bfd_coff_long_filenames */
3229 false, /* _bfd_coff_long_section_names */
3230 (3), /* _bfd_coff_default_section_alignment_power */
3231 false, /* _bfd_coff_force_symnames_in_strings */
3232 2, /* _bfd_coff_debug_string_prefix_length */
3233 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
3234 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
3235 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
3236 coff_swap_reloc_in, /* _bfd_reloc_in */
3237 coff_bad_format_hook, /* _bfd_bad_format_hook */
3238 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
3239 coff_mkobject_hook, /* _bfd_mkobject_hook */
3240 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
3241 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
3242 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
3243 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
3244 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
3245 coff_print_aux, /* bfd_coff_print_aux */
3246 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
3247 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
3248 NULL, /* bfd_coff_sym_is_global */
3249 /* _bfd_coff_compute_section_file_positions */
3250 coff_compute_section_file_positions,
3251 NULL , /* _bfd_coff_start_final_link */
3252 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
3253 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
3254 NULL , /* _bfd_coff_addust_symndx */
3255 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3256 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3257 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3258 },
3259
3260 0x01DF, /* magic number */
3261 bfd_arch_powerpc, /* architecture */
3262 bfd_mach_ppc, /* machine */
3263
3264 /* function pointers to xcoff specific swap routines */
3265 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
3266 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
3267 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3268 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3269 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3270 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3271
3272 /* sizes */
3273 LDHDRSZ, /* _xcoff_ldhdrsz */
3274 LDSYMSZ, /* _xcoff_ldsymsz */
3275 LDRELSZ, /* _xcoff_ldrelsz */
3276 12, /* _xcoff_function_descriptor_size */
3277 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3278
3279 /* versions */
3280 1, /* _xcoff_ldhdr_version */
3281
3282 /* xcoff vs xcoff64 putting symbol names */
3283 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3284 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3285
3286 &xcoff_dynamic_reloc, /* dynamic reloc howto */
3287
3288 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3289
3290 /* lineno and reloc count overflow */
3291 xcoff_is_lineno_count_overflow,
3292 xcoff_is_reloc_count_overflow,
3293
3294 xcoff_loader_symbol_offset,
3295 xcoff_loader_reloc_offset,
3296
3297 /* glink */
3298 &xcoff_glink_code[0],
3299 (36), /* _xcoff_glink_size */
3300
3301};
3302
3303/* The transfer vector that leads the outside world to all of the above. */
3304const bfd_target pmac_xcoff_vec =
3305{
3306 "xcoff-powermac",
3307 bfd_target_xcoff_flavour,
3308 BFD_ENDIAN_BIG, /* data byte order is big */
3309 BFD_ENDIAN_BIG, /* header byte order is big */
3310
3311 (HAS_RELOC | EXEC_P | /* object flags */
3312 HAS_LINENO | HAS_DEBUG | DYNAMIC |
3313 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3314
3315 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3316 0, /* leading char */
3317 '/', /* ar_pad_char */
3318 15, /* ar_max_namelen??? FIXMEmgo */
3319
3320 /* data */
3321 bfd_getb64, /* bfd_getx64 */
3322 bfd_getb_signed_64, /* bfd_getx_signed_64 */
3323 bfd_putb64, /* bfd_putx64 */
3324 bfd_getb32, /* bfd_getx32 */
3325 bfd_getb_signed_32, /* bfd_getx_signed_32 */
3326 bfd_putb32, /* bfd_putx32 */
3327 bfd_getb16, /* bfd_getx16 */
3328 bfd_getb_signed_16, /* bfd_getx_signed_16 */
3329 bfd_putb16, /* bfd_putx16 */
3330
3331 /* hdrs */
3332 bfd_getb64, /* bfd_h_getx64 */
3333 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
3334 bfd_putb64, /* bfd_h_putx64 */
3335 bfd_getb32, /* bfd_h_getx32 */
3336 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
3337 bfd_putb32, /* bfd_h_putx32 */
3338 bfd_getb16, /* bfd_h_getx16 */
3339 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
3340 bfd_putb16, /* bfd_h_putx16 */
3341
3342 { /* bfd_check_format */
3343 _bfd_dummy_target,
3344 coff_object_p,
3345 _bfd_xcoff_archive_p,
3346 CORE_FILE_P
3347 },
3348
3349 { /* bfd_set_format */
3350 bfd_false,
3351 coff_mkobject,
3352 _bfd_generic_mkarchive,
3353 bfd_false
3354 },
3355
3356 {/* bfd_write_contents */
3357 bfd_false,
3358 coff_write_object_contents,
3359 _bfd_xcoff_write_archive_contents,
3360 bfd_false
3361 },
3362
3363 /* Generic */
3364 bfd_true, /* _close_and_cleanup */
3365 bfd_true, /* _bfd_free_cached_info */
3366 coff_new_section_hook, /* _new_section_hook */
3367 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
3368 /* _bfd_get_section_contents_in_window */
3369 _bfd_generic_get_section_contents_in_window,
3370
3371 /* Copy */
3372 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
3373 /* _bfd_merge_private_bfd_data */
3374 ((boolean (*) (bfd *, bfd *)) bfd_true),
3375 /* _bfd_copy_pivate_section_data */
3376 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
3377 /* _bfd_copy_private_symbol_data */
3378 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
3379 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
3380 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
3381
3382 /* Core */
b55039f4
L
3383 coff_core_file_failing_command, /* _core_file_failing_command */
3384 coff_core_file_failing_signal, /* _core_file_failing_signal */
beb1bf64 3385 /* _core_file_matches_executable_p */
b55039f4 3386 coff_core_file_matches_executable_p,
beb1bf64
TR
3387
3388 /* Archive */
3389 _bfd_xcoff_slurp_armap, /* _slurp_armap */
3390 /* XCOFF archives do not have
3391 anything which corresponds to
3392 an extended name table. */
3393 bfd_false, /* _slurp_extended_name_table */
3394 /* _construct_extended_name_table */
3395 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
3396 bfd_dont_truncate_arname, /* _truncate_arname */
3397 _bfd_xcoff_write_armap, /* _write_armap */
3398 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
3399 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
3400 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
3401 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
3402 /* XCOFF archives do not have
3403 a timestamp. */
3404 bfd_true, /* _update_armap_timestamp */
3405
3406 /* Symbols */
3407 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
3408 coff_get_symtab, /* _get_symtab */
3409 coff_make_empty_symbol, /* _make_empty_symbol */
3410 coff_print_symbol, /* _print_symbol */
3411 coff_get_symbol_info, /* _get_symbol_info */
3412 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
3413 coff_get_lineno, /* _get_lineno */
3414 coff_find_nearest_line, /* _find_nearest_line */
3415 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
3416 _bfd_generic_read_minisymbols, /* _read_minisymbols */
3417 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
3418
3419 /* Reloc */
3420 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
3421 coff_canonicalize_reloc, /* _cononicalize_reloc */
3422 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
3423
3424 /* Write */
3425 coff_set_arch_mach, /* _set_arch_mach */
3426 coff_set_section_contents, /* _set_section_contents */
3427
3428 /* Link */
3429 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
3430 /* _bfd_get_relocated_section_contents */
3431 bfd_generic_get_relocated_section_contents,
3432 bfd_generic_relax_section, /* _bfd_relax_section */
3433 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
3434 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
3435 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
3436 _bfd_generic_link_split_section, /* _bfd_link_split_section */
3437 bfd_generic_gc_sections, /* _bfd_gc_sections */
3438 bfd_generic_merge_sections, /* _bfd_merge_sections */
3439
3440 /* Dynamic */
3441 /* _get_dynamic_symtab_upper_bound */
3442 _bfd_xcoff_get_dynamic_symtab_upper_bound,
3443 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
3444 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
3445 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
3446
3447 /* Opposite endian version, none exists */
3448 NULL,
3449
3450 /* back end data */
3451 (void *) &bfd_pmac_xcoff_backend_data,
3452};
This page took 0.233918 seconds and 4 git commands to generate.