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