1 /* Byte-swapping routines for COFF files */
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Diddler.
7 BFD is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 1, or (at your option) any later version.
11 BFD is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 You should have received a copy of the GNU General Public License along with
17 BFD; see the file COPYING. If not, write to the Free Software Foundation,
18 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
24 #include "intel-coff.h"
26 #include "libcoff.h" /* to allow easier abstraction-breaking */
28 #define sp(x) bfd_h_put_x(abfd, x, &x)
30 /* All the swapping routines:
32 FIXME, these routines assume that the sizes, alignments, and offsets of
33 these fields are the same in the host and target. This is an invalid
34 assumption, which in particular breaks on the 386 and SPARC. Fix this
35 the same way that a.out.h and sunos.c were fixed: define char arrays
36 that represent the headers in the target systems' file, and have these
37 functions translate in from that format, and out to that format. */
40 DEFUN(bfd_coff_swap_name,(abfd, ptr),
45 /* There is an index which needs to be swapped */
46 bfd_h_put_x(abfd, ptr[1], (ptr + 1));
49 /* This is a string .. leave it alone */
54 DEFUN(bfd_coff_swap_sym,(abfd, se),
58 bfd_coff_swap_name(abfd, (long*)(se->n_name));
59 bfd_h_put_x(abfd, se->n_value, &se->n_value);
60 bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum);
61 bfd_h_put_x(abfd, se->n_type, &se->n_type);
62 bfd_h_put_x(abfd, se->n_sclass, &se->n_sclass);
63 bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux);
67 DEFUN(bfd_coff_swap_aux,(abfd, au, type, class),
75 bfd_coff_swap_name(abfd, (long *)(&au->x_file.x_n));
83 sp(au->x_scn.x_scnlen);
84 sp(au->x_scn.x_nreloc);
85 sp(au->x_scn.x_nlinno);
89 sp(au->x_sym.x_tagndx);
90 sp(au->x_sym.x_tvndx);
92 if (ISARY(type) || class == C_BLOCK) {
93 sp(au->x_sym.x_fcnary.x_ary.x_dimen[0]);
94 sp(au->x_sym.x_fcnary.x_ary.x_dimen[1]);
95 sp(au->x_sym.x_fcnary.x_ary.x_dimen[2]);
96 sp(au->x_sym.x_fcnary.x_ary.x_dimen[3]);
99 sp(au->x_sym.x_fcnary.x_fcn.x_lnnoptr);
100 sp(au->x_sym.x_fcnary.x_fcn.x_endndx);
103 sp(au->x_sym.x_misc.x_fsize);
106 sp(au->x_sym.x_misc.x_lnsz.x_lnno);
107 sp(au->x_sym.x_misc.x_lnsz.x_size);
113 DEFUN(bfd_coff_swap_lineno,(abfd, lineno),
117 sp(lineno->l_addr.l_symndx);