From patchwork Wed Jul 7 18:11:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix LTO handling of ELFOSABI_NONE vs. ELFOSABI_LINUX objects Date: Wed, 07 Jul 2010 08:11:48 -0000 From: Jakub Jelinek X-Patchwork-Id: 58140 Message-Id: <20100707181148.GF20208@tyan-ft48-01.lab.bos.redhat.com> To: gcc-patches@gcc.gnu.org Hi! As reported by Honza on IRC, lto fails when mixing ELFOSABI_LINUX *.o files with ELFOSABI_NONE *.o files. The latter is what has been used on Linux until recently, ELFOSABI_LINUX is only used when the object uses some GNU specific ELF features like STB_GNU_UNIQUE or STT_GNU_IFUNC. The following patch allows merging those two, with the result being ELFOSABI_LINUX. Bootstrapped/regtested on x86_64-linux and i686-linux, tested by Honza on Mozilla or where he was seeing the failure. Ok for trunk? 2010-07-07 Jakub Jelinek * lto-elf.c (ELFOSABI_NONE, ELFOSABI_LINUX): Define if not defined. (validate_file): Allow merging of ELFOSABI_NONE with ELFOSABI_LINUX objects. Jakub --- gcc/lto/lto-elf.c.jj 2010-05-25 11:27:37.000000000 +0200 +++ gcc/lto/lto-elf.c 2010-07-06 18:25:43.000000000 +0200 @@ -38,6 +38,13 @@ along with GCC; see the file COPYING3. # define EM_SPARC32PLUS 18 #endif +#ifndef ELFOSABI_NONE +# define ELFOSABI_NONE 0 +#endif +#ifndef ELFOSABI_LINUX +# define ELFOSABI_LINUX 3 +#endif + /* Handle opening elf files on hosts, such as Windows, that may use text file handling that will break binary access. */ @@ -519,10 +526,29 @@ validate_file (lto_elf_file *elf_file) memcpy (cached_file_attrs.elf_ident, elf_ident, sizeof cached_file_attrs.elf_ident); } + else + { + char elf_ident_buf[EI_NIDENT]; + + memcpy (elf_ident_buf, elf_ident, + sizeof elf_ident_buf); + + if (elf_ident_buf[EI_OSABI] != cached_file_attrs.elf_ident[EI_OSABI]) + { + /* Allow mixing ELFOSABI_NONE with ELFOSABI_LINUX, with the result + ELFOSABI_LINUX. */ + if (elf_ident_buf[EI_OSABI] == ELFOSABI_NONE + && cached_file_attrs.elf_ident[EI_OSABI] == ELFOSABI_LINUX) + elf_ident_buf[EI_OSABI] = cached_file_attrs.elf_ident[EI_OSABI]; + else if (elf_ident_buf[EI_OSABI] == ELFOSABI_LINUX + && cached_file_attrs.elf_ident[EI_OSABI] == ELFOSABI_NONE) + cached_file_attrs.elf_ident[EI_OSABI] = elf_ident_buf[EI_OSABI]; + } - if (memcmp (elf_ident, cached_file_attrs.elf_ident, - sizeof cached_file_attrs.elf_ident)) - return false; + if (memcmp (elf_ident_buf, cached_file_attrs.elf_ident, + sizeof cached_file_attrs.elf_ident)) + return false; + } /* Check that the input file is a relocatable object file with the correct architecture. */