This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Warn alternate ELF machine code
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sources dot redhat dot com
- Date: Tue, 7 Apr 2009 13:10:16 -0700
- Subject: PATCH: Warn alternate ELF machine code
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
This patch adds an option, --warn-alternate-em, to issue a warning if
an object has alternate ELF machine code. The default is off. OK for
trunk?
Thanks.
H.J.
---
bfd/
2009-04-07 H.J. Lu <hongjiu.lu@intel.com>
* elflink.c (elf_link_add_object_symbols): Warn alternate ELF
machine code.
include/
2009-04-07 H.J. Lu <hongjiu.lu@intel.com>
* bfdlink.h (bfd_link_info): Add warn_alternate_em.
ld/
2009-04-07 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.
Index: ld/lexsup.c
===================================================================
--- ld/lexsup.c (revision 5628)
+++ ld/lexsup.c (working copy)
@@ -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;
Index: ld/NEWS
===================================================================
--- ld/NEWS (revision 5628)
+++ ld/NEWS (working copy)
@@ -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: ld/ld.texinfo
===================================================================
--- ld/ld.texinfo (revision 5628)
+++ ld/ld.texinfo (working copy)
@@ -1935,6 +1935,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: include/bfdlink.h
===================================================================
--- include/bfdlink.h (revision 5628)
+++ include/bfdlink.h (working copy)
@@ -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: bfd/elflink.c
===================================================================
--- bfd/elflink.c (revision 5628)
+++ bfd/elflink.c (working copy)
@@ -3425,6 +3425,7 @@ _bfd_elf_relocs_compatible (const bfd_ta
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,
}
}
+ 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: warning: alternate ELF machine code (%d): %B\n"),
+ ehdr->e_machine, abfd);
+
/* 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