Back to index

cell-binutils  2.17cvs20070401
coffswap.h
Go to the documentation of this file.
00001 /* Generic COFF swapping routines, for BFD.
00002    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000,
00003    2001, 2002, 2005
00004    Free Software Foundation, Inc.
00005    Written by Cygnus Support.
00006 
00007    This file is part of BFD, the Binary File Descriptor library.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00022 
00023 /* This file contains routines used to swap COFF data.  It is a header
00024    file because the details of swapping depend on the details of the
00025    structures used by each COFF implementation.  This is included by
00026    coffcode.h, as well as by the ECOFF backend.
00027 
00028    Any file which uses this must first include "coff/internal.h" and
00029    "coff/CPU.h".  The functions will then be correct for that CPU.  */
00030 
00031 #ifndef GET_FCN_LNNOPTR
00032 #define GET_FCN_LNNOPTR(abfd, ext) \
00033   H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
00034 #endif
00035 
00036 #ifndef GET_FCN_ENDNDX
00037 #define GET_FCN_ENDNDX(abfd, ext) \
00038   H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx)
00039 #endif
00040 
00041 #ifndef PUT_FCN_LNNOPTR
00042 #define PUT_FCN_LNNOPTR(abfd, in, ext) \
00043   H_PUT_32 (abfd,  in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
00044 #endif
00045 #ifndef PUT_FCN_ENDNDX
00046 #define PUT_FCN_ENDNDX(abfd, in, ext) \
00047   H_PUT_32 (abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx)
00048 #endif
00049 #ifndef GET_LNSZ_LNNO
00050 #define GET_LNSZ_LNNO(abfd, ext) \
00051   H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno)
00052 #endif
00053 #ifndef GET_LNSZ_SIZE
00054 #define GET_LNSZ_SIZE(abfd, ext) \
00055   H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size)
00056 #endif
00057 #ifndef PUT_LNSZ_LNNO
00058 #define PUT_LNSZ_LNNO(abfd, in, ext) \
00059   H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno)
00060 #endif
00061 #ifndef PUT_LNSZ_SIZE
00062 #define PUT_LNSZ_SIZE(abfd, in, ext) \
00063   H_PUT_16 (abfd, in, ext->x_sym.x_misc.x_lnsz.x_size)
00064 #endif
00065 #ifndef GET_SCN_SCNLEN
00066 #define GET_SCN_SCNLEN(abfd, ext) \
00067   H_GET_32 (abfd, ext->x_scn.x_scnlen)
00068 #endif
00069 #ifndef GET_SCN_NRELOC
00070 #define GET_SCN_NRELOC(abfd, ext) \
00071   H_GET_16 (abfd, ext->x_scn.x_nreloc)
00072 #endif
00073 #ifndef GET_SCN_NLINNO
00074 #define GET_SCN_NLINNO(abfd, ext) \
00075   H_GET_16 (abfd, ext->x_scn.x_nlinno)
00076 #endif
00077 #ifndef PUT_SCN_SCNLEN
00078 #define PUT_SCN_SCNLEN(abfd, in, ext) \
00079   H_PUT_32 (abfd, in, ext->x_scn.x_scnlen)
00080 #endif
00081 #ifndef PUT_SCN_NRELOC
00082 #define PUT_SCN_NRELOC(abfd, in, ext) \
00083   H_PUT_16 (abfd, in, ext->x_scn.x_nreloc)
00084 #endif
00085 #ifndef PUT_SCN_NLINNO
00086 #define PUT_SCN_NLINNO(abfd, in, ext) \
00087   H_PUT_16 (abfd, in, ext->x_scn.x_nlinno)
00088 #endif
00089 #ifndef GET_LINENO_LNNO
00090 #define GET_LINENO_LNNO(abfd, ext) \
00091   H_GET_16 (abfd, ext->l_lnno);
00092 #endif
00093 #ifndef PUT_LINENO_LNNO
00094 #define PUT_LINENO_LNNO(abfd, val, ext) \
00095   H_PUT_16 (abfd, val, ext->l_lnno);
00096 #endif
00097 
00098 /* The f_symptr field in the filehdr is sometimes 64 bits.  */
00099 #ifndef GET_FILEHDR_SYMPTR
00100 #define GET_FILEHDR_SYMPTR H_GET_32
00101 #endif
00102 #ifndef PUT_FILEHDR_SYMPTR
00103 #define PUT_FILEHDR_SYMPTR H_PUT_32
00104 #endif
00105 
00106 /* Some fields in the aouthdr are sometimes 64 bits.  */
00107 #ifndef GET_AOUTHDR_TSIZE
00108 #define GET_AOUTHDR_TSIZE H_GET_32
00109 #endif
00110 #ifndef PUT_AOUTHDR_TSIZE
00111 #define PUT_AOUTHDR_TSIZE H_PUT_32
00112 #endif
00113 #ifndef GET_AOUTHDR_DSIZE
00114 #define GET_AOUTHDR_DSIZE H_GET_32
00115 #endif
00116 #ifndef PUT_AOUTHDR_DSIZE
00117 #define PUT_AOUTHDR_DSIZE H_PUT_32
00118 #endif
00119 #ifndef GET_AOUTHDR_BSIZE
00120 #define GET_AOUTHDR_BSIZE H_GET_32
00121 #endif
00122 #ifndef PUT_AOUTHDR_BSIZE
00123 #define PUT_AOUTHDR_BSIZE H_PUT_32
00124 #endif
00125 #ifndef GET_AOUTHDR_ENTRY
00126 #define GET_AOUTHDR_ENTRY H_GET_32
00127 #endif
00128 #ifndef PUT_AOUTHDR_ENTRY
00129 #define PUT_AOUTHDR_ENTRY H_PUT_32
00130 #endif
00131 #ifndef GET_AOUTHDR_TEXT_START
00132 #define GET_AOUTHDR_TEXT_START H_GET_32
00133 #endif
00134 #ifndef PUT_AOUTHDR_TEXT_START
00135 #define PUT_AOUTHDR_TEXT_START H_PUT_32
00136 #endif
00137 #ifndef GET_AOUTHDR_DATA_START
00138 #define GET_AOUTHDR_DATA_START H_GET_32
00139 #endif
00140 #ifndef PUT_AOUTHDR_DATA_START
00141 #define PUT_AOUTHDR_DATA_START H_PUT_32
00142 #endif
00143 
00144 /* Some fields in the scnhdr are sometimes 64 bits.  */
00145 #ifndef GET_SCNHDR_PADDR
00146 #define GET_SCNHDR_PADDR H_GET_32
00147 #endif
00148 #ifndef PUT_SCNHDR_PADDR
00149 #define PUT_SCNHDR_PADDR H_PUT_32
00150 #endif
00151 #ifndef GET_SCNHDR_VADDR
00152 #define GET_SCNHDR_VADDR H_GET_32
00153 #endif
00154 #ifndef PUT_SCNHDR_VADDR
00155 #define PUT_SCNHDR_VADDR H_PUT_32
00156 #endif
00157 #ifndef GET_SCNHDR_SIZE
00158 #define GET_SCNHDR_SIZE H_GET_32
00159 #endif
00160 #ifndef PUT_SCNHDR_SIZE
00161 #define PUT_SCNHDR_SIZE H_PUT_32
00162 #endif
00163 #ifndef GET_SCNHDR_SCNPTR
00164 #define GET_SCNHDR_SCNPTR H_GET_32
00165 #endif
00166 #ifndef PUT_SCNHDR_SCNPTR
00167 #define PUT_SCNHDR_SCNPTR H_PUT_32
00168 #endif
00169 #ifndef GET_SCNHDR_RELPTR
00170 #define GET_SCNHDR_RELPTR H_GET_32
00171 #endif
00172 #ifndef PUT_SCNHDR_RELPTR
00173 #define PUT_SCNHDR_RELPTR H_PUT_32
00174 #endif
00175 #ifndef GET_SCNHDR_LNNOPTR
00176 #define GET_SCNHDR_LNNOPTR H_GET_32
00177 #endif
00178 #ifndef PUT_SCNHDR_LNNOPTR
00179 #define PUT_SCNHDR_LNNOPTR H_PUT_32
00180 #endif
00181 #ifndef GET_SCNHDR_NRELOC
00182 #define GET_SCNHDR_NRELOC H_GET_16
00183 #endif
00184 #ifndef MAX_SCNHDR_NRELOC
00185 #define MAX_SCNHDR_NRELOC 0xffff
00186 #endif
00187 #ifndef PUT_SCNHDR_NRELOC
00188 #define PUT_SCNHDR_NRELOC H_PUT_16
00189 #endif
00190 #ifndef GET_SCNHDR_NLNNO
00191 #define GET_SCNHDR_NLNNO H_GET_16
00192 #endif
00193 #ifndef MAX_SCNHDR_NLNNO
00194 #define MAX_SCNHDR_NLNNO 0xffff
00195 #endif
00196 #ifndef PUT_SCNHDR_NLNNO
00197 #define PUT_SCNHDR_NLNNO H_PUT_16
00198 #endif
00199 #ifndef GET_SCNHDR_FLAGS
00200 #define GET_SCNHDR_FLAGS H_GET_32
00201 #endif
00202 #ifndef PUT_SCNHDR_FLAGS
00203 #define PUT_SCNHDR_FLAGS H_PUT_32
00204 #endif
00205 
00206 #ifndef GET_RELOC_VADDR
00207 #define GET_RELOC_VADDR H_GET_32
00208 #endif
00209 #ifndef PUT_RELOC_VADDR
00210 #define PUT_RELOC_VADDR H_PUT_32
00211 #endif
00212 
00213 #ifndef NO_COFF_RELOCS
00214 
00215 static void
00216 coff_swap_reloc_in (bfd * abfd, void * src, void * dst)
00217 {
00218   RELOC *reloc_src = (RELOC *) src;
00219   struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
00220 
00221   reloc_dst->r_vaddr  = GET_RELOC_VADDR (abfd, reloc_src->r_vaddr);
00222   reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
00223   reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
00224 
00225 #ifdef SWAP_IN_RELOC_OFFSET
00226   reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
00227 #endif
00228 }
00229 
00230 static unsigned int
00231 coff_swap_reloc_out (bfd * abfd, void * src, void * dst)
00232 {
00233   struct internal_reloc *reloc_src = (struct internal_reloc *) src;
00234   struct external_reloc *reloc_dst = (struct external_reloc *) dst;
00235 
00236   PUT_RELOC_VADDR (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
00237   H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
00238   H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
00239 
00240 #ifdef SWAP_OUT_RELOC_OFFSET
00241   SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
00242 #endif
00243 #ifdef SWAP_OUT_RELOC_EXTRA
00244   SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
00245 #endif
00246 
00247   return bfd_coff_relsz (abfd);
00248 }
00249 
00250 #endif /* NO_COFF_RELOCS */
00251 
00252 static void
00253 coff_swap_filehdr_in (bfd * abfd, void * src, void * dst)
00254 {
00255   FILHDR *filehdr_src = (FILHDR *) src;
00256   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
00257 
00258 #ifdef COFF_ADJUST_FILEHDR_IN_PRE
00259   COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst);
00260 #endif
00261   filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
00262   filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
00263   filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
00264   filehdr_dst->f_symptr = GET_FILEHDR_SYMPTR (abfd, filehdr_src->f_symptr);
00265   filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
00266   filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src->f_opthdr);
00267   filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
00268 #ifdef TIC80_TARGET_ID
00269   filehdr_dst->f_target_id = H_GET_16 (abfd, filehdr_src->f_target_id);
00270 #endif
00271 
00272 #ifdef COFF_ADJUST_FILEHDR_IN_POST
00273   COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst);
00274 #endif
00275 }
00276 
00277 static  unsigned int
00278 coff_swap_filehdr_out (bfd *abfd, void * in, void * out)
00279 {
00280   struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
00281   FILHDR *filehdr_out = (FILHDR *) out;
00282 
00283 #ifdef COFF_ADJUST_FILEHDR_OUT_PRE
00284   COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out);
00285 #endif
00286   H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic);
00287   H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns);
00288   H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->f_timdat);
00289   PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr);
00290   H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms);
00291   H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr);
00292   H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags);
00293 #ifdef TIC80_TARGET_ID
00294   H_PUT_16 (abfd, filehdr_in->f_target_id, filehdr_out->f_target_id);
00295 #endif
00296 
00297 #ifdef COFF_ADJUST_FILEHDR_OUT_POST
00298   COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out);
00299 #endif
00300   return bfd_coff_filhsz (abfd);
00301 }
00302 
00303 #ifndef NO_COFF_SYMBOLS
00304 
00305 static void
00306 coff_swap_sym_in (bfd * abfd, void * ext1, void * in1)
00307 {
00308   SYMENT *ext = (SYMENT *) ext1;
00309   struct internal_syment *in = (struct internal_syment *) in1;
00310 
00311   if (ext->e.e_name[0] == 0)
00312     {
00313       in->_n._n_n._n_zeroes = 0;
00314       in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
00315     }
00316   else
00317     {
00318 #if SYMNMLEN != E_SYMNMLEN
00319 #error we need to cope with truncating or extending SYMNMLEN
00320 #else
00321       memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
00322 #endif
00323     }
00324 
00325   in->n_value = H_GET_32 (abfd, ext->e_value);
00326   in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
00327   if (sizeof (ext->e_type) == 2)
00328     in->n_type = H_GET_16 (abfd, ext->e_type);
00329   else
00330     in->n_type = H_GET_32 (abfd, ext->e_type);
00331   in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
00332   in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
00333 #ifdef COFF_ADJUST_SYM_IN_POST
00334   COFF_ADJUST_SYM_IN_POST (abfd, ext1, in1);
00335 #endif
00336 }
00337 
00338 static unsigned int
00339 coff_swap_sym_out (bfd * abfd, void * inp, void * extp)
00340 {
00341   struct internal_syment *in = (struct internal_syment *) inp;
00342   SYMENT *ext =(SYMENT *) extp;
00343 
00344 #ifdef COFF_ADJUST_SYM_OUT_PRE
00345   COFF_ADJUST_SYM_OUT_PRE (abfd, inp, extp);
00346 #endif
00347 
00348   if (in->_n._n_name[0] == 0)
00349     {
00350       H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
00351       H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
00352     }
00353   else
00354     {
00355 #if SYMNMLEN != E_SYMNMLEN
00356 #error we need to cope with truncating or extending SYMNMLEN
00357 #else
00358       memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
00359 #endif
00360     }
00361 
00362   H_PUT_32 (abfd, in->n_value, ext->e_value);
00363   H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
00364 
00365   if (sizeof (ext->e_type) == 2)
00366     H_PUT_16 (abfd, in->n_type, ext->e_type);
00367   else
00368     H_PUT_32 (abfd, in->n_type, ext->e_type);
00369 
00370   H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
00371   H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
00372 
00373 #ifdef COFF_ADJUST_SYM_OUT_POST
00374   COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp);
00375 #endif
00376 
00377   return SYMESZ;
00378 }
00379 
00380 static void
00381 coff_swap_aux_in (bfd *abfd,
00382                 void * ext1,
00383                 int type,
00384                 int class,
00385                 int indx,
00386                 int numaux,
00387                 void * in1)
00388 {
00389   AUXENT *ext = (AUXENT *) ext1;
00390   union internal_auxent *in = (union internal_auxent *) in1;
00391 
00392 #ifdef COFF_ADJUST_AUX_IN_PRE
00393   COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1);
00394 #endif
00395 
00396   switch (class)
00397     {
00398     case C_FILE:
00399       if (ext->x_file.x_fname[0] == 0)
00400        {
00401          in->x_file.x_n.x_zeroes = 0;
00402          in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
00403        }
00404       else
00405        {
00406 #if FILNMLEN != E_FILNMLEN
00407 #error we need to cope with truncating or extending FILNMLEN
00408 #else
00409          if (numaux > 1)
00410            {
00411              if (indx == 0)
00412               memcpy (in->x_file.x_fname, ext->x_file.x_fname,
00413                      numaux * sizeof (AUXENT));
00414            }
00415          else
00416            memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
00417 #endif
00418        }
00419       goto end;
00420 
00421     case C_STAT:
00422 #ifdef C_LEAFSTAT
00423     case C_LEAFSTAT:
00424 #endif
00425     case C_HIDDEN:
00426       if (type == T_NULL)
00427        {
00428          in->x_scn.x_scnlen = GET_SCN_SCNLEN (abfd, ext);
00429          in->x_scn.x_nreloc = GET_SCN_NRELOC (abfd, ext);
00430          in->x_scn.x_nlinno = GET_SCN_NLINNO (abfd, ext);
00431 
00432          /* PE defines some extra fields; we zero them out for
00433              safety.  */
00434          in->x_scn.x_checksum = 0;
00435          in->x_scn.x_associated = 0;
00436          in->x_scn.x_comdat = 0;
00437 
00438          goto end;
00439        }
00440       break;
00441     }
00442 
00443   in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
00444 #ifndef NO_TVNDX
00445   in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
00446 #endif
00447 
00448   if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
00449     {
00450       in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
00451       in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
00452     }
00453   else
00454     {
00455 #if DIMNUM != E_DIMNUM
00456 #error we need to cope with truncating or extending DIMNUM
00457 #endif
00458       in->x_sym.x_fcnary.x_ary.x_dimen[0] =
00459        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
00460       in->x_sym.x_fcnary.x_ary.x_dimen[1] =
00461        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
00462       in->x_sym.x_fcnary.x_ary.x_dimen[2] =
00463        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
00464       in->x_sym.x_fcnary.x_ary.x_dimen[3] =
00465        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
00466     }
00467 
00468   if (ISFCN (type))
00469     in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
00470   else
00471     {
00472       in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO (abfd, ext);
00473       in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE (abfd, ext);
00474     }
00475 
00476  end: ;
00477 
00478 #ifdef COFF_ADJUST_AUX_IN_POST
00479   COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, class, indx, numaux, in1);
00480 #endif
00481 }
00482 
00483 static unsigned int
00484 coff_swap_aux_out (bfd * abfd,
00485                  void * inp,
00486                  int type,
00487                  int class,
00488                  int indx ATTRIBUTE_UNUSED,
00489                  int numaux ATTRIBUTE_UNUSED,
00490                  void * extp)
00491 {
00492   union internal_auxent * in = (union internal_auxent *) inp;
00493   AUXENT *ext = (AUXENT *) extp;
00494 
00495 #ifdef COFF_ADJUST_AUX_OUT_PRE
00496   COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp);
00497 #endif
00498 
00499   memset (ext, 0, AUXESZ);
00500 
00501   switch (class)
00502     {
00503     case C_FILE:
00504       if (in->x_file.x_fname[0] == 0)
00505        {
00506          H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
00507          H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
00508        }
00509       else
00510        {
00511 #if FILNMLEN != E_FILNMLEN
00512 #error we need to cope with truncating or extending FILNMLEN
00513 #else
00514          memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
00515 #endif
00516        }
00517       goto end;
00518 
00519     case C_STAT:
00520 #ifdef C_LEAFSTAT
00521     case C_LEAFSTAT:
00522 #endif
00523     case C_HIDDEN:
00524       if (type == T_NULL)
00525        {
00526          PUT_SCN_SCNLEN (abfd, in->x_scn.x_scnlen, ext);
00527          PUT_SCN_NRELOC (abfd, in->x_scn.x_nreloc, ext);
00528          PUT_SCN_NLINNO (abfd, in->x_scn.x_nlinno, ext);
00529          goto end;
00530        }
00531       break;
00532     }
00533 
00534   H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
00535 #ifndef NO_TVNDX
00536   H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
00537 #endif
00538 
00539   if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
00540     {
00541       PUT_FCN_LNNOPTR (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
00542       PUT_FCN_ENDNDX (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
00543     }
00544   else
00545     {
00546 #if DIMNUM != E_DIMNUM
00547 #error we need to cope with truncating or extending DIMNUM
00548 #endif
00549       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
00550               ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
00551       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
00552               ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
00553       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
00554               ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
00555       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
00556               ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
00557     }
00558 
00559   if (ISFCN (type))
00560     H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
00561   else
00562     {
00563       PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
00564       PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
00565     }
00566 
00567  end:
00568 #ifdef COFF_ADJUST_AUX_OUT_POST
00569   COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, class, indx, numaux, extp);
00570 #endif
00571   return AUXESZ;
00572 }
00573 
00574 #endif /* NO_COFF_SYMBOLS */
00575 
00576 #ifndef NO_COFF_LINENOS
00577 
00578 static void
00579 coff_swap_lineno_in (bfd * abfd, void * ext1, void * in1)
00580 {
00581   LINENO *ext = (LINENO *) ext1;
00582   struct internal_lineno *in = (struct internal_lineno *) in1;
00583 
00584   in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
00585   in->l_lnno = GET_LINENO_LNNO (abfd, ext);
00586 }
00587 
00588 static unsigned int
00589 coff_swap_lineno_out (bfd * abfd, void * inp, void * outp)
00590 {
00591   struct internal_lineno *in = (struct internal_lineno *) inp;
00592   struct external_lineno *ext = (struct external_lineno *) outp;
00593   H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
00594 
00595   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
00596   return LINESZ;
00597 }
00598 
00599 #endif /* NO_COFF_LINENOS */
00600 
00601 static void
00602 coff_swap_aouthdr_in (bfd * abfd, void * aouthdr_ext1, void * aouthdr_int1)
00603 {
00604   AOUTHDR *aouthdr_ext;
00605   struct internal_aouthdr *aouthdr_int;
00606 
00607   aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
00608   aouthdr_int = (struct internal_aouthdr *) aouthdr_int1;
00609   aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic);
00610   aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp);
00611   aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize);
00612   aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize);
00613   aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize);
00614   aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry);
00615   aouthdr_int->text_start =
00616     GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start);
00617   aouthdr_int->data_start =
00618     GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start);
00619 
00620 #ifdef I960
00621   aouthdr_int->tagentries = H_GET_32 (abfd, aouthdr_ext->tagentries);
00622 #endif
00623 
00624 #ifdef APOLLO_M68
00625   H_PUT_32 (abfd, aouthdr_int->o_inlib, aouthdr_ext->o_inlib);
00626   H_PUT_32 (abfd, aouthdr_int->o_sri, aouthdr_ext->o_sri);
00627   H_PUT_32 (abfd, aouthdr_int->vid[0], aouthdr_ext->vid);
00628   H_PUT_32 (abfd, aouthdr_int->vid[1], aouthdr_ext->vid + 4);
00629 #endif
00630 
00631 #ifdef RS6000COFF_C
00632 #ifdef XCOFF64
00633   aouthdr_int->o_toc = H_GET_64 (abfd, aouthdr_ext->o_toc);
00634 #else
00635   aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc);
00636 #endif
00637   aouthdr_int->o_snentry  = H_GET_16 (abfd, aouthdr_ext->o_snentry);
00638   aouthdr_int->o_sntext   = H_GET_16 (abfd, aouthdr_ext->o_sntext);
00639   aouthdr_int->o_sndata   = H_GET_16 (abfd, aouthdr_ext->o_sndata);
00640   aouthdr_int->o_sntoc    = H_GET_16 (abfd, aouthdr_ext->o_sntoc);
00641   aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader);
00642   aouthdr_int->o_snbss    = H_GET_16 (abfd, aouthdr_ext->o_snbss);
00643   aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext);
00644   aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata);
00645   aouthdr_int->o_modtype  = H_GET_16 (abfd, aouthdr_ext->o_modtype);
00646   aouthdr_int->o_cputype  = H_GET_16 (abfd, aouthdr_ext->o_cputype);
00647 #ifdef XCOFF64
00648   aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack);
00649   aouthdr_int->o_maxdata  = H_GET_64 (abfd, aouthdr_ext->o_maxdata);
00650 #else
00651   aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack);
00652   aouthdr_int->o_maxdata  = H_GET_32 (abfd, aouthdr_ext->o_maxdata);
00653 #endif
00654 #endif
00655 
00656 #ifdef MIPSECOFF
00657   aouthdr_int->bss_start  = H_GET_32 (abfd, aouthdr_ext->bss_start);
00658   aouthdr_int->gp_value   = H_GET_32 (abfd, aouthdr_ext->gp_value);
00659   aouthdr_int->gprmask    = H_GET_32 (abfd, aouthdr_ext->gprmask);
00660   aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]);
00661   aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]);
00662   aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]);
00663   aouthdr_int->cprmask[3] = H_GET_32 (abfd, aouthdr_ext->cprmask[3]);
00664 #endif
00665 
00666 #ifdef ALPHAECOFF
00667   aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start);
00668   aouthdr_int->gp_value  = H_GET_64 (abfd, aouthdr_ext->gp_value);
00669   aouthdr_int->gprmask   = H_GET_32 (abfd, aouthdr_ext->gprmask);
00670   aouthdr_int->fprmask   = H_GET_32 (abfd, aouthdr_ext->fprmask);
00671 #endif
00672 }
00673 
00674 static unsigned int
00675 coff_swap_aouthdr_out (bfd * abfd, void * in, void * out)
00676 {
00677   struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in;
00678   AOUTHDR *aouthdr_out = (AOUTHDR *) out;
00679 
00680   H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->magic);
00681   H_PUT_16 (abfd, aouthdr_in->vstamp, aouthdr_out->vstamp);
00682   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, aouthdr_out->tsize);
00683   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, aouthdr_out->dsize);
00684   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, aouthdr_out->bsize);
00685   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, aouthdr_out->entry);
00686   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
00687                        aouthdr_out->text_start);
00688   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
00689                        aouthdr_out->data_start);
00690 
00691 #ifdef I960
00692   H_PUT_32 (abfd, aouthdr_in->tagentries, aouthdr_out->tagentries);
00693 #endif
00694 
00695 #ifdef RS6000COFF_C
00696 #ifdef XCOFF64
00697   H_PUT_64 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc);
00698 #else
00699   H_PUT_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc);
00700 #endif
00701   H_PUT_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry);
00702   H_PUT_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext);
00703   H_PUT_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata);
00704   H_PUT_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc);
00705   H_PUT_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader);
00706   H_PUT_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss);
00707   H_PUT_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext);
00708   H_PUT_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata);
00709   H_PUT_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype);
00710   H_PUT_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype);
00711 #ifdef XCOFF64
00712   H_PUT_64 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
00713   H_PUT_64 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
00714 #else
00715   H_PUT_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
00716   H_PUT_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
00717 #endif
00718   memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2);
00719 #ifdef XCOFF64
00720   memset (aouthdr_out->o_debugger, 0, sizeof aouthdr_out->o_debugger);
00721   memset (aouthdr_out->o_resv3, 0, sizeof aouthdr_out->o_resv3);
00722 #endif
00723 #endif
00724 
00725 #ifdef MIPSECOFF
00726   H_PUT_32 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start);
00727   H_PUT_32 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value);
00728   H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask);
00729   H_PUT_32 (abfd, aouthdr_in->cprmask[0], aouthdr_out->cprmask[0]);
00730   H_PUT_32 (abfd, aouthdr_in->cprmask[1], aouthdr_out->cprmask[1]);
00731   H_PUT_32 (abfd, aouthdr_in->cprmask[2], aouthdr_out->cprmask[2]);
00732   H_PUT_32 (abfd, aouthdr_in->cprmask[3], aouthdr_out->cprmask[3]);
00733 #endif
00734 
00735 #ifdef ALPHAECOFF
00736   /* FIXME: What does bldrev mean?  */
00737   H_PUT_16 (abfd, 2, aouthdr_out->bldrev);
00738   H_PUT_16 (abfd, 0, aouthdr_out->padding);
00739   H_PUT_64 (abfd, aouthdr_in->bss_start, aouthdr_out->bss_start);
00740   H_PUT_64 (abfd, aouthdr_in->gp_value, aouthdr_out->gp_value);
00741   H_PUT_32 (abfd, aouthdr_in->gprmask, aouthdr_out->gprmask);
00742   H_PUT_32 (abfd, aouthdr_in->fprmask, aouthdr_out->fprmask);
00743 #endif
00744 
00745   return AOUTSZ;
00746 }
00747 
00748 static void
00749 coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
00750 {
00751   SCNHDR *scnhdr_ext = (SCNHDR *) ext;
00752   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
00753 
00754 #ifdef COFF_ADJUST_SCNHDR_IN_PRE
00755   COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in);
00756 #endif
00757   memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
00758 
00759   scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
00760   scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
00761   scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
00762 
00763   scnhdr_int->s_scnptr = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
00764   scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
00765   scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
00766   scnhdr_int->s_flags = GET_SCNHDR_FLAGS (abfd, scnhdr_ext->s_flags);
00767   scnhdr_int->s_nreloc = GET_SCNHDR_NRELOC (abfd, scnhdr_ext->s_nreloc);
00768   scnhdr_int->s_nlnno = GET_SCNHDR_NLNNO (abfd, scnhdr_ext->s_nlnno);
00769 #ifdef I960
00770   scnhdr_int->s_align = GET_SCNHDR_ALIGN (abfd, scnhdr_ext->s_align);
00771 #endif
00772 #ifdef COFF_ADJUST_SCNHDR_IN_POST
00773   COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in);
00774 #endif
00775 }
00776 
00777 static unsigned int
00778 coff_swap_scnhdr_out (bfd * abfd, void * in, void * out)
00779 {
00780   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
00781   SCNHDR *scnhdr_ext = (SCNHDR *) out;
00782   unsigned int ret = bfd_coff_scnhsz (abfd);
00783 
00784 #ifdef COFF_ADJUST_SCNHDR_OUT_PRE
00785   COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out);
00786 #endif
00787   memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
00788 
00789   PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr, scnhdr_ext->s_vaddr);
00790   PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr, scnhdr_ext->s_paddr);
00791   PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size, scnhdr_ext->s_size);
00792   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr, scnhdr_ext->s_scnptr);
00793   PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr, scnhdr_ext->s_relptr);
00794   PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr, scnhdr_ext->s_lnnoptr);
00795   PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags);
00796 #if defined(M88)
00797   H_PUT_32 (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
00798   H_PUT_32 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
00799 #else
00800   if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO)
00801     PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
00802   else
00803     {
00804       char buf[sizeof (scnhdr_int->s_name) + 1];
00805 
00806       memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
00807       buf[sizeof (scnhdr_int->s_name)] = '\0';
00808       (*_bfd_error_handler)
00809        (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"),
00810         bfd_get_filename (abfd),
00811         buf, scnhdr_int->s_nlnno);
00812       PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno);
00813     }
00814 
00815   if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC)
00816     PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
00817   else
00818     {
00819       char buf[sizeof (scnhdr_int->s_name) + 1];
00820 
00821       memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
00822       buf[sizeof (scnhdr_int->s_name)] = '\0';
00823       (*_bfd_error_handler) (_("%s: %s: reloc overflow: 0x%lx > 0xffff"),
00824                           bfd_get_filename (abfd),
00825                           buf, scnhdr_int->s_nreloc);
00826       bfd_set_error (bfd_error_file_truncated);
00827       PUT_SCNHDR_NRELOC (abfd, 0xffff, scnhdr_ext->s_nreloc);
00828       ret = 0;
00829     }
00830 #endif
00831 
00832 #ifdef I960
00833   PUT_SCNHDR_ALIGN (abfd, scnhdr_int->s_align, scnhdr_ext->s_align);
00834 #endif
00835 #ifdef COFF_ADJUST_SCNHDR_OUT_POST
00836   COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out);
00837 #endif
00838   return ret;
00839 }