1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
6 Archive support from Damon A. Permezel.
7 Contributed by IBM Corporation and Cygnus Support.
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
27 #include "libiberty.h"
31 #include "coff/internal.h"
32 #include "coff/xcoff.h"
33 #include "coff/rs6000.h"
37 extern bfd_boolean
_bfd_xcoff_mkobject (bfd
*);
38 extern bfd_boolean
_bfd_xcoff_copy_private_bfd_data (bfd
*, bfd
*);
39 extern bfd_boolean
_bfd_xcoff_is_local_label_name (bfd
*, const char *);
40 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
41 (bfd
*, bfd_reloc_code_real_type
);
42 extern bfd_boolean
_bfd_xcoff_slurp_armap (bfd
*);
43 extern const bfd_target
*_bfd_xcoff_archive_p (bfd
*);
44 extern void * _bfd_xcoff_read_ar_hdr (bfd
*);
45 extern bfd
*_bfd_xcoff_openr_next_archived_file (bfd
*, bfd
*);
46 extern int _bfd_xcoff_stat_arch_elt (bfd
*, struct stat
*);
47 extern bfd_boolean _bfd_xcoff_write_armap
48 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
49 extern bfd_boolean
_bfd_xcoff_write_archive_contents (bfd
*);
50 extern int _bfd_xcoff_sizeof_headers (bfd
*, struct bfd_link_info
*);
51 extern void _bfd_xcoff_swap_sym_in (bfd
*, void *, void *);
52 extern unsigned int _bfd_xcoff_swap_sym_out (bfd
*, void *, void *);
53 extern void _bfd_xcoff_swap_aux_in (bfd
*, void *, int, int, int, int, void *);
54 extern unsigned int _bfd_xcoff_swap_aux_out
55 (bfd
*, void *, int, int, int, int, void *);
56 static void xcoff_swap_reloc_in (bfd
*, void *, void *);
57 static unsigned int xcoff_swap_reloc_out (bfd
*, void *, void *);
59 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
60 void xcoff_rtype2howto (arelent
*, struct internal_reloc
*);
62 /* coffcode.h needs these to be defined. */
63 #define RS6000COFF_C 1
65 #define SELECT_RELOC(internal, howto) \
67 internal.r_type = howto->type; \
69 ((howto->complain_on_overflow == complain_overflow_signed \
72 | (howto->bitsize - 1)); \
75 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
76 #define COFF_LONG_FILENAMES
77 #define NO_COFF_SYMBOLS
78 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
79 #define coff_mkobject _bfd_xcoff_mkobject
80 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
81 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
82 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
83 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
85 extern const bfd_target
* rs6000coff_core_p (bfd
*abfd
);
86 extern bfd_boolean rs6000coff_core_file_matches_executable_p
87 (bfd
*cbfd
, bfd
*ebfd
);
88 extern char *rs6000coff_core_file_failing_command (bfd
*abfd
);
89 extern int rs6000coff_core_file_failing_signal (bfd
*abfd
);
90 #define CORE_FILE_P rs6000coff_core_p
91 #define coff_core_file_failing_command \
92 rs6000coff_core_file_failing_command
93 #define coff_core_file_failing_signal \
94 rs6000coff_core_file_failing_signal
95 #define coff_core_file_matches_executable_p \
96 rs6000coff_core_file_matches_executable_p
97 #define coff_core_file_pid \
98 _bfd_nocore_core_file_pid
100 #define CORE_FILE_P _bfd_dummy_target
101 #define coff_core_file_failing_command \
102 _bfd_nocore_core_file_failing_command
103 #define coff_core_file_failing_signal \
104 _bfd_nocore_core_file_failing_signal
105 #define coff_core_file_matches_executable_p \
106 _bfd_nocore_core_file_matches_executable_p
107 #define coff_core_file_pid \
108 _bfd_nocore_core_file_pid
110 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
111 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
112 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
113 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
114 #define coff_swap_reloc_in xcoff_swap_reloc_in
115 #define coff_swap_reloc_out xcoff_swap_reloc_out
116 #define NO_COFF_RELOCS
118 #ifndef bfd_pe_print_pdata
119 #define bfd_pe_print_pdata NULL
122 #include "coffcode.h"
124 /* The main body of code is in coffcode.h. */
126 static const char *normalize_filename (bfd
*);
127 static bfd_boolean xcoff_write_armap_old
128 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
129 static bfd_boolean xcoff_write_armap_big
130 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
131 static bfd_boolean
xcoff_write_archive_contents_old (bfd
*);
132 static bfd_boolean
xcoff_write_archive_contents_big (bfd
*);
133 static void xcoff_swap_ldhdr_in (bfd
*, const void *, struct internal_ldhdr
*);
134 static void xcoff_swap_ldhdr_out (bfd
*, const struct internal_ldhdr
*, void *);
135 static void xcoff_swap_ldsym_in (bfd
*, const void *, struct internal_ldsym
*);
136 static void xcoff_swap_ldsym_out (bfd
*, const struct internal_ldsym
*, void *);
137 static void xcoff_swap_ldrel_in (bfd
*, const void *, struct internal_ldrel
*);
138 static void xcoff_swap_ldrel_out (bfd
*, const struct internal_ldrel
*, void *);
139 static bfd_boolean xcoff_ppc_relocate_section
140 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
141 struct internal_reloc
*, struct internal_syment
*, asection
**);
142 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
143 (bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*, const char *);
144 static asection
*xcoff_create_csect_from_smclas
145 (bfd
*, union internal_auxent
*, const char *);
146 static bfd_boolean
xcoff_is_lineno_count_overflow (bfd
*, bfd_vma
);
147 static bfd_boolean
xcoff_is_reloc_count_overflow (bfd
*, bfd_vma
);
148 static bfd_vma
xcoff_loader_symbol_offset (bfd
*, struct internal_ldhdr
*);
149 static bfd_vma
xcoff_loader_reloc_offset (bfd
*, struct internal_ldhdr
*);
150 static bfd_boolean xcoff_generate_rtinit
151 (bfd
*, const char *, const char *, bfd_boolean
);
152 static bfd_boolean
do_pad (bfd
*, unsigned int);
153 static bfd_boolean
do_copy (bfd
*, bfd
*);
155 /* Relocation functions */
156 static bfd_boolean
xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS
);
158 static bfd_boolean xcoff_complain_overflow_dont_func
159 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
160 static bfd_boolean xcoff_complain_overflow_bitfield_func
161 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
162 static bfd_boolean xcoff_complain_overflow_signed_func
163 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
164 static bfd_boolean xcoff_complain_overflow_unsigned_func
165 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
167 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
168 (XCOFF_RELOC_FUNCTION_ARGS
) =
170 xcoff_reloc_type_pos
, /* R_POS (0x00) */
171 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
172 xcoff_reloc_type_rel
, /* R_REL (0x02) */
173 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
174 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
175 xcoff_reloc_type_toc
, /* R_GL (0x05) */
176 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
177 xcoff_reloc_type_fail
, /* (0x07) */
178 xcoff_reloc_type_ba
, /* R_BA (0x08) */
179 xcoff_reloc_type_fail
, /* (0x09) */
180 xcoff_reloc_type_br
, /* R_BR (0x0a) */
181 xcoff_reloc_type_fail
, /* (0x0b) */
182 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
183 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
184 xcoff_reloc_type_fail
, /* (0x0e) */
185 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
186 xcoff_reloc_type_fail
, /* (0x10) */
187 xcoff_reloc_type_fail
, /* (0x11) */
188 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
189 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
190 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
191 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
192 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
193 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
194 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
195 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
196 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
197 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
200 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
201 (XCOFF_COMPLAIN_FUNCTION_ARGS
) =
203 xcoff_complain_overflow_dont_func
,
204 xcoff_complain_overflow_bitfield_func
,
205 xcoff_complain_overflow_signed_func
,
206 xcoff_complain_overflow_unsigned_func
,
209 /* Information about one member of an archive. */
210 struct member_layout
{
211 /* The archive member that this structure describes. */
214 /* The number of bytes of padding that must be inserted before the
215 start of the member in order to ensure that the section contents
216 are correctly aligned. */
217 unsigned int leading_padding
;
219 /* The offset of MEMBER from the start of the archive (i.e. the end
220 of the leading padding). */
223 /* The normalized name of MEMBER. */
226 /* The length of NAME, without padding. */
227 bfd_size_type namlen
;
229 /* The length of NAME, with padding. */
230 bfd_size_type padded_namlen
;
232 /* The size of MEMBER's header, including the name and magic sequence. */
233 bfd_size_type header_size
;
235 /* The size of the MEMBER's contents. */
236 bfd_size_type contents_size
;
238 /* The number of bytes of padding that must be inserted after MEMBER
239 in order to preserve even alignment. */
240 bfd_size_type trailing_padding
;
243 /* A structure used for iterating over the members of an archive. */
244 struct archive_iterator
{
245 /* The archive itself. */
248 /* Information about the current archive member. */
249 struct member_layout current
;
251 /* Information about the next archive member. MEMBER is null if there
252 are no more archive members, in which case OFFSET is the offset of
253 the first unused byte. */
254 struct member_layout next
;
257 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
258 OFFSET is the even-padded offset of MEMBER, not including any leading
259 padding needed for section alignment. */
262 member_layout_init (struct member_layout
*info
, bfd
*archive
,
263 bfd
*member
, file_ptr offset
)
265 info
->member
= member
;
266 info
->leading_padding
= 0;
269 info
->name
= normalize_filename (member
);
270 info
->namlen
= strlen (info
->name
);
271 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
272 if (xcoff_big_format_p (archive
))
273 info
->header_size
= SIZEOF_AR_HDR_BIG
;
275 info
->header_size
= SIZEOF_AR_HDR
;
276 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
277 info
->contents_size
= arelt_size (member
);
278 info
->trailing_padding
= info
->contents_size
& 1;
280 if (bfd_check_format (member
, bfd_object
)
281 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
282 && (member
->flags
& DYNAMIC
) != 0)
283 info
->leading_padding
284 = (-(offset
+ info
->header_size
)
285 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
287 info
->offset
= offset
+ info
->leading_padding
;
290 /* Set up ITERATOR to iterate through archive ARCHIVE. */
293 archive_iterator_begin (struct archive_iterator
*iterator
,
296 iterator
->archive
= archive
;
297 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
298 xcoff_big_format_p (archive
)
299 ? SIZEOF_AR_FILE_HDR_BIG
300 : SIZEOF_AR_FILE_HDR
);
303 /* Make ITERATOR visit the first unvisited archive member. Return true
304 on success; return false if all members have been visited. */
307 archive_iterator_next (struct archive_iterator
*iterator
)
309 if (!iterator
->next
.member
)
312 iterator
->current
= iterator
->next
;
313 member_layout_init (&iterator
->next
, iterator
->archive
,
314 iterator
->current
.member
->archive_next
,
315 iterator
->current
.offset
316 + iterator
->current
.header_size
317 + iterator
->current
.contents_size
318 + iterator
->current
.trailing_padding
);
322 /* We use our own tdata type. Its first field is the COFF tdata type,
323 so the COFF routines are compatible. */
326 _bfd_xcoff_mkobject (bfd
*abfd
)
328 coff_data_type
*coff
;
329 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
331 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
332 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
334 coff
= coff_data (abfd
);
335 coff
->symbols
= (coff_symbol_type
*) NULL
;
336 coff
->conversion_table
= (unsigned int *) NULL
;
337 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
340 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
342 /* We set cputype to -1 to indicate that it has not been
344 xcoff_data (abfd
)->cputype
= -1;
346 xcoff_data (abfd
)->csects
= NULL
;
347 xcoff_data (abfd
)->debug_indices
= NULL
;
349 /* text section alignment is different than the default */
350 bfd_xcoff_text_align_power (abfd
) = 2;
355 /* Copy XCOFF data from one BFD to another. */
358 _bfd_xcoff_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
360 struct xcoff_tdata
*ix
, *ox
;
363 if (ibfd
->xvec
!= obfd
->xvec
)
365 ix
= xcoff_data (ibfd
);
366 ox
= xcoff_data (obfd
);
367 ox
->full_aouthdr
= ix
->full_aouthdr
;
373 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
377 ox
->sntoc
= sec
->output_section
->target_index
;
379 if (ix
->snentry
== 0)
383 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
387 ox
->snentry
= sec
->output_section
->target_index
;
389 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
390 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
391 ox
->modtype
= ix
->modtype
;
392 ox
->cputype
= ix
->cputype
;
393 ox
->maxdata
= ix
->maxdata
;
394 ox
->maxstack
= ix
->maxstack
;
398 /* I don't think XCOFF really has a notion of local labels based on
399 name. This will mean that ld -X doesn't actually strip anything.
400 The AIX native linker does not have a -X option, and it ignores the
404 _bfd_xcoff_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
405 const char *name ATTRIBUTE_UNUSED
)
410 static const struct dwarf_debug_section xcoff_debug_sections
[] =
412 { ".dwabrev", NULL
},
413 { ".dwarnge", NULL
},
414 { NULL
, NULL
}, /* .debug_frame */
417 { NULL
, NULL
}, /* .debug_loc */
418 { NULL
, NULL
}, /* .debug_macinfo */
419 { NULL
, NULL
}, /* .debug_macro */
420 { ".dwpbnms", NULL
},
421 { ".dwpbtyp", NULL
},
422 { ".dwrnges", NULL
},
423 { NULL
, NULL
}, /* .debug_static_func */
424 { NULL
, NULL
}, /* .debug_static_vars */
426 { NULL
, NULL
}, /* .debug_types */
427 /* GNU DWARF 1 extensions */
428 { NULL
, NULL
}, /* .debug_sfnames */
429 { NULL
, NULL
}, /* .debug_srcinfo */
430 /* SGI/MIPS DWARF 2 extensions */
431 { NULL
, NULL
}, /* .debug_funcnames */
432 { NULL
, NULL
}, /* .debug_typenames */
433 { NULL
, NULL
}, /* .debug_varnames */
434 { NULL
, NULL
}, /* .debug_weaknames */
439 xcoff_find_nearest_line (bfd
*abfd
,
443 const char **filename_ptr
,
444 const char **functionname_ptr
,
445 unsigned int *line_ptr
)
447 return coff_find_nearest_line_with_names (abfd
, xcoff_debug_sections
,
448 section
, symbols
, offset
,
449 filename_ptr
, functionname_ptr
,
454 xcoff_find_nearest_line_discriminator (bfd
*abfd
,
458 const char **filename_ptr
,
459 const char **functionname_ptr
,
460 unsigned int *line_ptr
,
461 unsigned int *discriminator
)
464 return coff_find_nearest_line_with_names (abfd
, xcoff_debug_sections
,
465 section
, symbols
, offset
,
466 filename_ptr
, functionname_ptr
,
472 _bfd_xcoff_swap_sym_in (bfd
*abfd
, void * ext1
, void * in1
)
474 SYMENT
*ext
= (SYMENT
*)ext1
;
475 struct internal_syment
* in
= (struct internal_syment
*)in1
;
477 if (ext
->e
.e_name
[0] != 0)
479 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
483 in
->_n
._n_n
._n_zeroes
= 0;
484 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
487 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
488 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
489 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
490 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
491 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
495 _bfd_xcoff_swap_sym_out (bfd
*abfd
, void * inp
, void * extp
)
497 struct internal_syment
*in
= (struct internal_syment
*)inp
;
498 SYMENT
*ext
=(SYMENT
*)extp
;
500 if (in
->_n
._n_name
[0] != 0)
502 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
506 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
507 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
510 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
511 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
512 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
513 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
514 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
515 return bfd_coff_symesz (abfd
);
519 _bfd_xcoff_swap_aux_in (bfd
*abfd
, void * ext1
, int type
, int in_class
,
520 int indx
, int numaux
, void * in1
)
522 AUXENT
* ext
= (AUXENT
*)ext1
;
523 union internal_auxent
*in
= (union internal_auxent
*)in1
;
528 if (ext
->x_file
.x_n
.x_fname
[0] == 0)
530 in
->x_file
.x_n
.x_zeroes
= 0;
531 in
->x_file
.x_n
.x_offset
=
532 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_n
.x_offset
);
539 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
,
540 numaux
* sizeof (AUXENT
));
544 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
, FILNMLEN
);
549 /* RS/6000 "csect" auxents */
553 if (indx
+ 1 == numaux
)
555 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
556 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
557 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
558 /* We don't have to hack bitfields in x_smtyp because it's
559 defined by shifts-and-ands, which are equivalent on all
561 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
562 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
563 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
564 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
574 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
575 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
576 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
577 /* PE defines some extra fields; we zero them out for
579 in
->x_scn
.x_checksum
= 0;
580 in
->x_scn
.x_associated
= 0;
581 in
->x_scn
.x_comdat
= 0;
588 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
589 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
591 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
594 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
595 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
596 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
597 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
601 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
602 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
603 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
604 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
605 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
606 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
607 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
608 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
613 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
617 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
618 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
619 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
620 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
624 /* The semicolon is because MSVC doesn't like labels at
629 _bfd_xcoff_swap_aux_out (bfd
*abfd
, void * inp
, int type
, int in_class
,
630 int indx ATTRIBUTE_UNUSED
,
631 int numaux ATTRIBUTE_UNUSED
,
634 union internal_auxent
*in
= (union internal_auxent
*)inp
;
635 AUXENT
*ext
= (AUXENT
*)extp
;
637 memset (ext
, 0, bfd_coff_auxesz (abfd
));
641 if (in
->x_file
.x_fname
[0] == 0)
643 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_n
.x_zeroes
);
644 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
,
645 ext
->x_file
.x_n
.x_n
.x_offset
);
649 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
653 /* RS/6000 "csect" auxents */
657 if (indx
+ 1 == numaux
)
659 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
660 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
661 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
662 /* We don't have to hack bitfields in x_smtyp because it's
663 defined by shifts-and-ands, which are equivalent on all
665 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
666 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
667 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
668 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
678 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
679 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
680 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
686 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
687 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
689 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
692 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
693 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
694 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
695 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
699 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
700 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
701 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
702 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
703 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
704 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
705 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
706 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
710 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
713 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
714 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
715 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
716 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
720 return bfd_coff_auxesz (abfd
);
725 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
726 bitsize and whether they are signed or not, along with a
727 conventional type. This table is for the types, which are used for
728 different algorithms for putting in the reloc. Many of these
729 relocs need special_function entries, which I have not written. */
732 reloc_howto_type xcoff_howto_table
[] =
734 /* Standard 32 bit relocation. */
735 HOWTO (R_POS
, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE
, /* pc_relative */
741 complain_overflow_bitfield
, /* complain_on_overflow */
742 0, /* special_function */
744 TRUE
, /* partial_inplace */
745 0xffffffff, /* src_mask */
746 0xffffffff, /* dst_mask */
747 FALSE
), /* pcrel_offset */
749 /* 32 bit relocation, but store negative value. */
750 HOWTO (R_NEG
, /* type */
752 -2, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_bitfield
, /* complain_on_overflow */
757 0, /* special_function */
759 TRUE
, /* partial_inplace */
760 0xffffffff, /* src_mask */
761 0xffffffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* 32 bit PC relative relocation. */
765 HOWTO (R_REL
, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 TRUE
, /* pc_relative */
771 complain_overflow_signed
, /* complain_on_overflow */
772 0, /* special_function */
774 TRUE
, /* partial_inplace */
775 0xffffffff, /* src_mask */
776 0xffffffff, /* dst_mask */
777 FALSE
), /* pcrel_offset */
779 /* 16 bit TOC relative relocation. */
780 HOWTO (R_TOC
, /* type */
782 1, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 0, /* special_function */
789 TRUE
, /* partial_inplace */
790 0xffff, /* src_mask */
791 0xffff, /* dst_mask */
792 FALSE
), /* pcrel_offset */
794 /* I don't really know what this is. */
795 HOWTO (R_RTB
, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 FALSE
, /* pc_relative */
801 complain_overflow_bitfield
, /* complain_on_overflow */
802 0, /* special_function */
804 TRUE
, /* partial_inplace */
805 0xffffffff, /* src_mask */
806 0xffffffff, /* dst_mask */
807 FALSE
), /* pcrel_offset */
809 /* External TOC relative symbol. */
810 HOWTO (R_GL
, /* type */
812 1, /* size (0 = byte, 1 = short, 2 = long) */
814 FALSE
, /* pc_relative */
816 complain_overflow_bitfield
, /* complain_on_overflow */
817 0, /* special_function */
819 TRUE
, /* partial_inplace */
820 0xffff, /* src_mask */
821 0xffff, /* dst_mask */
822 FALSE
), /* pcrel_offset */
824 /* Local TOC relative symbol. */
825 HOWTO (R_TCL
, /* type */
827 1, /* size (0 = byte, 1 = short, 2 = long) */
829 FALSE
, /* pc_relative */
831 complain_overflow_bitfield
, /* complain_on_overflow */
832 0, /* special_function */
834 TRUE
, /* partial_inplace */
835 0xffff, /* src_mask */
836 0xffff, /* dst_mask */
837 FALSE
), /* pcrel_offset */
841 /* Non modifiable absolute branch. */
842 HOWTO (R_BA
, /* type */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
846 FALSE
, /* pc_relative */
848 complain_overflow_bitfield
, /* complain_on_overflow */
849 0, /* special_function */
850 "R_BA_26", /* name */
851 TRUE
, /* partial_inplace */
852 0x03fffffc, /* src_mask */
853 0x03fffffc, /* dst_mask */
854 FALSE
), /* pcrel_offset */
858 /* Non modifiable relative branch. */
859 HOWTO (R_BR
, /* type */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
863 TRUE
, /* pc_relative */
865 complain_overflow_signed
, /* complain_on_overflow */
866 0, /* special_function */
868 TRUE
, /* partial_inplace */
869 0x03fffffc, /* src_mask */
870 0x03fffffc, /* dst_mask */
871 FALSE
), /* pcrel_offset */
876 HOWTO (R_RL
, /* type */
878 1, /* size (0 = byte, 1 = short, 2 = long) */
880 FALSE
, /* pc_relative */
882 complain_overflow_bitfield
, /* complain_on_overflow */
883 0, /* special_function */
885 TRUE
, /* partial_inplace */
886 0xffff, /* src_mask */
887 0xffff, /* dst_mask */
888 FALSE
), /* pcrel_offset */
891 HOWTO (R_RLA
, /* type */
893 1, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE
, /* pc_relative */
897 complain_overflow_bitfield
, /* complain_on_overflow */
898 0, /* special_function */
900 TRUE
, /* partial_inplace */
901 0xffff, /* src_mask */
902 0xffff, /* dst_mask */
903 FALSE
), /* pcrel_offset */
907 /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
908 HOWTO (R_REF
, /* type */
910 0, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_dont
, /* complain_on_overflow */
915 0, /* special_function */
917 FALSE
, /* partial_inplace */
920 FALSE
), /* pcrel_offset */
925 /* TOC relative indirect load. */
926 HOWTO (R_TRL
, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE
, /* pc_relative */
932 complain_overflow_bitfield
, /* complain_on_overflow */
933 0, /* special_function */
935 TRUE
, /* partial_inplace */
936 0xffff, /* src_mask */
937 0xffff, /* dst_mask */
938 FALSE
), /* pcrel_offset */
940 /* TOC relative load address. */
941 HOWTO (R_TRLA
, /* type */
943 1, /* size (0 = byte, 1 = short, 2 = long) */
945 FALSE
, /* pc_relative */
947 complain_overflow_bitfield
, /* complain_on_overflow */
948 0, /* special_function */
950 TRUE
, /* partial_inplace */
951 0xffff, /* src_mask */
952 0xffff, /* dst_mask */
953 FALSE
), /* pcrel_offset */
955 /* Modifiable relative branch. */
956 HOWTO (R_RRTBI
, /* type */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
960 FALSE
, /* pc_relative */
962 complain_overflow_bitfield
, /* complain_on_overflow */
963 0, /* special_function */
964 "R_RRTBI", /* name */
965 TRUE
, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 FALSE
), /* pcrel_offset */
970 /* Modifiable absolute branch. */
971 HOWTO (R_RRTBA
, /* type */
973 2, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_bitfield
, /* complain_on_overflow */
978 0, /* special_function */
979 "R_RRTBA", /* name */
980 TRUE
, /* partial_inplace */
981 0xffffffff, /* src_mask */
982 0xffffffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 /* Modifiable call absolute indirect. */
986 HOWTO (R_CAI
, /* type */
988 1, /* size (0 = byte, 1 = short, 2 = long) */
990 FALSE
, /* pc_relative */
992 complain_overflow_bitfield
, /* complain_on_overflow */
993 0, /* special_function */
995 TRUE
, /* partial_inplace */
996 0xffff, /* src_mask */
997 0xffff, /* dst_mask */
998 FALSE
), /* pcrel_offset */
1000 /* Modifiable call relative. */
1001 HOWTO (R_CREL
, /* type */
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_bitfield
, /* complain_on_overflow */
1008 0, /* special_function */
1009 "R_CREL", /* name */
1010 TRUE
, /* partial_inplace */
1011 0xffff, /* src_mask */
1012 0xffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 /* Modifiable branch absolute. */
1016 HOWTO (R_RBA
, /* type */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE
, /* pc_relative */
1022 complain_overflow_bitfield
, /* complain_on_overflow */
1023 0, /* special_function */
1025 TRUE
, /* partial_inplace */
1026 0x03fffffc, /* src_mask */
1027 0x03fffffc, /* dst_mask */
1028 FALSE
), /* pcrel_offset */
1030 /* Modifiable branch absolute. */
1031 HOWTO (R_RBAC
, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 FALSE
, /* pc_relative */
1037 complain_overflow_bitfield
, /* complain_on_overflow */
1038 0, /* special_function */
1039 "R_RBAC", /* name */
1040 TRUE
, /* partial_inplace */
1041 0xffffffff, /* src_mask */
1042 0xffffffff, /* dst_mask */
1043 FALSE
), /* pcrel_offset */
1045 /* Modifiable branch relative. */
1046 HOWTO (R_RBR
, /* type */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE
, /* pc_relative */
1052 complain_overflow_signed
, /* complain_on_overflow */
1053 0, /* special_function */
1054 "R_RBR_26", /* name */
1055 TRUE
, /* partial_inplace */
1056 0x03fffffc, /* src_mask */
1057 0x03fffffc, /* dst_mask */
1058 FALSE
), /* pcrel_offset */
1060 /* Modifiable branch absolute. */
1061 HOWTO (R_RBRC
, /* type */
1063 1, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE
, /* pc_relative */
1067 complain_overflow_bitfield
, /* complain_on_overflow */
1068 0, /* special_function */
1069 "R_RBRC", /* name */
1070 TRUE
, /* partial_inplace */
1071 0xffff, /* src_mask */
1072 0xffff, /* dst_mask */
1073 FALSE
), /* pcrel_offset */
1075 /* 16 bit Non modifiable absolute branch. */
1076 HOWTO (R_BA
, /* type */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE
, /* pc_relative */
1082 complain_overflow_bitfield
, /* complain_on_overflow */
1083 0, /* special_function */
1084 "R_BA_16", /* name */
1085 TRUE
, /* partial_inplace */
1086 0xfffc, /* src_mask */
1087 0xfffc, /* dst_mask */
1088 FALSE
), /* pcrel_offset */
1090 /* Modifiable branch relative. */
1091 HOWTO (R_RBR
, /* type */
1093 1, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_signed
, /* complain_on_overflow */
1098 0, /* special_function */
1099 "R_RBR_16", /* name */
1100 TRUE
, /* partial_inplace */
1101 0xffff, /* src_mask */
1102 0xffff, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 /* Modifiable branch relative. */
1106 HOWTO (R_RBA
, /* type */
1108 1, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_signed
, /* complain_on_overflow */
1113 0, /* special_function */
1114 "R_RBA_16", /* name */
1115 TRUE
, /* partial_inplace */
1116 0xffff, /* src_mask */
1117 0xffff, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1122 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1124 if (internal
->r_type
> R_RBRC
)
1127 /* Default howto layout works most of the time */
1128 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1130 /* Special case some 16 bit reloc */
1131 if (15 == (internal
->r_size
& 0x1f))
1133 if (R_BA
== internal
->r_type
)
1134 relent
->howto
= &xcoff_howto_table
[0x1c];
1135 else if (R_RBR
== internal
->r_type
)
1136 relent
->howto
= &xcoff_howto_table
[0x1d];
1137 else if (R_RBA
== internal
->r_type
)
1138 relent
->howto
= &xcoff_howto_table
[0x1e];
1141 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1142 relocation, as well as indicating whether it is signed or not.
1143 Doublecheck that the relocation information gathered from the
1144 type matches this information. The bitsize is not significant
1145 for R_REF relocs. */
1146 if (relent
->howto
->dst_mask
!= 0
1147 && (relent
->howto
->bitsize
1148 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1153 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1154 bfd_reloc_code_real_type code
)
1158 case BFD_RELOC_PPC_B26
:
1159 return &xcoff_howto_table
[0xa];
1160 case BFD_RELOC_PPC_BA16
:
1161 return &xcoff_howto_table
[0x1c];
1162 case BFD_RELOC_PPC_BA26
:
1163 return &xcoff_howto_table
[8];
1164 case BFD_RELOC_PPC_TOC16
:
1165 return &xcoff_howto_table
[3];
1167 /* Note that this relocation is only internally used by gas. */
1168 return &xcoff_howto_table
[0xc];
1170 case BFD_RELOC_CTOR
:
1171 return &xcoff_howto_table
[0];
1172 case BFD_RELOC_NONE
:
1173 return &xcoff_howto_table
[0xf];
1179 static reloc_howto_type
*
1180 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1186 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1188 if (xcoff_howto_table
[i
].name
!= NULL
1189 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1190 return &xcoff_howto_table
[i
];
1195 /* XCOFF archive support. The original version of this code was by
1196 Damon A. Permezel. It was enhanced to permit cross support, and
1197 writing archive files, by Ian Lance Taylor, Cygnus Support.
1199 XCOFF uses its own archive format. Everything is hooked together
1200 with file offset links, so it is possible to rapidly update an
1201 archive in place. Of course, we don't do that. An XCOFF archive
1202 has a real file header, not just an ARMAG string. The structure of
1203 the file header and of each archive header appear below.
1205 An XCOFF archive also has a member table, which is a list of
1206 elements in the archive (you can get that by looking through the
1207 linked list, but you have to read a lot more of the file). The
1208 member table has a normal archive header with an empty name. It is
1209 normally (and perhaps must be) the second to last entry in the
1210 archive. The member table data is almost printable ASCII. It
1211 starts with a 12 character decimal string which is the number of
1212 entries in the table. For each entry it has a 12 character decimal
1213 string which is the offset in the archive of that member. These
1214 entries are followed by a series of null terminated strings which
1215 are the member names for each entry.
1217 Finally, an XCOFF archive has a global symbol table, which is what
1218 we call the armap. The global symbol table has a normal archive
1219 header with an empty name. It is normally (and perhaps must be)
1220 the last entry in the archive. The contents start with a four byte
1221 binary number which is the number of entries. This is followed by
1222 a that many four byte binary numbers; each is the file offset of an
1223 entry in the archive. These numbers are followed by a series of
1224 null terminated strings, which are symbol names.
1226 AIX 4.3 introduced a new archive format which can handle larger
1227 files and also 32- and 64-bit objects in the same archive. The
1228 things said above remain true except that there is now more than
1229 one global symbol table. The one is used to index 32-bit objects,
1230 the other for 64-bit objects.
1232 The new archives (recognizable by the new ARMAG string) has larger
1233 field lengths so that we cannot really share any code. Also we have
1234 to take care that we are not generating the new form of archives
1235 on AIX 4.2 or earlier systems. */
1237 /* XCOFF archives use this as a magic string. Note that both strings
1238 have the same length. */
1240 /* Set the magic for archive. */
1243 bfd_xcoff_ar_archive_set_magic (bfd
*abfd ATTRIBUTE_UNUSED
,
1244 char *magic ATTRIBUTE_UNUSED
)
1246 /* Not supported yet. */
1248 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1251 /* Read in the armap of an XCOFF archive. */
1254 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1259 bfd_byte
*contents
, *cend
;
1264 if (xcoff_ardata (abfd
) == NULL
)
1266 bfd_has_map (abfd
) = FALSE
;
1270 if (! xcoff_big_format_p (abfd
))
1272 /* This is for the old format. */
1273 struct xcoff_ar_hdr hdr
;
1275 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1278 bfd_has_map (abfd
) = FALSE
;
1282 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1285 /* The symbol table starts with a normal archive header. */
1286 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1290 /* Skip the name (normally empty). */
1291 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1292 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1293 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1296 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1298 /* Read in the entire symbol table. */
1299 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1300 if (contents
== NULL
)
1302 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1305 /* The symbol table starts with a four byte count. */
1306 c
= H_GET_32 (abfd
, contents
);
1310 bfd_set_error (bfd_error_bad_value
);
1314 bfd_ardata (abfd
)->symdefs
=
1315 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1316 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1319 /* After the count comes a list of four byte file offsets. */
1320 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1322 ++i
, ++arsym
, p
+= 4)
1323 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1327 /* This is for the new format. */
1328 struct xcoff_ar_hdr_big hdr
;
1330 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1333 bfd_has_map (abfd
) = FALSE
;
1337 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1340 /* The symbol table starts with a normal archive header. */
1341 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1342 != SIZEOF_AR_HDR_BIG
)
1345 /* Skip the name (normally empty). */
1346 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1347 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1348 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1351 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1352 machines) since the field width is 20 and there numbers with more
1353 than 32 bits can be represented. */
1354 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1356 /* Read in the entire symbol table. */
1357 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1358 if (contents
== NULL
)
1360 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1363 /* The symbol table starts with an eight byte count. */
1364 c
= H_GET_64 (abfd
, contents
);
1368 bfd_set_error (bfd_error_bad_value
);
1372 bfd_ardata (abfd
)->symdefs
=
1373 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1374 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1377 /* After the count comes a list of eight byte file offsets. */
1378 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1380 ++i
, ++arsym
, p
+= 8)
1381 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1384 /* After the file offsets come null terminated symbol names. */
1385 cend
= contents
+ sz
;
1386 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1388 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1392 bfd_set_error (bfd_error_bad_value
);
1395 arsym
->name
= (char *) p
;
1398 bfd_ardata (abfd
)->symdef_count
= c
;
1399 bfd_has_map (abfd
) = TRUE
;
1404 /* See if this is an XCOFF archive. */
1407 _bfd_xcoff_archive_p (bfd
*abfd
)
1409 struct artdata
*tdata_hold
;
1410 char magic
[SXCOFFARMAG
];
1411 bfd_size_type amt
= SXCOFFARMAG
;
1413 if (bfd_bread (magic
, amt
, abfd
) != amt
)
1415 if (bfd_get_error () != bfd_error_system_call
)
1416 bfd_set_error (bfd_error_wrong_format
);
1420 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1421 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1423 bfd_set_error (bfd_error_wrong_format
);
1427 tdata_hold
= bfd_ardata (abfd
);
1429 amt
= sizeof (struct artdata
);
1430 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1431 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1432 goto error_ret_restore
;
1434 /* Cleared by bfd_zalloc above.
1435 bfd_ardata (abfd)->cache = NULL;
1436 bfd_ardata (abfd)->archive_head = NULL;
1437 bfd_ardata (abfd)->symdefs = NULL;
1438 bfd_ardata (abfd)->extended_names = NULL;
1439 bfd_ardata (abfd)->extended_names_size = 0; */
1441 /* Now handle the two formats. */
1442 if (magic
[1] != 'b')
1444 /* This is the old format. */
1445 struct xcoff_ar_file_hdr hdr
;
1447 /* Copy over the magic string. */
1448 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1450 /* Now read the rest of the file header. */
1451 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1452 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1454 if (bfd_get_error () != bfd_error_system_call
)
1455 bfd_set_error (bfd_error_wrong_format
);
1459 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1460 (char **) NULL
, 10);
1462 amt
= SIZEOF_AR_FILE_HDR
;
1463 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1464 if (bfd_ardata (abfd
)->tdata
== NULL
)
1467 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1471 /* This is the new format. */
1472 struct xcoff_ar_file_hdr_big hdr
;
1474 /* Copy over the magic string. */
1475 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1477 /* Now read the rest of the file header. */
1478 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1479 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1481 if (bfd_get_error () != bfd_error_system_call
)
1482 bfd_set_error (bfd_error_wrong_format
);
1486 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1490 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1491 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1492 if (bfd_ardata (abfd
)->tdata
== NULL
)
1495 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1498 if (! _bfd_xcoff_slurp_armap (abfd
))
1501 bfd_release (abfd
, bfd_ardata (abfd
));
1503 bfd_ardata (abfd
) = tdata_hold
;
1510 /* Read the archive header in an XCOFF archive. */
1513 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1515 bfd_size_type namlen
;
1516 struct areltdata
*ret
;
1517 bfd_size_type amt
= sizeof (struct areltdata
);
1519 ret
= (struct areltdata
*) bfd_zmalloc (amt
);
1523 if (! xcoff_big_format_p (abfd
))
1525 struct xcoff_ar_hdr hdr
;
1526 struct xcoff_ar_hdr
*hdrp
;
1528 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1535 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1536 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1537 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1543 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1544 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1549 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1551 ret
->arch_header
= (char *) hdrp
;
1552 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1553 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1557 struct xcoff_ar_hdr_big hdr
;
1558 struct xcoff_ar_hdr_big
*hdrp
;
1560 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1561 != SIZEOF_AR_HDR_BIG
)
1567 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1568 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1569 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1575 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1576 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1581 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1583 ret
->arch_header
= (char *) hdrp
;
1584 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1585 machines) since the field width is 20 and there numbers with more
1586 than 32 bits can be represented. */
1587 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1588 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1591 /* Skip over the XCOFFARFMAG at the end of the file name. */
1592 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1598 /* Open the next element in an XCOFF archive. */
1601 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1605 if (xcoff_ardata (archive
) == NULL
)
1607 bfd_set_error (bfd_error_invalid_operation
);
1611 if (! xcoff_big_format_p (archive
))
1613 if (last_file
== NULL
)
1614 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1616 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1620 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1622 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1623 (char **) NULL
, 10))
1625 bfd_set_error (bfd_error_no_more_archived_files
);
1631 if (last_file
== NULL
)
1632 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1634 /* XXX These actually have to be a calls to strtoll (at least
1635 on 32-bit machines) since the fields's width is 20 and
1636 there numbers with more than 32 bits can be represented. */
1637 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1640 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1641 machines) since the fields's width is 20 and there numbers with more
1642 than 32 bits can be represented. */
1644 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1646 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1647 (char **) NULL
, 10))
1649 bfd_set_error (bfd_error_no_more_archived_files
);
1654 return _bfd_get_elt_at_filepos (archive
, filestart
);
1657 /* Stat an element in an XCOFF archive. */
1660 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1662 if (abfd
->arelt_data
== NULL
)
1664 bfd_set_error (bfd_error_invalid_operation
);
1668 if (! xcoff_big_format_p (abfd
->my_archive
))
1670 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1672 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1673 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1674 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1675 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1676 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1680 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1682 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1683 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1684 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1685 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1686 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1692 /* Normalize a file name for inclusion in an archive. */
1695 normalize_filename (bfd
*abfd
)
1698 const char *filename
;
1700 file
= bfd_get_filename (abfd
);
1701 filename
= strrchr (file
, '/');
1702 if (filename
!= NULL
)
1709 /* Write out an XCOFF armap. */
1712 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1713 struct orl
*map
, unsigned int orl_count
, int stridx
)
1715 struct archive_iterator iterator
;
1716 struct xcoff_ar_hdr hdr
;
1718 unsigned char buf
[4];
1721 memset (&hdr
, 0, sizeof hdr
);
1722 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1723 sprintf (hdr
.nextoff
, "%d", 0);
1724 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1725 sprintf (hdr
.date
, "%d", 0);
1726 sprintf (hdr
.uid
, "%d", 0);
1727 sprintf (hdr
.gid
, "%d", 0);
1728 sprintf (hdr
.mode
, "%d", 0);
1729 sprintf (hdr
.namlen
, "%d", 0);
1731 /* We need spaces, not null bytes, in the header. */
1732 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1736 if (bfd_bwrite (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1738 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1742 H_PUT_32 (abfd
, orl_count
, buf
);
1743 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1747 archive_iterator_begin (&iterator
, abfd
);
1748 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1749 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1751 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1752 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1757 for (i
= 0; i
< orl_count
; i
++)
1762 name
= *map
[i
].name
;
1763 namlen
= strlen (name
);
1764 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1768 if ((stridx
& 1) != 0)
1773 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1780 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1781 #define FMT20 "%-20lld"
1782 #define FMT12 "%-12d"
1783 #define FMT12_OCTAL "%-12o"
1785 #define PRINT20(d, v) \
1786 sprintf (buff20, FMT20, (long long)(v)), \
1787 memcpy ((void *) (d), buff20, 20)
1789 #define PRINT12(d, v) \
1790 sprintf (buff20, FMT12, (int)(v)), \
1791 memcpy ((void *) (d), buff20, 12)
1793 #define PRINT12_OCTAL(d, v) \
1794 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1795 memcpy ((void *) (d), buff20, 12)
1797 #define PRINT4(d, v) \
1798 sprintf (buff20, FMT4, (int)(v)), \
1799 memcpy ((void *) (d), buff20, 4)
1801 #define READ20(d, v) \
1803 memcpy (buff20, (d), 20), \
1804 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1807 do_pad (bfd
*abfd
, unsigned int number
)
1811 /* Limit pad to <= 4096. */
1816 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1823 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1825 bfd_size_type remaining
;
1826 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1828 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1831 remaining
= arelt_size (in_bfd
);
1833 while (remaining
>= DEFAULT_BUFFERSIZE
)
1835 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1836 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1839 remaining
-= DEFAULT_BUFFERSIZE
;
1844 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1845 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1853 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1854 struct orl
*map
, unsigned int orl_count
, int stridx
)
1856 struct archive_iterator iterator
;
1857 struct xcoff_ar_file_hdr_big
*fhdr
;
1858 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1859 const bfd_arch_info_type
*arch_info
;
1861 size_t string_length
;
1862 file_ptr nextoff
, prevoff
;
1864 /* First, we look through the symbols and work out which are
1865 from 32-bit objects and which from 64-bit ones. */
1866 sym_32
= sym_64
= str_32
= str_64
= 0;
1869 for (current_bfd
= abfd
->archive_head
;
1870 current_bfd
!= NULL
&& i
< orl_count
;
1871 current_bfd
= current_bfd
->archive_next
)
1873 arch_info
= bfd_get_arch_info (current_bfd
);
1874 while (map
[i
].u
.abfd
== current_bfd
)
1876 string_length
= strlen (*map
[i
].name
) + 1;
1877 if (arch_info
->bits_per_address
== 64)
1880 str_64
+= string_length
;
1885 str_32
+= string_length
;
1891 /* A quick sanity check... */
1892 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1893 /* Explicit cast to int for compiler. */
1894 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1896 fhdr
= xcoff_ardata_big (abfd
);
1898 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1899 READ20 (fhdr
->memoff
, prevoff
);
1900 READ20 (fhdr
->symoff
, nextoff
);
1902 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1904 /* Write out the symbol table.
1907 standard big archive header
1908 0x0000 ar_size [0x14]
1909 0x0014 ar_nxtmem [0x14]
1910 0x0028 ar_prvmem [0x14]
1911 0x003C ar_date [0x0C]
1912 0x0048 ar_uid [0x0C]
1913 0x0054 ar_gid [0x0C]
1914 0x0060 ar_mod [0x0C]
1915 0x006C ar_namelen[0x04]
1916 0x0070 ar_fmag [SXCOFFARFMAG]
1919 0x0072 num_syms [0x08], binary
1920 0x0078 offsets [0x08 * num_syms], binary
1921 0x0086 + 0x08 * num_syms names [??]
1922 ?? pad to even bytes.
1927 struct xcoff_ar_hdr_big
*hdr
;
1931 bfd_vma symbol_table_size
=
1936 + str_32
+ (str_32
& 1);
1938 symbol_table
= bfd_zmalloc (symbol_table_size
);
1939 if (symbol_table
== NULL
)
1942 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1944 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1947 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1949 PRINT20 (hdr
->nextoff
, 0);
1951 PRINT20 (hdr
->prevoff
, prevoff
);
1952 PRINT12 (hdr
->date
, 0);
1953 PRINT12 (hdr
->uid
, 0);
1954 PRINT12 (hdr
->gid
, 0);
1955 PRINT12 (hdr
->mode
, 0);
1956 PRINT4 (hdr
->namlen
, 0) ;
1958 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1959 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1962 bfd_h_put_64 (abfd
, sym_32
, st
);
1965 /* loop over the 32 bit offsets */
1967 archive_iterator_begin (&iterator
, abfd
);
1968 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1970 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1971 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1973 if (arch_info
->bits_per_address
== 32)
1975 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1982 /* loop over the 32 bit symbol names */
1984 for (current_bfd
= abfd
->archive_head
;
1985 current_bfd
!= NULL
&& i
< orl_count
;
1986 current_bfd
= current_bfd
->archive_next
)
1988 arch_info
= bfd_get_arch_info (current_bfd
);
1989 while (map
[i
].u
.abfd
== current_bfd
)
1991 if (arch_info
->bits_per_address
== 32)
1993 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1994 st
+= string_length
+ 1;
2000 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2002 free (symbol_table
);
2005 nextoff
= nextoff
+ symbol_table_size
;
2008 PRINT20 (fhdr
->symoff
, 0);
2012 struct xcoff_ar_hdr_big
*hdr
;
2016 bfd_vma symbol_table_size
=
2021 + str_64
+ (str_64
& 1);
2023 symbol_table
= bfd_zmalloc (symbol_table_size
);
2024 if (symbol_table
== NULL
)
2027 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2029 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
2030 PRINT20 (hdr
->nextoff
, 0);
2031 PRINT20 (hdr
->prevoff
, prevoff
);
2032 PRINT12 (hdr
->date
, 0);
2033 PRINT12 (hdr
->uid
, 0);
2034 PRINT12 (hdr
->gid
, 0);
2035 PRINT12 (hdr
->mode
, 0);
2036 PRINT4 (hdr
->namlen
, 0);
2038 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2039 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2042 bfd_h_put_64 (abfd
, sym_64
, st
);
2045 /* loop over the 64 bit offsets */
2047 archive_iterator_begin (&iterator
, abfd
);
2048 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2050 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2051 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2053 if (arch_info
->bits_per_address
== 64)
2055 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2062 /* loop over the 64 bit symbol names */
2064 for (current_bfd
= abfd
->archive_head
;
2065 current_bfd
!= NULL
&& i
< orl_count
;
2066 current_bfd
= current_bfd
->archive_next
)
2068 arch_info
= bfd_get_arch_info (current_bfd
);
2069 while (map
[i
].u
.abfd
== current_bfd
)
2071 if (arch_info
->bits_per_address
== 64)
2073 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2074 st
+= string_length
+ 1;
2080 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2082 free (symbol_table
);
2084 PRINT20 (fhdr
->symoff64
, nextoff
);
2087 PRINT20 (fhdr
->symoff64
, 0);
2093 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2094 struct orl
*map
, unsigned int orl_count
, int stridx
)
2096 if (! xcoff_big_format_p (abfd
))
2097 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2099 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2102 /* Write out an XCOFF archive. We always write an entire archive,
2103 rather than fussing with the freelist and so forth. */
2106 xcoff_write_archive_contents_old (bfd
*abfd
)
2108 struct archive_iterator iterator
;
2109 struct xcoff_ar_file_hdr fhdr
;
2110 bfd_size_type count
;
2111 bfd_size_type total_namlen
;
2113 bfd_boolean makemap
;
2114 bfd_boolean hasobjects
;
2115 file_ptr prevoff
, nextoff
;
2118 struct xcoff_ar_hdr ahdr
;
2121 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2123 memset (&fhdr
, 0, sizeof fhdr
);
2124 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2125 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2126 sprintf (fhdr
.freeoff
, "%d", 0);
2130 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2133 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2134 if (sub
->arelt_data
== NULL
)
2136 sub
->arelt_data
= bfd_zmalloc (sizeof (struct areltdata
));
2137 if (sub
->arelt_data
== NULL
)
2140 if (arch_xhdr (sub
) == NULL
)
2142 struct xcoff_ar_hdr
*ahdrp
;
2145 if (stat (bfd_get_filename (sub
), &s
) != 0)
2147 bfd_set_error (bfd_error_system_call
);
2151 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2155 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2156 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2157 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2158 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2159 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2161 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2162 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2165 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2166 if (offsets
== NULL
)
2169 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2172 makemap
= bfd_has_map (abfd
);
2175 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2176 archive_iterator_next (&iterator
);
2179 bfd_size_type namlen
;
2180 struct xcoff_ar_hdr
*ahdrp
;
2182 if (makemap
&& ! hasobjects
)
2184 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2188 ahdrp
= arch_xhdr (iterator
.current
.member
);
2189 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2190 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2191 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2193 /* We need spaces, not null bytes, in the header. */
2194 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2198 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2201 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2202 namlen
= iterator
.current
.padded_namlen
;
2203 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2204 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2205 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2206 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2207 || !do_copy (abfd
, iterator
.current
.member
)
2208 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2211 offsets
[i
] = iterator
.current
.offset
;
2212 prevoff
= iterator
.current
.offset
;
2215 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2217 /* Write out the member table. */
2219 nextoff
= iterator
.next
.offset
;
2220 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2221 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2223 memset (&ahdr
, 0, sizeof ahdr
);
2224 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2225 + count
* XCOFFARMAG_ELEMENT_SIZE
2227 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2228 sprintf (ahdr
.date
, "%d", 0);
2229 sprintf (ahdr
.uid
, "%d", 0);
2230 sprintf (ahdr
.gid
, "%d", 0);
2231 sprintf (ahdr
.mode
, "%d", 0);
2232 sprintf (ahdr
.namlen
, "%d", 0);
2234 size
= (SIZEOF_AR_HDR
2235 + XCOFFARMAG_ELEMENT_SIZE
2236 + count
* XCOFFARMAG_ELEMENT_SIZE
2241 nextoff
+= size
+ (size
& 1);
2243 if (makemap
&& hasobjects
)
2244 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2246 sprintf (ahdr
.nextoff
, "%d", 0);
2248 /* We need spaces, not null bytes, in the header. */
2249 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2253 if ((bfd_bwrite (&ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2255 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2259 sprintf (decbuf
, "%-12ld", (long) count
);
2260 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2261 != XCOFFARMAG_ELEMENT_SIZE
)
2263 for (i
= 0; i
< (size_t) count
; i
++)
2265 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2266 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2267 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2270 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2273 bfd_size_type namlen
;
2275 name
= normalize_filename (sub
);
2276 namlen
= strlen (name
);
2277 if (bfd_bwrite (name
, namlen
+ 1, abfd
) != namlen
+ 1)
2281 if (! do_pad (abfd
, size
& 1))
2284 /* Write out the armap, if appropriate. */
2285 if (! makemap
|| ! hasobjects
)
2286 sprintf (fhdr
.symoff
, "%d", 0);
2289 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2290 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2291 bfd_ardata (abfd
)->tdata
= &fhdr
;
2292 if (! _bfd_compute_and_write_armap (abfd
, 0))
2296 /* Write out the archive file header. */
2298 /* We need spaces, not null bytes, in the header. */
2299 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2303 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2304 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2305 != SIZEOF_AR_FILE_HDR
))
2312 xcoff_write_archive_contents_big (bfd
*abfd
)
2314 struct xcoff_ar_file_hdr_big fhdr
;
2315 bfd_size_type count
;
2316 bfd_size_type total_namlen
;
2318 bfd_boolean makemap
;
2319 bfd_boolean hasobjects
;
2320 file_ptr prevoff
, nextoff
;
2323 struct xcoff_ar_hdr_big
*hdr
;
2325 char *member_table
, *mt
;
2326 bfd_vma member_table_size
;
2327 struct archive_iterator iterator
;
2329 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2330 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2332 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2335 /* Calculate count and total_namlen. */
2336 makemap
= bfd_has_map (abfd
);
2338 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2339 current_bfd
!= NULL
;
2340 current_bfd
= current_bfd
->archive_next
, count
++)
2342 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2346 && bfd_check_format (current_bfd
, bfd_object
))
2349 if (current_bfd
->arelt_data
== NULL
)
2351 size
= sizeof (struct areltdata
);
2352 current_bfd
->arelt_data
= bfd_zmalloc (size
);
2353 if (current_bfd
->arelt_data
== NULL
)
2357 if (arch_xhdr_big (current_bfd
) == NULL
)
2359 struct xcoff_ar_hdr_big
*ahdrp
;
2362 /* XXX This should actually be a call to stat64 (at least on
2364 XXX This call will fail if the original object is not found. */
2365 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2367 bfd_set_error (bfd_error_system_call
);
2371 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2375 PRINT20 (ahdrp
->size
, s
.st_size
);
2376 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2377 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2378 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2379 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2381 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2382 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2389 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2390 if (offsets
== NULL
)
2395 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2396 archive_iterator_next (&iterator
);
2399 bfd_size_type namlen
;
2400 struct xcoff_ar_hdr_big
*ahdrp
;
2402 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2403 PRINT20 (ahdrp
->prevoff
, prevoff
);
2404 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2405 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2407 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2410 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2411 namlen
= iterator
.current
.padded_namlen
;
2412 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2413 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2414 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2415 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2416 || !do_copy (abfd
, iterator
.current
.member
)
2417 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2420 offsets
[i
] = iterator
.current
.offset
;
2421 prevoff
= iterator
.current
.offset
;
2426 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2427 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2430 /* Write out the member table.
2433 standard big archive header
2434 0x0000 ar_size [0x14]
2435 0x0014 ar_nxtmem [0x14]
2436 0x0028 ar_prvmem [0x14]
2437 0x003C ar_date [0x0C]
2438 0x0048 ar_uid [0x0C]
2439 0x0054 ar_gid [0x0C]
2440 0x0060 ar_mod [0x0C]
2441 0x006C ar_namelen[0x04]
2442 0x0070 ar_fmag [0x02]
2446 0x0086 offsets [0x14 * counts]
2447 0x0086 + 0x14 * counts names [??]
2448 ?? pad to even bytes.
2451 nextoff
= iterator
.next
.offset
;
2452 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2454 member_table_size
= (SIZEOF_AR_HDR_BIG
2456 + XCOFFARMAGBIG_ELEMENT_SIZE
2457 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2460 member_table_size
+= member_table_size
& 1;
2461 member_table
= bfd_zmalloc (member_table_size
);
2462 if (member_table
== NULL
)
2465 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2467 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2468 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2469 + total_namlen
+ (total_namlen
& 1)));
2470 if (makemap
&& hasobjects
)
2471 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2473 PRINT20 (hdr
->nextoff
, 0);
2474 PRINT20 (hdr
->prevoff
, prevoff
);
2475 PRINT12 (hdr
->date
, 0);
2476 PRINT12 (hdr
->uid
, 0);
2477 PRINT12 (hdr
->gid
, 0);
2478 PRINT12 (hdr
->mode
, 0);
2479 PRINT4 (hdr
->namlen
, 0);
2481 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2482 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2485 PRINT20 (mt
, count
);
2486 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2487 for (i
= 0; i
< (size_t) count
; i
++)
2489 PRINT20 (mt
, offsets
[i
]);
2490 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2499 for (current_bfd
= abfd
->archive_head
;
2500 current_bfd
!= NULL
;
2501 current_bfd
= current_bfd
->archive_next
)
2506 name
= normalize_filename (current_bfd
);
2507 namlen
= sprintf (mt
, "%s", name
);
2511 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2514 free (member_table
);
2516 PRINT20 (fhdr
.memoff
, nextoff
);
2519 nextoff
+= member_table_size
;
2521 /* Write out the armap, if appropriate. */
2523 if (! makemap
|| ! hasobjects
)
2524 PRINT20 (fhdr
.symoff
, 0);
2527 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2529 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2530 PRINT20 (fhdr
.symoff
, nextoff
);
2532 bfd_ardata (abfd
)->tdata
= &fhdr
;
2533 if (! _bfd_compute_and_write_armap (abfd
, 0))
2537 /* Write out the archive file header. */
2539 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2540 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2541 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2548 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2550 if (! xcoff_big_format_p (abfd
))
2551 return xcoff_write_archive_contents_old (abfd
);
2553 return xcoff_write_archive_contents_big (abfd
);
2556 /* We can't use the usual coff_sizeof_headers routine, because AIX
2557 always uses an a.out header. */
2560 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2561 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2566 if (xcoff_data (abfd
)->full_aouthdr
)
2569 size
+= SMALL_AOUTSZ
;
2570 size
+= abfd
->section_count
* SCNHSZ
;
2574 /* Routines to swap information in the XCOFF .loader section. If we
2575 ever need to write an XCOFF loader, this stuff will need to be
2576 moved to another file shared by the linker (which XCOFF calls the
2577 ``binder'') and the loader. */
2579 /* Swap in the ldhdr structure. */
2582 xcoff_swap_ldhdr_in (bfd
*abfd
, const void * s
, struct internal_ldhdr
*dst
)
2584 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2586 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2587 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2588 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2589 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2590 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2591 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2592 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2593 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2596 /* Swap out the ldhdr structure. */
2599 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, void * d
)
2601 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2603 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2604 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2605 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2606 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2607 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2608 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2609 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2610 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2613 /* Swap in the ldsym structure. */
2616 xcoff_swap_ldsym_in (bfd
*abfd
, const void * s
, struct internal_ldsym
*dst
)
2618 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2620 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2621 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2623 dst
->_l
._l_l
._l_zeroes
= 0;
2624 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2626 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2627 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2628 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2629 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2630 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2631 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2634 /* Swap out the ldsym structure. */
2637 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, void * d
)
2639 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2641 if (src
->_l
._l_l
._l_zeroes
!= 0)
2642 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2645 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2646 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2647 dst
->_l
._l_l
._l_offset
);
2649 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2650 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2651 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2652 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2653 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2654 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2658 xcoff_swap_reloc_in (bfd
*abfd
, void * s
, void * d
)
2660 struct external_reloc
*src
= (struct external_reloc
*) s
;
2661 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2663 memset (dst
, 0, sizeof (struct internal_reloc
));
2665 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2666 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2667 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2668 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2672 xcoff_swap_reloc_out (bfd
*abfd
, void * s
, void * d
)
2674 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2675 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2677 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2678 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2679 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2680 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2682 return bfd_coff_relsz (abfd
);
2685 /* Swap in the ldrel structure. */
2688 xcoff_swap_ldrel_in (bfd
*abfd
, const void * s
, struct internal_ldrel
*dst
)
2690 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2692 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2693 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2694 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2695 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2698 /* Swap out the ldrel structure. */
2701 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, void * d
)
2703 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2705 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2706 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2707 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2708 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2713 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2714 asection
*input_section ATTRIBUTE_UNUSED
,
2715 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2716 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2717 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2718 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2719 bfd_vma val ATTRIBUTE_UNUSED
,
2720 bfd_vma addend ATTRIBUTE_UNUSED
,
2721 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2722 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2728 xcoff_reloc_type_fail (bfd
*input_bfd
,
2729 asection
*input_section ATTRIBUTE_UNUSED
,
2730 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2731 struct internal_reloc
*rel
,
2732 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2733 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2734 bfd_vma val ATTRIBUTE_UNUSED
,
2735 bfd_vma addend ATTRIBUTE_UNUSED
,
2736 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2737 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2739 (*_bfd_error_handler
)
2740 (_("%s: unsupported relocation type 0x%02x"),
2741 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2742 bfd_set_error (bfd_error_bad_value
);
2747 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2748 asection
*input_section ATTRIBUTE_UNUSED
,
2749 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2750 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2751 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2752 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2755 bfd_vma
*relocation
,
2756 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2758 *relocation
= val
+ addend
;
2763 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2764 asection
*input_section ATTRIBUTE_UNUSED
,
2765 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2766 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2767 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2768 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2771 bfd_vma
*relocation
,
2772 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2774 *relocation
= addend
- val
;
2779 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2780 asection
*input_section
,
2781 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2782 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2783 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2784 struct reloc_howto_struct
*howto
,
2787 bfd_vma
*relocation
,
2788 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2790 howto
->pc_relative
= TRUE
;
2792 /* A PC relative reloc includes the section address. */
2793 addend
+= input_section
->vma
;
2795 *relocation
= val
+ addend
;
2796 *relocation
-= (input_section
->output_section
->vma
2797 + input_section
->output_offset
);
2802 xcoff_reloc_type_toc (bfd
*input_bfd
,
2803 asection
*input_section ATTRIBUTE_UNUSED
,
2805 struct internal_reloc
*rel
,
2806 struct internal_syment
*sym
,
2807 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2809 bfd_vma addend ATTRIBUTE_UNUSED
,
2810 bfd_vma
*relocation
,
2811 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2813 struct xcoff_link_hash_entry
*h
;
2815 if (0 > rel
->r_symndx
)
2818 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2820 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2822 if (h
->toc_section
== NULL
)
2824 (*_bfd_error_handler
)
2825 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2826 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2827 h
->root
.root
.string
);
2828 bfd_set_error (bfd_error_bad_value
);
2832 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2833 val
= (h
->toc_section
->output_section
->vma
2834 + h
->toc_section
->output_offset
);
2837 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2838 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2843 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2844 asection
*input_section ATTRIBUTE_UNUSED
,
2845 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2846 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2847 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2848 struct reloc_howto_struct
*howto
,
2851 bfd_vma
*relocation
,
2852 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2854 howto
->src_mask
&= ~3;
2855 howto
->dst_mask
= howto
->src_mask
;
2857 *relocation
= val
+ addend
;
2863 xcoff_reloc_type_br (bfd
*input_bfd
,
2864 asection
*input_section
,
2865 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2866 struct internal_reloc
*rel
,
2867 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2868 struct reloc_howto_struct
*howto
,
2871 bfd_vma
*relocation
,
2874 struct xcoff_link_hash_entry
*h
;
2875 bfd_vma section_offset
;
2877 if (0 > rel
->r_symndx
)
2880 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2881 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2883 /* If we see an R_BR or R_RBR reloc which is jumping to global
2884 linkage code, and it is followed by an appropriate cror nop
2885 instruction, we replace the cror with lwz r2,20(r1). This
2886 restores the TOC after the glink code. Contrariwise, if the
2887 call is followed by a lwz r2,20(r1), but the call is not
2888 going to global linkage code, we can replace the load with a
2891 && (bfd_link_hash_defined
== h
->root
.type
2892 || bfd_link_hash_defweak
== h
->root
.type
)
2893 && section_offset
+ 8 <= input_section
->size
)
2898 pnext
= contents
+ section_offset
+ 4;
2899 next
= bfd_get_32 (input_bfd
, pnext
);
2901 /* The _ptrgl function is magic. It is used by the AIX
2902 compiler to call a function through a pointer. */
2903 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2905 if (next
== 0x4def7b82 /* cror 15,15,15 */
2906 || next
== 0x4ffffb82 /* cror 31,31,31 */
2907 || next
== 0x60000000) /* ori r0,r0,0 */
2908 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2913 if (next
== 0x80410014) /* lwz r2,20(r1) */
2914 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2917 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2919 /* Normally, this relocation is against a defined symbol. In the
2920 case where this is a partial link and the output section offset
2921 is greater than 2^25, the linker will return an invalid error
2922 message that the relocation has been truncated. Yes it has been
2923 truncated but no it not important. For this case, disable the
2924 overflow checking. */
2926 howto
->complain_on_overflow
= complain_overflow_dont
;
2929 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2930 the value below will give the absolute target address. */
2931 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2933 howto
->src_mask
&= ~3;
2934 howto
->dst_mask
= howto
->src_mask
;
2937 && (h
->root
.type
== bfd_link_hash_defined
2938 || h
->root
.type
== bfd_link_hash_defweak
)
2939 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2940 && section_offset
+ 4 <= input_section
->size
)
2945 /* Turn the relative branch into an absolute one by setting the
2947 ptr
= contents
+ section_offset
;
2948 insn
= bfd_get_32 (input_bfd
, ptr
);
2950 bfd_put_32 (input_bfd
, insn
, ptr
);
2952 /* Make the howto absolute too. */
2953 howto
->pc_relative
= FALSE
;
2954 howto
->complain_on_overflow
= complain_overflow_bitfield
;
2958 /* Use a PC-relative howto and subtract the instruction's address
2959 from the target address we calculated above. */
2960 howto
->pc_relative
= TRUE
;
2961 *relocation
-= (input_section
->output_section
->vma
2962 + input_section
->output_offset
2969 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2970 asection
*input_section
,
2971 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2972 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2973 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2974 struct reloc_howto_struct
*howto
,
2975 bfd_vma val ATTRIBUTE_UNUSED
,
2977 bfd_vma
*relocation
,
2978 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2980 howto
->pc_relative
= TRUE
;
2981 howto
->src_mask
&= ~3;
2982 howto
->dst_mask
= howto
->src_mask
;
2984 /* A PC relative reloc includes the section address. */
2985 addend
+= input_section
->vma
;
2987 *relocation
= val
+ addend
;
2988 *relocation
-= (input_section
->output_section
->vma
2989 + input_section
->output_offset
);
2994 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2995 bfd_vma val ATTRIBUTE_UNUSED
,
2996 bfd_vma relocation ATTRIBUTE_UNUSED
,
2997 struct reloc_howto_struct
*
2998 howto ATTRIBUTE_UNUSED
)
3004 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
3007 struct reloc_howto_struct
*howto
)
3009 bfd_vma fieldmask
, signmask
, ss
;
3012 /* Get the values to be added together. For signed and unsigned
3013 relocations, we assume that all values should be truncated to
3014 the size of an address. For bitfields, all the bits matter.
3015 See also bfd_check_overflow. */
3016 fieldmask
= N_ONES (howto
->bitsize
);
3018 b
= val
& howto
->src_mask
;
3020 /* Much like unsigned, except no trimming with addrmask. In
3021 addition, the sum overflows if there is a carry out of
3022 the bfd_vma, i.e., the sum is less than either input
3024 a
>>= howto
->rightshift
;
3025 b
>>= howto
->bitpos
;
3027 /* Bitfields are sometimes used for signed numbers; for
3028 example, a 13-bit field sometimes represents values in
3029 0..8191 and sometimes represents values in -4096..4095.
3030 If the field is signed and a is -4095 (0x1001) and b is
3031 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3032 0x1fff is 0x3000). It's not clear how to handle this
3033 everywhere, since there is not way to know how many bits
3034 are significant in the relocation, but the original code
3035 assumed that it was fully sign extended, and we will keep
3037 signmask
= (fieldmask
>> 1) + 1;
3039 if ((a
& ~ fieldmask
) != 0)
3041 /* Some bits out of the field are set. This might not
3042 be a problem: if this is a signed bitfield, it is OK
3043 iff all the high bits are set, including the sign
3044 bit. We'll try setting all but the most significant
3045 bit in the original relocation value: if this is all
3046 ones, we are OK, assuming a signed bitfield. */
3047 ss
= (signmask
<< howto
->rightshift
) - 1;
3048 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3053 /* We just assume (b & ~ fieldmask) == 0. */
3055 /* We explicitly permit wrap around if this relocation
3056 covers the high bit of an address. The Linux kernel
3057 relies on it, and it is the only way to write assembler
3058 code which can run when loaded at a location 0x80000000
3059 away from the location at which it is linked. */
3060 if (howto
->bitsize
+ howto
->rightshift
3061 == bfd_arch_bits_per_address (input_bfd
))
3065 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3067 /* There was a carry out, or the field overflow. Test
3068 for signed operands again. Here is the overflow test
3069 is as for complain_overflow_signed. */
3070 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3078 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3081 struct reloc_howto_struct
*howto
)
3083 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3086 /* Get the values to be added together. For signed and unsigned
3087 relocations, we assume that all values should be truncated to
3088 the size of an address. For bitfields, all the bits matter.
3089 See also bfd_check_overflow. */
3090 fieldmask
= N_ONES (howto
->bitsize
);
3091 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3093 b
= val
& howto
->src_mask
;
3095 a
= (a
& addrmask
) >> howto
->rightshift
;
3097 /* If any sign bits are set, all sign bits must be set.
3098 That is, A must be a valid negative address after
3100 signmask
= ~ (fieldmask
>> 1);
3102 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3105 /* We only need this next bit of code if the sign bit of B
3106 is below the sign bit of A. This would only happen if
3107 SRC_MASK had fewer bits than BITSIZE. Note that if
3108 SRC_MASK has more bits than BITSIZE, we can get into
3109 trouble; we would need to verify that B is in range, as
3110 we do for A above. */
3111 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3112 if ((b
& signmask
) != 0)
3114 /* Set all the bits above the sign bit. */
3115 b
-= signmask
<<= 1;
3118 b
= (b
& addrmask
) >> howto
->bitpos
;
3120 /* Now we can do the addition. */
3123 /* See if the result has the correct sign. Bits above the
3124 sign bit are junk now; ignore them. If the sum is
3125 positive, make sure we did not have all negative inputs;
3126 if the sum is negative, make sure we did not have all
3127 positive inputs. The test below looks only at the sign
3128 bits, and it really just
3129 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3131 signmask
= (fieldmask
>> 1) + 1;
3132 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3139 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3142 struct reloc_howto_struct
*howto
)
3144 bfd_vma addrmask
, fieldmask
;
3147 /* Get the values to be added together. For signed and unsigned
3148 relocations, we assume that all values should be truncated to
3149 the size of an address. For bitfields, all the bits matter.
3150 See also bfd_check_overflow. */
3151 fieldmask
= N_ONES (howto
->bitsize
);
3152 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3154 b
= val
& howto
->src_mask
;
3156 /* Checking for an unsigned overflow is relatively easy:
3157 trim the addresses and add, and trim the result as well.
3158 Overflow is normally indicated when the result does not
3159 fit in the field. However, we also need to consider the
3160 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3161 input is 0x80000000, and bfd_vma is only 32 bits; then we
3162 will get sum == 0, but there is an overflow, since the
3163 inputs did not fit in the field. Instead of doing a
3164 separate test, we can check for this by or-ing in the
3165 operands when testing for the sum overflowing its final
3167 a
= (a
& addrmask
) >> howto
->rightshift
;
3168 b
= (b
& addrmask
) >> howto
->bitpos
;
3169 sum
= (a
+ b
) & addrmask
;
3170 if ((a
| b
| sum
) & ~ fieldmask
)
3176 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3177 This is currently the only processor which uses XCOFF; I hope that
3180 I took the relocation type definitions from two documents:
3181 the PowerPC AIX Version 4 Application Binary Interface, First
3182 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3183 32-Bit Hardware Implementation (June 30, 1994). Differences
3184 between the documents are noted below.
3186 Unsupported r_type's
3192 These relocs are defined by the PowerPC ABI to be
3193 relative branches which use half of the difference
3194 between the symbol and the program counter. I can't
3195 quite figure out when this is useful. These relocs are
3196 not defined by the PowerOpen ABI.
3201 Simple positive relocation.
3204 Simple negative relocation.
3207 Simple PC relative relocation.
3210 TOC relative relocation. The value in the instruction in
3211 the input file is the offset from the input file TOC to
3212 the desired location. We want the offset from the final
3213 TOC to the desired location. We have:
3218 so we must change insn by on - in.
3221 GL linkage relocation. The value of this relocation
3222 is the address of the entry in the TOC section.
3225 Local object TOC address. I can't figure out the
3226 difference between this and case R_GL.
3229 TOC relative relocation. A TOC relative load instruction
3230 which may be changed to a load address instruction.
3231 FIXME: We don't currently implement this optimization.
3234 TOC relative relocation. This is a TOC relative load
3235 address instruction which may be changed to a load
3236 instruction. FIXME: I don't know if this is the correct
3240 Absolute branch. We don't want to mess with the lower
3241 two bits of the instruction.
3244 The PowerPC ABI defines this as an absolute call which
3245 may be modified to become a relative call. The PowerOpen
3246 ABI does not define this relocation type.
3249 Absolute branch which may be modified to become a
3253 The PowerPC ABI defines this as an absolute branch to a
3254 fixed address which may be modified to an absolute branch
3255 to a symbol. The PowerOpen ABI does not define this
3259 The PowerPC ABI defines this as an absolute branch to a
3260 fixed address which may be modified to a relative branch.
3261 The PowerOpen ABI does not define this relocation type.
3264 Relative branch. We don't want to mess with the lower
3265 two bits of the instruction.
3268 The PowerPC ABI defines this as a relative call which may
3269 be modified to become an absolute call. The PowerOpen
3270 ABI does not define this relocation type.
3273 A relative branch which may be modified to become an
3277 The PowerPC AIX ABI describes this as a load which may be
3278 changed to a load address. The PowerOpen ABI says this
3279 is the same as case R_POS.
3282 The PowerPC AIX ABI describes this as a load address
3283 which may be changed to a load. The PowerOpen ABI says
3284 this is the same as R_POS.
3288 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3289 struct bfd_link_info
*info
,
3291 asection
*input_section
,
3293 struct internal_reloc
*relocs
,
3294 struct internal_syment
*syms
,
3295 asection
**sections
)
3297 struct internal_reloc
*rel
;
3298 struct internal_reloc
*relend
;
3301 relend
= rel
+ input_section
->reloc_count
;
3302 for (; rel
< relend
; rel
++)
3305 struct xcoff_link_hash_entry
*h
;
3306 struct internal_syment
*sym
;
3309 struct reloc_howto_struct howto
;
3311 bfd_vma value_to_relocate
;
3315 /* Relocation type R_REF is a special relocation type which is
3316 merely used to prevent garbage collection from occurring for
3317 the csect including the symbol which it references. */
3318 if (rel
->r_type
== R_REF
)
3322 howto
.type
= rel
->r_type
;
3323 howto
.rightshift
= 0;
3324 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3325 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3326 howto
.pc_relative
= FALSE
;
3328 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3329 ? complain_overflow_signed
3330 : complain_overflow_bitfield
);
3331 howto
.special_function
= NULL
;
3332 howto
.name
= "internal";
3333 howto
.partial_inplace
= TRUE
;
3334 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3335 howto
.pcrel_offset
= FALSE
;
3342 symndx
= rel
->r_symndx
;
3348 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3349 sym
= syms
+ symndx
;
3350 addend
= - sym
->n_value
;
3354 sec
= sections
[symndx
];
3355 /* Hack to make sure we use the right TOC anchor value
3356 if this reloc is against the TOC anchor. */
3357 if (sec
->name
[3] == '0'
3358 && strcmp (sec
->name
, ".tc0") == 0)
3359 val
= xcoff_data (output_bfd
)->toc
;
3361 val
= (sec
->output_section
->vma
3362 + sec
->output_offset
3368 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3369 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3371 if (! ((*info
->callbacks
->undefined_symbol
)
3372 (info
, h
->root
.root
.string
,
3373 input_bfd
, input_section
,
3374 rel
->r_vaddr
- input_section
->vma
,
3375 (info
->unresolved_syms_in_objects
3376 == RM_GENERATE_ERROR
))))
3379 if (h
->root
.type
== bfd_link_hash_defined
3380 || h
->root
.type
== bfd_link_hash_defweak
)
3382 sec
= h
->root
.u
.def
.section
;
3383 val
= (h
->root
.u
.def
.value
3384 + sec
->output_section
->vma
3385 + sec
->output_offset
);
3387 else if (h
->root
.type
== bfd_link_hash_common
)
3389 sec
= h
->root
.u
.c
.p
->section
;
3390 val
= (sec
->output_section
->vma
3391 + sec
->output_offset
);
3396 BFD_ASSERT (info
->relocatable
3397 || (info
->static_link
3398 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3399 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3400 || (h
->flags
& XCOFF_IMPORT
) != 0);
3405 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3406 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3407 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3408 addend
, &relocation
, contents
)))
3412 address
= rel
->r_vaddr
- input_section
->vma
;
3413 location
= contents
+ address
;
3415 if (address
> input_section
->size
)
3418 /* Get the value we are going to relocate. */
3419 if (1 == howto
.size
)
3420 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3422 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3426 FIXME: We may drop bits during the addition
3427 which we don't check for. We must either check at every single
3428 operation, which would be tedious, or we must do the computations
3429 in a type larger than bfd_vma, which would be inefficient. */
3431 if ((unsigned int) howto
.complain_on_overflow
3432 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3435 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3436 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3439 char buf
[SYMNMLEN
+ 1];
3440 char reloc_type_name
[10];
3452 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3456 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3458 if (! ((*info
->callbacks
->reloc_overflow
)
3459 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3460 (bfd_vma
) 0, input_bfd
, input_section
,
3461 rel
->r_vaddr
- input_section
->vma
)))
3465 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3466 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3467 | (((value_to_relocate
& howto
.src_mask
)
3468 + relocation
) & howto
.dst_mask
));
3470 /* Put the value back in the object file. */
3471 if (1 == howto
.size
)
3472 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3474 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3481 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3482 struct xcoff_loader_info
*ldinfo
,
3483 struct internal_ldsym
*ldsym
,
3487 len
= strlen (name
);
3489 if (len
<= SYMNMLEN
)
3490 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3493 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3495 bfd_size_type newalc
;
3498 newalc
= ldinfo
->string_alc
* 2;
3501 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3504 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3505 if (newstrings
== NULL
)
3507 ldinfo
->failed
= TRUE
;
3510 ldinfo
->string_alc
= newalc
;
3511 ldinfo
->strings
= newstrings
;
3514 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3515 ldinfo
->strings
+ ldinfo
->string_size
);
3516 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3517 ldsym
->_l
._l_l
._l_zeroes
= 0;
3518 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3519 ldinfo
->string_size
+= len
+ 3;
3526 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3527 struct internal_syment
*sym
,
3530 if (strlen (name
) <= SYMNMLEN
)
3532 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3540 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3542 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3543 if (indx
== (bfd_size_type
) -1)
3545 sym
->_n
._n_n
._n_zeroes
= 0;
3546 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3552 xcoff_create_csect_from_smclas (bfd
*abfd
,
3553 union internal_auxent
*aux
,
3554 const char *symbol_name
)
3556 asection
*return_value
= NULL
;
3558 /* .sv64 = x_smclas == 17
3559 This is an invalid csect for 32 bit apps. */
3560 static const char * const names
[] =
3562 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3563 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0", /* 8 - 15 */
3564 ".td", NULL
, ".sv3264", NULL
, ".tl", ".ul", ".te"
3567 if ((aux
->x_csect
.x_smclas
< ARRAY_SIZE (names
))
3568 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3570 return_value
= bfd_make_section_anyway
3571 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3575 (*_bfd_error_handler
)
3576 (_("%B: symbol `%s' has unrecognized smclas %d"),
3577 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3578 bfd_set_error (bfd_error_bad_value
);
3581 return return_value
;
3585 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3587 if (0xffff <= value
)
3594 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3596 if (0xffff <= value
)
3603 xcoff_loader_symbol_offset (bfd
*abfd
,
3604 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3606 return bfd_xcoff_ldhdrsz (abfd
);
3610 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3612 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3616 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3619 bfd_byte filehdr_ext
[FILHSZ
];
3620 bfd_byte scnhdr_ext
[SCNHSZ
];
3621 bfd_byte syment_ext
[SYMESZ
* 10];
3622 bfd_byte reloc_ext
[RELSZ
* 3];
3623 bfd_byte
*data_buffer
;
3624 bfd_size_type data_buffer_size
;
3625 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3626 bfd_size_type string_table_size
;
3628 size_t initsz
, finisz
;
3629 struct internal_filehdr filehdr
;
3630 struct internal_scnhdr scnhdr
;
3631 struct internal_syment syment
;
3632 union internal_auxent auxent
;
3633 struct internal_reloc reloc
;
3635 char *data_name
= ".data";
3636 char *rtinit_name
= "__rtinit";
3637 char *rtld_name
= "__rtld";
3639 if (! bfd_xcoff_rtinit_size (abfd
))
3642 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3643 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3646 memset (filehdr_ext
, 0, FILHSZ
);
3647 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3648 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3649 filehdr
.f_nscns
= 1;
3650 filehdr
.f_timdat
= 0;
3651 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3652 filehdr
.f_symptr
= 0; /* set below */
3653 filehdr
.f_opthdr
= 0;
3654 filehdr
.f_flags
= 0;
3656 /* section header */
3657 memset (scnhdr_ext
, 0, SCNHSZ
);
3658 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3659 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3662 scnhdr
.s_size
= 0; /* set below */
3663 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3664 scnhdr
.s_relptr
= 0; /* set below */
3665 scnhdr
.s_lnnoptr
= 0;
3666 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3668 scnhdr
.s_flags
= STYP_DATA
;
3671 0x0000 0x00000000 : rtl
3672 0x0004 0x00000010 : offset to init, or 0
3673 0x0008 0x00000028 : offset to fini, or 0
3674 0x000C 0x0000000C : size of descriptor
3675 0x0010 0x00000000 : init, needs a reloc
3676 0x0014 0x00000040 : offset to init name
3677 0x0018 0x00000000 : flags, padded to a word
3678 0x001C 0x00000000 : empty init
3681 0x0028 0x00000000 : fini, needs a reloc
3682 0x002C 0x00000??? : offset to fini name
3683 0x0030 0x00000000 : flags, padded to a word
3684 0x0034 0x00000000 : empty fini
3688 0x0040 + initsz fini name */
3690 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3691 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3693 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3694 if (data_buffer
== NULL
)
3700 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3702 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3703 memcpy (&data_buffer
[val
], init
, initsz
);
3709 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3710 val
= 0x40 + initsz
;
3711 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3712 memcpy (&data_buffer
[val
], fini
, finisz
);
3716 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3718 scnhdr
.s_size
= data_buffer_size
;
3721 string_table_size
= 0;
3723 string_table_size
+= initsz
;
3725 string_table_size
+= finisz
;
3726 if (string_table_size
)
3728 string_table_size
+= 4;
3729 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3730 if (string_table
== NULL
)
3733 val
= string_table_size
;
3734 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3735 st_tmp
= string_table
+ 4;
3744 memset (syment_ext
, 0, 10 * SYMESZ
);
3745 memset (reloc_ext
, 0, 3 * RELSZ
);
3748 memset (&syment
, 0, sizeof (struct internal_syment
));
3749 memset (&auxent
, 0, sizeof (union internal_auxent
));
3750 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3752 syment
.n_sclass
= C_HIDEXT
;
3753 syment
.n_numaux
= 1;
3754 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3755 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3756 auxent
.x_csect
.x_smclas
= XMC_RW
;
3757 bfd_coff_swap_sym_out (abfd
, &syment
,
3758 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3759 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3761 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3762 filehdr
.f_nsyms
+= 2;
3765 memset (&syment
, 0, sizeof (struct internal_syment
));
3766 memset (&auxent
, 0, sizeof (union internal_auxent
));
3767 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3769 syment
.n_sclass
= C_EXT
;
3770 syment
.n_numaux
= 1;
3771 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3772 auxent
.x_csect
.x_smclas
= XMC_RW
;
3773 bfd_coff_swap_sym_out (abfd
, &syment
,
3774 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3775 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3777 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3778 filehdr
.f_nsyms
+= 2;
3783 memset (&syment
, 0, sizeof (struct internal_syment
));
3784 memset (&auxent
, 0, sizeof (union internal_auxent
));
3788 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3789 memcpy (st_tmp
, init
, initsz
);
3793 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3795 syment
.n_sclass
= C_EXT
;
3796 syment
.n_numaux
= 1;
3797 bfd_coff_swap_sym_out (abfd
, &syment
,
3798 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3799 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3801 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3804 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3805 reloc
.r_vaddr
= 0x0010;
3806 reloc
.r_symndx
= filehdr
.f_nsyms
;
3807 reloc
.r_type
= R_POS
;
3809 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3811 filehdr
.f_nsyms
+= 2;
3812 scnhdr
.s_nreloc
+= 1;
3818 memset (&syment
, 0, sizeof (struct internal_syment
));
3819 memset (&auxent
, 0, sizeof (union internal_auxent
));
3823 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3824 memcpy (st_tmp
, fini
, finisz
);
3828 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3830 syment
.n_sclass
= C_EXT
;
3831 syment
.n_numaux
= 1;
3832 bfd_coff_swap_sym_out (abfd
, &syment
,
3833 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3834 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3836 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3839 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3840 reloc
.r_vaddr
= 0x0028;
3841 reloc
.r_symndx
= filehdr
.f_nsyms
;
3842 reloc
.r_type
= R_POS
;
3844 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3845 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3847 filehdr
.f_nsyms
+= 2;
3848 scnhdr
.s_nreloc
+= 1;
3853 memset (&syment
, 0, sizeof (struct internal_syment
));
3854 memset (&auxent
, 0, sizeof (union internal_auxent
));
3855 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3856 syment
.n_sclass
= C_EXT
;
3857 syment
.n_numaux
= 1;
3858 bfd_coff_swap_sym_out (abfd
, &syment
,
3859 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3860 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3862 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3865 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3866 reloc
.r_vaddr
= 0x0000;
3867 reloc
.r_symndx
= filehdr
.f_nsyms
;
3868 reloc
.r_type
= R_POS
;
3870 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3871 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3873 filehdr
.f_nsyms
+= 2;
3874 scnhdr
.s_nreloc
+= 1;
3877 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3878 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3880 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3881 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3882 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3883 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3884 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3885 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3886 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3887 bfd_bwrite (string_table
, string_table_size
, abfd
);
3896 static reloc_howto_type xcoff_dynamic_reloc
=
3897 HOWTO (0, /* type */
3899 2, /* size (0 = byte, 1 = short, 2 = long) */
3901 FALSE
, /* pc_relative */
3903 complain_overflow_bitfield
, /* complain_on_overflow */
3904 0, /* special_function */
3906 TRUE
, /* partial_inplace */
3907 0xffffffff, /* src_mask */
3908 0xffffffff, /* dst_mask */
3909 FALSE
); /* pcrel_offset */
3913 The first word of global linkage code must be modified by filling in
3914 the correct TOC offset. */
3916 static unsigned long xcoff_glink_code
[9] =
3918 0x81820000, /* lwz r12,0(r2) */
3919 0x90410014, /* stw r2,20(r1) */
3920 0x800c0000, /* lwz r0,0(r12) */
3921 0x804c0004, /* lwz r2,4(r12) */
3922 0x7c0903a6, /* mtctr r0 */
3923 0x4e800420, /* bctr */
3924 0x00000000, /* start of traceback table */
3925 0x000c8000, /* traceback table */
3926 0x00000000, /* traceback table */
3929 /* Table to convert DWARF flags to section names. */
3931 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
3932 { SSUBTYP_DWINFO
, ".dwinfo", TRUE
},
3933 { SSUBTYP_DWLINE
, ".dwline", TRUE
},
3934 { SSUBTYP_DWPBNMS
, ".dwpbnms", TRUE
},
3935 { SSUBTYP_DWPBTYP
, ".dwpbtyp", TRUE
},
3936 { SSUBTYP_DWARNGE
, ".dwarnge", TRUE
},
3937 { SSUBTYP_DWABREV
, ".dwabrev", FALSE
},
3938 { SSUBTYP_DWSTR
, ".dwstr", TRUE
},
3939 { SSUBTYP_DWRNGES
, ".dwrnges", TRUE
}
3942 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3944 { /* COFF backend, defined in libcoff.h. */
3945 _bfd_xcoff_swap_aux_in
,
3946 _bfd_xcoff_swap_sym_in
,
3947 coff_swap_lineno_in
,
3948 _bfd_xcoff_swap_aux_out
,
3949 _bfd_xcoff_swap_sym_out
,
3950 coff_swap_lineno_out
,
3951 xcoff_swap_reloc_out
,
3952 coff_swap_filehdr_out
,
3953 coff_swap_aouthdr_out
,
3954 coff_swap_scnhdr_out
,
3963 TRUE
, /* _bfd_coff_long_filenames */
3964 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
3965 3, /* _bfd_coff_default_section_alignment_power */
3966 FALSE
, /* _bfd_coff_force_symnames_in_strings */
3967 2, /* _bfd_coff_debug_string_prefix_length */
3968 coff_swap_filehdr_in
,
3969 coff_swap_aouthdr_in
,
3970 coff_swap_scnhdr_in
,
3971 xcoff_swap_reloc_in
,
3972 coff_bad_format_hook
,
3973 coff_set_arch_mach_hook
,
3976 coff_set_alignment_hook
,
3977 coff_slurp_symbol_table
,
3978 symname_in_debug_hook
,
3979 coff_pointerize_aux_hook
,
3981 dummy_reloc16_extra_cases
,
3982 dummy_reloc16_estimate
,
3983 NULL
, /* bfd_coff_sym_is_global */
3984 coff_compute_section_file_positions
,
3985 NULL
, /* _bfd_coff_start_final_link */
3986 xcoff_ppc_relocate_section
,
3987 coff_rtype_to_howto
,
3988 NULL
, /* _bfd_coff_adjust_symndx */
3989 _bfd_generic_link_add_one_symbol
,
3990 coff_link_output_has_begun
,
3991 coff_final_link_postscript
,
3992 NULL
/* print_pdata. */
3995 0x01DF, /* magic number */
3999 /* Function pointers to xcoff specific swap routines. */
4000 xcoff_swap_ldhdr_in
,
4001 xcoff_swap_ldhdr_out
,
4002 xcoff_swap_ldsym_in
,
4003 xcoff_swap_ldsym_out
,
4004 xcoff_swap_ldrel_in
,
4005 xcoff_swap_ldrel_out
,
4011 12, /* _xcoff_function_descriptor_size */
4015 1, /* _xcoff_ldhdr_version */
4017 _bfd_xcoff_put_symbol_name
,
4018 _bfd_xcoff_put_ldsymbol_name
,
4019 &xcoff_dynamic_reloc
,
4020 xcoff_create_csect_from_smclas
,
4022 /* Lineno and reloc count overflow. */
4023 xcoff_is_lineno_count_overflow
,
4024 xcoff_is_reloc_count_overflow
,
4026 xcoff_loader_symbol_offset
,
4027 xcoff_loader_reloc_offset
,
4030 &xcoff_glink_code
[0],
4031 36, /* _xcoff_glink_size */
4034 64, /* _xcoff_rtinit_size */
4035 xcoff_generate_rtinit
,
4038 /* The transfer vector that leads the outside world to all of the above. */
4039 const bfd_target rs6000coff_vec
=
4042 bfd_target_xcoff_flavour
,
4043 BFD_ENDIAN_BIG
, /* data byte order is big */
4044 BFD_ENDIAN_BIG
, /* header byte order is big */
4046 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4047 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4049 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4050 0, /* leading char */
4051 '/', /* ar_pad_char */
4052 15, /* ar_max_namelen */
4053 0, /* match priority. */
4077 { /* bfd_check_format */
4080 _bfd_xcoff_archive_p
,
4084 { /* bfd_set_format */
4087 _bfd_generic_mkarchive
,
4091 {/* bfd_write_contents */
4093 coff_write_object_contents
,
4094 _bfd_xcoff_write_archive_contents
,
4099 _bfd_archive_close_and_cleanup
,
4101 coff_new_section_hook
,
4102 _bfd_generic_get_section_contents
,
4103 _bfd_generic_get_section_contents_in_window
,
4106 _bfd_xcoff_copy_private_bfd_data
,
4107 _bfd_generic_bfd_merge_private_bfd_data
,
4108 _bfd_generic_init_private_section_data
,
4109 _bfd_generic_bfd_copy_private_section_data
,
4110 _bfd_generic_bfd_copy_private_symbol_data
,
4111 _bfd_generic_bfd_copy_private_header_data
,
4112 _bfd_generic_bfd_set_private_flags
,
4113 _bfd_generic_bfd_print_private_bfd_data
,
4116 BFD_JUMP_TABLE_CORE (coff
),
4119 _bfd_xcoff_slurp_armap
,
4120 _bfd_noarchive_slurp_extended_name_table
,
4121 _bfd_noarchive_construct_extended_name_table
,
4122 bfd_dont_truncate_arname
,
4123 _bfd_xcoff_write_armap
,
4124 _bfd_xcoff_read_ar_hdr
,
4125 _bfd_generic_write_ar_hdr
,
4126 _bfd_xcoff_openr_next_archived_file
,
4127 _bfd_generic_get_elt_at_index
,
4128 _bfd_xcoff_stat_arch_elt
,
4132 coff_get_symtab_upper_bound
,
4133 coff_canonicalize_symtab
,
4134 coff_make_empty_symbol
,
4136 coff_get_symbol_info
,
4137 _bfd_xcoff_is_local_label_name
,
4138 coff_bfd_is_target_special_symbol
,
4140 xcoff_find_nearest_line
,
4141 xcoff_find_nearest_line_discriminator
,
4142 _bfd_generic_find_line
,
4143 coff_find_inliner_info
,
4144 coff_bfd_make_debug_symbol
,
4145 _bfd_generic_read_minisymbols
,
4146 _bfd_generic_minisymbol_to_symbol
,
4149 coff_get_reloc_upper_bound
,
4150 coff_canonicalize_reloc
,
4151 _bfd_xcoff_reloc_type_lookup
,
4152 _bfd_xcoff_reloc_name_lookup
,
4156 coff_set_section_contents
,
4159 _bfd_xcoff_sizeof_headers
,
4160 bfd_generic_get_relocated_section_contents
,
4161 bfd_generic_relax_section
,
4162 _bfd_xcoff_bfd_link_hash_table_create
,
4163 _bfd_generic_link_hash_table_free
,
4164 _bfd_xcoff_bfd_link_add_symbols
,
4165 _bfd_generic_link_just_syms
,
4166 _bfd_generic_copy_link_hash_symbol_type
,
4167 _bfd_xcoff_bfd_final_link
,
4168 _bfd_generic_link_split_section
,
4169 bfd_generic_gc_sections
,
4170 bfd_generic_lookup_section_flags
,
4171 bfd_generic_merge_sections
,
4172 bfd_generic_is_group_section
,
4173 bfd_generic_discard_group
,
4174 _bfd_generic_section_already_linked
,
4175 _bfd_xcoff_define_common_symbol
,
4178 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4179 _bfd_xcoff_canonicalize_dynamic_symtab
,
4180 _bfd_nodynamic_get_synthetic_symtab
,
4181 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4182 _bfd_xcoff_canonicalize_dynamic_reloc
,
4184 /* Opposite endian version, none exists */
4187 & bfd_xcoff_backend_data
,
4190 /* xcoff-powermac target
4192 Only difference between this target and the rs6000 target is the
4193 the default architecture and machine type used in coffcode.h
4195 PowerPC Macs use the same magic numbers as RS/6000
4196 (because that's how they were bootstrapped originally),
4197 but they are always PowerPC architecture. */
4198 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4200 { /* COFF backend, defined in libcoff.h. */
4201 _bfd_xcoff_swap_aux_in
,
4202 _bfd_xcoff_swap_sym_in
,
4203 coff_swap_lineno_in
,
4204 _bfd_xcoff_swap_aux_out
,
4205 _bfd_xcoff_swap_sym_out
,
4206 coff_swap_lineno_out
,
4207 xcoff_swap_reloc_out
,
4208 coff_swap_filehdr_out
,
4209 coff_swap_aouthdr_out
,
4210 coff_swap_scnhdr_out
,
4219 TRUE
, /* _bfd_coff_long_filenames */
4220 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4221 3, /* _bfd_coff_default_section_alignment_power */
4222 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4223 2, /* _bfd_coff_debug_string_prefix_length */
4224 coff_swap_filehdr_in
,
4225 coff_swap_aouthdr_in
,
4226 coff_swap_scnhdr_in
,
4227 xcoff_swap_reloc_in
,
4228 coff_bad_format_hook
,
4229 coff_set_arch_mach_hook
,
4232 coff_set_alignment_hook
,
4233 coff_slurp_symbol_table
,
4234 symname_in_debug_hook
,
4235 coff_pointerize_aux_hook
,
4237 dummy_reloc16_extra_cases
,
4238 dummy_reloc16_estimate
,
4239 NULL
, /* bfd_coff_sym_is_global */
4240 coff_compute_section_file_positions
,
4241 NULL
, /* _bfd_coff_start_final_link */
4242 xcoff_ppc_relocate_section
,
4243 coff_rtype_to_howto
,
4244 NULL
, /* _bfd_coff_adjust_symndx */
4245 _bfd_generic_link_add_one_symbol
,
4246 coff_link_output_has_begun
,
4247 coff_final_link_postscript
,
4248 NULL
/* print_pdata. */
4251 0x01DF, /* magic number */
4255 /* Function pointers to xcoff specific swap routines. */
4256 xcoff_swap_ldhdr_in
,
4257 xcoff_swap_ldhdr_out
,
4258 xcoff_swap_ldsym_in
,
4259 xcoff_swap_ldsym_out
,
4260 xcoff_swap_ldrel_in
,
4261 xcoff_swap_ldrel_out
,
4267 12, /* _xcoff_function_descriptor_size */
4271 1, /* _xcoff_ldhdr_version */
4273 _bfd_xcoff_put_symbol_name
,
4274 _bfd_xcoff_put_ldsymbol_name
,
4275 &xcoff_dynamic_reloc
,
4276 xcoff_create_csect_from_smclas
,
4278 /* Lineno and reloc count overflow. */
4279 xcoff_is_lineno_count_overflow
,
4280 xcoff_is_reloc_count_overflow
,
4282 xcoff_loader_symbol_offset
,
4283 xcoff_loader_reloc_offset
,
4286 &xcoff_glink_code
[0],
4287 36, /* _xcoff_glink_size */
4290 0, /* _xcoff_rtinit_size */
4291 xcoff_generate_rtinit
,
4294 /* The transfer vector that leads the outside world to all of the above. */
4295 const bfd_target pmac_xcoff_vec
=
4298 bfd_target_xcoff_flavour
,
4299 BFD_ENDIAN_BIG
, /* data byte order is big */
4300 BFD_ENDIAN_BIG
, /* header byte order is big */
4302 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4303 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4305 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4306 0, /* leading char */
4307 '/', /* ar_pad_char */
4308 15, /* ar_max_namelen */
4309 0, /* match priority. */
4333 { /* bfd_check_format */
4336 _bfd_xcoff_archive_p
,
4340 { /* bfd_set_format */
4343 _bfd_generic_mkarchive
,
4347 {/* bfd_write_contents */
4349 coff_write_object_contents
,
4350 _bfd_xcoff_write_archive_contents
,
4355 _bfd_archive_close_and_cleanup
,
4357 coff_new_section_hook
,
4358 _bfd_generic_get_section_contents
,
4359 _bfd_generic_get_section_contents_in_window
,
4362 _bfd_xcoff_copy_private_bfd_data
,
4363 _bfd_generic_bfd_merge_private_bfd_data
,
4364 _bfd_generic_init_private_section_data
,
4365 _bfd_generic_bfd_copy_private_section_data
,
4366 _bfd_generic_bfd_copy_private_symbol_data
,
4367 _bfd_generic_bfd_copy_private_header_data
,
4368 _bfd_generic_bfd_set_private_flags
,
4369 _bfd_generic_bfd_print_private_bfd_data
,
4372 BFD_JUMP_TABLE_CORE (coff
),
4375 _bfd_xcoff_slurp_armap
,
4376 _bfd_noarchive_slurp_extended_name_table
,
4377 _bfd_noarchive_construct_extended_name_table
,
4378 bfd_dont_truncate_arname
,
4379 _bfd_xcoff_write_armap
,
4380 _bfd_xcoff_read_ar_hdr
,
4381 _bfd_generic_write_ar_hdr
,
4382 _bfd_xcoff_openr_next_archived_file
,
4383 _bfd_generic_get_elt_at_index
,
4384 _bfd_xcoff_stat_arch_elt
,
4388 coff_get_symtab_upper_bound
,
4389 coff_canonicalize_symtab
,
4390 coff_make_empty_symbol
,
4392 coff_get_symbol_info
,
4393 _bfd_xcoff_is_local_label_name
,
4394 coff_bfd_is_target_special_symbol
,
4396 xcoff_find_nearest_line
,
4397 _bfd_generic_find_nearest_line_discriminator
,
4398 _bfd_generic_find_line
,
4399 coff_find_inliner_info
,
4400 coff_bfd_make_debug_symbol
,
4401 _bfd_generic_read_minisymbols
,
4402 _bfd_generic_minisymbol_to_symbol
,
4405 coff_get_reloc_upper_bound
,
4406 coff_canonicalize_reloc
,
4407 _bfd_xcoff_reloc_type_lookup
,
4408 _bfd_xcoff_reloc_name_lookup
,
4412 coff_set_section_contents
,
4415 _bfd_xcoff_sizeof_headers
,
4416 bfd_generic_get_relocated_section_contents
,
4417 bfd_generic_relax_section
,
4418 _bfd_xcoff_bfd_link_hash_table_create
,
4419 _bfd_generic_link_hash_table_free
,
4420 _bfd_xcoff_bfd_link_add_symbols
,
4421 _bfd_generic_link_just_syms
,
4422 _bfd_generic_copy_link_hash_symbol_type
,
4423 _bfd_xcoff_bfd_final_link
,
4424 _bfd_generic_link_split_section
,
4425 bfd_generic_gc_sections
,
4426 bfd_generic_lookup_section_flags
,
4427 bfd_generic_merge_sections
,
4428 bfd_generic_is_group_section
,
4429 bfd_generic_discard_group
,
4430 _bfd_generic_section_already_linked
,
4431 _bfd_xcoff_define_common_symbol
,
4434 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4435 _bfd_xcoff_canonicalize_dynamic_symtab
,
4436 _bfd_nodynamic_get_synthetic_symtab
,
4437 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4438 _bfd_xcoff_canonicalize_dynamic_reloc
,
4440 /* Opposite endian version, none exists */
4443 & bfd_pmac_xcoff_backend_data
,