]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Generic COFF swapping routines, for BFD. |
dc810e39 AM |
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, |
3 | 2001 | |
5f771d47 | 4 | Free Software Foundation, Inc. |
252b5132 RH |
5 | Written by Cygnus Support. |
6 | ||
7 | This file is part of BFD, the Binary File Descriptor library. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
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. */ | |
22 | ||
23 | /* This file contains routines used to swap COFF data. It is a header | |
24 | file because the details of swapping depend on the details of the | |
25 | structures used by each COFF implementation. This is included by | |
26 | coffcode.h, as well as by the ECOFF backend. | |
27 | ||
28 | Any file which uses this must first include "coff/internal.h" and | |
29 | "coff/CPU.h". The functions will then be correct for that CPU. */ | |
30 | ||
252b5132 | 31 | #ifndef GET_FCN_LNNOPTR |
dc810e39 AM |
32 | #define GET_FCN_LNNOPTR(abfd, ext) \ |
33 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) | |
252b5132 RH |
34 | #endif |
35 | ||
36 | #ifndef GET_FCN_ENDNDX | |
dc810e39 AM |
37 | #define GET_FCN_ENDNDX(abfd, ext) \ |
38 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx) | |
252b5132 RH |
39 | #endif |
40 | ||
41 | #ifndef PUT_FCN_LNNOPTR | |
dc810e39 AM |
42 | #define PUT_FCN_LNNOPTR(abfd, in, ext) \ |
43 | H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) | |
252b5132 RH |
44 | #endif |
45 | #ifndef PUT_FCN_ENDNDX | |
dc810e39 AM |
46 | #define PUT_FCN_ENDNDX(abfd, in, ext) \ |
47 | H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx) | |
252b5132 RH |
48 | #endif |
49 | #ifndef GET_LNSZ_LNNO | |
dc810e39 AM |
50 | #define GET_LNSZ_LNNO(abfd, ext) \ |
51 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno) | |
252b5132 RH |
52 | #endif |
53 | #ifndef GET_LNSZ_SIZE | |
dc810e39 AM |
54 | #define GET_LNSZ_SIZE(abfd, ext) \ |
55 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size) | |
252b5132 RH |
56 | #endif |
57 | #ifndef PUT_LNSZ_LNNO | |
dc810e39 AM |
58 | #define PUT_LNSZ_LNNO(abfd, in, ext) \ |
59 | H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno) | |
252b5132 RH |
60 | #endif |
61 | #ifndef PUT_LNSZ_SIZE | |
dc810e39 AM |
62 | #define PUT_LNSZ_SIZE(abfd, in, ext) \ |
63 | H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_size) | |
252b5132 RH |
64 | #endif |
65 | #ifndef GET_SCN_SCNLEN | |
dc810e39 AM |
66 | #define GET_SCN_SCNLEN(abfd, ext) \ |
67 | H_GET_32 (abfd, ext->x_scn.x_scnlen) | |
252b5132 RH |
68 | #endif |
69 | #ifndef GET_SCN_NRELOC | |
dc810e39 AM |
70 | #define GET_SCN_NRELOC(abfd, ext) \ |
71 | H_GET_16 (abfd, ext->x_scn.x_nreloc) | |
252b5132 RH |
72 | #endif |
73 | #ifndef GET_SCN_NLINNO | |
dc810e39 AM |
74 | #define GET_SCN_NLINNO(abfd, ext) \ |
75 | H_GET_16 (abfd, ext->x_scn.x_nlinno) | |
252b5132 RH |
76 | #endif |
77 | #ifndef PUT_SCN_SCNLEN | |
dc810e39 AM |
78 | #define PUT_SCN_SCNLEN(abfd, in, ext) \ |
79 | H_PUT_32 (abfd, in, ext->x_scn.x_scnlen) | |
252b5132 RH |
80 | #endif |
81 | #ifndef PUT_SCN_NRELOC | |
dc810e39 AM |
82 | #define PUT_SCN_NRELOC(abfd, in, ext) \ |
83 | H_PUT_16 (abfd, in, ext->x_scn.x_nreloc) | |
252b5132 RH |
84 | #endif |
85 | #ifndef PUT_SCN_NLINNO | |
dc810e39 AM |
86 | #define PUT_SCN_NLINNO(abfd, in, ext) \ |
87 | H_PUT_16 (abfd, in, ext->x_scn.x_nlinno) | |
252b5132 RH |
88 | #endif |
89 | #ifndef GET_LINENO_LNNO | |
dc810e39 AM |
90 | #define GET_LINENO_LNNO(abfd, ext) \ |
91 | H_GET_16 (abfd, ext->l_lnno); | |
252b5132 RH |
92 | #endif |
93 | #ifndef PUT_LINENO_LNNO | |
dc810e39 AM |
94 | #define PUT_LINENO_LNNO(abfd, val, ext) \ |
95 | H_PUT_16 (abfd, val, ext->l_lnno); | |
252b5132 RH |
96 | #endif |
97 | ||
98 | /* The f_symptr field in the filehdr is sometimes 64 bits. */ | |
99 | #ifndef GET_FILEHDR_SYMPTR | |
dc810e39 | 100 | #define GET_FILEHDR_SYMPTR H_GET_32 |
252b5132 RH |
101 | #endif |
102 | #ifndef PUT_FILEHDR_SYMPTR | |
dc810e39 | 103 | #define PUT_FILEHDR_SYMPTR H_PUT_32 |
252b5132 RH |
104 | #endif |
105 | ||
106 | /* Some fields in the aouthdr are sometimes 64 bits. */ | |
107 | #ifndef GET_AOUTHDR_TSIZE | |
dc810e39 | 108 | #define GET_AOUTHDR_TSIZE H_GET_32 |
252b5132 RH |
109 | #endif |
110 | #ifndef PUT_AOUTHDR_TSIZE | |
dc810e39 | 111 | #define PUT_AOUTHDR_TSIZE H_PUT_32 |
252b5132 RH |
112 | #endif |
113 | #ifndef GET_AOUTHDR_DSIZE | |
dc810e39 | 114 | #define GET_AOUTHDR_DSIZE H_GET_32 |
252b5132 RH |
115 | #endif |
116 | #ifndef PUT_AOUTHDR_DSIZE | |
dc810e39 | 117 | #define PUT_AOUTHDR_DSIZE H_PUT_32 |
252b5132 RH |
118 | #endif |
119 | #ifndef GET_AOUTHDR_BSIZE | |
dc810e39 | 120 | #define GET_AOUTHDR_BSIZE H_GET_32 |
252b5132 RH |
121 | #endif |
122 | #ifndef PUT_AOUTHDR_BSIZE | |
dc810e39 | 123 | #define PUT_AOUTHDR_BSIZE H_PUT_32 |
252b5132 RH |
124 | #endif |
125 | #ifndef GET_AOUTHDR_ENTRY | |
dc810e39 | 126 | #define GET_AOUTHDR_ENTRY H_GET_32 |
252b5132 RH |
127 | #endif |
128 | #ifndef PUT_AOUTHDR_ENTRY | |
dc810e39 | 129 | #define PUT_AOUTHDR_ENTRY H_PUT_32 |
252b5132 RH |
130 | #endif |
131 | #ifndef GET_AOUTHDR_TEXT_START | |
dc810e39 | 132 | #define GET_AOUTHDR_TEXT_START H_GET_32 |
252b5132 RH |
133 | #endif |
134 | #ifndef PUT_AOUTHDR_TEXT_START | |
dc810e39 | 135 | #define PUT_AOUTHDR_TEXT_START H_PUT_32 |
252b5132 RH |
136 | #endif |
137 | #ifndef GET_AOUTHDR_DATA_START | |
dc810e39 | 138 | #define GET_AOUTHDR_DATA_START H_GET_32 |
252b5132 RH |
139 | #endif |
140 | #ifndef PUT_AOUTHDR_DATA_START | |
dc810e39 | 141 | #define PUT_AOUTHDR_DATA_START H_PUT_32 |
252b5132 RH |
142 | #endif |
143 | ||
144 | /* Some fields in the scnhdr are sometimes 64 bits. */ | |
145 | #ifndef GET_SCNHDR_PADDR | |
dc810e39 | 146 | #define GET_SCNHDR_PADDR H_GET_32 |
252b5132 RH |
147 | #endif |
148 | #ifndef PUT_SCNHDR_PADDR | |
dc810e39 | 149 | #define PUT_SCNHDR_PADDR H_PUT_32 |
252b5132 RH |
150 | #endif |
151 | #ifndef GET_SCNHDR_VADDR | |
dc810e39 | 152 | #define GET_SCNHDR_VADDR H_GET_32 |
252b5132 RH |
153 | #endif |
154 | #ifndef PUT_SCNHDR_VADDR | |
dc810e39 | 155 | #define PUT_SCNHDR_VADDR H_PUT_32 |
252b5132 RH |
156 | #endif |
157 | #ifndef GET_SCNHDR_SIZE | |
dc810e39 | 158 | #define GET_SCNHDR_SIZE H_GET_32 |
252b5132 RH |
159 | #endif |
160 | #ifndef PUT_SCNHDR_SIZE | |
dc810e39 | 161 | #define PUT_SCNHDR_SIZE H_PUT_32 |
252b5132 RH |
162 | #endif |
163 | #ifndef GET_SCNHDR_SCNPTR | |
dc810e39 | 164 | #define GET_SCNHDR_SCNPTR H_GET_32 |
252b5132 RH |
165 | #endif |
166 | #ifndef PUT_SCNHDR_SCNPTR | |
dc810e39 | 167 | #define PUT_SCNHDR_SCNPTR H_PUT_32 |
252b5132 RH |
168 | #endif |
169 | #ifndef GET_SCNHDR_RELPTR | |
dc810e39 | 170 | #define GET_SCNHDR_RELPTR H_GET_32 |
252b5132 RH |
171 | #endif |
172 | #ifndef PUT_SCNHDR_RELPTR | |
dc810e39 | 173 | #define PUT_SCNHDR_RELPTR H_PUT_32 |
252b5132 RH |
174 | #endif |
175 | #ifndef GET_SCNHDR_LNNOPTR | |
dc810e39 | 176 | #define GET_SCNHDR_LNNOPTR H_GET_32 |
252b5132 RH |
177 | #endif |
178 | #ifndef PUT_SCNHDR_LNNOPTR | |
dc810e39 | 179 | #define PUT_SCNHDR_LNNOPTR H_PUT_32 |
252b5132 RH |
180 | #endif |
181 | #ifndef GET_SCNHDR_NRELOC | |
dc810e39 | 182 | #define GET_SCNHDR_NRELOC H_GET_16 |
252b5132 | 183 | #endif |
7f6d05e8 CP |
184 | #ifndef MAX_SCNHDR_NRELOC |
185 | #define MAX_SCNHDR_NRELOC 0xffff | |
186 | #endif | |
252b5132 | 187 | #ifndef PUT_SCNHDR_NRELOC |
dc810e39 | 188 | #define PUT_SCNHDR_NRELOC H_PUT_16 |
252b5132 RH |
189 | #endif |
190 | #ifndef GET_SCNHDR_NLNNO | |
dc810e39 | 191 | #define GET_SCNHDR_NLNNO H_GET_16 |
252b5132 | 192 | #endif |
7f6d05e8 CP |
193 | #ifndef MAX_SCNHDR_NLNNO |
194 | #define MAX_SCNHDR_NLNNO 0xffff | |
195 | #endif | |
252b5132 | 196 | #ifndef PUT_SCNHDR_NLNNO |
dc810e39 | 197 | #define PUT_SCNHDR_NLNNO H_PUT_16 |
252b5132 RH |
198 | #endif |
199 | #ifndef GET_SCNHDR_FLAGS | |
dc810e39 | 200 | #define GET_SCNHDR_FLAGS H_GET_32 |
252b5132 RH |
201 | #endif |
202 | #ifndef PUT_SCNHDR_FLAGS | |
dc810e39 | 203 | #define PUT_SCNHDR_FLAGS H_PUT_32 |
252b5132 RH |
204 | #endif |
205 | ||
7f6d05e8 | 206 | #ifndef GET_RELOC_VADDR |
dc810e39 | 207 | #define GET_RELOC_VADDR H_GET_32 |
7f6d05e8 CP |
208 | #endif |
209 | #ifndef PUT_RELOC_VADDR | |
dc810e39 | 210 | #define PUT_RELOC_VADDR H_PUT_32 |
7f6d05e8 | 211 | #endif |
252b5132 RH |
212 | |
213 | static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR)); | |
214 | static unsigned int coff_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR)); | |
215 | static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR)); | |
216 | static unsigned int coff_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR)); | |
217 | static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR)); | |
218 | static unsigned int coff_swap_filehdr_out PARAMS ((bfd *, PTR, PTR)); | |
219 | #ifndef NO_COFF_RELOCS | |
220 | static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR)); | |
221 | static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR)); | |
222 | #endif /* NO_COFF_RELOCS */ | |
223 | #ifndef NO_COFF_SYMBOLS | |
224 | static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR)); | |
225 | static unsigned int coff_swap_sym_out PARAMS ((bfd *, PTR, PTR)); | |
226 | static void coff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
227 | static unsigned int coff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
228 | #endif /* NO_COFF_SYMBOLS */ | |
229 | #ifndef NO_COFF_LINENOS | |
230 | static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR)); | |
231 | static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR)); | |
232 | #endif /* NO_COFF_LINENOS */ | |
233 | ||
234 | #ifndef NO_COFF_RELOCS | |
235 | ||
236 | static void | |
237 | coff_swap_reloc_in (abfd, src, dst) | |
238 | bfd *abfd; | |
239 | PTR src; | |
240 | PTR dst; | |
241 | { | |
242 | RELOC *reloc_src = (RELOC *) src; | |
243 | struct internal_reloc *reloc_dst = (struct internal_reloc *) dst; | |
244 | ||
dc810e39 AM |
245 | reloc_dst->r_vaddr = GET_RELOC_VADDR (abfd, reloc_src->r_vaddr); |
246 | reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx); | |
dc810e39 | 247 | reloc_dst->r_type = H_GET_16 (abfd, reloc_src->r_type); |
252b5132 RH |
248 | |
249 | #ifdef SWAP_IN_RELOC_OFFSET | |
dc810e39 | 250 | reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset); |
252b5132 RH |
251 | #endif |
252 | } | |
253 | ||
254 | static unsigned int | |
255 | coff_swap_reloc_out (abfd, src, dst) | |
dc810e39 AM |
256 | bfd *abfd; |
257 | PTR src; | |
258 | PTR dst; | |
252b5132 | 259 | { |
dc810e39 AM |
260 | struct internal_reloc *reloc_src = (struct internal_reloc *) src; |
261 | struct external_reloc *reloc_dst = (struct external_reloc *) dst; | |
262 | PUT_RELOC_VADDR (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr); | |
263 | H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx); | |
dc810e39 | 264 | H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type); |
252b5132 RH |
265 | |
266 | #ifdef SWAP_OUT_RELOC_OFFSET | |
dc810e39 | 267 | SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset); |
252b5132 RH |
268 | #endif |
269 | #ifdef SWAP_OUT_RELOC_EXTRA | |
dc810e39 | 270 | SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst); |
252b5132 RH |
271 | #endif |
272 | ||
6b3b007b | 273 | return bfd_coff_relsz (abfd); |
252b5132 RH |
274 | } |
275 | ||
276 | #endif /* NO_COFF_RELOCS */ | |
277 | ||
278 | static void | |
279 | coff_swap_filehdr_in (abfd, src, dst) | |
dc810e39 AM |
280 | bfd *abfd; |
281 | PTR src; | |
282 | PTR dst; | |
252b5132 RH |
283 | { |
284 | FILHDR *filehdr_src = (FILHDR *) src; | |
285 | struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst; | |
beb1bf64 | 286 | |
252b5132 RH |
287 | #ifdef COFF_ADJUST_FILEHDR_IN_PRE |
288 | COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst); | |
289 | #endif | |
dc810e39 AM |
290 | filehdr_dst->f_magic = H_GET_16 (abfd, filehdr_src->f_magic); |
291 | filehdr_dst->f_nscns = H_GET_16 (abfd, filehdr_src->f_nscns); | |
292 | filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat); | |
293 | filehdr_dst->f_symptr = GET_FILEHDR_SYMPTR (abfd, filehdr_src->f_symptr); | |
294 | filehdr_dst->f_nsyms = H_GET_32 (abfd, filehdr_src->f_nsyms); | |
295 | filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src->f_opthdr); | |
296 | filehdr_dst->f_flags = H_GET_16 (abfd, filehdr_src->f_flags); | |
252b5132 | 297 | #ifdef TIC80_TARGET_ID |
dc810e39 | 298 | filehdr_dst->f_target_id = H_GET_16 (abfd, filehdr_src->f_target_id); |
252b5132 RH |
299 | #endif |
300 | ||
301 | #ifdef COFF_ADJUST_FILEHDR_IN_POST | |
302 | COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst); | |
303 | #endif | |
304 | } | |
305 | ||
306 | static unsigned int | |
307 | coff_swap_filehdr_out (abfd, in, out) | |
dc810e39 AM |
308 | bfd *abfd; |
309 | PTR in; | |
310 | PTR out; | |
252b5132 | 311 | { |
dc810e39 AM |
312 | struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in; |
313 | FILHDR *filehdr_out = (FILHDR *) out; | |
252b5132 RH |
314 | |
315 | #ifdef COFF_ADJUST_FILEHDR_OUT_PRE | |
316 | COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out); | |
317 | #endif | |
dc810e39 AM |
318 | H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic); |
319 | H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns); | |
320 | H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->f_timdat); | |
321 | PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr); | |
322 | H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms); | |
323 | H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr); | |
324 | H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags); | |
252b5132 | 325 | #ifdef TIC80_TARGET_ID |
dc810e39 | 326 | H_PUT_16 (abfd, filehdr_in->f_target_id, filehdr_out->f_target_id); |
252b5132 RH |
327 | #endif |
328 | ||
329 | #ifdef COFF_ADJUST_FILEHDR_OUT_POST | |
330 | COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out); | |
331 | #endif | |
6b3b007b | 332 | return bfd_coff_filhsz (abfd); |
252b5132 RH |
333 | } |
334 | ||
252b5132 RH |
335 | #ifndef NO_COFF_SYMBOLS |
336 | ||
337 | static void | |
338 | coff_swap_sym_in (abfd, ext1, in1) | |
dc810e39 | 339 | bfd *abfd; |
252b5132 RH |
340 | PTR ext1; |
341 | PTR in1; | |
342 | { | |
dc810e39 AM |
343 | SYMENT *ext = (SYMENT *) ext1; |
344 | struct internal_syment *in = (struct internal_syment *) in1; | |
345 | ||
346 | if (ext->e.e_name[0] == 0) | |
347 | { | |
348 | in->_n._n_n._n_zeroes = 0; | |
349 | in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset); | |
350 | } | |
351 | else | |
352 | { | |
252b5132 | 353 | #if SYMNMLEN != E_SYMNMLEN |
dc810e39 | 354 | -> Error, we need to cope with truncating or extending SYMNMLEN!; |
252b5132 | 355 | #else |
dc810e39 AM |
356 | memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN); |
357 | #endif | |
358 | } | |
359 | in->n_value = H_GET_32 (abfd, ext->e_value); | |
360 | in->n_scnum = H_GET_16 (abfd, ext->e_scnum); | |
361 | if (sizeof (ext->e_type) == 2) | |
362 | { | |
363 | in->n_type = H_GET_16 (abfd, ext->e_type); | |
364 | } | |
365 | else | |
366 | { | |
367 | in->n_type = H_GET_32 (abfd, ext->e_type); | |
368 | } | |
369 | in->n_sclass = H_GET_8 (abfd, ext->e_sclass); | |
370 | in->n_numaux = H_GET_8 (abfd, ext->e_numaux); | |
6c784c9a TW |
371 | #ifdef COFF_ADJUST_SYM_IN_POST |
372 | COFF_ADJUST_SYM_IN_POST (abfd, ext1, in1); | |
373 | #endif | |
252b5132 RH |
374 | } |
375 | ||
376 | static unsigned int | |
377 | coff_swap_sym_out (abfd, inp, extp) | |
dc810e39 AM |
378 | bfd *abfd; |
379 | PTR inp; | |
380 | PTR extp; | |
252b5132 | 381 | { |
dc810e39 AM |
382 | struct internal_syment *in = (struct internal_syment *) inp; |
383 | SYMENT *ext =(SYMENT *) extp; | |
384 | if(in->_n._n_name[0] == 0) | |
385 | { | |
386 | H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); | |
387 | H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); | |
388 | } | |
389 | else | |
390 | { | |
252b5132 | 391 | #if SYMNMLEN != E_SYMNMLEN |
dc810e39 | 392 | -> Error, we need to cope with truncating or extending SYMNMLEN!; |
252b5132 | 393 | #else |
dc810e39 | 394 | memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN); |
252b5132 | 395 | #endif |
dc810e39 AM |
396 | } |
397 | H_PUT_32 (abfd, in->n_value, ext->e_value); | |
398 | H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); | |
e60b52c6 | 399 | if (sizeof (ext->e_type) == 2) |
dc810e39 AM |
400 | { |
401 | H_PUT_16 (abfd, in->n_type, ext->e_type); | |
402 | } | |
252b5132 | 403 | else |
dc810e39 AM |
404 | { |
405 | H_PUT_32 (abfd, in->n_type, ext->e_type); | |
406 | } | |
407 | H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); | |
408 | H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); | |
6c784c9a TW |
409 | #ifdef COFF_ADJUST_SYM_OUT_POST |
410 | COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp); | |
411 | #endif | |
252b5132 RH |
412 | return SYMESZ; |
413 | } | |
414 | ||
415 | static void | |
416 | coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1) | |
dc810e39 AM |
417 | bfd *abfd; |
418 | PTR ext1; | |
419 | int type; | |
420 | int class; | |
421 | int indx; | |
422 | int numaux; | |
423 | PTR in1; | |
252b5132 | 424 | { |
dc810e39 AM |
425 | AUXENT *ext = (AUXENT *) ext1; |
426 | union internal_auxent *in = (union internal_auxent *) in1; | |
252b5132 RH |
427 | |
428 | #ifdef COFF_ADJUST_AUX_IN_PRE | |
429 | COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1); | |
430 | #endif | |
dc810e39 AM |
431 | switch (class) |
432 | { | |
252b5132 | 433 | case C_FILE: |
dc810e39 AM |
434 | if (ext->x_file.x_fname[0] == 0) |
435 | { | |
252b5132 | 436 | in->x_file.x_n.x_zeroes = 0; |
dc810e39 AM |
437 | in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset); |
438 | } | |
439 | else | |
440 | { | |
252b5132 | 441 | #if FILNMLEN != E_FILNMLEN |
dc810e39 | 442 | -> Error, we need to cope with truncating or extending FILNMLEN!; |
252b5132 | 443 | #else |
dc810e39 AM |
444 | if (numaux > 1) |
445 | { | |
446 | if (indx == 0) | |
447 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, | |
448 | numaux * sizeof (AUXENT)); | |
449 | } | |
450 | else | |
451 | { | |
452 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); | |
453 | } | |
454 | #endif | |
455 | } | |
252b5132 RH |
456 | goto end; |
457 | ||
252b5132 RH |
458 | case C_STAT: |
459 | #ifdef C_LEAFSTAT | |
460 | case C_LEAFSTAT: | |
461 | #endif | |
462 | case C_HIDDEN: | |
dc810e39 AM |
463 | if (type == T_NULL) |
464 | { | |
465 | in->x_scn.x_scnlen = GET_SCN_SCNLEN (abfd, ext); | |
466 | in->x_scn.x_nreloc = GET_SCN_NRELOC (abfd, ext); | |
467 | in->x_scn.x_nlinno = GET_SCN_NLINNO (abfd, ext); | |
252b5132 RH |
468 | |
469 | /* PE defines some extra fields; we zero them out for | |
470 | safety. */ | |
471 | in->x_scn.x_checksum = 0; | |
472 | in->x_scn.x_associated = 0; | |
473 | in->x_scn.x_comdat = 0; | |
474 | ||
475 | goto end; | |
476 | } | |
477 | break; | |
478 | } | |
479 | ||
dc810e39 | 480 | in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx); |
252b5132 | 481 | #ifndef NO_TVNDX |
dc810e39 | 482 | in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx); |
252b5132 RH |
483 | #endif |
484 | ||
485 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
486 | { | |
487 | in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext); | |
488 | in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext); | |
489 | } | |
490 | else | |
491 | { | |
492 | #if DIMNUM != E_DIMNUM | |
dc810e39 | 493 | #error we need to cope with truncating or extending DIMNUM |
252b5132 RH |
494 | #endif |
495 | in->x_sym.x_fcnary.x_ary.x_dimen[0] = | |
dc810e39 | 496 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]); |
252b5132 | 497 | in->x_sym.x_fcnary.x_ary.x_dimen[1] = |
dc810e39 | 498 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]); |
252b5132 | 499 | in->x_sym.x_fcnary.x_ary.x_dimen[2] = |
dc810e39 | 500 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]); |
252b5132 | 501 | in->x_sym.x_fcnary.x_ary.x_dimen[3] = |
dc810e39 | 502 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); |
252b5132 RH |
503 | } |
504 | ||
dc810e39 AM |
505 | if (ISFCN(type)) |
506 | { | |
507 | in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); | |
508 | } | |
509 | else | |
510 | { | |
511 | in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO (abfd, ext); | |
512 | in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE (abfd, ext); | |
513 | } | |
252b5132 | 514 | |
dc810e39 | 515 | end: ; |
252b5132 RH |
516 | |
517 | #ifdef COFF_ADJUST_AUX_IN_POST | |
518 | COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, class, indx, numaux, in1); | |
519 | #endif | |
520 | } | |
521 | ||
522 | static unsigned int | |
523 | coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp) | |
dc810e39 AM |
524 | bfd *abfd; |
525 | PTR inp; | |
526 | int type; | |
527 | int class; | |
528 | int indx ATTRIBUTE_UNUSED; | |
529 | int numaux ATTRIBUTE_UNUSED; | |
530 | PTR extp; | |
252b5132 | 531 | { |
dc810e39 AM |
532 | union internal_auxent *in = (union internal_auxent *) inp; |
533 | AUXENT *ext = (AUXENT *) extp; | |
252b5132 RH |
534 | |
535 | #ifdef COFF_ADJUST_AUX_OUT_PRE | |
536 | COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp); | |
537 | #endif | |
538 | memset((PTR)ext, 0, AUXESZ); | |
dc810e39 AM |
539 | switch (class) |
540 | { | |
541 | case C_FILE: | |
542 | if (in->x_file.x_fname[0] == 0) | |
543 | { | |
544 | H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes); | |
545 | H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset); | |
546 | } | |
547 | else | |
548 | { | |
252b5132 | 549 | #if FILNMLEN != E_FILNMLEN |
dc810e39 | 550 | -> Error, we need to cope with truncating or extending FILNMLEN!; |
252b5132 | 551 | #else |
dc810e39 | 552 | memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN); |
252b5132 | 553 | #endif |
dc810e39 AM |
554 | } |
555 | goto end; | |
252b5132 | 556 | |
dc810e39 | 557 | case C_STAT: |
252b5132 | 558 | #ifdef C_LEAFSTAT |
dc810e39 | 559 | case C_LEAFSTAT: |
252b5132 | 560 | #endif |
dc810e39 AM |
561 | case C_HIDDEN: |
562 | if (type == T_NULL) | |
563 | { | |
564 | PUT_SCN_SCNLEN (abfd, in->x_scn.x_scnlen, ext); | |
565 | PUT_SCN_NRELOC (abfd, in->x_scn.x_nreloc, ext); | |
566 | PUT_SCN_NLINNO (abfd, in->x_scn.x_nlinno, ext); | |
567 | goto end; | |
568 | } | |
569 | break; | |
252b5132 | 570 | } |
252b5132 | 571 | |
dc810e39 | 572 | H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx); |
252b5132 | 573 | #ifndef NO_TVNDX |
dc810e39 | 574 | H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx); |
252b5132 RH |
575 | #endif |
576 | ||
577 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
578 | { | |
dc810e39 AM |
579 | PUT_FCN_LNNOPTR (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext); |
580 | PUT_FCN_ENDNDX (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext); | |
252b5132 RH |
581 | } |
582 | else | |
583 | { | |
584 | #if DIMNUM != E_DIMNUM | |
dc810e39 AM |
585 | #error we need to cope with truncating or extending DIMNUM |
586 | #endif | |
587 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], | |
588 | ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | |
589 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], | |
590 | ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | |
591 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], | |
592 | ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | |
593 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], | |
594 | ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | |
252b5132 RH |
595 | } |
596 | ||
597 | if (ISFCN (type)) | |
dc810e39 | 598 | H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize); |
252b5132 RH |
599 | else |
600 | { | |
601 | PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext); | |
602 | PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext); | |
603 | } | |
604 | ||
dc810e39 | 605 | end: |
252b5132 RH |
606 | #ifdef COFF_ADJUST_AUX_OUT_POST |
607 | COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, class, indx, numaux, extp); | |
608 | #endif | |
609 | return AUXESZ; | |
610 | } | |
611 | ||
612 | #endif /* NO_COFF_SYMBOLS */ | |
613 | ||
614 | #ifndef NO_COFF_LINENOS | |
615 | ||
616 | static void | |
617 | coff_swap_lineno_in (abfd, ext1, in1) | |
dc810e39 | 618 | bfd *abfd; |
252b5132 RH |
619 | PTR ext1; |
620 | PTR in1; | |
621 | { | |
dc810e39 AM |
622 | LINENO *ext = (LINENO *) ext1; |
623 | struct internal_lineno *in = (struct internal_lineno *) in1; | |
252b5132 | 624 | |
dc810e39 AM |
625 | in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx); |
626 | in->l_lnno = GET_LINENO_LNNO (abfd, ext); | |
252b5132 RH |
627 | } |
628 | ||
629 | static unsigned int | |
630 | coff_swap_lineno_out (abfd, inp, outp) | |
dc810e39 AM |
631 | bfd *abfd; |
632 | PTR inp; | |
633 | PTR outp; | |
252b5132 | 634 | { |
dc810e39 AM |
635 | struct internal_lineno *in = (struct internal_lineno *) inp; |
636 | struct external_lineno *ext = (struct external_lineno *) outp; | |
637 | H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx); | |
252b5132 RH |
638 | |
639 | PUT_LINENO_LNNO (abfd, in->l_lnno, ext); | |
640 | return LINESZ; | |
641 | } | |
642 | ||
643 | #endif /* NO_COFF_LINENOS */ | |
644 | ||
645 | static void | |
646 | coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1) | |
dc810e39 | 647 | bfd *abfd; |
252b5132 RH |
648 | PTR aouthdr_ext1; |
649 | PTR aouthdr_int1; | |
650 | { | |
dc810e39 AM |
651 | AOUTHDR *aouthdr_ext; |
652 | struct internal_aouthdr *aouthdr_int; | |
653 | ||
654 | aouthdr_ext = (AOUTHDR *) aouthdr_ext1; | |
655 | aouthdr_int = (struct internal_aouthdr *) aouthdr_int1; | |
656 | aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic); | |
657 | aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp); | |
658 | aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize); | |
659 | aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize); | |
660 | aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize); | |
661 | aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry); | |
252b5132 | 662 | aouthdr_int->text_start = |
dc810e39 | 663 | GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start); |
252b5132 | 664 | aouthdr_int->data_start = |
dc810e39 | 665 | GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start); |
252b5132 RH |
666 | |
667 | #ifdef I960 | |
dc810e39 | 668 | aouthdr_int->tagentries = H_GET_32 (abfd, aouthdr_ext->tagentries); |
252b5132 RH |
669 | #endif |
670 | ||
671 | #ifdef APOLLO_M68 | |
dc810e39 AM |
672 | H_PUT_32 (abfd, aouthdr_int->o_inlib, aouthdr_ext->o_inlib); |
673 | H_PUT_32 (abfd, aouthdr_int->o_sri, aouthdr_ext->o_sri); | |
674 | H_PUT_32 (abfd, aouthdr_int->vid[0], aouthdr_ext->vid); | |
675 | H_PUT_32 (abfd, aouthdr_int->vid[1], aouthdr_ext->vid + 4); | |
252b5132 RH |
676 | #endif |
677 | ||
252b5132 | 678 | #ifdef RS6000COFF_C |
7f6d05e8 | 679 | #ifdef XCOFF64 |
dc810e39 | 680 | aouthdr_int->o_toc = H_GET_64 (abfd, aouthdr_ext->o_toc); |
7f6d05e8 | 681 | #else |
dc810e39 AM |
682 | aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc); |
683 | #endif | |
684 | aouthdr_int->o_snentry = H_GET_16 (abfd, aouthdr_ext->o_snentry); | |
685 | aouthdr_int->o_sntext = H_GET_16 (abfd, aouthdr_ext->o_sntext); | |
686 | aouthdr_int->o_sndata = H_GET_16 (abfd, aouthdr_ext->o_sndata); | |
687 | aouthdr_int->o_sntoc = H_GET_16 (abfd, aouthdr_ext->o_sntoc); | |
688 | aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader); | |
689 | aouthdr_int->o_snbss = H_GET_16 (abfd, aouthdr_ext->o_snbss); | |
690 | aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext); | |
691 | aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata); | |
692 | aouthdr_int->o_modtype = H_GET_16 (abfd, aouthdr_ext->o_modtype); | |
693 | aouthdr_int->o_cputype = H_GET_16 (abfd, aouthdr_ext->o_cputype); | |
7f6d05e8 | 694 | #ifdef XCOFF64 |
dc810e39 AM |
695 | aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack); |
696 | aouthdr_int->o_maxdata = H_GET_64 (abfd, aouthdr_ext->o_maxdata); | |
7f6d05e8 | 697 | #else |
dc810e39 AM |
698 | aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack); |
699 | aouthdr_int->o_maxdata = H_GET_32 (abfd, aouthdr_ext->o_maxdata); | |
252b5132 | 700 | #endif |
7f6d05e8 | 701 | #endif |
252b5132 RH |
702 | |
703 | #ifdef MIPSECOFF | |
dc810e39 AM |
704 | aouthdr_int->bss_start = H_GET_32 (abfd, aouthdr_ext->bss_start); |
705 | aouthdr_int->gp_value = H_GET_32 (abfd, aouthdr_ext->gp_value); | |
706 | aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); | |
707 | aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]); | |
708 | aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]); | |
709 | aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]); | |
710 | aouthdr_int->cprmask[3] = H_GET_32 (abfd, aouthdr_ext->cprmask[3]); | |
252b5132 RH |
711 | #endif |
712 | ||
713 | #ifdef ALPHAECOFF | |
dc810e39 AM |
714 | aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start); |
715 | aouthdr_int->gp_value = H_GET_64 (abfd, aouthdr_ext->gp_value); | |
716 | aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); | |
717 | aouthdr_int->fprmask = H_GET_32 (abfd, aouthdr_ext->fprmask); | |
252b5132 RH |
718 | #endif |
719 | } | |
720 | ||
721 | static unsigned int | |
722 | coff_swap_aouthdr_out (abfd, in, out) | |
dc810e39 AM |
723 | bfd *abfd; |
724 | PTR in; | |
725 | PTR out; | |
252b5132 | 726 | { |
dc810e39 AM |
727 | struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in; |
728 | AOUTHDR *aouthdr_out = (AOUTHDR *) out; | |
729 | ||
730 | H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->magic); | |
731 | H_PUT_16 (abfd, aouthdr_in->vstamp, aouthdr_out->vstamp); | |
732 | PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, aouthdr_out->tsize); | |
733 | PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, aouthdr_out->dsize); | |
734 | PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, aouthdr_out->bsize); | |
735 | PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, aouthdr_out->entry); | |
252b5132 | 736 | PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start, |
dc810e39 | 737 | aouthdr_out->text_start); |
252b5132 | 738 | PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start, |
dc810e39 | 739 | aouthdr_out->data_start); |
252b5132 RH |
740 | |
741 | #ifdef I960 | |
dc810e39 | 742 | H_PUT_32 (abfd, aouthdr_in->tagentries, aouthdr_out->tagentries); |
252b5132 RH |
743 | #endif |
744 | ||
745 | #ifdef RS6000COFF_C | |
7f6d05e8 | 746 | #ifdef XCOFF64 |
dc810e39 | 747 | H_PUT_64 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); |
7f6d05e8 | 748 | #else |
dc810e39 AM |
749 | H_PUT_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); |
750 | #endif | |
751 | H_PUT_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry); | |
752 | H_PUT_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext); | |
753 | H_PUT_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata); | |
754 | H_PUT_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc); | |
755 | H_PUT_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader); | |
756 | H_PUT_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss); | |
757 | H_PUT_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext); | |
758 | H_PUT_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata); | |
759 | H_PUT_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype); | |
760 | H_PUT_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype); | |
7f6d05e8 | 761 | #ifdef XCOFF64 |
dc810e39 AM |
762 | H_PUT_64 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); |
763 | H_PUT_64 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); | |
7f6d05e8 | 764 | #else |
dc810e39 AM |
765 | H_PUT_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); |
766 | H_PUT_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); | |
7f6d05e8 | 767 | #endif |
252b5132 | 768 | memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2); |
7f6d05e8 CP |
769 | #ifdef XCOFF64 |
770 | memset (aouthdr_out->o_debugger, 0, sizeof aouthdr_out->o_debugger); | |
771 | memset (aouthdr_out->o_resv3, 0, sizeof aouthdr_out->o_resv3); | |
772 | #endif | |
252b5132 RH |
773 | #endif |
774 | ||
775 | #ifdef MIPSECOFF | |
dc810e39 AM |
776 | H_PUT_32 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); |
777 | H_PUT_32 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); | |
778 | H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); | |
779 | H_PUT_32 (abfd, aouthdr_in->cprmask[0], aouthdr_out->cprmask[0]); | |
780 | H_PUT_32 (abfd, aouthdr_in->cprmask[1], aouthdr_out->cprmask[1]); | |
781 | H_PUT_32 (abfd, aouthdr_in->cprmask[2], aouthdr_out->cprmask[2]); | |
782 | H_PUT_32 (abfd, aouthdr_in->cprmask[3], aouthdr_out->cprmask[3]); | |
252b5132 RH |
783 | #endif |
784 | ||
785 | #ifdef ALPHAECOFF | |
786 | /* FIXME: What does bldrev mean? */ | |
dc810e39 AM |
787 | H_PUT_16 (abfd, 2, aouthdr_out->bldrev); |
788 | H_PUT_16 (abfd, 0, aouthdr_out->padding); | |
789 | H_PUT_64 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); | |
790 | H_PUT_64 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); | |
791 | H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); | |
792 | H_PUT_32 (abfd, aouthdr_in->fprmask, aouthdr_out->fprmask); | |
252b5132 RH |
793 | #endif |
794 | ||
795 | return AOUTSZ; | |
796 | } | |
797 | ||
798 | static void | |
799 | coff_swap_scnhdr_in (abfd, ext, in) | |
dc810e39 AM |
800 | bfd *abfd; |
801 | PTR ext; | |
802 | PTR in; | |
252b5132 RH |
803 | { |
804 | SCNHDR *scnhdr_ext = (SCNHDR *) ext; | |
805 | struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; | |
806 | ||
807 | #ifdef COFF_ADJUST_SCNHDR_IN_PRE | |
808 | COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in); | |
809 | #endif | |
e60b52c6 | 810 | memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name)); |
dc810e39 AM |
811 | scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr); |
812 | scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr); | |
813 | scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size); | |
814 | ||
815 | scnhdr_int->s_scnptr = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr); | |
816 | scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr); | |
817 | scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr); | |
818 | scnhdr_int->s_flags = GET_SCNHDR_FLAGS (abfd, scnhdr_ext->s_flags); | |
819 | scnhdr_int->s_nreloc = GET_SCNHDR_NRELOC (abfd, scnhdr_ext->s_nreloc); | |
820 | scnhdr_int->s_nlnno = GET_SCNHDR_NLNNO (abfd, scnhdr_ext->s_nlnno); | |
252b5132 | 821 | #ifdef I960 |
dc810e39 | 822 | scnhdr_int->s_align = GET_SCNHDR_ALIGN (abfd, scnhdr_ext->s_align); |
252b5132 RH |
823 | #endif |
824 | #ifdef COFF_ADJUST_SCNHDR_IN_POST | |
825 | COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in); | |
826 | #endif | |
827 | } | |
828 | ||
829 | static unsigned int | |
830 | coff_swap_scnhdr_out (abfd, in, out) | |
dc810e39 AM |
831 | bfd *abfd; |
832 | PTR in; | |
833 | PTR out; | |
252b5132 | 834 | { |
dc810e39 AM |
835 | struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; |
836 | SCNHDR *scnhdr_ext = (SCNHDR *) out; | |
6b3b007b | 837 | unsigned int ret = bfd_coff_scnhsz (abfd); |
252b5132 RH |
838 | |
839 | #ifdef COFF_ADJUST_SCNHDR_OUT_PRE | |
840 | COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out); | |
841 | #endif | |
dc810e39 | 842 | memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); |
252b5132 | 843 | |
dc810e39 AM |
844 | PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr, scnhdr_ext->s_vaddr); |
845 | PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr, scnhdr_ext->s_paddr); | |
846 | PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size, scnhdr_ext->s_size); | |
847 | PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr, scnhdr_ext->s_scnptr); | |
848 | PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr, scnhdr_ext->s_relptr); | |
849 | PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr, scnhdr_ext->s_lnnoptr); | |
850 | PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags); | |
252b5132 | 851 | #if defined(M88) |
dc810e39 AM |
852 | H_PUT_32 (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno); |
853 | H_PUT_32 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); | |
252b5132 | 854 | #else |
7f6d05e8 | 855 | if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO) |
dc810e39 | 856 | PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno); |
252b5132 RH |
857 | else |
858 | { | |
859 | char buf[sizeof (scnhdr_int->s_name) + 1]; | |
860 | ||
861 | memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); | |
862 | buf[sizeof (scnhdr_int->s_name)] = '\0'; | |
863 | (*_bfd_error_handler) | |
864 | (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), | |
865 | bfd_get_filename (abfd), | |
866 | buf, scnhdr_int->s_nlnno); | |
dc810e39 | 867 | PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno); |
252b5132 | 868 | } |
7f6d05e8 | 869 | if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC) |
dc810e39 | 870 | PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); |
252b5132 RH |
871 | else |
872 | { | |
873 | char buf[sizeof (scnhdr_int->s_name) + 1]; | |
874 | ||
875 | memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); | |
876 | buf[sizeof (scnhdr_int->s_name)] = '\0'; | |
877 | (*_bfd_error_handler) (_("%s: %s: reloc overflow: 0x%lx > 0xffff"), | |
878 | bfd_get_filename (abfd), | |
879 | buf, scnhdr_int->s_nreloc); | |
880 | bfd_set_error (bfd_error_file_truncated); | |
dc810e39 | 881 | PUT_SCNHDR_NRELOC (abfd, 0xffff, scnhdr_ext->s_nreloc); |
252b5132 RH |
882 | ret = 0; |
883 | } | |
884 | #endif | |
885 | ||
886 | #ifdef I960 | |
dc810e39 | 887 | PUT_SCNHDR_ALIGN (abfd, scnhdr_int->s_align, scnhdr_ext->s_align); |
252b5132 RH |
888 | #endif |
889 | #ifdef COFF_ADJUST_SCNHDR_OUT_POST | |
890 | COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out); | |
891 | #endif | |
892 | return ret; | |
893 | } |