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