1 |
/* Generic COFF swapping routines, for BFD. |
/* Generic COFF swapping routines, for BFD. |
2 |
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, |
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, |
3 |
2001 |
2001, 2002 |
4 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
5 |
Written by Cygnus Support. |
Written by Cygnus Support. |
6 |
|
|
7 |
This file is part of BFD, the Binary File Descriptor library. |
This file is part of BFD, the Binary File Descriptor library. |
8 |
|
|
9 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
10 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
11 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
12 |
(at your option) any later version. |
(at your option) any later version. |
13 |
|
|
14 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
GNU General Public License for more details. |
GNU General Public License for more details. |
18 |
|
|
19 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
20 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
21 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
22 |
|
|
23 |
/* This file contains routines used to swap COFF data. It is a header |
/* This file contains routines used to swap COFF data. It is a header |
24 |
file because the details of swapping depend on the details of the |
file because the details of swapping depend on the details of the |
381 |
{ |
{ |
382 |
struct internal_syment *in = (struct internal_syment *) inp; |
struct internal_syment *in = (struct internal_syment *) inp; |
383 |
SYMENT *ext =(SYMENT *) extp; |
SYMENT *ext =(SYMENT *) extp; |
384 |
if(in->_n._n_name[0] == 0) |
|
385 |
|
#ifdef COFF_ADJUST_SYM_OUT_PRE |
386 |
|
COFF_ADJUST_SYM_OUT_PRE (abfd, inp, extp); |
387 |
|
#endif |
388 |
|
|
389 |
|
if (in->_n._n_name[0] == 0) |
390 |
{ |
{ |
391 |
H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); |
H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); |
392 |
H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); |
H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); |
396 |
#if SYMNMLEN != E_SYMNMLEN |
#if SYMNMLEN != E_SYMNMLEN |
397 |
-> Error, we need to cope with truncating or extending SYMNMLEN!; |
-> Error, we need to cope with truncating or extending SYMNMLEN!; |
398 |
#else |
#else |
399 |
memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN); |
memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN); |
400 |
#endif |
#endif |
401 |
} |
} |
402 |
|
|
403 |
H_PUT_32 (abfd, in->n_value, ext->e_value); |
H_PUT_32 (abfd, in->n_value, ext->e_value); |
404 |
H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); |
H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); |
405 |
|
|
406 |
if (sizeof (ext->e_type) == 2) |
if (sizeof (ext->e_type) == 2) |
407 |
{ |
{ |
408 |
H_PUT_16 (abfd, in->n_type, ext->e_type); |
H_PUT_16 (abfd, in->n_type, ext->e_type); |
411 |
{ |
{ |
412 |
H_PUT_32 (abfd, in->n_type, ext->e_type); |
H_PUT_32 (abfd, in->n_type, ext->e_type); |
413 |
} |
} |
414 |
|
|
415 |
H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); |
H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); |
416 |
H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); |
H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); |
417 |
|
|
418 |
#ifdef COFF_ADJUST_SYM_OUT_POST |
#ifdef COFF_ADJUST_SYM_OUT_POST |
419 |
COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp); |
COFF_ADJUST_SYM_OUT_POST (abfd, inp, extp); |
420 |
#endif |
#endif |
421 |
|
|
422 |
return SYMESZ; |
return SYMESZ; |
423 |
} |
} |
424 |
|
|
438 |
#ifdef COFF_ADJUST_AUX_IN_PRE |
#ifdef COFF_ADJUST_AUX_IN_PRE |
439 |
COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1); |
COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1); |
440 |
#endif |
#endif |
441 |
|
|
442 |
switch (class) |
switch (class) |
443 |
{ |
{ |
444 |
case C_FILE: |
case C_FILE: |
459 |
numaux * sizeof (AUXENT)); |
numaux * sizeof (AUXENT)); |
460 |
} |
} |
461 |
else |
else |
462 |
{ |
memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); |
|
memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); |
|
|
} |
|
463 |
#endif |
#endif |
464 |
} |
} |
465 |
goto end; |
goto end; |
511 |
H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); |
H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); |
512 |
} |
} |
513 |
|
|
514 |
if (ISFCN(type)) |
if (ISFCN (type)) |
515 |
{ |
{ |
516 |
in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); |
in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); |
517 |
} |
} |
544 |
#ifdef COFF_ADJUST_AUX_OUT_PRE |
#ifdef COFF_ADJUST_AUX_OUT_PRE |
545 |
COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp); |
COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp); |
546 |
#endif |
#endif |
547 |
memset((PTR)ext, 0, AUXESZ); |
|
548 |
|
memset ((PTR)ext, 0, AUXESZ); |
549 |
|
|
550 |
switch (class) |
switch (class) |
551 |
{ |
{ |
552 |
case C_FILE: |
case C_FILE: |
692 |
#else |
#else |
693 |
aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc); |
aouthdr_int->o_toc = H_GET_32 (abfd, aouthdr_ext->o_toc); |
694 |
#endif |
#endif |
695 |
aouthdr_int->o_snentry = H_GET_16 (abfd, aouthdr_ext->o_snentry); |
aouthdr_int->o_snentry = H_GET_16 (abfd, aouthdr_ext->o_snentry); |
696 |
aouthdr_int->o_sntext = H_GET_16 (abfd, aouthdr_ext->o_sntext); |
aouthdr_int->o_sntext = H_GET_16 (abfd, aouthdr_ext->o_sntext); |
697 |
aouthdr_int->o_sndata = H_GET_16 (abfd, aouthdr_ext->o_sndata); |
aouthdr_int->o_sndata = H_GET_16 (abfd, aouthdr_ext->o_sndata); |
698 |
aouthdr_int->o_sntoc = H_GET_16 (abfd, aouthdr_ext->o_sntoc); |
aouthdr_int->o_sntoc = H_GET_16 (abfd, aouthdr_ext->o_sntoc); |
699 |
aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader); |
aouthdr_int->o_snloader = H_GET_16 (abfd, aouthdr_ext->o_snloader); |
700 |
aouthdr_int->o_snbss = H_GET_16 (abfd, aouthdr_ext->o_snbss); |
aouthdr_int->o_snbss = H_GET_16 (abfd, aouthdr_ext->o_snbss); |
701 |
aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext); |
aouthdr_int->o_algntext = H_GET_16 (abfd, aouthdr_ext->o_algntext); |
702 |
aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata); |
aouthdr_int->o_algndata = H_GET_16 (abfd, aouthdr_ext->o_algndata); |
703 |
aouthdr_int->o_modtype = H_GET_16 (abfd, aouthdr_ext->o_modtype); |
aouthdr_int->o_modtype = H_GET_16 (abfd, aouthdr_ext->o_modtype); |
704 |
aouthdr_int->o_cputype = H_GET_16 (abfd, aouthdr_ext->o_cputype); |
aouthdr_int->o_cputype = H_GET_16 (abfd, aouthdr_ext->o_cputype); |
705 |
#ifdef XCOFF64 |
#ifdef XCOFF64 |
706 |
aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack); |
aouthdr_int->o_maxstack = H_GET_64 (abfd, aouthdr_ext->o_maxstack); |
707 |
aouthdr_int->o_maxdata = H_GET_64 (abfd, aouthdr_ext->o_maxdata); |
aouthdr_int->o_maxdata = H_GET_64 (abfd, aouthdr_ext->o_maxdata); |
708 |
#else |
#else |
709 |
aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack); |
aouthdr_int->o_maxstack = H_GET_32 (abfd, aouthdr_ext->o_maxstack); |
710 |
aouthdr_int->o_maxdata = H_GET_32 (abfd, aouthdr_ext->o_maxdata); |
aouthdr_int->o_maxdata = H_GET_32 (abfd, aouthdr_ext->o_maxdata); |
711 |
#endif |
#endif |
712 |
#endif |
#endif |
713 |
|
|
714 |
#ifdef MIPSECOFF |
#ifdef MIPSECOFF |
715 |
aouthdr_int->bss_start = H_GET_32 (abfd, aouthdr_ext->bss_start); |
aouthdr_int->bss_start = H_GET_32 (abfd, aouthdr_ext->bss_start); |
716 |
aouthdr_int->gp_value = H_GET_32 (abfd, aouthdr_ext->gp_value); |
aouthdr_int->gp_value = H_GET_32 (abfd, aouthdr_ext->gp_value); |
717 |
aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); |
aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); |
718 |
aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]); |
aouthdr_int->cprmask[0] = H_GET_32 (abfd, aouthdr_ext->cprmask[0]); |
719 |
aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]); |
aouthdr_int->cprmask[1] = H_GET_32 (abfd, aouthdr_ext->cprmask[1]); |
720 |
aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]); |
aouthdr_int->cprmask[2] = H_GET_32 (abfd, aouthdr_ext->cprmask[2]); |
723 |
|
|
724 |
#ifdef ALPHAECOFF |
#ifdef ALPHAECOFF |
725 |
aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start); |
aouthdr_int->bss_start = H_GET_64 (abfd, aouthdr_ext->bss_start); |
726 |
aouthdr_int->gp_value = H_GET_64 (abfd, aouthdr_ext->gp_value); |
aouthdr_int->gp_value = H_GET_64 (abfd, aouthdr_ext->gp_value); |
727 |
aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); |
aouthdr_int->gprmask = H_GET_32 (abfd, aouthdr_ext->gprmask); |
728 |
aouthdr_int->fprmask = H_GET_32 (abfd, aouthdr_ext->fprmask); |
aouthdr_int->fprmask = H_GET_32 (abfd, aouthdr_ext->fprmask); |
729 |
#endif |
#endif |
730 |
} |
} |
731 |
|
|
818 |
#ifdef COFF_ADJUST_SCNHDR_IN_PRE |
#ifdef COFF_ADJUST_SCNHDR_IN_PRE |
819 |
COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in); |
COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in); |
820 |
#endif |
#endif |
821 |
memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name)); |
memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name)); |
822 |
|
|
823 |
scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr); |
scnhdr_int->s_vaddr = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr); |
824 |
scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr); |
scnhdr_int->s_paddr = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr); |
825 |
scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size); |
scnhdr_int->s_size = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size); |
878 |
buf, scnhdr_int->s_nlnno); |
buf, scnhdr_int->s_nlnno); |
879 |
PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno); |
PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno); |
880 |
} |
} |
881 |
|
|
882 |
if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC) |
if (scnhdr_int->s_nreloc <= MAX_SCNHDR_NRELOC) |
883 |
PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); |
PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc); |
884 |
else |
else |