1 /* BFD back-end for IBM RS/6000 "XCOFF64" files.
3 Free Software Foundation, Inc.
4 Written Clinton Popetz.
5 Contributed by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* Internalcoff.h and coffcode.h modify themselves based on these flags. */
25 #define RS6000COFF_C 1
30 #include "coff/internal.h"
31 #include "coff/rs6k64.h"
35 #define GET_FILEHDR_SYMPTR bfd_h_get_64
36 #define PUT_FILEHDR_SYMPTR bfd_h_put_64
37 #define GET_AOUTHDR_DATA_START bfd_h_get_64
38 #define PUT_AOUTHDR_DATA_START bfd_h_put_64
39 #define GET_AOUTHDR_TEXT_START bfd_h_get_64
40 #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
41 #define GET_AOUTHDR_TSIZE bfd_h_get_64
42 #define PUT_AOUTHDR_TSIZE bfd_h_put_64
43 #define GET_AOUTHDR_DSIZE bfd_h_get_64
44 #define PUT_AOUTHDR_DSIZE bfd_h_put_64
45 #define GET_AOUTHDR_BSIZE bfd_h_get_64
46 #define PUT_AOUTHDR_BSIZE bfd_h_put_64
47 #define GET_AOUTHDR_ENTRY bfd_h_get_64
48 #define PUT_AOUTHDR_ENTRY bfd_h_put_64
49 #define GET_SCNHDR_PADDR bfd_h_get_64
50 #define PUT_SCNHDR_PADDR bfd_h_put_64
51 #define GET_SCNHDR_VADDR bfd_h_get_64
52 #define PUT_SCNHDR_VADDR bfd_h_put_64
53 #define GET_SCNHDR_SIZE bfd_h_get_64
54 #define PUT_SCNHDR_SIZE bfd_h_put_64
55 #define GET_SCNHDR_SCNPTR bfd_h_get_64
56 #define PUT_SCNHDR_SCNPTR bfd_h_put_64
57 #define GET_SCNHDR_RELPTR bfd_h_get_64
58 #define PUT_SCNHDR_RELPTR bfd_h_put_64
59 #define GET_SCNHDR_LNNOPTR bfd_h_get_64
60 #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
61 #define GET_SCNHDR_NRELOC bfd_h_get_32
62 #define MAX_SCNHDR_NRELOC 0xffffffff
63 #define PUT_SCNHDR_NRELOC bfd_h_put_32
64 #define GET_SCNHDR_NLNNO bfd_h_get_32
65 #define MAX_SCNHDR_NLNNO 0xffffffff
66 #define PUT_SCNHDR_NLNNO bfd_h_put_32
67 #define GET_RELOC_VADDR bfd_h_get_64
68 #define PUT_RELOC_VADDR bfd_h_put_64
70 #define COFF_FORCE_SYMBOLS_IN_STRINGS
71 #define COFF_DEBUG_STRING_WIDE_PREFIX
73 #define TARGET_SYM rs6000coff64_vec
74 #define TARGET_NAME "aixcoff64-rs6000"
76 #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD,INT,EXT) \
78 memset (((SCNHDR *)EXT)->s_pad, 0, sizeof (((SCNHDR *)EXT)->s_pad));\
81 #define NO_COFF_LINENOS
83 #define coff_SWAP_lineno_in xcoff64_swap_lineno_in
84 #define coff_SWAP_lineno_out xcoff64_swap_lineno_out
86 #define PUTWORD bfd_h_put_32
87 #define PUTHALF bfd_h_put_16
88 #define PUTBYTE bfd_h_put_8
89 #define GETWORD bfd_h_get_32
90 #define GETHALF bfd_h_get_16
91 #define GETBYTE bfd_h_get_8
94 /* For XCOFF64, the effective width of symndx changes depending on
95 whether we are the first entry. Sigh. */
97 xcoff64_swap_lineno_in (abfd, ext1, in1)
102 LINENO *ext = (LINENO *)ext1;
103 struct internal_lineno *in = (struct internal_lineno *)in1;
105 in->l_lnno = bfd_h_get_32(abfd, (bfd_byte *) (ext->l_lnno));
107 in->l_addr.l_symndx =
108 bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
110 in->l_addr.l_symndx =
111 bfd_h_get_64(abfd, (bfd_byte *) ext->l_addr.l_symndx);
115 xcoff64_swap_lineno_out (abfd, inp, outp)
120 struct internal_lineno *in = (struct internal_lineno *)inp;
121 struct external_lineno *ext = (struct external_lineno *)outp;
122 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
123 ext->l_addr.l_symndx);
125 bfd_h_put_32 (abfd, in->l_lnno, (bfd_byte *) (ext->l_lnno));
127 bfd_h_put_32 (abfd, in->l_addr.l_symndx, (bfd_byte *)ext->l_addr.l_symndx);
129 bfd_h_put_64 (abfd, in->l_addr.l_symndx, (bfd_byte *)ext->l_addr.l_symndx);
131 return bfd_coff_linesz (abfd);
134 #define NO_COFF_SYMBOLS
136 static void xcoff64_swap_sym_in PARAMS ((bfd *, PTR, PTR));
137 static unsigned int xcoff64_swap_sym_out PARAMS ((bfd *, PTR, PTR));
138 static void xcoff64_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
139 static unsigned int xcoff64_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
142 xcoff64_swap_sym_in (abfd, ext1, in1)
147 SYMENT *ext = (SYMENT *)ext1;
148 struct internal_syment *in = (struct internal_syment *)in1;
151 in->_n._n_n._n_zeroes = 0;
152 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e_offset);
153 in->n_value = bfd_h_get_64(abfd, (bfd_byte *) ext->e.e_value);
154 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
155 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
156 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
157 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
161 xcoff64_swap_sym_out (abfd, inp, extp)
166 struct internal_syment *in = (struct internal_syment *)inp;
167 SYMENT *ext =(SYMENT *)extp;
169 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e_offset);
170 bfd_h_put_64(abfd, in->n_value , (bfd_byte *) ext->e.e_value);
171 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
172 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
173 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
174 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
175 return bfd_coff_symesz (abfd);
179 xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
188 AUXENT *ext = (AUXENT *)ext1;
189 union internal_auxent *in = (union internal_auxent *)in1;
193 if (ext->x_file.x_fname[0] == 0) {
194 in->x_file.x_n.x_zeroes = 0;
195 in->x_file.x_n.x_offset =
196 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
201 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
202 numaux * sizeof (AUXENT));
206 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
211 /* RS/6000 "csect" auxents */
214 if (indx + 1 == numaux)
216 in->x_csect.x_scnlen.l =
217 bfd_h_get_32(abfd, ext->x_csect.x_scnlen_lo);
218 /* FIXME: If we want section lengths larger than 32 bits, we need
219 to modify the internal coff structures to support it. */
220 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
221 ext->x_csect.x_parmhash);
222 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
223 /* We don't have to hack bitfields in x_smtyp because it's
224 defined by shifts-and-ands, which are equivalent on all
226 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
227 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
235 if (type == T_NULL) {
236 /* PE defines some extra fields; we zero them out for
238 in->x_scn.x_checksum = 0;
239 in->x_scn.x_associated = 0;
240 in->x_scn.x_comdat = 0;
247 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
249 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_64(abfd, (bfd_byte *)
250 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
251 in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
252 ext->x_sym.x_fcnary.x_fcn.x_endndx);
255 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
258 in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_32(abfd, (bfd_byte *)
259 ext->x_sym.x_fcnary.x_lnsz.x_lnno);
260 in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
261 ext->x_sym.x_fcnary.x_lnsz.x_size);
265 /* the semicolon is because MSVC doesn't like labels at
273 xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
278 int indx ATTRIBUTE_UNUSED;
279 int numaux ATTRIBUTE_UNUSED;
282 union internal_auxent *in = (union internal_auxent *)inp;
283 AUXENT *ext = (AUXENT *)extp;
285 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
289 if (in->x_file.x_fname[0] == 0)
291 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
293 in->x_file.x_n.x_offset,
294 (bfd_byte *) ext->x_file.x_n.x_offset);
298 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
300 PUTBYTE (abfd, _AUX_FILE, (bfd_byte *) ext->x_auxtype.x_auxtype);
303 /* RS/6000 "csect" auxents */
306 if (indx + 1 == numaux)
308 PUTWORD (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen_lo);
309 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
310 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
311 /* We don't have to hack bitfields in x_smtyp because it's
312 defined by shifts-and-ands, which are equivalent on all
314 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
315 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
316 PUTBYTE (abfd, _AUX_CSECT, (bfd_byte *) ext->x_auxtype.x_auxtype);
324 if (type == T_NULL) {
330 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
332 bfd_h_put_64(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
333 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
334 PUTBYTE (abfd, _AUX_FCN, (bfd_byte *) ext->x_auxtype.x_auxtype);
335 PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
336 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
339 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
340 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
343 bfd_h_put_32(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
344 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_lnno);
345 bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
346 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_size);
350 return bfd_coff_auxesz (abfd);
353 #define SELECT_RELOC(internal, howto) \
355 internal.r_type = howto->type; \
357 ((howto->complain_on_overflow == complain_overflow_signed \
360 | (howto->bitsize - 1)); \
363 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
365 #define COFF_LONG_FILENAMES
367 #define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst)
369 #define coff_SWAP_sym_in xcoff64_swap_sym_in
370 #define coff_SWAP_sym_out xcoff64_swap_sym_out
371 #define coff_SWAP_aux_in xcoff64_swap_aux_in
372 #define coff_SWAP_aux_out xcoff64_swap_aux_out
373 #define coff_mkobject _bfd_xcoff_mkobject
374 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
375 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
376 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
377 #define coff_relocate_section _bfd_ppc_xcoff_relocate_section
379 extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
380 extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
381 extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
382 extern void _bfd_xcoff_rtype2howto
383 PARAMS ((arelent *, struct internal_reloc *));
384 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
385 PARAMS ((bfd *, bfd_reloc_code_real_type));
386 extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
387 extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *));
388 extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
389 extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
390 extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
391 extern boolean _bfd_xcoff_write_armap
392 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
393 extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
394 extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
396 #define _bfd_xcoff_slurp_extended_name_table bfd_false
397 #define _bfd_xcoff_construct_extended_name_table \
398 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
400 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
402 /* We can use the standard get_elt_at_index routine. */
404 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
406 /* XCOFF archives do not have a timestamp. */
408 #define _bfd_xcoff_update_armap_timestamp bfd_true
410 #include "coffcode.h"
412 #define CORE_FILE_P _bfd_dummy_target
414 #define coff_core_file_failing_command _bfd_nocore_core_file_failing_command
415 #define coff_core_file_failing_signal _bfd_nocore_core_file_failing_signal
416 #define coff_core_file_matches_executable_p \
417 _bfd_nocore_core_file_matches_executable_p
419 #define _bfd_xcoff_bfd_get_relocated_section_contents \
420 coff_bfd_get_relocated_section_contents
421 #define _bfd_xcoff_bfd_relax_section coff_bfd_relax_section
422 #define _bfd_xcoff_bfd_gc_sections coff_bfd_gc_sections
423 #define _bfd_xcoff_bfd_link_split_section coff_bfd_link_split_section
425 /* The transfer vector that leads the outside world to all of the above. */
437 "aixcoff64-rs6000", /* name */
439 bfd_target_coff_flavour,
440 BFD_ENDIAN_BIG, /* data byte order is big */
441 BFD_ENDIAN_BIG, /* header byte order is big */
443 (HAS_RELOC | EXEC_P | /* object flags */
444 HAS_LINENO | HAS_DEBUG | DYNAMIC |
445 HAS_SYMS | HAS_LOCALS | WP_TEXT),
447 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
448 0, /* leading char */
449 '/', /* ar_pad_char */
450 15, /* ar_max_namelen??? FIXMEmgo */
452 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
453 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
454 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
455 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
456 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
457 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
459 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
460 _bfd_xcoff_archive_p, CORE_FILE_P},
461 {bfd_false, coff_mkobject, /* bfd_set_format */
462 _bfd_generic_mkarchive, bfd_false},
463 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
464 _bfd_xcoff_write_archive_contents, bfd_false},
466 BFD_JUMP_TABLE_GENERIC (coff),
467 BFD_JUMP_TABLE_COPY (coff),
468 BFD_JUMP_TABLE_CORE (coff),
469 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
470 BFD_JUMP_TABLE_SYMBOLS (coff),
471 BFD_JUMP_TABLE_RELOCS (coff),
472 BFD_JUMP_TABLE_WRITE (coff),
473 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
474 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),