Avoid making a machine-dependent (probably wrong) declaration of malloc
[deliverable/binutils-gdb.git] / bfd / coffswap.c
CommitLineData
ff37ea55
JG
1/* Byte-swapping routines for COFF files */
2
3/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
4
5This file is part of BFD, the Binary File Diddler.
6
7BFD 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.
10
11BFD 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
14 details.
15
16You 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.
19*/
20
21/* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
22
23#include <ansidecl.h>
24#include "intel-coff.h"
25#include "bfd.h"
26#include "libcoff.h" /* to allow easier abstraction-breaking */
27
28#define sp(x) bfd_h_put_x(abfd, x, &x)
29
30/* All the swapping routines:
31
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. */
38
39void
40DEFUN(bfd_coff_swap_name,(abfd, ptr),
41 bfd *abfd AND
42 long *ptr)
43{
44 if (ptr[0] == 0) {
45 /* There is an index which needs to be swapped */
46 bfd_h_put_x(abfd, ptr[1], (ptr + 1));
47 }
48 else {
49 /* This is a string .. leave it alone */
50 }
51}
52
53void
54DEFUN(bfd_coff_swap_sym,(abfd, se),
55 bfd *abfd AND
56 SYMENT *se)
57{
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);
64}
65
66void
67DEFUN(bfd_coff_swap_aux,(abfd, au, type, class),
68 bfd *abfd AND
69 AUXENT *au AND
70 int type AND
71 int class)
72{
73 switch (class) {
74 case C_FILE:
75 bfd_coff_swap_name(abfd, (long *)(&au->x_file.x_n));
76 break;
77 case C_STAT:
78#ifdef C_LEAFSTAT
79 case C_LEAFSTAT:
80#endif
81 case C_HIDDEN:
82 if (type == T_NULL) {
83 sp(au->x_scn.x_scnlen);
84 sp(au->x_scn.x_nreloc);
85 sp(au->x_scn.x_nlinno);
86 break;
87 }
88 default:
89 sp(au->x_sym.x_tagndx);
90 sp(au->x_sym.x_tvndx);
91
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]);
97 }
98 else {
99 sp(au->x_sym.x_fcnary.x_fcn.x_lnnoptr);
100 sp(au->x_sym.x_fcnary.x_fcn.x_endndx);
101 }
102 if (ISFCN(type)) {
103 sp(au->x_sym.x_misc.x_fsize);
104 }
105 else {
106 sp(au->x_sym.x_misc.x_lnsz.x_lnno);
107 sp(au->x_sym.x_misc.x_lnsz.x_size);
108 }
109 }
110}
111
112void
113DEFUN(bfd_coff_swap_lineno,(abfd, lineno),
114 bfd *abfd AND
115 LINENO *lineno)
116{
117 sp(lineno->l_addr.l_symndx);
118 sp(lineno->l_lnno);
119}
120
121
This page took 0.027228 seconds and 4 git commands to generate.