From: Eric Botcazou Date: Wed, 3 Mar 2010 10:29:22 +0000 (+0000) Subject: lto-elf.c (is_compatible_architecture): New static function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bef7d288df865ca1b76d20b56f2883b1338ea285;p=gcc.git lto-elf.c (is_compatible_architecture): New static function. * lto-elf.c (is_compatible_architecture): New static function. (DEFINE_VALIDATE_EHDR): Use it to validate the architecture. From-SVN: r157192 --- diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index 58e51231bf1..560539d4ee2 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,8 @@ +2010-03-03 Eric Botcazou + + * lto-elf.c (is_compatible_architecture): New static function. + (DEFINE_VALIDATE_EHDR): Use it to validate the architecture. + 2010-02-11 Richard Guenther PR driver/43021 diff --git a/gcc/lto/lto-elf.c b/gcc/lto/lto-elf.c index 356e5139536..013528486ea 100644 --- a/gcc/lto/lto-elf.c +++ b/gcc/lto/lto-elf.c @@ -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; \