1 /* Generic COFF swapping routines, for BFD.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file contains routines used to swap COFF data. It is a header
22 file because the details of swapping depend on the details of the
23 structures used by each COFF implementation. This is included by
24 coffcode.h, as well as by the ECOFF backend.
26 Any file which uses this must first include "coff/internal.h" and
27 "coff/CPU.h". The functions will then be correct for that CPU. */
33 #define PUTWORD bfd_h_put_32
34 #define PUTHALF bfd_h_put_16
35 #define PUTBYTE bfd_h_put_8
37 #ifndef GET_FCN_LNNOPTR
38 #define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
41 #ifndef GET_FCN_ENDNDX
42 #define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
45 #ifndef PUT_FCN_LNNOPTR
46 #define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
48 #ifndef PUT_FCN_ENDNDX
49 #define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
52 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
55 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
58 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
61 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
63 #ifndef GET_SCN_SCNLEN
64 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
66 #ifndef GET_SCN_NRELOC
67 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
69 #ifndef GET_SCN_NLINNO
70 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
72 #ifndef PUT_SCN_SCNLEN
73 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
75 #ifndef PUT_SCN_NRELOC
76 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
78 #ifndef PUT_SCN_NLINNO
79 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
81 #ifndef GET_LINENO_LNNO
82 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
84 #ifndef PUT_LINENO_LNNO
85 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
88 /* The f_symptr field in the filehdr is sometimes 64 bits. */
89 #ifndef GET_FILEHDR_SYMPTR
90 #define GET_FILEHDR_SYMPTR bfd_h_get_32
92 #ifndef PUT_FILEHDR_SYMPTR
93 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
96 /* Some fields in the aouthdr are sometimes 64 bits. */
97 #ifndef GET_AOUTHDR_TSIZE
98 #define GET_AOUTHDR_TSIZE bfd_h_get_32
100 #ifndef PUT_AOUTHDR_TSIZE
101 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
103 #ifndef GET_AOUTHDR_DSIZE
104 #define GET_AOUTHDR_DSIZE bfd_h_get_32
106 #ifndef PUT_AOUTHDR_DSIZE
107 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
109 #ifndef GET_AOUTHDR_BSIZE
110 #define GET_AOUTHDR_BSIZE bfd_h_get_32
112 #ifndef PUT_AOUTHDR_BSIZE
113 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
115 #ifndef GET_AOUTHDR_ENTRY
116 #define GET_AOUTHDR_ENTRY bfd_h_get_32
118 #ifndef PUT_AOUTHDR_ENTRY
119 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
121 #ifndef GET_AOUTHDR_TEXT_START
122 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
124 #ifndef PUT_AOUTHDR_TEXT_START
125 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
127 #ifndef GET_AOUTHDR_DATA_START
128 #define GET_AOUTHDR_DATA_START bfd_h_get_32
130 #ifndef PUT_AOUTHDR_DATA_START
131 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
134 /* Some fields in the scnhdr are sometimes 64 bits. */
135 #ifndef GET_SCNHDR_PADDR
136 #define GET_SCNHDR_PADDR bfd_h_get_32
138 #ifndef PUT_SCNHDR_PADDR
139 #define PUT_SCNHDR_PADDR bfd_h_put_32
141 #ifndef GET_SCNHDR_VADDR
142 #define GET_SCNHDR_VADDR bfd_h_get_32
144 #ifndef PUT_SCNHDR_VADDR
145 #define PUT_SCNHDR_VADDR bfd_h_put_32
147 #ifndef GET_SCNHDR_SIZE
148 #define GET_SCNHDR_SIZE bfd_h_get_32
150 #ifndef PUT_SCNHDR_SIZE
151 #define PUT_SCNHDR_SIZE bfd_h_put_32
153 #ifndef GET_SCNHDR_SCNPTR
154 #define GET_SCNHDR_SCNPTR bfd_h_get_32
156 #ifndef PUT_SCNHDR_SCNPTR
157 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
159 #ifndef GET_SCNHDR_RELPTR
160 #define GET_SCNHDR_RELPTR bfd_h_get_32
162 #ifndef PUT_SCNHDR_RELPTR
163 #define PUT_SCNHDR_RELPTR bfd_h_put_32
165 #ifndef GET_SCNHDR_LNNOPTR
166 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
168 #ifndef PUT_SCNHDR_LNNOPTR
169 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
172 static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR));
173 static unsigned int coff_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
174 static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
175 static unsigned int coff_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
176 static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
177 static unsigned int coff_swap_filehdr_out PARAMS ((bfd *, PTR, PTR));
178 #ifndef NO_COFF_RELOCS
179 static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
180 static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
181 #endif /* NO_COFF_RELOCS */
182 #ifndef NO_COFF_SYMBOLS
183 static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
184 static unsigned int coff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
185 static void coff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
186 static unsigned int coff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
187 #endif /* NO_COFF_SYMBOLS */
188 #ifndef NO_COFF_LINENOS
189 static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
190 static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
191 #endif /* NO_COFF_LINENOS */
193 #ifndef NO_COFF_RELOCS
196 coff_swap_reloc_in (abfd, src, dst)
201 RELOC *reloc_src = (RELOC *) src;
202 struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
204 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
205 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
208 reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
209 reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
211 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
214 #ifdef SWAP_IN_RELOC_OFFSET
215 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
216 (bfd_byte *) reloc_src->r_offset);
221 coff_swap_reloc_out (abfd, src, dst)
226 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
227 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
228 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
229 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
232 bfd_h_put_8 (abfd, reloc_src->r_type, (bfd_byte *) reloc_dst->r_type);
233 bfd_h_put_8 (abfd, reloc_src->r_size, (bfd_byte *) reloc_dst->r_size);
235 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
239 #ifdef SWAP_OUT_RELOC_OFFSET
240 SWAP_OUT_RELOC_OFFSET(abfd,
242 (bfd_byte *) reloc_dst->r_offset);
244 #ifdef SWAP_OUT_RELOC_EXTRA
245 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
251 #endif /* NO_COFF_RELOCS */
254 coff_swap_filehdr_in (abfd, src, dst)
259 FILHDR *filehdr_src = (FILHDR *) src;
260 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
261 #ifdef COFF_ADJUST_FILEHDR_IN_PRE
262 COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst);
264 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
265 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
266 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
267 filehdr_dst->f_symptr =
268 GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
269 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
270 filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
271 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
272 /* start-sanitize-tic80 */
273 #ifdef TIC80_TARGET_ID
274 filehdr_dst->f_target_id = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_target_id);
276 /* end-sanitize-tic80 */
278 #ifdef COFF_ADJUST_FILEHDR_IN_POST
279 COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst);
284 coff_swap_filehdr_out (abfd, in, out)
289 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
290 FILHDR *filehdr_out = (FILHDR *)out;
292 #ifdef COFF_ADJUST_FILEHDR_OUT_PRE
293 COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out);
295 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
296 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
297 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
298 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
299 (bfd_byte *) filehdr_out->f_symptr);
300 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
301 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
302 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
303 /* start-sanitize-tic80 */
304 #ifdef TIC80_TARGET_ID
305 bfd_h_put_16(abfd, filehdr_in->f_target_id, (bfd_byte *) filehdr_out->f_target_id);
307 /* end-sanitize-tic80 */
309 #ifdef COFF_ADJUST_FILEHDR_OUT_POST
310 COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out);
316 #ifndef NO_COFF_SYMBOLS
319 coff_swap_sym_in (abfd, ext1, in1)
324 SYMENT *ext = (SYMENT *)ext1;
325 struct internal_syment *in = (struct internal_syment *)in1;
327 if( ext->e.e_name[0] == 0) {
328 in->_n._n_n._n_zeroes = 0;
329 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
332 #if SYMNMLEN != E_SYMNMLEN
333 -> Error, we need to cope with truncating or extending SYMNMLEN!;
335 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
338 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
339 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
340 if (sizeof(ext->e_type) == 2){
341 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
344 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
346 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
347 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
351 coff_swap_sym_out (abfd, inp, extp)
356 struct internal_syment *in = (struct internal_syment *)inp;
357 SYMENT *ext =(SYMENT *)extp;
358 if(in->_n._n_name[0] == 0) {
359 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
360 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
363 #if SYMNMLEN != E_SYMNMLEN
364 -> Error, we need to cope with truncating or extending SYMNMLEN!;
366 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
369 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
370 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
371 if (sizeof(ext->e_type) == 2)
373 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
377 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
379 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
380 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
385 coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
394 AUXENT *ext = (AUXENT *)ext1;
395 union internal_auxent *in = (union internal_auxent *)in1;
397 #ifdef COFF_ADJUST_AUX_IN_PRE
398 COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1);
402 if (ext->x_file.x_fname[0] == 0) {
403 in->x_file.x_n.x_zeroes = 0;
404 in->x_file.x_n.x_offset =
405 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
407 #if FILNMLEN != E_FILNMLEN
408 -> Error, we need to cope with truncating or extending FILNMLEN!;
410 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
415 /* RS/6000 "csect" auxents */
419 if (indx + 1 == numaux)
421 in->x_csect.x_scnlen.l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
422 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
423 ext->x_csect.x_parmhash);
424 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
425 /* We don't have to hack bitfields in x_smtyp because it's
426 defined by shifts-and-ands, which are equivalent on all
428 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
429 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
430 in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
431 in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
442 if (type == T_NULL) {
443 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
444 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
445 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
447 /* PE defines some extra fields; we zero them out for
449 in->x_scn.x_checksum = 0;
450 in->x_scn.x_associated = 0;
451 in->x_scn.x_comdat = 0;
458 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
460 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
463 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
465 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
466 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
470 #if DIMNUM != E_DIMNUM
471 #error we need to cope with truncating or extending DIMNUM
473 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
474 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
475 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
476 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
477 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
478 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
479 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
480 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
484 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
487 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
488 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
492 #ifdef COFF_ADJUST_AUX_IN_POST
493 COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, class, indx, numaux, in1);
498 coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
507 union internal_auxent *in = (union internal_auxent *)inp;
508 AUXENT *ext = (AUXENT *)extp;
510 #ifdef COFF_ADJUST_AUX_OUT_PRE
511 COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp);
513 memset((PTR)ext, 0, AUXESZ);
516 if (in->x_file.x_fname[0] == 0) {
517 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
519 in->x_file.x_n.x_offset,
520 (bfd_byte *) ext->x_file.x_n.x_offset);
523 #if FILNMLEN != E_FILNMLEN
524 -> Error, we need to cope with truncating or extending FILNMLEN!;
526 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
532 /* RS/6000 "csect" auxents */
535 if (indx + 1 == numaux)
537 PUTWORD (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
538 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
539 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
540 /* We don't have to hack bitfields in x_smtyp because it's
541 defined by shifts-and-ands, which are equivalent on all
543 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
544 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
545 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
546 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
557 if (type == T_NULL) {
558 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
559 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
560 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
566 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
568 bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
571 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
573 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
574 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
578 #if DIMNUM != E_DIMNUM
579 #error we need to cope with truncating or extending DIMNUM
581 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
582 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
583 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
584 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
585 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
586 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
587 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
588 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
592 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
593 (bfd_byte *) ext->x_sym.x_misc.x_fsize);
596 PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
597 PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
601 #ifdef COFF_ADJUST_AUX_OUT_POST
602 COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, class, indx, numaux, extp);
607 #endif /* NO_COFF_SYMBOLS */
609 #ifndef NO_COFF_LINENOS
612 coff_swap_lineno_in (abfd, ext1, in1)
617 LINENO *ext = (LINENO *)ext1;
618 struct internal_lineno *in = (struct internal_lineno *)in1;
620 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
621 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
625 coff_swap_lineno_out (abfd, inp, outp)
630 struct internal_lineno *in = (struct internal_lineno *)inp;
631 struct external_lineno *ext = (struct external_lineno *)outp;
632 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
633 ext->l_addr.l_symndx);
635 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
639 #endif /* NO_COFF_LINENOS */
642 coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
647 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
648 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
650 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
651 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
653 GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
655 GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
657 GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
659 GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
660 aouthdr_int->text_start =
661 GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
662 aouthdr_int->data_start =
663 GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
666 aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
670 bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
671 bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
672 bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
673 bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
678 aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
679 aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
680 aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
681 aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
682 aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
683 aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
684 aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
685 aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
686 aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
687 aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
688 aouthdr_int->o_cputype = bfd_h_get_16(abfd, aouthdr_ext->o_cputype);
689 aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
690 aouthdr_int->o_maxdata = bfd_h_get_32(abfd, aouthdr_ext->o_maxdata);
694 aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
695 aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
696 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
697 aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
698 aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
699 aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
700 aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
704 aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
705 aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
706 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
707 aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
712 coff_swap_aouthdr_out (abfd, in, out)
717 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
718 AOUTHDR *aouthdr_out = (AOUTHDR *)out;
720 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
721 bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
722 PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
723 PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
724 PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
725 PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
726 PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
727 (bfd_byte *) aouthdr_out->text_start);
728 PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
729 (bfd_byte *) aouthdr_out->data_start);
732 bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
736 bfd_h_put_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc);
737 bfd_h_put_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry);
738 bfd_h_put_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext);
739 bfd_h_put_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata);
740 bfd_h_put_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc);
741 bfd_h_put_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader);
742 bfd_h_put_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss);
743 bfd_h_put_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext);
744 bfd_h_put_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata);
745 bfd_h_put_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype);
746 bfd_h_put_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype);
747 bfd_h_put_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
748 bfd_h_put_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
749 memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2);
753 bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
754 bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
755 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
756 bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
757 bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
758 bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
759 bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
763 /* FIXME: What does bldrev mean? */
764 bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
765 bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
766 bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
767 bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
768 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
769 bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
776 coff_swap_scnhdr_in (abfd, ext, in)
781 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
782 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
784 #ifdef COFF_ADJUST_SCNHDR_IN_PRE
785 COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in);
787 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
788 scnhdr_int->s_vaddr =
789 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
790 scnhdr_int->s_paddr =
791 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
793 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
795 scnhdr_int->s_scnptr =
796 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
797 scnhdr_int->s_relptr =
798 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
799 scnhdr_int->s_lnnoptr =
800 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
801 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
803 scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
804 scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
806 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
807 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
810 scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
812 #ifdef COFF_ADJUST_SCNHDR_IN_POST
813 COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in);
818 coff_swap_scnhdr_out (abfd, in, out)
823 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
824 SCNHDR *scnhdr_ext = (SCNHDR *)out;
825 unsigned int ret = SCNHSZ;
827 #ifdef COFF_ADJUST_SCNHDR_OUT_PRE
828 COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out);
830 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
832 PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
833 (bfd_byte *) scnhdr_ext->s_vaddr);
836 PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
837 (bfd_byte *) scnhdr_ext->s_paddr);
838 PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
839 (bfd_byte *) scnhdr_ext->s_size);
841 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
842 (bfd_byte *) scnhdr_ext->s_scnptr);
843 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
844 (bfd_byte *) scnhdr_ext->s_relptr);
845 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
846 (bfd_byte *) scnhdr_ext->s_lnnoptr);
847 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
849 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
850 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
852 if (scnhdr_int->s_nlnno <= 0xffff)
853 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
856 char buf[sizeof (scnhdr_int->s_name) + 1];
858 memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
859 buf[sizeof (scnhdr_int->s_name)] = '\0';
860 (*_bfd_error_handler)
861 ("%s: warning: %s: line number overflow: 0x%lx > 0xffff",
862 bfd_get_filename (abfd),
863 buf, scnhdr_int->s_nlnno);
864 PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nlnno);
866 if (scnhdr_int->s_nreloc <= 0xffff)
867 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
870 char buf[sizeof (scnhdr_int->s_name) + 1];
872 memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
873 buf[sizeof (scnhdr_int->s_name)] = '\0';
874 (*_bfd_error_handler) ("%s: %s: reloc overflow: 0x%lx > 0xffff",
875 bfd_get_filename (abfd),
876 buf, scnhdr_int->s_nreloc);
877 bfd_set_error (bfd_error_file_truncated);
878 PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nreloc);
884 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
886 #ifdef COFF_ADJUST_SCNHDR_OUT_POST
887 COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out);