From 05bf877ad11654a983d2ed5d31370e4469a657f0 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 11 Sep 1999 22:41:54 +0000 Subject: [PATCH] 1999-09-11 Donn Terry * peicode.h (coff_swap_filehdr_in): Check the NT executable magic number if COFF_IMAGE_WITH_PE. --- bfd/ChangeLog | 3 +++ bfd/peicode.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 26ffe3d479..e5f738333e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -7,6 +7,9 @@ 1999-09-11 Donn Terry + * peicode.h (coff_swap_filehdr_in): Check the NT executable magic + number if COFF_IMAGE_WITH_PE. + * coffcode.h (coff_mkobject_hook): If COFF_WITH_PE, set HAS_DEBUG to the reverse of IMAGE_FILE_DEBUG_STRIPPED. (coff_write_object_contents): Set IMAGE_FILE_DEBUG_STRIPPED if diff --git a/bfd/peicode.h b/bfd/peicode.h index e7bab8492e..2a19565938 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -295,6 +295,21 @@ coff_swap_filehdr_in (abfd, src, dst) filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags); filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr); +#ifdef COFF_IMAGE_WITH_PE + /* There are really two magic numbers involved; the magic number + that says this is a NT executable (PEI) and the magic number that + determines the architecture. The former is DOSMAGIC, stored in + the e_magic field. The latter is stored in the f_magic field. + If the NT magic number isn't valid, the architecture magic number + could be mimicked by some other field (specifically, the number + of relocs in section 3). Since this routine can only be called + correctly for a PEI file, check the e_magic number here, and, if + it doesn't match, clobber the f_magic number so that we don't get + a false match. */ + if (bfd_h_get_16 (abfd, (bfd_byte *) filehdr_src->e_magic) != DOSMAGIC) + filehdr_dst->f_magic = -1; +#endif + /* Other people's tools sometimes generate headers with an nsyms but a zero symptr. */ if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)