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