XCOFF64 fixes. For setting arch/mach and for R_BR relocations.
[deliverable/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 (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 (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 /* xcoff_data (abfd)->text_align_power = 5; */
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 ox->text_align_power = ix->text_align_power;
282 ox->data_align_power = ix->data_align_power;
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 2, /* 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 2, /* 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 0x3fffffc, /* src_mask */
699 0x3fffffc, /* 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 0x3fffffc, /* src_mask */
716 0x3fffffc, /* dst_mask */
717 false), /* pcrel_offset */
718
719 EMPTY_HOWTO (0xb),
720
721 /* Indirect load. */
722 HOWTO (R_RL, /* type */
723 0, /* rightshift */
724 2, /* 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 2, /* 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_bitfield, /* 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 2, /* 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 2, /* 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 2, /* 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 2, /* 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 0xffff, /* src_mask */
873 0xffff, /* 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 0xffff, /* src_mask */
888 0xffff, /* 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 0xffff, /* src_mask */
903 0xffff, /* dst_mask */
904 false), /* pcrel_offset */
905
906 /* Modifiable branch absolute. */
907 HOWTO (R_RBRC, /* type */
908 0, /* rightshift */
909 2, /* 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 };
952
953 void
954 xcoff_rtype2howto (relent, internal)
955 arelent *relent;
956 struct internal_reloc *internal;
957 {
958 if (internal->r_type > R_RBRC)
959 abort ();
960
961 /* Default howto layout works most of the time */
962 relent->howto = &xcoff_howto_table[internal->r_type];
963
964 /* Special case some 16 bit reoloc */
965 if (15 == (internal->r_size & 0x1f))
966 {
967 if (R_BA == internal->r_type)
968 relent->howto = &xcoff_howto_table[0x1c];
969 else if (R_RBR == internal->r_type)
970 relent->howto = &xcoff_howto_table[0x1d];
971 }
972
973 /* The r_size field of an XCOFF reloc encodes the bitsize of the
974 relocation, as well as indicating whether it is signed or not.
975 Doublecheck that the relocation information gathered from the
976 type matches this information. The bitsize is not significant
977 for R_REF relocs. */
978 if (relent->howto->dst_mask != 0
979 && (relent->howto->bitsize
980 != ((unsigned int) internal->r_size & 0x1f) + 1))
981 abort ();
982
983 /* Put a meaningful value in addend */
984 relent->addend = (internal->r_size & 0x80) ? - internal->r_vaddr
985 : internal->r_vaddr;
986 }
987
988 reloc_howto_type *
989 _bfd_xcoff_reloc_type_lookup (abfd, code)
990 bfd *abfd ATTRIBUTE_UNUSED;
991 bfd_reloc_code_real_type code;
992 {
993 switch (code)
994 {
995 case BFD_RELOC_PPC_B26:
996 return &xcoff_howto_table[0xa];
997 case BFD_RELOC_PPC_BA16:
998 return &xcoff_howto_table[0x1c];
999 case BFD_RELOC_PPC_BA26:
1000 return &xcoff_howto_table[8];
1001 case BFD_RELOC_PPC_TOC16:
1002 return &xcoff_howto_table[3];
1003 case BFD_RELOC_32:
1004 case BFD_RELOC_CTOR:
1005 return &xcoff_howto_table[0];
1006 default:
1007 return NULL;
1008 }
1009 }
1010
1011 \f
1012 /* XCOFF archive support. The original version of this code was by
1013 Damon A. Permezel. It was enhanced to permit cross support, and
1014 writing archive files, by Ian Lance Taylor, Cygnus Support.
1015
1016 XCOFF uses its own archive format. Everything is hooked together
1017 with file offset links, so it is possible to rapidly update an
1018 archive in place. Of course, we don't do that. An XCOFF archive
1019 has a real file header, not just an ARMAG string. The structure of
1020 the file header and of each archive header appear below.
1021
1022 An XCOFF archive also has a member table, which is a list of
1023 elements in the archive (you can get that by looking through the
1024 linked list, but you have to read a lot more of the file). The
1025 member table has a normal archive header with an empty name. It is
1026 normally (and perhaps must be) the second to last entry in the
1027 archive. The member table data is almost printable ASCII. It
1028 starts with a 12 character decimal string which is the number of
1029 entries in the table. For each entry it has a 12 character decimal
1030 string which is the offset in the archive of that member. These
1031 entries are followed by a series of null terminated strings which
1032 are the member names for each entry.
1033
1034 Finally, an XCOFF archive has a global symbol table, which is what
1035 we call the armap. The global symbol table has a normal archive
1036 header with an empty name. It is normally (and perhaps must be)
1037 the last entry in the archive. The contents start with a four byte
1038 binary number which is the number of entries. This is followed by
1039 a that many four byte binary numbers; each is the file offset of an
1040 entry in the archive. These numbers are followed by a series of
1041 null terminated strings, which are symbol names.
1042
1043 AIX 4.3 introduced a new archive format which can handle larger
1044 files and also 32- and 64-bit objects in the same archive. The
1045 things said above remain true except that there is now more than
1046 one global symbol table. The one is used to index 32-bit objects,
1047 the other for 64-bit objects.
1048
1049 The new archives (recognizable by the new ARMAG string) has larger
1050 field lengths so that we cannot really share any code. Also we have
1051 to take care that we are not generating the new form of archives
1052 on AIX 4.2 or earlier systems. */
1053
1054 /* XCOFF archives use this as a magic string. Note that both strings
1055 have the same length. */
1056
1057 /* Set the magic for archive. */
1058
1059 boolean
1060 bfd_xcoff_ar_archive_set_magic (abfd, magic)
1061 bfd *abfd ATTRIBUTE_UNUSED;
1062 char *magic ATTRIBUTE_UNUSED;
1063 {
1064 /* Not supported yet. */
1065 return false;
1066 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1067 }
1068
1069 /* Read in the armap of an XCOFF archive. */
1070
1071 boolean
1072 _bfd_xcoff_slurp_armap (abfd)
1073 bfd *abfd;
1074 {
1075 file_ptr off;
1076 size_t namlen;
1077 bfd_size_type sz;
1078 bfd_byte *contents, *cend;
1079 bfd_vma c, i;
1080 carsym *arsym;
1081 bfd_byte *p;
1082
1083 if (xcoff_ardata (abfd) == NULL)
1084 {
1085 bfd_has_map (abfd) = false;
1086 return true;
1087 }
1088
1089 if (! xcoff_big_format_p (abfd))
1090 {
1091 /* This is for the old format. */
1092 struct xcoff_ar_hdr hdr;
1093
1094 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1095 if (off == 0)
1096 {
1097 bfd_has_map (abfd) = false;
1098 return true;
1099 }
1100
1101 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1102 return false;
1103
1104 /* The symbol table starts with a normal archive header. */
1105 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1106 != SIZEOF_AR_HDR)
1107 return false;
1108
1109 /* Skip the name (normally empty). */
1110 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1111 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1112 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1113 return false;
1114
1115 sz = strtol (hdr.size, (char **) NULL, 10);
1116
1117 /* Read in the entire symbol table. */
1118 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1119 if (contents == NULL)
1120 return false;
1121 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1122 return false;
1123
1124 /* The symbol table starts with a four byte count. */
1125 c = H_GET_32 (abfd, contents);
1126
1127 if (c * 4 >= sz)
1128 {
1129 bfd_set_error (bfd_error_bad_value);
1130 return false;
1131 }
1132
1133 bfd_ardata (abfd)->symdefs =
1134 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1135 if (bfd_ardata (abfd)->symdefs == NULL)
1136 return false;
1137
1138 /* After the count comes a list of four byte file offsets. */
1139 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1140 i < c;
1141 ++i, ++arsym, p += 4)
1142 arsym->file_offset = H_GET_32 (abfd, p);
1143 }
1144 else
1145 {
1146 /* This is for the new format. */
1147 struct xcoff_ar_hdr_big hdr;
1148
1149 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1150 if (off == 0)
1151 {
1152 bfd_has_map (abfd) = false;
1153 return true;
1154 }
1155
1156 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1157 return false;
1158
1159 /* The symbol table starts with a normal archive header. */
1160 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1161 != SIZEOF_AR_HDR_BIG)
1162 return false;
1163
1164 /* Skip the name (normally empty). */
1165 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1166 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1167 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1168 return false;
1169
1170 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1171 machines) since the field width is 20 and there numbers with more
1172 than 32 bits can be represented. */
1173 sz = strtol (hdr.size, (char **) NULL, 10);
1174
1175 /* Read in the entire symbol table. */
1176 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1177 if (contents == NULL)
1178 return false;
1179 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1180 return false;
1181
1182 /* The symbol table starts with an eight byte count. */
1183 c = H_GET_64 (abfd, contents);
1184
1185 if (c * 8 >= sz)
1186 {
1187 bfd_set_error (bfd_error_bad_value);
1188 return false;
1189 }
1190
1191 bfd_ardata (abfd)->symdefs =
1192 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1193 if (bfd_ardata (abfd)->symdefs == NULL)
1194 return false;
1195
1196 /* After the count comes a list of eight byte file offsets. */
1197 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1198 i < c;
1199 ++i, ++arsym, p += 8)
1200 arsym->file_offset = H_GET_64 (abfd, p);
1201 }
1202
1203 /* After the file offsets come null terminated symbol names. */
1204 cend = contents + sz;
1205 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1206 i < c;
1207 ++i, ++arsym, p += strlen ((char *) p) + 1)
1208 {
1209 if (p >= cend)
1210 {
1211 bfd_set_error (bfd_error_bad_value);
1212 return false;
1213 }
1214 arsym->name = (char *) p;
1215 }
1216
1217 bfd_ardata (abfd)->symdef_count = c;
1218 bfd_has_map (abfd) = true;
1219
1220 return true;
1221 }
1222
1223 /* See if this is an XCOFF archive. */
1224
1225 const bfd_target *
1226 _bfd_xcoff_archive_p (abfd)
1227 bfd *abfd;
1228 {
1229 char magic[SXCOFFARMAG];
1230 bfd_size_type amt;
1231
1232 if (bfd_bread ((PTR) magic, (bfd_size_type) SXCOFFARMAG, abfd) != SXCOFFARMAG)
1233 {
1234 if (bfd_get_error () != bfd_error_system_call)
1235 bfd_set_error (bfd_error_wrong_format);
1236 return NULL;
1237 }
1238
1239 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1240 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1241 {
1242 bfd_set_error (bfd_error_wrong_format);
1243 return NULL;
1244 }
1245
1246 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1247 involves a cast, we can't do it as the left operand of
1248 assignment. */
1249 amt = sizeof (struct artdata);
1250 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
1251 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1252 return NULL;
1253
1254 bfd_ardata (abfd)->cache = NULL;
1255 bfd_ardata (abfd)->archive_head = NULL;
1256 bfd_ardata (abfd)->symdefs = NULL;
1257 bfd_ardata (abfd)->extended_names = NULL;
1258
1259 /* Now handle the two formats. */
1260 if (magic[1] != 'b')
1261 {
1262 /* This is the old format. */
1263 struct xcoff_ar_file_hdr hdr;
1264
1265 /* Copy over the magic string. */
1266 memcpy (hdr.magic, magic, SXCOFFARMAG);
1267
1268 /* Now read the rest of the file header. */
1269 if (bfd_bread ((PTR) &hdr.memoff,
1270 (bfd_size_type) SIZEOF_AR_FILE_HDR - SXCOFFARMAG, abfd)
1271 != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
1272 {
1273 if (bfd_get_error () != bfd_error_system_call)
1274 bfd_set_error (bfd_error_wrong_format);
1275 return NULL;
1276 }
1277
1278 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1279 (char **) NULL, 10);
1280
1281 amt = SIZEOF_AR_FILE_HDR;
1282 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1283 if (bfd_ardata (abfd)->tdata == NULL)
1284 return NULL;
1285
1286 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1287 }
1288 else
1289 {
1290 /* This is the new format. */
1291 struct xcoff_ar_file_hdr_big hdr;
1292
1293 /* Copy over the magic string. */
1294 memcpy (hdr.magic, magic, SXCOFFARMAG);
1295
1296 /* Now read the rest of the file header. */
1297 if (bfd_bread ((PTR) &hdr.memoff,
1298 (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, abfd)
1299 != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1300 {
1301 if (bfd_get_error () != bfd_error_system_call)
1302 bfd_set_error (bfd_error_wrong_format);
1303 return NULL;
1304 }
1305
1306 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1307 machines) since the field width is 20 and there numbers with more
1308 than 32 bits can be represented. */
1309 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1310 (char **) NULL, 10);
1311
1312 amt = SIZEOF_AR_FILE_HDR_BIG;
1313 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1314 if (bfd_ardata (abfd)->tdata == NULL)
1315 return NULL;
1316
1317 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1318 }
1319
1320 if (! _bfd_xcoff_slurp_armap (abfd))
1321 {
1322 bfd_release (abfd, bfd_ardata (abfd));
1323 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1324 return NULL;
1325 }
1326
1327 return abfd->xvec;
1328 }
1329
1330 /* Read the archive header in an XCOFF archive. */
1331
1332 PTR
1333 _bfd_xcoff_read_ar_hdr (abfd)
1334 bfd *abfd;
1335 {
1336 bfd_size_type namlen;
1337 struct areltdata *ret;
1338 bfd_size_type amt = sizeof (struct areltdata);
1339
1340 ret = (struct areltdata *) bfd_alloc (abfd, amt);
1341 if (ret == NULL)
1342 return NULL;
1343
1344 if (! xcoff_big_format_p (abfd))
1345 {
1346 struct xcoff_ar_hdr hdr;
1347 struct xcoff_ar_hdr *hdrp;
1348
1349 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1350 != SIZEOF_AR_HDR)
1351 {
1352 free (ret);
1353 return NULL;
1354 }
1355
1356 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1357 amt = SIZEOF_AR_HDR + namlen + 1;
1358 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1359 if (hdrp == NULL)
1360 {
1361 free (ret);
1362 return NULL;
1363 }
1364 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1365 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1366 {
1367 free (ret);
1368 return NULL;
1369 }
1370 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1371
1372 ret->arch_header = (char *) hdrp;
1373 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1374 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1375 }
1376 else
1377 {
1378 struct xcoff_ar_hdr_big hdr;
1379 struct xcoff_ar_hdr_big *hdrp;
1380
1381 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1382 != SIZEOF_AR_HDR_BIG)
1383 {
1384 free (ret);
1385 return NULL;
1386 }
1387
1388 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1389 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1390 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1391 if (hdrp == NULL)
1392 {
1393 free (ret);
1394 return NULL;
1395 }
1396 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1397 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1398 {
1399 free (ret);
1400 return NULL;
1401 }
1402 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1403
1404 ret->arch_header = (char *) hdrp;
1405 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1406 machines) since the field width is 20 and there numbers with more
1407 than 32 bits can be represented. */
1408 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1409 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1410 }
1411
1412 /* Skip over the XCOFFARFMAG at the end of the file name. */
1413 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1414 return NULL;
1415
1416 return (PTR) ret;
1417 }
1418
1419 /* Open the next element in an XCOFF archive. */
1420
1421 bfd *
1422 _bfd_xcoff_openr_next_archived_file (archive, last_file)
1423 bfd *archive;
1424 bfd *last_file;
1425 {
1426 file_ptr filestart;
1427
1428 if (xcoff_ardata (archive) == NULL)
1429 {
1430 bfd_set_error (bfd_error_invalid_operation);
1431 return NULL;
1432 }
1433
1434 if (! xcoff_big_format_p (archive))
1435 {
1436 if (last_file == NULL)
1437 filestart = bfd_ardata (archive)->first_file_filepos;
1438 else
1439 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1440 10);
1441
1442 if (filestart == 0
1443 || filestart == strtol (xcoff_ardata (archive)->memoff,
1444 (char **) NULL, 10)
1445 || filestart == strtol (xcoff_ardata (archive)->symoff,
1446 (char **) NULL, 10))
1447 {
1448 bfd_set_error (bfd_error_no_more_archived_files);
1449 return NULL;
1450 }
1451 }
1452 else
1453 {
1454 if (last_file == NULL)
1455 filestart = bfd_ardata (archive)->first_file_filepos;
1456 else
1457 /* XXX These actually have to be a calls to strtoll (at least
1458 on 32-bit machines) since the fields's width is 20 and
1459 there numbers with more than 32 bits can be represented. */
1460 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1461 10);
1462
1463 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1464 machines) since the fields's width is 20 and there numbers with more
1465 than 32 bits can be represented. */
1466 if (filestart == 0
1467 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1468 (char **) NULL, 10)
1469 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1470 (char **) NULL, 10))
1471 {
1472 bfd_set_error (bfd_error_no_more_archived_files);
1473 return NULL;
1474 }
1475 }
1476
1477 return _bfd_get_elt_at_filepos (archive, filestart);
1478 }
1479
1480 /* Stat an element in an XCOFF archive. */
1481
1482 int
1483 _bfd_xcoff_stat_arch_elt (abfd, s)
1484 bfd *abfd;
1485 struct stat *s;
1486 {
1487 if (abfd->arelt_data == NULL)
1488 {
1489 bfd_set_error (bfd_error_invalid_operation);
1490 return -1;
1491 }
1492
1493 if (! xcoff_big_format_p (abfd->my_archive))
1494 {
1495 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1496
1497 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1498 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1499 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1500 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1501 s->st_size = arch_eltdata (abfd)->parsed_size;
1502 }
1503 else
1504 {
1505 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1506
1507 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1508 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1509 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1510 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1511 s->st_size = arch_eltdata (abfd)->parsed_size;
1512 }
1513
1514 return 0;
1515 }
1516
1517 /* Normalize a file name for inclusion in an archive. */
1518
1519 static const char *
1520 normalize_filename (abfd)
1521 bfd *abfd;
1522 {
1523 const char *file;
1524 const char *filename;
1525
1526 file = bfd_get_filename (abfd);
1527 filename = strrchr (file, '/');
1528 if (filename != NULL)
1529 filename++;
1530 else
1531 filename = file;
1532 return filename;
1533 }
1534
1535 /* Write out an XCOFF armap. */
1536
1537 /*ARGSUSED*/
1538 static boolean
1539 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1540 bfd *abfd;
1541 unsigned int elength ATTRIBUTE_UNUSED;
1542 struct orl *map;
1543 unsigned int orl_count;
1544 int stridx;
1545 {
1546 struct xcoff_ar_hdr hdr;
1547 char *p;
1548 unsigned char buf[4];
1549 bfd *sub;
1550 file_ptr fileoff;
1551 unsigned int i;
1552
1553 memset (&hdr, 0, sizeof hdr);
1554 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1555 sprintf (hdr.nextoff, "%d", 0);
1556 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1557 sprintf (hdr.date, "%d", 0);
1558 sprintf (hdr.uid, "%d", 0);
1559 sprintf (hdr.gid, "%d", 0);
1560 sprintf (hdr.mode, "%d", 0);
1561 sprintf (hdr.namlen, "%d", 0);
1562
1563 /* We need spaces, not null bytes, in the header. */
1564 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1565 if (*p == '\0')
1566 *p = ' ';
1567
1568 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1569 != SIZEOF_AR_HDR
1570 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1571 != SXCOFFARFMAG))
1572 return false;
1573
1574 H_PUT_32 (abfd, orl_count, buf);
1575 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1576 return false;
1577
1578 sub = abfd->archive_head;
1579 fileoff = SIZEOF_AR_FILE_HDR;
1580 i = 0;
1581 while (sub != NULL && i < orl_count)
1582 {
1583 size_t namlen;
1584
1585 while (map[i].u.abfd == sub)
1586 {
1587 H_PUT_32 (abfd, fileoff, buf);
1588 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1589 return false;
1590 ++i;
1591 }
1592 namlen = strlen (normalize_filename (sub));
1593 namlen = (namlen + 1) &~ (size_t) 1;
1594 fileoff += (SIZEOF_AR_HDR
1595 + namlen
1596 + SXCOFFARFMAG
1597 + arelt_size (sub));
1598 fileoff = (fileoff + 1) &~ 1;
1599 sub = sub->next;
1600 }
1601
1602 for (i = 0; i < orl_count; i++)
1603 {
1604 const char *name;
1605 size_t namlen;
1606
1607 name = *map[i].name;
1608 namlen = strlen (name);
1609 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1610 return false;
1611 }
1612
1613 if ((stridx & 1) != 0)
1614 {
1615 char b;
1616
1617 b = '\0';
1618 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1619 return false;
1620 }
1621
1622 return true;
1623 }
1624
1625 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1626 #define FMT20 "%-20lld"
1627 #define FMT12 "%-12d"
1628 #define FMT12_OCTAL "%-12o"
1629 #define FMT4 "%-4d"
1630 #define PRINT20(d, v) \
1631 sprintf (buff20, FMT20, (long long)(v)), \
1632 memcpy ((void *) (d), buff20, 20)
1633
1634 #define PRINT12(d, v) \
1635 sprintf (buff20, FMT12, (int)(v)), \
1636 memcpy ((void *) (d), buff20, 12)
1637
1638 #define PRINT12_OCTAL(d, v) \
1639 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1640 memcpy ((void *) (d), buff20, 12)
1641
1642 #define PRINT4(d, v) \
1643 sprintf (buff20, FMT4, (int)(v)), \
1644 memcpy ((void *) (d), buff20, 4)
1645
1646 #define READ20(d, v) \
1647 buff20[20] = 0, \
1648 memcpy (buff20, (d), 20), \
1649 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1650
1651 static boolean
1652 do_pad (abfd, number)
1653 bfd *abfd;
1654 unsigned int number;
1655 {
1656 bfd_byte b = 0;
1657
1658 /* Limit pad to <= 4096. */
1659 if (number > 4096)
1660 return false;
1661
1662 while (number--)
1663 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1664 return false;
1665
1666 return true;
1667 }
1668
1669 static boolean
1670 do_copy (out_bfd, in_bfd)
1671 bfd *out_bfd;
1672 bfd *in_bfd;
1673 {
1674 bfd_size_type remaining;
1675 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1676
1677 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1678 return false;
1679
1680 remaining = arelt_size (in_bfd);
1681
1682 while (remaining >= DEFAULT_BUFFERSIZE)
1683 {
1684 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1685 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1686 return false;
1687
1688 remaining -= DEFAULT_BUFFERSIZE;
1689 }
1690
1691 if (remaining)
1692 {
1693 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1694 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1695 return false;
1696 }
1697
1698 return true;
1699 }
1700
1701 static boolean
1702 do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size)
1703 bfd *out_bfd;
1704 bfd *in_bfd;
1705 ufile_ptr *offset;
1706 int ar_header_size;
1707 {
1708 if (bfd_check_format (in_bfd, bfd_object)
1709 && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour
1710 && (in_bfd->flags & DYNAMIC) != 0)
1711 {
1712 bfd_size_type pad = 0;
1713 int text_align_power;
1714
1715 text_align_power = bfd_xcoff_text_align_power (in_bfd);
1716 BFD_ASSERT (2 < text_align_power);
1717
1718 pad = 1 << text_align_power;
1719 pad -= (*offset + ar_header_size) & (pad - 1);
1720
1721 if (! do_pad (out_bfd, pad))
1722 return false;
1723
1724 *offset += pad;
1725 }
1726
1727 return true;
1728 }
1729
1730 static boolean
1731 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1732 bfd *abfd;
1733 unsigned int elength ATTRIBUTE_UNUSED;
1734 struct orl *map;
1735 unsigned int orl_count;
1736 int stridx;
1737 {
1738 struct xcoff_ar_file_hdr_big *fhdr;
1739 bfd_vma i, sym_32, sym_64, str_32, str_64;
1740 const bfd_arch_info_type *arch_info = NULL;
1741 bfd *current_bfd;
1742 size_t string_length;
1743 ufile_ptr nextoff, prevoff;
1744
1745 /* First, we look through the symbols and work out which are
1746 from 32-bit objects and which from 64-bit ones. */
1747 sym_32 = sym_64 = str_32 = str_64 = 0;
1748
1749 current_bfd = abfd->archive_head;
1750 if (current_bfd != NULL)
1751 arch_info = bfd_get_arch_info (current_bfd);
1752 i = 0;
1753 while (current_bfd != NULL && i < orl_count)
1754 {
1755 while (map[i].u.abfd == current_bfd)
1756 {
1757 string_length = strlen (*map[i].name) + 1;
1758
1759 if (arch_info->bits_per_address == 64)
1760 {
1761 sym_64++;
1762 str_64 += string_length;
1763 }
1764 else
1765 {
1766 sym_32++;
1767 str_32 += string_length;
1768 }
1769 i++;
1770 }
1771 current_bfd = current_bfd->next;
1772 if (current_bfd != NULL)
1773 arch_info = bfd_get_arch_info (current_bfd);
1774 }
1775
1776 /* A quick sanity check... */
1777 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1778 /* Explicit cast to int for compiler. */
1779 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1780
1781 fhdr = xcoff_ardata_big (abfd);
1782
1783 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1784 READ20 (fhdr->memoff, prevoff);
1785 READ20 (fhdr->symoff, nextoff);
1786
1787 BFD_ASSERT (nextoff == bfd_tell (abfd));
1788
1789 /* Write out the symbol table.
1790 Layout :
1791
1792 standard big archive header
1793 0x0000 ar_size [0x14]
1794 0x0014 ar_nxtmem [0x14]
1795 0x0028 ar_prvmem [0x14]
1796 0x003C ar_date [0x0C]
1797 0x0048 ar_uid [0x0C]
1798 0x0054 ar_gid [0x0C]
1799 0x0060 ar_mod [0x0C]
1800 0x006C ar_namelen[0x04]
1801 0x0070 ar_fmag [SXCOFFARFMAG]
1802
1803 Symbol table
1804 0x0072 num_syms [0x08], binary
1805 0x0078 offsets [0x08 * num_syms], binary
1806 0x0086 + 0x08 * num_syms names [??]
1807 ?? pad to even bytes.
1808 */
1809
1810 if (sym_32)
1811 {
1812 struct xcoff_ar_hdr_big *hdr;
1813 bfd_byte *symbol_table;
1814 bfd_byte *st;
1815 file_ptr fileoff;
1816
1817 bfd_vma symbol_table_size =
1818 SIZEOF_AR_HDR_BIG
1819 + SXCOFFARFMAG
1820 + 8
1821 + 8 * sym_32
1822 + str_32 + (str_32 & 1);
1823
1824 symbol_table = NULL;
1825 symbol_table = (bfd_byte *) bfd_malloc (symbol_table_size);
1826 if (symbol_table == NULL)
1827 return false;
1828 memset (symbol_table, 0, symbol_table_size);
1829
1830 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1831
1832 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1833
1834 if (sym_64)
1835 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1836 else
1837 PRINT20 (hdr->nextoff, 0);
1838
1839 PRINT20 (hdr->prevoff, prevoff);
1840 PRINT12 (hdr->date, 0);
1841 PRINT12 (hdr->uid, 0);
1842 PRINT12 (hdr->gid, 0);
1843 PRINT12 (hdr->mode, 0);
1844 PRINT4 (hdr->namlen, 0) ;
1845
1846 st = symbol_table + SIZEOF_AR_HDR_BIG;
1847 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1848 st += SXCOFFARFMAG;
1849
1850 bfd_h_put_64 (abfd, sym_32, st);
1851 st += 8;
1852
1853 /* loop over the 32 bit offsets */
1854 current_bfd = abfd->archive_head;
1855 if (current_bfd != NULL)
1856 arch_info = bfd_get_arch_info (current_bfd);
1857 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1858 i = 0;
1859 while (current_bfd != NULL && i < orl_count)
1860 {
1861 while (map[i].u.abfd == current_bfd)
1862 {
1863 if (arch_info->bits_per_address == 32)
1864 {
1865 bfd_h_put_64 (abfd, fileoff, st);
1866 st += 8;
1867 }
1868 i++;
1869 }
1870 string_length = strlen (normalize_filename (current_bfd));
1871 string_length += string_length & 1;
1872 fileoff += (SIZEOF_AR_HDR_BIG
1873 + string_length
1874 + SXCOFFARFMAG
1875 + arelt_size (current_bfd));
1876 fileoff += fileoff & 1;
1877 current_bfd = current_bfd->next;
1878 if (current_bfd != NULL)
1879 arch_info = bfd_get_arch_info (current_bfd);
1880 }
1881
1882 /* loop over the 32 bit symbol names */
1883 current_bfd = abfd->archive_head;
1884 if (current_bfd != NULL)
1885 arch_info = bfd_get_arch_info (current_bfd);
1886 i = 0;
1887 while (current_bfd != NULL && i < orl_count)
1888 {
1889 while (map[i].u.abfd == current_bfd)
1890 {
1891 if (arch_info->bits_per_address == 32)
1892 {
1893 string_length = sprintf (st, "%s", *map[i].name);
1894 st += string_length + 1;
1895 }
1896 i++;
1897 }
1898 current_bfd = current_bfd->next;
1899 if (current_bfd != NULL)
1900 arch_info = bfd_get_arch_info (current_bfd);
1901 }
1902
1903 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1904
1905 free (symbol_table);
1906 symbol_table = NULL;
1907
1908 prevoff = nextoff;
1909 nextoff = nextoff + symbol_table_size;
1910 }
1911 else
1912 PRINT20 (fhdr->symoff, 0);
1913
1914 if (sym_64)
1915 {
1916 struct xcoff_ar_hdr_big *hdr;
1917 bfd_byte *symbol_table;
1918 bfd_byte *st;
1919 file_ptr fileoff;
1920
1921 bfd_vma symbol_table_size =
1922 SIZEOF_AR_HDR_BIG
1923 + SXCOFFARFMAG
1924 + 8
1925 + 8 * sym_64
1926 + str_64 + (str_64 & 1);
1927
1928 symbol_table = NULL;
1929 symbol_table = (bfd_byte *) bfd_malloc (symbol_table_size);
1930 if (symbol_table == NULL)
1931 return false;
1932 memset (symbol_table, 0, symbol_table_size);
1933
1934 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1935
1936 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
1937 PRINT20 (hdr->nextoff, 0);
1938 PRINT20 (hdr->prevoff, prevoff);
1939 PRINT12 (hdr->date, 0);
1940 PRINT12 (hdr->uid, 0);
1941 PRINT12 (hdr->gid, 0);
1942 PRINT12 (hdr->mode, 0);
1943 PRINT4 (hdr->namlen, 0);
1944
1945 st = symbol_table + SIZEOF_AR_HDR_BIG;
1946 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1947 st += SXCOFFARFMAG;
1948
1949 bfd_h_put_64 (abfd, sym_64, st);
1950 st += 8;
1951
1952 /* loop over the 64 bit offsets */
1953 current_bfd = abfd->archive_head;
1954 if (current_bfd != NULL)
1955 arch_info = bfd_get_arch_info (current_bfd);
1956 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1957 i = 0;
1958 while (current_bfd != NULL && i < orl_count)
1959 {
1960 while (map[i].u.abfd == current_bfd)
1961 {
1962 if (arch_info->bits_per_address == 64)
1963 {
1964 bfd_h_put_64 (abfd, fileoff, st);
1965 st += 8;
1966 }
1967 i++;
1968 }
1969 string_length = strlen (normalize_filename (current_bfd));
1970 string_length += string_length & 1;
1971 fileoff += (SIZEOF_AR_HDR_BIG
1972 + string_length
1973 + SXCOFFARFMAG
1974 + arelt_size (current_bfd));
1975 fileoff += fileoff & 1;
1976 current_bfd = current_bfd->next;
1977 if (current_bfd != NULL)
1978 arch_info = bfd_get_arch_info (current_bfd);
1979 }
1980
1981 /* loop over the 64 bit symbol names */
1982 current_bfd = abfd->archive_head;
1983 if (current_bfd != NULL)
1984 arch_info = bfd_get_arch_info (current_bfd);
1985 i = 0;
1986 while (current_bfd != NULL && i < orl_count)
1987 {
1988 while (map[i].u.abfd == current_bfd)
1989 {
1990 if (arch_info->bits_per_address == 64)
1991 {
1992 string_length = sprintf (st, "%s", *map[i].name);
1993 st += string_length + 1;
1994 }
1995 i++;
1996 }
1997 current_bfd = current_bfd->next;
1998 if (current_bfd != NULL)
1999 arch_info = bfd_get_arch_info (current_bfd);
2000 }
2001
2002 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2003
2004 free (symbol_table);
2005 symbol_table = NULL;
2006
2007 PRINT20 (fhdr->symoff64, nextoff);
2008 }
2009 else
2010 PRINT20 (fhdr->symoff64, 0);
2011
2012 return true;
2013 }
2014
2015 boolean
2016 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
2017 bfd *abfd;
2018 unsigned int elength ATTRIBUTE_UNUSED;
2019 struct orl *map;
2020 unsigned int orl_count;
2021 int stridx;
2022 {
2023 if (! xcoff_big_format_p (abfd))
2024 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2025 else
2026 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2027 }
2028
2029 /* Write out an XCOFF archive. We always write an entire archive,
2030 rather than fussing with the freelist and so forth. */
2031
2032 static boolean
2033 xcoff_write_archive_contents_old (abfd)
2034 bfd *abfd;
2035 {
2036 struct xcoff_ar_file_hdr fhdr;
2037 bfd_size_type count;
2038 bfd_size_type total_namlen;
2039 file_ptr *offsets;
2040 boolean makemap;
2041 boolean hasobjects;
2042 ufile_ptr prevoff, nextoff;
2043 bfd *sub;
2044 size_t i;
2045 struct xcoff_ar_hdr ahdr;
2046 bfd_size_type size;
2047 char *p;
2048 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2049
2050 memset (&fhdr, 0, sizeof fhdr);
2051 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2052 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2053 sprintf (fhdr.freeoff, "%d", 0);
2054
2055 count = 0;
2056 total_namlen = 0;
2057 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2058 {
2059 ++count;
2060 total_namlen += strlen (normalize_filename (sub)) + 1;
2061 }
2062 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2063 if (offsets == NULL)
2064 return false;
2065
2066 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2067 return false;
2068
2069 makemap = bfd_has_map (abfd);
2070 hasobjects = false;
2071 prevoff = 0;
2072 nextoff = SIZEOF_AR_FILE_HDR;
2073 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
2074 {
2075 const char *name;
2076 bfd_size_type namlen;
2077 struct xcoff_ar_hdr *ahdrp;
2078 bfd_size_type remaining;
2079
2080 if (makemap && ! hasobjects)
2081 {
2082 if (bfd_check_format (sub, bfd_object))
2083 hasobjects = true;
2084 }
2085
2086 name = normalize_filename (sub);
2087 namlen = strlen (name);
2088
2089 if (sub->arelt_data != NULL)
2090 ahdrp = arch_xhdr (sub);
2091 else
2092 ahdrp = NULL;
2093
2094 if (ahdrp == NULL)
2095 {
2096 struct stat s;
2097
2098 memset (&ahdr, 0, sizeof ahdr);
2099 ahdrp = &ahdr;
2100 if (stat (bfd_get_filename (sub), &s) != 0)
2101 {
2102 bfd_set_error (bfd_error_system_call);
2103 return false;
2104 }
2105
2106 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2107 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2108 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2109 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2110 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2111
2112 if (sub->arelt_data == NULL)
2113 {
2114 size = sizeof (struct areltdata);
2115 sub->arelt_data = bfd_alloc (sub, size);
2116 if (sub->arelt_data == NULL)
2117 return false;
2118 }
2119
2120 arch_eltdata (sub)->parsed_size = s.st_size;
2121 }
2122
2123 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2124 sprintf (ahdrp->namlen, "%ld", (long) namlen);
2125
2126 /* If the length of the name is odd, we write out the null byte
2127 after the name as well. */
2128 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2129
2130 remaining = arelt_size (sub);
2131 size = (SIZEOF_AR_HDR
2132 + namlen
2133 + SXCOFFARFMAG
2134 + remaining);
2135
2136 BFD_ASSERT (nextoff == bfd_tell (abfd));
2137
2138 offsets[i] = nextoff;
2139
2140 prevoff = nextoff;
2141 nextoff += size + (size & 1);
2142
2143 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
2144
2145 /* We need spaces, not null bytes, in the header. */
2146 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2147 if (*p == '\0')
2148 *p = ' ';
2149
2150 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2151 != SIZEOF_AR_HDR)
2152 || (bfd_bwrite ((PTR) name, namlen, abfd) != namlen)
2153 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2154 != SXCOFFARFMAG))
2155 return false;
2156
2157 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
2158 return false;
2159
2160 if (! do_copy (abfd, sub))
2161 return false;
2162
2163 if (! do_pad (abfd, size & 1))
2164 return false;
2165 }
2166
2167 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2168
2169 /* Write out the member table. */
2170
2171 BFD_ASSERT (nextoff == bfd_tell (abfd));
2172 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2173
2174 memset (&ahdr, 0, sizeof ahdr);
2175 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE +
2176 count * XCOFFARMAG_ELEMENT_SIZE +
2177 total_namlen));
2178 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2179 sprintf (ahdr.date, "%d", 0);
2180 sprintf (ahdr.uid, "%d", 0);
2181 sprintf (ahdr.gid, "%d", 0);
2182 sprintf (ahdr.mode, "%d", 0);
2183 sprintf (ahdr.namlen, "%d", 0);
2184
2185 size = (SIZEOF_AR_HDR
2186 + XCOFFARMAG_ELEMENT_SIZE
2187 + count * XCOFFARMAG_ELEMENT_SIZE
2188 + total_namlen
2189 + SXCOFFARFMAG);
2190
2191 prevoff = nextoff;
2192 nextoff += size + (size & 1);
2193
2194 if (makemap && hasobjects)
2195 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2196 else
2197 sprintf (ahdr.nextoff, "%d", 0);
2198
2199 /* We need spaces, not null bytes, in the header. */
2200 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2201 if (*p == '\0')
2202 *p = ' ';
2203
2204 if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2205 != SIZEOF_AR_HDR)
2206 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2207 != SXCOFFARFMAG))
2208 return false;
2209
2210 sprintf (decbuf, "%-12ld", (long) count);
2211 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2212 != XCOFFARMAG_ELEMENT_SIZE)
2213 return false;
2214 for (i = 0; i < (size_t) count; i++)
2215 {
2216 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2217 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2218 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2219 return false;
2220 }
2221 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2222 {
2223 const char *name;
2224 bfd_size_type namlen;
2225
2226 name = normalize_filename (sub);
2227 namlen = strlen (name);
2228 if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
2229 return false;
2230 }
2231
2232 if (! do_pad (abfd, size & 1))
2233 return false;
2234
2235 /* Write out the armap, if appropriate. */
2236 if (! makemap || ! hasobjects)
2237 sprintf (fhdr.symoff, "%d", 0);
2238 else
2239 {
2240 BFD_ASSERT (nextoff == bfd_tell (abfd));
2241 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2242 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2243 if (! _bfd_compute_and_write_armap (abfd, 0))
2244 return false;
2245 }
2246
2247 /* Write out the archive file header. */
2248
2249 /* We need spaces, not null bytes, in the header. */
2250 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2251 if (*p == '\0')
2252 *p = ' ';
2253
2254 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2255 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2256 != SIZEOF_AR_FILE_HDR))
2257 return false;
2258
2259 return true;
2260 }
2261
2262 static boolean
2263 xcoff_write_archive_contents_big (abfd)
2264 bfd *abfd;
2265 {
2266 struct xcoff_ar_file_hdr_big fhdr;
2267 bfd_size_type count;
2268 bfd_size_type total_namlen;
2269 file_ptr *offsets;
2270 boolean makemap;
2271 boolean hasobjects;
2272 ufile_ptr prevoff, nextoff;
2273 bfd *current_bfd;
2274 size_t i;
2275 struct xcoff_ar_hdr_big *hdr, ahdr;
2276 bfd_size_type size;
2277 bfd_byte *member_table, *mt;
2278 bfd_vma member_table_size;
2279
2280 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2281 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2282
2283 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2284 return false;
2285
2286 /* Calculate count and total_namlen. */
2287 makemap = bfd_has_map (abfd);
2288 hasobjects = false;
2289 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2290 current_bfd != NULL;
2291 current_bfd = current_bfd->next, count++)
2292 {
2293 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2294
2295 if (makemap
2296 && ! hasobjects
2297 && bfd_check_format (current_bfd, bfd_object))
2298 hasobjects = true;
2299 }
2300
2301 offsets = NULL;
2302 if (count)
2303 {
2304 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2305 if (offsets == NULL)
2306 return false;
2307 }
2308
2309 prevoff = 0;
2310 nextoff = SIZEOF_AR_FILE_HDR_BIG;
2311 for (current_bfd = abfd->archive_head, i = 0;
2312 current_bfd != NULL;
2313 current_bfd = current_bfd->next, i++)
2314 {
2315 const char *name;
2316 bfd_size_type namlen;
2317 struct xcoff_ar_hdr_big *ahdrp;
2318 bfd_size_type remaining;
2319
2320 name = normalize_filename (current_bfd);
2321 namlen = strlen (name);
2322
2323 if (current_bfd->arelt_data != NULL)
2324 ahdrp = arch_xhdr_big (current_bfd);
2325 else
2326 ahdrp = NULL;
2327
2328 if (ahdrp == NULL)
2329 {
2330 struct stat s;
2331
2332 ahdrp = &ahdr;
2333 /* XXX This should actually be a call to stat64 (at least on
2334 32-bit machines).
2335 XXX This call will fail if the original object is not found. */
2336 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2337 {
2338 bfd_set_error (bfd_error_system_call);
2339 return false;
2340 }
2341
2342 PRINT20 (ahdrp->size, s.st_size);
2343 PRINT12 (ahdrp->date, s.st_mtime);
2344 PRINT12 (ahdrp->uid, s.st_uid);
2345 PRINT12 (ahdrp->gid, s.st_gid);
2346 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2347
2348 if (current_bfd->arelt_data == NULL)
2349 {
2350 size = sizeof (struct areltdata);
2351 current_bfd->arelt_data = bfd_alloc (current_bfd, size);
2352 if (current_bfd->arelt_data == NULL)
2353 return false;
2354 }
2355
2356 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2357 }
2358
2359 PRINT20 (ahdrp->prevoff, prevoff);
2360 PRINT4 (ahdrp->namlen, namlen);
2361
2362 /* If the length of the name is odd, we write out the null byte
2363 after the name as well. */
2364 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2365
2366 remaining = arelt_size (current_bfd);
2367 size = (SIZEOF_AR_HDR_BIG
2368 + namlen
2369 + SXCOFFARFMAG
2370 + remaining);
2371
2372 BFD_ASSERT (nextoff == bfd_tell (abfd));
2373
2374 /* Check for xcoff shared objects.
2375 Their text section needs to be aligned wrt the archive file position.
2376 This requires extra padding before the archive header. */
2377 if (! do_shared_object_padding (abfd, current_bfd, & nextoff,
2378 SIZEOF_AR_HDR_BIG + namlen
2379 + SXCOFFARFMAG))
2380 return false;
2381
2382 offsets[i] = nextoff;
2383
2384 prevoff = nextoff;
2385 nextoff += size + (size & 1);
2386
2387 PRINT20 (ahdrp->nextoff, nextoff);
2388
2389 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
2390 != SIZEOF_AR_HDR_BIG)
2391 || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen
2392 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG,
2393 abfd) != SXCOFFARFMAG))
2394 return false;
2395
2396 if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0)
2397 return false;
2398
2399 if (! do_copy (abfd, current_bfd))
2400 return false;
2401
2402 if (! do_pad (abfd, size & 1))
2403 return false;
2404 }
2405
2406 if (count)
2407 {
2408 PRINT20 (fhdr.firstmemoff, offsets[0]);
2409 PRINT20 (fhdr.lastmemoff, prevoff);
2410 }
2411
2412 /* Write out the member table.
2413 Layout :
2414
2415 standard big archive header
2416 0x0000 ar_size [0x14]
2417 0x0014 ar_nxtmem [0x14]
2418 0x0028 ar_prvmem [0x14]
2419 0x003C ar_date [0x0C]
2420 0x0048 ar_uid [0x0C]
2421 0x0054 ar_gid [0x0C]
2422 0x0060 ar_mod [0x0C]
2423 0x006C ar_namelen[0x04]
2424 0x0070 ar_fmag [0x02]
2425
2426 Member table
2427 0x0072 count [0x14]
2428 0x0086 offsets [0x14 * counts]
2429 0x0086 + 0x14 * counts names [??]
2430 ?? pad to even bytes.
2431 */
2432
2433 BFD_ASSERT (nextoff == bfd_tell (abfd));
2434
2435 member_table_size = (SIZEOF_AR_HDR_BIG
2436 + SXCOFFARFMAG
2437 + XCOFFARMAGBIG_ELEMENT_SIZE
2438 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2439 + total_namlen);
2440
2441 member_table_size += member_table_size & 1;
2442 member_table = NULL;
2443 member_table = (bfd_byte *) bfd_malloc (member_table_size);
2444 if (member_table == NULL)
2445 return false;
2446 memset (member_table, 0, member_table_size);
2447
2448 hdr = (struct xcoff_ar_hdr_big *) member_table;
2449
2450 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE +
2451 count * XCOFFARMAGBIG_ELEMENT_SIZE +
2452 total_namlen + (total_namlen & 1)));
2453 if (makemap && hasobjects)
2454 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2455 else
2456 PRINT20 (hdr->nextoff, 0);
2457 PRINT20 (hdr->prevoff, prevoff);
2458 PRINT12 (hdr->date, 0);
2459 PRINT12 (hdr->uid, 0);
2460 PRINT12 (hdr->gid, 0);
2461 PRINT12 (hdr->mode, 0);
2462 PRINT4 (hdr->namlen, 0);
2463
2464 mt = member_table + SIZEOF_AR_HDR_BIG;
2465 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2466 mt += SXCOFFARFMAG;
2467
2468 PRINT20 (mt, count);
2469 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2470 for (i = 0; i < (size_t) count; i++)
2471 {
2472 PRINT20 (mt, offsets[i]);
2473 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2474 }
2475
2476 if (count)
2477 {
2478 free (offsets);
2479 offsets = NULL;
2480 }
2481
2482 for (current_bfd = abfd->archive_head; current_bfd != NULL;
2483 current_bfd = current_bfd->next)
2484 {
2485 const char *name;
2486 size_t namlen;
2487
2488 name = normalize_filename (current_bfd);
2489 namlen = sprintf(mt, "%s", name);
2490 mt += namlen + 1;
2491 }
2492
2493 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2494 return false;
2495
2496 free (member_table);
2497 member_table = NULL;
2498
2499 PRINT20 (fhdr.memoff, nextoff);
2500
2501 prevoff = nextoff;
2502 nextoff += member_table_size;
2503
2504 /* Write out the armap, if appropriate. */
2505
2506 if (! makemap || ! hasobjects)
2507 PRINT20 (fhdr.symoff, 0);
2508 else
2509 {
2510 BFD_ASSERT (nextoff == bfd_tell (abfd));
2511
2512 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2513 PRINT20 (fhdr.symoff, nextoff);
2514
2515 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2516 if (! _bfd_compute_and_write_armap (abfd, 0))
2517 return false;
2518 }
2519
2520 /* Write out the archive file header. */
2521
2522 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2523 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2524 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2525 return false;
2526
2527 return true;
2528 }
2529
2530 boolean
2531 _bfd_xcoff_write_archive_contents (abfd)
2532 bfd *abfd;
2533 {
2534 if (! xcoff_big_format_p (abfd))
2535 return xcoff_write_archive_contents_old (abfd);
2536 else
2537 return xcoff_write_archive_contents_big (abfd);
2538 }
2539 \f
2540 /* We can't use the usual coff_sizeof_headers routine, because AIX
2541 always uses an a.out header. */
2542
2543 int
2544 _bfd_xcoff_sizeof_headers (abfd, reloc)
2545 bfd *abfd;
2546 boolean reloc ATTRIBUTE_UNUSED;
2547 {
2548 int size;
2549
2550 size = FILHSZ;
2551 if (xcoff_data (abfd)->full_aouthdr)
2552 size += AOUTSZ;
2553 else
2554 size += SMALL_AOUTSZ;
2555 size += abfd->section_count * SCNHSZ;
2556 return size;
2557 }
2558 \f
2559 /* Routines to swap information in the XCOFF .loader section. If we
2560 ever need to write an XCOFF loader, this stuff will need to be
2561 moved to another file shared by the linker (which XCOFF calls the
2562 ``binder'') and the loader. */
2563
2564 /* Swap in the ldhdr structure. */
2565
2566 static void
2567 xcoff_swap_ldhdr_in (abfd, s, dst)
2568 bfd *abfd;
2569 const PTR s;
2570 struct internal_ldhdr *dst;
2571 {
2572 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2573
2574 dst->l_version = bfd_get_32 (abfd, src->l_version);
2575 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2576 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2577 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2578 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2579 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2580 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2581 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2582 }
2583
2584 /* Swap out the ldhdr structure. */
2585
2586 static void
2587 xcoff_swap_ldhdr_out (abfd, src, d)
2588 bfd *abfd;
2589 const struct internal_ldhdr *src;
2590 PTR d;
2591 {
2592 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2593
2594 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2595 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2596 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2597 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2598 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2599 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2600 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2601 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2602 }
2603
2604 /* Swap in the ldsym structure. */
2605
2606 static void
2607 xcoff_swap_ldsym_in (abfd, s, dst)
2608 bfd *abfd;
2609 const PTR s;
2610 struct internal_ldsym *dst;
2611 {
2612 const struct external_ldsym *src = (const struct external_ldsym *) s;
2613
2614 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2615 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2616 } else {
2617 dst->_l._l_l._l_zeroes = 0;
2618 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2619 }
2620 dst->l_value = bfd_get_32 (abfd, src->l_value);
2621 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2622 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2623 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2624 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2625 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2626 }
2627
2628 /* Swap out the ldsym structure. */
2629
2630 static void
2631 xcoff_swap_ldsym_out (abfd, src, d)
2632 bfd *abfd;
2633 const struct internal_ldsym *src;
2634 PTR d;
2635 {
2636 struct external_ldsym *dst = (struct external_ldsym *) d;
2637
2638 if (src->_l._l_l._l_zeroes != 0)
2639 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2640 else
2641 {
2642 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2643 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2644 dst->_l._l_l._l_offset);
2645 }
2646 bfd_put_32 (abfd, src->l_value, dst->l_value);
2647 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2648 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2649 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2650 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2651 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2652 }
2653
2654 static void
2655 xcoff_swap_reloc_in (abfd, s, d)
2656 bfd *abfd;
2657 PTR s;
2658 PTR d;
2659 {
2660 struct external_reloc *src = (struct external_reloc *) s;
2661 struct internal_reloc *dst = (struct internal_reloc *) d;
2662
2663 memset (dst, 0, sizeof (struct internal_reloc));
2664
2665 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2666 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2667 dst->r_size = bfd_get_8 (abfd, src->r_size);
2668 dst->r_type = bfd_get_8 (abfd, src->r_type);
2669 }
2670
2671 static unsigned int
2672 xcoff_swap_reloc_out (abfd, s, d)
2673 bfd *abfd;
2674 PTR s;
2675 PTR d;
2676 {
2677 struct internal_reloc *src = (struct internal_reloc *) s;
2678 struct external_reloc *dst = (struct external_reloc *) d;
2679
2680 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2681 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2682 bfd_put_8 (abfd, src->r_type, dst->r_type);
2683 bfd_put_8 (abfd, src->r_size, dst->r_size);
2684
2685 return bfd_coff_relsz (abfd);
2686 }
2687
2688 /* Swap in the ldrel structure. */
2689
2690 static void
2691 xcoff_swap_ldrel_in (abfd, s, dst)
2692 bfd *abfd;
2693 const PTR s;
2694 struct internal_ldrel *dst;
2695 {
2696 const struct external_ldrel *src = (const struct external_ldrel *) s;
2697
2698 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2699 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2700 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2701 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2702 }
2703
2704 /* Swap out the ldrel structure. */
2705
2706 static void
2707 xcoff_swap_ldrel_out (abfd, src, d)
2708 bfd *abfd;
2709 const struct internal_ldrel *src;
2710 PTR d;
2711 {
2712 struct external_ldrel *dst = (struct external_ldrel *) d;
2713
2714 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2715 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2716 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2717 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2718 }
2719 \f
2720
2721 boolean
2722 xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
2723 val, addend, relocation, contents)
2724 bfd *input_bfd ATTRIBUTE_UNUSED;
2725 asection *input_section ATTRIBUTE_UNUSED;
2726 bfd *output_bfd ATTRIBUTE_UNUSED;
2727 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2728 struct internal_syment *sym ATTRIBUTE_UNUSED;
2729 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2730 bfd_vma val ATTRIBUTE_UNUSED;
2731 bfd_vma addend ATTRIBUTE_UNUSED;
2732 bfd_vma *relocation ATTRIBUTE_UNUSED;
2733 bfd_byte *contents ATTRIBUTE_UNUSED;
2734 {
2735 return true;
2736 }
2737
2738 boolean
2739 xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
2740 val, addend, relocation, contents)
2741 bfd *input_bfd;
2742 asection *input_section ATTRIBUTE_UNUSED;
2743 bfd *output_bfd ATTRIBUTE_UNUSED;
2744 struct internal_reloc *rel;
2745 struct internal_syment *sym ATTRIBUTE_UNUSED;
2746 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2747 bfd_vma val ATTRIBUTE_UNUSED;
2748 bfd_vma addend ATTRIBUTE_UNUSED;
2749 bfd_vma *relocation ATTRIBUTE_UNUSED;
2750 bfd_byte *contents ATTRIBUTE_UNUSED;
2751 {
2752 (*_bfd_error_handler)
2753 (_("%s: unsupported relocation type 0x%02x"),
2754 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2755 bfd_set_error (bfd_error_bad_value);
2756 return false;
2757 }
2758
2759 boolean
2760 xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
2761 val, addend, relocation, contents)
2762 bfd *input_bfd ATTRIBUTE_UNUSED;
2763 asection *input_section ATTRIBUTE_UNUSED;
2764 bfd *output_bfd ATTRIBUTE_UNUSED;
2765 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2766 struct internal_syment *sym ATTRIBUTE_UNUSED;
2767 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2768 bfd_vma val;
2769 bfd_vma addend;
2770 bfd_vma *relocation;
2771 bfd_byte *contents ATTRIBUTE_UNUSED;
2772 {
2773 *relocation = val + addend;
2774 return true;
2775 }
2776
2777 boolean
2778 xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
2779 val, addend, relocation, contents)
2780 bfd *input_bfd ATTRIBUTE_UNUSED;
2781 asection *input_section ATTRIBUTE_UNUSED;
2782 bfd *output_bfd ATTRIBUTE_UNUSED;
2783 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2784 struct internal_syment *sym ATTRIBUTE_UNUSED;
2785 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2786 bfd_vma val;
2787 bfd_vma addend;
2788 bfd_vma *relocation;
2789 bfd_byte *contents ATTRIBUTE_UNUSED;
2790 {
2791 *relocation = addend - val;
2792 return true;
2793 }
2794
2795 boolean
2796 xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
2797 val, addend, relocation, contents)
2798 bfd *input_bfd ATTRIBUTE_UNUSED;
2799 asection *input_section;
2800 bfd *output_bfd ATTRIBUTE_UNUSED;
2801 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2802 struct internal_syment *sym ATTRIBUTE_UNUSED;
2803 struct reloc_howto_struct *howto;
2804 bfd_vma val;
2805 bfd_vma addend;
2806 bfd_vma *relocation;
2807 bfd_byte *contents ATTRIBUTE_UNUSED;
2808 {
2809 howto->pc_relative = true;
2810
2811 /* A PC relative reloc includes the section address. */
2812 addend += input_section->vma;
2813
2814 *relocation = val + addend;
2815 *relocation -= (input_section->output_section->vma +
2816 input_section->output_offset);
2817 return true;
2818 }
2819
2820 boolean
2821 xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
2822 val, addend, relocation, contents)
2823 bfd *input_bfd;
2824 asection *input_section ATTRIBUTE_UNUSED;
2825 bfd *output_bfd;
2826 struct internal_reloc *rel;
2827 struct internal_syment *sym;
2828 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2829 bfd_vma val;
2830 bfd_vma addend ATTRIBUTE_UNUSED;
2831 bfd_vma *relocation;
2832 bfd_byte *contents ATTRIBUTE_UNUSED;
2833 {
2834 struct xcoff_link_hash_entry *h;
2835
2836 if (0 > rel->r_symndx)
2837 return false;
2838
2839 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2840
2841 if (h != NULL && h->smclas != XMC_TD)
2842 {
2843 if (h->toc_section == NULL)
2844 {
2845 (*_bfd_error_handler)
2846 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2847 bfd_get_filename (input_bfd), rel->r_vaddr,
2848 h->root.root.string);
2849 bfd_set_error (bfd_error_bad_value);
2850 return false;
2851 }
2852
2853 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2854 val = (h->toc_section->output_section->vma
2855 + h->toc_section->output_offset);
2856 }
2857
2858 *relocation = ((val - xcoff_data (output_bfd)->toc) -
2859 (sym->n_value - xcoff_data (input_bfd)->toc));
2860 return true;
2861 }
2862
2863 boolean
2864 xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
2865 val, addend, relocation, contents)
2866 bfd *input_bfd ATTRIBUTE_UNUSED;
2867 asection *input_section ATTRIBUTE_UNUSED;
2868 bfd *output_bfd ATTRIBUTE_UNUSED;
2869 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2870 struct internal_syment *sym ATTRIBUTE_UNUSED;
2871 struct reloc_howto_struct *howto;
2872 bfd_vma val;
2873 bfd_vma addend;
2874 bfd_vma *relocation;
2875 bfd_byte *contents ATTRIBUTE_UNUSED;
2876 {
2877 howto->src_mask &= ~3;
2878 howto->dst_mask = howto->src_mask;
2879
2880 *relocation = val + addend;
2881
2882 return true;
2883 }
2884
2885 static boolean
2886 xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
2887 val, addend, relocation, contents)
2888 bfd *input_bfd;
2889 asection *input_section;
2890 bfd *output_bfd ATTRIBUTE_UNUSED;
2891 struct internal_reloc *rel;
2892 struct internal_syment *sym ATTRIBUTE_UNUSED;
2893 struct reloc_howto_struct *howto;
2894 bfd_vma val;
2895 bfd_vma addend;
2896 bfd_vma *relocation;
2897 bfd_byte *contents;
2898 {
2899 struct xcoff_link_hash_entry *h;
2900
2901 if (0 > rel->r_symndx)
2902 return false;
2903
2904 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2905
2906 /* If we see an R_BR or R_RBR reloc which is jumping to global
2907 linkage code, and it is followed by an appropriate cror nop
2908 instruction, we replace the cror with lwz r2,20(r1). This
2909 restores the TOC after the glink code. Contrariwise, if the
2910 call is followed by a lwz r2,20(r1), but the call is not
2911 going to global linkage code, we can replace the load with a
2912 cror. */
2913 if (NULL != h
2914 && bfd_link_hash_defined == h->root.type
2915 && (rel->r_vaddr - input_section->vma + 8 <=
2916 input_section->_cooked_size))
2917 {
2918 bfd_byte *pnext;
2919 unsigned long next;
2920
2921 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2922 next = bfd_get_32 (input_bfd, pnext);
2923
2924 /* The _ptrgl function is magic. It is used by the AIX
2925 compiler to call a function through a pointer. */
2926 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2927 {
2928 if (next == 0x4def7b82 /* cror 15,15,15 */
2929 || next == 0x4ffffb82 /* cror 31,31,31 */
2930 || next == 0x60000000) /* ori r0,r0,0 */
2931 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2932
2933 } else
2934 {
2935 if (next == 0x80410014) /* lwz r1,20(r1) */
2936 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2937 }
2938 }
2939 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2940 {
2941 /* Normally, this relocation is against a defined symbol. In the
2942 case where this is a partial link and the output section offset
2943 is greater than 2^25, the linker will return an invalid error
2944 message that the relocation has been truncated. Yes it has been
2945 truncated but no it not important. For this case, disable the
2946 overflow checking. */
2947
2948 howto->complain_on_overflow = complain_overflow_dont;
2949 }
2950
2951 howto->pc_relative = true;
2952 howto->src_mask &= ~3;
2953 howto->dst_mask = howto->src_mask;
2954
2955 /* A PC relative reloc includes the section address. */
2956 addend += input_section->vma;
2957
2958 *relocation = val + addend;
2959 *relocation -= (input_section->output_section->vma +
2960 input_section->output_offset);
2961 return true;
2962 }
2963
2964 boolean
2965 xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
2966 val, addend, relocation, contents)
2967 bfd *input_bfd ATTRIBUTE_UNUSED;
2968 asection *input_section;
2969 bfd *output_bfd ATTRIBUTE_UNUSED;
2970 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2971 struct internal_syment *sym ATTRIBUTE_UNUSED;
2972 struct reloc_howto_struct *howto;
2973 bfd_vma val ATTRIBUTE_UNUSED;
2974 bfd_vma addend;
2975 bfd_vma *relocation;
2976 bfd_byte *contents ATTRIBUTE_UNUSED;
2977 {
2978 howto->pc_relative = true;
2979 howto->src_mask &= ~3;
2980 howto->dst_mask = howto->src_mask;
2981
2982 /* A PC relative reloc includes the section address. */
2983 addend += input_section->vma;
2984
2985 *relocation = val + addend;
2986 *relocation -= (input_section->output_section->vma +
2987 input_section->output_offset);
2988 return true;
2989 }
2990
2991 static boolean
2992 xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
2993 bfd *input_bfd ATTRIBUTE_UNUSED;
2994 bfd_vma val ATTRIBUTE_UNUSED;
2995 bfd_vma relocation ATTRIBUTE_UNUSED;
2996 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2997 {
2998 return false;
2999 }
3000
3001 static boolean
3002 xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
3003 bfd *input_bfd;
3004 bfd_vma val;
3005 bfd_vma relocation;
3006 struct reloc_howto_struct *howto;
3007 {
3008 bfd_vma addrmask, fieldmask, signmask, ss;
3009 bfd_vma a, b, sum;
3010
3011 /* Get the values to be added together. For signed and unsigned
3012 relocations, we assume that all values should be truncated to
3013 the size of an address. For bitfields, all the bits matter.
3014 See also bfd_check_overflow. */
3015 fieldmask = N_ONES (howto->bitsize);
3016 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3017 a = relocation;
3018 b = val & howto->src_mask;
3019
3020 /* Much like unsigned, except no trimming with addrmask. In
3021 addition, the sum overflows if there is a carry out of
3022 the bfd_vma, i.e., the sum is less than either input
3023 operand. */
3024 a >>= howto->rightshift;
3025 b >>= howto->bitpos;
3026
3027 /* Bitfields are sometimes used for signed numbers; for
3028 example, a 13-bit field sometimes represents values in
3029 0..8191 and sometimes represents values in -4096..4095.
3030 If the field is signed and a is -4095 (0x1001) and b is
3031 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3032 0x1fff is 0x3000). It's not clear how to handle this
3033 everywhere, since there is not way to know how many bits
3034 are significant in the relocation, but the original code
3035 assumed that it was fully sign extended, and we will keep
3036 that assumption. */
3037 signmask = (fieldmask >> 1) + 1;
3038
3039 if ((a & ~ fieldmask) != 0)
3040 {
3041 /* Some bits out of the field are set. This might not
3042 be a problem: if this is a signed bitfield, it is OK
3043 iff all the high bits are set, including the sign
3044 bit. We'll try setting all but the most significant
3045 bit in the original relocation value: if this is all
3046 ones, we are OK, assuming a signed bitfield. */
3047 ss = (signmask << howto->rightshift) - 1;
3048 if ((ss | relocation) != ~ (bfd_vma) 0)
3049 return true;
3050 a &= fieldmask;
3051 }
3052
3053 /* We just assume (b & ~ fieldmask) == 0. */
3054
3055 /* We explicitly permit wrap around if this relocation
3056 covers the high bit of an address. The Linux kernel
3057 relies on it, and it is the only way to write assembler
3058 code which can run when loaded at a location 0x80000000
3059 away from the location at which it is linked. */
3060 if (howto->bitsize + howto->rightshift
3061 == bfd_arch_bits_per_address (input_bfd))
3062 return false;
3063
3064 sum = a + b;
3065 if (sum < a || (sum & ~ fieldmask) != 0)
3066 {
3067 /* There was a carry out, or the field overflow. Test
3068 for signed operands again. Here is the overflow test
3069 is as for complain_overflow_signed. */
3070 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3071 return true;
3072 }
3073
3074 return false;
3075 }
3076
3077 static boolean
3078 xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
3079 bfd *input_bfd;
3080 bfd_vma val;
3081 bfd_vma relocation;
3082 struct reloc_howto_struct *howto;
3083 {
3084 bfd_vma addrmask, fieldmask, signmask, ss;
3085 bfd_vma a, b, sum;
3086
3087 /* Get the values to be added together. For signed and unsigned
3088 relocations, we assume that all values should be truncated to
3089 the size of an address. For bitfields, all the bits matter.
3090 See also bfd_check_overflow. */
3091 fieldmask = N_ONES (howto->bitsize);
3092 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3093 a = relocation;
3094 b = val & howto->src_mask;
3095
3096 a = (a & addrmask) >> howto->rightshift;
3097
3098 /* If any sign bits are set, all sign bits must be set.
3099 That is, A must be a valid negative address after
3100 shifting. */
3101 signmask = ~ (fieldmask >> 1);
3102 ss = a & signmask;
3103 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3104 return true;
3105
3106 /* We only need this next bit of code if the sign bit of B
3107 is below the sign bit of A. This would only happen if
3108 SRC_MASK had fewer bits than BITSIZE. Note that if
3109 SRC_MASK has more bits than BITSIZE, we can get into
3110 trouble; we would need to verify that B is in range, as
3111 we do for A above. */
3112 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3113 if ((b & signmask) != 0)
3114 {
3115 /* Set all the bits above the sign bit. */
3116 b -= signmask <<= 1;
3117 }
3118
3119 b = (b & addrmask) >> howto->bitpos;
3120
3121 /* Now we can do the addition. */
3122 sum = a + b;
3123
3124 /* See if the result has the correct sign. Bits above the
3125 sign bit are junk now; ignore them. If the sum is
3126 positive, make sure we did not have all negative inputs;
3127 if the sum is negative, make sure we did not have all
3128 positive inputs. The test below looks only at the sign
3129 bits, and it really just
3130 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3131 */
3132 signmask = (fieldmask >> 1) + 1;
3133 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3134 return true;
3135
3136 return false;
3137 }
3138
3139 static boolean
3140 xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
3141 bfd *input_bfd;
3142 bfd_vma val;
3143 bfd_vma relocation;
3144 struct reloc_howto_struct *howto;
3145 {
3146 bfd_vma addrmask, fieldmask;
3147 bfd_vma a, b, sum;
3148
3149 /* Get the values to be added together. For signed and unsigned
3150 relocations, we assume that all values should be truncated to
3151 the size of an address. For bitfields, all the bits matter.
3152 See also bfd_check_overflow. */
3153 fieldmask = N_ONES (howto->bitsize);
3154 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3155 a = relocation;
3156 b = val & howto->src_mask;
3157
3158 /* Checking for an unsigned overflow is relatively easy:
3159 trim the addresses and add, and trim the result as well.
3160 Overflow is normally indicated when the result does not
3161 fit in the field. However, we also need to consider the
3162 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3163 input is 0x80000000, and bfd_vma is only 32 bits; then we
3164 will get sum == 0, but there is an overflow, since the
3165 inputs did not fit in the field. Instead of doing a
3166 separate test, we can check for this by or-ing in the
3167 operands when testing for the sum overflowing its final
3168 field. */
3169 a = (a & addrmask) >> howto->rightshift;
3170 b = (b & addrmask) >> howto->bitpos;
3171 sum = (a + b) & addrmask;
3172 if ((a | b | sum) & ~ fieldmask)
3173 return true;
3174
3175 return false;
3176 }
3177
3178 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3179 This is currently the only processor which uses XCOFF; I hope that
3180 will never change.
3181
3182 I took the relocation type definitions from two documents:
3183 the PowerPC AIX Version 4 Application Binary Interface, First
3184 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3185 32-Bit Hardware Implementation (June 30, 1994). Differences
3186 between the documents are noted below.
3187
3188 Unsupported r_type's
3189
3190 R_RTB:
3191 R_RRTBI:
3192 R_RRTBA:
3193
3194 These relocs are defined by the PowerPC ABI to be
3195 relative branches which use half of the difference
3196 between the symbol and the program counter. I can't
3197 quite figure out when this is useful. These relocs are
3198 not defined by the PowerOpen ABI.
3199
3200 Supported r_type's
3201
3202 R_POS:
3203 Simple positive relocation.
3204
3205 R_NEG:
3206 Simple negative relocation.
3207
3208 R_REL:
3209 Simple PC relative relocation.
3210
3211 R_TOC:
3212 TOC relative relocation. The value in the instruction in
3213 the input file is the offset from the input file TOC to
3214 the desired location. We want the offset from the final
3215 TOC to the desired location. We have:
3216 isym = iTOC + in
3217 iinsn = in + o
3218 osym = oTOC + on
3219 oinsn = on + o
3220 so we must change insn by on - in.
3221
3222 R_GL:
3223 GL linkage relocation. The value of this relocation
3224 is the address of the entry in the TOC section.
3225
3226 R_TCL:
3227 Local object TOC address. I can't figure out the
3228 difference between this and case R_GL.
3229
3230 R_TRL:
3231 TOC relative relocation. A TOC relative load instruction
3232 which may be changed to a load address instruction.
3233 FIXME: We don't currently implement this optimization.
3234
3235 R_TRLA:
3236 TOC relative relocation. This is a TOC relative load
3237 address instruction which may be changed to a load
3238 instruction. FIXME: I don't know if this is the correct
3239 implementation.
3240
3241 R_BA:
3242 Absolute branch. We don't want to mess with the lower
3243 two bits of the instruction.
3244
3245 R_CAI:
3246 The PowerPC ABI defines this as an absolute call which
3247 may be modified to become a relative call. The PowerOpen
3248 ABI does not define this relocation type.
3249
3250 R_RBA:
3251 Absolute branch which may be modified to become a
3252 relative branch.
3253
3254 R_RBAC:
3255 The PowerPC ABI defines this as an absolute branch to a
3256 fixed address which may be modified to an absolute branch
3257 to a symbol. The PowerOpen ABI does not define this
3258 relocation type.
3259
3260 R_RBRC:
3261 The PowerPC ABI defines this as an absolute branch to a
3262 fixed address which may be modified to a relative branch.
3263 The PowerOpen ABI does not define this relocation type.
3264
3265 R_BR:
3266 Relative branch. We don't want to mess with the lower
3267 two bits of the instruction.
3268
3269 R_CREL:
3270 The PowerPC ABI defines this as a relative call which may
3271 be modified to become an absolute call. The PowerOpen
3272 ABI does not define this relocation type.
3273
3274 R_RBR:
3275 A relative branch which may be modified to become an
3276 absolute branch. FIXME: We don't implement this,
3277 although we should for symbols of storage mapping class
3278 XMC_XO.
3279
3280 R_RL:
3281 The PowerPC AIX ABI describes this as a load which may be
3282 changed to a load address. The PowerOpen ABI says this
3283 is the same as case R_POS.
3284
3285 R_RLA:
3286 The PowerPC AIX ABI describes this as a load address
3287 which may be changed to a load. The PowerOpen ABI says
3288 this is the same as R_POS.
3289 */
3290
3291 boolean
3292 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
3293 input_section, contents, relocs, syms,
3294 sections)
3295 bfd *output_bfd;
3296 struct bfd_link_info *info;
3297 bfd *input_bfd;
3298 asection *input_section;
3299 bfd_byte *contents;
3300 struct internal_reloc *relocs;
3301 struct internal_syment *syms;
3302 asection **sections;
3303 {
3304 struct internal_reloc *rel;
3305 struct internal_reloc *relend;
3306
3307 rel = relocs;
3308 relend = rel + input_section->reloc_count;
3309 for (; rel < relend; rel++)
3310 {
3311 long symndx;
3312 struct xcoff_link_hash_entry *h;
3313 struct internal_syment *sym;
3314 bfd_vma addend;
3315 bfd_vma val;
3316 struct reloc_howto_struct howto;
3317 bfd_vma relocation;
3318 bfd_vma value_to_relocate;
3319 bfd_vma address;
3320 bfd_byte *location;
3321
3322 /* Relocation type R_REF is a special relocation type which is
3323 merely used to prevent garbage collection from occurring for
3324 the csect including the symbol which it references. */
3325 if (rel->r_type == R_REF)
3326 continue;
3327
3328 /* howto */
3329 howto.type = rel->r_type;
3330 howto.rightshift = 0;
3331 howto.bitsize = (rel->r_size & 0x1f) + 1;
3332 howto.size = howto.bitsize > 16 ? 2 : 1;
3333 howto.pc_relative = false;
3334 howto.bitpos = 0;
3335 howto.complain_on_overflow = rel->r_size & 0x80 ?
3336 complain_overflow_signed : complain_overflow_bitfield;
3337 howto.special_function = NULL;
3338 howto.name = "internal";
3339 howto.partial_inplace = true;
3340 howto.src_mask = howto.dst_mask = N_ONES(howto.bitsize);
3341 howto.pcrel_offset = false;
3342
3343 /* symbol */
3344 val = 0;
3345 addend = 0;
3346 h = NULL;
3347 sym = NULL;
3348 symndx = rel->r_symndx;
3349
3350 if (-1 != symndx)
3351 {
3352 asection *sec;
3353
3354 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3355 sym = syms + symndx;
3356 addend = - sym->n_value;
3357
3358 if (NULL == h)
3359 {
3360 sec = sections[symndx];
3361 /* Hack to make sure we use the right TOC anchor value
3362 if this reloc is against the TOC anchor. */
3363 if (sec->name[3] == '0'
3364 && strcmp (sec->name, ".tc0") == 0)
3365 val = xcoff_data (output_bfd)->toc;
3366 else
3367 val = (sec->output_section->vma
3368 + sec->output_offset
3369 + sym->n_value
3370 - sec->vma);
3371 }
3372 else
3373 {
3374 if (h->root.type == bfd_link_hash_defined
3375 || h->root.type == bfd_link_hash_defweak)
3376 {
3377 sec = h->root.u.def.section;
3378 val = (h->root.u.def.value
3379 + sec->output_section->vma
3380 + sec->output_offset);
3381 }
3382 else if (h->root.type == bfd_link_hash_common)
3383 {
3384 sec = h->root.u.c.p->section;
3385 val = (sec->output_section->vma
3386 + sec->output_offset);
3387
3388 }
3389 else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT)))
3390 && ! info->relocateable)
3391 {
3392 if (! ((*info->callbacks->undefined_symbol)
3393 (info, h->root.root.string, input_bfd, input_section,
3394 rel->r_vaddr - input_section->vma, true)))
3395 return false;
3396
3397 /* Don't try to process the reloc. It can't help, and
3398 it may generate another error. */
3399 continue;
3400 }
3401 }
3402 }
3403
3404 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3405 || (false == xcoff_calculate_relocation[rel->r_type]
3406 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3407 addend, &relocation, contents)))
3408 return false;
3409
3410 /* address */
3411 address = rel->r_vaddr - input_section->vma;
3412 location = contents + address;
3413
3414 if (address > input_section->_raw_size)
3415 abort();
3416
3417 /* Get the value we are going to relocate. */
3418 if (1 == howto.size)
3419 value_to_relocate = bfd_get_16 (input_bfd, location);
3420 else
3421 value_to_relocate = bfd_get_32 (input_bfd, location);
3422
3423 /* overflow.
3424
3425 FIXME: We may drop bits during the addition
3426 which we don't check for. We must either check at every single
3427 operation, which would be tedious, or we must do the computations
3428 in a type larger than bfd_vma, which would be inefficient. */
3429
3430 if ((unsigned int) howto.complain_on_overflow >=
3431 XCOFF_MAX_COMPLAIN_OVERFLOW)
3432 abort();
3433
3434 if ((true == xcoff_complain_overflow[howto.complain_on_overflow]
3435 (input_bfd, value_to_relocate, relocation, &howto)))
3436 {
3437 const char *name;
3438 char buf[SYMNMLEN + 1];
3439 char reloc_type_name[10];
3440
3441 if (symndx == -1)
3442 {
3443 name = "*ABS*";
3444 }
3445 else if (h != NULL)
3446 {
3447 name = h->root.root.string;
3448 }
3449 else
3450 {
3451 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3452 if (name == NULL)
3453 name = "UNKNOWN";
3454 }
3455 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3456
3457 if (! ((*info->callbacks->reloc_overflow)
3458 (info, name, reloc_type_name, (bfd_vma) 0, input_bfd,
3459 input_section, rel->r_vaddr - input_section->vma)))
3460 return false;
3461 }
3462
3463 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3464 value_to_relocate = ((value_to_relocate & ~howto.dst_mask) |
3465 (((value_to_relocate & howto.src_mask) +
3466 relocation) & howto.dst_mask));
3467
3468 /* Put the value back in the object file. */
3469 if (1 == howto.size)
3470 bfd_put_16 (input_bfd, value_to_relocate, location);
3471 else
3472 bfd_put_32 (input_bfd, value_to_relocate, location);
3473 }
3474
3475 return true;
3476 }
3477
3478 static boolean
3479 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
3480 bfd *abfd ATTRIBUTE_UNUSED;
3481 struct xcoff_loader_info *ldinfo;
3482 struct internal_ldsym *ldsym;
3483 const char *name;
3484 {
3485 size_t len;
3486 len = strlen (name);
3487
3488 if (len <= SYMNMLEN)
3489 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3490 else
3491 {
3492 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3493 {
3494 bfd_size_type newalc;
3495 bfd_byte *newstrings;
3496
3497 newalc = ldinfo->string_alc * 2;
3498 if (newalc == 0)
3499 newalc = 32;
3500 while (ldinfo->string_size + len + 3 > newalc)
3501 newalc *= 2;
3502
3503 newstrings = ((bfd_byte *)
3504 bfd_realloc ((PTR) ldinfo->strings, newalc));
3505 if (newstrings == NULL)
3506 {
3507 ldinfo->failed = true;
3508 return false;
3509 }
3510 ldinfo->string_alc = newalc;
3511 ldinfo->strings = newstrings;
3512 }
3513
3514 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3515 ldinfo->strings + ldinfo->string_size);
3516 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3517 ldsym->_l._l_l._l_zeroes = 0;
3518 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3519 ldinfo->string_size += len + 3;
3520 }
3521
3522 return true;
3523 }
3524
3525 static boolean
3526 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3527 struct internal_syment *sym,
3528 const char *name)
3529 {
3530 if (strlen (name) <= SYMNMLEN)
3531 {
3532 strncpy (sym->_n._n_name, name, SYMNMLEN);
3533 }
3534 else
3535 {
3536 boolean hash;
3537 bfd_size_type indx;
3538
3539 hash = true;
3540 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3541 hash = false;
3542 indx = _bfd_stringtab_add (strtab, name, hash, false);
3543 if (indx == (bfd_size_type) -1)
3544 return false;
3545 sym->_n._n_n._n_zeroes = 0;
3546 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3547 }
3548 return true;
3549 }
3550
3551 static asection *
3552 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
3553 bfd *abfd;
3554 union internal_auxent *aux;
3555 const char *symbol_name;
3556 {
3557 asection *return_value = NULL;
3558
3559 /* .sv64 = x_smclas == 17
3560 This is an invalid csect for 32 bit apps. */
3561 static const char *names[19] =
3562 {
3563 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3564 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
3565 ".td", NULL, ".sv3264"
3566 };
3567
3568 if ((19 >= aux->x_csect.x_smclas) &&
3569 (NULL != names[aux->x_csect.x_smclas]))
3570 {
3571 return_value = bfd_make_section_anyway
3572 (abfd, names[aux->x_csect.x_smclas]);
3573 }
3574 else
3575 {
3576 (*_bfd_error_handler)
3577 (_("%s: symbol `%s' has unrecognized smclas %d"),
3578 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
3579 bfd_set_error (bfd_error_bad_value);
3580 }
3581
3582 return return_value;
3583 }
3584
3585 static boolean
3586 xcoff_is_lineno_count_overflow (abfd, value)
3587 bfd *abfd ATTRIBUTE_UNUSED;
3588 bfd_vma value;
3589 {
3590 if (0xffff <= value)
3591 return true;
3592
3593 return false;
3594 }
3595
3596 static boolean
3597 xcoff_is_reloc_count_overflow (abfd, value)
3598 bfd *abfd ATTRIBUTE_UNUSED;
3599 bfd_vma value;
3600 {
3601 if (0xffff <= value)
3602 return true;
3603
3604 return false;
3605 }
3606
3607 static bfd_vma
3608 xcoff_loader_symbol_offset (abfd, ldhdr)
3609 bfd *abfd;
3610 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
3611 {
3612 return bfd_xcoff_ldhdrsz(abfd);
3613 }
3614
3615 static bfd_vma
3616 xcoff_loader_reloc_offset (abfd, ldhdr)
3617 bfd *abfd;
3618 struct internal_ldhdr *ldhdr;
3619 {
3620 return bfd_xcoff_ldhdrsz(abfd) +
3621 (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd));
3622 }
3623
3624 static boolean
3625 xcoff_generate_rtinit (abfd, init, fini, rtld)
3626 bfd *abfd;
3627 const char *init;
3628 const char *fini;
3629 boolean rtld;
3630 {
3631 bfd_byte filehdr_ext[FILHSZ];
3632 bfd_byte scnhdr_ext[SCNHSZ];
3633 bfd_byte syment_ext[SYMESZ * 10];
3634 bfd_byte reloc_ext[RELSZ * 3];
3635 bfd_byte *data_buffer;
3636 bfd_size_type data_buffer_size;
3637 bfd_byte *string_table = NULL, *st_tmp = NULL;
3638 bfd_size_type string_table_size;
3639 bfd_vma val;
3640 size_t initsz, finisz;
3641 struct internal_filehdr filehdr;
3642 struct internal_scnhdr scnhdr;
3643 struct internal_syment syment;
3644 union internal_auxent auxent;
3645 struct internal_reloc reloc;
3646
3647 char *data_name = ".data";
3648 char *rtinit_name = "__rtinit";
3649 char *rtld_name = "__rtld";
3650
3651 if (! bfd_xcoff_rtinit_size (abfd))
3652 return false;
3653
3654 initsz = (init == NULL ? 0 : 1 + strlen (init));
3655 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3656
3657 /* file header */
3658 memset (filehdr_ext, 0, FILHSZ);
3659 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3660 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3661 filehdr.f_nscns = 1;
3662 filehdr.f_timdat = 0;
3663 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3664 filehdr.f_symptr = 0; /* set below */
3665 filehdr.f_opthdr = 0;
3666 filehdr.f_flags = 0;
3667
3668 /* section header */
3669 memset (scnhdr_ext, 0, SCNHSZ);
3670 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3671 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3672 scnhdr.s_paddr = 0;
3673 scnhdr.s_vaddr = 0;
3674 scnhdr.s_size = 0; /* set below */
3675 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3676 scnhdr.s_relptr = 0; /* set below */
3677 scnhdr.s_lnnoptr = 0;
3678 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3679 scnhdr.s_nlnno = 0;
3680 scnhdr.s_flags = STYP_DATA;
3681
3682 /* .data
3683 0x0000 0x00000000 : rtl
3684 0x0004 0x00000010 : offset to init, or 0
3685 0x0008 0x00000028 : offset to fini, or 0
3686 0x000C 0x0000000C : size of descriptor
3687 0x0010 0x00000000 : init, needs a reloc
3688 0x0014 0x00000040 : offset to init name
3689 0x0018 0x00000000 : flags, padded to a word
3690 0x001C 0x00000000 : empty init
3691 0x0020 0x00000000 :
3692 0x0024 0x00000000 :
3693 0x0028 0x00000000 : fini, needs a reloc
3694 0x002C 0x00000??? : offset to fini name
3695 0x0030 0x00000000 : flags, padded to a word
3696 0x0034 0x00000000 : empty fini
3697 0x0038 0x00000000 :
3698 0x003C 0x00000000 :
3699 0x0040 init name
3700 0x0040 + initsz fini name */
3701
3702 data_buffer_size = 0x0040 + initsz + finisz;
3703 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
3704 data_buffer = NULL;
3705 data_buffer = (bfd_byte *) bfd_malloc (data_buffer_size);
3706 if (data_buffer == NULL)
3707 return false;
3708
3709 memset (data_buffer, 0, data_buffer_size);
3710
3711 if (initsz)
3712 {
3713 val = 0x10;
3714 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3715 val = 0x40;
3716 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3717 memcpy (&data_buffer[val], init, initsz);
3718 }
3719
3720 if (finisz)
3721 {
3722 val = 0x28;
3723 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3724 val = 0x40 + initsz;
3725 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3726 memcpy (&data_buffer[val], fini, finisz);
3727 }
3728
3729 val = 0x0C;
3730 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3731
3732 scnhdr.s_size = data_buffer_size;
3733
3734 /* string table */
3735 string_table_size = 0;
3736 if (initsz > 9)
3737 string_table_size += initsz;
3738 if (finisz > 9)
3739 string_table_size += finisz;
3740 if (string_table_size)
3741 {
3742 string_table_size += 4;
3743 string_table = (bfd_byte *)bfd_malloc (string_table_size);
3744 memset (string_table, 0, string_table_size);
3745 val = string_table_size;
3746 bfd_h_put_32 (abfd, val, &string_table[0]);
3747 st_tmp = string_table + 4;
3748 }
3749
3750 /* symbols
3751 0. .data csect
3752 2. __rtinit
3753 4. init function
3754 6. fini function
3755 8. __rtld */
3756 memset (syment_ext, 0, 10 * SYMESZ);
3757 memset (reloc_ext, 0, 3 * RELSZ);
3758
3759 /* .data csect */
3760 memset (&syment, 0, sizeof (struct internal_syment));
3761 memset (&auxent, 0, sizeof (union internal_auxent));
3762 memcpy (syment._n._n_name, data_name, strlen (data_name));
3763 syment.n_scnum = 1;
3764 syment.n_sclass = C_HIDEXT;
3765 syment.n_numaux = 1;
3766 auxent.x_csect.x_scnlen.l = data_buffer_size;
3767 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3768 auxent.x_csect.x_smclas = XMC_RW;
3769 bfd_coff_swap_sym_out (abfd, &syment,
3770 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3771 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3772 syment.n_numaux,
3773 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3774 filehdr.f_nsyms += 2;
3775
3776 /* __rtinit */
3777 memset (&syment, 0, sizeof (struct internal_syment));
3778 memset (&auxent, 0, sizeof (union internal_auxent));
3779 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3780 syment.n_scnum = 1;
3781 syment.n_sclass = C_EXT;
3782 syment.n_numaux = 1;
3783 auxent.x_csect.x_smtyp = XTY_LD;
3784 auxent.x_csect.x_smclas = XMC_RW;
3785 bfd_coff_swap_sym_out (abfd, &syment,
3786 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3787 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3788 syment.n_numaux,
3789 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3790 filehdr.f_nsyms += 2;
3791
3792 /* init */
3793 if (initsz)
3794 {
3795 memset (&syment, 0, sizeof (struct internal_syment));
3796 memset (&auxent, 0, sizeof (union internal_auxent));
3797
3798 if (initsz > 9)
3799 {
3800 syment._n._n_n._n_offset = st_tmp - string_table;
3801 memcpy (st_tmp, init, initsz);
3802 st_tmp += initsz;
3803 }
3804 else
3805 memcpy (syment._n._n_name, init, initsz - 1);
3806
3807 syment.n_sclass = C_EXT;
3808 syment.n_numaux = 1;
3809 bfd_coff_swap_sym_out (abfd, &syment,
3810 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3811 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3812 syment.n_numaux,
3813 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3814
3815 /* reloc */
3816 memset (&reloc, 0, sizeof (struct internal_reloc));
3817 reloc.r_vaddr = 0x0010;
3818 reloc.r_symndx = filehdr.f_nsyms;
3819 reloc.r_type = R_POS;
3820 reloc.r_size = 31;
3821 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3822
3823 filehdr.f_nsyms += 2;
3824 scnhdr.s_nreloc += 1;
3825 }
3826
3827 /* fini */
3828 if (finisz)
3829 {
3830 memset (&syment, 0, sizeof (struct internal_syment));
3831 memset (&auxent, 0, sizeof (union internal_auxent));
3832
3833 if (finisz > 9)
3834 {
3835 syment._n._n_n._n_offset = st_tmp - string_table;
3836 memcpy (st_tmp, fini, finisz);
3837 st_tmp += finisz;
3838 }
3839 else
3840 memcpy (syment._n._n_name, fini, finisz - 1);
3841
3842 syment.n_sclass = C_EXT;
3843 syment.n_numaux = 1;
3844 bfd_coff_swap_sym_out (abfd, &syment,
3845 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3846 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3847 syment.n_numaux,
3848 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3849
3850 /* reloc */
3851 memset (&reloc, 0, sizeof (struct internal_reloc));
3852 reloc.r_vaddr = 0x0028;
3853 reloc.r_symndx = filehdr.f_nsyms;
3854 reloc.r_type = R_POS;
3855 reloc.r_size = 31;
3856 bfd_coff_swap_reloc_out (abfd, &reloc,
3857 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3858
3859 filehdr.f_nsyms += 2;
3860 scnhdr.s_nreloc += 1;
3861 }
3862
3863 if (rtld)
3864 {
3865 memset (&syment, 0, sizeof (struct internal_syment));
3866 memset (&auxent, 0, sizeof (union internal_auxent));
3867 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3868 syment.n_sclass = C_EXT;
3869 syment.n_numaux = 1;
3870 bfd_coff_swap_sym_out (abfd, &syment,
3871 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3872 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3873 syment.n_numaux,
3874 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3875
3876 /* reloc */
3877 memset (&reloc, 0, sizeof (struct internal_reloc));
3878 reloc.r_vaddr = 0x0000;
3879 reloc.r_symndx = filehdr.f_nsyms;
3880 reloc.r_type = R_POS;
3881 reloc.r_size = 31;
3882 bfd_coff_swap_reloc_out (abfd, &reloc,
3883 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3884
3885 filehdr.f_nsyms += 2;
3886 scnhdr.s_nreloc += 1;
3887 }
3888
3889 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3890 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3891
3892 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3893 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3894 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3895 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3896 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3897 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3898 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3899 bfd_bwrite (string_table, string_table_size, abfd);
3900
3901 free (data_buffer);
3902 data_buffer = NULL;
3903
3904 return true;
3905 }
3906
3907
3908 static reloc_howto_type xcoff_dynamic_reloc =
3909 HOWTO (0, /* type */
3910 0, /* rightshift */
3911 2, /* size (0 = byte, 1 = short, 2 = long) */
3912 32, /* bitsize */
3913 false, /* pc_relative */
3914 0, /* bitpos */
3915 complain_overflow_bitfield, /* complain_on_overflow */
3916 0, /* special_function */
3917 "R_POS", /* name */
3918 true, /* partial_inplace */
3919 0xffffffff, /* src_mask */
3920 0xffffffff, /* dst_mask */
3921 false); /* pcrel_offset */
3922
3923 /* glink
3924
3925 The first word of global linkage code must be modified by filling in
3926 the correct TOC offset. */
3927
3928 static unsigned long xcoff_glink_code[9] =
3929 {
3930 0x81820000, /* lwz r12,0(r2) */
3931 0x90410014, /* stw r2,20(r1) */
3932 0x800c0000, /* lwz r0,0(r12) */
3933 0x804c0004, /* lwz r2,4(r12) */
3934 0x7c0903a6, /* mtctr r0 */
3935 0x4e800420, /* bctr */
3936 0x00000000, /* start of traceback table */
3937 0x000c8000, /* traceback table */
3938 0x00000000, /* traceback table */
3939 };
3940
3941
3942 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
3943 {
3944 { /* COFF backend, defined in libcoff.h. */
3945 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
3946 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
3947 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
3948 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
3949 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
3950 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
3951 xcoff_swap_reloc_out, /* _bfd_swap_reloc_out */
3952 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
3953 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
3954 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
3955 FILHSZ, /* _bfd_filhsz */
3956 AOUTSZ, /* _bfd_aoutsz */
3957 SCNHSZ, /* _bfd_scnhsz */
3958 SYMESZ, /* _bfd_symesz */
3959 AUXESZ, /* _bfd_auxesz */
3960 RELSZ, /* _bfd_relsz */
3961 LINESZ, /* _bfd_linesz */
3962 FILNMLEN, /* _bfd_filnmlen */
3963 true, /* _bfd_coff_long_filenames */
3964 false, /* _bfd_coff_long_section_names */
3965 (3), /* _bfd_coff_default_section_alignment_power */
3966 false, /* _bfd_coff_force_symnames_in_strings */
3967 2, /* _bfd_coff_debug_string_prefix_length */
3968 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
3969 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
3970 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
3971 xcoff_swap_reloc_in, /* _bfd_reloc_in */
3972 coff_bad_format_hook, /* _bfd_bad_format_hook */
3973 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
3974 coff_mkobject_hook, /* _bfd_mkobject_hook */
3975 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
3976 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
3977 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
3978 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
3979 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
3980 coff_print_aux, /* bfd_coff_print_aux */
3981 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
3982 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
3983 NULL, /* bfd_coff_sym_is_global */
3984 coff_compute_section_file_positions, /* _bfd_coff_compute_section_file_positions */
3985 NULL, /* _bfd_coff_start_final_link */
3986 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
3987 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
3988 NULL, /* _bfd_coff_addust_symndx */
3989 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3990 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3991 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3992 },
3993
3994 0x01DF, /* magic number */
3995 bfd_arch_rs6000, /* architecture */
3996 bfd_mach_rs6k, /* machine */
3997
3998 /* Function pointers to xcoff specific swap routines. */
3999 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
4000 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
4001 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
4002 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
4003 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
4004 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
4005
4006 /* Sizes. */
4007 LDHDRSZ, /* _xcoff_ldhdrsz */
4008 LDSYMSZ, /* _xcoff_ldsymsz */
4009 LDRELSZ, /* _xcoff_ldrelsz */
4010 12, /* _xcoff_function_descriptor_size */
4011 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
4012
4013 /* Versions. */
4014 1, /* _xcoff_ldhdr_version */
4015
4016 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
4017 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
4018 & xcoff_dynamic_reloc, /* dynamic reloc howto */
4019 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
4020
4021 /* Lineno and reloc count overflow. */
4022 xcoff_is_lineno_count_overflow,
4023 xcoff_is_reloc_count_overflow,
4024
4025 xcoff_loader_symbol_offset,
4026 xcoff_loader_reloc_offset,
4027
4028 /* glink. */
4029 & xcoff_glink_code[0],
4030 (36), /* _xcoff_glink_size */
4031
4032 /* rtinit */
4033 64, /* _xcoff_rtinit_size */
4034 xcoff_generate_rtinit, /* _xcoff_generate_rtinit */
4035 };
4036
4037 /* The transfer vector that leads the outside world to all of the above. */
4038 const bfd_target rs6000coff_vec =
4039 {
4040 "aixcoff-rs6000",
4041 bfd_target_xcoff_flavour,
4042 BFD_ENDIAN_BIG, /* data byte order is big */
4043 BFD_ENDIAN_BIG, /* header byte order is big */
4044
4045 (HAS_RELOC | EXEC_P | /* object flags */
4046 HAS_LINENO | HAS_DEBUG | DYNAMIC |
4047 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4048
4049 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4050 0, /* leading char */
4051 '/', /* ar_pad_char */
4052 15, /* ar_max_namelen??? FIXMEmgo */
4053
4054 /* data */
4055 bfd_getb64, /* bfd_getx64 */
4056 bfd_getb_signed_64, /* bfd_getx_signed_64 */
4057 bfd_putb64, /* bfd_putx64 */
4058 bfd_getb32, /* bfd_getx32 */
4059 bfd_getb_signed_32, /* bfd_getx_signed_32 */
4060 bfd_putb32, /* bfd_putx32 */
4061 bfd_getb16, /* bfd_getx16 */
4062 bfd_getb_signed_16, /* bfd_getx_signed_16 */
4063 bfd_putb16, /* bfd_putx16 */
4064
4065 /* hdrs */
4066 bfd_getb64, /* bfd_h_getx64 */
4067 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
4068 bfd_putb64, /* bfd_h_putx64 */
4069 bfd_getb32, /* bfd_h_getx32 */
4070 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
4071 bfd_putb32, /* bfd_h_putx32 */
4072 bfd_getb16, /* bfd_h_getx16 */
4073 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
4074 bfd_putb16, /* bfd_h_putx16 */
4075
4076 { /* bfd_check_format */
4077 _bfd_dummy_target,
4078 coff_object_p,
4079 _bfd_xcoff_archive_p,
4080 CORE_FILE_P
4081 },
4082
4083 { /* bfd_set_format */
4084 bfd_false,
4085 coff_mkobject,
4086 _bfd_generic_mkarchive,
4087 bfd_false
4088 },
4089
4090 {/* bfd_write_contents */
4091 bfd_false,
4092 coff_write_object_contents,
4093 _bfd_xcoff_write_archive_contents,
4094 bfd_false
4095 },
4096
4097 /* Generic */
4098 bfd_true, /* _close_and_cleanup */
4099 bfd_true, /* _bfd_free_cached_info */
4100 coff_new_section_hook, /* _new_section_hook */
4101 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
4102 /* _bfd_get_section_contents_in_window */
4103 _bfd_generic_get_section_contents_in_window,
4104
4105 /* Copy */
4106 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
4107 /* _bfd_merge_private_bfd_data */
4108 ((boolean (*) (bfd *, bfd *)) bfd_true),
4109 /* _bfd_copy_pivate_section_data */
4110 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4111 /* _bfd_copy_private_symbol_data */
4112 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4113 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
4114 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
4115
4116 /* Core */
4117 coff_core_file_failing_command, /* _core_file_failing_command */
4118 coff_core_file_failing_signal, /* _core_file_failing_signal */
4119 /* _core_file_matches_executable_p */
4120 coff_core_file_matches_executable_p,
4121
4122 /* Archive */
4123 _bfd_xcoff_slurp_armap, /* _slurp_armap */
4124 /* XCOFF archives do not have
4125 anything which corresponds to
4126 an extended name table. */
4127 bfd_false, /* _slurp_extended_name_table */
4128 /* _construct_extended_name_table */
4129 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4130 bfd_dont_truncate_arname, /* _truncate_arname */
4131 _bfd_xcoff_write_armap, /* _write_armap */
4132 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
4133 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
4134 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
4135 _bfd_xcoff_stat_arch_elt, /* _generic_stat_arch_elt */
4136 /* XCOFF archives do not have
4137 a timestamp. */
4138 bfd_true, /* _update_armap_timestamp */
4139
4140 /* Symbols */
4141 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
4142 coff_get_symtab, /* _get_symtab */
4143 coff_make_empty_symbol, /* _make_empty_symbol */
4144 coff_print_symbol, /* _print_symbol */
4145 coff_get_symbol_info, /* _get_symbol_info */
4146 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
4147 coff_get_lineno, /* _get_lineno */
4148 coff_find_nearest_line, /* _find_nearest_line */
4149 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
4150 _bfd_generic_read_minisymbols, /* _read_minisymbols */
4151 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
4152
4153 /* Reloc */
4154 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
4155 coff_canonicalize_reloc, /* _cononicalize_reloc */
4156 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
4157
4158 /* Write */
4159 coff_set_arch_mach, /* _set_arch_mach */
4160 coff_set_section_contents, /* _set_section_contents */
4161
4162 /* Link */
4163 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
4164 /* _bfd_get_relocated_section_contents */
4165 bfd_generic_get_relocated_section_contents,
4166 bfd_generic_relax_section, /* _bfd_relax_section */
4167 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
4168 _bfd_generic_link_hash_table_free, /* _bfd_link_hash_table_free */
4169 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
4170 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
4171 _bfd_generic_link_split_section, /* _bfd_link_split_section */
4172 bfd_generic_gc_sections, /* _bfd_gc_sections */
4173 bfd_generic_merge_sections, /* _bfd_merge_sections */
4174
4175 /* Dynamic */
4176 /* _get_dynamic_symtab_upper_bound */
4177 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4178 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
4179 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
4180 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
4181
4182 /* Opposite endian version, none exists */
4183 NULL,
4184
4185 /* back end data */
4186 (void *) &bfd_xcoff_backend_data,
4187 };
4188
4189 /*
4190 * xcoff-powermac target
4191 * Old target.
4192 * Only difference between this target and the rs6000 target is the
4193 * the default architecture and machine type used in coffcode.h
4194 *
4195 * PowerPC Macs use the same magic numbers as RS/6000
4196 * (because that's how they were bootstrapped originally),
4197 * but they are always PowerPC architecture.
4198 */
4199 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4200 {
4201 { /* COFF backend, defined in libcoff.h */
4202 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
4203 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
4204 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
4205 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
4206 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
4207 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
4208 xcoff_swap_reloc_out, /* _bfd_swap_reloc_out */
4209 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
4210 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
4211 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
4212 FILHSZ, /* _bfd_filhsz */
4213 AOUTSZ, /* _bfd_aoutsz */
4214 SCNHSZ, /* _bfd_scnhsz */
4215 SYMESZ, /* _bfd_symesz */
4216 AUXESZ, /* _bfd_auxesz */
4217 RELSZ, /* _bfd_relsz */
4218 LINESZ, /* _bfd_linesz */
4219 FILNMLEN, /* _bfd_filnmlen */
4220 true, /* _bfd_coff_long_filenames */
4221 false, /* _bfd_coff_long_section_names */
4222 (3), /* _bfd_coff_default_section_alignment_power */
4223 false, /* _bfd_coff_force_symnames_in_strings */
4224 2, /* _bfd_coff_debug_string_prefix_length */
4225 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
4226 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
4227 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
4228 xcoff_swap_reloc_in, /* _bfd_reloc_in */
4229 coff_bad_format_hook, /* _bfd_bad_format_hook */
4230 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
4231 coff_mkobject_hook, /* _bfd_mkobject_hook */
4232 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
4233 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
4234 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
4235 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
4236 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
4237 coff_print_aux, /* bfd_coff_print_aux */
4238 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
4239 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
4240 NULL, /* bfd_coff_sym_is_global */
4241 /* _bfd_coff_compute_section_file_positions */
4242 coff_compute_section_file_positions,
4243 NULL, /* _bfd_coff_start_final_link */
4244 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
4245 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
4246 NULL, /* _bfd_coff_addust_symndx */
4247 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
4248 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
4249 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
4250 },
4251
4252 0x01DF, /* magic number */
4253 bfd_arch_powerpc, /* architecture */
4254 bfd_mach_ppc, /* machine */
4255
4256 /* function pointers to xcoff specific swap routines */
4257 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
4258 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
4259 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
4260 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
4261 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
4262 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
4263
4264 /* sizes */
4265 LDHDRSZ, /* _xcoff_ldhdrsz */
4266 LDSYMSZ, /* _xcoff_ldsymsz */
4267 LDRELSZ, /* _xcoff_ldrelsz */
4268 12, /* _xcoff_function_descriptor_size */
4269 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
4270
4271 /* versions */
4272 1, /* _xcoff_ldhdr_version */
4273
4274 /* xcoff vs xcoff64 putting symbol names */
4275 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
4276 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
4277
4278 &xcoff_dynamic_reloc, /* dynamic reloc howto */
4279
4280 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
4281
4282 /* lineno and reloc count overflow */
4283 xcoff_is_lineno_count_overflow,
4284 xcoff_is_reloc_count_overflow,
4285
4286 xcoff_loader_symbol_offset,
4287 xcoff_loader_reloc_offset,
4288
4289 /* glink */
4290 &xcoff_glink_code[0],
4291 (36), /* _xcoff_glink_size */
4292
4293 /* rtinit */
4294 0, /* _xcoff_rtinit_size */
4295 xcoff_generate_rtinit, /* _xcoff_generate_rtinit */
4296 };
4297
4298 /* The transfer vector that leads the outside world to all of the above. */
4299 const bfd_target pmac_xcoff_vec =
4300 {
4301 "xcoff-powermac",
4302 bfd_target_xcoff_flavour,
4303 BFD_ENDIAN_BIG, /* data byte order is big */
4304 BFD_ENDIAN_BIG, /* header byte order is big */
4305
4306 (HAS_RELOC | EXEC_P | /* object flags */
4307 HAS_LINENO | HAS_DEBUG | DYNAMIC |
4308 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4309
4310 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4311 0, /* leading char */
4312 '/', /* ar_pad_char */
4313 15, /* ar_max_namelen??? FIXMEmgo */
4314
4315 /* data */
4316 bfd_getb64, /* bfd_getx64 */
4317 bfd_getb_signed_64, /* bfd_getx_signed_64 */
4318 bfd_putb64, /* bfd_putx64 */
4319 bfd_getb32, /* bfd_getx32 */
4320 bfd_getb_signed_32, /* bfd_getx_signed_32 */
4321 bfd_putb32, /* bfd_putx32 */
4322 bfd_getb16, /* bfd_getx16 */
4323 bfd_getb_signed_16, /* bfd_getx_signed_16 */
4324 bfd_putb16, /* bfd_putx16 */
4325
4326 /* hdrs */
4327 bfd_getb64, /* bfd_h_getx64 */
4328 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
4329 bfd_putb64, /* bfd_h_putx64 */
4330 bfd_getb32, /* bfd_h_getx32 */
4331 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
4332 bfd_putb32, /* bfd_h_putx32 */
4333 bfd_getb16, /* bfd_h_getx16 */
4334 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
4335 bfd_putb16, /* bfd_h_putx16 */
4336
4337 { /* bfd_check_format */
4338 _bfd_dummy_target,
4339 coff_object_p,
4340 _bfd_xcoff_archive_p,
4341 CORE_FILE_P
4342 },
4343
4344 { /* bfd_set_format */
4345 bfd_false,
4346 coff_mkobject,
4347 _bfd_generic_mkarchive,
4348 bfd_false
4349 },
4350
4351 {/* bfd_write_contents */
4352 bfd_false,
4353 coff_write_object_contents,
4354 _bfd_xcoff_write_archive_contents,
4355 bfd_false
4356 },
4357
4358 /* Generic */
4359 bfd_true, /* _close_and_cleanup */
4360 bfd_true, /* _bfd_free_cached_info */
4361 coff_new_section_hook, /* _new_section_hook */
4362 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
4363 /* _bfd_get_section_contents_in_window */
4364 _bfd_generic_get_section_contents_in_window,
4365
4366 /* Copy */
4367 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
4368 /* _bfd_merge_private_bfd_data */
4369 ((boolean (*) (bfd *, bfd *)) bfd_true),
4370 /* _bfd_copy_pivate_section_data */
4371 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4372 /* _bfd_copy_private_symbol_data */
4373 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4374 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
4375 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
4376
4377 /* Core */
4378 coff_core_file_failing_command, /* _core_file_failing_command */
4379 coff_core_file_failing_signal, /* _core_file_failing_signal */
4380 /* _core_file_matches_executable_p */
4381 coff_core_file_matches_executable_p,
4382
4383 /* Archive */
4384 _bfd_xcoff_slurp_armap, /* _slurp_armap */
4385 /* XCOFF archives do not have
4386 anything which corresponds to
4387 an extended name table. */
4388 bfd_false, /* _slurp_extended_name_table */
4389 /* _construct_extended_name_table */
4390 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4391 bfd_dont_truncate_arname, /* _truncate_arname */
4392 _bfd_xcoff_write_armap, /* _write_armap */
4393 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
4394 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
4395 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
4396 _bfd_xcoff_stat_arch_elt, /* _generic_stat_arch_elt */
4397 /* XCOFF archives do not have
4398 a timestamp. */
4399 bfd_true, /* _update_armap_timestamp */
4400
4401 /* Symbols */
4402 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
4403 coff_get_symtab, /* _get_symtab */
4404 coff_make_empty_symbol, /* _make_empty_symbol */
4405 coff_print_symbol, /* _print_symbol */
4406 coff_get_symbol_info, /* _get_symbol_info */
4407 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
4408 coff_get_lineno, /* _get_lineno */
4409 coff_find_nearest_line, /* _find_nearest_line */
4410 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
4411 _bfd_generic_read_minisymbols, /* _read_minisymbols */
4412 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
4413
4414 /* Reloc */
4415 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
4416 coff_canonicalize_reloc, /* _cononicalize_reloc */
4417 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
4418
4419 /* Write */
4420 coff_set_arch_mach, /* _set_arch_mach */
4421 coff_set_section_contents, /* _set_section_contents */
4422
4423 /* Link */
4424 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
4425 /* _bfd_get_relocated_section_contents */
4426 bfd_generic_get_relocated_section_contents,
4427 bfd_generic_relax_section, /* _bfd_relax_section */
4428 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
4429 _bfd_generic_link_hash_table_free, /* _bfd_link_hash_table_free */
4430 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
4431 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
4432 _bfd_generic_link_split_section, /* _bfd_link_split_section */
4433 bfd_generic_gc_sections, /* _bfd_gc_sections */
4434 bfd_generic_merge_sections, /* _bfd_merge_sections */
4435
4436 /* Dynamic */
4437 /* _get_dynamic_symtab_upper_bound */
4438 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4439 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
4440 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
4441 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
4442
4443 /* Opposite endian version, none exists */
4444 NULL,
4445
4446 /* back end data */
4447 (void *) &bfd_pmac_xcoff_backend_data,
4448 };
This page took 0.122296 seconds and 4 git commands to generate.