133965Sjdp/* Generic COFF swapping routines, for BFD. 289857Sobrien Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 3218822Sdim 2001, 2002, 2005 460484Sobrien Free Software Foundation, Inc. 533965Sjdp Written by Cygnus Support. 633965Sjdp 7130561Sobrien This file is part of BFD, the Binary File Descriptor library. 833965Sjdp 9130561Sobrien This program is free software; you can redistribute it and/or modify 10130561Sobrien it under the terms of the GNU General Public License as published by 11130561Sobrien the Free Software Foundation; either version 2 of the License, or 12130561Sobrien (at your option) any later version. 1333965Sjdp 14130561Sobrien This program is distributed in the hope that it will be useful, 15130561Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 16130561Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17130561Sobrien GNU General Public License for more details. 1833965Sjdp 19130561Sobrien You should have received a copy of the GNU General Public License 20130561Sobrien along with this program; if not, write to the Free Software 21218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2233965Sjdp 2333965Sjdp/* This file contains routines used to swap COFF data. It is a header 2433965Sjdp file because the details of swapping depend on the details of the 2533965Sjdp structures used by each COFF implementation. This is included by 2633965Sjdp coffcode.h, as well as by the ECOFF backend. 2733965Sjdp 2833965Sjdp Any file which uses this must first include "coff/internal.h" and 2933965Sjdp "coff/CPU.h". The functions will then be correct for that CPU. */ 3033965Sjdp 3133965Sjdp#ifndef GET_FCN_LNNOPTR 3289857Sobrien#define GET_FCN_LNNOPTR(abfd, ext) \ 3389857Sobrien H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) 3433965Sjdp#endif 3533965Sjdp 3633965Sjdp#ifndef GET_FCN_ENDNDX 3789857Sobrien#define GET_FCN_ENDNDX(abfd, ext) \ 3889857Sobrien H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx) 3933965Sjdp#endif 4033965Sjdp 4133965Sjdp#ifndef PUT_FCN_LNNOPTR 4289857Sobrien#define PUT_FCN_LNNOPTR(abfd, in, ext) \ 4389857Sobrien H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) 4433965Sjdp#endif 4533965Sjdp#ifndef PUT_FCN_ENDNDX 4689857Sobrien#define PUT_FCN_ENDNDX(abfd, in, ext) \ 4789857Sobrien H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx) 4833965Sjdp#endif 4933965Sjdp#ifndef GET_LNSZ_LNNO 5089857Sobrien#define GET_LNSZ_LNNO(abfd, ext) \ 5189857Sobrien H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno) 5233965Sjdp#endif 5333965Sjdp#ifndef GET_LNSZ_SIZE 5489857Sobrien#define GET_LNSZ_SIZE(abfd, ext) \ 5589857Sobrien H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size) 5633965Sjdp#endif 5733965Sjdp#ifndef PUT_LNSZ_LNNO 5889857Sobrien#define PUT_LNSZ_LNNO(abfd, in, ext) \ 5989857Sobrien H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno) 6033965Sjdp#endif 6133965Sjdp#ifndef PUT_LNSZ_SIZE 6289857Sobrien#define PUT_LNSZ_SIZE(abfd, in, ext) \ 6389857Sobrien H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_size) 6433965Sjdp#endif 6533965Sjdp#ifndef GET_SCN_SCNLEN 6689857Sobrien#define GET_SCN_SCNLEN(abfd, ext) \ 6789857Sobrien H_GET_32 (abfd, ext->x_scn.x_scnlen) 6833965Sjdp#endif 6933965Sjdp#ifndef GET_SCN_NRELOC 7089857Sobrien#define GET_SCN_NRELOC(abfd, ext) \ 7189857Sobrien H_GET_16 (abfd, ext->x_scn.x_nreloc) 7233965Sjdp#endif 7333965Sjdp#ifndef GET_SCN_NLINNO 7489857Sobrien#define GET_SCN_NLINNO(abfd, ext) \ 7589857Sobrien H_GET_16 (abfd, ext->x_scn.x_nlinno) 7633965Sjdp#endif 7733965Sjdp#ifndef PUT_SCN_SCNLEN 7889857Sobrien#define PUT_SCN_SCNLEN(abfd, in, ext) \ 7989857Sobrien H_PUT_32 (abfd, in, ext->x_scn.x_scnlen) 8033965Sjdp#endif 8133965Sjdp#ifndef PUT_SCN_NRELOC 8289857Sobrien#define PUT_SCN_NRELOC(abfd, in, ext) \ 8389857Sobrien H_PUT_16 (abfd, in, ext->x_scn.x_nreloc) 8433965Sjdp#endif 8533965Sjdp#ifndef PUT_SCN_NLINNO 8689857Sobrien#define PUT_SCN_NLINNO(abfd, in, ext) \ 8789857Sobrien H_PUT_16 (abfd, in, ext->x_scn.x_nlinno) 8833965Sjdp#endif 8933965Sjdp#ifndef GET_LINENO_LNNO 9089857Sobrien#define GET_LINENO_LNNO(abfd, ext) \ 9189857Sobrien H_GET_16 (abfd, ext->l_lnno); 9233965Sjdp#endif 9333965Sjdp#ifndef PUT_LINENO_LNNO 9489857Sobrien#define PUT_LINENO_LNNO(abfd, val, ext) \ 9589857Sobrien H_PUT_16 (abfd, val, ext->l_lnno); 9633965Sjdp#endif 9733965Sjdp 9833965Sjdp/* The f_symptr field in the filehdr is sometimes 64 bits. */ 9933965Sjdp#ifndef GET_FILEHDR_SYMPTR 10089857Sobrien#define GET_FILEHDR_SYMPTR H_GET_32 10133965Sjdp#endif 10233965Sjdp#ifndef PUT_FILEHDR_SYMPTR 10389857Sobrien#define PUT_FILEHDR_SYMPTR H_PUT_32 10433965Sjdp#endif 10533965Sjdp 10633965Sjdp/* Some fields in the aouthdr are sometimes 64 bits. */ 10733965Sjdp#ifndef GET_AOUTHDR_TSIZE 10889857Sobrien#define GET_AOUTHDR_TSIZE H_GET_32 10933965Sjdp#endif 11033965Sjdp#ifndef PUT_AOUTHDR_TSIZE 11189857Sobrien#define PUT_AOUTHDR_TSIZE H_PUT_32 11233965Sjdp#endif 11333965Sjdp#ifndef GET_AOUTHDR_DSIZE 11489857Sobrien#define GET_AOUTHDR_DSIZE H_GET_32 11533965Sjdp#endif 11633965Sjdp#ifndef PUT_AOUTHDR_DSIZE 11789857Sobrien#define PUT_AOUTHDR_DSIZE H_PUT_32 11833965Sjdp#endif 11933965Sjdp#ifndef GET_AOUTHDR_BSIZE 12089857Sobrien#define GET_AOUTHDR_BSIZE H_GET_32 12133965Sjdp#endif 12233965Sjdp#ifndef PUT_AOUTHDR_BSIZE 12389857Sobrien#define PUT_AOUTHDR_BSIZE H_PUT_32 12433965Sjdp#endif 12533965Sjdp#ifndef GET_AOUTHDR_ENTRY 12689857Sobrien#define GET_AOUTHDR_ENTRY H_GET_32 12733965Sjdp#endif 12833965Sjdp#ifndef PUT_AOUTHDR_ENTRY 12989857Sobrien#define PUT_AOUTHDR_ENTRY H_PUT_32 13033965Sjdp#endif 13133965Sjdp#ifndef GET_AOUTHDR_TEXT_START 13289857Sobrien#define GET_AOUTHDR_TEXT_START H_GET_32 13333965Sjdp#endif 13433965Sjdp#ifndef PUT_AOUTHDR_TEXT_START 13589857Sobrien#define PUT_AOUTHDR_TEXT_START H_PUT_32 13633965Sjdp#endif 13733965Sjdp#ifndef GET_AOUTHDR_DATA_START 13889857Sobrien#define GET_AOUTHDR_DATA_START H_GET_32 13933965Sjdp#endif 14033965Sjdp#ifndef PUT_AOUTHDR_DATA_START 14189857Sobrien#define PUT_AOUTHDR_DATA_START H_PUT_32 14233965Sjdp#endif 14333965Sjdp 14433965Sjdp/* Some fields in the scnhdr are sometimes 64 bits. */ 14533965Sjdp#ifndef GET_SCNHDR_PADDR 14689857Sobrien#define GET_SCNHDR_PADDR H_GET_32 14733965Sjdp#endif 14833965Sjdp#ifndef PUT_SCNHDR_PADDR 14989857Sobrien#define PUT_SCNHDR_PADDR H_PUT_32 15033965Sjdp#endif 15133965Sjdp#ifndef GET_SCNHDR_VADDR 15289857Sobrien#define GET_SCNHDR_VADDR H_GET_32 15333965Sjdp#endif 15433965Sjdp#ifndef PUT_SCNHDR_VADDR 15589857Sobrien#define PUT_SCNHDR_VADDR H_PUT_32 15633965Sjdp#endif 15733965Sjdp#ifndef GET_SCNHDR_SIZE 15889857Sobrien#define GET_SCNHDR_SIZE H_GET_32 15933965Sjdp#endif 16033965Sjdp#ifndef PUT_SCNHDR_SIZE 16189857Sobrien#define PUT_SCNHDR_SIZE H_PUT_32 16233965Sjdp#endif 16333965Sjdp#ifndef GET_SCNHDR_SCNPTR 16489857Sobrien#define GET_SCNHDR_SCNPTR H_GET_32 16533965Sjdp#endif 16633965Sjdp#ifndef PUT_SCNHDR_SCNPTR 16789857Sobrien#define PUT_SCNHDR_SCNPTR H_PUT_32 16833965Sjdp#endif 16933965Sjdp#ifndef GET_SCNHDR_RELPTR 17089857Sobrien#define GET_SCNHDR_RELPTR H_GET_32 17133965Sjdp#endif 17233965Sjdp#ifndef PUT_SCNHDR_RELPTR 17389857Sobrien#define PUT_SCNHDR_RELPTR H_PUT_32 17433965Sjdp#endif 17533965Sjdp#ifndef GET_SCNHDR_LNNOPTR 17689857Sobrien#define GET_SCNHDR_LNNOPTR H_GET_32 17733965Sjdp#endif 17833965Sjdp#ifndef PUT_SCNHDR_LNNOPTR 17989857Sobrien#define PUT_SCNHDR_LNNOPTR H_PUT_32 18033965Sjdp#endif 18138889Sjdp#ifndef GET_SCNHDR_NRELOC 18289857Sobrien#define GET_SCNHDR_NRELOC H_GET_16 18338889Sjdp#endif 18477298Sobrien#ifndef MAX_SCNHDR_NRELOC 18577298Sobrien#define MAX_SCNHDR_NRELOC 0xffff 18677298Sobrien#endif 18738889Sjdp#ifndef PUT_SCNHDR_NRELOC 18889857Sobrien#define PUT_SCNHDR_NRELOC H_PUT_16 18938889Sjdp#endif 19038889Sjdp#ifndef GET_SCNHDR_NLNNO 19189857Sobrien#define GET_SCNHDR_NLNNO H_GET_16 19238889Sjdp#endif 19377298Sobrien#ifndef MAX_SCNHDR_NLNNO 19477298Sobrien#define MAX_SCNHDR_NLNNO 0xffff 19577298Sobrien#endif 19638889Sjdp#ifndef PUT_SCNHDR_NLNNO 19789857Sobrien#define PUT_SCNHDR_NLNNO H_PUT_16 19838889Sjdp#endif 19938889Sjdp#ifndef GET_SCNHDR_FLAGS 20089857Sobrien#define GET_SCNHDR_FLAGS H_GET_32 20138889Sjdp#endif 20238889Sjdp#ifndef PUT_SCNHDR_FLAGS 20389857Sobrien#define PUT_SCNHDR_FLAGS H_PUT_32 20438889Sjdp#endif 20533965Sjdp 20677298Sobrien#ifndef GET_RELOC_VADDR 20789857Sobrien#define GET_RELOC_VADDR H_GET_32 20877298Sobrien#endif 20977298Sobrien#ifndef PUT_RELOC_VADDR 21089857Sobrien#define PUT_RELOC_VADDR H_PUT_32 21177298Sobrien#endif 21238889Sjdp 21333965Sjdp#ifndef NO_COFF_RELOCS 21433965Sjdp 21533965Sjdpstatic void 216218822Sdimcoff_swap_reloc_in (bfd * abfd, void * src, void * dst) 21733965Sjdp{ 21833965Sjdp RELOC *reloc_src = (RELOC *) src; 21933965Sjdp struct internal_reloc *reloc_dst = (struct internal_reloc *) dst; 22033965Sjdp 221218822Sdim reloc_dst->r_vaddr = GET_RELOC_VADDR (abfd, reloc_src->r_vaddr); 22289857Sobrien reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx); 223218822Sdim reloc_dst->r_type = H_GET_16 (abfd, reloc_src->r_type); 22433965Sjdp 22533965Sjdp#ifdef SWAP_IN_RELOC_OFFSET 22689857Sobrien reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset); 22733965Sjdp#endif 22833965Sjdp} 22933965Sjdp 23033965Sjdpstatic unsigned int 231218822Sdimcoff_swap_reloc_out (bfd * abfd, void * src, void * dst) 23233965Sjdp{ 23389857Sobrien struct internal_reloc *reloc_src = (struct internal_reloc *) src; 23489857Sobrien struct external_reloc *reloc_dst = (struct external_reloc *) dst; 235218822Sdim 23689857Sobrien PUT_RELOC_VADDR (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr); 23789857Sobrien H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx); 23889857Sobrien H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type); 23933965Sjdp 24033965Sjdp#ifdef SWAP_OUT_RELOC_OFFSET 24189857Sobrien SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset); 24233965Sjdp#endif 24333965Sjdp#ifdef SWAP_OUT_RELOC_EXTRA 24489857Sobrien SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst); 24533965Sjdp#endif 24633965Sjdp 24760484Sobrien return bfd_coff_relsz (abfd); 24833965Sjdp} 24933965Sjdp 25033965Sjdp#endif /* NO_COFF_RELOCS */ 25133965Sjdp 25233965Sjdpstatic void 253218822Sdimcoff_swap_filehdr_in (bfd * abfd, void * src, void * dst) 25433965Sjdp{ 25533965Sjdp FILHDR *filehdr_src = (FILHDR *) src; 25633965Sjdp struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst; 25778828Sobrien 25838889Sjdp#ifdef COFF_ADJUST_FILEHDR_IN_PRE 25938889Sjdp COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst); 26038889Sjdp#endif 261218822Sdim filehdr_dst->f_magic = H_GET_16 (abfd, filehdr_src->f_magic); 262218822Sdim filehdr_dst->f_nscns = H_GET_16 (abfd, filehdr_src->f_nscns); 26389857Sobrien filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat); 26489857Sobrien filehdr_dst->f_symptr = GET_FILEHDR_SYMPTR (abfd, filehdr_src->f_symptr); 265218822Sdim filehdr_dst->f_nsyms = H_GET_32 (abfd, filehdr_src->f_nsyms); 26689857Sobrien filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src->f_opthdr); 267218822Sdim filehdr_dst->f_flags = H_GET_16 (abfd, filehdr_src->f_flags); 26860484Sobrien#ifdef TIC80_TARGET_ID 26989857Sobrien filehdr_dst->f_target_id = H_GET_16 (abfd, filehdr_src->f_target_id); 27060484Sobrien#endif 27138889Sjdp 27238889Sjdp#ifdef COFF_ADJUST_FILEHDR_IN_POST 27338889Sjdp COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst); 27438889Sjdp#endif 27533965Sjdp} 27633965Sjdp 27733965Sjdpstatic unsigned int 278218822Sdimcoff_swap_filehdr_out (bfd *abfd, void * in, void * out) 27933965Sjdp{ 28089857Sobrien struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in; 28189857Sobrien FILHDR *filehdr_out = (FILHDR *) out; 28233965Sjdp 28338889Sjdp#ifdef COFF_ADJUST_FILEHDR_OUT_PRE 28438889Sjdp COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out); 28538889Sjdp#endif 28689857Sobrien H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic); 28789857Sobrien H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns); 28889857Sobrien H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->f_timdat); 28989857Sobrien PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr); 29089857Sobrien H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms); 29189857Sobrien H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr); 29289857Sobrien H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags); 29360484Sobrien#ifdef TIC80_TARGET_ID 29489857Sobrien H_PUT_16 (abfd, filehdr_in->f_target_id, filehdr_out->f_target_id); 29560484Sobrien#endif 29633965Sjdp 29738889Sjdp#ifdef COFF_ADJUST_FILEHDR_OUT_POST 29838889Sjdp COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out); 29938889Sjdp#endif 30060484Sobrien return bfd_coff_filhsz (abfd); 30133965Sjdp} 30233965Sjdp 30333965Sjdp#ifndef NO_COFF_SYMBOLS 30433965Sjdp 30533965Sjdpstatic void 306218822Sdimcoff_swap_sym_in (bfd * abfd, void * ext1, void * in1) 30733965Sjdp{ 30889857Sobrien SYMENT *ext = (SYMENT *) ext1; 30989857Sobrien struct internal_syment *in = (struct internal_syment *) in1; 31033965Sjdp 31189857Sobrien if (ext->e.e_name[0] == 0) 31289857Sobrien { 31389857Sobrien in->_n._n_n._n_zeroes = 0; 31489857Sobrien in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset); 31589857Sobrien } 31689857Sobrien else 31789857Sobrien { 31833965Sjdp#if SYMNMLEN != E_SYMNMLEN 319218822Sdim#error we need to cope with truncating or extending SYMNMLEN 32033965Sjdp#else 32189857Sobrien memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN); 32233965Sjdp#endif 32389857Sobrien } 324218822Sdim 32589857Sobrien in->n_value = H_GET_32 (abfd, ext->e_value); 32689857Sobrien in->n_scnum = H_GET_16 (abfd, ext->e_scnum); 32789857Sobrien if (sizeof (ext->e_type) == 2) 328218822Sdim in->n_type = H_GET_16 (abfd, ext->e_type); 32989857Sobrien else 330218822Sdim in->n_type = H_GET_32 (abfd, ext->e_type); 33189857Sobrien in->n_sclass = H_GET_8 (abfd, ext->e_sclass); 33289857Sobrien in->n_numaux = H_GET_8 (abfd, ext->e_numaux); 33360484Sobrien#ifdef COFF_ADJUST_SYM_IN_POST 33460484Sobrien COFF_ADJUST_SYM_IN_POST (abfd, ext1, in1); 33560484Sobrien#endif 33633965Sjdp} 33733965Sjdp 33833965Sjdpstatic unsigned int 339218822Sdimcoff_swap_sym_out (bfd * abfd, void * inp, void * extp) 34033965Sjdp{ 34189857Sobrien struct internal_syment *in = (struct internal_syment *) inp; 34289857Sobrien SYMENT *ext =(SYMENT *) extp; 343130561Sobrien 344130561Sobrien#ifdef COFF_ADJUST_SYM_OUT_PRE 345130561Sobrien COFF_ADJUST_SYM_OUT_PRE (abfd, inp, extp); 346130561Sobrien#endif 347130561Sobrien 348130561Sobrien if (in->_n._n_name[0] == 0) 34989857Sobrien { 35089857Sobrien H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); 35189857Sobrien H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); 35289857Sobrien } 35389857Sobrien else 35489857Sobrien { 35533965Sjdp#if SYMNMLEN != E_SYMNMLEN 356218822Sdim#error we need to cope with truncating or extending SYMNMLEN 35733965Sjdp#else 358130561Sobrien memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN); 35933965Sjdp#endif 36089857Sobrien } 361130561Sobrien 36289857Sobrien H_PUT_32 (abfd, in->n_value, ext->e_value); 36389857Sobrien H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); 364130561Sobrien 36577298Sobrien if (sizeof (ext->e_type) == 2) 366218822Sdim H_PUT_16 (abfd, in->n_type, ext->e_type); 36733965Sjdp else 368218822Sdim H_PUT_32 (abfd, in->n_type, ext->e_type); 369130561Sobrien 37089857Sobrien H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); 37189857Sobrien H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); 372130561Sobrien 37360484Sobrien#ifdef COFF_ADJUST_SYM_OUT_POST 37460484Sobrien COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp); 37560484Sobrien#endif 376130561Sobrien 37733965Sjdp return SYMESZ; 37833965Sjdp} 37933965Sjdp 38033965Sjdpstatic void 381218822Sdimcoff_swap_aux_in (bfd *abfd, 382218822Sdim void * ext1, 383218822Sdim int type, 384218822Sdim int class, 385218822Sdim int indx, 386218822Sdim int numaux, 387218822Sdim void * in1) 38833965Sjdp{ 38989857Sobrien AUXENT *ext = (AUXENT *) ext1; 39089857Sobrien union internal_auxent *in = (union internal_auxent *) in1; 39133965Sjdp 39238889Sjdp#ifdef COFF_ADJUST_AUX_IN_PRE 39338889Sjdp COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1); 39438889Sjdp#endif 395130561Sobrien 39689857Sobrien switch (class) 39789857Sobrien { 39833965Sjdp case C_FILE: 39989857Sobrien if (ext->x_file.x_fname[0] == 0) 40089857Sobrien { 40133965Sjdp in->x_file.x_n.x_zeroes = 0; 40289857Sobrien in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset); 40389857Sobrien } 40489857Sobrien else 40589857Sobrien { 40633965Sjdp#if FILNMLEN != E_FILNMLEN 407218822Sdim#error we need to cope with truncating or extending FILNMLEN 40833965Sjdp#else 40989857Sobrien if (numaux > 1) 41089857Sobrien { 41189857Sobrien if (indx == 0) 41289857Sobrien memcpy (in->x_file.x_fname, ext->x_file.x_fname, 41389857Sobrien numaux * sizeof (AUXENT)); 41489857Sobrien } 41589857Sobrien else 416130561Sobrien memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); 41733965Sjdp#endif 41889857Sobrien } 41938889Sjdp goto end; 42033965Sjdp 42133965Sjdp case C_STAT: 42233965Sjdp#ifdef C_LEAFSTAT 42333965Sjdp case C_LEAFSTAT: 42433965Sjdp#endif 42533965Sjdp case C_HIDDEN: 42689857Sobrien if (type == T_NULL) 42789857Sobrien { 42889857Sobrien in->x_scn.x_scnlen = GET_SCN_SCNLEN (abfd, ext); 42989857Sobrien in->x_scn.x_nreloc = GET_SCN_NRELOC (abfd, ext); 43089857Sobrien in->x_scn.x_nlinno = GET_SCN_NLINNO (abfd, ext); 43133965Sjdp 43233965Sjdp /* PE defines some extra fields; we zero them out for 43333965Sjdp safety. */ 43433965Sjdp in->x_scn.x_checksum = 0; 43533965Sjdp in->x_scn.x_associated = 0; 43633965Sjdp in->x_scn.x_comdat = 0; 43733965Sjdp 43838889Sjdp goto end; 43933965Sjdp } 44033965Sjdp break; 44133965Sjdp } 44233965Sjdp 44389857Sobrien in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx); 44433965Sjdp#ifndef NO_TVNDX 44589857Sobrien in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx); 44633965Sjdp#endif 44733965Sjdp 44833965Sjdp if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) 44933965Sjdp { 45033965Sjdp in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext); 45133965Sjdp in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext); 45233965Sjdp } 45333965Sjdp else 45433965Sjdp { 45533965Sjdp#if DIMNUM != E_DIMNUM 45689857Sobrien#error we need to cope with truncating or extending DIMNUM 45733965Sjdp#endif 45833965Sjdp in->x_sym.x_fcnary.x_ary.x_dimen[0] = 45989857Sobrien H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]); 46033965Sjdp in->x_sym.x_fcnary.x_ary.x_dimen[1] = 46189857Sobrien H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]); 46233965Sjdp in->x_sym.x_fcnary.x_ary.x_dimen[2] = 46389857Sobrien H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]); 46433965Sjdp in->x_sym.x_fcnary.x_ary.x_dimen[3] = 46589857Sobrien H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); 46633965Sjdp } 46733965Sjdp 468130561Sobrien if (ISFCN (type)) 469218822Sdim in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); 47089857Sobrien else 47189857Sobrien { 47289857Sobrien in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO (abfd, ext); 47389857Sobrien in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE (abfd, ext); 47489857Sobrien } 47538889Sjdp 47689857Sobrien end: ; 47738889Sjdp 47838889Sjdp#ifdef COFF_ADJUST_AUX_IN_POST 47938889Sjdp COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, class, indx, numaux, in1); 48038889Sjdp#endif 48133965Sjdp} 48233965Sjdp 48333965Sjdpstatic unsigned int 484218822Sdimcoff_swap_aux_out (bfd * abfd, 485218822Sdim void * inp, 486218822Sdim int type, 487218822Sdim int class, 488218822Sdim int indx ATTRIBUTE_UNUSED, 489218822Sdim int numaux ATTRIBUTE_UNUSED, 490218822Sdim void * extp) 49133965Sjdp{ 492218822Sdim union internal_auxent * in = (union internal_auxent *) inp; 49389857Sobrien AUXENT *ext = (AUXENT *) extp; 49433965Sjdp 49538889Sjdp#ifdef COFF_ADJUST_AUX_OUT_PRE 49638889Sjdp COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp); 49738889Sjdp#endif 498130561Sobrien 499218822Sdim memset (ext, 0, AUXESZ); 500130561Sobrien 50189857Sobrien switch (class) 50289857Sobrien { 50389857Sobrien case C_FILE: 50489857Sobrien if (in->x_file.x_fname[0] == 0) 50589857Sobrien { 50689857Sobrien H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes); 50789857Sobrien H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset); 50889857Sobrien } 50989857Sobrien else 51089857Sobrien { 51133965Sjdp#if FILNMLEN != E_FILNMLEN 512218822Sdim#error we need to cope with truncating or extending FILNMLEN 51333965Sjdp#else 51489857Sobrien memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN); 51533965Sjdp#endif 51689857Sobrien } 51789857Sobrien goto end; 51833965Sjdp 51989857Sobrien case C_STAT: 52033965Sjdp#ifdef C_LEAFSTAT 52189857Sobrien case C_LEAFSTAT: 52233965Sjdp#endif 52389857Sobrien case C_HIDDEN: 52489857Sobrien if (type == T_NULL) 52589857Sobrien { 52689857Sobrien PUT_SCN_SCNLEN (abfd, in->x_scn.x_scnlen, ext); 52789857Sobrien PUT_SCN_NRELOC (abfd, in->x_scn.x_nreloc, ext); 52889857Sobrien PUT_SCN_NLINNO (abfd, in->x_scn.x_nlinno, ext); 52989857Sobrien goto end; 53089857Sobrien } 53189857Sobrien break; 53233965Sjdp } 53333965Sjdp 53489857Sobrien H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx); 53533965Sjdp#ifndef NO_TVNDX 53689857Sobrien H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx); 53733965Sjdp#endif 53833965Sjdp 53933965Sjdp if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) 54033965Sjdp { 54189857Sobrien PUT_FCN_LNNOPTR (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext); 54289857Sobrien PUT_FCN_ENDNDX (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext); 54333965Sjdp } 54433965Sjdp else 54533965Sjdp { 54633965Sjdp#if DIMNUM != E_DIMNUM 54789857Sobrien#error we need to cope with truncating or extending DIMNUM 54833965Sjdp#endif 54989857Sobrien H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], 55089857Sobrien ext->x_sym.x_fcnary.x_ary.x_dimen[0]); 55189857Sobrien H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], 55289857Sobrien ext->x_sym.x_fcnary.x_ary.x_dimen[1]); 55389857Sobrien H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], 55489857Sobrien ext->x_sym.x_fcnary.x_ary.x_dimen[2]); 55589857Sobrien H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], 55689857Sobrien ext->x_sym.x_fcnary.x_ary.x_dimen[3]); 55733965Sjdp } 55833965Sjdp 55933965Sjdp if (ISFCN (type)) 56089857Sobrien H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize); 56133965Sjdp else 56233965Sjdp { 56333965Sjdp PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext); 56433965Sjdp PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext); 56533965Sjdp } 56633965Sjdp 56789857Sobrien end: 56838889Sjdp#ifdef COFF_ADJUST_AUX_OUT_POST 56938889Sjdp COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, class, indx, numaux, extp); 57038889Sjdp#endif 57133965Sjdp return AUXESZ; 57233965Sjdp} 57333965Sjdp 57433965Sjdp#endif /* NO_COFF_SYMBOLS */ 57533965Sjdp 57633965Sjdp#ifndef NO_COFF_LINENOS 57733965Sjdp 57833965Sjdpstatic void 579218822Sdimcoff_swap_lineno_in (bfd * abfd, void * ext1, void * in1) 58033965Sjdp{ 58189857Sobrien LINENO *ext = (LINENO *) ext1; 58289857Sobrien struct internal_lineno *in = (struct internal_lineno *) in1; 58333965Sjdp 58489857Sobrien in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx); 58589857Sobrien in->l_lnno = GET_LINENO_LNNO (abfd, ext); 58633965Sjdp} 58733965Sjdp 58833965Sjdpstatic unsigned int 589218822Sdimcoff_swap_lineno_out (bfd * abfd, void * inp, void * outp) 59033965Sjdp{ 59189857Sobrien struct internal_lineno *in = (struct internal_lineno *) inp; 59289857Sobrien struct external_lineno *ext = (struct external_lineno *) outp; 59389857Sobrien H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx); 59433965Sjdp 59533965Sjdp PUT_LINENO_LNNO (abfd, in->l_lnno, ext); 59633965Sjdp return LINESZ; 59733965Sjdp} 59833965Sjdp 59933965Sjdp#endif /* NO_COFF_LINENOS */ 60033965Sjdp 60133965Sjdpstatic void 602218822Sdimcoff_swap_aouthdr_in (bfd * abfd, void * aouthdr_ext1, void * aouthdr_int1) 60333965Sjdp{ 60489857Sobrien AOUTHDR *aouthdr_ext; 60589857Sobrien struct internal_aouthdr *aouthdr_int; 60633965Sjdp 60789857Sobrien aouthdr_ext = (AOUTHDR *) aouthdr_ext1; 60889857Sobrien aouthdr_int = (struct internal_aouthdr *) aouthdr_int1; 60989857Sobrien aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic); 61089857Sobrien aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp); 61189857Sobrien aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize); 61289857Sobrien aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize); 61389857Sobrien aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize); 61489857Sobrien aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry); 61533965Sjdp aouthdr_int->text_start = 61689857Sobrien GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start); 61733965Sjdp aouthdr_int->data_start = 61889857Sobrien GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start); 61933965Sjdp 62033965Sjdp#ifdef I960 62189857Sobrien aouthdr_int->tagentries = H_GET_32 (abfd, aouthdr_ext->tagentries); 62233965Sjdp#endif 62333965Sjdp 62433965Sjdp#ifdef APOLLO_M68 62589857Sobrien H_PUT_32 (abfd, aouthdr_int->o_inlib, aouthdr_ext->o_inlib); 62689857Sobrien H_PUT_32 (abfd, aouthdr_int->o_sri, aouthdr_ext->o_sri); 62789857Sobrien H_PUT_32 (abfd, aouthdr_int->vid[0], aouthdr_ext->vid); 62889857Sobrien H_PUT_32 (abfd, aouthdr_int->vid[1], aouthdr_ext->vid + 4); 62933965Sjdp#endif 63033965Sjdp 63133965Sjdp#ifdef RS6000COFF_C 63277298Sobrien#ifdef XCOFF64 63389857Sobrien aouthdr_int->o_toc = H_GET_64 (abfd, aouthdr_ext->o_toc); 63477298Sobrien#else 63589857Sobrien aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc); 63677298Sobrien#endif 637130561Sobrien aouthdr_int->o_snentry = H_GET_16 (abfd, aouthdr_ext->o_snentry); 638130561Sobrien aouthdr_int->o_sntext = H_GET_16 (abfd, aouthdr_ext->o_sntext); 639130561Sobrien aouthdr_int->o_sndata = H_GET_16 (abfd, aouthdr_ext->o_sndata); 640130561Sobrien aouthdr_int->o_sntoc = H_GET_16 (abfd, aouthdr_ext->o_sntoc); 64189857Sobrien aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader); 642130561Sobrien aouthdr_int->o_snbss = H_GET_16 (abfd, aouthdr_ext->o_snbss); 64389857Sobrien aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext); 64489857Sobrien aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata); 645130561Sobrien aouthdr_int->o_modtype = H_GET_16 (abfd, aouthdr_ext->o_modtype); 646130561Sobrien aouthdr_int->o_cputype = H_GET_16 (abfd, aouthdr_ext->o_cputype); 64777298Sobrien#ifdef XCOFF64 64889857Sobrien aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack); 649130561Sobrien aouthdr_int->o_maxdata = H_GET_64 (abfd, aouthdr_ext->o_maxdata); 65077298Sobrien#else 65189857Sobrien aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack); 652130561Sobrien aouthdr_int->o_maxdata = H_GET_32 (abfd, aouthdr_ext->o_maxdata); 65333965Sjdp#endif 65477298Sobrien#endif 65533965Sjdp 65633965Sjdp#ifdef MIPSECOFF 657130561Sobrien aouthdr_int->bss_start = H_GET_32 (abfd, aouthdr_ext->bss_start); 658130561Sobrien aouthdr_int->gp_value = H_GET_32 (abfd, aouthdr_ext->gp_value); 659130561Sobrien aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); 66089857Sobrien aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]); 66189857Sobrien aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]); 66289857Sobrien aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]); 66389857Sobrien aouthdr_int->cprmask[3] = H_GET_32 (abfd, aouthdr_ext->cprmask[3]); 66433965Sjdp#endif 66533965Sjdp 66633965Sjdp#ifdef ALPHAECOFF 66789857Sobrien aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start); 668130561Sobrien aouthdr_int->gp_value = H_GET_64 (abfd, aouthdr_ext->gp_value); 669130561Sobrien aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); 670130561Sobrien aouthdr_int->fprmask = H_GET_32 (abfd, aouthdr_ext->fprmask); 67133965Sjdp#endif 67233965Sjdp} 67333965Sjdp 67433965Sjdpstatic unsigned int 675218822Sdimcoff_swap_aouthdr_out (bfd * abfd, void * in, void * out) 67633965Sjdp{ 67789857Sobrien struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in; 67889857Sobrien AOUTHDR *aouthdr_out = (AOUTHDR *) out; 67933965Sjdp 68089857Sobrien H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->magic); 68189857Sobrien H_PUT_16 (abfd, aouthdr_in->vstamp, aouthdr_out->vstamp); 68289857Sobrien PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, aouthdr_out->tsize); 68389857Sobrien PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, aouthdr_out->dsize); 68489857Sobrien PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, aouthdr_out->bsize); 68589857Sobrien PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, aouthdr_out->entry); 68633965Sjdp PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start, 68789857Sobrien aouthdr_out->text_start); 68833965Sjdp PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start, 68989857Sobrien aouthdr_out->data_start); 69033965Sjdp 69133965Sjdp#ifdef I960 69289857Sobrien H_PUT_32 (abfd, aouthdr_in->tagentries, aouthdr_out->tagentries); 69333965Sjdp#endif 69433965Sjdp 69533965Sjdp#ifdef RS6000COFF_C 69677298Sobrien#ifdef XCOFF64 69789857Sobrien H_PUT_64 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); 69877298Sobrien#else 69989857Sobrien H_PUT_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc); 70077298Sobrien#endif 70189857Sobrien H_PUT_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry); 70289857Sobrien H_PUT_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext); 70389857Sobrien H_PUT_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata); 70489857Sobrien H_PUT_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc); 70589857Sobrien H_PUT_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader); 70689857Sobrien H_PUT_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss); 70789857Sobrien H_PUT_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext); 70889857Sobrien H_PUT_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata); 70989857Sobrien H_PUT_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype); 71089857Sobrien H_PUT_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype); 71177298Sobrien#ifdef XCOFF64 71289857Sobrien H_PUT_64 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); 71389857Sobrien H_PUT_64 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); 71477298Sobrien#else 71589857Sobrien H_PUT_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack); 71689857Sobrien H_PUT_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata); 71777298Sobrien#endif 71833965Sjdp memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2); 71977298Sobrien#ifdef XCOFF64 72077298Sobrien memset (aouthdr_out->o_debugger, 0, sizeof aouthdr_out->o_debugger); 72177298Sobrien memset (aouthdr_out->o_resv3, 0, sizeof aouthdr_out->o_resv3); 72233965Sjdp#endif 72377298Sobrien#endif 72433965Sjdp 72533965Sjdp#ifdef MIPSECOFF 72689857Sobrien H_PUT_32 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); 72789857Sobrien H_PUT_32 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); 72889857Sobrien H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); 72989857Sobrien H_PUT_32 (abfd, aouthdr_in->cprmask[0], aouthdr_out->cprmask[0]); 73089857Sobrien H_PUT_32 (abfd, aouthdr_in->cprmask[1], aouthdr_out->cprmask[1]); 73189857Sobrien H_PUT_32 (abfd, aouthdr_in->cprmask[2], aouthdr_out->cprmask[2]); 73289857Sobrien H_PUT_32 (abfd, aouthdr_in->cprmask[3], aouthdr_out->cprmask[3]); 73333965Sjdp#endif 73433965Sjdp 73533965Sjdp#ifdef ALPHAECOFF 73633965Sjdp /* FIXME: What does bldrev mean? */ 73789857Sobrien H_PUT_16 (abfd, 2, aouthdr_out->bldrev); 73889857Sobrien H_PUT_16 (abfd, 0, aouthdr_out->padding); 73989857Sobrien H_PUT_64 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start); 74089857Sobrien H_PUT_64 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value); 74189857Sobrien H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask); 74289857Sobrien H_PUT_32 (abfd, aouthdr_in->fprmask, aouthdr_out->fprmask); 74333965Sjdp#endif 74433965Sjdp 74533965Sjdp return AOUTSZ; 74633965Sjdp} 74733965Sjdp 74833965Sjdpstatic void 749218822Sdimcoff_swap_scnhdr_in (bfd * abfd, void * ext, void * in) 75033965Sjdp{ 75133965Sjdp SCNHDR *scnhdr_ext = (SCNHDR *) ext; 75233965Sjdp struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; 75333965Sjdp 75438889Sjdp#ifdef COFF_ADJUST_SCNHDR_IN_PRE 75538889Sjdp COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in); 75638889Sjdp#endif 757130561Sobrien memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name)); 758130561Sobrien 75989857Sobrien scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr); 76089857Sobrien scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr); 76189857Sobrien scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size); 76233965Sjdp 76389857Sobrien scnhdr_int->s_scnptr = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr); 76489857Sobrien scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr); 76589857Sobrien scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr); 76689857Sobrien scnhdr_int->s_flags = GET_SCNHDR_FLAGS (abfd, scnhdr_ext->s_flags); 76789857Sobrien scnhdr_int->s_nreloc = GET_SCNHDR_NRELOC (abfd, scnhdr_ext->s_nreloc); 76889857Sobrien scnhdr_int->s_nlnno = GET_SCNHDR_NLNNO (abfd, scnhdr_ext->s_nlnno); 76933965Sjdp#ifdef I960 77089857Sobrien scnhdr_int->s_align = GET_SCNHDR_ALIGN (abfd, scnhdr_ext->s_align); 77133965Sjdp#endif 77238889Sjdp#ifdef COFF_ADJUST_SCNHDR_IN_POST 77338889Sjdp COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in); 77438889Sjdp#endif 77533965Sjdp} 77633965Sjdp 77733965Sjdpstatic unsigned int 778218822Sdimcoff_swap_scnhdr_out (bfd * abfd, void * in, void * out) 77933965Sjdp{ 78089857Sobrien struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in; 78189857Sobrien SCNHDR *scnhdr_ext = (SCNHDR *) out; 78260484Sobrien unsigned int ret = bfd_coff_scnhsz (abfd); 78333965Sjdp 78438889Sjdp#ifdef COFF_ADJUST_SCNHDR_OUT_PRE 78538889Sjdp COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out); 78638889Sjdp#endif 78789857Sobrien memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 78833965Sjdp 78989857Sobrien PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr, scnhdr_ext->s_vaddr); 79089857Sobrien PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr, scnhdr_ext->s_paddr); 79189857Sobrien PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size, scnhdr_ext->s_size); 79289857Sobrien PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr, scnhdr_ext->s_scnptr); 79389857Sobrien PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr, scnhdr_ext->s_relptr); 79489857Sobrien PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr, scnhdr_ext->s_lnnoptr); 79589857Sobrien PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags); 79633965Sjdp#if defined(M88) 79789857Sobrien H_PUT_32 (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno); 79889857Sobrien H_PUT_32 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); 79933965Sjdp#else 80077298Sobrien if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO) 80189857Sobrien PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno); 80233965Sjdp else 80333965Sjdp { 80433965Sjdp char buf[sizeof (scnhdr_int->s_name) + 1]; 80533965Sjdp 80633965Sjdp memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 80733965Sjdp buf[sizeof (scnhdr_int->s_name)] = '\0'; 80833965Sjdp (*_bfd_error_handler) 80960484Sobrien (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), 81033965Sjdp bfd_get_filename (abfd), 81133965Sjdp buf, scnhdr_int->s_nlnno); 81289857Sobrien PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno); 81333965Sjdp } 814130561Sobrien 81577298Sobrien if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC) 81689857Sobrien PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); 81733965Sjdp else 81833965Sjdp { 81933965Sjdp char buf[sizeof (scnhdr_int->s_name) + 1]; 82033965Sjdp 82133965Sjdp memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name)); 82233965Sjdp buf[sizeof (scnhdr_int->s_name)] = '\0'; 82360484Sobrien (*_bfd_error_handler) (_("%s: %s: reloc overflow: 0x%lx > 0xffff"), 82433965Sjdp bfd_get_filename (abfd), 82533965Sjdp buf, scnhdr_int->s_nreloc); 82633965Sjdp bfd_set_error (bfd_error_file_truncated); 82789857Sobrien PUT_SCNHDR_NRELOC (abfd, 0xffff, scnhdr_ext->s_nreloc); 82833965Sjdp ret = 0; 82933965Sjdp } 83033965Sjdp#endif 83133965Sjdp 83238889Sjdp#ifdef I960 83389857Sobrien PUT_SCNHDR_ALIGN (abfd, scnhdr_int->s_align, scnhdr_ext->s_align); 83433965Sjdp#endif 83538889Sjdp#ifdef COFF_ADJUST_SCNHDR_OUT_POST 83638889Sjdp COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out); 83738889Sjdp#endif 83833965Sjdp return ret; 83933965Sjdp} 840