* lto-elf.c (is_compatible_architecture): New static function.
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 3 Mar 2010 10:29:22 +0000 (10:29 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 3 Mar 2010 10:29:22 +0000 (10:29 +0000)
(DEFINE_VALIDATE_EHDR): Use it to validate the architecture.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157192 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/lto/ChangeLog
gcc/lto/lto-elf.c

index 58e5123..560539d 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-03  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * lto-elf.c (is_compatible_architecture): New static function.
+       (DEFINE_VALIDATE_EHDR): Use it to validate the architecture.
+
 2010-02-11  Richard Guenther  <rguenther@suse.de>
 
        PR driver/43021
index 356e513..0135284 100644 (file)
@@ -374,6 +374,38 @@ lto_elf_end_section (void)
 }
 
 
+/* Return true if ELF_MACHINE is compatible with the cached value of the
+   architecture and possibly update the latter.  Return false otherwise.  */
+
+static bool
+is_compatible_architecture (Elf64_Half elf_machine)
+{
+  if (cached_file_attrs.elf_machine == elf_machine)
+    return true;
+
+  switch (cached_file_attrs.elf_machine)
+    {
+    case EM_SPARC:
+      if (elf_machine == EM_SPARC32PLUS)
+       {
+         cached_file_attrs.elf_machine = elf_machine;
+         return true;
+       }
+      break;
+
+    case EM_SPARC32PLUS:
+      if (elf_machine == EM_SPARC)
+       return true;
+      break;
+
+    default:
+      break;
+    }
+
+  return false;
+}
+
+
 /* Validate's ELF_FILE's executable header and, if cached_file_attrs is
    uninitialized, caches the architecture.  */
 
@@ -398,8 +430,7 @@ validate_ehdr##BITS (lto_elf_file *elf_file)                        \
                                                                \
   if (!cached_file_attrs.initialized)                          \
     cached_file_attrs.elf_machine = elf_header->e_machine;     \
-                                                               \
-  if (cached_file_attrs.elf_machine != elf_header->e_machine)  \
+  else if (!is_compatible_architecture (elf_header->e_machine))        \
     {                                                          \
       error ("inconsistent file architecture detected");       \
       return false;                                            \