Add support for -brtl, run time linking, to AIX ld.
[deliverable/binutils-gdb.git] / bfd / coff64-rs6000.c
1 /* BFD back-end for IBM RS/6000 "XCOFF64" files.
2 Copyright 2000, 2001
3 Free Software Foundation, Inc.
4 Written Clinton Popetz.
5 Contributed by Cygnus Support.
6
7 This file is part of BFD, the Binary File Descriptor library.
8
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.
13
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.
18
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. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "bfdlink.h"
26 #include "libbfd.h"
27 #include "coff/internal.h"
28 #include "coff/xcoff.h"
29 #include "coff/rs6k64.h"
30 #include "libcoff.h"
31 #include "libxcoff.h"
32
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
67
68 #define COFF_FORCE_SYMBOLS_IN_STRINGS
69 #define COFF_DEBUG_STRING_WIDE_PREFIX
70
71
72 #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
73 do \
74 { \
75 memset (((SCNHDR *) EXT)->s_pad, 0, \
76 sizeof (((SCNHDR *) EXT)->s_pad)); \
77 } \
78 while (0)
79
80 #define NO_COFF_LINENOS
81
82 #define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
83 #define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
84
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 *,
89 const char *));
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));
148
149 /* coffcode.h needs these to be defined */
150 /* Internalcoff.h and coffcode.h modify themselves based on these flags. */
151 #define XCOFF64
152 #define RS6000COFF_C 1
153
154 #define SELECT_RELOC(internal, howto) \
155 { \
156 internal.r_type = howto->type; \
157 internal.r_size = \
158 ((howto->complain_on_overflow == complain_overflow_signed \
159 ? 0x80 \
160 : 0) \
161 | (howto->bitsize - 1)); \
162 }
163
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
172 #ifdef AIX_CORE
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
185 #else
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
193 #endif
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
198
199
200 #include "coffcode.h"
201
202 /* For XCOFF64, the effective width of symndx changes depending on
203 whether we are the first entry. Sigh. */
204 static void
205 _bfd_xcoff64_swap_lineno_in (abfd, ext1, in1)
206 bfd *abfd;
207 PTR ext1;
208 PTR in1;
209 {
210 LINENO *ext = (LINENO *) ext1;
211 struct internal_lineno *in = (struct internal_lineno *) in1;
212
213 in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
214 if (in->l_lnno == 0)
215 in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
216 else
217 in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
218 }
219
220 static unsigned int
221 _bfd_xcoff64_swap_lineno_out (abfd, inp, outp)
222 bfd *abfd;
223 PTR inp;
224 PTR outp;
225 {
226 struct internal_lineno *in = (struct internal_lineno *) inp;
227 struct external_lineno *ext = (struct external_lineno *) outp;
228
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));
231
232 if (in->l_lnno == 0)
233 H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
234 else
235 H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
236
237 return bfd_coff_linesz (abfd);
238 }
239
240 static void
241 _bfd_xcoff64_swap_sym_in (abfd, ext1, in1)
242 bfd *abfd;
243 PTR ext1;
244 PTR in1;
245 {
246 struct external_syment *ext = (struct external_syment *) ext1;
247 struct internal_syment *in = (struct internal_syment *) in1;
248
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);
256 }
257
258 static unsigned int
259 _bfd_xcoff64_swap_sym_out (abfd, inp, extp)
260 bfd *abfd;
261 PTR inp;
262 PTR extp;
263 {
264 struct internal_syment *in = (struct internal_syment *) inp;
265 struct external_syment *ext = (struct external_syment *) extp;
266
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);
274 }
275
276 static void
277 _bfd_xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
278 bfd *abfd;
279 PTR ext1;
280 int type;
281 int class;
282 int indx;
283 int numaux;
284 PTR in1;
285 {
286 union external_auxent *ext = (union external_auxent *) ext1;
287 union internal_auxent *in = (union internal_auxent *) in1;
288
289 switch (class)
290 {
291 case C_FILE:
292 if (ext->x_file.x_n.x_zeroes == 0)
293 {
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);
296 }
297 else
298 {
299 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
300 }
301 goto end;
302
303 /* RS/6000 "csect" auxents */
304 case C_EXT:
305 case C_HIDEXT:
306 if (indx + 1 == numaux)
307 {
308 bfd_signed_vma h = 0;
309 bfd_vma l = 0;
310
311 h = H_GET_S32 (abfd, ext->x_csect.x_scnlen_hi);
312 l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
313
314 in->x_csect.x_scnlen.l = h << 32 | (l & 0xffffffff);
315
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
320 byte orders. */
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);
323 goto end;
324 }
325 break;
326
327 case C_STAT:
328 case C_LEAFSTAT:
329 case C_HIDDEN:
330 if (type == T_NULL)
331 {
332 /* PE defines some extra fields; we zero them out for
333 safety. */
334 in->x_scn.x_checksum = 0;
335 in->x_scn.x_associated = 0;
336 in->x_scn.x_comdat = 0;
337
338 goto end;
339 }
340 break;
341 }
342
343 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
344 {
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);
349 }
350 if (ISFCN (type))
351 {
352 in->x_sym.x_misc.x_fsize
353 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_fsize);
354 }
355 else
356 {
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);
361 }
362
363 end: ;
364 }
365
366 static unsigned int
367 _bfd_xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
368 bfd *abfd;
369 PTR inp;
370 int type;
371 int class;
372 int indx ATTRIBUTE_UNUSED;
373 int numaux ATTRIBUTE_UNUSED;
374 PTR extp;
375 {
376 union internal_auxent *in = (union internal_auxent *) inp;
377 union external_auxent *ext = (union external_auxent *) extp;
378
379 memset ((PTR) ext, 0, bfd_coff_auxesz (abfd));
380 switch (class)
381 {
382 case C_FILE:
383 if (ext->x_file.x_n.x_zeroes == 0)
384 {
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);
387 }
388 else
389 {
390 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
391 }
392 H_PUT_8 (abfd, _AUX_FILE, ext->x_auxtype.x_auxtype);
393 goto end;
394
395 /* RS/6000 "csect" auxents */
396 case C_EXT:
397 case C_HIDEXT:
398 if (indx + 1 == numaux)
399 {
400 bfd_vma temp;
401
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
410 byte orders. */
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);
414 goto end;
415 }
416 break;
417
418 case C_STAT:
419 case C_LEAFSTAT:
420 case C_HIDDEN:
421 if (type == T_NULL)
422 {
423 goto end;
424 }
425 break;
426 }
427
428 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
429 {
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);
436 }
437 if (ISFCN (type))
438 {
439 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize,
440 ext->x_sym.x_fcnary.x_fcn.x_fsize);
441 }
442 else
443 {
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);
448 }
449
450 end:
451
452 return bfd_coff_auxesz (abfd);
453 }
454
455 static boolean
456 _bfd_xcoff64_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
457 struct internal_syment *sym,
458 const char *name) {
459 boolean hash;
460 bfd_size_type indx;
461
462 hash = true;
463
464 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
465 hash = false;
466
467 indx = _bfd_stringtab_add (strtab, name, hash, false);
468
469 if (indx == (bfd_size_type) -1)
470 return false;
471
472 sym->_n._n_n._n_zeroes = 0;
473 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
474
475 return true;
476 }
477
478 static boolean
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;
483 const char *name;
484 {
485
486 size_t len;
487 len = strlen (name);
488
489 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
490 {
491 bfd_size_type newalc;
492 bfd_byte *newstrings;
493
494 newalc = ldinfo->string_alc * 2;
495 if (newalc == 0)
496 newalc = 32;
497 while (ldinfo->string_size + len + 3 > newalc)
498 newalc *= 2;
499
500 newstrings = ((bfd_byte *)
501 bfd_realloc ((PTR) ldinfo->strings, newalc));
502 if (newstrings == NULL)
503 {
504 ldinfo->failed = true;
505 return false;
506 }
507 ldinfo->string_alc = newalc;
508 ldinfo->strings = newstrings;
509 }
510
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;
517
518 return true;
519 }
520
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. */
525
526 /* Swap in the ldhdr structure. */
527
528 static void
529 xcoff64_swap_ldhdr_in (abfd, s, dst)
530 bfd *abfd;
531 const PTR s;
532 struct internal_ldhdr *dst;
533 {
534 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
535
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);
546 }
547
548 /* Swap out the ldhdr structure. */
549
550 static void
551 xcoff64_swap_ldhdr_out (abfd, src, d)
552 bfd *abfd;
553 const struct internal_ldhdr *src;
554 PTR d;
555 {
556 struct external_ldhdr *dst = (struct external_ldhdr *) d;
557
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);
568 }
569
570 /* Swap in the ldsym structure. */
571
572 static void
573 xcoff64_swap_ldsym_in (abfd, s, dst)
574 bfd *abfd;
575 const PTR s;
576 struct internal_ldsym *dst;
577 {
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);
590 }
591
592 /* Swap out the ldsym structure. */
593
594 static void
595 xcoff64_swap_ldsym_out (abfd, src, d)
596 bfd *abfd;
597 const struct internal_ldsym *src;
598 PTR d;
599 {
600 struct external_ldsym *dst = (struct external_ldsym *) d;
601
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);
609 }
610
611 /* Swap in the ldrel structure. */
612
613 static void
614 xcoff64_swap_ldrel_in (abfd, s, dst)
615 bfd *abfd;
616 const PTR s;
617 struct internal_ldrel *dst;
618 {
619 const struct external_ldrel *src = (const struct external_ldrel *) s;
620
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);
625 }
626
627 /* Swap out the ldrel structure. */
628
629 static void
630 xcoff64_swap_ldrel_out (abfd, src, d)
631 bfd *abfd;
632 const struct internal_ldrel *src;
633 PTR d;
634 {
635 struct external_ldrel *dst = (struct external_ldrel *) d;
636
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);
641 }
642
643 static boolean
644 xcoff64_write_object_contents (abfd)
645 bfd * abfd;
646 {
647 asection *current;
648 boolean hasrelocs = false;
649 boolean haslinno = false;
650 file_ptr scn_base;
651 file_ptr reloc_base;
652 file_ptr lineno_base;
653 file_ptr sym_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;
662
663 bfd_set_error (bfd_error_system_call);
664
665 if (abfd->output_has_begun == false)
666 {
667 if (! bfd_coff_compute_section_file_positions (abfd))
668 return false;
669 }
670
671 /* Work out the size of the reloc and linno areas */
672 reloc_base = obj_relocbase (abfd);
673
674 for (current = abfd->sections; current != NULL; current = current->next)
675 reloc_size += current->reloc_count * bfd_coff_relsz (abfd);
676
677 lineno_base = reloc_base + reloc_size;
678
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);
682
683 sym_base = lineno_base + lnno_size;
684
685 /* Indicate in each section->line_filepos its actual file address */
686 for (current = abfd->sections; current != NULL; current = current->next)
687 {
688 if (current->lineno_count)
689 {
690 current->line_filepos = lineno_base;
691 current->moving_line_filepos = lineno_base;
692 lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
693 }
694 else
695 {
696 current->line_filepos = 0;
697 }
698
699 if (current->reloc_count)
700 {
701 current->rel_filepos = reloc_base;
702 reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
703 }
704 else
705 {
706 current->rel_filepos = 0;
707 }
708 }
709
710 if ((abfd->flags & EXEC_P) != 0)
711 {
712 scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
713 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
714 }
715 else
716 {
717 scn_base = bfd_coff_filhsz (abfd);
718 internal_f.f_opthdr = 0;
719 }
720
721 internal_f.f_nscns = 0;
722
723 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
724 return false;
725
726 long_section_names = false;
727 for (current = abfd->sections; current != NULL; current = current->next)
728 {
729 struct internal_scnhdr section;
730 struct external_scnhdr buff;
731 bfd_size_type amount;
732
733 internal_f.f_nscns++;
734
735 strncpy (section.s_name, current->name, SCNNMLEN);
736
737 section.s_vaddr = current->vma;
738 section.s_paddr = current->lma;
739 section.s_size = current->_raw_size;
740
741 /* If this section has no size or is unloadable then the scnptr
742 will be 0 too. */
743 if (current->_raw_size == 0
744 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
745 {
746 section.s_scnptr = 0;
747 }
748 else
749 {
750 section.s_scnptr = current->filepos;
751 }
752
753 section.s_relptr = current->rel_filepos;
754 section.s_lnnoptr = current->line_filepos;
755 section.s_nreloc = current->reloc_count;
756
757 section.s_nlnno = current->lineno_count;
758 if (current->reloc_count != 0)
759 hasrelocs = true;
760 if (current->lineno_count != 0)
761 haslinno = true;
762
763 section.s_flags = sec_to_styp_flags (current->name, current->flags);
764
765 if (!strcmp (current->name, _TEXT))
766 {
767 text_sec = current;
768 }
769 else if (!strcmp (current->name, _DATA))
770 {
771 data_sec = current;
772 }
773 else if (!strcmp (current->name, _BSS))
774 {
775 bss_sec = current;
776 }
777
778 amount = bfd_coff_scnhsz (abfd);
779 if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
780 || bfd_bwrite ((PTR) (&buff), amount, abfd) != amount)
781 return false;
782 }
783
784 internal_f.f_timdat = 0;
785
786 internal_f.f_flags = 0;
787
788 if (!hasrelocs)
789 internal_f.f_flags |= F_RELFLG;
790 if (!haslinno)
791 internal_f.f_flags |= F_LNNO;
792 if (abfd->flags & EXEC_P)
793 internal_f.f_flags |= F_EXEC;
794
795 /* FIXME: this is wrong for PPC_PE! */
796 if (bfd_little_endian (abfd))
797 internal_f.f_flags |= F_AR32WR;
798 else
799 internal_f.f_flags |= F_AR32W;
800
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;
805
806 memset (&internal_a, 0, sizeof internal_a);
807
808
809 /* This can only be called from the xcoff64 backend so the magic #
810 must be for xcoff64. */
811 internal_f.f_magic = 0757;
812
813 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
814 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
815 RS6K_AOUTHDR_OMAGIC;
816
817 /* FIXME: Does anybody ever set this to another value? */
818 internal_a.vstamp = 0;
819
820 /* Now should write relocs, strings, syms */
821 obj_sym_filepos (abfd) = sym_base;
822
823 internal_f.f_symptr = 0;
824 internal_f.f_nsyms = 0;
825
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)
830 {
831 int firstundef;
832
833 if (!coff_renumber_symbols (abfd, &firstundef))
834 return false;
835 coff_mangle_symbols (abfd);
836 if (! coff_write_symbols (abfd))
837 return false;
838 if (! coff_write_linenumbers (abfd))
839 return false;
840 if (! coff_write_relocs (abfd, firstundef))
841 return false;
842
843 internal_f.f_symptr = sym_base;
844 internal_f.f_nsyms = bfd_get_symcount (abfd);
845 }
846 else if (obj_raw_syment_count (abfd) != 0)
847 {
848 internal_f.f_symptr = sym_base;
849
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;
853 }
854 else
855 {
856 internal_f.f_flags |= F_LSYMS;
857 }
858
859 if (text_sec)
860 {
861 internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
862 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
863 }
864
865 if (data_sec)
866 {
867 internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
868 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
869 }
870
871 if (bss_sec)
872 {
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;
876 }
877
878 internal_a.entry = bfd_get_start_address (abfd);
879 internal_f.f_nsyms = obj_raw_syment_count (abfd);
880
881 if (xcoff_data (abfd)->full_aouthdr)
882 {
883 bfd_vma toc;
884 asection *loader_sec;
885
886 internal_a.vstamp = 1;
887
888 internal_a.o_snentry = xcoff_data (abfd)->snentry;
889 if (internal_a.o_snentry == 0)
890 internal_a.entry = (bfd_vma) -1;
891
892 if (text_sec != NULL)
893 {
894 internal_a.o_sntext = text_sec->target_index;
895 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
896 }
897 else
898 {
899 internal_a.o_sntext = 0;
900 internal_a.o_algntext = 0;
901 }
902
903 if (data_sec != NULL)
904 {
905 internal_a.o_sndata = data_sec->target_index;
906 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
907 }
908 else
909 {
910 internal_a.o_sndata = 0;
911 internal_a.o_algndata = 0;
912 }
913
914 loader_sec = bfd_get_section_by_name (abfd, ".loader");
915 if (loader_sec != NULL)
916 internal_a.o_snloader = loader_sec->target_index;
917 else
918 internal_a.o_snloader = 0;
919 if (bss_sec != NULL)
920 internal_a.o_snbss = bss_sec->target_index;
921 else
922 internal_a.o_snbss = 0;
923
924 toc = xcoff_data (abfd)->toc;
925 internal_a.o_toc = toc;
926 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
927
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;
931 else
932 {
933 switch (bfd_get_arch (abfd))
934 {
935 case bfd_arch_rs6000:
936 internal_a.o_cputype = 4;
937 break;
938 case bfd_arch_powerpc:
939 if (bfd_get_mach (abfd) == 0)
940 internal_a.o_cputype = 3;
941 else
942 internal_a.o_cputype = 1;
943 break;
944 default:
945 abort ();
946 }
947 }
948 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
949 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
950 }
951
952 if (bfd_seek (abfd, (file_ptr) 0, 0) != 0)
953 return false;
954
955 {
956 char * buff;
957 bfd_size_type amount = bfd_coff_filhsz (abfd);
958
959 buff = bfd_malloc (amount);
960 if (buff == NULL)
961 return false;
962
963 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) buff);
964 amount = bfd_bwrite ((PTR) buff, amount, abfd);
965
966 free (buff);
967
968 if (amount != bfd_coff_filhsz (abfd))
969 return false;
970 }
971
972 if (abfd->flags & EXEC_P)
973 {
974 char * buff;
975 bfd_size_type amount = bfd_coff_aoutsz (abfd);
976
977 buff = bfd_malloc (amount);
978 if (buff == NULL)
979 return false;
980
981 bfd_coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
982 amount = bfd_bwrite ((PTR) buff, amount, abfd);
983
984 free (buff);
985
986 if (amount != bfd_coff_aoutsz (abfd))
987 return false;
988 }
989
990 return true;
991 }
992
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. */
996
997 static boolean
998 xcoff64_ppc_relocate_section (output_bfd, info, input_bfd,
999 input_section, contents, relocs, syms,
1000 sections)
1001 bfd *output_bfd;
1002 struct bfd_link_info *info;
1003 bfd *input_bfd;
1004 asection *input_section;
1005 bfd_byte *contents;
1006 struct internal_reloc *relocs;
1007 struct internal_syment *syms;
1008 asection **sections;
1009 {
1010 struct internal_reloc *rel;
1011 struct internal_reloc *relend;
1012
1013 rel = relocs;
1014 relend = rel + input_section->reloc_count;
1015 for (; rel < relend; rel++)
1016 {
1017 long symndx;
1018 struct xcoff_link_hash_entry *h;
1019 struct internal_syment *sym;
1020 bfd_vma addend;
1021 bfd_vma val;
1022 struct reloc_howto_struct howto;
1023 bfd_reloc_status_type rstat;
1024
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)
1029 continue;
1030
1031 symndx = rel->r_symndx;
1032
1033 if (symndx == -1)
1034 {
1035 h = NULL;
1036 sym = NULL;
1037 addend = 0;
1038 }
1039 else
1040 {
1041 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
1042 sym = syms + symndx;
1043 addend = - sym->n_value;
1044 }
1045
1046 /* We build the howto information on the fly. */
1047
1048 howto.type = rel->r_type;
1049 howto.rightshift = 0;
1050 howto.size = 4;
1051 howto.bitsize = (rel->r_size & 0x3f) + 1;
1052 howto.pc_relative = false;
1053 howto.bitpos = 0;
1054 if ((rel->r_size & 0x80) != 0)
1055 howto.complain_on_overflow = complain_overflow_signed;
1056 else
1057 howto.complain_on_overflow = complain_overflow_bitfield;
1058 howto.special_function = NULL;
1059 howto.name = "internal";
1060 howto.partial_inplace = true;
1061
1062 if (howto.bitsize == 64)
1063 {
1064 howto.src_mask = howto.dst_mask = MINUS_ONE;
1065 }
1066 else if (howto.bitsize == 32)
1067 {
1068 howto.src_mask = howto.dst_mask = 0xffffffff;
1069 }
1070 else
1071 {
1072 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
1073 if (howto.bitsize == 16)
1074 howto.size = 1;
1075 }
1076 howto.pcrel_offset = false;
1077
1078 val = 0;
1079
1080 if (h == NULL)
1081 {
1082 asection *sec;
1083
1084 if (symndx == -1)
1085 {
1086 sec = bfd_abs_section_ptr;
1087 val = 0;
1088 }
1089 else
1090 {
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;
1097 else
1098 val = (sec->output_section->vma
1099 + sec->output_offset
1100 + sym->n_value
1101 - sec->vma);
1102 }
1103
1104 }
1105 else
1106 {
1107
1108 if (h->root.type == bfd_link_hash_defined
1109 || h->root.type == bfd_link_hash_defweak)
1110 {
1111 asection *sec;
1112
1113 sec = h->root.u.def.section;
1114 val = (h->root.u.def.value
1115 + sec->output_section->vma
1116 + sec->output_offset);
1117
1118 }
1119 else if (h->root.type == bfd_link_hash_common)
1120 {
1121 asection *sec;
1122
1123 sec = h->root.u.c.p->section;
1124 val = (sec->output_section->vma
1125 + sec->output_offset);
1126 }
1127 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
1128 || (h->flags & XCOFF_IMPORT) != 0)
1129 {
1130 /* Every symbol in a shared object is defined somewhere. */
1131 val = 0;
1132 }
1133 else if (! info->relocateable)
1134 {
1135 if (! ((*info->callbacks->undefined_symbol)
1136 (info, h->root.root.string, input_bfd, input_section,
1137 rel->r_vaddr - input_section->vma, true)))
1138 return false;
1139
1140 /* Don't try to process the reloc. It can't help, and
1141 it may generate another error. */
1142 continue;
1143 }
1144 }
1145
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. */
1151
1152 switch (rel->r_type)
1153 {
1154 case R_RTB:
1155 case R_RRTBI:
1156 case R_RRTBA:
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. */
1162 default:
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);
1167 return false;
1168 case R_POS:
1169 /* Simple positive relocation. */
1170 break;
1171 case R_NEG:
1172 /* Simple negative relocation. */
1173 val = - val;
1174 break;
1175 case R_REL:
1176 /* Simple PC relative relocation. */
1177 howto.pc_relative = true;
1178 break;
1179 case R_TOC:
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:
1184 isym = iTOC + in
1185 iinsn = in + o
1186 osym = oTOC + on
1187 oinsn = on + o
1188 so we must change insn by on - in.
1189 */
1190 case R_GL:
1191 /* Global linkage relocation. The value of this relocation
1192 is the address of the entry in the TOC section. */
1193 case R_TCL:
1194 /* Local object TOC address. I can't figure out the
1195 difference between this and case R_GL. */
1196 case R_TRL:
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. */
1200 case R_TRLA:
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
1204 implementation. */
1205 if (h != NULL && h->smclas != XMC_TD)
1206 {
1207 if (h->toc_section == NULL)
1208 {
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);
1214 return false;
1215 }
1216
1217 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
1218 val = (h->toc_section->output_section->vma
1219 + h->toc_section->output_offset);
1220 }
1221
1222 val = ((val - xcoff_data (output_bfd)->toc)
1223 - (sym->n_value - xcoff_data (input_bfd)->toc));
1224
1225 addend = 0;
1226 break;
1227 case R_BA:
1228 /* Absolute branch. We don't want to mess with the lower
1229 two bits of the instruction. */
1230 case R_CAI:
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. */
1234 case R_RBA:
1235 /* Absolute branch which may be modified to become a
1236 relative branch. */
1237 case R_RBAC:
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
1241 relocation type. */
1242 case R_RBRC:
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;
1248 break;
1249 case R_BR:
1250 /* Relative branch. We don't want to mess with the lower
1251 two bits of the instruction. */
1252 case R_CREL:
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. */
1256 case R_RBR:
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
1260 XMC_XO. */
1261 howto.pc_relative = true;
1262 howto.src_mask &= ~3;
1263 howto.dst_mask = howto.src_mask;
1264 howto.size = 2;
1265 howto.complain_on_overflow = complain_overflow_bitfield;
1266 break;
1267 case R_RL:
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. */
1271 break;
1272 case R_RLA:
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. */
1276 break;
1277 }
1278
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
1285 cror. */
1286 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
1287 && h != NULL
1288 && h->root.type == bfd_link_hash_defined
1289 && (rel->r_vaddr - input_section->vma + 8
1290 <= input_section->_cooked_size))
1291 {
1292 bfd_byte *pnext;
1293 unsigned long next;
1294
1295 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
1296 next = bfd_get_32 (input_bfd, pnext);
1297
1298
1299 /* The _ptrgl function is magic. It is used by the AIX
1300 * compiler to call a function through a pointer.
1301 *
1302 * special case XMC_GL, global linkage
1303 */
1304 if (h->smclas == XMC_GL
1305 || strcmp (h->root.root.string, "._ptrgl") == 0)
1306 {
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) */,
1311 pnext);
1312 }
1313 else
1314 {
1315 if (next == 0xe8410028 /* ld r2,40(r1) */)
1316 bfd_put_32 (input_bfd, (bfd_vma) 0x60000000 /* ori r0,r0,0 */,
1317 pnext);
1318 }
1319 }
1320
1321 /* A PC relative reloc includes the section address. */
1322 if (howto.pc_relative)
1323 addend += input_section->vma;
1324
1325 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
1326 contents,
1327 rel->r_vaddr - input_section->vma,
1328 val, addend);
1329
1330 switch (rstat)
1331 {
1332 default:
1333 abort ();
1334 case bfd_reloc_ok:
1335 break;
1336 case bfd_reloc_overflow:
1337 {
1338 const char *name;
1339 char buf[SYMNMLEN + 1];
1340 char howto_name[10];
1341
1342 if (symndx == -1)
1343 name = "*ABS*";
1344 else if (h != NULL)
1345 name = h->root.root.string;
1346 else
1347 {
1348 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1349 if (name == NULL)
1350 return false;
1351 }
1352 sprintf (howto_name, "0x%02x", rel->r_type);
1353
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)))
1357 return false;
1358 }
1359 }
1360 }
1361
1362 return true;
1363 }
1364
1365
1366 \f
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. */
1372
1373
1374 reloc_howto_type xcoff64_howto_table[] =
1375 {
1376 /* Standard 64 bit relocation. */
1377 HOWTO (0, /* type */
1378 0, /* rightshift */
1379 4, /* size (0 = byte, 1 = short, 2 = long) */
1380 64, /* bitsize */
1381 false, /* pc_relative */
1382 0, /* bitpos */
1383 complain_overflow_bitfield, /* complain_on_overflow */
1384 0, /* special_function */
1385 "R_POS", /* name */
1386 true, /* partial_inplace */
1387 MINUS_ONE, /* src_mask */
1388 MINUS_ONE, /* dst_mask */
1389 false), /* pcrel_offset */
1390
1391 /* 64 bit relocation, but store negative value. */
1392 HOWTO (1, /* type */
1393 0, /* rightshift */
1394 -4, /* size (0 = byte, 1 = short, 2 = long) */
1395 64, /* bitsize */
1396 false, /* pc_relative */
1397 0, /* bitpos */
1398 complain_overflow_bitfield, /* complain_on_overflow */
1399 0, /* special_function */
1400 "R_NEG", /* name */
1401 true, /* partial_inplace */
1402 MINUS_ONE, /* src_mask */
1403 MINUS_ONE, /* dst_mask */
1404 false), /* pcrel_offset */
1405
1406 /* 32 bit PC relative relocation. */
1407 HOWTO (2, /* type */
1408 0, /* rightshift */
1409 2, /* size (0 = byte, 1 = short, 2 = long) */
1410 32, /* bitsize */
1411 true, /* pc_relative */
1412 0, /* bitpos */
1413 complain_overflow_signed, /* complain_on_overflow */
1414 0, /* special_function */
1415 "R_REL", /* name */
1416 true, /* partial_inplace */
1417 0xffffffff, /* src_mask */
1418 0xffffffff, /* dst_mask */
1419 false), /* pcrel_offset */
1420
1421 /* 16 bit TOC relative relocation. */
1422 HOWTO (3, /* type */
1423 0, /* rightshift */
1424 1, /* size (0 = byte, 1 = short, 2 = long) */
1425 16, /* bitsize */
1426 false, /* pc_relative */
1427 0, /* bitpos */
1428 complain_overflow_bitfield, /* complain_on_overflow */
1429 0, /* special_function */
1430 "R_TOC", /* name */
1431 true, /* partial_inplace */
1432 0xffff, /* src_mask */
1433 0xffff, /* dst_mask */
1434 false), /* pcrel_offset */
1435
1436 /* I don't really know what this is. */
1437 HOWTO (4, /* type */
1438 1, /* rightshift */
1439 2, /* size (0 = byte, 1 = short, 2 = long) */
1440 32, /* bitsize */
1441 false, /* pc_relative */
1442 0, /* bitpos */
1443 complain_overflow_bitfield, /* complain_on_overflow */
1444 0, /* special_function */
1445 "R_RTB", /* name */
1446 true, /* partial_inplace */
1447 0xffffffff, /* src_mask */
1448 0xffffffff, /* dst_mask */
1449 false), /* pcrel_offset */
1450
1451 /* External TOC relative symbol. */
1452 HOWTO (5, /* type */
1453 0, /* rightshift */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1455 16, /* bitsize */
1456 false, /* pc_relative */
1457 0, /* bitpos */
1458 complain_overflow_bitfield, /* complain_on_overflow */
1459 0, /* special_function */
1460 "R_GL", /* name */
1461 true, /* partial_inplace */
1462 0xffff, /* src_mask */
1463 0xffff, /* dst_mask */
1464 false), /* pcrel_offset */
1465
1466 /* Local TOC relative symbol. */
1467 HOWTO (6, /* type */
1468 0, /* rightshift */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 16, /* bitsize */
1471 false, /* pc_relative */
1472 0, /* bitpos */
1473 complain_overflow_bitfield, /* complain_on_overflow */
1474 0, /* special_function */
1475 "R_TCL", /* name */
1476 true, /* partial_inplace */
1477 0xffff, /* src_mask */
1478 0xffff, /* dst_mask */
1479 false), /* pcrel_offset */
1480
1481 EMPTY_HOWTO (7),
1482
1483 /* Non modifiable absolute branch. */
1484 HOWTO (8, /* type */
1485 0, /* rightshift */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1487 26, /* bitsize */
1488 false, /* pc_relative */
1489 0, /* bitpos */
1490 complain_overflow_bitfield, /* complain_on_overflow */
1491 0, /* special_function */
1492 "R_BA", /* name */
1493 true, /* partial_inplace */
1494 0x3fffffc, /* src_mask */
1495 0x3fffffc, /* dst_mask */
1496 false), /* pcrel_offset */
1497
1498 EMPTY_HOWTO (9),
1499
1500 /* Non modifiable relative branch. */
1501 HOWTO (0xa, /* type */
1502 0, /* rightshift */
1503 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 26, /* bitsize */
1505 true, /* pc_relative */
1506 0, /* bitpos */
1507 complain_overflow_signed, /* complain_on_overflow */
1508 0, /* special_function */
1509 "R_BR", /* name */
1510 true, /* partial_inplace */
1511 0x3fffffc, /* src_mask */
1512 0x3fffffc, /* dst_mask */
1513 false), /* pcrel_offset */
1514
1515 EMPTY_HOWTO (0xb),
1516
1517 /* Indirect load. */
1518 HOWTO (0xc, /* type */
1519 0, /* rightshift */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1521 16, /* bitsize */
1522 false, /* pc_relative */
1523 0, /* bitpos */
1524 complain_overflow_bitfield, /* complain_on_overflow */
1525 0, /* special_function */
1526 "R_RL", /* name */
1527 true, /* partial_inplace */
1528 0xffff, /* src_mask */
1529 0xffff, /* dst_mask */
1530 false), /* pcrel_offset */
1531
1532 /* Load address. */
1533 HOWTO (0xd, /* type */
1534 0, /* rightshift */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1536 16, /* bitsize */
1537 false, /* pc_relative */
1538 0, /* bitpos */
1539 complain_overflow_bitfield, /* complain_on_overflow */
1540 0, /* special_function */
1541 "R_RLA", /* name */
1542 true, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 false), /* pcrel_offset */
1546
1547 EMPTY_HOWTO (0xe),
1548
1549 /* Non-relocating reference. */
1550 HOWTO (0xf, /* type */
1551 0, /* rightshift */
1552 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 32, /* bitsize */
1554 false, /* pc_relative */
1555 0, /* bitpos */
1556 complain_overflow_bitfield, /* complain_on_overflow */
1557 0, /* special_function */
1558 "R_REF", /* name */
1559 false, /* partial_inplace */
1560 0, /* src_mask */
1561 0, /* dst_mask */
1562 false), /* pcrel_offset */
1563
1564 EMPTY_HOWTO (0x10),
1565 EMPTY_HOWTO (0x11),
1566
1567 /* TOC relative indirect load. */
1568 HOWTO (0x12, /* type */
1569 0, /* rightshift */
1570 2, /* size (0 = byte, 1 = short, 2 = long) */
1571 16, /* bitsize */
1572 false, /* pc_relative */
1573 0, /* bitpos */
1574 complain_overflow_bitfield, /* complain_on_overflow */
1575 0, /* special_function */
1576 "R_TRL", /* name */
1577 true, /* partial_inplace */
1578 0xffff, /* src_mask */
1579 0xffff, /* dst_mask */
1580 false), /* pcrel_offset */
1581
1582 /* TOC relative load address. */
1583 HOWTO (0x13, /* type */
1584 0, /* rightshift */
1585 2, /* size (0 = byte, 1 = short, 2 = long) */
1586 16, /* bitsize */
1587 false, /* pc_relative */
1588 0, /* bitpos */
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 */
1596
1597 /* Modifiable relative branch. */
1598 HOWTO (0x14, /* type */
1599 1, /* rightshift */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1601 32, /* bitsize */
1602 false, /* pc_relative */
1603 0, /* bitpos */
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 */
1611
1612 /* Modifiable absolute branch. */
1613 HOWTO (0x15, /* type */
1614 1, /* rightshift */
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 32, /* bitsize */
1617 false, /* pc_relative */
1618 0, /* bitpos */
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 */
1626
1627 /* Modifiable call absolute indirect. */
1628 HOWTO (0x16, /* type */
1629 0, /* rightshift */
1630 2, /* size (0 = byte, 1 = short, 2 = long) */
1631 16, /* bitsize */
1632 false, /* pc_relative */
1633 0, /* bitpos */
1634 complain_overflow_bitfield, /* complain_on_overflow */
1635 0, /* special_function */
1636 "R_CAI", /* name */
1637 true, /* partial_inplace */
1638 0xffff, /* src_mask */
1639 0xffff, /* dst_mask */
1640 false), /* pcrel_offset */
1641
1642 /* Modifiable call relative. */
1643 HOWTO (0x17, /* type */
1644 0, /* rightshift */
1645 2, /* size (0 = byte, 1 = short, 2 = long) */
1646 16, /* bitsize */
1647 false, /* pc_relative */
1648 0, /* bitpos */
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 */
1656
1657 /* Modifiable branch absolute. */
1658 HOWTO (0x18, /* type */
1659 0, /* rightshift */
1660 2, /* size (0 = byte, 1 = short, 2 = long) */
1661 26, /* bitsize */
1662 false, /* pc_relative */
1663 0, /* bitpos */
1664 complain_overflow_bitfield, /* complain_on_overflow */
1665 0, /* special_function */
1666 "R_RBA", /* name */
1667 true, /* partial_inplace */
1668 0xffff, /* src_mask */
1669 0xffff, /* dst_mask */
1670 false), /* pcrel_offset */
1671
1672 /* Modifiable branch absolute. */
1673 HOWTO (0x19, /* type */
1674 0, /* rightshift */
1675 2, /* size (0 = byte, 1 = short, 2 = long) */
1676 32, /* bitsize */
1677 false, /* pc_relative */
1678 0, /* bitpos */
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 */
1686
1687 /* Modifiable branch relative. */
1688 HOWTO (0x1a, /* type */
1689 0, /* rightshift */
1690 2, /* size (0 = byte, 1 = short, 2 = long) */
1691 26, /* bitsize */
1692 false, /* pc_relative */
1693 0, /* bitpos */
1694 complain_overflow_signed, /* complain_on_overflow */
1695 0, /* special_function */
1696 "R_RBR", /* name */
1697 true, /* partial_inplace */
1698 0xffff, /* src_mask */
1699 0xffff, /* dst_mask */
1700 false), /* pcrel_offset */
1701
1702 /* Modifiable branch absolute. */
1703 HOWTO (0x1b, /* type */
1704 0, /* rightshift */
1705 2, /* size (0 = byte, 1 = short, 2 = long) */
1706 16, /* bitsize */
1707 false, /* pc_relative */
1708 0, /* bitpos */
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 */
1716
1717 HOWTO (0, /* type */
1718 0, /* rightshift */
1719 4, /* size (0 = byte, 1 = short, 2 = long) */
1720 64, /* bitsize */
1721 false, /* pc_relative */
1722 0, /* bitpos */
1723 complain_overflow_bitfield, /* complain_on_overflow */
1724 0, /* special_function */
1725 "R_POS", /* name */
1726 true, /* partial_inplace */
1727 MINUS_ONE, /* src_mask */
1728 MINUS_ONE, /* dst_mask */
1729 false) /* pcrel_offset */
1730 };
1731
1732 void
1733 xcoff64_rtype2howto (relent, internal)
1734 arelent *relent;
1735 struct internal_reloc *internal;
1736 {
1737 relent->howto = xcoff64_howto_table + internal->r_type;
1738
1739 /* Check for relocs we don't know of. */
1740 if (internal->r_type
1741 >= sizeof (xcoff64_howto_table) / sizeof (xcoff64_howto_table[0]))
1742 abort ();
1743 if (internal->r_type != relent->howto->type)
1744 abort ();
1745
1746 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1747 relocation, as well as indicating whether it is signed or not.
1748 Doublecheck that the relocation information gathered from the
1749 type matches this information. The bitsize is not significant
1750 for R_REF relocs. */
1751 if (relent->howto->dst_mask != 0
1752 && (relent->howto->bitsize
1753 != ((unsigned int) internal->r_size & 0x3f) + 1))
1754 abort ();
1755 #if 0
1756 if ((internal->r_size & 0x80) != 0
1757 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
1758 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
1759 abort ();
1760 #endif
1761 }
1762
1763 reloc_howto_type *
1764 xcoff64_reloc_type_lookup (abfd, code)
1765 bfd *abfd ATTRIBUTE_UNUSED;
1766 bfd_reloc_code_real_type code;
1767 {
1768 switch (code)
1769 {
1770 case BFD_RELOC_PPC_B26:
1771 return &xcoff64_howto_table[0xa];
1772 case BFD_RELOC_PPC_BA26:
1773 return &xcoff64_howto_table[8];
1774 case BFD_RELOC_PPC_TOC16:
1775 return &xcoff64_howto_table[3];
1776 case BFD_RELOC_32:
1777 case BFD_RELOC_CTOR:
1778 return &xcoff64_howto_table[0];
1779 case BFD_RELOC_64:
1780 return &xcoff64_howto_table[0x1c];
1781 default:
1782 return NULL;
1783 }
1784 }
1785
1786
1787
1788 /* Read in the armap of an XCOFF archive. */
1789
1790 static boolean
1791 xcoff64_slurp_armap (abfd)
1792 bfd *abfd;
1793 {
1794 file_ptr off;
1795 size_t namlen;
1796 bfd_size_type sz, amt;
1797 bfd_byte *contents, *cend;
1798 bfd_vma c, i;
1799 carsym *arsym;
1800 bfd_byte *p;
1801 file_ptr pos;
1802
1803 /* This is for the new format. */
1804 struct xcoff_ar_hdr_big hdr;
1805
1806 if (xcoff_ardata (abfd) == NULL)
1807 {
1808 bfd_has_map (abfd) = false;
1809 return true;
1810 }
1811
1812 off = strtol (xcoff_ardata_big (abfd)->symoff64, (char **) NULL, 10);
1813 if (off == 0)
1814 {
1815 bfd_has_map (abfd) = false;
1816 return true;
1817 }
1818
1819 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1820 return false;
1821
1822 /* The symbol table starts with a normal archive header. */
1823 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1824 != SIZEOF_AR_HDR_BIG)
1825 return false;
1826
1827 /* Skip the name (normally empty). */
1828 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1829 pos = ((namlen + 1) & ~(size_t) 1) + SXCOFFARFMAG;
1830 if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
1831 return false;
1832
1833 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1834 machines) since the field width is 20 and there numbers with more
1835 than 32 bits can be represented. */
1836 sz = strtol (hdr.size, (char **) NULL, 10);
1837
1838 /* Read in the entire symbol table. */
1839 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1840 if (contents == NULL)
1841 return false;
1842 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1843 return false;
1844
1845 /* The symbol table starts with an eight byte count. */
1846 c = H_GET_64 (abfd, contents);
1847
1848 if (c * 8 >= sz)
1849 {
1850 bfd_set_error (bfd_error_bad_value);
1851 return false;
1852 }
1853 amt = c;
1854 amt *= sizeof (carsym);
1855 bfd_ardata (abfd)->symdefs = (carsym *) bfd_alloc (abfd, amt);
1856 if (bfd_ardata (abfd)->symdefs == NULL)
1857 return false;
1858
1859 /* After the count comes a list of eight byte file offsets. */
1860 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1861 i < c;
1862 ++i, ++arsym, p += 8)
1863 arsym->file_offset = H_GET_64 (abfd, p);
1864
1865 /* After the file offsets come null terminated symbol names. */
1866 cend = contents + sz;
1867 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1868 i < c;
1869 ++i, ++arsym, p += strlen ((char *) p) + 1)
1870 {
1871 if (p >= cend)
1872 {
1873 bfd_set_error (bfd_error_bad_value);
1874 return false;
1875 }
1876 arsym->name = (char *) p;
1877 }
1878
1879 bfd_ardata (abfd)->symdef_count = c;
1880 bfd_has_map (abfd) = true;
1881
1882 return true;
1883 }
1884
1885
1886 /* See if this is an NEW XCOFF archive. */
1887
1888 static const bfd_target *
1889 xcoff64_archive_p (abfd)
1890 bfd *abfd;
1891 {
1892 char magic[SXCOFFARMAG];
1893 /* This is the new format. */
1894 struct xcoff_ar_file_hdr_big hdr;
1895 bfd_size_type amt = SXCOFFARMAG;
1896
1897 if (bfd_bread ((PTR) magic, amt, abfd) != amt)
1898 {
1899 if (bfd_get_error () != bfd_error_system_call)
1900 bfd_set_error (bfd_error_wrong_format);
1901 return NULL;
1902 }
1903
1904 if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1905 {
1906 bfd_set_error (bfd_error_wrong_format);
1907 return NULL;
1908 }
1909
1910 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1911 involves a cast, we can't do it as the left operand of
1912 assignment. */
1913 amt = sizeof (struct artdata);
1914 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
1915
1916 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1917 return NULL;
1918
1919 bfd_ardata (abfd)->cache = NULL;
1920 bfd_ardata (abfd)->archive_head = NULL;
1921 bfd_ardata (abfd)->symdefs = NULL;
1922 bfd_ardata (abfd)->extended_names = NULL;
1923
1924 /* Copy over the magic string. */
1925 memcpy (hdr.magic, magic, SXCOFFARMAG);
1926
1927 /* Now read the rest of the file header. */
1928 if (bfd_bread ((PTR) &hdr.memoff,
1929 (bfd_size_type) (SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG),
1930 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1931 {
1932 if (bfd_get_error () != bfd_error_system_call)
1933 bfd_set_error (bfd_error_wrong_format);
1934 return NULL;
1935 }
1936
1937 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1938 machines) since the field width is 20 and there numbers with more
1939 than 32 bits can be represented. */
1940 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1941 (char **) NULL, 10);
1942
1943 amt = SIZEOF_AR_FILE_HDR_BIG;
1944 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1945 if (bfd_ardata (abfd)->tdata == NULL)
1946 return NULL;
1947
1948 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1949
1950 if (! xcoff64_slurp_armap (abfd))
1951 {
1952 bfd_release (abfd, bfd_ardata (abfd));
1953 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1954 return NULL;
1955 }
1956
1957 return abfd->xvec;
1958 }
1959
1960
1961 /* Open the next element in an XCOFF archive. */
1962
1963 static bfd *
1964 xcoff64_openr_next_archived_file (archive, last_file)
1965 bfd *archive;
1966 bfd *last_file;
1967 {
1968 file_ptr filestart;
1969
1970 if ((xcoff_ardata (archive) == NULL)
1971 || ! xcoff_big_format_p (archive))
1972 {
1973 bfd_set_error (bfd_error_invalid_operation);
1974 return NULL;
1975 }
1976
1977 if (last_file == NULL)
1978 {
1979 filestart = bfd_ardata (archive)->first_file_filepos;
1980 }
1981 else
1982 {
1983 /* XXX These actually have to be a calls to strtoll (at least
1984 on 32-bit machines) since the fields's width is 20 and
1985 there numbers with more than 32 bits can be represented. */
1986 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1987 10);
1988 }
1989 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1990 machines) since the fields's width is 20 and there numbers with more
1991 than 32 bits can be represented. */
1992 if (filestart == 0
1993 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1994 (char **) NULL, 10)
1995 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1996 (char **) NULL, 10))
1997 {
1998 bfd_set_error (bfd_error_no_more_archived_files);
1999 return NULL;
2000 }
2001
2002 return _bfd_get_elt_at_filepos (archive, filestart);
2003 }
2004
2005 /* We can't use the usual coff_sizeof_headers routine, because AIX
2006 always uses an a.out header. */
2007
2008 /*ARGSUSED*/
2009 static int
2010 xcoff64_sizeof_headers (abfd, reloc)
2011 bfd *abfd;
2012 boolean reloc ATTRIBUTE_UNUSED;
2013 {
2014 int size;
2015
2016 size = bfd_coff_filhsz (abfd);
2017
2018 /* Don't think the small aout header can be used since some of the
2019 old elements have been reordered past the end of the old coff
2020 small aout size. */
2021
2022 if (xcoff_data (abfd)->full_aouthdr)
2023 size += bfd_coff_aoutsz (abfd);
2024
2025 size += abfd->section_count * bfd_coff_scnhsz (abfd);
2026 return size;
2027 }
2028
2029
2030
2031 static asection *
2032 xcoff64_create_csect_from_smclas (abfd, aux, symbol_name)
2033 bfd *abfd;
2034 union internal_auxent *aux;
2035 const char *symbol_name;
2036 {
2037 asection *return_value = NULL;
2038
2039 /* Changes from 32 :
2040 .sv == 8, is only for 32 bit programs
2041 .ti == 12 and .tb == 13 are now reserved. */
2042 static const char *names[19] =
2043 {
2044 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2045 NULL, ".bs", ".ds", ".uc", NULL, NULL, NULL, ".tc0",
2046 ".td", ".sv64", ".sv3264"
2047 };
2048
2049 if ((19 >= aux->x_csect.x_smclas)
2050 && (NULL != names[aux->x_csect.x_smclas]))
2051 {
2052
2053 return_value = bfd_make_section_anyway
2054 (abfd, names[aux->x_csect.x_smclas]);
2055
2056 }
2057 else
2058 {
2059 (*_bfd_error_handler)
2060 (_("%s: symbol `%s' has unrecognized smclas %d"),
2061 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2062 bfd_set_error (bfd_error_bad_value);
2063 }
2064
2065 return return_value;
2066 }
2067
2068 static boolean
2069 xcoff64_is_lineno_count_overflow (abfd, value)
2070 bfd *abfd ATTRIBUTE_UNUSED;
2071 bfd_vma value ATTRIBUTE_UNUSED;
2072 {
2073 return false;
2074 }
2075
2076 static boolean
2077 xcoff64_is_reloc_count_overflow (abfd, value)
2078 bfd *abfd ATTRIBUTE_UNUSED;
2079 bfd_vma value ATTRIBUTE_UNUSED;
2080 {
2081 return false;
2082 }
2083
2084 static bfd_vma
2085 xcoff64_loader_symbol_offset (abfd, ldhdr)
2086 bfd *abfd ATTRIBUTE_UNUSED;
2087 struct internal_ldhdr *ldhdr;
2088 {
2089 return (ldhdr->l_symoff);
2090 }
2091
2092 static bfd_vma
2093 xcoff64_loader_reloc_offset (abfd, ldhdr)
2094 bfd *abfd ATTRIBUTE_UNUSED;
2095 struct internal_ldhdr *ldhdr;
2096 {
2097 return (ldhdr->l_rldoff);
2098 }
2099
2100 static boolean
2101 xcoff64_generate_rtinit (abfd, init, fini, rtld)
2102 bfd *abfd;
2103 const char *init;
2104 const char *fini;
2105 boolean rtld;
2106 {
2107 bfd_byte filehdr_ext[FILHSZ];
2108 bfd_byte scnhdr_ext[SCNHSZ * 3];
2109 bfd_byte syment_ext[SYMESZ * 10];
2110 bfd_byte reloc_ext[RELSZ * 3];
2111 bfd_byte *data_buffer;
2112 bfd_size_type data_buffer_size;
2113 bfd_byte *string_table, *st_tmp;
2114 bfd_size_type string_table_size;
2115 bfd_vma val;
2116 size_t initsz, finisz;
2117 struct internal_filehdr filehdr;
2118 struct internal_scnhdr text_scnhdr;
2119 struct internal_scnhdr data_scnhdr;
2120 struct internal_scnhdr bss_scnhdr;
2121 struct internal_syment syment;
2122 union internal_auxent auxent;
2123 struct internal_reloc reloc;
2124
2125 char *text_name = ".text";
2126 char *data_name = ".data";
2127 char *bss_name = ".bss";
2128 char *rtinit_name = "__rtinit";
2129 char *rtld_name = "__rtld";
2130
2131 if (! bfd_xcoff_rtinit_size (abfd))
2132 return false;
2133
2134 initsz = (init == NULL ? 0 : 1 + strlen (init));
2135 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
2136
2137 /* file header */
2138 memset (filehdr_ext, 0, FILHSZ);
2139 memset (&filehdr, 0, sizeof (struct internal_filehdr));
2140 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
2141 filehdr.f_nscns = 3;
2142 filehdr.f_timdat = 0;
2143 filehdr.f_nsyms = 0; /* at least 6, no more than 8 */
2144 filehdr.f_symptr = 0; /* set below */
2145 filehdr.f_opthdr = 0;
2146 filehdr.f_flags = 0;
2147
2148 /* section headers */
2149 memset (scnhdr_ext, 0, 3 * SCNHSZ);
2150
2151 /* text */
2152 memset (&text_scnhdr, 0, sizeof (struct internal_scnhdr));
2153 memcpy (text_scnhdr.s_name, text_name, strlen (text_name));
2154 text_scnhdr.s_paddr = 0;
2155 text_scnhdr.s_vaddr = 0;
2156 text_scnhdr.s_size = 0;
2157 text_scnhdr.s_scnptr = 0;
2158 text_scnhdr.s_relptr = 0;
2159 text_scnhdr.s_lnnoptr = 0;
2160 text_scnhdr.s_nreloc = 0;
2161 text_scnhdr.s_nlnno = 0;
2162 text_scnhdr.s_flags = STYP_TEXT;
2163
2164 /* data */
2165 memset (&data_scnhdr, 0, sizeof (struct internal_scnhdr));
2166 memcpy (data_scnhdr.s_name, data_name, strlen (data_name));
2167 data_scnhdr.s_paddr = 0;
2168 data_scnhdr.s_vaddr = 0;
2169 data_scnhdr.s_size = 0; /* set below */
2170 data_scnhdr.s_scnptr = FILHSZ + 3 * SCNHSZ;
2171 data_scnhdr.s_relptr = 0; /* set below */
2172 data_scnhdr.s_lnnoptr = 0;
2173 data_scnhdr.s_nreloc = 0; /* either 1 or 2 */
2174 data_scnhdr.s_nlnno = 0;
2175 data_scnhdr.s_flags = STYP_DATA;
2176
2177 /* bss */
2178 memset (&bss_scnhdr, 0, sizeof (struct internal_scnhdr));
2179 memcpy (bss_scnhdr.s_name, bss_name, strlen (bss_name));
2180 bss_scnhdr.s_paddr = 0; /* set below */
2181 bss_scnhdr.s_vaddr = 0; /* set below */
2182 bss_scnhdr.s_size = 0; /* set below */
2183 bss_scnhdr.s_scnptr = 0;
2184 bss_scnhdr.s_relptr = 0;
2185 bss_scnhdr.s_lnnoptr = 0;
2186 bss_scnhdr.s_nreloc = 0;
2187 bss_scnhdr.s_nlnno = 0;
2188 bss_scnhdr.s_flags = STYP_BSS;
2189
2190 /* .data
2191 0x0000 0x00000000 : rtl
2192 0x0004 0x00000000 :
2193 0x0008 0x00000018 : offset to init, or 0
2194 0x000C 0x00000038 : offset to fini, or 0
2195 0x0010 0x00000010 : size of descriptor
2196 0x0014 0x00000000 : pad
2197 0x0018 0x00000000 : init, needs a reloc
2198 0x001C 0x00000000 :
2199 0x0020 0x00000058 : offset to init name
2200 0x0024 0x00000000 : flags, padded to a word
2201 0x0028 0x00000000 : empty init
2202 0x002C 0x00000000 :
2203 0x0030 0x00000000 :
2204 0x0034 0x00000000 :
2205 0x0038 0x00000000 : fini, needs a reloc
2206 0x003C 0x00000000 :
2207 0x0040 0x00000??? : offset to fini name
2208 0x0044 0x00000000 : flags, padded to a word
2209 0x0048 0x00000000 : empty fini
2210 0x004C 0x00000000 :
2211 0x0050 0x00000000 :
2212 0x0054 0x00000000 :
2213 0x0058 init name
2214 0x0058 + initsz fini name */
2215
2216 data_buffer_size = 0x0058 + initsz + finisz;
2217 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
2218 data_buffer = NULL;
2219 data_buffer = (bfd_byte *)bfd_malloc (data_buffer_size);
2220 if (data_buffer == NULL)
2221 return false;
2222
2223 memset (data_buffer, 0, data_buffer_size);
2224
2225 if (initsz)
2226 {
2227 val = 0x18;
2228 bfd_put_32 (abfd, val, &data_buffer[0x08]);
2229 val = 0x58;
2230 bfd_put_32 (abfd, val, &data_buffer[0x20]);
2231 memcpy (&data_buffer[val], init, initsz);
2232 }
2233
2234 if (finisz)
2235 {
2236 val = 0x38;
2237 bfd_put_32 (abfd, val, &data_buffer[0x0C]);
2238 val = 0x58 + initsz;
2239 bfd_put_32 (abfd, val, &data_buffer[0x40]);
2240 memcpy (&data_buffer[val], fini, finisz);
2241 }
2242
2243 val = 0x10;
2244 bfd_put_32 (abfd, val, &data_buffer[0x10]);
2245 data_scnhdr.s_size = data_buffer_size;
2246 bss_scnhdr.s_paddr = bss_scnhdr.s_vaddr = data_scnhdr.s_size;
2247
2248 /* string table */
2249 string_table_size = 4;
2250 string_table_size += strlen (data_name) + 1;
2251 string_table_size += strlen (rtinit_name) + 1;
2252 string_table_size += initsz;
2253 string_table_size += finisz;
2254 if (true == rtld)
2255 string_table_size += strlen (rtld_name) + 1;
2256
2257 string_table = (bfd_byte *)bfd_malloc (string_table_size);
2258 memset (string_table, 0, string_table_size);
2259 val = string_table_size;
2260 bfd_put_32 (abfd, val, &string_table[0]);
2261 st_tmp = string_table + 4;
2262
2263 /* symbols
2264 0. .data csect
2265 2. __rtinit
2266 4. init function
2267 6. fini function
2268 8. __rtld */
2269 memset (syment_ext, 0, 10 * SYMESZ);
2270 memset (reloc_ext, 0, 3 * RELSZ);
2271
2272 /* .data csect */
2273 memset (&syment, 0, sizeof (struct internal_syment));
2274 memset (&auxent, 0, sizeof (union internal_auxent));
2275
2276 syment._n._n_n._n_offset = st_tmp - string_table;
2277 memcpy (st_tmp, data_name, strlen (data_name));
2278 st_tmp += strlen (data_name) + 1;
2279
2280 syment.n_scnum = 2;
2281 syment.n_sclass = C_HIDEXT;
2282 syment.n_numaux = 1;
2283 auxent.x_csect.x_scnlen.l = data_buffer_size;
2284 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
2285 auxent.x_csect.x_smclas = XMC_RW;
2286 bfd_coff_swap_sym_out (abfd, &syment,
2287 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2288 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2289 syment.n_numaux,
2290 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2291 filehdr.f_nsyms += 2;
2292
2293 /* __rtinit */
2294 memset (&syment, 0, sizeof (struct internal_syment));
2295 memset (&auxent, 0, sizeof (union internal_auxent));
2296 syment._n._n_n._n_offset = st_tmp - string_table;
2297 memcpy (st_tmp, rtinit_name, strlen (rtinit_name));
2298 st_tmp += strlen (rtinit_name) + 1;
2299
2300 syment.n_scnum = 2;
2301 syment.n_sclass = C_EXT;
2302 syment.n_numaux = 1;
2303 auxent.x_csect.x_smtyp = XTY_LD;
2304 auxent.x_csect.x_smclas = XMC_RW;
2305 bfd_coff_swap_sym_out (abfd, &syment,
2306 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2307 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2308 syment.n_numaux,
2309 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2310 filehdr.f_nsyms += 2;
2311
2312 /* init */
2313 if (initsz)
2314 {
2315 memset (&syment, 0, sizeof (struct internal_syment));
2316 memset (&auxent, 0, sizeof (union internal_auxent));
2317
2318 syment._n._n_n._n_offset = st_tmp - string_table;
2319 memcpy (st_tmp, init, initsz);
2320 st_tmp += initsz;
2321
2322 syment.n_sclass = C_EXT;
2323 syment.n_numaux = 1;
2324 bfd_coff_swap_sym_out (abfd, &syment,
2325 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2326 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2327 syment.n_numaux,
2328 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2329 /* reloc */
2330 memset (&reloc, 0, sizeof (struct internal_reloc));
2331 reloc.r_vaddr = 0x0018;
2332 reloc.r_symndx = filehdr.f_nsyms;
2333 reloc.r_type = R_POS;
2334 reloc.r_size = 63;
2335 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
2336
2337 filehdr.f_nsyms += 2;
2338 data_scnhdr.s_nreloc += 1;
2339 }
2340
2341 /* finit */
2342 if (finisz)
2343 {
2344 memset (&syment, 0, sizeof (struct internal_syment));
2345 memset (&auxent, 0, sizeof (union internal_auxent));
2346
2347 syment._n._n_n._n_offset = st_tmp - string_table;
2348 memcpy (st_tmp, fini, finisz);
2349 st_tmp += finisz;
2350
2351 syment.n_sclass = C_EXT;
2352 syment.n_numaux = 1;
2353 bfd_coff_swap_sym_out (abfd, &syment,
2354 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2355 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2356 syment.n_numaux,
2357 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2358
2359 /* reloc */
2360 memset (&reloc, 0, sizeof (struct internal_reloc));
2361 reloc.r_vaddr = 0x0038;
2362 reloc.r_symndx = filehdr.f_nsyms;
2363 reloc.r_type = R_POS;
2364 reloc.r_size = 63;
2365 bfd_coff_swap_reloc_out (abfd, &reloc,
2366 &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2367
2368 filehdr.f_nsyms += 2;
2369 data_scnhdr.s_nreloc += 1;
2370 }
2371
2372 if (rtld)
2373 {
2374 memset (&syment, 0, sizeof (struct internal_syment));
2375 memset (&auxent, 0, sizeof (union internal_auxent));
2376
2377 syment._n._n_n._n_offset = st_tmp - string_table;
2378 memcpy (st_tmp, rtld_name, strlen (rtld_name));
2379 st_tmp += strlen (rtld_name) + 1;
2380
2381 syment.n_sclass = C_EXT;
2382 syment.n_numaux = 1;
2383 bfd_coff_swap_sym_out (abfd, &syment,
2384 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2385 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2386 syment.n_numaux,
2387 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2388
2389 /* reloc */
2390 memset (&reloc, 0, sizeof (struct internal_reloc));
2391 reloc.r_vaddr = 0x0000;
2392 reloc.r_symndx = filehdr.f_nsyms;
2393 reloc.r_type = R_POS;
2394 reloc.r_size = 63;
2395 bfd_coff_swap_reloc_out (abfd, &reloc,
2396 &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2397
2398 filehdr.f_nsyms += 2;
2399 data_scnhdr.s_nreloc += 1;
2400
2401 bss_scnhdr.s_size = 0;
2402 }
2403
2404 data_scnhdr.s_relptr = data_scnhdr.s_scnptr + data_buffer_size;
2405 filehdr.f_symptr = data_scnhdr.s_relptr + data_scnhdr.s_nreloc * RELSZ;
2406
2407 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
2408 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
2409 bfd_coff_swap_scnhdr_out (abfd, &text_scnhdr, &scnhdr_ext[SCNHSZ * 0]);
2410 bfd_coff_swap_scnhdr_out (abfd, &data_scnhdr, &scnhdr_ext[SCNHSZ * 1]);
2411 bfd_coff_swap_scnhdr_out (abfd, &bss_scnhdr, &scnhdr_ext[SCNHSZ * 2]);
2412 bfd_bwrite (scnhdr_ext, 3 * SCNHSZ, abfd);
2413 bfd_bwrite (data_buffer, data_buffer_size, abfd);
2414 bfd_bwrite (reloc_ext, data_scnhdr.s_nreloc * RELSZ, abfd);
2415 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
2416 bfd_bwrite (string_table, string_table_size, abfd);
2417
2418 free (data_buffer);
2419 data_buffer = NULL;
2420
2421 return true;
2422 }
2423
2424 /* The typical dynamic reloc. */
2425
2426 static reloc_howto_type xcoff64_dynamic_reloc =
2427 HOWTO (0, /* type */
2428 0, /* rightshift */
2429 4, /* size (0 = byte, 1 = short, 2 = long) */
2430 64, /* bitsize */
2431 false, /* pc_relative */
2432 0, /* bitpos */
2433 complain_overflow_bitfield, /* complain_on_overflow */
2434 0, /* special_function */
2435 "R_POS", /* name */
2436 true, /* partial_inplace */
2437 MINUS_ONE, /* src_mask */
2438 MINUS_ONE, /* dst_mask */
2439 false); /* pcrel_offset */
2440
2441 static unsigned long xcoff64_glink_code[10] =
2442 {
2443 0xe9820000, /* ld r12,0(r2) */
2444 0xf8410028, /* std r2,40(r1) */
2445 0xe80c0000, /* ld r0,0(r12) */
2446 0xe84c0008, /* ld r0,8(r12) */
2447 0x7c0903a6, /* mtctr r0 */
2448 0x4e800420, /* bctr */
2449 0x00000000, /* start of traceback table */
2450 0x000ca000, /* traceback table */
2451 0x00000000, /* traceback table */
2452 0x00000018, /* ??? */
2453 };
2454
2455 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2456 {
2457 { /* COFF backend, defined in libcoff.h */
2458 _bfd_xcoff64_swap_aux_in, /* _bfd_coff_swap_aux_in */
2459 _bfd_xcoff64_swap_sym_in, /* _bfd_coff_swap_sym_in */
2460 _bfd_xcoff64_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2461 _bfd_xcoff64_swap_aux_out, /* _bfd_swap_aux_out */
2462 _bfd_xcoff64_swap_sym_out, /* _bfd_swap_sym_out */
2463 _bfd_xcoff64_swap_lineno_out, /* _bfd_swap_lineno_out */
2464 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2465 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2466 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2467 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2468 FILHSZ, /* _bfd_filhsz */
2469 AOUTSZ, /* _bfd_aoutsz */
2470 SCNHSZ, /* _bfd_scnhsz */
2471 SYMESZ, /* _bfd_symesz */
2472 AUXESZ, /* _bfd_auxesz */
2473 RELSZ, /* _bfd_relsz */
2474 LINESZ, /* _bfd_linesz */
2475 FILNMLEN, /* _bfd_filnmlen */
2476 true, /* _bfd_coff_long_filenames */
2477 false, /* _bfd_coff_long_section_names */
2478 (3), /* _bfd_coff_default_section_alignment_power */
2479 true, /* _bfd_coff_force_symnames_in_strings */
2480 4, /* _bfd_coff_debug_string_prefix_length */
2481 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2482 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2483 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2484 coff_swap_reloc_in, /* _bfd_reloc_in */
2485 coff_bad_format_hook, /* _bfd_bad_format_hook */
2486 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2487 coff_mkobject_hook, /* _bfd_mkobject_hook */
2488 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2489 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2490 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2491 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2492 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2493 coff_print_aux, /* bfd_coff_print_aux */
2494 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2495 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2496 NULL, /* bfd_coff_sym_is_global */
2497 /* _bfd_coff_compute_section_file_positions */
2498 coff_compute_section_file_positions,
2499 NULL , /* _bfd_coff_start_final_link */
2500 xcoff64_ppc_relocate_section, /* _bfd_coff_relocate_section */
2501 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2502 NULL , /* _bfd_coff_addust_symndx */
2503 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2504 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2505 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2506 },
2507
2508 0x01EF, /* magic number */
2509 bfd_arch_powerpc, /* architecture */
2510 bfd_mach_ppc_620, /* machine */
2511
2512 /* function pointers to xcoff specific swap routines */
2513 xcoff64_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2514 xcoff64_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2515 xcoff64_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
2516 xcoff64_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
2517 xcoff64_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
2518 xcoff64_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
2519
2520 /* sizes */
2521 LDHDRSZ, /* _xcoff_ldhdrsz */
2522 LDSYMSZ, /* _xcoff_ldsymsz */
2523 LDRELSZ, /* _xcoff_ldrelsz */
2524 24, /* _xcoff_function_descriptor_size */
2525 0, /* _xcoff_small_aout_header_size */
2526 /* versions */
2527 2, /* _xcoff_ldhdr_version */
2528
2529 /* xcoff vs xcoff64 putting symbol names */
2530 _bfd_xcoff64_put_symbol_name, /* _xcoff_put_symbol_name */
2531 _bfd_xcoff64_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
2532
2533 /* dynamic reloc howto */
2534 &xcoff64_dynamic_reloc,
2535
2536 xcoff64_create_csect_from_smclas,
2537
2538 /* lineno and reloc count overflow */
2539 xcoff64_is_lineno_count_overflow,
2540 xcoff64_is_reloc_count_overflow,
2541
2542 xcoff64_loader_symbol_offset,
2543 xcoff64_loader_reloc_offset,
2544
2545 /* glink */
2546 &xcoff64_glink_code[0],
2547 40, /* _xcoff_glink_size */
2548
2549 /* rtinit */
2550 88, /* _xcoff_rtinit_size */
2551 xcoff64_generate_rtinit, /* _xcoff_generate_rtinit */
2552 };
2553
2554 /* The transfer vector that leads the outside world to all of the above. */
2555 const bfd_target rs6000coff64_vec =
2556 {
2557 "aixcoff64-rs6000",
2558 bfd_target_xcoff_flavour,
2559 BFD_ENDIAN_BIG, /* data byte order is big */
2560 BFD_ENDIAN_BIG, /* header byte order is big */
2561
2562 (HAS_RELOC | EXEC_P | /* object flags */
2563 HAS_LINENO | HAS_DEBUG | DYNAMIC |
2564 HAS_SYMS | HAS_LOCALS | WP_TEXT),
2565
2566 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2567 0, /* leading char */
2568 '/', /* ar_pad_char */
2569 15, /* ar_max_namelen??? FIXMEmgo */
2570
2571 /* data */
2572 bfd_getb64, /* bfd_getx64 */
2573 bfd_getb_signed_64, /* bfd_getx_signed_64 */
2574 bfd_putb64, /* bfd_putx64 */
2575 bfd_getb32, /* bfd_getx32 */
2576 bfd_getb_signed_32, /* bfd_getx_signed_32 */
2577 bfd_putb32, /* bfd_putx32 */
2578 bfd_getb16, /* bfd_getx16 */
2579 bfd_getb_signed_16, /* bfd_getx_signed_16 */
2580 bfd_putb16, /* bfd_putx16 */
2581
2582 /* hdrs */
2583 bfd_getb64, /* bfd_h_getx64 */
2584 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
2585 bfd_putb64, /* bfd_h_putx64 */
2586 bfd_getb32, /* bfd_h_getx32 */
2587 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
2588 bfd_putb32, /* bfd_h_putx32 */
2589 bfd_getb16, /* bfd_h_getx16 */
2590 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
2591 bfd_putb16, /* bfd_h_putx16 */
2592
2593 { /* bfd_check_format */
2594 _bfd_dummy_target,
2595 coff_object_p,
2596 xcoff64_archive_p,
2597 CORE_FILE_P
2598 },
2599
2600 { /* bfd_set_format */
2601 bfd_false,
2602 coff_mkobject,
2603 _bfd_generic_mkarchive,
2604 bfd_false
2605 },
2606
2607 {/* bfd_write_contents */
2608 bfd_false,
2609 xcoff64_write_object_contents,
2610 _bfd_xcoff_write_archive_contents,
2611 bfd_false
2612 },
2613
2614 /* Generic */
2615 bfd_true, /* _close_and_cleanup */
2616 bfd_true, /* _bfd_free_cached_info */
2617 coff_new_section_hook, /* _new_section_hook */
2618 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
2619 /* _bfd_get_section_contents_in_window */
2620 _bfd_generic_get_section_contents_in_window,
2621
2622 /* Copy */
2623 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
2624 /* _bfd_merge_private_bfd_data */
2625 ((boolean (*) (bfd *, bfd *)) bfd_true),
2626 /* _bfd_copy_pivate_section_data */
2627 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
2628 /* _bfd_copy_private_symbol_data */
2629 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
2630 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
2631 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
2632
2633 /* Core */
2634 coff_core_file_failing_command, /* _core_file_failing_command */
2635 coff_core_file_failing_signal, /* _core_file_failing_signal */
2636 /* _core_file_matches_executable_p */
2637 coff_core_file_matches_executable_p,
2638
2639 /* Archive */
2640 xcoff64_slurp_armap, /* _slurp_armap */
2641 /* XCOFF archives do not have
2642 anything which corresponds to
2643 an extended name table. */
2644 bfd_false, /* _slurp_extended_name_table */
2645 /* _construct_extended_name_table */
2646 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
2647 bfd_dont_truncate_arname, /* _truncate_arname */
2648 _bfd_xcoff_write_armap, /* _write_armap */
2649 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
2650 xcoff64_openr_next_archived_file, /* _openr_next_archived_file */
2651 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
2652 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
2653 /* XCOFF archives do not have
2654 a timestamp. */
2655 bfd_true, /* _update_armap_timestamp */
2656
2657 /* Symbols */
2658 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
2659 coff_get_symtab, /* _get_symtab */
2660 coff_make_empty_symbol, /* _make_empty_symbol */
2661 coff_print_symbol, /* _print_symbol */
2662 coff_get_symbol_info, /* _get_symbol_info */
2663 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
2664 coff_get_lineno, /* _get_lineno */
2665 coff_find_nearest_line, /* _find_nearest_line */
2666 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
2667 _bfd_generic_read_minisymbols, /* _read_minisymbols */
2668 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
2669
2670 /* Reloc */
2671 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
2672 coff_canonicalize_reloc, /* _cononicalize_reloc */
2673 xcoff64_reloc_type_lookup, /* _bfd_reloc_type_lookup */
2674
2675 /* Write */
2676 coff_set_arch_mach, /* _set_arch_mach */
2677 coff_set_section_contents, /* _set_section_contents */
2678
2679 /* Link */
2680 xcoff64_sizeof_headers, /* _sizeof_headers */
2681 /* _bfd_get_relocated_section_contents */
2682 bfd_generic_get_relocated_section_contents,
2683 bfd_generic_relax_section, /* _bfd_relax_section */
2684 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
2685 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
2686 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
2687 _bfd_generic_link_split_section, /* _bfd_link_split_section */
2688 bfd_generic_gc_sections, /* _bfd_gc_sections */
2689 bfd_generic_merge_sections, /* _bfd_merge_sections */
2690
2691 /* Dynamic */
2692 /* _get_dynamic_symtab_upper_bound */
2693 _bfd_xcoff_get_dynamic_symtab_upper_bound,
2694 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
2695 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
2696 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
2697
2698 /* Opposite endian version, none exists */
2699 NULL,
2700
2701 /* back end data */
2702 (void *) &bfd_xcoff_backend_data,
2703 };
This page took 0.083357 seconds and 5 git commands to generate.