1 /* BFD back-end for IBM RS/6000 "XCOFF64" files.
3 Free Software Foundation, Inc.
4 Written Clinton Popetz.
5 Contributed by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "coff/internal.h"
28 #include "coff/xcoff.h"
29 #include "coff/rs6k64.h"
33 #define GET_FILEHDR_SYMPTR H_GET_64
34 #define PUT_FILEHDR_SYMPTR H_PUT_64
35 #define GET_AOUTHDR_DATA_START H_GET_64
36 #define PUT_AOUTHDR_DATA_START H_PUT_64
37 #define GET_AOUTHDR_TEXT_START H_GET_64
38 #define PUT_AOUTHDR_TEXT_START H_PUT_64
39 #define GET_AOUTHDR_TSIZE H_GET_64
40 #define PUT_AOUTHDR_TSIZE H_PUT_64
41 #define GET_AOUTHDR_DSIZE H_GET_64
42 #define PUT_AOUTHDR_DSIZE H_PUT_64
43 #define GET_AOUTHDR_BSIZE H_GET_64
44 #define PUT_AOUTHDR_BSIZE H_PUT_64
45 #define GET_AOUTHDR_ENTRY H_GET_64
46 #define PUT_AOUTHDR_ENTRY H_PUT_64
47 #define GET_SCNHDR_PADDR H_GET_64
48 #define PUT_SCNHDR_PADDR H_PUT_64
49 #define GET_SCNHDR_VADDR H_GET_64
50 #define PUT_SCNHDR_VADDR H_PUT_64
51 #define GET_SCNHDR_SIZE H_GET_64
52 #define PUT_SCNHDR_SIZE H_PUT_64
53 #define GET_SCNHDR_SCNPTR H_GET_64
54 #define PUT_SCNHDR_SCNPTR H_PUT_64
55 #define GET_SCNHDR_RELPTR H_GET_64
56 #define PUT_SCNHDR_RELPTR H_PUT_64
57 #define GET_SCNHDR_LNNOPTR H_GET_64
58 #define PUT_SCNHDR_LNNOPTR H_PUT_64
59 #define GET_SCNHDR_NRELOC H_GET_32
60 #define MAX_SCNHDR_NRELOC 0xffffffff
61 #define PUT_SCNHDR_NRELOC H_PUT_32
62 #define GET_SCNHDR_NLNNO H_GET_32
63 #define MAX_SCNHDR_NLNNO 0xffffffff
64 #define PUT_SCNHDR_NLNNO H_PUT_32
65 #define GET_RELOC_VADDR H_GET_64
66 #define PUT_RELOC_VADDR H_PUT_64
68 #define COFF_FORCE_SYMBOLS_IN_STRINGS
69 #define COFF_DEBUG_STRING_WIDE_PREFIX
72 #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
75 memset (((SCNHDR *) EXT)->s_pad, 0, \
76 sizeof (((SCNHDR *) EXT)->s_pad)); \
80 #define NO_COFF_LINENOS
82 #define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
83 #define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
85 static void _bfd_xcoff64_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
86 static unsigned int _bfd_xcoff64_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
87 static boolean _bfd_xcoff64_put_ldsymbol_name
88 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
90 static void _bfd_xcoff64_swap_sym_in PARAMS ((bfd *, PTR, PTR));
91 static unsigned int _bfd_xcoff64_swap_sym_out PARAMS ((bfd *, PTR, PTR));
92 static void _bfd_xcoff64_swap_aux_in
93 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
94 static unsigned int _bfd_xcoff64_swap_aux_out
95 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
96 extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
97 extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
98 extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
99 extern void xcoff64_rtype2howto
100 PARAMS ((arelent *, struct internal_reloc *));
101 extern reloc_howto_type * xcoff64_reloc_type_lookup
102 PARAMS ((bfd *, bfd_reloc_code_real_type));
103 extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
104 extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
105 extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
106 extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
107 extern boolean _bfd_xcoff_write_armap
108 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
109 extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
110 extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
111 extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
112 extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
113 extern void _bfd_xcoff_swap_aux_in
114 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
115 extern unsigned int _bfd_xcoff_swap_aux_out
116 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
117 static void xcoff64_swap_ldhdr_in
118 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
119 static void xcoff64_swap_ldhdr_out
120 PARAMS ((bfd *, const struct internal_ldhdr *, PTR d));
121 static void xcoff64_swap_ldsym_in
122 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
123 static void xcoff64_swap_ldsym_out
124 PARAMS ((bfd *, const struct internal_ldsym *, PTR d));
125 static void xcoff64_swap_ldrel_in
126 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
127 static void xcoff64_swap_ldrel_out
128 PARAMS ((bfd *, const struct internal_ldrel *, PTR d));
129 static boolean xcoff64_write_object_contents PARAMS ((bfd *));
130 static boolean xcoff64_ppc_relocate_section
131 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
132 struct internal_reloc *, struct internal_syment *,
133 asection **sections));
134 static boolean xcoff64_slurp_armap PARAMS ((bfd *));
135 static const bfd_target *xcoff64_archive_p PARAMS ((bfd *));
136 static bfd *xcoff64_openr_next_archived_file PARAMS ((bfd *, bfd *));
137 static int xcoff64_sizeof_headers PARAMS ((bfd *, boolean));
138 static asection *xcoff64_create_csect_from_smclas
139 PARAMS ((bfd *, union internal_auxent *, const char *));
140 static boolean xcoff64_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
141 static boolean xcoff64_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
142 static bfd_vma xcoff64_loader_symbol_offset
143 PARAMS ((bfd *, struct internal_ldhdr *));
144 static bfd_vma xcoff64_loader_reloc_offset
145 PARAMS ((bfd *, struct internal_ldhdr *));
146 static boolean xcoff64_generate_rtinit
147 PARAMS((bfd *, const char *, const char *, boolean));
149 /* coffcode.h needs these to be defined */
150 /* Internalcoff.h and coffcode.h modify themselves based on these flags. */
152 #define RS6000COFF_C 1
154 #define SELECT_RELOC(internal, howto) \
156 internal.r_type = howto->type; \
158 ((howto->complain_on_overflow == complain_overflow_signed \
161 | (howto->bitsize - 1)); \
164 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
165 #define COFF_LONG_FILENAMES
166 #define NO_COFF_SYMBOLS
167 #define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
168 #define coff_mkobject _bfd_xcoff_mkobject
169 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
170 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
171 #define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
173 extern const bfd_target * rs6000coff_core_p PARAMS ((bfd *abfd));
174 extern boolean rs6000coff_core_file_matches_executable_p
175 PARAMS((bfd *cbfd, bfd *ebfd));
176 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
177 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
178 #define CORE_FILE_P rs6000coff_core_p
179 #define coff_core_file_failing_command \
180 rs6000coff_core_file_failing_command
181 #define coff_core_file_failing_signal \
182 rs6000coff_core_file_failing_signal
183 #define coff_core_file_matches_executable_p \
184 rs6000coff_core_file_matches_executable_p
186 #define CORE_FILE_P _bfd_dummy_target
187 #define coff_core_file_failing_command \
188 _bfd_nocore_core_file_failing_command
189 #define coff_core_file_failing_signal \
190 _bfd_nocore_core_file_failing_signal
191 #define coff_core_file_matches_executable_p \
192 _bfd_nocore_core_file_matches_executable_p
194 #define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
195 #define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
196 #define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
197 #define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
200 #include "coffcode.h"
202 /* For XCOFF64, the effective width of symndx changes depending on
203 whether we are the first entry. Sigh. */
205 _bfd_xcoff64_swap_lineno_in (abfd, ext1, in1)
210 LINENO *ext = (LINENO *) ext1;
211 struct internal_lineno *in = (struct internal_lineno *) in1;
213 in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
215 in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
217 in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
221 _bfd_xcoff64_swap_lineno_out (abfd, inp, outp)
226 struct internal_lineno *in = (struct internal_lineno *) inp;
227 struct external_lineno *ext = (struct external_lineno *) outp;
229 H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
230 H_PUT_32 (abfd, in->l_lnno, (ext->l_lnno));
233 H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
235 H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
237 return bfd_coff_linesz (abfd);
241 _bfd_xcoff64_swap_sym_in (abfd, ext1, in1)
246 struct external_syment *ext = (struct external_syment *) ext1;
247 struct internal_syment *in = (struct internal_syment *) in1;
249 in->_n._n_n._n_zeroes = 0;
250 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e_offset);
251 in->n_value = H_GET_64 (abfd, ext->e_value);
252 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
253 in->n_type = H_GET_16 (abfd, ext->e_type);
254 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
255 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
259 _bfd_xcoff64_swap_sym_out (abfd, inp, extp)
264 struct internal_syment *in = (struct internal_syment *) inp;
265 struct external_syment *ext = (struct external_syment *) extp;
267 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e_offset);
268 H_PUT_64 (abfd, in->n_value, ext->e_value);
269 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
270 H_PUT_16 (abfd, in->n_type, ext->e_type);
271 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
272 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
273 return bfd_coff_symesz (abfd);
277 _bfd_xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
286 union external_auxent *ext = (union external_auxent *) ext1;
287 union internal_auxent *in = (union internal_auxent *) in1;
292 if (ext->x_file.x_n.x_zeroes == 0)
294 in->x_file.x_n.x_zeroes = 0;
295 in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
299 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
303 /* RS/6000 "csect" auxents */
306 if (indx + 1 == numaux)
308 bfd_signed_vma h = 0;
311 h = H_GET_S32 (abfd, ext->x_csect.x_scnlen_hi);
312 l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
314 in->x_csect.x_scnlen.l = h << 32 | (l & 0xffffffff);
316 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
317 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
318 /* We don't have to hack bitfields in x_smtyp because it's
319 defined by shifts-and-ands, which are equivalent on all
321 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
322 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
332 /* PE defines some extra fields; we zero them out for
334 in->x_scn.x_checksum = 0;
335 in->x_scn.x_associated = 0;
336 in->x_scn.x_comdat = 0;
343 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
345 in->x_sym.x_fcnary.x_fcn.x_lnnoptr
346 = H_GET_64 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
347 in->x_sym.x_fcnary.x_fcn.x_endndx.l
348 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
352 in->x_sym.x_misc.x_fsize
353 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_fsize);
357 in->x_sym.x_misc.x_lnsz.x_lnno
358 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_lnsz.x_lnno);
359 in->x_sym.x_misc.x_lnsz.x_size
360 = H_GET_16 (abfd, ext->x_sym.x_fcnary.x_lnsz.x_size);
367 _bfd_xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
372 int indx ATTRIBUTE_UNUSED;
373 int numaux ATTRIBUTE_UNUSED;
376 union internal_auxent *in = (union internal_auxent *) inp;
377 union external_auxent *ext = (union external_auxent *) extp;
379 memset ((PTR) ext, 0, bfd_coff_auxesz (abfd));
383 if (ext->x_file.x_n.x_zeroes == 0)
385 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
386 H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
390 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
392 H_PUT_8 (abfd, _AUX_FILE, ext->x_auxtype.x_auxtype);
395 /* RS/6000 "csect" auxents */
398 if (indx + 1 == numaux)
402 temp = in->x_csect.x_scnlen.l & 0xffffffff;
403 H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
404 temp = in->x_csect.x_scnlen.l >> 32;
405 H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
406 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
407 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
408 /* We don't have to hack bitfields in x_smtyp because it's
409 defined by shifts-and-ands, which are equivalent on all
411 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
412 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
413 H_PUT_8 (abfd, _AUX_CSECT, ext->x_auxtype.x_auxtype);
428 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
430 H_PUT_64 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
431 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
432 H_PUT_8 (abfd, _AUX_FCN,
433 ext->x_auxtype.x_auxtype);
434 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
435 ext->x_sym.x_fcnary.x_fcn.x_endndx);
439 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize,
440 ext->x_sym.x_fcnary.x_fcn.x_fsize);
444 H_PUT_32 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
445 ext->x_sym.x_fcnary.x_lnsz.x_lnno);
446 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
447 ext->x_sym.x_fcnary.x_lnsz.x_size);
452 return bfd_coff_auxesz (abfd);
456 _bfd_xcoff64_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
457 struct internal_syment *sym,
464 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
467 indx = _bfd_stringtab_add (strtab, name, hash, false);
469 if (indx == (bfd_size_type) -1)
472 sym->_n._n_n._n_zeroes = 0;
473 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
479 _bfd_xcoff64_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
480 bfd *abfd ATTRIBUTE_UNUSED;
481 struct xcoff_loader_info *ldinfo;
482 struct internal_ldsym *ldsym;
489 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
491 bfd_size_type newalc;
492 bfd_byte *newstrings;
494 newalc = ldinfo->string_alc * 2;
497 while (ldinfo->string_size + len + 3 > newalc)
500 newstrings = ((bfd_byte *)
501 bfd_realloc ((PTR) ldinfo->strings, newalc));
502 if (newstrings == NULL)
504 ldinfo->failed = true;
507 ldinfo->string_alc = newalc;
508 ldinfo->strings = newstrings;
511 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
512 ldinfo->strings + ldinfo->string_size);
513 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
514 ldsym->_l._l_l._l_zeroes = 0;
515 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
516 ldinfo->string_size += len + 3;
521 /* Routines to swap information in the XCOFF .loader section. If we
522 ever need to write an XCOFF loader, this stuff will need to be
523 moved to another file shared by the linker (which XCOFF calls the
524 ``binder'') and the loader. */
526 /* Swap in the ldhdr structure. */
529 xcoff64_swap_ldhdr_in (abfd, s, dst)
532 struct internal_ldhdr *dst;
534 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
536 dst->l_version = bfd_get_32 (abfd, src->l_version);
537 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
538 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
539 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
540 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
541 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
542 dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
543 dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
544 dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
545 dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
548 /* Swap out the ldhdr structure. */
551 xcoff64_swap_ldhdr_out (abfd, src, d)
553 const struct internal_ldhdr *src;
556 struct external_ldhdr *dst = (struct external_ldhdr *) d;
558 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
559 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
560 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
561 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
562 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
563 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
564 bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
565 bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
566 bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
567 bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
570 /* Swap in the ldsym structure. */
573 xcoff64_swap_ldsym_in (abfd, s, dst)
576 struct internal_ldsym *dst;
578 const struct external_ldsym *src = (const struct external_ldsym *) s;
579 /* XCOFF64 does not use l_zeroes like XCOFF32
580 Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
581 as an offset into the loader symbol table. */
582 dst->_l._l_l._l_zeroes = 0;
583 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
584 dst->l_value = bfd_get_64 (abfd, src->l_value);
585 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
586 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
587 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
588 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
589 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
592 /* Swap out the ldsym structure. */
595 xcoff64_swap_ldsym_out (abfd, src, d)
597 const struct internal_ldsym *src;
600 struct external_ldsym *dst = (struct external_ldsym *) d;
602 bfd_put_64 (abfd, src->l_value, dst->l_value);
603 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, dst->l_offset);
604 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
605 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
606 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
607 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
608 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
611 /* Swap in the ldrel structure. */
614 xcoff64_swap_ldrel_in (abfd, s, dst)
617 struct internal_ldrel *dst;
619 const struct external_ldrel *src = (const struct external_ldrel *) s;
621 dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
622 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
623 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
624 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
627 /* Swap out the ldrel structure. */
630 xcoff64_swap_ldrel_out (abfd, src, d)
632 const struct internal_ldrel *src;
635 struct external_ldrel *dst = (struct external_ldrel *) d;
637 bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
638 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
639 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
640 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
644 xcoff64_write_object_contents (abfd)
648 boolean hasrelocs = false;
649 boolean haslinno = false;
652 file_ptr lineno_base;
654 unsigned long reloc_size = 0;
655 unsigned long lnno_size = 0;
656 boolean long_section_names;
657 asection *text_sec = ((void *) 0);
658 asection *data_sec = ((void *) 0);
659 asection *bss_sec = ((void *) 0);
660 struct internal_filehdr internal_f;
661 struct internal_aouthdr internal_a;
663 bfd_set_error (bfd_error_system_call);
665 if (abfd->output_has_begun == false)
667 if (! bfd_coff_compute_section_file_positions (abfd))
671 /* Work out the size of the reloc and linno areas */
672 reloc_base = obj_relocbase (abfd);
674 for (current = abfd->sections; current != NULL; current = current->next)
675 reloc_size += current->reloc_count * bfd_coff_relsz (abfd);
677 lineno_base = reloc_base + reloc_size;
679 /* Make a pass through the symbol table to count line number entries and
680 put them into the correct asections */
681 lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
683 sym_base = lineno_base + lnno_size;
685 /* Indicate in each section->line_filepos its actual file address */
686 for (current = abfd->sections; current != NULL; current = current->next)
688 if (current->lineno_count)
690 current->line_filepos = lineno_base;
691 current->moving_line_filepos = lineno_base;
692 lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
696 current->line_filepos = 0;
699 if (current->reloc_count)
701 current->rel_filepos = reloc_base;
702 reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
706 current->rel_filepos = 0;
710 if ((abfd->flags & EXEC_P) != 0)
712 scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
713 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
717 scn_base = bfd_coff_filhsz (abfd);
718 internal_f.f_opthdr = 0;
721 internal_f.f_nscns = 0;
723 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
726 long_section_names = false;
727 for (current = abfd->sections; current != NULL; current = current->next)
729 struct internal_scnhdr section;
730 struct external_scnhdr buff;
731 bfd_size_type amount;
733 internal_f.f_nscns++;
735 strncpy (section.s_name, current->name, SCNNMLEN);
737 section.s_vaddr = current->vma;
738 section.s_paddr = current->lma;
739 section.s_size = current->_raw_size;
741 /* If this section has no size or is unloadable then the scnptr
743 if (current->_raw_size == 0
744 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
746 section.s_scnptr = 0;
750 section.s_scnptr = current->filepos;
753 section.s_relptr = current->rel_filepos;
754 section.s_lnnoptr = current->line_filepos;
755 section.s_nreloc = current->reloc_count;
757 section.s_nlnno = current->lineno_count;
758 if (current->reloc_count != 0)
760 if (current->lineno_count != 0)
763 section.s_flags = sec_to_styp_flags (current->name, current->flags);
765 if (!strcmp (current->name, _TEXT))
769 else if (!strcmp (current->name, _DATA))
773 else if (!strcmp (current->name, _BSS))
778 amount = bfd_coff_scnhsz (abfd);
779 if (bfd_coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
780 || bfd_bwrite ((PTR) (&buff), amount, abfd) != amount)
784 internal_f.f_timdat = 0;
786 internal_f.f_flags = 0;
789 internal_f.f_flags |= F_RELFLG;
791 internal_f.f_flags |= F_LNNO;
792 if (abfd->flags & EXEC_P)
793 internal_f.f_flags |= F_EXEC;
795 /* FIXME: this is wrong for PPC_PE! */
796 if (bfd_little_endian (abfd))
797 internal_f.f_flags |= F_AR32WR;
799 internal_f.f_flags |= F_AR32W;
801 if ((abfd->flags & DYNAMIC) != 0)
802 internal_f.f_flags |= F_SHROBJ;
803 if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
804 internal_f.f_flags |= F_DYNLOAD;
806 memset (&internal_a, 0, sizeof internal_a);
809 /* This can only be called from the xcoff64 backend so the magic #
810 must be for xcoff64. */
811 internal_f.f_magic = 0757;
813 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
814 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
817 /* FIXME: Does anybody ever set this to another value? */
818 internal_a.vstamp = 0;
820 /* Now should write relocs, strings, syms */
821 obj_sym_filepos (abfd) = sym_base;
823 internal_f.f_symptr = 0;
824 internal_f.f_nsyms = 0;
826 /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
827 backend linker, and obj_raw_syment_count is not valid until after
828 coff_write_symbols is called. */
829 if (bfd_get_symcount (abfd) != 0)
833 if (!coff_renumber_symbols (abfd, &firstundef))
835 coff_mangle_symbols (abfd);
836 if (! coff_write_symbols (abfd))
838 if (! coff_write_linenumbers (abfd))
840 if (! coff_write_relocs (abfd, firstundef))
843 internal_f.f_symptr = sym_base;
844 internal_f.f_nsyms = bfd_get_symcount (abfd);
846 else if (obj_raw_syment_count (abfd) != 0)
848 internal_f.f_symptr = sym_base;
850 /* AIX appears to require that F_RELFLG not be set if there are
851 local symbols but no relocations. */
852 internal_f.f_flags &=~ F_RELFLG;
856 internal_f.f_flags |= F_LSYMS;
861 internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
862 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
867 internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
868 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
873 internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec);
874 if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
875 internal_a.data_start = bss_sec->vma;
878 internal_a.entry = bfd_get_start_address (abfd);
879 internal_f.f_nsyms = obj_raw_syment_count (abfd);
881 if (xcoff_data (abfd)->full_aouthdr)
884 asection *loader_sec;
886 internal_a.vstamp = 1;
888 internal_a.o_snentry = xcoff_data (abfd)->snentry;
889 if (internal_a.o_snentry == 0)
890 internal_a.entry = (bfd_vma) -1;
892 if (text_sec != NULL)
894 internal_a.o_sntext = text_sec->target_index;
895 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
899 internal_a.o_sntext = 0;
900 internal_a.o_algntext = 0;
903 if (data_sec != NULL)
905 internal_a.o_sndata = data_sec->target_index;
906 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
910 internal_a.o_sndata = 0;
911 internal_a.o_algndata = 0;
914 loader_sec = bfd_get_section_by_name (abfd, ".loader");
915 if (loader_sec != NULL)
916 internal_a.o_snloader = loader_sec->target_index;
918 internal_a.o_snloader = 0;
920 internal_a.o_snbss = bss_sec->target_index;
922 internal_a.o_snbss = 0;
924 toc = xcoff_data (abfd)->toc;
925 internal_a.o_toc = toc;
926 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
928 internal_a.o_modtype = xcoff_data (abfd)->modtype;
929 if (xcoff_data (abfd)->cputype != -1)
930 internal_a.o_cputype = xcoff_data (abfd)->cputype;
933 switch (bfd_get_arch (abfd))
935 case bfd_arch_rs6000:
936 internal_a.o_cputype = 4;
938 case bfd_arch_powerpc:
939 if (bfd_get_mach (abfd) == 0)
940 internal_a.o_cputype = 3;
942 internal_a.o_cputype = 1;
948 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
949 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
952 if (bfd_seek (abfd, (file_ptr) 0, 0) != 0)
957 bfd_size_type amount = bfd_coff_filhsz (abfd);
959 buff = bfd_malloc (amount);
963 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) buff);
964 amount = bfd_bwrite ((PTR) buff, amount, abfd);
968 if (amount != bfd_coff_filhsz (abfd))
972 if (abfd->flags & EXEC_P)
975 bfd_size_type amount = bfd_coff_aoutsz (abfd);
977 buff = bfd_malloc (amount);
981 bfd_coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
982 amount = bfd_bwrite ((PTR) buff, amount, abfd);
986 if (amount != bfd_coff_aoutsz (abfd))
993 /* This is the relocation function for the RS/6000/POWER/PowerPC.
994 This is currently the only processor which uses XCOFF; I hope that
995 will never change. */
998 xcoff64_ppc_relocate_section (output_bfd, info, input_bfd,
999 input_section, contents, relocs, syms,
1002 struct bfd_link_info *info;
1004 asection *input_section;
1006 struct internal_reloc *relocs;
1007 struct internal_syment *syms;
1008 asection **sections;
1010 struct internal_reloc *rel;
1011 struct internal_reloc *relend;
1014 relend = rel + input_section->reloc_count;
1015 for (; rel < relend; rel++)
1018 struct xcoff_link_hash_entry *h;
1019 struct internal_syment *sym;
1022 struct reloc_howto_struct howto;
1023 bfd_reloc_status_type rstat;
1025 /* Relocation type R_REF is a special relocation type which is
1026 merely used to prevent garbage collection from occurring for
1027 the csect including the symbol which it references. */
1028 if (rel->r_type == R_REF)
1031 symndx = rel->r_symndx;
1041 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
1042 sym = syms + symndx;
1043 addend = - sym->n_value;
1046 /* We build the howto information on the fly. */
1048 howto.type = rel->r_type;
1049 howto.rightshift = 0;
1051 howto.bitsize = (rel->r_size & 0x3f) + 1;
1052 howto.pc_relative = false;
1054 if ((rel->r_size & 0x80) != 0)
1055 howto.complain_on_overflow = complain_overflow_signed;
1057 howto.complain_on_overflow = complain_overflow_bitfield;
1058 howto.special_function = NULL;
1059 howto.name = "internal";
1060 howto.partial_inplace = true;
1062 if (howto.bitsize == 64)
1064 howto.src_mask = howto.dst_mask = MINUS_ONE;
1066 else if (howto.bitsize == 32)
1068 howto.src_mask = howto.dst_mask = 0xffffffff;
1072 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
1073 if (howto.bitsize == 16)
1076 howto.pcrel_offset = false;
1086 sec = bfd_abs_section_ptr;
1091 sec = sections[symndx];
1092 /* Hack to make sure we use the right TOC anchor value
1093 if this reloc is against the TOC anchor. */
1094 if (sec->name[3] == '0'
1095 && strcmp (sec->name, ".tc0") == 0)
1096 val = xcoff_data (output_bfd)->toc;
1098 val = (sec->output_section->vma
1099 + sec->output_offset
1108 if (h->root.type == bfd_link_hash_defined
1109 || h->root.type == bfd_link_hash_defweak)
1113 sec = h->root.u.def.section;
1114 val = (h->root.u.def.value
1115 + sec->output_section->vma
1116 + sec->output_offset);
1119 else if (h->root.type == bfd_link_hash_common)
1123 sec = h->root.u.c.p->section;
1124 val = (sec->output_section->vma
1125 + sec->output_offset);
1127 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
1128 || (h->flags & XCOFF_IMPORT) != 0)
1130 /* Every symbol in a shared object is defined somewhere. */
1133 else if (! info->relocateable)
1135 if (! ((*info->callbacks->undefined_symbol)
1136 (info, h->root.root.string, input_bfd, input_section,
1137 rel->r_vaddr - input_section->vma, true)))
1140 /* Don't try to process the reloc. It can't help, and
1141 it may generate another error. */
1146 /* I took the relocation type definitions from two documents:
1147 the PowerPC AIX Version 4 Application Binary Interface, First
1148 Edition (April 1992), and the PowerOpen ABI, Big-Endian
1149 32-Bit Hardware Implementation (June 30, 1994). Differences
1150 between the documents are noted below. */
1152 switch (rel->r_type)
1157 /* These relocs are defined by the PowerPC ABI to be
1158 relative branches which use half of the difference
1159 between the symbol and the program counter. I can't
1160 quite figure out when this is useful. These relocs are
1161 not defined by the PowerOpen ABI. */
1163 (*_bfd_error_handler)
1164 (_("%s: unsupported relocation type 0x%02x"),
1165 bfd_archive_filename (input_bfd), (unsigned int) rel->r_type);
1166 bfd_set_error (bfd_error_bad_value);
1169 /* Simple positive relocation. */
1172 /* Simple negative relocation. */
1176 /* Simple PC relative relocation. */
1177 howto.pc_relative = true;
1180 /* TOC relative relocation. The value in the instruction in
1181 the input file is the offset from the input file TOC to
1182 the desired location. We want the offset from the final
1183 TOC to the desired location. We have:
1188 so we must change insn by on - in.
1191 /* Global linkage relocation. The value of this relocation
1192 is the address of the entry in the TOC section. */
1194 /* Local object TOC address. I can't figure out the
1195 difference between this and case R_GL. */
1197 /* TOC relative relocation. A TOC relative load instruction
1198 which may be changed to a load address instruction.
1199 FIXME: We don't currently implement this optimization. */
1201 /* TOC relative relocation. This is a TOC relative load
1202 address instruction which may be changed to a load
1203 instruction. FIXME: I don't know if this is the correct
1205 if (h != NULL && h->smclas != XMC_TD)
1207 if (h->toc_section == NULL)
1209 (*_bfd_error_handler)
1210 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
1211 bfd_archive_filename (input_bfd), rel->r_vaddr,
1212 h->root.root.string);
1213 bfd_set_error (bfd_error_bad_value);
1217 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
1218 val = (h->toc_section->output_section->vma
1219 + h->toc_section->output_offset);
1222 val = ((val - xcoff_data (output_bfd)->toc)
1223 - (sym->n_value - xcoff_data (input_bfd)->toc));
1228 /* Absolute branch. We don't want to mess with the lower
1229 two bits of the instruction. */
1231 /* The PowerPC ABI defines this as an absolute call which
1232 may be modified to become a relative call. The PowerOpen
1233 ABI does not define this relocation type. */
1235 /* Absolute branch which may be modified to become a
1238 /* The PowerPC ABI defines this as an absolute branch to a
1239 fixed address which may be modified to an absolute branch
1240 to a symbol. The PowerOpen ABI does not define this
1243 /* The PowerPC ABI defines this as an absolute branch to a
1244 fixed address which may be modified to a relative branch.
1245 The PowerOpen ABI does not define this relocation type. */
1246 howto.src_mask &= ~3;
1247 howto.dst_mask = howto.src_mask;
1250 /* Relative branch. We don't want to mess with the lower
1251 two bits of the instruction. */
1253 /* The PowerPC ABI defines this as a relative call which may
1254 be modified to become an absolute call. The PowerOpen
1255 ABI does not define this relocation type. */
1257 /* A relative branch which may be modified to become an
1258 absolute branch. FIXME: We don't implement this,
1259 although we should for symbols of storage mapping class
1261 howto.pc_relative = true;
1262 howto.src_mask &= ~3;
1263 howto.dst_mask = howto.src_mask;
1265 howto.complain_on_overflow = complain_overflow_bitfield;
1268 /* The PowerPC AIX ABI describes this as a load which may be
1269 changed to a load address. The PowerOpen ABI says this
1270 is the same as case R_POS. */
1273 /* The PowerPC AIX ABI describes this as a load address
1274 which may be changed to a load. The PowerOpen ABI says
1275 this is the same as R_POS. */
1279 /* If we see an R_BR or R_RBR reloc which is jumping to global
1280 linkage code, and it is followed by an appropriate cror nop
1281 instruction, we replace the cror with ld r2,40(r1). This
1282 restores the TOC after the glink code. Contrariwise, if the
1283 call is followed by a ld r2,40(r1), but the call is not
1284 going to global linkage code, we can replace the load with a
1286 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
1288 && h->root.type == bfd_link_hash_defined
1289 && (rel->r_vaddr - input_section->vma + 8
1290 <= input_section->_cooked_size))
1295 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
1296 next = bfd_get_32 (input_bfd, pnext);
1299 /* The _ptrgl function is magic. It is used by the AIX
1300 * compiler to call a function through a pointer.
1302 * special case XMC_GL, global linkage
1304 if (h->smclas == XMC_GL
1305 || strcmp (h->root.root.string, "._ptrgl") == 0)
1307 if (next == 0x4def7b82 /* cror 15,15,15 */
1308 || next == 0x4ffffb82 /* cror 31,31,31 */
1309 || next == 0x60000000 /* ori r0,r0,0 */)
1310 bfd_put_32 (input_bfd, (bfd_vma) 0xe8410028 /* ld r2,40(r1) */,
1315 if (next == 0xe8410028 /* ld r2,40(r1) */)
1316 bfd_put_32 (input_bfd, (bfd_vma) 0x60000000 /* ori r0,r0,0 */,
1321 /* A PC relative reloc includes the section address. */
1322 if (howto.pc_relative)
1323 addend += input_section->vma;
1325 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
1327 rel->r_vaddr - input_section->vma,
1336 case bfd_reloc_overflow:
1339 char buf[SYMNMLEN + 1];
1340 char howto_name[10];
1345 name = h->root.root.string;
1348 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1352 sprintf (howto_name, "0x%02x", rel->r_type);
1354 if (! ((*info->callbacks->reloc_overflow)
1355 (info, name, howto_name, (bfd_vma) 0, input_bfd,
1356 input_section, rel->r_vaddr - input_section->vma)))
1367 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
1368 bitsize and whether they are signed or not, along with a
1369 conventional type. This table is for the types, which are used for
1370 different algorithms for putting in the reloc. Many of these
1371 relocs need special_function entries, which I have not written. */
1374 reloc_howto_type xcoff64_howto_table[] =
1376 /* Standard 64 bit relocation. */
1377 HOWTO (0, /* type */
1379 4, /* size (0 = byte, 1 = short, 2 = long) */
1381 false, /* pc_relative */
1383 complain_overflow_bitfield, /* complain_on_overflow */
1384 0, /* special_function */
1386 true, /* partial_inplace */
1387 MINUS_ONE, /* src_mask */
1388 MINUS_ONE, /* dst_mask */
1389 false), /* pcrel_offset */
1391 /* 64 bit relocation, but store negative value. */
1392 HOWTO (1, /* type */
1394 -4, /* size (0 = byte, 1 = short, 2 = long) */
1396 false, /* pc_relative */
1398 complain_overflow_bitfield, /* complain_on_overflow */
1399 0, /* special_function */
1401 true, /* partial_inplace */
1402 MINUS_ONE, /* src_mask */
1403 MINUS_ONE, /* dst_mask */
1404 false), /* pcrel_offset */
1406 /* 32 bit PC relative relocation. */
1407 HOWTO (2, /* type */
1409 2, /* size (0 = byte, 1 = short, 2 = long) */
1411 true, /* pc_relative */
1413 complain_overflow_signed, /* complain_on_overflow */
1414 0, /* special_function */
1416 true, /* partial_inplace */
1417 0xffffffff, /* src_mask */
1418 0xffffffff, /* dst_mask */
1419 false), /* pcrel_offset */
1421 /* 16 bit TOC relative relocation. */
1422 HOWTO (3, /* type */
1424 1, /* size (0 = byte, 1 = short, 2 = long) */
1426 false, /* pc_relative */
1428 complain_overflow_bitfield, /* complain_on_overflow */
1429 0, /* special_function */
1431 true, /* partial_inplace */
1432 0xffff, /* src_mask */
1433 0xffff, /* dst_mask */
1434 false), /* pcrel_offset */
1436 /* I don't really know what this is. */
1437 HOWTO (4, /* type */
1439 2, /* size (0 = byte, 1 = short, 2 = long) */
1441 false, /* pc_relative */
1443 complain_overflow_bitfield, /* complain_on_overflow */
1444 0, /* special_function */
1446 true, /* partial_inplace */
1447 0xffffffff, /* src_mask */
1448 0xffffffff, /* dst_mask */
1449 false), /* pcrel_offset */
1451 /* External TOC relative symbol. */
1452 HOWTO (5, /* type */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1456 false, /* pc_relative */
1458 complain_overflow_bitfield, /* complain_on_overflow */
1459 0, /* special_function */
1461 true, /* partial_inplace */
1462 0xffff, /* src_mask */
1463 0xffff, /* dst_mask */
1464 false), /* pcrel_offset */
1466 /* Local TOC relative symbol. */
1467 HOWTO (6, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 false, /* pc_relative */
1473 complain_overflow_bitfield, /* complain_on_overflow */
1474 0, /* special_function */
1476 true, /* partial_inplace */
1477 0xffff, /* src_mask */
1478 0xffff, /* dst_mask */
1479 false), /* pcrel_offset */
1483 /* Non modifiable absolute branch. */
1484 HOWTO (8, /* type */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1488 false, /* pc_relative */
1490 complain_overflow_bitfield, /* complain_on_overflow */
1491 0, /* special_function */
1493 true, /* partial_inplace */
1494 0x3fffffc, /* src_mask */
1495 0x3fffffc, /* dst_mask */
1496 false), /* pcrel_offset */
1500 /* Non modifiable relative branch. */
1501 HOWTO (0xa, /* type */
1503 2, /* size (0 = byte, 1 = short, 2 = long) */
1505 true, /* pc_relative */
1507 complain_overflow_signed, /* complain_on_overflow */
1508 0, /* special_function */
1510 true, /* partial_inplace */
1511 0x3fffffc, /* src_mask */
1512 0x3fffffc, /* dst_mask */
1513 false), /* pcrel_offset */
1517 /* Indirect load. */
1518 HOWTO (0xc, /* type */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1522 false, /* pc_relative */
1524 complain_overflow_bitfield, /* complain_on_overflow */
1525 0, /* special_function */
1527 true, /* partial_inplace */
1528 0xffff, /* src_mask */
1529 0xffff, /* dst_mask */
1530 false), /* pcrel_offset */
1533 HOWTO (0xd, /* type */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 false, /* pc_relative */
1539 complain_overflow_bitfield, /* complain_on_overflow */
1540 0, /* special_function */
1542 true, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 false), /* pcrel_offset */
1549 /* Non-relocating reference. */
1550 HOWTO (0xf, /* type */
1552 2, /* size (0 = byte, 1 = short, 2 = long) */
1554 false, /* pc_relative */
1556 complain_overflow_bitfield, /* complain_on_overflow */
1557 0, /* special_function */
1559 false, /* partial_inplace */
1562 false), /* pcrel_offset */
1567 /* TOC relative indirect load. */
1568 HOWTO (0x12, /* type */
1570 2, /* size (0 = byte, 1 = short, 2 = long) */
1572 false, /* pc_relative */
1574 complain_overflow_bitfield, /* complain_on_overflow */
1575 0, /* special_function */
1577 true, /* partial_inplace */
1578 0xffff, /* src_mask */
1579 0xffff, /* dst_mask */
1580 false), /* pcrel_offset */
1582 /* TOC relative load address. */
1583 HOWTO (0x13, /* type */
1585 2, /* size (0 = byte, 1 = short, 2 = long) */
1587 false, /* pc_relative */
1589 complain_overflow_bitfield, /* complain_on_overflow */
1590 0, /* special_function */
1591 "R_TRLA", /* name */
1592 true, /* partial_inplace */
1593 0xffff, /* src_mask */
1594 0xffff, /* dst_mask */
1595 false), /* pcrel_offset */
1597 /* Modifiable relative branch. */
1598 HOWTO (0x14, /* type */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1602 false, /* pc_relative */
1604 complain_overflow_bitfield, /* complain_on_overflow */
1605 0, /* special_function */
1606 "R_RRTBI", /* name */
1607 true, /* partial_inplace */
1608 0xffffffff, /* src_mask */
1609 0xffffffff, /* dst_mask */
1610 false), /* pcrel_offset */
1612 /* Modifiable absolute branch. */
1613 HOWTO (0x15, /* type */
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1617 false, /* pc_relative */
1619 complain_overflow_bitfield, /* complain_on_overflow */
1620 0, /* special_function */
1621 "R_RRTBA", /* name */
1622 true, /* partial_inplace */
1623 0xffffffff, /* src_mask */
1624 0xffffffff, /* dst_mask */
1625 false), /* pcrel_offset */
1627 /* Modifiable call absolute indirect. */
1628 HOWTO (0x16, /* type */
1630 2, /* size (0 = byte, 1 = short, 2 = long) */
1632 false, /* pc_relative */
1634 complain_overflow_bitfield, /* complain_on_overflow */
1635 0, /* special_function */
1637 true, /* partial_inplace */
1638 0xffff, /* src_mask */
1639 0xffff, /* dst_mask */
1640 false), /* pcrel_offset */
1642 /* Modifiable call relative. */
1643 HOWTO (0x17, /* type */
1645 2, /* size (0 = byte, 1 = short, 2 = long) */
1647 false, /* pc_relative */
1649 complain_overflow_bitfield, /* complain_on_overflow */
1650 0, /* special_function */
1651 "R_CREL", /* name */
1652 true, /* partial_inplace */
1653 0xffff, /* src_mask */
1654 0xffff, /* dst_mask */
1655 false), /* pcrel_offset */
1657 /* Modifiable branch absolute. */
1658 HOWTO (0x18, /* type */
1660 2, /* size (0 = byte, 1 = short, 2 = long) */
1662 false, /* pc_relative */
1664 complain_overflow_bitfield, /* complain_on_overflow */
1665 0, /* special_function */
1667 true, /* partial_inplace */
1668 0xffff, /* src_mask */
1669 0xffff, /* dst_mask */
1670 false), /* pcrel_offset */
1672 /* Modifiable branch absolute. */
1673 HOWTO (0x19, /* type */
1675 2, /* size (0 = byte, 1 = short, 2 = long) */
1677 false, /* pc_relative */
1679 complain_overflow_bitfield, /* complain_on_overflow */
1680 0, /* special_function */
1681 "R_RBAC", /* name */
1682 true, /* partial_inplace */
1683 0xffff, /* src_mask */
1684 0xffff, /* dst_mask */
1685 false), /* pcrel_offset */
1687 /* Modifiable branch relative. */
1688 HOWTO (0x1a, /* type */
1690 2, /* size (0 = byte, 1 = short, 2 = long) */
1692 false, /* pc_relative */
1694 complain_overflow_signed, /* complain_on_overflow */
1695 0, /* special_function */
1697 true, /* partial_inplace */
1698 0xffff, /* src_mask */
1699 0xffff, /* dst_mask */
1700 false), /* pcrel_offset */
1702 /* Modifiable branch absolute. */
1703 HOWTO (0x1b, /* type */
1705 2, /* size (0 = byte, 1 = short, 2 = long) */
1707 false, /* pc_relative */
1709 complain_overflow_bitfield, /* complain_on_overflow */
1710 0, /* special_function */
1711 "R_RBRC", /* name */
1712 true, /* partial_inplace */
1713 0xffff, /* src_mask */
1714 0xffff, /* dst_mask */
1715 false), /* pcrel_offset */
1717 HOWTO (0x1c, /* type */
1719 4, /* size (0 = byte, 1 = short, 2 = long) */
1721 false, /* pc_relative */
1723 complain_overflow_bitfield, /* complain_on_overflow */
1724 0, /* special_function */
1726 true, /* partial_inplace */
1727 MINUS_ONE, /* src_mask */
1728 MINUS_ONE, /* dst_mask */
1729 false), /* pcrel_offset */
1731 /* 16 bit Non modifiable absolute branch. */
1732 HOWTO (0x1d, /* type */
1734 2, /* size (0 = byte, 1 = short, 2 = long) */
1736 false, /* pc_relative */
1738 complain_overflow_bitfield, /* complain_on_overflow */
1739 0, /* special_function */
1741 true, /* partial_inplace */
1742 0xfffc, /* src_mask */
1743 0xfffc, /* dst_mask */
1744 false), /* pcrel_offset */
1748 xcoff64_rtype2howto (relent, internal)
1750 struct internal_reloc *internal;
1752 relent->howto = xcoff64_howto_table + internal->r_type;
1754 /* Check for relocs we don't know of. */
1755 if (internal->r_type
1756 >= sizeof (xcoff64_howto_table) / sizeof (xcoff64_howto_table[0]))
1758 if (internal->r_type != relent->howto->type)
1761 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1762 relocation, as well as indicating whether it is signed or not.
1763 Doublecheck that the relocation information gathered from the
1764 type matches this information. The bitsize is not significant
1765 for R_REF relocs. */
1766 if (relent->howto->dst_mask != 0
1767 && (relent->howto->bitsize
1768 != ((unsigned int) internal->r_size & 0x3f) + 1))
1771 if ((internal->r_size & 0x80) != 0
1772 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
1773 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
1779 xcoff64_reloc_type_lookup (abfd, code)
1780 bfd *abfd ATTRIBUTE_UNUSED;
1781 bfd_reloc_code_real_type code;
1785 case BFD_RELOC_PPC_B26:
1786 return &xcoff64_howto_table[0xa];
1787 case BFD_RELOC_PPC_BA16:
1788 return &xcoff64_howto_table[0x1d];
1789 case BFD_RELOC_PPC_BA26:
1790 return &xcoff64_howto_table[8];
1791 case BFD_RELOC_PPC_TOC16:
1792 return &xcoff64_howto_table[3];
1794 case BFD_RELOC_CTOR:
1795 return &xcoff64_howto_table[0];
1797 return &xcoff64_howto_table[0x1c];
1805 /* Read in the armap of an XCOFF archive. */
1808 xcoff64_slurp_armap (abfd)
1813 bfd_size_type sz, amt;
1814 bfd_byte *contents, *cend;
1820 /* This is for the new format. */
1821 struct xcoff_ar_hdr_big hdr;
1823 if (xcoff_ardata (abfd) == NULL)
1825 bfd_has_map (abfd) = false;
1829 off = strtol (xcoff_ardata_big (abfd)->symoff64, (char **) NULL, 10);
1832 bfd_has_map (abfd) = false;
1836 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1839 /* The symbol table starts with a normal archive header. */
1840 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1841 != SIZEOF_AR_HDR_BIG)
1844 /* Skip the name (normally empty). */
1845 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1846 pos = ((namlen + 1) & ~(size_t) 1) + SXCOFFARFMAG;
1847 if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
1850 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1851 machines) since the field width is 20 and there numbers with more
1852 than 32 bits can be represented. */
1853 sz = strtol (hdr.size, (char **) NULL, 10);
1855 /* Read in the entire symbol table. */
1856 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1857 if (contents == NULL)
1859 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1862 /* The symbol table starts with an eight byte count. */
1863 c = H_GET_64 (abfd, contents);
1867 bfd_set_error (bfd_error_bad_value);
1871 amt *= sizeof (carsym);
1872 bfd_ardata (abfd)->symdefs = (carsym *) bfd_alloc (abfd, amt);
1873 if (bfd_ardata (abfd)->symdefs == NULL)
1876 /* After the count comes a list of eight byte file offsets. */
1877 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1879 ++i, ++arsym, p += 8)
1880 arsym->file_offset = H_GET_64 (abfd, p);
1882 /* After the file offsets come null terminated symbol names. */
1883 cend = contents + sz;
1884 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1886 ++i, ++arsym, p += strlen ((char *) p) + 1)
1890 bfd_set_error (bfd_error_bad_value);
1893 arsym->name = (char *) p;
1896 bfd_ardata (abfd)->symdef_count = c;
1897 bfd_has_map (abfd) = true;
1903 /* See if this is an NEW XCOFF archive. */
1905 static const bfd_target *
1906 xcoff64_archive_p (abfd)
1909 char magic[SXCOFFARMAG];
1910 /* This is the new format. */
1911 struct xcoff_ar_file_hdr_big hdr;
1912 bfd_size_type amt = SXCOFFARMAG;
1914 if (bfd_bread ((PTR) magic, amt, abfd) != amt)
1916 if (bfd_get_error () != bfd_error_system_call)
1917 bfd_set_error (bfd_error_wrong_format);
1921 if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1923 bfd_set_error (bfd_error_wrong_format);
1927 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1928 involves a cast, we can't do it as the left operand of
1930 amt = sizeof (struct artdata);
1931 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
1933 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1936 bfd_ardata (abfd)->cache = NULL;
1937 bfd_ardata (abfd)->archive_head = NULL;
1938 bfd_ardata (abfd)->symdefs = NULL;
1939 bfd_ardata (abfd)->extended_names = NULL;
1941 /* Copy over the magic string. */
1942 memcpy (hdr.magic, magic, SXCOFFARMAG);
1944 /* Now read the rest of the file header. */
1945 if (bfd_bread ((PTR) &hdr.memoff,
1946 (bfd_size_type) (SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG),
1947 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1949 if (bfd_get_error () != bfd_error_system_call)
1950 bfd_set_error (bfd_error_wrong_format);
1954 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1955 machines) since the field width is 20 and there numbers with more
1956 than 32 bits can be represented. */
1957 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1958 (char **) NULL, 10);
1960 amt = SIZEOF_AR_FILE_HDR_BIG;
1961 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1962 if (bfd_ardata (abfd)->tdata == NULL)
1965 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1967 if (! xcoff64_slurp_armap (abfd))
1969 bfd_release (abfd, bfd_ardata (abfd));
1970 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1978 /* Open the next element in an XCOFF archive. */
1981 xcoff64_openr_next_archived_file (archive, last_file)
1987 if ((xcoff_ardata (archive) == NULL)
1988 || ! xcoff_big_format_p (archive))
1990 bfd_set_error (bfd_error_invalid_operation);
1994 if (last_file == NULL)
1996 filestart = bfd_ardata (archive)->first_file_filepos;
2000 /* XXX These actually have to be a calls to strtoll (at least
2001 on 32-bit machines) since the fields's width is 20 and
2002 there numbers with more than 32 bits can be represented. */
2003 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
2006 /* XXX These actually have to be calls to strtoll (at least on 32-bit
2007 machines) since the fields's width is 20 and there numbers with more
2008 than 32 bits can be represented. */
2010 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
2012 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
2013 (char **) NULL, 10))
2015 bfd_set_error (bfd_error_no_more_archived_files);
2019 return _bfd_get_elt_at_filepos (archive, filestart);
2022 /* We can't use the usual coff_sizeof_headers routine, because AIX
2023 always uses an a.out header. */
2027 xcoff64_sizeof_headers (abfd, reloc)
2029 boolean reloc ATTRIBUTE_UNUSED;
2033 size = bfd_coff_filhsz (abfd);
2035 /* Don't think the small aout header can be used since some of the
2036 old elements have been reordered past the end of the old coff
2039 if (xcoff_data (abfd)->full_aouthdr)
2040 size += bfd_coff_aoutsz (abfd);
2042 size += abfd->section_count * bfd_coff_scnhsz (abfd);
2049 xcoff64_create_csect_from_smclas (abfd, aux, symbol_name)
2051 union internal_auxent *aux;
2052 const char *symbol_name;
2054 asection *return_value = NULL;
2056 /* Changes from 32 :
2057 .sv == 8, is only for 32 bit programs
2058 .ti == 12 and .tb == 13 are now reserved. */
2059 static const char *names[19] =
2061 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2062 NULL, ".bs", ".ds", ".uc", NULL, NULL, NULL, ".tc0",
2063 ".td", ".sv64", ".sv3264"
2066 if ((19 >= aux->x_csect.x_smclas)
2067 && (NULL != names[aux->x_csect.x_smclas]))
2070 return_value = bfd_make_section_anyway
2071 (abfd, names[aux->x_csect.x_smclas]);
2076 (*_bfd_error_handler)
2077 (_("%s: symbol `%s' has unrecognized smclas %d"),
2078 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2079 bfd_set_error (bfd_error_bad_value);
2082 return return_value;
2086 xcoff64_is_lineno_count_overflow (abfd, value)
2087 bfd *abfd ATTRIBUTE_UNUSED;
2088 bfd_vma value ATTRIBUTE_UNUSED;
2094 xcoff64_is_reloc_count_overflow (abfd, value)
2095 bfd *abfd ATTRIBUTE_UNUSED;
2096 bfd_vma value ATTRIBUTE_UNUSED;
2102 xcoff64_loader_symbol_offset (abfd, ldhdr)
2103 bfd *abfd ATTRIBUTE_UNUSED;
2104 struct internal_ldhdr *ldhdr;
2106 return (ldhdr->l_symoff);
2110 xcoff64_loader_reloc_offset (abfd, ldhdr)
2111 bfd *abfd ATTRIBUTE_UNUSED;
2112 struct internal_ldhdr *ldhdr;
2114 return (ldhdr->l_rldoff);
2118 xcoff64_generate_rtinit (abfd, init, fini, rtld)
2124 bfd_byte filehdr_ext[FILHSZ];
2125 bfd_byte scnhdr_ext[SCNHSZ * 3];
2126 bfd_byte syment_ext[SYMESZ * 10];
2127 bfd_byte reloc_ext[RELSZ * 3];
2128 bfd_byte *data_buffer;
2129 bfd_size_type data_buffer_size;
2130 bfd_byte *string_table, *st_tmp;
2131 bfd_size_type string_table_size;
2133 size_t initsz, finisz;
2134 struct internal_filehdr filehdr;
2135 struct internal_scnhdr text_scnhdr;
2136 struct internal_scnhdr data_scnhdr;
2137 struct internal_scnhdr bss_scnhdr;
2138 struct internal_syment syment;
2139 union internal_auxent auxent;
2140 struct internal_reloc reloc;
2142 char *text_name = ".text";
2143 char *data_name = ".data";
2144 char *bss_name = ".bss";
2145 char *rtinit_name = "__rtinit";
2146 char *rtld_name = "__rtld";
2148 if (! bfd_xcoff_rtinit_size (abfd))
2151 initsz = (init == NULL ? 0 : 1 + strlen (init));
2152 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
2155 memset (filehdr_ext, 0, FILHSZ);
2156 memset (&filehdr, 0, sizeof (struct internal_filehdr));
2157 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
2158 filehdr.f_nscns = 3;
2159 filehdr.f_timdat = 0;
2160 filehdr.f_nsyms = 0; /* at least 6, no more than 8 */
2161 filehdr.f_symptr = 0; /* set below */
2162 filehdr.f_opthdr = 0;
2163 filehdr.f_flags = 0;
2165 /* section headers */
2166 memset (scnhdr_ext, 0, 3 * SCNHSZ);
2169 memset (&text_scnhdr, 0, sizeof (struct internal_scnhdr));
2170 memcpy (text_scnhdr.s_name, text_name, strlen (text_name));
2171 text_scnhdr.s_paddr = 0;
2172 text_scnhdr.s_vaddr = 0;
2173 text_scnhdr.s_size = 0;
2174 text_scnhdr.s_scnptr = 0;
2175 text_scnhdr.s_relptr = 0;
2176 text_scnhdr.s_lnnoptr = 0;
2177 text_scnhdr.s_nreloc = 0;
2178 text_scnhdr.s_nlnno = 0;
2179 text_scnhdr.s_flags = STYP_TEXT;
2182 memset (&data_scnhdr, 0, sizeof (struct internal_scnhdr));
2183 memcpy (data_scnhdr.s_name, data_name, strlen (data_name));
2184 data_scnhdr.s_paddr = 0;
2185 data_scnhdr.s_vaddr = 0;
2186 data_scnhdr.s_size = 0; /* set below */
2187 data_scnhdr.s_scnptr = FILHSZ + 3 * SCNHSZ;
2188 data_scnhdr.s_relptr = 0; /* set below */
2189 data_scnhdr.s_lnnoptr = 0;
2190 data_scnhdr.s_nreloc = 0; /* either 1 or 2 */
2191 data_scnhdr.s_nlnno = 0;
2192 data_scnhdr.s_flags = STYP_DATA;
2195 memset (&bss_scnhdr, 0, sizeof (struct internal_scnhdr));
2196 memcpy (bss_scnhdr.s_name, bss_name, strlen (bss_name));
2197 bss_scnhdr.s_paddr = 0; /* set below */
2198 bss_scnhdr.s_vaddr = 0; /* set below */
2199 bss_scnhdr.s_size = 0; /* set below */
2200 bss_scnhdr.s_scnptr = 0;
2201 bss_scnhdr.s_relptr = 0;
2202 bss_scnhdr.s_lnnoptr = 0;
2203 bss_scnhdr.s_nreloc = 0;
2204 bss_scnhdr.s_nlnno = 0;
2205 bss_scnhdr.s_flags = STYP_BSS;
2208 0x0000 0x00000000 : rtl
2210 0x0008 0x00000018 : offset to init, or 0
2211 0x000C 0x00000038 : offset to fini, or 0
2212 0x0010 0x00000010 : size of descriptor
2213 0x0014 0x00000000 : pad
2214 0x0018 0x00000000 : init, needs a reloc
2216 0x0020 0x00000058 : offset to init name
2217 0x0024 0x00000000 : flags, padded to a word
2218 0x0028 0x00000000 : empty init
2222 0x0038 0x00000000 : fini, needs a reloc
2224 0x0040 0x00000??? : offset to fini name
2225 0x0044 0x00000000 : flags, padded to a word
2226 0x0048 0x00000000 : empty fini
2231 0x0058 + initsz fini name */
2233 data_buffer_size = 0x0058 + initsz + finisz;
2234 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
2236 data_buffer = (bfd_byte *)bfd_malloc (data_buffer_size);
2237 if (data_buffer == NULL)
2240 memset (data_buffer, 0, data_buffer_size);
2245 bfd_put_32 (abfd, val, &data_buffer[0x08]);
2247 bfd_put_32 (abfd, val, &data_buffer[0x20]);
2248 memcpy (&data_buffer[val], init, initsz);
2254 bfd_put_32 (abfd, val, &data_buffer[0x0C]);
2255 val = 0x58 + initsz;
2256 bfd_put_32 (abfd, val, &data_buffer[0x40]);
2257 memcpy (&data_buffer[val], fini, finisz);
2261 bfd_put_32 (abfd, val, &data_buffer[0x10]);
2262 data_scnhdr.s_size = data_buffer_size;
2263 bss_scnhdr.s_paddr = bss_scnhdr.s_vaddr = data_scnhdr.s_size;
2266 string_table_size = 4;
2267 string_table_size += strlen (data_name) + 1;
2268 string_table_size += strlen (rtinit_name) + 1;
2269 string_table_size += initsz;
2270 string_table_size += finisz;
2272 string_table_size += strlen (rtld_name) + 1;
2274 string_table = (bfd_byte *)bfd_malloc (string_table_size);
2275 memset (string_table, 0, string_table_size);
2276 val = string_table_size;
2277 bfd_put_32 (abfd, val, &string_table[0]);
2278 st_tmp = string_table + 4;
2286 memset (syment_ext, 0, 10 * SYMESZ);
2287 memset (reloc_ext, 0, 3 * RELSZ);
2290 memset (&syment, 0, sizeof (struct internal_syment));
2291 memset (&auxent, 0, sizeof (union internal_auxent));
2293 syment._n._n_n._n_offset = st_tmp - string_table;
2294 memcpy (st_tmp, data_name, strlen (data_name));
2295 st_tmp += strlen (data_name) + 1;
2298 syment.n_sclass = C_HIDEXT;
2299 syment.n_numaux = 1;
2300 auxent.x_csect.x_scnlen.l = data_buffer_size;
2301 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
2302 auxent.x_csect.x_smclas = XMC_RW;
2303 bfd_coff_swap_sym_out (abfd, &syment,
2304 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2305 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2307 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2308 filehdr.f_nsyms += 2;
2311 memset (&syment, 0, sizeof (struct internal_syment));
2312 memset (&auxent, 0, sizeof (union internal_auxent));
2313 syment._n._n_n._n_offset = st_tmp - string_table;
2314 memcpy (st_tmp, rtinit_name, strlen (rtinit_name));
2315 st_tmp += strlen (rtinit_name) + 1;
2318 syment.n_sclass = C_EXT;
2319 syment.n_numaux = 1;
2320 auxent.x_csect.x_smtyp = XTY_LD;
2321 auxent.x_csect.x_smclas = XMC_RW;
2322 bfd_coff_swap_sym_out (abfd, &syment,
2323 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2324 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2326 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2327 filehdr.f_nsyms += 2;
2332 memset (&syment, 0, sizeof (struct internal_syment));
2333 memset (&auxent, 0, sizeof (union internal_auxent));
2335 syment._n._n_n._n_offset = st_tmp - string_table;
2336 memcpy (st_tmp, init, initsz);
2339 syment.n_sclass = C_EXT;
2340 syment.n_numaux = 1;
2341 bfd_coff_swap_sym_out (abfd, &syment,
2342 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2343 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2345 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2347 memset (&reloc, 0, sizeof (struct internal_reloc));
2348 reloc.r_vaddr = 0x0018;
2349 reloc.r_symndx = filehdr.f_nsyms;
2350 reloc.r_type = R_POS;
2352 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
2354 filehdr.f_nsyms += 2;
2355 data_scnhdr.s_nreloc += 1;
2361 memset (&syment, 0, sizeof (struct internal_syment));
2362 memset (&auxent, 0, sizeof (union internal_auxent));
2364 syment._n._n_n._n_offset = st_tmp - string_table;
2365 memcpy (st_tmp, fini, finisz);
2368 syment.n_sclass = C_EXT;
2369 syment.n_numaux = 1;
2370 bfd_coff_swap_sym_out (abfd, &syment,
2371 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2372 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2374 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2377 memset (&reloc, 0, sizeof (struct internal_reloc));
2378 reloc.r_vaddr = 0x0038;
2379 reloc.r_symndx = filehdr.f_nsyms;
2380 reloc.r_type = R_POS;
2382 bfd_coff_swap_reloc_out (abfd, &reloc,
2383 &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2385 filehdr.f_nsyms += 2;
2386 data_scnhdr.s_nreloc += 1;
2391 memset (&syment, 0, sizeof (struct internal_syment));
2392 memset (&auxent, 0, sizeof (union internal_auxent));
2394 syment._n._n_n._n_offset = st_tmp - string_table;
2395 memcpy (st_tmp, rtld_name, strlen (rtld_name));
2396 st_tmp += strlen (rtld_name) + 1;
2398 syment.n_sclass = C_EXT;
2399 syment.n_numaux = 1;
2400 bfd_coff_swap_sym_out (abfd, &syment,
2401 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2402 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2404 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2407 memset (&reloc, 0, sizeof (struct internal_reloc));
2408 reloc.r_vaddr = 0x0000;
2409 reloc.r_symndx = filehdr.f_nsyms;
2410 reloc.r_type = R_POS;
2412 bfd_coff_swap_reloc_out (abfd, &reloc,
2413 &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2415 filehdr.f_nsyms += 2;
2416 data_scnhdr.s_nreloc += 1;
2418 bss_scnhdr.s_size = 0;
2421 data_scnhdr.s_relptr = data_scnhdr.s_scnptr + data_buffer_size;
2422 filehdr.f_symptr = data_scnhdr.s_relptr + data_scnhdr.s_nreloc * RELSZ;
2424 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
2425 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
2426 bfd_coff_swap_scnhdr_out (abfd, &text_scnhdr, &scnhdr_ext[SCNHSZ * 0]);
2427 bfd_coff_swap_scnhdr_out (abfd, &data_scnhdr, &scnhdr_ext[SCNHSZ * 1]);
2428 bfd_coff_swap_scnhdr_out (abfd, &bss_scnhdr, &scnhdr_ext[SCNHSZ * 2]);
2429 bfd_bwrite (scnhdr_ext, 3 * SCNHSZ, abfd);
2430 bfd_bwrite (data_buffer, data_buffer_size, abfd);
2431 bfd_bwrite (reloc_ext, data_scnhdr.s_nreloc * RELSZ, abfd);
2432 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
2433 bfd_bwrite (string_table, string_table_size, abfd);
2441 /* The typical dynamic reloc. */
2443 static reloc_howto_type xcoff64_dynamic_reloc =
2444 HOWTO (0, /* type */
2446 4, /* size (0 = byte, 1 = short, 2 = long) */
2448 false, /* pc_relative */
2450 complain_overflow_bitfield, /* complain_on_overflow */
2451 0, /* special_function */
2453 true, /* partial_inplace */
2454 MINUS_ONE, /* src_mask */
2455 MINUS_ONE, /* dst_mask */
2456 false); /* pcrel_offset */
2458 static unsigned long xcoff64_glink_code[10] =
2460 0xe9820000, /* ld r12,0(r2) */
2461 0xf8410028, /* std r2,40(r1) */
2462 0xe80c0000, /* ld r0,0(r12) */
2463 0xe84c0008, /* ld r0,8(r12) */
2464 0x7c0903a6, /* mtctr r0 */
2465 0x4e800420, /* bctr */
2466 0x00000000, /* start of traceback table */
2467 0x000ca000, /* traceback table */
2468 0x00000000, /* traceback table */
2469 0x00000018, /* ??? */
2472 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2474 { /* COFF backend, defined in libcoff.h */
2475 _bfd_xcoff64_swap_aux_in, /* _bfd_coff_swap_aux_in */
2476 _bfd_xcoff64_swap_sym_in, /* _bfd_coff_swap_sym_in */
2477 _bfd_xcoff64_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2478 _bfd_xcoff64_swap_aux_out, /* _bfd_swap_aux_out */
2479 _bfd_xcoff64_swap_sym_out, /* _bfd_swap_sym_out */
2480 _bfd_xcoff64_swap_lineno_out, /* _bfd_swap_lineno_out */
2481 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2482 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2483 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2484 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2485 FILHSZ, /* _bfd_filhsz */
2486 AOUTSZ, /* _bfd_aoutsz */
2487 SCNHSZ, /* _bfd_scnhsz */
2488 SYMESZ, /* _bfd_symesz */
2489 AUXESZ, /* _bfd_auxesz */
2490 RELSZ, /* _bfd_relsz */
2491 LINESZ, /* _bfd_linesz */
2492 FILNMLEN, /* _bfd_filnmlen */
2493 true, /* _bfd_coff_long_filenames */
2494 false, /* _bfd_coff_long_section_names */
2495 (3), /* _bfd_coff_default_section_alignment_power */
2496 true, /* _bfd_coff_force_symnames_in_strings */
2497 4, /* _bfd_coff_debug_string_prefix_length */
2498 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2499 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2500 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2501 coff_swap_reloc_in, /* _bfd_reloc_in */
2502 coff_bad_format_hook, /* _bfd_bad_format_hook */
2503 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2504 coff_mkobject_hook, /* _bfd_mkobject_hook */
2505 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2506 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2507 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2508 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2509 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2510 coff_print_aux, /* bfd_coff_print_aux */
2511 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2512 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2513 NULL, /* bfd_coff_sym_is_global */
2514 /* _bfd_coff_compute_section_file_positions */
2515 coff_compute_section_file_positions,
2516 NULL , /* _bfd_coff_start_final_link */
2517 xcoff64_ppc_relocate_section, /* _bfd_coff_relocate_section */
2518 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2519 NULL , /* _bfd_coff_addust_symndx */
2520 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2521 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2522 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2525 0x01EF, /* magic number */
2526 bfd_arch_powerpc, /* architecture */
2527 bfd_mach_ppc_620, /* machine */
2529 /* function pointers to xcoff specific swap routines */
2530 xcoff64_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2531 xcoff64_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2532 xcoff64_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
2533 xcoff64_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
2534 xcoff64_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
2535 xcoff64_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
2538 LDHDRSZ, /* _xcoff_ldhdrsz */
2539 LDSYMSZ, /* _xcoff_ldsymsz */
2540 LDRELSZ, /* _xcoff_ldrelsz */
2541 24, /* _xcoff_function_descriptor_size */
2542 0, /* _xcoff_small_aout_header_size */
2544 2, /* _xcoff_ldhdr_version */
2546 /* xcoff vs xcoff64 putting symbol names */
2547 _bfd_xcoff64_put_symbol_name, /* _xcoff_put_symbol_name */
2548 _bfd_xcoff64_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
2550 /* dynamic reloc howto */
2551 &xcoff64_dynamic_reloc,
2553 xcoff64_create_csect_from_smclas,
2555 /* lineno and reloc count overflow */
2556 xcoff64_is_lineno_count_overflow,
2557 xcoff64_is_reloc_count_overflow,
2559 xcoff64_loader_symbol_offset,
2560 xcoff64_loader_reloc_offset,
2563 &xcoff64_glink_code[0],
2564 40, /* _xcoff_glink_size */
2567 88, /* _xcoff_rtinit_size */
2568 xcoff64_generate_rtinit, /* _xcoff_generate_rtinit */
2571 /* The transfer vector that leads the outside world to all of the above. */
2572 const bfd_target rs6000coff64_vec =
2575 bfd_target_xcoff_flavour,
2576 BFD_ENDIAN_BIG, /* data byte order is big */
2577 BFD_ENDIAN_BIG, /* header byte order is big */
2579 (HAS_RELOC | EXEC_P | /* object flags */
2580 HAS_LINENO | HAS_DEBUG | DYNAMIC |
2581 HAS_SYMS | HAS_LOCALS | WP_TEXT),
2583 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2584 0, /* leading char */
2585 '/', /* ar_pad_char */
2586 15, /* ar_max_namelen??? FIXMEmgo */
2589 bfd_getb64, /* bfd_getx64 */
2590 bfd_getb_signed_64, /* bfd_getx_signed_64 */
2591 bfd_putb64, /* bfd_putx64 */
2592 bfd_getb32, /* bfd_getx32 */
2593 bfd_getb_signed_32, /* bfd_getx_signed_32 */
2594 bfd_putb32, /* bfd_putx32 */
2595 bfd_getb16, /* bfd_getx16 */
2596 bfd_getb_signed_16, /* bfd_getx_signed_16 */
2597 bfd_putb16, /* bfd_putx16 */
2600 bfd_getb64, /* bfd_h_getx64 */
2601 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
2602 bfd_putb64, /* bfd_h_putx64 */
2603 bfd_getb32, /* bfd_h_getx32 */
2604 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
2605 bfd_putb32, /* bfd_h_putx32 */
2606 bfd_getb16, /* bfd_h_getx16 */
2607 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
2608 bfd_putb16, /* bfd_h_putx16 */
2610 { /* bfd_check_format */
2617 { /* bfd_set_format */
2620 _bfd_generic_mkarchive,
2624 {/* bfd_write_contents */
2626 xcoff64_write_object_contents,
2627 _bfd_xcoff_write_archive_contents,
2632 bfd_true, /* _close_and_cleanup */
2633 bfd_true, /* _bfd_free_cached_info */
2634 coff_new_section_hook, /* _new_section_hook */
2635 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
2636 /* _bfd_get_section_contents_in_window */
2637 _bfd_generic_get_section_contents_in_window,
2640 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
2641 /* _bfd_merge_private_bfd_data */
2642 ((boolean (*) (bfd *, bfd *)) bfd_true),
2643 /* _bfd_copy_pivate_section_data */
2644 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
2645 /* _bfd_copy_private_symbol_data */
2646 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
2647 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
2648 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
2651 coff_core_file_failing_command, /* _core_file_failing_command */
2652 coff_core_file_failing_signal, /* _core_file_failing_signal */
2653 /* _core_file_matches_executable_p */
2654 coff_core_file_matches_executable_p,
2657 xcoff64_slurp_armap, /* _slurp_armap */
2658 /* XCOFF archives do not have
2659 anything which corresponds to
2660 an extended name table. */
2661 bfd_false, /* _slurp_extended_name_table */
2662 /* _construct_extended_name_table */
2663 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
2664 bfd_dont_truncate_arname, /* _truncate_arname */
2665 _bfd_xcoff_write_armap, /* _write_armap */
2666 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
2667 xcoff64_openr_next_archived_file, /* _openr_next_archived_file */
2668 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
2669 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
2670 /* XCOFF archives do not have
2672 bfd_true, /* _update_armap_timestamp */
2675 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
2676 coff_get_symtab, /* _get_symtab */
2677 coff_make_empty_symbol, /* _make_empty_symbol */
2678 coff_print_symbol, /* _print_symbol */
2679 coff_get_symbol_info, /* _get_symbol_info */
2680 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
2681 coff_get_lineno, /* _get_lineno */
2682 coff_find_nearest_line, /* _find_nearest_line */
2683 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
2684 _bfd_generic_read_minisymbols, /* _read_minisymbols */
2685 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
2688 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
2689 coff_canonicalize_reloc, /* _cononicalize_reloc */
2690 xcoff64_reloc_type_lookup, /* _bfd_reloc_type_lookup */
2693 coff_set_arch_mach, /* _set_arch_mach */
2694 coff_set_section_contents, /* _set_section_contents */
2697 xcoff64_sizeof_headers, /* _sizeof_headers */
2698 /* _bfd_get_relocated_section_contents */
2699 bfd_generic_get_relocated_section_contents,
2700 bfd_generic_relax_section, /* _bfd_relax_section */
2701 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
2702 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
2703 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
2704 _bfd_generic_link_split_section, /* _bfd_link_split_section */
2705 bfd_generic_gc_sections, /* _bfd_gc_sections */
2706 bfd_generic_merge_sections, /* _bfd_merge_sections */
2709 /* _get_dynamic_symtab_upper_bound */
2710 _bfd_xcoff_get_dynamic_symtab_upper_bound,
2711 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
2712 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
2713 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
2715 /* Opposite endian version, none exists */
2719 (void *) &bfd_xcoff_backend_data,