* coff-rs6000.c: Formatting fixes.
[binutils-gdb.git] / bfd / coff-rs6000.c
1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 FIXME: Can someone provide a transliteration of this name into ASCII?
5 Using the following chars caused a compiler warning on HIUX (so I replaced
6 them with octal escapes), and isn't useful without an understanding of what
7 character set it is.
8 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
9 and John Gilmore.
10 Archive support from Damon A. Permezel.
11 Contributed by IBM Corporation and Cygnus Support.
12
13 This file is part of BFD, the Binary File Descriptor library.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28
29 #include "bfd.h"
30 #include "sysdep.h"
31 #include "bfdlink.h"
32 #include "libbfd.h"
33 #include "coff/internal.h"
34 #include "coff/xcoff.h"
35 #include "coff/rs6000.h"
36 #include "libcoff.h"
37 #include "libxcoff.h"
38
39 extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
40 extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
41 extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
42 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
43 PARAMS ((bfd *, bfd_reloc_code_real_type));
44 extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
45 extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *));
46 extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
47 extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
48 extern int _bfd_xcoff_stat_arch_elt PARAMS ((bfd *, struct stat *));
49 extern boolean _bfd_xcoff_write_armap
50 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
51 extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
52 extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
53 extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
54 extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
55 extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
56 extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
57 static void xcoff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
58 static unsigned int xcoff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
59
60 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
61 void xcoff_rtype2howto PARAMS ((arelent *, struct internal_reloc *));
62
63 /* coffcode.h needs these to be defined. */
64 #define RS6000COFF_C 1
65
66 #define SELECT_RELOC(internal, howto) \
67 { \
68 internal.r_type = howto->type; \
69 internal.r_size = \
70 ((howto->complain_on_overflow == complain_overflow_signed \
71 ? 0x80 \
72 : 0) \
73 | (howto->bitsize - 1)); \
74 }
75
76 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
77 #define COFF_LONG_FILENAMES
78 #define NO_COFF_SYMBOLS
79 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
80 #define coff_mkobject _bfd_xcoff_mkobject
81 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
82 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
83 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
84 #ifdef AIX_CORE
85 extern const bfd_target * rs6000coff_core_p PARAMS ((bfd *abfd));
86 extern boolean rs6000coff_core_file_matches_executable_p
87 PARAMS ((bfd *cbfd, bfd *ebfd));
88 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
89 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
90 #define CORE_FILE_P rs6000coff_core_p
91 #define coff_core_file_failing_command \
92 rs6000coff_core_file_failing_command
93 #define coff_core_file_failing_signal \
94 rs6000coff_core_file_failing_signal
95 #define coff_core_file_matches_executable_p \
96 rs6000coff_core_file_matches_executable_p
97 #else
98 #define CORE_FILE_P _bfd_dummy_target
99 #define coff_core_file_failing_command \
100 _bfd_nocore_core_file_failing_command
101 #define coff_core_file_failing_signal \
102 _bfd_nocore_core_file_failing_signal
103 #define coff_core_file_matches_executable_p \
104 _bfd_nocore_core_file_matches_executable_p
105 #endif
106 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
107 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
108 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
109 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
110 #define coff_swap_reloc_in xcoff_swap_reloc_in
111 #define coff_swap_reloc_out xcoff_swap_reloc_out
112 #define NO_COFF_RELOCS
113
114 #include "coffcode.h"
115
116 /* The main body of code is in coffcode.h. */
117
118 static const char *normalize_filename PARAMS ((bfd *));
119 static boolean xcoff_write_armap_old
120 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
121 static boolean xcoff_write_armap_big
122 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
123 static boolean xcoff_write_archive_contents_old PARAMS ((bfd *));
124 static boolean xcoff_write_archive_contents_big PARAMS ((bfd *));
125 static void xcoff_swap_ldhdr_in
126 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
127 static void xcoff_swap_ldhdr_out
128 PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
129 static void xcoff_swap_ldsym_in
130 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
131 static void xcoff_swap_ldsym_out
132 PARAMS ((bfd *, const struct internal_ldsym *, PTR));
133 static void xcoff_swap_ldrel_in
134 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
135 static void xcoff_swap_ldrel_out
136 PARAMS ((bfd *, const struct internal_ldrel *, PTR));
137 static boolean xcoff_ppc_relocate_section
138 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
139 struct internal_reloc *, struct internal_syment *, asection **));
140 static boolean _bfd_xcoff_put_ldsymbol_name
141 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
142 const char *));
143 static asection *xcoff_create_csect_from_smclas
144 PARAMS ((bfd *, union internal_auxent *, const char *));
145 static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
146 static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
147 static bfd_vma xcoff_loader_symbol_offset
148 PARAMS ((bfd *, struct internal_ldhdr *));
149 static bfd_vma xcoff_loader_reloc_offset
150 PARAMS ((bfd *, struct internal_ldhdr *));
151 static boolean xcoff_generate_rtinit
152 PARAMS ((bfd *, const char *, const char *, boolean));
153 static boolean do_pad PARAMS ((bfd *, unsigned int));
154 static boolean do_copy PARAMS ((bfd *, bfd *));
155 static boolean do_shared_object_padding PARAMS ((bfd *, bfd *, ufile_ptr *, int));
156
157 /* Relocation functions */
158 static boolean xcoff_reloc_type_br PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
159
160 static boolean xcoff_complain_overflow_dont_func
161 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
162 static boolean xcoff_complain_overflow_bitfield_func
163 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
164 static boolean xcoff_complain_overflow_signed_func
165 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
166 static boolean xcoff_complain_overflow_unsigned_func
167 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
168
169 boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
170 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) =
171 {
172 xcoff_reloc_type_pos, /* R_POS (0x00) */
173 xcoff_reloc_type_neg, /* R_NEG (0x01) */
174 xcoff_reloc_type_rel, /* R_REL (0x02) */
175 xcoff_reloc_type_toc, /* R_TOC (0x03) */
176 xcoff_reloc_type_fail, /* R_RTB (0x04) */
177 xcoff_reloc_type_toc, /* R_GL (0x05) */
178 xcoff_reloc_type_toc, /* R_TCL (0x06) */
179 xcoff_reloc_type_fail, /* (0x07) */
180 xcoff_reloc_type_ba, /* R_BA (0x08) */
181 xcoff_reloc_type_fail, /* (0x09) */
182 xcoff_reloc_type_br, /* R_BR (0x0a) */
183 xcoff_reloc_type_fail, /* (0x0b) */
184 xcoff_reloc_type_pos, /* R_RL (0x0c) */
185 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
186 xcoff_reloc_type_fail, /* (0x0e) */
187 xcoff_reloc_type_noop, /* R_REF (0x0f) */
188 xcoff_reloc_type_fail, /* (0x10) */
189 xcoff_reloc_type_fail, /* (0x11) */
190 xcoff_reloc_type_toc, /* R_TRL (0x12) */
191 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
192 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
193 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
194 xcoff_reloc_type_ba, /* R_CAI (0x16) */
195 xcoff_reloc_type_crel, /* R_CREL (0x17) */
196 xcoff_reloc_type_ba, /* R_RBA (0x18) */
197 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
198 xcoff_reloc_type_br, /* R_RBR (0x1a) */
199 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
200 };
201
202 boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
203 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) =
204 {
205 xcoff_complain_overflow_dont_func,
206 xcoff_complain_overflow_bitfield_func,
207 xcoff_complain_overflow_signed_func,
208 xcoff_complain_overflow_unsigned_func,
209 };
210
211 /* We use our own tdata type. Its first field is the COFF tdata type,
212 so the COFF routines are compatible. */
213
214 boolean
215 _bfd_xcoff_mkobject (abfd)
216 bfd *abfd;
217 {
218 coff_data_type *coff;
219 bfd_size_type amt = sizeof (struct xcoff_tdata);
220
221 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
222 if (abfd->tdata.xcoff_obj_data == NULL)
223 return false;
224 coff = coff_data (abfd);
225 coff->symbols = (coff_symbol_type *) NULL;
226 coff->conversion_table = (unsigned int *) NULL;
227 coff->raw_syments = (struct coff_ptr_struct *) NULL;
228 coff->relocbase = 0;
229
230 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
231
232 /* We set cputype to -1 to indicate that it has not been
233 initialized. */
234 xcoff_data (abfd)->cputype = -1;
235
236 xcoff_data (abfd)->csects = NULL;
237 xcoff_data (abfd)->debug_indices = NULL;
238
239 /* text section alignment is different than the default */
240 bfd_xcoff_text_align_power (abfd) = 2;
241
242 return true;
243 }
244
245 /* Copy XCOFF data from one BFD to another. */
246
247 boolean
248 _bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
249 bfd *ibfd;
250 bfd *obfd;
251 {
252 struct xcoff_tdata *ix, *ox;
253 asection *sec;
254
255 if (ibfd->xvec != obfd->xvec)
256 return true;
257 ix = xcoff_data (ibfd);
258 ox = xcoff_data (obfd);
259 ox->full_aouthdr = ix->full_aouthdr;
260 ox->toc = ix->toc;
261 if (ix->sntoc == 0)
262 ox->sntoc = 0;
263 else
264 {
265 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
266 if (sec == NULL)
267 ox->sntoc = 0;
268 else
269 ox->sntoc = sec->output_section->target_index;
270 }
271 if (ix->snentry == 0)
272 ox->snentry = 0;
273 else
274 {
275 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
276 if (sec == NULL)
277 ox->snentry = 0;
278 else
279 ox->snentry = sec->output_section->target_index;
280 }
281 bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
282 bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
283 ox->modtype = ix->modtype;
284 ox->cputype = ix->cputype;
285 ox->maxdata = ix->maxdata;
286 ox->maxstack = ix->maxstack;
287 return true;
288 }
289
290 /* I don't think XCOFF really has a notion of local labels based on
291 name. This will mean that ld -X doesn't actually strip anything.
292 The AIX native linker does not have a -X option, and it ignores the
293 -x option. */
294
295 boolean
296 _bfd_xcoff_is_local_label_name (abfd, name)
297 bfd *abfd ATTRIBUTE_UNUSED;
298 const char *name ATTRIBUTE_UNUSED;
299 {
300 return false;
301 }
302 \f
303 void
304 _bfd_xcoff_swap_sym_in (abfd, ext1, in1)
305 bfd *abfd;
306 PTR ext1;
307 PTR in1;
308 {
309 SYMENT *ext = (SYMENT *)ext1;
310 struct internal_syment * in = (struct internal_syment *)in1;
311
312 if (ext->e.e_name[0] != 0)
313 {
314 memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
315 }
316 else
317 {
318 in->_n._n_n._n_zeroes = 0;
319 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
320 }
321
322 in->n_value = H_GET_32 (abfd, ext->e_value);
323 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
324 in->n_type = H_GET_16 (abfd, ext->e_type);
325 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
326 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
327 }
328
329 unsigned int
330 _bfd_xcoff_swap_sym_out (abfd, inp, extp)
331 bfd *abfd;
332 PTR inp;
333 PTR extp;
334 {
335 struct internal_syment *in = (struct internal_syment *)inp;
336 SYMENT *ext =(SYMENT *)extp;
337
338 if (in->_n._n_name[0] != 0)
339 {
340 memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
341 }
342 else
343 {
344 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
345 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
346 }
347
348 H_PUT_32 (abfd, in->n_value, ext->e_value);
349 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
350 H_PUT_16 (abfd, in->n_type, ext->e_type);
351 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
352 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
353 return bfd_coff_symesz (abfd);
354 }
355
356 void
357 _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
358 bfd *abfd;
359 PTR ext1;
360 int type;
361 int class;
362 int indx;
363 int numaux;
364 PTR in1;
365 {
366 AUXENT * ext = (AUXENT *)ext1;
367 union internal_auxent *in = (union internal_auxent *)in1;
368
369 switch (class)
370 {
371 case C_FILE:
372 if (ext->x_file.x_fname[0] == 0)
373 {
374 in->x_file.x_n.x_zeroes = 0;
375 in->x_file.x_n.x_offset =
376 H_GET_32 (abfd, ext->x_file.x_n.x_offset);
377 }
378 else
379 {
380 if (numaux > 1)
381 {
382 if (indx == 0)
383 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
384 numaux * sizeof (AUXENT));
385 }
386 else
387 {
388 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
389 }
390 }
391 goto end;
392
393 /* RS/6000 "csect" auxents */
394 case C_EXT:
395 case C_HIDEXT:
396 if (indx + 1 == numaux)
397 {
398 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
399 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
400 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
401 /* We don't have to hack bitfields in x_smtyp because it's
402 defined by shifts-and-ands, which are equivalent on all
403 byte orders. */
404 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
405 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
406 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
407 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
408 goto end;
409 }
410 break;
411
412 case C_STAT:
413 case C_LEAFSTAT:
414 case C_HIDDEN:
415 if (type == T_NULL)
416 {
417 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
418 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
419 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
420 /* PE defines some extra fields; we zero them out for
421 safety. */
422 in->x_scn.x_checksum = 0;
423 in->x_scn.x_associated = 0;
424 in->x_scn.x_comdat = 0;
425
426 goto end;
427 }
428 break;
429 }
430
431 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
432 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
433
434 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
435 {
436 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
437 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
438 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
439 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
440 }
441 else
442 {
443 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
444 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
445 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
446 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
447 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
448 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
449 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
450 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
451 }
452
453 if (ISFCN (type))
454 {
455 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
456 }
457 else
458 {
459 in->x_sym.x_misc.x_lnsz.x_lnno =
460 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
461 in->x_sym.x_misc.x_lnsz.x_size =
462 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
463 }
464
465 end: ;
466 /* The semicolon is because MSVC doesn't like labels at
467 end of block. */
468 }
469
470
471 unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
472
473 unsigned int
474 _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
475 bfd * abfd;
476 PTR inp;
477 int type;
478 int class;
479 int indx ATTRIBUTE_UNUSED;
480 int numaux ATTRIBUTE_UNUSED;
481 PTR extp;
482 {
483 union internal_auxent *in = (union internal_auxent *)inp;
484 AUXENT *ext = (AUXENT *)extp;
485
486 memset ((PTR)ext, 0, bfd_coff_auxesz (abfd));
487 switch (class)
488 {
489 case C_FILE:
490 if (in->x_file.x_fname[0] == 0)
491 {
492 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
493 H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
494 }
495 else
496 {
497 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
498 }
499 goto end;
500
501 /* RS/6000 "csect" auxents */
502 case C_EXT:
503 case C_HIDEXT:
504 if (indx + 1 == numaux)
505 {
506 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
507 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
508 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
509 /* We don't have to hack bitfields in x_smtyp because it's
510 defined by shifts-and-ands, which are equivalent on all
511 byte orders. */
512 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
513 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
514 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
515 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
516 goto end;
517 }
518 break;
519
520 case C_STAT:
521 case C_LEAFSTAT:
522 case C_HIDDEN:
523 if (type == T_NULL)
524 {
525 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
526 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
527 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
528 goto end;
529 }
530 break;
531 }
532
533 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
534 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
535
536 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
537 {
538 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
539 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
540 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
541 ext->x_sym.x_fcnary.x_fcn.x_endndx);
542 }
543 else
544 {
545 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
546 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
547 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
548 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
549 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
550 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
551 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
552 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
553 }
554
555 if (ISFCN (type))
556 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
557 else
558 {
559 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
560 ext->x_sym.x_misc.x_lnsz.x_lnno);
561 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
562 ext->x_sym.x_misc.x_lnsz.x_size);
563 }
564
565 end:
566 return bfd_coff_auxesz (abfd);
567 }
568
569
570 \f
571 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
572 bitsize and whether they are signed or not, along with a
573 conventional type. This table is for the types, which are used for
574 different algorithms for putting in the reloc. Many of these
575 relocs need special_function entries, which I have not written. */
576
577
578 reloc_howto_type xcoff_howto_table[] =
579 {
580 /* Standard 32 bit relocation. */
581 HOWTO (R_POS, /* type */
582 0, /* rightshift */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
584 32, /* bitsize */
585 false, /* pc_relative */
586 0, /* bitpos */
587 complain_overflow_bitfield, /* complain_on_overflow */
588 0, /* special_function */
589 "R_POS", /* name */
590 true, /* partial_inplace */
591 0xffffffff, /* src_mask */
592 0xffffffff, /* dst_mask */
593 false), /* pcrel_offset */
594
595 /* 32 bit relocation, but store negative value. */
596 HOWTO (R_NEG, /* type */
597 0, /* rightshift */
598 -2, /* size (0 = byte, 1 = short, 2 = long) */
599 32, /* bitsize */
600 false, /* pc_relative */
601 0, /* bitpos */
602 complain_overflow_bitfield, /* complain_on_overflow */
603 0, /* special_function */
604 "R_NEG", /* name */
605 true, /* partial_inplace */
606 0xffffffff, /* src_mask */
607 0xffffffff, /* dst_mask */
608 false), /* pcrel_offset */
609
610 /* 32 bit PC relative relocation. */
611 HOWTO (R_REL, /* type */
612 0, /* rightshift */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
614 32, /* bitsize */
615 true, /* pc_relative */
616 0, /* bitpos */
617 complain_overflow_signed, /* complain_on_overflow */
618 0, /* special_function */
619 "R_REL", /* name */
620 true, /* partial_inplace */
621 0xffffffff, /* src_mask */
622 0xffffffff, /* dst_mask */
623 false), /* pcrel_offset */
624
625 /* 16 bit TOC relative relocation. */
626 HOWTO (R_TOC, /* type */
627 0, /* rightshift */
628 1, /* size (0 = byte, 1 = short, 2 = long) */
629 16, /* bitsize */
630 false, /* pc_relative */
631 0, /* bitpos */
632 complain_overflow_bitfield, /* complain_on_overflow */
633 0, /* special_function */
634 "R_TOC", /* name */
635 true, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 false), /* pcrel_offset */
639
640 /* I don't really know what this is. */
641 HOWTO (R_RTB, /* type */
642 1, /* rightshift */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
644 32, /* bitsize */
645 false, /* pc_relative */
646 0, /* bitpos */
647 complain_overflow_bitfield, /* complain_on_overflow */
648 0, /* special_function */
649 "R_RTB", /* name */
650 true, /* partial_inplace */
651 0xffffffff, /* src_mask */
652 0xffffffff, /* dst_mask */
653 false), /* pcrel_offset */
654
655 /* External TOC relative symbol. */
656 HOWTO (R_GL, /* type */
657 0, /* rightshift */
658 1, /* size (0 = byte, 1 = short, 2 = long) */
659 16, /* bitsize */
660 false, /* pc_relative */
661 0, /* bitpos */
662 complain_overflow_bitfield, /* complain_on_overflow */
663 0, /* special_function */
664 "R_GL", /* name */
665 true, /* partial_inplace */
666 0xffff, /* src_mask */
667 0xffff, /* dst_mask */
668 false), /* pcrel_offset */
669
670 /* Local TOC relative symbol. */
671 HOWTO (R_TCL, /* type */
672 0, /* rightshift */
673 1, /* size (0 = byte, 1 = short, 2 = long) */
674 16, /* bitsize */
675 false, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_bitfield, /* complain_on_overflow */
678 0, /* special_function */
679 "R_TCL", /* name */
680 true, /* partial_inplace */
681 0xffff, /* src_mask */
682 0xffff, /* dst_mask */
683 false), /* pcrel_offset */
684
685 EMPTY_HOWTO (7),
686
687 /* Non modifiable absolute branch. */
688 HOWTO (R_BA, /* type */
689 0, /* rightshift */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
691 26, /* bitsize */
692 false, /* pc_relative */
693 0, /* bitpos */
694 complain_overflow_bitfield, /* complain_on_overflow */
695 0, /* special_function */
696 "R_BA_26", /* name */
697 true, /* partial_inplace */
698 0x03fffffc, /* src_mask */
699 0x03fffffc, /* dst_mask */
700 false), /* pcrel_offset */
701
702 EMPTY_HOWTO (9),
703
704 /* Non modifiable relative branch. */
705 HOWTO (R_BR, /* type */
706 0, /* rightshift */
707 2, /* size (0 = byte, 1 = short, 2 = long) */
708 26, /* bitsize */
709 true, /* pc_relative */
710 0, /* bitpos */
711 complain_overflow_signed, /* complain_on_overflow */
712 0, /* special_function */
713 "R_BR", /* name */
714 true, /* partial_inplace */
715 0x03fffffc, /* src_mask */
716 0x03fffffc, /* dst_mask */
717 false), /* pcrel_offset */
718
719 EMPTY_HOWTO (0xb),
720
721 /* Indirect load. */
722 HOWTO (R_RL, /* type */
723 0, /* rightshift */
724 1, /* size (0 = byte, 1 = short, 2 = long) */
725 16, /* bitsize */
726 false, /* pc_relative */
727 0, /* bitpos */
728 complain_overflow_bitfield, /* complain_on_overflow */
729 0, /* special_function */
730 "R_RL", /* name */
731 true, /* partial_inplace */
732 0xffff, /* src_mask */
733 0xffff, /* dst_mask */
734 false), /* pcrel_offset */
735
736 /* Load address. */
737 HOWTO (R_RLA, /* type */
738 0, /* rightshift */
739 1, /* size (0 = byte, 1 = short, 2 = long) */
740 16, /* bitsize */
741 false, /* pc_relative */
742 0, /* bitpos */
743 complain_overflow_bitfield, /* complain_on_overflow */
744 0, /* special_function */
745 "R_RLA", /* name */
746 true, /* partial_inplace */
747 0xffff, /* src_mask */
748 0xffff, /* dst_mask */
749 false), /* pcrel_offset */
750
751 EMPTY_HOWTO (0xe),
752
753 /* Non-relocating reference. */
754 HOWTO (R_REF, /* type */
755 0, /* rightshift */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
757 32, /* bitsize */
758 false, /* pc_relative */
759 0, /* bitpos */
760 complain_overflow_dont, /* complain_on_overflow */
761 0, /* special_function */
762 "R_REF", /* name */
763 false, /* partial_inplace */
764 0, /* src_mask */
765 0, /* dst_mask */
766 false), /* pcrel_offset */
767
768 EMPTY_HOWTO (0x10),
769 EMPTY_HOWTO (0x11),
770
771 /* TOC relative indirect load. */
772 HOWTO (R_TRL, /* type */
773 0, /* rightshift */
774 1, /* size (0 = byte, 1 = short, 2 = long) */
775 16, /* bitsize */
776 false, /* pc_relative */
777 0, /* bitpos */
778 complain_overflow_bitfield, /* complain_on_overflow */
779 0, /* special_function */
780 "R_TRL", /* name */
781 true, /* partial_inplace */
782 0xffff, /* src_mask */
783 0xffff, /* dst_mask */
784 false), /* pcrel_offset */
785
786 /* TOC relative load address. */
787 HOWTO (R_TRLA, /* type */
788 0, /* rightshift */
789 1, /* size (0 = byte, 1 = short, 2 = long) */
790 16, /* bitsize */
791 false, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_bitfield, /* complain_on_overflow */
794 0, /* special_function */
795 "R_TRLA", /* name */
796 true, /* partial_inplace */
797 0xffff, /* src_mask */
798 0xffff, /* dst_mask */
799 false), /* pcrel_offset */
800
801 /* Modifiable relative branch. */
802 HOWTO (R_RRTBI, /* type */
803 1, /* rightshift */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
805 32, /* bitsize */
806 false, /* pc_relative */
807 0, /* bitpos */
808 complain_overflow_bitfield, /* complain_on_overflow */
809 0, /* special_function */
810 "R_RRTBI", /* name */
811 true, /* partial_inplace */
812 0xffffffff, /* src_mask */
813 0xffffffff, /* dst_mask */
814 false), /* pcrel_offset */
815
816 /* Modifiable absolute branch. */
817 HOWTO (R_RRTBA, /* type */
818 1, /* rightshift */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
820 32, /* bitsize */
821 false, /* pc_relative */
822 0, /* bitpos */
823 complain_overflow_bitfield, /* complain_on_overflow */
824 0, /* special_function */
825 "R_RRTBA", /* name */
826 true, /* partial_inplace */
827 0xffffffff, /* src_mask */
828 0xffffffff, /* dst_mask */
829 false), /* pcrel_offset */
830
831 /* Modifiable call absolute indirect. */
832 HOWTO (R_CAI, /* type */
833 0, /* rightshift */
834 1, /* size (0 = byte, 1 = short, 2 = long) */
835 16, /* bitsize */
836 false, /* pc_relative */
837 0, /* bitpos */
838 complain_overflow_bitfield, /* complain_on_overflow */
839 0, /* special_function */
840 "R_CAI", /* name */
841 true, /* partial_inplace */
842 0xffff, /* src_mask */
843 0xffff, /* dst_mask */
844 false), /* pcrel_offset */
845
846 /* Modifiable call relative. */
847 HOWTO (R_CREL, /* type */
848 0, /* rightshift */
849 1, /* size (0 = byte, 1 = short, 2 = long) */
850 16, /* bitsize */
851 false, /* pc_relative */
852 0, /* bitpos */
853 complain_overflow_bitfield, /* complain_on_overflow */
854 0, /* special_function */
855 "R_CREL", /* name */
856 true, /* partial_inplace */
857 0xffff, /* src_mask */
858 0xffff, /* dst_mask */
859 false), /* pcrel_offset */
860
861 /* Modifiable branch absolute. */
862 HOWTO (R_RBA, /* type */
863 0, /* rightshift */
864 2, /* size (0 = byte, 1 = short, 2 = long) */
865 26, /* bitsize */
866 false, /* pc_relative */
867 0, /* bitpos */
868 complain_overflow_bitfield, /* complain_on_overflow */
869 0, /* special_function */
870 "R_RBA", /* name */
871 true, /* partial_inplace */
872 0x03fffffc, /* src_mask */
873 0x03fffffc, /* dst_mask */
874 false), /* pcrel_offset */
875
876 /* Modifiable branch absolute. */
877 HOWTO (R_RBAC, /* type */
878 0, /* rightshift */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
880 32, /* bitsize */
881 false, /* pc_relative */
882 0, /* bitpos */
883 complain_overflow_bitfield, /* complain_on_overflow */
884 0, /* special_function */
885 "R_RBAC", /* name */
886 true, /* partial_inplace */
887 0xffffffff, /* src_mask */
888 0xffffffff, /* dst_mask */
889 false), /* pcrel_offset */
890
891 /* Modifiable branch relative. */
892 HOWTO (R_RBR, /* type */
893 0, /* rightshift */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
895 26, /* bitsize */
896 false, /* pc_relative */
897 0, /* bitpos */
898 complain_overflow_signed, /* complain_on_overflow */
899 0, /* special_function */
900 "R_RBR_26", /* name */
901 true, /* partial_inplace */
902 0x03fffffc, /* src_mask */
903 0x03fffffc, /* dst_mask */
904 false), /* pcrel_offset */
905
906 /* Modifiable branch absolute. */
907 HOWTO (R_RBRC, /* type */
908 0, /* rightshift */
909 1, /* size (0 = byte, 1 = short, 2 = long) */
910 16, /* bitsize */
911 false, /* pc_relative */
912 0, /* bitpos */
913 complain_overflow_bitfield, /* complain_on_overflow */
914 0, /* special_function */
915 "R_RBRC", /* name */
916 true, /* partial_inplace */
917 0xffff, /* src_mask */
918 0xffff, /* dst_mask */
919 false), /* pcrel_offset */
920
921 /* 16 bit Non modifiable absolute branch. */
922 HOWTO (R_BA, /* type */
923 0, /* rightshift */
924 1, /* size (0 = byte, 1 = short, 2 = long) */
925 16, /* bitsize */
926 false, /* pc_relative */
927 0, /* bitpos */
928 complain_overflow_bitfield, /* complain_on_overflow */
929 0, /* special_function */
930 "R_BA_16", /* name */
931 true, /* partial_inplace */
932 0xfffc, /* src_mask */
933 0xfffc, /* dst_mask */
934 false), /* pcrel_offset */
935
936 /* Modifiable branch relative. */
937 HOWTO (R_RBR, /* type */
938 0, /* rightshift */
939 1, /* size (0 = byte, 1 = short, 2 = long) */
940 16, /* bitsize */
941 false, /* pc_relative */
942 0, /* bitpos */
943 complain_overflow_signed, /* complain_on_overflow */
944 0, /* special_function */
945 "R_RBR_16", /* name */
946 true, /* partial_inplace */
947 0xffff, /* src_mask */
948 0xffff, /* dst_mask */
949 false), /* pcrel_offset */
950
951 /* Modifiable branch relative. */
952 HOWTO (R_RBA, /* type */
953 0, /* rightshift */
954 1, /* size (0 = byte, 1 = short, 2 = long) */
955 16, /* bitsize */
956 false, /* pc_relative */
957 0, /* bitpos */
958 complain_overflow_signed, /* complain_on_overflow */
959 0, /* special_function */
960 "R_RBA_16", /* name */
961 true, /* partial_inplace */
962 0xffff, /* src_mask */
963 0xffff, /* dst_mask */
964 false), /* pcrel_offset */
965
966 };
967
968 void
969 xcoff_rtype2howto (relent, internal)
970 arelent *relent;
971 struct internal_reloc *internal;
972 {
973 if (internal->r_type > R_RBRC)
974 abort ();
975
976 /* Default howto layout works most of the time */
977 relent->howto = &xcoff_howto_table[internal->r_type];
978
979 /* Special case some 16 bit reoloc */
980 if (15 == (internal->r_size & 0x1f))
981 {
982 if (R_BA == internal->r_type)
983 relent->howto = &xcoff_howto_table[0x1c];
984 else if (R_RBR == internal->r_type)
985 relent->howto = &xcoff_howto_table[0x1d];
986 else if (R_RBA == internal->r_type)
987 relent->howto = &xcoff_howto_table[0x1e];
988 }
989
990 /* The r_size field of an XCOFF reloc encodes the bitsize of the
991 relocation, as well as indicating whether it is signed or not.
992 Doublecheck that the relocation information gathered from the
993 type matches this information. The bitsize is not significant
994 for R_REF relocs. */
995 if (relent->howto->dst_mask != 0
996 && (relent->howto->bitsize
997 != ((unsigned int) internal->r_size & 0x1f) + 1))
998 abort ();
999
1000 /* Put a meaningful value in addend */
1001 relent->addend = (internal->r_size & 0x80
1002 ? -internal->r_vaddr
1003 : internal->r_vaddr);
1004 }
1005
1006 reloc_howto_type *
1007 _bfd_xcoff_reloc_type_lookup (abfd, code)
1008 bfd *abfd ATTRIBUTE_UNUSED;
1009 bfd_reloc_code_real_type code;
1010 {
1011 switch (code)
1012 {
1013 case BFD_RELOC_PPC_B26:
1014 return &xcoff_howto_table[0xa];
1015 case BFD_RELOC_PPC_BA16:
1016 return &xcoff_howto_table[0x1c];
1017 case BFD_RELOC_PPC_BA26:
1018 return &xcoff_howto_table[8];
1019 case BFD_RELOC_PPC_TOC16:
1020 return &xcoff_howto_table[3];
1021 case BFD_RELOC_32:
1022 case BFD_RELOC_CTOR:
1023 return &xcoff_howto_table[0];
1024 default:
1025 return NULL;
1026 }
1027 }
1028
1029 \f
1030 /* XCOFF archive support. The original version of this code was by
1031 Damon A. Permezel. It was enhanced to permit cross support, and
1032 writing archive files, by Ian Lance Taylor, Cygnus Support.
1033
1034 XCOFF uses its own archive format. Everything is hooked together
1035 with file offset links, so it is possible to rapidly update an
1036 archive in place. Of course, we don't do that. An XCOFF archive
1037 has a real file header, not just an ARMAG string. The structure of
1038 the file header and of each archive header appear below.
1039
1040 An XCOFF archive also has a member table, which is a list of
1041 elements in the archive (you can get that by looking through the
1042 linked list, but you have to read a lot more of the file). The
1043 member table has a normal archive header with an empty name. It is
1044 normally (and perhaps must be) the second to last entry in the
1045 archive. The member table data is almost printable ASCII. It
1046 starts with a 12 character decimal string which is the number of
1047 entries in the table. For each entry it has a 12 character decimal
1048 string which is the offset in the archive of that member. These
1049 entries are followed by a series of null terminated strings which
1050 are the member names for each entry.
1051
1052 Finally, an XCOFF archive has a global symbol table, which is what
1053 we call the armap. The global symbol table has a normal archive
1054 header with an empty name. It is normally (and perhaps must be)
1055 the last entry in the archive. The contents start with a four byte
1056 binary number which is the number of entries. This is followed by
1057 a that many four byte binary numbers; each is the file offset of an
1058 entry in the archive. These numbers are followed by a series of
1059 null terminated strings, which are symbol names.
1060
1061 AIX 4.3 introduced a new archive format which can handle larger
1062 files and also 32- and 64-bit objects in the same archive. The
1063 things said above remain true except that there is now more than
1064 one global symbol table. The one is used to index 32-bit objects,
1065 the other for 64-bit objects.
1066
1067 The new archives (recognizable by the new ARMAG string) has larger
1068 field lengths so that we cannot really share any code. Also we have
1069 to take care that we are not generating the new form of archives
1070 on AIX 4.2 or earlier systems. */
1071
1072 /* XCOFF archives use this as a magic string. Note that both strings
1073 have the same length. */
1074
1075 /* Set the magic for archive. */
1076
1077 boolean
1078 bfd_xcoff_ar_archive_set_magic (abfd, magic)
1079 bfd *abfd ATTRIBUTE_UNUSED;
1080 char *magic ATTRIBUTE_UNUSED;
1081 {
1082 /* Not supported yet. */
1083 return false;
1084 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1085 }
1086
1087 /* Read in the armap of an XCOFF archive. */
1088
1089 boolean
1090 _bfd_xcoff_slurp_armap (abfd)
1091 bfd *abfd;
1092 {
1093 file_ptr off;
1094 size_t namlen;
1095 bfd_size_type sz;
1096 bfd_byte *contents, *cend;
1097 bfd_vma c, i;
1098 carsym *arsym;
1099 bfd_byte *p;
1100
1101 if (xcoff_ardata (abfd) == NULL)
1102 {
1103 bfd_has_map (abfd) = false;
1104 return true;
1105 }
1106
1107 if (! xcoff_big_format_p (abfd))
1108 {
1109 /* This is for the old format. */
1110 struct xcoff_ar_hdr hdr;
1111
1112 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1113 if (off == 0)
1114 {
1115 bfd_has_map (abfd) = false;
1116 return true;
1117 }
1118
1119 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1120 return false;
1121
1122 /* The symbol table starts with a normal archive header. */
1123 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1124 != SIZEOF_AR_HDR)
1125 return false;
1126
1127 /* Skip the name (normally empty). */
1128 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1129 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1130 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1131 return false;
1132
1133 sz = strtol (hdr.size, (char **) NULL, 10);
1134
1135 /* Read in the entire symbol table. */
1136 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1137 if (contents == NULL)
1138 return false;
1139 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1140 return false;
1141
1142 /* The symbol table starts with a four byte count. */
1143 c = H_GET_32 (abfd, contents);
1144
1145 if (c * 4 >= sz)
1146 {
1147 bfd_set_error (bfd_error_bad_value);
1148 return false;
1149 }
1150
1151 bfd_ardata (abfd)->symdefs =
1152 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1153 if (bfd_ardata (abfd)->symdefs == NULL)
1154 return false;
1155
1156 /* After the count comes a list of four byte file offsets. */
1157 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1158 i < c;
1159 ++i, ++arsym, p += 4)
1160 arsym->file_offset = H_GET_32 (abfd, p);
1161 }
1162 else
1163 {
1164 /* This is for the new format. */
1165 struct xcoff_ar_hdr_big hdr;
1166
1167 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1168 if (off == 0)
1169 {
1170 bfd_has_map (abfd) = false;
1171 return true;
1172 }
1173
1174 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1175 return false;
1176
1177 /* The symbol table starts with a normal archive header. */
1178 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1179 != SIZEOF_AR_HDR_BIG)
1180 return false;
1181
1182 /* Skip the name (normally empty). */
1183 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1184 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1185 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1186 return false;
1187
1188 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1189 machines) since the field width is 20 and there numbers with more
1190 than 32 bits can be represented. */
1191 sz = strtol (hdr.size, (char **) NULL, 10);
1192
1193 /* Read in the entire symbol table. */
1194 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1195 if (contents == NULL)
1196 return false;
1197 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1198 return false;
1199
1200 /* The symbol table starts with an eight byte count. */
1201 c = H_GET_64 (abfd, contents);
1202
1203 if (c * 8 >= sz)
1204 {
1205 bfd_set_error (bfd_error_bad_value);
1206 return false;
1207 }
1208
1209 bfd_ardata (abfd)->symdefs =
1210 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1211 if (bfd_ardata (abfd)->symdefs == NULL)
1212 return false;
1213
1214 /* After the count comes a list of eight byte file offsets. */
1215 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1216 i < c;
1217 ++i, ++arsym, p += 8)
1218 arsym->file_offset = H_GET_64 (abfd, p);
1219 }
1220
1221 /* After the file offsets come null terminated symbol names. */
1222 cend = contents + sz;
1223 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1224 i < c;
1225 ++i, ++arsym, p += strlen ((char *) p) + 1)
1226 {
1227 if (p >= cend)
1228 {
1229 bfd_set_error (bfd_error_bad_value);
1230 return false;
1231 }
1232 arsym->name = (char *) p;
1233 }
1234
1235 bfd_ardata (abfd)->symdef_count = c;
1236 bfd_has_map (abfd) = true;
1237
1238 return true;
1239 }
1240
1241 /* See if this is an XCOFF archive. */
1242
1243 const bfd_target *
1244 _bfd_xcoff_archive_p (abfd)
1245 bfd *abfd;
1246 {
1247 struct artdata *tdata_hold;
1248 char magic[SXCOFFARMAG];
1249 bfd_size_type amt = SXCOFFARMAG;
1250
1251 if (bfd_bread ((PTR) magic, amt, abfd) != amt)
1252 {
1253 if (bfd_get_error () != bfd_error_system_call)
1254 bfd_set_error (bfd_error_wrong_format);
1255 return NULL;
1256 }
1257
1258 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1259 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1260 {
1261 bfd_set_error (bfd_error_wrong_format);
1262 return NULL;
1263 }
1264
1265 tdata_hold = bfd_ardata (abfd);
1266
1267 amt = sizeof (struct artdata);
1268 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
1269 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1270 goto error_ret_restore;
1271
1272 bfd_ardata (abfd)->cache = NULL;
1273 bfd_ardata (abfd)->archive_head = NULL;
1274 bfd_ardata (abfd)->symdefs = NULL;
1275 bfd_ardata (abfd)->extended_names = NULL;
1276
1277 /* Now handle the two formats. */
1278 if (magic[1] != 'b')
1279 {
1280 /* This is the old format. */
1281 struct xcoff_ar_file_hdr hdr;
1282
1283 /* Copy over the magic string. */
1284 memcpy (hdr.magic, magic, SXCOFFARMAG);
1285
1286 /* Now read the rest of the file header. */
1287 amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
1288 if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
1289 {
1290 if (bfd_get_error () != bfd_error_system_call)
1291 bfd_set_error (bfd_error_wrong_format);
1292 goto error_ret;
1293 }
1294
1295 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1296 (char **) NULL, 10);
1297
1298 amt = SIZEOF_AR_FILE_HDR;
1299 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1300 if (bfd_ardata (abfd)->tdata == NULL)
1301 goto error_ret;
1302
1303 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1304 }
1305 else
1306 {
1307 /* This is the new format. */
1308 struct xcoff_ar_file_hdr_big hdr;
1309
1310 /* Copy over the magic string. */
1311 memcpy (hdr.magic, magic, SXCOFFARMAG);
1312
1313 /* Now read the rest of the file header. */
1314 amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1315 if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
1316 {
1317 if (bfd_get_error () != bfd_error_system_call)
1318 bfd_set_error (bfd_error_wrong_format);
1319 goto error_ret;
1320 }
1321
1322 bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
1323 (const char **) 0,
1324 10);
1325
1326 amt = SIZEOF_AR_FILE_HDR_BIG;
1327 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1328 if (bfd_ardata (abfd)->tdata == NULL)
1329 goto error_ret;
1330
1331 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1332 }
1333
1334 if (! _bfd_xcoff_slurp_armap (abfd))
1335 {
1336 error_ret:
1337 bfd_release (abfd, bfd_ardata (abfd));
1338 error_ret_restore:
1339 bfd_ardata (abfd) = tdata_hold;
1340 return NULL;
1341 }
1342
1343 return abfd->xvec;
1344 }
1345
1346 /* Read the archive header in an XCOFF archive. */
1347
1348 PTR
1349 _bfd_xcoff_read_ar_hdr (abfd)
1350 bfd *abfd;
1351 {
1352 bfd_size_type namlen;
1353 struct areltdata *ret;
1354 bfd_size_type amt = sizeof (struct areltdata);
1355
1356 ret = (struct areltdata *) bfd_alloc (abfd, amt);
1357 if (ret == NULL)
1358 return NULL;
1359
1360 if (! xcoff_big_format_p (abfd))
1361 {
1362 struct xcoff_ar_hdr hdr;
1363 struct xcoff_ar_hdr *hdrp;
1364
1365 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1366 != SIZEOF_AR_HDR)
1367 {
1368 free (ret);
1369 return NULL;
1370 }
1371
1372 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1373 amt = SIZEOF_AR_HDR + namlen + 1;
1374 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1375 if (hdrp == NULL)
1376 {
1377 free (ret);
1378 return NULL;
1379 }
1380 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1381 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1382 {
1383 free (ret);
1384 return NULL;
1385 }
1386 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1387
1388 ret->arch_header = (char *) hdrp;
1389 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1390 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1391 }
1392 else
1393 {
1394 struct xcoff_ar_hdr_big hdr;
1395 struct xcoff_ar_hdr_big *hdrp;
1396
1397 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1398 != SIZEOF_AR_HDR_BIG)
1399 {
1400 free (ret);
1401 return NULL;
1402 }
1403
1404 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1405 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1406 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1407 if (hdrp == NULL)
1408 {
1409 free (ret);
1410 return NULL;
1411 }
1412 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1413 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1414 {
1415 free (ret);
1416 return NULL;
1417 }
1418 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1419
1420 ret->arch_header = (char *) hdrp;
1421 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1422 machines) since the field width is 20 and there numbers with more
1423 than 32 bits can be represented. */
1424 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1425 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1426 }
1427
1428 /* Skip over the XCOFFARFMAG at the end of the file name. */
1429 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1430 return NULL;
1431
1432 return (PTR) ret;
1433 }
1434
1435 /* Open the next element in an XCOFF archive. */
1436
1437 bfd *
1438 _bfd_xcoff_openr_next_archived_file (archive, last_file)
1439 bfd *archive;
1440 bfd *last_file;
1441 {
1442 file_ptr filestart;
1443
1444 if (xcoff_ardata (archive) == NULL)
1445 {
1446 bfd_set_error (bfd_error_invalid_operation);
1447 return NULL;
1448 }
1449
1450 if (! xcoff_big_format_p (archive))
1451 {
1452 if (last_file == NULL)
1453 filestart = bfd_ardata (archive)->first_file_filepos;
1454 else
1455 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1456 10);
1457
1458 if (filestart == 0
1459 || filestart == strtol (xcoff_ardata (archive)->memoff,
1460 (char **) NULL, 10)
1461 || filestart == strtol (xcoff_ardata (archive)->symoff,
1462 (char **) NULL, 10))
1463 {
1464 bfd_set_error (bfd_error_no_more_archived_files);
1465 return NULL;
1466 }
1467 }
1468 else
1469 {
1470 if (last_file == NULL)
1471 filestart = bfd_ardata (archive)->first_file_filepos;
1472 else
1473 /* XXX These actually have to be a calls to strtoll (at least
1474 on 32-bit machines) since the fields's width is 20 and
1475 there numbers with more than 32 bits can be represented. */
1476 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1477 10);
1478
1479 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1480 machines) since the fields's width is 20 and there numbers with more
1481 than 32 bits can be represented. */
1482 if (filestart == 0
1483 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1484 (char **) NULL, 10)
1485 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1486 (char **) NULL, 10))
1487 {
1488 bfd_set_error (bfd_error_no_more_archived_files);
1489 return NULL;
1490 }
1491 }
1492
1493 return _bfd_get_elt_at_filepos (archive, filestart);
1494 }
1495
1496 /* Stat an element in an XCOFF archive. */
1497
1498 int
1499 _bfd_xcoff_stat_arch_elt (abfd, s)
1500 bfd *abfd;
1501 struct stat *s;
1502 {
1503 if (abfd->arelt_data == NULL)
1504 {
1505 bfd_set_error (bfd_error_invalid_operation);
1506 return -1;
1507 }
1508
1509 if (! xcoff_big_format_p (abfd->my_archive))
1510 {
1511 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1512
1513 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1514 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1515 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1516 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1517 s->st_size = arch_eltdata (abfd)->parsed_size;
1518 }
1519 else
1520 {
1521 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1522
1523 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1524 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1525 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1526 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1527 s->st_size = arch_eltdata (abfd)->parsed_size;
1528 }
1529
1530 return 0;
1531 }
1532
1533 /* Normalize a file name for inclusion in an archive. */
1534
1535 static const char *
1536 normalize_filename (abfd)
1537 bfd *abfd;
1538 {
1539 const char *file;
1540 const char *filename;
1541
1542 file = bfd_get_filename (abfd);
1543 filename = strrchr (file, '/');
1544 if (filename != NULL)
1545 filename++;
1546 else
1547 filename = file;
1548 return filename;
1549 }
1550
1551 /* Write out an XCOFF armap. */
1552
1553 /*ARGSUSED*/
1554 static boolean
1555 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1556 bfd *abfd;
1557 unsigned int elength ATTRIBUTE_UNUSED;
1558 struct orl *map;
1559 unsigned int orl_count;
1560 int stridx;
1561 {
1562 struct xcoff_ar_hdr hdr;
1563 char *p;
1564 unsigned char buf[4];
1565 bfd *sub;
1566 file_ptr fileoff;
1567 unsigned int i;
1568
1569 memset (&hdr, 0, sizeof hdr);
1570 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1571 sprintf (hdr.nextoff, "%d", 0);
1572 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1573 sprintf (hdr.date, "%d", 0);
1574 sprintf (hdr.uid, "%d", 0);
1575 sprintf (hdr.gid, "%d", 0);
1576 sprintf (hdr.mode, "%d", 0);
1577 sprintf (hdr.namlen, "%d", 0);
1578
1579 /* We need spaces, not null bytes, in the header. */
1580 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1581 if (*p == '\0')
1582 *p = ' ';
1583
1584 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1585 != SIZEOF_AR_HDR
1586 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1587 != SXCOFFARFMAG))
1588 return false;
1589
1590 H_PUT_32 (abfd, orl_count, buf);
1591 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1592 return false;
1593
1594 sub = abfd->archive_head;
1595 fileoff = SIZEOF_AR_FILE_HDR;
1596 i = 0;
1597 while (sub != NULL && i < orl_count)
1598 {
1599 size_t namlen;
1600
1601 while (map[i].u.abfd == sub)
1602 {
1603 H_PUT_32 (abfd, fileoff, buf);
1604 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1605 return false;
1606 ++i;
1607 }
1608 namlen = strlen (normalize_filename (sub));
1609 namlen = (namlen + 1) &~ (size_t) 1;
1610 fileoff += (SIZEOF_AR_HDR
1611 + namlen
1612 + SXCOFFARFMAG
1613 + arelt_size (sub));
1614 fileoff = (fileoff + 1) &~ 1;
1615 sub = sub->next;
1616 }
1617
1618 for (i = 0; i < orl_count; i++)
1619 {
1620 const char *name;
1621 size_t namlen;
1622
1623 name = *map[i].name;
1624 namlen = strlen (name);
1625 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1626 return false;
1627 }
1628
1629 if ((stridx & 1) != 0)
1630 {
1631 char b;
1632
1633 b = '\0';
1634 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1635 return false;
1636 }
1637
1638 return true;
1639 }
1640
1641 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1642 #define FMT20 "%-20lld"
1643 #define FMT12 "%-12d"
1644 #define FMT12_OCTAL "%-12o"
1645 #define FMT4 "%-4d"
1646 #define PRINT20(d, v) \
1647 sprintf (buff20, FMT20, (long long)(v)), \
1648 memcpy ((void *) (d), buff20, 20)
1649
1650 #define PRINT12(d, v) \
1651 sprintf (buff20, FMT12, (int)(v)), \
1652 memcpy ((void *) (d), buff20, 12)
1653
1654 #define PRINT12_OCTAL(d, v) \
1655 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1656 memcpy ((void *) (d), buff20, 12)
1657
1658 #define PRINT4(d, v) \
1659 sprintf (buff20, FMT4, (int)(v)), \
1660 memcpy ((void *) (d), buff20, 4)
1661
1662 #define READ20(d, v) \
1663 buff20[20] = 0, \
1664 memcpy (buff20, (d), 20), \
1665 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1666
1667 static boolean
1668 do_pad (abfd, number)
1669 bfd *abfd;
1670 unsigned int number;
1671 {
1672 bfd_byte b = 0;
1673
1674 /* Limit pad to <= 4096. */
1675 if (number > 4096)
1676 return false;
1677
1678 while (number--)
1679 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1680 return false;
1681
1682 return true;
1683 }
1684
1685 static boolean
1686 do_copy (out_bfd, in_bfd)
1687 bfd *out_bfd;
1688 bfd *in_bfd;
1689 {
1690 bfd_size_type remaining;
1691 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1692
1693 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1694 return false;
1695
1696 remaining = arelt_size (in_bfd);
1697
1698 while (remaining >= DEFAULT_BUFFERSIZE)
1699 {
1700 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1701 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1702 return false;
1703
1704 remaining -= DEFAULT_BUFFERSIZE;
1705 }
1706
1707 if (remaining)
1708 {
1709 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1710 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1711 return false;
1712 }
1713
1714 return true;
1715 }
1716
1717 static boolean
1718 do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size)
1719 bfd *out_bfd;
1720 bfd *in_bfd;
1721 ufile_ptr *offset;
1722 int ar_header_size;
1723 {
1724 if (bfd_check_format (in_bfd, bfd_object)
1725 && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour
1726 && (in_bfd->flags & DYNAMIC) != 0)
1727 {
1728 bfd_size_type pad = 0;
1729 int text_align_power;
1730
1731 text_align_power = bfd_xcoff_text_align_power (in_bfd);
1732
1733 pad = 1 << text_align_power;
1734 pad -= (*offset + ar_header_size) & (pad - 1);
1735
1736 if (! do_pad (out_bfd, pad))
1737 return false;
1738
1739 *offset += pad;
1740 }
1741
1742 return true;
1743 }
1744
1745 static boolean
1746 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1747 bfd *abfd;
1748 unsigned int elength ATTRIBUTE_UNUSED;
1749 struct orl *map;
1750 unsigned int orl_count;
1751 int stridx;
1752 {
1753 struct xcoff_ar_file_hdr_big *fhdr;
1754 bfd_vma i, sym_32, sym_64, str_32, str_64;
1755 const bfd_arch_info_type *arch_info = NULL;
1756 bfd *current_bfd;
1757 size_t string_length;
1758 ufile_ptr nextoff, prevoff;
1759
1760 /* First, we look through the symbols and work out which are
1761 from 32-bit objects and which from 64-bit ones. */
1762 sym_32 = sym_64 = str_32 = str_64 = 0;
1763
1764 current_bfd = abfd->archive_head;
1765 if (current_bfd != NULL)
1766 arch_info = bfd_get_arch_info (current_bfd);
1767 i = 0;
1768 while (current_bfd != NULL && i < orl_count)
1769 {
1770 while (map[i].u.abfd == current_bfd)
1771 {
1772 string_length = strlen (*map[i].name) + 1;
1773
1774 if (arch_info->bits_per_address == 64)
1775 {
1776 sym_64++;
1777 str_64 += string_length;
1778 }
1779 else
1780 {
1781 sym_32++;
1782 str_32 += string_length;
1783 }
1784 i++;
1785 }
1786 current_bfd = current_bfd->next;
1787 if (current_bfd != NULL)
1788 arch_info = bfd_get_arch_info (current_bfd);
1789 }
1790
1791 /* A quick sanity check... */
1792 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1793 /* Explicit cast to int for compiler. */
1794 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1795
1796 fhdr = xcoff_ardata_big (abfd);
1797
1798 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1799 READ20 (fhdr->memoff, prevoff);
1800 READ20 (fhdr->symoff, nextoff);
1801
1802 BFD_ASSERT (nextoff == bfd_tell (abfd));
1803
1804 /* Write out the symbol table.
1805 Layout :
1806
1807 standard big archive header
1808 0x0000 ar_size [0x14]
1809 0x0014 ar_nxtmem [0x14]
1810 0x0028 ar_prvmem [0x14]
1811 0x003C ar_date [0x0C]
1812 0x0048 ar_uid [0x0C]
1813 0x0054 ar_gid [0x0C]
1814 0x0060 ar_mod [0x0C]
1815 0x006C ar_namelen[0x04]
1816 0x0070 ar_fmag [SXCOFFARFMAG]
1817
1818 Symbol table
1819 0x0072 num_syms [0x08], binary
1820 0x0078 offsets [0x08 * num_syms], binary
1821 0x0086 + 0x08 * num_syms names [??]
1822 ?? pad to even bytes.
1823 */
1824
1825 if (sym_32)
1826 {
1827 struct xcoff_ar_hdr_big *hdr;
1828 bfd_byte *symbol_table;
1829 bfd_byte *st;
1830 file_ptr fileoff;
1831
1832 bfd_vma symbol_table_size =
1833 SIZEOF_AR_HDR_BIG
1834 + SXCOFFARFMAG
1835 + 8
1836 + 8 * sym_32
1837 + str_32 + (str_32 & 1);
1838
1839 symbol_table = NULL;
1840 symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size);
1841 if (symbol_table == NULL)
1842 return false;
1843
1844 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1845
1846 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1847
1848 if (sym_64)
1849 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1850 else
1851 PRINT20 (hdr->nextoff, 0);
1852
1853 PRINT20 (hdr->prevoff, prevoff);
1854 PRINT12 (hdr->date, 0);
1855 PRINT12 (hdr->uid, 0);
1856 PRINT12 (hdr->gid, 0);
1857 PRINT12 (hdr->mode, 0);
1858 PRINT4 (hdr->namlen, 0) ;
1859
1860 st = symbol_table + SIZEOF_AR_HDR_BIG;
1861 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1862 st += SXCOFFARFMAG;
1863
1864 bfd_h_put_64 (abfd, sym_32, st);
1865 st += 8;
1866
1867 /* loop over the 32 bit offsets */
1868 current_bfd = abfd->archive_head;
1869 if (current_bfd != NULL)
1870 arch_info = bfd_get_arch_info (current_bfd);
1871 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1872 i = 0;
1873 while (current_bfd != NULL && i < orl_count)
1874 {
1875 while (map[i].u.abfd == current_bfd)
1876 {
1877 if (arch_info->bits_per_address == 32)
1878 {
1879 bfd_h_put_64 (abfd, fileoff, st);
1880 st += 8;
1881 }
1882 i++;
1883 }
1884 string_length = strlen (normalize_filename (current_bfd));
1885 string_length += string_length & 1;
1886 fileoff += (SIZEOF_AR_HDR_BIG
1887 + string_length
1888 + SXCOFFARFMAG
1889 + arelt_size (current_bfd));
1890 fileoff += fileoff & 1;
1891 current_bfd = current_bfd->next;
1892 if (current_bfd != NULL)
1893 arch_info = bfd_get_arch_info (current_bfd);
1894 }
1895
1896 /* loop over the 32 bit symbol names */
1897 current_bfd = abfd->archive_head;
1898 if (current_bfd != NULL)
1899 arch_info = bfd_get_arch_info (current_bfd);
1900 i = 0;
1901 while (current_bfd != NULL && i < orl_count)
1902 {
1903 while (map[i].u.abfd == current_bfd)
1904 {
1905 if (arch_info->bits_per_address == 32)
1906 {
1907 string_length = sprintf (st, "%s", *map[i].name);
1908 st += string_length + 1;
1909 }
1910 i++;
1911 }
1912 current_bfd = current_bfd->next;
1913 if (current_bfd != NULL)
1914 arch_info = bfd_get_arch_info (current_bfd);
1915 }
1916
1917 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1918
1919 free (symbol_table);
1920 symbol_table = NULL;
1921
1922 prevoff = nextoff;
1923 nextoff = nextoff + symbol_table_size;
1924 }
1925 else
1926 PRINT20 (fhdr->symoff, 0);
1927
1928 if (sym_64)
1929 {
1930 struct xcoff_ar_hdr_big *hdr;
1931 bfd_byte *symbol_table;
1932 bfd_byte *st;
1933 file_ptr fileoff;
1934
1935 bfd_vma symbol_table_size =
1936 SIZEOF_AR_HDR_BIG
1937 + SXCOFFARFMAG
1938 + 8
1939 + 8 * sym_64
1940 + str_64 + (str_64 & 1);
1941
1942 symbol_table = NULL;
1943 symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size);
1944 if (symbol_table == NULL)
1945 return false;
1946
1947 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1948
1949 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
1950 PRINT20 (hdr->nextoff, 0);
1951 PRINT20 (hdr->prevoff, prevoff);
1952 PRINT12 (hdr->date, 0);
1953 PRINT12 (hdr->uid, 0);
1954 PRINT12 (hdr->gid, 0);
1955 PRINT12 (hdr->mode, 0);
1956 PRINT4 (hdr->namlen, 0);
1957
1958 st = symbol_table + SIZEOF_AR_HDR_BIG;
1959 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1960 st += SXCOFFARFMAG;
1961
1962 bfd_h_put_64 (abfd, sym_64, st);
1963 st += 8;
1964
1965 /* loop over the 64 bit offsets */
1966 current_bfd = abfd->archive_head;
1967 if (current_bfd != NULL)
1968 arch_info = bfd_get_arch_info (current_bfd);
1969 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1970 i = 0;
1971 while (current_bfd != NULL && i < orl_count)
1972 {
1973 while (map[i].u.abfd == current_bfd)
1974 {
1975 if (arch_info->bits_per_address == 64)
1976 {
1977 bfd_h_put_64 (abfd, fileoff, st);
1978 st += 8;
1979 }
1980 i++;
1981 }
1982 string_length = strlen (normalize_filename (current_bfd));
1983 string_length += string_length & 1;
1984 fileoff += (SIZEOF_AR_HDR_BIG
1985 + string_length
1986 + SXCOFFARFMAG
1987 + arelt_size (current_bfd));
1988 fileoff += fileoff & 1;
1989 current_bfd = current_bfd->next;
1990 if (current_bfd != NULL)
1991 arch_info = bfd_get_arch_info (current_bfd);
1992 }
1993
1994 /* loop over the 64 bit symbol names */
1995 current_bfd = abfd->archive_head;
1996 if (current_bfd != NULL)
1997 arch_info = bfd_get_arch_info (current_bfd);
1998 i = 0;
1999 while (current_bfd != NULL && i < orl_count)
2000 {
2001 while (map[i].u.abfd == current_bfd)
2002 {
2003 if (arch_info->bits_per_address == 64)
2004 {
2005 string_length = sprintf (st, "%s", *map[i].name);
2006 st += string_length + 1;
2007 }
2008 i++;
2009 }
2010 current_bfd = current_bfd->next;
2011 if (current_bfd != NULL)
2012 arch_info = bfd_get_arch_info (current_bfd);
2013 }
2014
2015 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2016
2017 free (symbol_table);
2018 symbol_table = NULL;
2019
2020 PRINT20 (fhdr->symoff64, nextoff);
2021 }
2022 else
2023 PRINT20 (fhdr->symoff64, 0);
2024
2025 return true;
2026 }
2027
2028 boolean
2029 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
2030 bfd *abfd;
2031 unsigned int elength ATTRIBUTE_UNUSED;
2032 struct orl *map;
2033 unsigned int orl_count;
2034 int stridx;
2035 {
2036 if (! xcoff_big_format_p (abfd))
2037 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2038 else
2039 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2040 }
2041
2042 /* Write out an XCOFF archive. We always write an entire archive,
2043 rather than fussing with the freelist and so forth. */
2044
2045 static boolean
2046 xcoff_write_archive_contents_old (abfd)
2047 bfd *abfd;
2048 {
2049 struct xcoff_ar_file_hdr fhdr;
2050 bfd_size_type count;
2051 bfd_size_type total_namlen;
2052 file_ptr *offsets;
2053 boolean makemap;
2054 boolean hasobjects;
2055 ufile_ptr prevoff, nextoff;
2056 bfd *sub;
2057 size_t i;
2058 struct xcoff_ar_hdr ahdr;
2059 bfd_size_type size;
2060 char *p;
2061 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2062
2063 memset (&fhdr, 0, sizeof fhdr);
2064 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2065 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2066 sprintf (fhdr.freeoff, "%d", 0);
2067
2068 count = 0;
2069 total_namlen = 0;
2070 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2071 {
2072 ++count;
2073 total_namlen += strlen (normalize_filename (sub)) + 1;
2074 }
2075 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2076 if (offsets == NULL)
2077 return false;
2078
2079 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2080 return false;
2081
2082 makemap = bfd_has_map (abfd);
2083 hasobjects = false;
2084 prevoff = 0;
2085 nextoff = SIZEOF_AR_FILE_HDR;
2086 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
2087 {
2088 const char *name;
2089 bfd_size_type namlen;
2090 struct xcoff_ar_hdr *ahdrp;
2091 bfd_size_type remaining;
2092
2093 if (makemap && ! hasobjects)
2094 {
2095 if (bfd_check_format (sub, bfd_object))
2096 hasobjects = true;
2097 }
2098
2099 name = normalize_filename (sub);
2100 namlen = strlen (name);
2101
2102 if (sub->arelt_data != NULL)
2103 ahdrp = arch_xhdr (sub);
2104 else
2105 ahdrp = NULL;
2106
2107 if (ahdrp == NULL)
2108 {
2109 struct stat s;
2110
2111 memset (&ahdr, 0, sizeof ahdr);
2112 ahdrp = &ahdr;
2113 if (stat (bfd_get_filename (sub), &s) != 0)
2114 {
2115 bfd_set_error (bfd_error_system_call);
2116 return false;
2117 }
2118
2119 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2120 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2121 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2122 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2123 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2124
2125 if (sub->arelt_data == NULL)
2126 {
2127 size = sizeof (struct areltdata);
2128 sub->arelt_data = bfd_alloc (sub, size);
2129 if (sub->arelt_data == NULL)
2130 return false;
2131 }
2132
2133 arch_eltdata (sub)->parsed_size = s.st_size;
2134 }
2135
2136 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2137 sprintf (ahdrp->namlen, "%ld", (long) namlen);
2138
2139 /* If the length of the name is odd, we write out the null byte
2140 after the name as well. */
2141 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2142
2143 remaining = arelt_size (sub);
2144 size = (SIZEOF_AR_HDR
2145 + namlen
2146 + SXCOFFARFMAG
2147 + remaining);
2148
2149 BFD_ASSERT (nextoff == bfd_tell (abfd));
2150
2151 offsets[i] = nextoff;
2152
2153 prevoff = nextoff;
2154 nextoff += size + (size & 1);
2155
2156 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
2157
2158 /* We need spaces, not null bytes, in the header. */
2159 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2160 if (*p == '\0')
2161 *p = ' ';
2162
2163 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2164 != SIZEOF_AR_HDR)
2165 || (bfd_bwrite ((PTR) name, namlen, abfd) != namlen)
2166 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2167 != SXCOFFARFMAG))
2168 return false;
2169
2170 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
2171 return false;
2172
2173 if (! do_copy (abfd, sub))
2174 return false;
2175
2176 if (! do_pad (abfd, size & 1))
2177 return false;
2178 }
2179
2180 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2181
2182 /* Write out the member table. */
2183
2184 BFD_ASSERT (nextoff == bfd_tell (abfd));
2185 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2186
2187 memset (&ahdr, 0, sizeof ahdr);
2188 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2189 + count * XCOFFARMAG_ELEMENT_SIZE
2190 + total_namlen));
2191 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2192 sprintf (ahdr.date, "%d", 0);
2193 sprintf (ahdr.uid, "%d", 0);
2194 sprintf (ahdr.gid, "%d", 0);
2195 sprintf (ahdr.mode, "%d", 0);
2196 sprintf (ahdr.namlen, "%d", 0);
2197
2198 size = (SIZEOF_AR_HDR
2199 + XCOFFARMAG_ELEMENT_SIZE
2200 + count * XCOFFARMAG_ELEMENT_SIZE
2201 + total_namlen
2202 + SXCOFFARFMAG);
2203
2204 prevoff = nextoff;
2205 nextoff += size + (size & 1);
2206
2207 if (makemap && hasobjects)
2208 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2209 else
2210 sprintf (ahdr.nextoff, "%d", 0);
2211
2212 /* We need spaces, not null bytes, in the header. */
2213 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2214 if (*p == '\0')
2215 *p = ' ';
2216
2217 if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2218 != SIZEOF_AR_HDR)
2219 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2220 != SXCOFFARFMAG))
2221 return false;
2222
2223 sprintf (decbuf, "%-12ld", (long) count);
2224 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2225 != XCOFFARMAG_ELEMENT_SIZE)
2226 return false;
2227 for (i = 0; i < (size_t) count; i++)
2228 {
2229 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2230 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2231 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2232 return false;
2233 }
2234 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2235 {
2236 const char *name;
2237 bfd_size_type namlen;
2238
2239 name = normalize_filename (sub);
2240 namlen = strlen (name);
2241 if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
2242 return false;
2243 }
2244
2245 if (! do_pad (abfd, size & 1))
2246 return false;
2247
2248 /* Write out the armap, if appropriate. */
2249 if (! makemap || ! hasobjects)
2250 sprintf (fhdr.symoff, "%d", 0);
2251 else
2252 {
2253 BFD_ASSERT (nextoff == bfd_tell (abfd));
2254 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2255 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2256 if (! _bfd_compute_and_write_armap (abfd, 0))
2257 return false;
2258 }
2259
2260 /* Write out the archive file header. */
2261
2262 /* We need spaces, not null bytes, in the header. */
2263 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2264 if (*p == '\0')
2265 *p = ' ';
2266
2267 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2268 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2269 != SIZEOF_AR_FILE_HDR))
2270 return false;
2271
2272 return true;
2273 }
2274
2275 static boolean
2276 xcoff_write_archive_contents_big (abfd)
2277 bfd *abfd;
2278 {
2279 struct xcoff_ar_file_hdr_big fhdr;
2280 bfd_size_type count;
2281 bfd_size_type total_namlen;
2282 file_ptr *offsets;
2283 boolean makemap;
2284 boolean hasobjects;
2285 ufile_ptr prevoff, nextoff;
2286 bfd *current_bfd;
2287 size_t i;
2288 struct xcoff_ar_hdr_big *hdr, ahdr;
2289 bfd_size_type size;
2290 bfd_byte *member_table, *mt;
2291 bfd_vma member_table_size;
2292
2293 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2294 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2295
2296 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2297 return false;
2298
2299 /* Calculate count and total_namlen. */
2300 makemap = bfd_has_map (abfd);
2301 hasobjects = false;
2302 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2303 current_bfd != NULL;
2304 current_bfd = current_bfd->next, count++)
2305 {
2306 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2307
2308 if (makemap
2309 && ! hasobjects
2310 && bfd_check_format (current_bfd, bfd_object))
2311 hasobjects = true;
2312 }
2313
2314 offsets = NULL;
2315 if (count)
2316 {
2317 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2318 if (offsets == NULL)
2319 return false;
2320 }
2321
2322 prevoff = 0;
2323 nextoff = SIZEOF_AR_FILE_HDR_BIG;
2324 for (current_bfd = abfd->archive_head, i = 0;
2325 current_bfd != NULL;
2326 current_bfd = current_bfd->next, i++)
2327 {
2328 const char *name;
2329 bfd_size_type namlen;
2330 struct xcoff_ar_hdr_big *ahdrp;
2331 bfd_size_type remaining;
2332
2333 name = normalize_filename (current_bfd);
2334 namlen = strlen (name);
2335
2336 if (current_bfd->arelt_data != NULL)
2337 ahdrp = arch_xhdr_big (current_bfd);
2338 else
2339 ahdrp = NULL;
2340
2341 if (ahdrp == NULL)
2342 {
2343 struct stat s;
2344
2345 ahdrp = &ahdr;
2346 /* XXX This should actually be a call to stat64 (at least on
2347 32-bit machines).
2348 XXX This call will fail if the original object is not found. */
2349 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2350 {
2351 bfd_set_error (bfd_error_system_call);
2352 return false;
2353 }
2354
2355 PRINT20 (ahdrp->size, s.st_size);
2356 PRINT12 (ahdrp->date, s.st_mtime);
2357 PRINT12 (ahdrp->uid, s.st_uid);
2358 PRINT12 (ahdrp->gid, s.st_gid);
2359 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2360
2361 if (current_bfd->arelt_data == NULL)
2362 {
2363 size = sizeof (struct areltdata);
2364 current_bfd->arelt_data = bfd_alloc (current_bfd, size);
2365 if (current_bfd->arelt_data == NULL)
2366 return false;
2367 }
2368
2369 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2370 }
2371
2372 PRINT20 (ahdrp->prevoff, prevoff);
2373 PRINT4 (ahdrp->namlen, namlen);
2374
2375 /* If the length of the name is odd, we write out the null byte
2376 after the name as well. */
2377 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2378
2379 remaining = arelt_size (current_bfd);
2380 size = (SIZEOF_AR_HDR_BIG
2381 + namlen
2382 + SXCOFFARFMAG
2383 + remaining);
2384
2385 BFD_ASSERT (nextoff == bfd_tell (abfd));
2386
2387 /* Check for xcoff shared objects.
2388 Their text section needs to be aligned wrt the archive file position.
2389 This requires extra padding before the archive header. */
2390 if (! do_shared_object_padding (abfd, current_bfd, & nextoff,
2391 SIZEOF_AR_HDR_BIG + namlen
2392 + SXCOFFARFMAG))
2393 return false;
2394
2395 offsets[i] = nextoff;
2396
2397 prevoff = nextoff;
2398 nextoff += size + (size & 1);
2399
2400 PRINT20 (ahdrp->nextoff, nextoff);
2401
2402 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
2403 != SIZEOF_AR_HDR_BIG)
2404 || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen
2405 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG,
2406 abfd) != SXCOFFARFMAG))
2407 return false;
2408
2409 if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0)
2410 return false;
2411
2412 if (! do_copy (abfd, current_bfd))
2413 return false;
2414
2415 if (! do_pad (abfd, size & 1))
2416 return false;
2417 }
2418
2419 if (count)
2420 {
2421 PRINT20 (fhdr.firstmemoff, offsets[0]);
2422 PRINT20 (fhdr.lastmemoff, prevoff);
2423 }
2424
2425 /* Write out the member table.
2426 Layout :
2427
2428 standard big archive header
2429 0x0000 ar_size [0x14]
2430 0x0014 ar_nxtmem [0x14]
2431 0x0028 ar_prvmem [0x14]
2432 0x003C ar_date [0x0C]
2433 0x0048 ar_uid [0x0C]
2434 0x0054 ar_gid [0x0C]
2435 0x0060 ar_mod [0x0C]
2436 0x006C ar_namelen[0x04]
2437 0x0070 ar_fmag [0x02]
2438
2439 Member table
2440 0x0072 count [0x14]
2441 0x0086 offsets [0x14 * counts]
2442 0x0086 + 0x14 * counts names [??]
2443 ?? pad to even bytes.
2444 */
2445
2446 BFD_ASSERT (nextoff == bfd_tell (abfd));
2447
2448 member_table_size = (SIZEOF_AR_HDR_BIG
2449 + SXCOFFARFMAG
2450 + XCOFFARMAGBIG_ELEMENT_SIZE
2451 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2452 + total_namlen);
2453
2454 member_table_size += member_table_size & 1;
2455 member_table = NULL;
2456 member_table = (bfd_byte *) bfd_zmalloc (member_table_size);
2457 if (member_table == NULL)
2458 return false;
2459
2460 hdr = (struct xcoff_ar_hdr_big *) member_table;
2461
2462 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
2463 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2464 + total_namlen + (total_namlen & 1)));
2465 if (makemap && hasobjects)
2466 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2467 else
2468 PRINT20 (hdr->nextoff, 0);
2469 PRINT20 (hdr->prevoff, prevoff);
2470 PRINT12 (hdr->date, 0);
2471 PRINT12 (hdr->uid, 0);
2472 PRINT12 (hdr->gid, 0);
2473 PRINT12 (hdr->mode, 0);
2474 PRINT4 (hdr->namlen, 0);
2475
2476 mt = member_table + SIZEOF_AR_HDR_BIG;
2477 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2478 mt += SXCOFFARFMAG;
2479
2480 PRINT20 (mt, count);
2481 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2482 for (i = 0; i < (size_t) count; i++)
2483 {
2484 PRINT20 (mt, offsets[i]);
2485 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2486 }
2487
2488 if (count)
2489 {
2490 free (offsets);
2491 offsets = NULL;
2492 }
2493
2494 for (current_bfd = abfd->archive_head; current_bfd != NULL;
2495 current_bfd = current_bfd->next)
2496 {
2497 const char *name;
2498 size_t namlen;
2499
2500 name = normalize_filename (current_bfd);
2501 namlen = sprintf (mt, "%s", name);
2502 mt += namlen + 1;
2503 }
2504
2505 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2506 return false;
2507
2508 free (member_table);
2509 member_table = NULL;
2510
2511 PRINT20 (fhdr.memoff, nextoff);
2512
2513 prevoff = nextoff;
2514 nextoff += member_table_size;
2515
2516 /* Write out the armap, if appropriate. */
2517
2518 if (! makemap || ! hasobjects)
2519 PRINT20 (fhdr.symoff, 0);
2520 else
2521 {
2522 BFD_ASSERT (nextoff == bfd_tell (abfd));
2523
2524 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2525 PRINT20 (fhdr.symoff, nextoff);
2526
2527 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2528 if (! _bfd_compute_and_write_armap (abfd, 0))
2529 return false;
2530 }
2531
2532 /* Write out the archive file header. */
2533
2534 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2535 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2536 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2537 return false;
2538
2539 return true;
2540 }
2541
2542 boolean
2543 _bfd_xcoff_write_archive_contents (abfd)
2544 bfd *abfd;
2545 {
2546 if (! xcoff_big_format_p (abfd))
2547 return xcoff_write_archive_contents_old (abfd);
2548 else
2549 return xcoff_write_archive_contents_big (abfd);
2550 }
2551 \f
2552 /* We can't use the usual coff_sizeof_headers routine, because AIX
2553 always uses an a.out header. */
2554
2555 int
2556 _bfd_xcoff_sizeof_headers (abfd, reloc)
2557 bfd *abfd;
2558 boolean reloc ATTRIBUTE_UNUSED;
2559 {
2560 int size;
2561
2562 size = FILHSZ;
2563 if (xcoff_data (abfd)->full_aouthdr)
2564 size += AOUTSZ;
2565 else
2566 size += SMALL_AOUTSZ;
2567 size += abfd->section_count * SCNHSZ;
2568 return size;
2569 }
2570 \f
2571 /* Routines to swap information in the XCOFF .loader section. If we
2572 ever need to write an XCOFF loader, this stuff will need to be
2573 moved to another file shared by the linker (which XCOFF calls the
2574 ``binder'') and the loader. */
2575
2576 /* Swap in the ldhdr structure. */
2577
2578 static void
2579 xcoff_swap_ldhdr_in (abfd, s, dst)
2580 bfd *abfd;
2581 const PTR s;
2582 struct internal_ldhdr *dst;
2583 {
2584 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2585
2586 dst->l_version = bfd_get_32 (abfd, src->l_version);
2587 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2588 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2589 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2590 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2591 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2592 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2593 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2594 }
2595
2596 /* Swap out the ldhdr structure. */
2597
2598 static void
2599 xcoff_swap_ldhdr_out (abfd, src, d)
2600 bfd *abfd;
2601 const struct internal_ldhdr *src;
2602 PTR d;
2603 {
2604 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2605
2606 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2607 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2608 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2609 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2610 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2611 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2612 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2613 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2614 }
2615
2616 /* Swap in the ldsym structure. */
2617
2618 static void
2619 xcoff_swap_ldsym_in (abfd, s, dst)
2620 bfd *abfd;
2621 const PTR s;
2622 struct internal_ldsym *dst;
2623 {
2624 const struct external_ldsym *src = (const struct external_ldsym *) s;
2625
2626 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2627 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2628 } else {
2629 dst->_l._l_l._l_zeroes = 0;
2630 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2631 }
2632 dst->l_value = bfd_get_32 (abfd, src->l_value);
2633 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2634 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2635 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2636 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2637 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2638 }
2639
2640 /* Swap out the ldsym structure. */
2641
2642 static void
2643 xcoff_swap_ldsym_out (abfd, src, d)
2644 bfd *abfd;
2645 const struct internal_ldsym *src;
2646 PTR d;
2647 {
2648 struct external_ldsym *dst = (struct external_ldsym *) d;
2649
2650 if (src->_l._l_l._l_zeroes != 0)
2651 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2652 else
2653 {
2654 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2655 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2656 dst->_l._l_l._l_offset);
2657 }
2658 bfd_put_32 (abfd, src->l_value, dst->l_value);
2659 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2660 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2661 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2662 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2663 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2664 }
2665
2666 static void
2667 xcoff_swap_reloc_in (abfd, s, d)
2668 bfd *abfd;
2669 PTR s;
2670 PTR d;
2671 {
2672 struct external_reloc *src = (struct external_reloc *) s;
2673 struct internal_reloc *dst = (struct internal_reloc *) d;
2674
2675 memset (dst, 0, sizeof (struct internal_reloc));
2676
2677 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2678 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2679 dst->r_size = bfd_get_8 (abfd, src->r_size);
2680 dst->r_type = bfd_get_8 (abfd, src->r_type);
2681 }
2682
2683 static unsigned int
2684 xcoff_swap_reloc_out (abfd, s, d)
2685 bfd *abfd;
2686 PTR s;
2687 PTR d;
2688 {
2689 struct internal_reloc *src = (struct internal_reloc *) s;
2690 struct external_reloc *dst = (struct external_reloc *) d;
2691
2692 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2693 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2694 bfd_put_8 (abfd, src->r_type, dst->r_type);
2695 bfd_put_8 (abfd, src->r_size, dst->r_size);
2696
2697 return bfd_coff_relsz (abfd);
2698 }
2699
2700 /* Swap in the ldrel structure. */
2701
2702 static void
2703 xcoff_swap_ldrel_in (abfd, s, dst)
2704 bfd *abfd;
2705 const PTR s;
2706 struct internal_ldrel *dst;
2707 {
2708 const struct external_ldrel *src = (const struct external_ldrel *) s;
2709
2710 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2711 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2712 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2713 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2714 }
2715
2716 /* Swap out the ldrel structure. */
2717
2718 static void
2719 xcoff_swap_ldrel_out (abfd, src, d)
2720 bfd *abfd;
2721 const struct internal_ldrel *src;
2722 PTR d;
2723 {
2724 struct external_ldrel *dst = (struct external_ldrel *) d;
2725
2726 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2727 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2728 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2729 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2730 }
2731 \f
2732
2733 boolean
2734 xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
2735 val, addend, relocation, contents)
2736 bfd *input_bfd ATTRIBUTE_UNUSED;
2737 asection *input_section ATTRIBUTE_UNUSED;
2738 bfd *output_bfd ATTRIBUTE_UNUSED;
2739 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2740 struct internal_syment *sym ATTRIBUTE_UNUSED;
2741 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2742 bfd_vma val ATTRIBUTE_UNUSED;
2743 bfd_vma addend ATTRIBUTE_UNUSED;
2744 bfd_vma *relocation ATTRIBUTE_UNUSED;
2745 bfd_byte *contents ATTRIBUTE_UNUSED;
2746 {
2747 return true;
2748 }
2749
2750 boolean
2751 xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
2752 val, addend, relocation, contents)
2753 bfd *input_bfd;
2754 asection *input_section ATTRIBUTE_UNUSED;
2755 bfd *output_bfd ATTRIBUTE_UNUSED;
2756 struct internal_reloc *rel;
2757 struct internal_syment *sym ATTRIBUTE_UNUSED;
2758 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2759 bfd_vma val ATTRIBUTE_UNUSED;
2760 bfd_vma addend ATTRIBUTE_UNUSED;
2761 bfd_vma *relocation ATTRIBUTE_UNUSED;
2762 bfd_byte *contents ATTRIBUTE_UNUSED;
2763 {
2764 (*_bfd_error_handler)
2765 (_("%s: unsupported relocation type 0x%02x"),
2766 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2767 bfd_set_error (bfd_error_bad_value);
2768 return false;
2769 }
2770
2771 boolean
2772 xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
2773 val, addend, relocation, contents)
2774 bfd *input_bfd ATTRIBUTE_UNUSED;
2775 asection *input_section ATTRIBUTE_UNUSED;
2776 bfd *output_bfd ATTRIBUTE_UNUSED;
2777 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2778 struct internal_syment *sym ATTRIBUTE_UNUSED;
2779 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2780 bfd_vma val;
2781 bfd_vma addend;
2782 bfd_vma *relocation;
2783 bfd_byte *contents ATTRIBUTE_UNUSED;
2784 {
2785 *relocation = val + addend;
2786 return true;
2787 }
2788
2789 boolean
2790 xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
2791 val, addend, relocation, contents)
2792 bfd *input_bfd ATTRIBUTE_UNUSED;
2793 asection *input_section ATTRIBUTE_UNUSED;
2794 bfd *output_bfd ATTRIBUTE_UNUSED;
2795 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2796 struct internal_syment *sym ATTRIBUTE_UNUSED;
2797 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2798 bfd_vma val;
2799 bfd_vma addend;
2800 bfd_vma *relocation;
2801 bfd_byte *contents ATTRIBUTE_UNUSED;
2802 {
2803 *relocation = addend - val;
2804 return true;
2805 }
2806
2807 boolean
2808 xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
2809 val, addend, relocation, contents)
2810 bfd *input_bfd ATTRIBUTE_UNUSED;
2811 asection *input_section;
2812 bfd *output_bfd ATTRIBUTE_UNUSED;
2813 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2814 struct internal_syment *sym ATTRIBUTE_UNUSED;
2815 struct reloc_howto_struct *howto;
2816 bfd_vma val;
2817 bfd_vma addend;
2818 bfd_vma *relocation;
2819 bfd_byte *contents ATTRIBUTE_UNUSED;
2820 {
2821 howto->pc_relative = true;
2822
2823 /* A PC relative reloc includes the section address. */
2824 addend += input_section->vma;
2825
2826 *relocation = val + addend;
2827 *relocation -= (input_section->output_section->vma
2828 + input_section->output_offset);
2829 return true;
2830 }
2831
2832 boolean
2833 xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
2834 val, addend, relocation, contents)
2835 bfd *input_bfd;
2836 asection *input_section ATTRIBUTE_UNUSED;
2837 bfd *output_bfd;
2838 struct internal_reloc *rel;
2839 struct internal_syment *sym;
2840 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2841 bfd_vma val;
2842 bfd_vma addend ATTRIBUTE_UNUSED;
2843 bfd_vma *relocation;
2844 bfd_byte *contents ATTRIBUTE_UNUSED;
2845 {
2846 struct xcoff_link_hash_entry *h;
2847
2848 if (0 > rel->r_symndx)
2849 return false;
2850
2851 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2852
2853 if (h != NULL && h->smclas != XMC_TD)
2854 {
2855 if (h->toc_section == NULL)
2856 {
2857 (*_bfd_error_handler)
2858 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2859 bfd_get_filename (input_bfd), rel->r_vaddr,
2860 h->root.root.string);
2861 bfd_set_error (bfd_error_bad_value);
2862 return false;
2863 }
2864
2865 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2866 val = (h->toc_section->output_section->vma
2867 + h->toc_section->output_offset);
2868 }
2869
2870 *relocation = ((val - xcoff_data (output_bfd)->toc)
2871 - (sym->n_value - xcoff_data (input_bfd)->toc));
2872 return true;
2873 }
2874
2875 boolean
2876 xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
2877 val, addend, relocation, contents)
2878 bfd *input_bfd ATTRIBUTE_UNUSED;
2879 asection *input_section ATTRIBUTE_UNUSED;
2880 bfd *output_bfd ATTRIBUTE_UNUSED;
2881 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2882 struct internal_syment *sym ATTRIBUTE_UNUSED;
2883 struct reloc_howto_struct *howto;
2884 bfd_vma val;
2885 bfd_vma addend;
2886 bfd_vma *relocation;
2887 bfd_byte *contents ATTRIBUTE_UNUSED;
2888 {
2889 howto->src_mask &= ~3;
2890 howto->dst_mask = howto->src_mask;
2891
2892 *relocation = val + addend;
2893
2894 return true;
2895 }
2896
2897 static boolean
2898 xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
2899 val, addend, relocation, contents)
2900 bfd *input_bfd;
2901 asection *input_section;
2902 bfd *output_bfd ATTRIBUTE_UNUSED;
2903 struct internal_reloc *rel;
2904 struct internal_syment *sym ATTRIBUTE_UNUSED;
2905 struct reloc_howto_struct *howto;
2906 bfd_vma val;
2907 bfd_vma addend;
2908 bfd_vma *relocation;
2909 bfd_byte *contents;
2910 {
2911 struct xcoff_link_hash_entry *h;
2912
2913 if (0 > rel->r_symndx)
2914 return false;
2915
2916 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2917
2918 /* If we see an R_BR or R_RBR reloc which is jumping to global
2919 linkage code, and it is followed by an appropriate cror nop
2920 instruction, we replace the cror with lwz r2,20(r1). This
2921 restores the TOC after the glink code. Contrariwise, if the
2922 call is followed by a lwz r2,20(r1), but the call is not
2923 going to global linkage code, we can replace the load with a
2924 cror. */
2925 if (NULL != h
2926 && bfd_link_hash_defined == h->root.type
2927 && (rel->r_vaddr - input_section->vma + 8
2928 <= input_section->_cooked_size))
2929 {
2930 bfd_byte *pnext;
2931 unsigned long next;
2932
2933 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2934 next = bfd_get_32 (input_bfd, pnext);
2935
2936 /* The _ptrgl function is magic. It is used by the AIX
2937 compiler to call a function through a pointer. */
2938 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2939 {
2940 if (next == 0x4def7b82 /* cror 15,15,15 */
2941 || next == 0x4ffffb82 /* cror 31,31,31 */
2942 || next == 0x60000000) /* ori r0,r0,0 */
2943 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2944
2945 }
2946 else
2947 {
2948 if (next == 0x80410014) /* lwz r1,20(r1) */
2949 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2950 }
2951 }
2952 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2953 {
2954 /* Normally, this relocation is against a defined symbol. In the
2955 case where this is a partial link and the output section offset
2956 is greater than 2^25, the linker will return an invalid error
2957 message that the relocation has been truncated. Yes it has been
2958 truncated but no it not important. For this case, disable the
2959 overflow checking. */
2960
2961 howto->complain_on_overflow = complain_overflow_dont;
2962 }
2963
2964 howto->pc_relative = true;
2965 howto->src_mask &= ~3;
2966 howto->dst_mask = howto->src_mask;
2967
2968 /* A PC relative reloc includes the section address. */
2969 addend += input_section->vma;
2970
2971 *relocation = val + addend;
2972 *relocation -= (input_section->output_section->vma
2973 + input_section->output_offset);
2974 return true;
2975 }
2976
2977 boolean
2978 xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
2979 val, addend, relocation, contents)
2980 bfd *input_bfd ATTRIBUTE_UNUSED;
2981 asection *input_section;
2982 bfd *output_bfd ATTRIBUTE_UNUSED;
2983 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2984 struct internal_syment *sym ATTRIBUTE_UNUSED;
2985 struct reloc_howto_struct *howto;
2986 bfd_vma val ATTRIBUTE_UNUSED;
2987 bfd_vma addend;
2988 bfd_vma *relocation;
2989 bfd_byte *contents ATTRIBUTE_UNUSED;
2990 {
2991 howto->pc_relative = true;
2992 howto->src_mask &= ~3;
2993 howto->dst_mask = howto->src_mask;
2994
2995 /* A PC relative reloc includes the section address. */
2996 addend += input_section->vma;
2997
2998 *relocation = val + addend;
2999 *relocation -= (input_section->output_section->vma
3000 + input_section->output_offset);
3001 return true;
3002 }
3003
3004 static boolean
3005 xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
3006 bfd *input_bfd ATTRIBUTE_UNUSED;
3007 bfd_vma val ATTRIBUTE_UNUSED;
3008 bfd_vma relocation ATTRIBUTE_UNUSED;
3009 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
3010 {
3011 return false;
3012 }
3013
3014 static boolean
3015 xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
3016 bfd *input_bfd;
3017 bfd_vma val;
3018 bfd_vma relocation;
3019 struct reloc_howto_struct *howto;
3020 {
3021 bfd_vma addrmask, fieldmask, signmask, ss;
3022 bfd_vma a, b, sum;
3023
3024 /* Get the values to be added together. For signed and unsigned
3025 relocations, we assume that all values should be truncated to
3026 the size of an address. For bitfields, all the bits matter.
3027 See also bfd_check_overflow. */
3028 fieldmask = N_ONES (howto->bitsize);
3029 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3030 a = relocation;
3031 b = val & howto->src_mask;
3032
3033 /* Much like unsigned, except no trimming with addrmask. In
3034 addition, the sum overflows if there is a carry out of
3035 the bfd_vma, i.e., the sum is less than either input
3036 operand. */
3037 a >>= howto->rightshift;
3038 b >>= howto->bitpos;
3039
3040 /* Bitfields are sometimes used for signed numbers; for
3041 example, a 13-bit field sometimes represents values in
3042 0..8191 and sometimes represents values in -4096..4095.
3043 If the field is signed and a is -4095 (0x1001) and b is
3044 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3045 0x1fff is 0x3000). It's not clear how to handle this
3046 everywhere, since there is not way to know how many bits
3047 are significant in the relocation, but the original code
3048 assumed that it was fully sign extended, and we will keep
3049 that assumption. */
3050 signmask = (fieldmask >> 1) + 1;
3051
3052 if ((a & ~ fieldmask) != 0)
3053 {
3054 /* Some bits out of the field are set. This might not
3055 be a problem: if this is a signed bitfield, it is OK
3056 iff all the high bits are set, including the sign
3057 bit. We'll try setting all but the most significant
3058 bit in the original relocation value: if this is all
3059 ones, we are OK, assuming a signed bitfield. */
3060 ss = (signmask << howto->rightshift) - 1;
3061 if ((ss | relocation) != ~ (bfd_vma) 0)
3062 return true;
3063 a &= fieldmask;
3064 }
3065
3066 /* We just assume (b & ~ fieldmask) == 0. */
3067
3068 /* We explicitly permit wrap around if this relocation
3069 covers the high bit of an address. The Linux kernel
3070 relies on it, and it is the only way to write assembler
3071 code which can run when loaded at a location 0x80000000
3072 away from the location at which it is linked. */
3073 if (howto->bitsize + howto->rightshift
3074 == bfd_arch_bits_per_address (input_bfd))
3075 return false;
3076
3077 sum = a + b;
3078 if (sum < a || (sum & ~ fieldmask) != 0)
3079 {
3080 /* There was a carry out, or the field overflow. Test
3081 for signed operands again. Here is the overflow test
3082 is as for complain_overflow_signed. */
3083 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3084 return true;
3085 }
3086
3087 return false;
3088 }
3089
3090 static boolean
3091 xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
3092 bfd *input_bfd;
3093 bfd_vma val;
3094 bfd_vma relocation;
3095 struct reloc_howto_struct *howto;
3096 {
3097 bfd_vma addrmask, fieldmask, signmask, ss;
3098 bfd_vma a, b, sum;
3099
3100 /* Get the values to be added together. For signed and unsigned
3101 relocations, we assume that all values should be truncated to
3102 the size of an address. For bitfields, all the bits matter.
3103 See also bfd_check_overflow. */
3104 fieldmask = N_ONES (howto->bitsize);
3105 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3106 a = relocation;
3107 b = val & howto->src_mask;
3108
3109 a = (a & addrmask) >> howto->rightshift;
3110
3111 /* If any sign bits are set, all sign bits must be set.
3112 That is, A must be a valid negative address after
3113 shifting. */
3114 signmask = ~ (fieldmask >> 1);
3115 ss = a & signmask;
3116 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3117 return true;
3118
3119 /* We only need this next bit of code if the sign bit of B
3120 is below the sign bit of A. This would only happen if
3121 SRC_MASK had fewer bits than BITSIZE. Note that if
3122 SRC_MASK has more bits than BITSIZE, we can get into
3123 trouble; we would need to verify that B is in range, as
3124 we do for A above. */
3125 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3126 if ((b & signmask) != 0)
3127 {
3128 /* Set all the bits above the sign bit. */
3129 b -= signmask <<= 1;
3130 }
3131
3132 b = (b & addrmask) >> howto->bitpos;
3133
3134 /* Now we can do the addition. */
3135 sum = a + b;
3136
3137 /* See if the result has the correct sign. Bits above the
3138 sign bit are junk now; ignore them. If the sum is
3139 positive, make sure we did not have all negative inputs;
3140 if the sum is negative, make sure we did not have all
3141 positive inputs. The test below looks only at the sign
3142 bits, and it really just
3143 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3144 */
3145 signmask = (fieldmask >> 1) + 1;
3146 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3147 return true;
3148
3149 return false;
3150 }
3151
3152 static boolean
3153 xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
3154 bfd *input_bfd;
3155 bfd_vma val;
3156 bfd_vma relocation;
3157 struct reloc_howto_struct *howto;
3158 {
3159 bfd_vma addrmask, fieldmask;
3160 bfd_vma a, b, sum;
3161
3162 /* Get the values to be added together. For signed and unsigned
3163 relocations, we assume that all values should be truncated to
3164 the size of an address. For bitfields, all the bits matter.
3165 See also bfd_check_overflow. */
3166 fieldmask = N_ONES (howto->bitsize);
3167 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3168 a = relocation;
3169 b = val & howto->src_mask;
3170
3171 /* Checking for an unsigned overflow is relatively easy:
3172 trim the addresses and add, and trim the result as well.
3173 Overflow is normally indicated when the result does not
3174 fit in the field. However, we also need to consider the
3175 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3176 input is 0x80000000, and bfd_vma is only 32 bits; then we
3177 will get sum == 0, but there is an overflow, since the
3178 inputs did not fit in the field. Instead of doing a
3179 separate test, we can check for this by or-ing in the
3180 operands when testing for the sum overflowing its final
3181 field. */
3182 a = (a & addrmask) >> howto->rightshift;
3183 b = (b & addrmask) >> howto->bitpos;
3184 sum = (a + b) & addrmask;
3185 if ((a | b | sum) & ~ fieldmask)
3186 return true;
3187
3188 return false;
3189 }
3190
3191 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3192 This is currently the only processor which uses XCOFF; I hope that
3193 will never change.
3194
3195 I took the relocation type definitions from two documents:
3196 the PowerPC AIX Version 4 Application Binary Interface, First
3197 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3198 32-Bit Hardware Implementation (June 30, 1994). Differences
3199 between the documents are noted below.
3200
3201 Unsupported r_type's
3202
3203 R_RTB:
3204 R_RRTBI:
3205 R_RRTBA:
3206
3207 These relocs are defined by the PowerPC ABI to be
3208 relative branches which use half of the difference
3209 between the symbol and the program counter. I can't
3210 quite figure out when this is useful. These relocs are
3211 not defined by the PowerOpen ABI.
3212
3213 Supported r_type's
3214
3215 R_POS:
3216 Simple positive relocation.
3217
3218 R_NEG:
3219 Simple negative relocation.
3220
3221 R_REL:
3222 Simple PC relative relocation.
3223
3224 R_TOC:
3225 TOC relative relocation. The value in the instruction in
3226 the input file is the offset from the input file TOC to
3227 the desired location. We want the offset from the final
3228 TOC to the desired location. We have:
3229 isym = iTOC + in
3230 iinsn = in + o
3231 osym = oTOC + on
3232 oinsn = on + o
3233 so we must change insn by on - in.
3234
3235 R_GL:
3236 GL linkage relocation. The value of this relocation
3237 is the address of the entry in the TOC section.
3238
3239 R_TCL:
3240 Local object TOC address. I can't figure out the
3241 difference between this and case R_GL.
3242
3243 R_TRL:
3244 TOC relative relocation. A TOC relative load instruction
3245 which may be changed to a load address instruction.
3246 FIXME: We don't currently implement this optimization.
3247
3248 R_TRLA:
3249 TOC relative relocation. This is a TOC relative load
3250 address instruction which may be changed to a load
3251 instruction. FIXME: I don't know if this is the correct
3252 implementation.
3253
3254 R_BA:
3255 Absolute branch. We don't want to mess with the lower
3256 two bits of the instruction.
3257
3258 R_CAI:
3259 The PowerPC ABI defines this as an absolute call which
3260 may be modified to become a relative call. The PowerOpen
3261 ABI does not define this relocation type.
3262
3263 R_RBA:
3264 Absolute branch which may be modified to become a
3265 relative branch.
3266
3267 R_RBAC:
3268 The PowerPC ABI defines this as an absolute branch to a
3269 fixed address which may be modified to an absolute branch
3270 to a symbol. The PowerOpen ABI does not define this
3271 relocation type.
3272
3273 R_RBRC:
3274 The PowerPC ABI defines this as an absolute branch to a
3275 fixed address which may be modified to a relative branch.
3276 The PowerOpen ABI does not define this relocation type.
3277
3278 R_BR:
3279 Relative branch. We don't want to mess with the lower
3280 two bits of the instruction.
3281
3282 R_CREL:
3283 The PowerPC ABI defines this as a relative call which may
3284 be modified to become an absolute call. The PowerOpen
3285 ABI does not define this relocation type.
3286
3287 R_RBR:
3288 A relative branch which may be modified to become an
3289 absolute branch. FIXME: We don't implement this,
3290 although we should for symbols of storage mapping class
3291 XMC_XO.
3292
3293 R_RL:
3294 The PowerPC AIX ABI describes this as a load which may be
3295 changed to a load address. The PowerOpen ABI says this
3296 is the same as case R_POS.
3297
3298 R_RLA:
3299 The PowerPC AIX ABI describes this as a load address
3300 which may be changed to a load. The PowerOpen ABI says
3301 this is the same as R_POS.
3302 */
3303
3304 boolean
3305 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
3306 input_section, contents, relocs, syms,
3307 sections)
3308 bfd *output_bfd;
3309 struct bfd_link_info *info;
3310 bfd *input_bfd;
3311 asection *input_section;
3312 bfd_byte *contents;
3313 struct internal_reloc *relocs;
3314 struct internal_syment *syms;
3315 asection **sections;
3316 {
3317 struct internal_reloc *rel;
3318 struct internal_reloc *relend;
3319
3320 rel = relocs;
3321 relend = rel + input_section->reloc_count;
3322 for (; rel < relend; rel++)
3323 {
3324 long symndx;
3325 struct xcoff_link_hash_entry *h;
3326 struct internal_syment *sym;
3327 bfd_vma addend;
3328 bfd_vma val;
3329 struct reloc_howto_struct howto;
3330 bfd_vma relocation;
3331 bfd_vma value_to_relocate;
3332 bfd_vma address;
3333 bfd_byte *location;
3334
3335 /* Relocation type R_REF is a special relocation type which is
3336 merely used to prevent garbage collection from occurring for
3337 the csect including the symbol which it references. */
3338 if (rel->r_type == R_REF)
3339 continue;
3340
3341 /* howto */
3342 howto.type = rel->r_type;
3343 howto.rightshift = 0;
3344 howto.bitsize = (rel->r_size & 0x1f) + 1;
3345 howto.size = howto.bitsize > 16 ? 2 : 1;
3346 howto.pc_relative = false;
3347 howto.bitpos = 0;
3348 howto.complain_on_overflow = (rel->r_size & 0x80
3349 ? complain_overflow_signed
3350 : complain_overflow_bitfield);
3351 howto.special_function = NULL;
3352 howto.name = "internal";
3353 howto.partial_inplace = true;
3354 howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
3355 howto.pcrel_offset = false;
3356
3357 /* symbol */
3358 val = 0;
3359 addend = 0;
3360 h = NULL;
3361 sym = NULL;
3362 symndx = rel->r_symndx;
3363
3364 if (-1 != symndx)
3365 {
3366 asection *sec;
3367
3368 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3369 sym = syms + symndx;
3370 addend = - sym->n_value;
3371
3372 if (NULL == h)
3373 {
3374 sec = sections[symndx];
3375 /* Hack to make sure we use the right TOC anchor value
3376 if this reloc is against the TOC anchor. */
3377 if (sec->name[3] == '0'
3378 && strcmp (sec->name, ".tc0") == 0)
3379 val = xcoff_data (output_bfd)->toc;
3380 else
3381 val = (sec->output_section->vma
3382 + sec->output_offset
3383 + sym->n_value
3384 - sec->vma);
3385 }
3386 else
3387 {
3388 if (h->root.type == bfd_link_hash_defined
3389 || h->root.type == bfd_link_hash_defweak)
3390 {
3391 sec = h->root.u.def.section;
3392 val = (h->root.u.def.value
3393 + sec->output_section->vma
3394 + sec->output_offset);
3395 }
3396 else if (h->root.type == bfd_link_hash_common)
3397 {
3398 sec = h->root.u.c.p->section;
3399 val = (sec->output_section->vma
3400 + sec->output_offset);
3401
3402 }
3403 else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT)))
3404 && ! info->relocateable)
3405 {
3406 if (! ((*info->callbacks->undefined_symbol)
3407 (info, h->root.root.string, input_bfd, input_section,
3408 rel->r_vaddr - input_section->vma, true)))
3409 return false;
3410
3411 /* Don't try to process the reloc. It can't help, and
3412 it may generate another error. */
3413 continue;
3414 }
3415 }
3416 }
3417
3418 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3419 || !((*xcoff_calculate_relocation[rel->r_type])
3420 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3421 addend, &relocation, contents)))
3422 return false;
3423
3424 /* address */
3425 address = rel->r_vaddr - input_section->vma;
3426 location = contents + address;
3427
3428 if (address > input_section->_raw_size)
3429 abort ();
3430
3431 /* Get the value we are going to relocate. */
3432 if (1 == howto.size)
3433 value_to_relocate = bfd_get_16 (input_bfd, location);
3434 else
3435 value_to_relocate = bfd_get_32 (input_bfd, location);
3436
3437 /* overflow.
3438
3439 FIXME: We may drop bits during the addition
3440 which we don't check for. We must either check at every single
3441 operation, which would be tedious, or we must do the computations
3442 in a type larger than bfd_vma, which would be inefficient. */
3443
3444 if ((unsigned int) howto.complain_on_overflow
3445 >= XCOFF_MAX_COMPLAIN_OVERFLOW)
3446 abort ();
3447
3448 if (((*xcoff_complain_overflow[howto.complain_on_overflow])
3449 (input_bfd, value_to_relocate, relocation, &howto)))
3450 {
3451 const char *name;
3452 char buf[SYMNMLEN + 1];
3453 char reloc_type_name[10];
3454
3455 if (symndx == -1)
3456 {
3457 name = "*ABS*";
3458 }
3459 else if (h != NULL)
3460 {
3461 name = h->root.root.string;
3462 }
3463 else
3464 {
3465 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3466 if (name == NULL)
3467 name = "UNKNOWN";
3468 }
3469 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3470
3471 if (! ((*info->callbacks->reloc_overflow)
3472 (info, name, reloc_type_name, (bfd_vma) 0, input_bfd,
3473 input_section, rel->r_vaddr - input_section->vma)))
3474 return false;
3475 }
3476
3477 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3478 value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
3479 | (((value_to_relocate & howto.src_mask)
3480 + relocation) & howto.dst_mask));
3481
3482 /* Put the value back in the object file. */
3483 if (1 == howto.size)
3484 bfd_put_16 (input_bfd, value_to_relocate, location);
3485 else
3486 bfd_put_32 (input_bfd, value_to_relocate, location);
3487 }
3488
3489 return true;
3490 }
3491
3492 static boolean
3493 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
3494 bfd *abfd ATTRIBUTE_UNUSED;
3495 struct xcoff_loader_info *ldinfo;
3496 struct internal_ldsym *ldsym;
3497 const char *name;
3498 {
3499 size_t len;
3500 len = strlen (name);
3501
3502 if (len <= SYMNMLEN)
3503 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3504 else
3505 {
3506 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3507 {
3508 bfd_size_type newalc;
3509 bfd_byte *newstrings;
3510
3511 newalc = ldinfo->string_alc * 2;
3512 if (newalc == 0)
3513 newalc = 32;
3514 while (ldinfo->string_size + len + 3 > newalc)
3515 newalc *= 2;
3516
3517 newstrings = ((bfd_byte *)
3518 bfd_realloc ((PTR) ldinfo->strings, newalc));
3519 if (newstrings == NULL)
3520 {
3521 ldinfo->failed = true;
3522 return false;
3523 }
3524 ldinfo->string_alc = newalc;
3525 ldinfo->strings = newstrings;
3526 }
3527
3528 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3529 ldinfo->strings + ldinfo->string_size);
3530 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3531 ldsym->_l._l_l._l_zeroes = 0;
3532 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3533 ldinfo->string_size += len + 3;
3534 }
3535
3536 return true;
3537 }
3538
3539 static boolean
3540 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3541 struct internal_syment *sym,
3542 const char *name)
3543 {
3544 if (strlen (name) <= SYMNMLEN)
3545 {
3546 strncpy (sym->_n._n_name, name, SYMNMLEN);
3547 }
3548 else
3549 {
3550 boolean hash;
3551 bfd_size_type indx;
3552
3553 hash = true;
3554 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3555 hash = false;
3556 indx = _bfd_stringtab_add (strtab, name, hash, false);
3557 if (indx == (bfd_size_type) -1)
3558 return false;
3559 sym->_n._n_n._n_zeroes = 0;
3560 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3561 }
3562 return true;
3563 }
3564
3565 static asection *
3566 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
3567 bfd *abfd;
3568 union internal_auxent *aux;
3569 const char *symbol_name;
3570 {
3571 asection *return_value = NULL;
3572
3573 /* .sv64 = x_smclas == 17
3574 This is an invalid csect for 32 bit apps. */
3575 static const char *names[19] =
3576 {
3577 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3578 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
3579 ".td", NULL, ".sv3264"
3580 };
3581
3582 if ((19 >= aux->x_csect.x_smclas)
3583 && (NULL != names[aux->x_csect.x_smclas]))
3584 {
3585 return_value = bfd_make_section_anyway
3586 (abfd, names[aux->x_csect.x_smclas]);
3587 }
3588 else
3589 {
3590 (*_bfd_error_handler)
3591 (_("%s: symbol `%s' has unrecognized smclas %d"),
3592 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
3593 bfd_set_error (bfd_error_bad_value);
3594 }
3595
3596 return return_value;
3597 }
3598
3599 static boolean
3600 xcoff_is_lineno_count_overflow (abfd, value)
3601 bfd *abfd ATTRIBUTE_UNUSED;
3602 bfd_vma value;
3603 {
3604 if (0xffff <= value)
3605 return true;
3606
3607 return false;
3608 }
3609
3610 static boolean
3611 xcoff_is_reloc_count_overflow (abfd, value)
3612 bfd *abfd ATTRIBUTE_UNUSED;
3613 bfd_vma value;
3614 {
3615 if (0xffff <= value)
3616 return true;
3617
3618 return false;
3619 }
3620
3621 static bfd_vma
3622 xcoff_loader_symbol_offset (abfd, ldhdr)
3623 bfd *abfd;
3624 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
3625 {
3626 return bfd_xcoff_ldhdrsz (abfd);
3627 }
3628
3629 static bfd_vma
3630 xcoff_loader_reloc_offset (abfd, ldhdr)
3631 bfd *abfd;
3632 struct internal_ldhdr *ldhdr;
3633 {
3634 return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
3635 }
3636
3637 static boolean
3638 xcoff_generate_rtinit (abfd, init, fini, rtld)
3639 bfd *abfd;
3640 const char *init;
3641 const char *fini;
3642 boolean rtld;
3643 {
3644 bfd_byte filehdr_ext[FILHSZ];
3645 bfd_byte scnhdr_ext[SCNHSZ];
3646 bfd_byte syment_ext[SYMESZ * 10];
3647 bfd_byte reloc_ext[RELSZ * 3];
3648 bfd_byte *data_buffer;
3649 bfd_size_type data_buffer_size;
3650 bfd_byte *string_table = NULL, *st_tmp = NULL;
3651 bfd_size_type string_table_size;
3652 bfd_vma val;
3653 size_t initsz, finisz;
3654 struct internal_filehdr filehdr;
3655 struct internal_scnhdr scnhdr;
3656 struct internal_syment syment;
3657 union internal_auxent auxent;
3658 struct internal_reloc reloc;
3659
3660 char *data_name = ".data";
3661 char *rtinit_name = "__rtinit";
3662 char *rtld_name = "__rtld";
3663
3664 if (! bfd_xcoff_rtinit_size (abfd))
3665 return false;
3666
3667 initsz = (init == NULL ? 0 : 1 + strlen (init));
3668 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3669
3670 /* file header */
3671 memset (filehdr_ext, 0, FILHSZ);
3672 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3673 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3674 filehdr.f_nscns = 1;
3675 filehdr.f_timdat = 0;
3676 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3677 filehdr.f_symptr = 0; /* set below */
3678 filehdr.f_opthdr = 0;
3679 filehdr.f_flags = 0;
3680
3681 /* section header */
3682 memset (scnhdr_ext, 0, SCNHSZ);
3683 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3684 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3685 scnhdr.s_paddr = 0;
3686 scnhdr.s_vaddr = 0;
3687 scnhdr.s_size = 0; /* set below */
3688 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3689 scnhdr.s_relptr = 0; /* set below */
3690 scnhdr.s_lnnoptr = 0;
3691 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3692 scnhdr.s_nlnno = 0;
3693 scnhdr.s_flags = STYP_DATA;
3694
3695 /* .data
3696 0x0000 0x00000000 : rtl
3697 0x0004 0x00000010 : offset to init, or 0
3698 0x0008 0x00000028 : offset to fini, or 0
3699 0x000C 0x0000000C : size of descriptor
3700 0x0010 0x00000000 : init, needs a reloc
3701 0x0014 0x00000040 : offset to init name
3702 0x0018 0x00000000 : flags, padded to a word
3703 0x001C 0x00000000 : empty init
3704 0x0020 0x00000000 :
3705 0x0024 0x00000000 :
3706 0x0028 0x00000000 : fini, needs a reloc
3707 0x002C 0x00000??? : offset to fini name
3708 0x0030 0x00000000 : flags, padded to a word
3709 0x0034 0x00000000 : empty fini
3710 0x0038 0x00000000 :
3711 0x003C 0x00000000 :
3712 0x0040 init name
3713 0x0040 + initsz fini name */
3714
3715 data_buffer_size = 0x0040 + initsz + finisz;
3716 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
3717 data_buffer = NULL;
3718 data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
3719 if (data_buffer == NULL)
3720 return false;
3721
3722 if (initsz)
3723 {
3724 val = 0x10;
3725 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3726 val = 0x40;
3727 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3728 memcpy (&data_buffer[val], init, initsz);
3729 }
3730
3731 if (finisz)
3732 {
3733 val = 0x28;
3734 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3735 val = 0x40 + initsz;
3736 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3737 memcpy (&data_buffer[val], fini, finisz);
3738 }
3739
3740 val = 0x0C;
3741 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3742
3743 scnhdr.s_size = data_buffer_size;
3744
3745 /* string table */
3746 string_table_size = 0;
3747 if (initsz > 9)
3748 string_table_size += initsz;
3749 if (finisz > 9)
3750 string_table_size += finisz;
3751 if (string_table_size)
3752 {
3753 string_table_size += 4;
3754 string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
3755 if (string_table == NULL)
3756 return false;
3757
3758 val = string_table_size;
3759 bfd_h_put_32 (abfd, val, &string_table[0]);
3760 st_tmp = string_table + 4;
3761 }
3762
3763 /* symbols
3764 0. .data csect
3765 2. __rtinit
3766 4. init function
3767 6. fini function
3768 8. __rtld */
3769 memset (syment_ext, 0, 10 * SYMESZ);
3770 memset (reloc_ext, 0, 3 * RELSZ);
3771
3772 /* .data csect */
3773 memset (&syment, 0, sizeof (struct internal_syment));
3774 memset (&auxent, 0, sizeof (union internal_auxent));
3775 memcpy (syment._n._n_name, data_name, strlen (data_name));
3776 syment.n_scnum = 1;
3777 syment.n_sclass = C_HIDEXT;
3778 syment.n_numaux = 1;
3779 auxent.x_csect.x_scnlen.l = data_buffer_size;
3780 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3781 auxent.x_csect.x_smclas = XMC_RW;
3782 bfd_coff_swap_sym_out (abfd, &syment,
3783 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3784 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3785 syment.n_numaux,
3786 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3787 filehdr.f_nsyms += 2;
3788
3789 /* __rtinit */
3790 memset (&syment, 0, sizeof (struct internal_syment));
3791 memset (&auxent, 0, sizeof (union internal_auxent));
3792 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3793 syment.n_scnum = 1;
3794 syment.n_sclass = C_EXT;
3795 syment.n_numaux = 1;
3796 auxent.x_csect.x_smtyp = XTY_LD;
3797 auxent.x_csect.x_smclas = XMC_RW;
3798 bfd_coff_swap_sym_out (abfd, &syment,
3799 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3800 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3801 syment.n_numaux,
3802 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3803 filehdr.f_nsyms += 2;
3804
3805 /* init */
3806 if (initsz)
3807 {
3808 memset (&syment, 0, sizeof (struct internal_syment));
3809 memset (&auxent, 0, sizeof (union internal_auxent));
3810
3811 if (initsz > 9)
3812 {
3813 syment._n._n_n._n_offset = st_tmp - string_table;
3814 memcpy (st_tmp, init, initsz);
3815 st_tmp += initsz;
3816 }
3817 else
3818 memcpy (syment._n._n_name, init, initsz - 1);
3819
3820 syment.n_sclass = C_EXT;
3821 syment.n_numaux = 1;
3822 bfd_coff_swap_sym_out (abfd, &syment,
3823 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3824 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3825 syment.n_numaux,
3826 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3827
3828 /* reloc */
3829 memset (&reloc, 0, sizeof (struct internal_reloc));
3830 reloc.r_vaddr = 0x0010;
3831 reloc.r_symndx = filehdr.f_nsyms;
3832 reloc.r_type = R_POS;
3833 reloc.r_size = 31;
3834 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3835
3836 filehdr.f_nsyms += 2;
3837 scnhdr.s_nreloc += 1;
3838 }
3839
3840 /* fini */
3841 if (finisz)
3842 {
3843 memset (&syment, 0, sizeof (struct internal_syment));
3844 memset (&auxent, 0, sizeof (union internal_auxent));
3845
3846 if (finisz > 9)
3847 {
3848 syment._n._n_n._n_offset = st_tmp - string_table;
3849 memcpy (st_tmp, fini, finisz);
3850 st_tmp += finisz;
3851 }
3852 else
3853 memcpy (syment._n._n_name, fini, finisz - 1);
3854
3855 syment.n_sclass = C_EXT;
3856 syment.n_numaux = 1;
3857 bfd_coff_swap_sym_out (abfd, &syment,
3858 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3859 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3860 syment.n_numaux,
3861 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3862
3863 /* reloc */
3864 memset (&reloc, 0, sizeof (struct internal_reloc));
3865 reloc.r_vaddr = 0x0028;
3866 reloc.r_symndx = filehdr.f_nsyms;
3867 reloc.r_type = R_POS;
3868 reloc.r_size = 31;
3869 bfd_coff_swap_reloc_out (abfd, &reloc,
3870 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3871
3872 filehdr.f_nsyms += 2;
3873 scnhdr.s_nreloc += 1;
3874 }
3875
3876 if (rtld)
3877 {
3878 memset (&syment, 0, sizeof (struct internal_syment));
3879 memset (&auxent, 0, sizeof (union internal_auxent));
3880 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3881 syment.n_sclass = C_EXT;
3882 syment.n_numaux = 1;
3883 bfd_coff_swap_sym_out (abfd, &syment,
3884 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3885 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3886 syment.n_numaux,
3887 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3888
3889 /* reloc */
3890 memset (&reloc, 0, sizeof (struct internal_reloc));
3891 reloc.r_vaddr = 0x0000;
3892 reloc.r_symndx = filehdr.f_nsyms;
3893 reloc.r_type = R_POS;
3894 reloc.r_size = 31;
3895 bfd_coff_swap_reloc_out (abfd, &reloc,
3896 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3897
3898 filehdr.f_nsyms += 2;
3899 scnhdr.s_nreloc += 1;
3900 }
3901
3902 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3903 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3904
3905 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3906 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3907 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3908 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3909 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3910 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3911 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3912 bfd_bwrite (string_table, string_table_size, abfd);
3913
3914 free (data_buffer);
3915 data_buffer = NULL;
3916
3917 return true;
3918 }
3919
3920
3921 static reloc_howto_type xcoff_dynamic_reloc =
3922 HOWTO (0, /* type */
3923 0, /* rightshift */
3924 2, /* size (0 = byte, 1 = short, 2 = long) */
3925 32, /* bitsize */
3926 false, /* pc_relative */
3927 0, /* bitpos */
3928 complain_overflow_bitfield, /* complain_on_overflow */
3929 0, /* special_function */
3930 "R_POS", /* name */
3931 true, /* partial_inplace */
3932 0xffffffff, /* src_mask */
3933 0xffffffff, /* dst_mask */
3934 false); /* pcrel_offset */
3935
3936 /* glink
3937
3938 The first word of global linkage code must be modified by filling in
3939 the correct TOC offset. */
3940
3941 static unsigned long xcoff_glink_code[9] =
3942 {
3943 0x81820000, /* lwz r12,0(r2) */
3944 0x90410014, /* stw r2,20(r1) */
3945 0x800c0000, /* lwz r0,0(r12) */
3946 0x804c0004, /* lwz r2,4(r12) */
3947 0x7c0903a6, /* mtctr r0 */
3948 0x4e800420, /* bctr */
3949 0x00000000, /* start of traceback table */
3950 0x000c8000, /* traceback table */
3951 0x00000000, /* traceback table */
3952 };
3953
3954
3955 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
3956 {
3957 { /* COFF backend, defined in libcoff.h. */
3958 _bfd_xcoff_swap_aux_in,
3959 _bfd_xcoff_swap_sym_in,
3960 coff_swap_lineno_in,
3961 _bfd_xcoff_swap_aux_out,
3962 _bfd_xcoff_swap_sym_out,
3963 coff_swap_lineno_out,
3964 xcoff_swap_reloc_out,
3965 coff_swap_filehdr_out,
3966 coff_swap_aouthdr_out,
3967 coff_swap_scnhdr_out,
3968 FILHSZ,
3969 AOUTSZ,
3970 SCNHSZ,
3971 SYMESZ,
3972 AUXESZ,
3973 RELSZ,
3974 LINESZ,
3975 FILNMLEN,
3976 true, /* _bfd_coff_long_filenames */
3977 false, /* _bfd_coff_long_section_names */
3978 3, /* _bfd_coff_default_section_alignment_power */
3979 false, /* _bfd_coff_force_symnames_in_strings */
3980 2, /* _bfd_coff_debug_string_prefix_length */
3981 coff_swap_filehdr_in,
3982 coff_swap_aouthdr_in,
3983 coff_swap_scnhdr_in,
3984 xcoff_swap_reloc_in,
3985 coff_bad_format_hook,
3986 coff_set_arch_mach_hook,
3987 coff_mkobject_hook,
3988 styp_to_sec_flags,
3989 coff_set_alignment_hook,
3990 coff_slurp_symbol_table,
3991 symname_in_debug_hook,
3992 coff_pointerize_aux_hook,
3993 coff_print_aux,
3994 dummy_reloc16_extra_cases,
3995 dummy_reloc16_estimate,
3996 NULL, /* bfd_coff_sym_is_global */
3997 coff_compute_section_file_positions,
3998 NULL, /* _bfd_coff_start_final_link */
3999 xcoff_ppc_relocate_section,
4000 coff_rtype_to_howto,
4001 NULL, /* _bfd_coff_adjust_symndx */
4002 _bfd_generic_link_add_one_symbol,
4003 coff_link_output_has_begun,
4004 coff_final_link_postscript
4005 },
4006
4007 0x01DF, /* magic number */
4008 bfd_arch_rs6000,
4009 bfd_mach_rs6k,
4010
4011 /* Function pointers to xcoff specific swap routines. */
4012 xcoff_swap_ldhdr_in,
4013 xcoff_swap_ldhdr_out,
4014 xcoff_swap_ldsym_in,
4015 xcoff_swap_ldsym_out,
4016 xcoff_swap_ldrel_in,
4017 xcoff_swap_ldrel_out,
4018
4019 /* Sizes. */
4020 LDHDRSZ,
4021 LDSYMSZ,
4022 LDRELSZ,
4023 12, /* _xcoff_function_descriptor_size */
4024 SMALL_AOUTSZ,
4025
4026 /* Versions. */
4027 1, /* _xcoff_ldhdr_version */
4028
4029 _bfd_xcoff_put_symbol_name,
4030 _bfd_xcoff_put_ldsymbol_name,
4031 &xcoff_dynamic_reloc,
4032 xcoff_create_csect_from_smclas,
4033
4034 /* Lineno and reloc count overflow. */
4035 xcoff_is_lineno_count_overflow,
4036 xcoff_is_reloc_count_overflow,
4037
4038 xcoff_loader_symbol_offset,
4039 xcoff_loader_reloc_offset,
4040
4041 /* glink. */
4042 &xcoff_glink_code[0],
4043 36, /* _xcoff_glink_size */
4044
4045 /* rtinit */
4046 64, /* _xcoff_rtinit_size */
4047 xcoff_generate_rtinit,
4048 };
4049
4050 /* The transfer vector that leads the outside world to all of the above. */
4051 const bfd_target rs6000coff_vec =
4052 {
4053 "aixcoff-rs6000",
4054 bfd_target_xcoff_flavour,
4055 BFD_ENDIAN_BIG, /* data byte order is big */
4056 BFD_ENDIAN_BIG, /* header byte order is big */
4057
4058 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4059 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4060
4061 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
4062 0, /* leading char */
4063 '/', /* ar_pad_char */
4064 15, /* ar_max_namelen */
4065
4066 /* data */
4067 bfd_getb64,
4068 bfd_getb_signed_64,
4069 bfd_putb64,
4070 bfd_getb32,
4071 bfd_getb_signed_32,
4072 bfd_putb32,
4073 bfd_getb16,
4074 bfd_getb_signed_16,
4075 bfd_putb16,
4076
4077 /* hdrs */
4078 bfd_getb64,
4079 bfd_getb_signed_64,
4080 bfd_putb64,
4081 bfd_getb32,
4082 bfd_getb_signed_32,
4083 bfd_putb32,
4084 bfd_getb16,
4085 bfd_getb_signed_16,
4086 bfd_putb16,
4087
4088 { /* bfd_check_format */
4089 _bfd_dummy_target,
4090 coff_object_p,
4091 _bfd_xcoff_archive_p,
4092 CORE_FILE_P
4093 },
4094
4095 { /* bfd_set_format */
4096 bfd_false,
4097 coff_mkobject,
4098 _bfd_generic_mkarchive,
4099 bfd_false
4100 },
4101
4102 {/* bfd_write_contents */
4103 bfd_false,
4104 coff_write_object_contents,
4105 _bfd_xcoff_write_archive_contents,
4106 bfd_false
4107 },
4108
4109 /* Generic */
4110 bfd_true,
4111 bfd_true,
4112 coff_new_section_hook,
4113 _bfd_generic_get_section_contents,
4114 _bfd_generic_get_section_contents_in_window,
4115
4116 /* Copy */
4117 _bfd_xcoff_copy_private_bfd_data,
4118 ((boolean (*) (bfd *, bfd *)) bfd_true),
4119 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4120 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4121 ((boolean (*) (bfd *, flagword)) bfd_true),
4122 ((boolean (*) (bfd *, void * )) bfd_true),
4123
4124 /* Core */
4125 coff_core_file_failing_command,
4126 coff_core_file_failing_signal,
4127 coff_core_file_matches_executable_p,
4128
4129 /* Archive */
4130 _bfd_xcoff_slurp_armap,
4131 bfd_false,
4132 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4133 bfd_dont_truncate_arname,
4134 _bfd_xcoff_write_armap,
4135 _bfd_xcoff_read_ar_hdr,
4136 _bfd_xcoff_openr_next_archived_file,
4137 _bfd_generic_get_elt_at_index,
4138 _bfd_xcoff_stat_arch_elt,
4139 bfd_true,
4140
4141 /* Symbols */
4142 coff_get_symtab_upper_bound,
4143 coff_get_symtab,
4144 coff_make_empty_symbol,
4145 coff_print_symbol,
4146 coff_get_symbol_info,
4147 _bfd_xcoff_is_local_label_name,
4148 coff_get_lineno,
4149 coff_find_nearest_line,
4150 coff_bfd_make_debug_symbol,
4151 _bfd_generic_read_minisymbols,
4152 _bfd_generic_minisymbol_to_symbol,
4153
4154 /* Reloc */
4155 coff_get_reloc_upper_bound,
4156 coff_canonicalize_reloc,
4157 _bfd_xcoff_reloc_type_lookup,
4158
4159 /* Write */
4160 coff_set_arch_mach,
4161 coff_set_section_contents,
4162
4163 /* Link */
4164 _bfd_xcoff_sizeof_headers,
4165 bfd_generic_get_relocated_section_contents,
4166 bfd_generic_relax_section,
4167 _bfd_xcoff_bfd_link_hash_table_create,
4168 _bfd_generic_link_hash_table_free,
4169 _bfd_xcoff_bfd_link_add_symbols,
4170 _bfd_generic_link_just_syms,
4171 _bfd_xcoff_bfd_final_link,
4172 _bfd_generic_link_split_section,
4173 bfd_generic_gc_sections,
4174 bfd_generic_merge_sections,
4175 bfd_generic_discard_group,
4176
4177 /* Dynamic */
4178 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4179 _bfd_xcoff_canonicalize_dynamic_symtab,
4180 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4181 _bfd_xcoff_canonicalize_dynamic_reloc,
4182
4183 /* Opposite endian version, none exists */
4184 NULL,
4185
4186 (void *) &bfd_xcoff_backend_data,
4187 };
4188
4189 /* xcoff-powermac target
4190 Old target.
4191 Only difference between this target and the rs6000 target is the
4192 the default architecture and machine type used in coffcode.h
4193
4194 PowerPC Macs use the same magic numbers as RS/6000
4195 (because that's how they were bootstrapped originally),
4196 but they are always PowerPC architecture. */
4197 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4198 {
4199 { /* COFF backend, defined in libcoff.h. */
4200 _bfd_xcoff_swap_aux_in,
4201 _bfd_xcoff_swap_sym_in,
4202 coff_swap_lineno_in,
4203 _bfd_xcoff_swap_aux_out,
4204 _bfd_xcoff_swap_sym_out,
4205 coff_swap_lineno_out,
4206 xcoff_swap_reloc_out,
4207 coff_swap_filehdr_out,
4208 coff_swap_aouthdr_out,
4209 coff_swap_scnhdr_out,
4210 FILHSZ,
4211 AOUTSZ,
4212 SCNHSZ,
4213 SYMESZ,
4214 AUXESZ,
4215 RELSZ,
4216 LINESZ,
4217 FILNMLEN,
4218 true, /* _bfd_coff_long_filenames */
4219 false, /* _bfd_coff_long_section_names */
4220 3, /* _bfd_coff_default_section_alignment_power */
4221 false, /* _bfd_coff_force_symnames_in_strings */
4222 2, /* _bfd_coff_debug_string_prefix_length */
4223 coff_swap_filehdr_in,
4224 coff_swap_aouthdr_in,
4225 coff_swap_scnhdr_in,
4226 xcoff_swap_reloc_in,
4227 coff_bad_format_hook,
4228 coff_set_arch_mach_hook,
4229 coff_mkobject_hook,
4230 styp_to_sec_flags,
4231 coff_set_alignment_hook,
4232 coff_slurp_symbol_table,
4233 symname_in_debug_hook,
4234 coff_pointerize_aux_hook,
4235 coff_print_aux,
4236 dummy_reloc16_extra_cases,
4237 dummy_reloc16_estimate,
4238 NULL, /* bfd_coff_sym_is_global */
4239 coff_compute_section_file_positions,
4240 NULL, /* _bfd_coff_start_final_link */
4241 xcoff_ppc_relocate_section,
4242 coff_rtype_to_howto,
4243 NULL, /* _bfd_coff_adjust_symndx */
4244 _bfd_generic_link_add_one_symbol,
4245 coff_link_output_has_begun,
4246 coff_final_link_postscript
4247 },
4248
4249 0x01DF, /* magic number */
4250 bfd_arch_powerpc,
4251 bfd_mach_ppc,
4252
4253 /* Function pointers to xcoff specific swap routines. */
4254 xcoff_swap_ldhdr_in,
4255 xcoff_swap_ldhdr_out,
4256 xcoff_swap_ldsym_in,
4257 xcoff_swap_ldsym_out,
4258 xcoff_swap_ldrel_in,
4259 xcoff_swap_ldrel_out,
4260
4261 /* Sizes. */
4262 LDHDRSZ,
4263 LDSYMSZ,
4264 LDRELSZ,
4265 12, /* _xcoff_function_descriptor_size */
4266 SMALL_AOUTSZ,
4267
4268 /* Versions. */
4269 1, /* _xcoff_ldhdr_version */
4270
4271 _bfd_xcoff_put_symbol_name,
4272 _bfd_xcoff_put_ldsymbol_name,
4273 &xcoff_dynamic_reloc,
4274 xcoff_create_csect_from_smclas,
4275
4276 /* Lineno and reloc count overflow. */
4277 xcoff_is_lineno_count_overflow,
4278 xcoff_is_reloc_count_overflow,
4279
4280 xcoff_loader_symbol_offset,
4281 xcoff_loader_reloc_offset,
4282
4283 /* glink. */
4284 &xcoff_glink_code[0],
4285 36, /* _xcoff_glink_size */
4286
4287 /* rtinit */
4288 0, /* _xcoff_rtinit_size */
4289 xcoff_generate_rtinit,
4290 };
4291
4292 /* The transfer vector that leads the outside world to all of the above. */
4293 const bfd_target pmac_xcoff_vec =
4294 {
4295 "xcoff-powermac",
4296 bfd_target_xcoff_flavour,
4297 BFD_ENDIAN_BIG, /* data byte order is big */
4298 BFD_ENDIAN_BIG, /* header byte order is big */
4299
4300 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4301 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4302
4303 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
4304 0, /* leading char */
4305 '/', /* ar_pad_char */
4306 15, /* ar_max_namelen */
4307
4308 /* data */
4309 bfd_getb64,
4310 bfd_getb_signed_64,
4311 bfd_putb64,
4312 bfd_getb32,
4313 bfd_getb_signed_32,
4314 bfd_putb32,
4315 bfd_getb16,
4316 bfd_getb_signed_16,
4317 bfd_putb16,
4318
4319 /* hdrs */
4320 bfd_getb64,
4321 bfd_getb_signed_64,
4322 bfd_putb64,
4323 bfd_getb32,
4324 bfd_getb_signed_32,
4325 bfd_putb32,
4326 bfd_getb16,
4327 bfd_getb_signed_16,
4328 bfd_putb16,
4329
4330 { /* bfd_check_format */
4331 _bfd_dummy_target,
4332 coff_object_p,
4333 _bfd_xcoff_archive_p,
4334 CORE_FILE_P
4335 },
4336
4337 { /* bfd_set_format */
4338 bfd_false,
4339 coff_mkobject,
4340 _bfd_generic_mkarchive,
4341 bfd_false
4342 },
4343
4344 {/* bfd_write_contents */
4345 bfd_false,
4346 coff_write_object_contents,
4347 _bfd_xcoff_write_archive_contents,
4348 bfd_false
4349 },
4350
4351 /* Generic */
4352 bfd_true,
4353 bfd_true,
4354 coff_new_section_hook,
4355 _bfd_generic_get_section_contents,
4356 _bfd_generic_get_section_contents_in_window,
4357
4358 /* Copy */
4359 _bfd_xcoff_copy_private_bfd_data,
4360 ((boolean (*) (bfd *, bfd *)) bfd_true),
4361 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4362 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4363 ((boolean (*) (bfd *, flagword)) bfd_true),
4364 ((boolean (*) (bfd *, void * )) bfd_true),
4365
4366 /* Core */
4367 coff_core_file_failing_command,
4368 coff_core_file_failing_signal,
4369 coff_core_file_matches_executable_p,
4370
4371 /* Archive */
4372 _bfd_xcoff_slurp_armap,
4373 bfd_false,
4374 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4375 bfd_dont_truncate_arname,
4376 _bfd_xcoff_write_armap,
4377 _bfd_xcoff_read_ar_hdr,
4378 _bfd_xcoff_openr_next_archived_file,
4379 _bfd_generic_get_elt_at_index,
4380 _bfd_xcoff_stat_arch_elt,
4381 bfd_true,
4382
4383 /* Symbols */
4384 coff_get_symtab_upper_bound,
4385 coff_get_symtab,
4386 coff_make_empty_symbol,
4387 coff_print_symbol,
4388 coff_get_symbol_info,
4389 _bfd_xcoff_is_local_label_name,
4390 coff_get_lineno,
4391 coff_find_nearest_line,
4392 coff_bfd_make_debug_symbol,
4393 _bfd_generic_read_minisymbols,
4394 _bfd_generic_minisymbol_to_symbol,
4395
4396 /* Reloc */
4397 coff_get_reloc_upper_bound,
4398 coff_canonicalize_reloc,
4399 _bfd_xcoff_reloc_type_lookup,
4400
4401 /* Write */
4402 coff_set_arch_mach,
4403 coff_set_section_contents,
4404
4405 /* Link */
4406 _bfd_xcoff_sizeof_headers,
4407 bfd_generic_get_relocated_section_contents,
4408 bfd_generic_relax_section,
4409 _bfd_xcoff_bfd_link_hash_table_create,
4410 _bfd_generic_link_hash_table_free,
4411 _bfd_xcoff_bfd_link_add_symbols,
4412 _bfd_generic_link_just_syms,
4413 _bfd_xcoff_bfd_final_link,
4414 _bfd_generic_link_split_section,
4415 bfd_generic_gc_sections,
4416 bfd_generic_merge_sections,
4417 bfd_generic_discard_group,
4418
4419 /* Dynamic */
4420 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4421 _bfd_xcoff_canonicalize_dynamic_symtab,
4422 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4423 _bfd_xcoff_canonicalize_dynamic_reloc,
4424
4425 /* Opposite endian version, none exists */
4426 NULL,
4427
4428 (void *) &bfd_pmac_xcoff_backend_data,
4429 };