bfd/
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 8 Apr 2009 16:04:50 +0000 (16:04 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 8 Apr 2009 16:04:50 +0000 (16:04 +0000)
2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>

* elflink.c (elf_link_add_object_symbols): Warn alternate ELF
machine code.

include/

2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>

* bfdlink.h (bfd_link_info): Add warn_alternate_em.

ld/

2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>

* lexsup.c (option_values): Add OPTION_WARN_ALTERNATE_EM.
(ld_options): Likewise.
(parse_args): Likewise.

* ld.texinfo: Document --warn-alternate-em.

* NEWS: Mention --warn-alternate-em.

bfd/ChangeLog
bfd/elflink.c
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/NEWS
ld/ld.texinfo
ld/lexsup.c

index b0a62b4be5c5db6bd4d9f4d0354a46a5dd12884e..679211b1b87ffec8776ad7a98b11e0e8735737f8 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elflink.c (elf_link_add_object_symbols): Warn alternate ELF
+       machine code.
+
 2009-04-07  DJ Delorie  <dj@redhat.com>
 
        * archures.c: Add bfd_mach_mep_c5.
index b699b922f6d39443a36b264f00a668455823726e..3f70d915fc9f2859b740a697f501beb5c4c3a864 100644 (file)
@@ -3425,6 +3425,7 @@ _bfd_elf_relocs_compatible (const bfd_target *input,
 static bfd_boolean
 elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 {
+  Elf_Internal_Ehdr *ehdr;
   Elf_Internal_Shdr *hdr;
   bfd_size_type symcount;
   bfd_size_type extsymcount;
@@ -3480,6 +3481,17 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
        }
     }
 
+  ehdr = elf_elfheader (abfd);
+  if (info->warn_alternate_em
+      && bed->elf_machine_code != ehdr->e_machine
+      && ((bed->elf_machine_alt1 != 0
+          && ehdr->e_machine == bed->elf_machine_alt1)
+         || (bed->elf_machine_alt2 != 0
+             && ehdr->e_machine == bed->elf_machine_alt2)))
+    info->callbacks->einfo
+      (_("%P: alternate ELF machine code found (%d) in %B, expecting %d\n"),
+       ehdr->e_machine, abfd, bed->elf_machine_code);
+
   /* As a GNU extension, any input sections which are named
      .gnu.warning.SYMBOL are treated as warning symbols for the given
      symbol.  This differs from .gnu.warning sections, which generate
index fe68874638b13eb8540a1ea2519ded4002224904..dfe9fcee963fd2b877d33aec8ed9a047a3c1ab92 100644 (file)
@@ -1,3 +1,7 @@
+2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * bfdlink.h (bfd_link_info): Add warn_alternate_em.
+
 2009-03-18  Alan Modra  <amodra@bigpond.net.au>
 
        * alloca-conf.h: Revise based on autoconf-2.61, autoconf-2.13
index 51c5b15cd68187a497c1b182c6b36b75c657aaba..910281ad536f30c308fd44ec5c4a46c1255da0e8 100644 (file)
@@ -322,6 +322,9 @@ struct bfd_link_info
   /* TRUE if we should warn when adding a DT_TEXTREL to a shared object.  */
   unsigned int warn_shared_textrel: 1;
 
+  /* TRUE if we should warn alternate ELF machine code.  */
+  unsigned int warn_alternate_em: 1;
+
   /* TRUE if unreferenced sections should be removed.  */
   unsigned int gc_sections: 1;
 
index 316130761b7eaf8d1c71bac38ed08bc3e9fa74a8..7f97b499156a11faa92b2f09f93abef34b3342cc 100644 (file)
@@ -1,3 +1,13 @@
+2009-04-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * lexsup.c (option_values): Add OPTION_WARN_ALTERNATE_EM.
+       (ld_options): Likewise.
+       (parse_args): Likewise.
+
+       * ld.texinfo: Document --warn-alternate-em.
+
+       * NEWS: Mention --warn-alternate-em.
+
 2009-04-07  DJ Delorie  <dj@redhat.com>
 
        * emulparams/elf32mep.sh: Change default endian to little.
diff --git a/ld/NEWS b/ld/NEWS
index 440534ac83fb2c4d0b24f8447e189bfabb607769..621b489331c5cb216a48813b25dc3fbfa4ce10e8 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,8 @@
 -*- text -*-
 
+* ELF: --warn-alternate-em option to warn if an object has alternate
+  ELF machine code.
+
 * New script function REGION_ALIAS to add alias names to memory regions.
 
 * PE targets no longer make use of the long section names PE extension to
index 37c36b007120c43a675a7fb6c72e3dac29d74b03..ca460b3bdc4f5b2fe68b133dbb1ef1b4eb9dc05b 100644 (file)
@@ -1941,6 +1941,10 @@ the section (@pxref{SECTIONS}).
 @item --warn-shared-textrel
 Warn if the linker adds a DT_TEXTREL to a shared object.
 
+@kindex --warn-alternate-em
+@item --warn-alternate-em
+Warn if an object has alternate ELF machine code.
+
 @kindex --warn-unresolved-symbols
 @item --warn-unresolved-symbols
 If the linker is going to report an unresolved symbol (see the option
index 3ddde61c4ab292e58b9a39850776c25919d43066..f1b5b4c0ffe11e832f9da872655f9f1538bcf9f8 100644 (file)
@@ -163,6 +163,7 @@ enum option_values
   OPTION_WARN_UNRESOLVED_SYMBOLS,
   OPTION_ERROR_UNRESOLVED_SYMBOLS,
   OPTION_WARN_SHARED_TEXTREL,
+  OPTION_WARN_ALTERNATE_EM,
   OPTION_REDUCE_MEMORY_OVERHEADS,
   OPTION_DEFAULT_SCRIPT
 };
@@ -555,6 +556,9 @@ static const struct ld_option ld_options[] =
   { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
     '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
     TWO_DASHES },
+  { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
+    '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
+    TWO_DASHES },
   { {"warn-unresolved-symbols", no_argument, NULL,
      OPTION_WARN_UNRESOLVED_SYMBOLS},
     '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
@@ -1359,6 +1363,9 @@ parse_args (unsigned argc, char **argv)
        case OPTION_WARN_SHARED_TEXTREL:
          link_info.warn_shared_textrel = TRUE;
          break;
+       case OPTION_WARN_ALTERNATE_EM:
+         link_info.warn_alternate_em = TRUE;
+         break;
        case OPTION_WHOLE_ARCHIVE:
          whole_archive = TRUE;
          break;