From patchwork Wed Jul 7 18:11:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 58140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 315ECB6F0C for ; Thu, 8 Jul 2010 04:10:41 +1000 (EST) Received: (qmail 7931 invoked by alias); 7 Jul 2010 18:10:37 -0000 Received: (qmail 7891 invoked by uid 22791); 7 Jul 2010 18:10:35 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CP, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Jul 2010 18:10:30 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o67IASRq000385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Jul 2010 14:10:28 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o67IARZf003666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 Jul 2010 14:10:28 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o67IBmN8019335 for ; Wed, 7 Jul 2010 20:11:48 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o67IBmJn019334 for gcc-patches@gcc.gnu.org; Wed, 7 Jul 2010 20:11:48 +0200 Date: Wed, 7 Jul 2010 20:11:48 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix LTO handling of ELFOSABI_NONE vs. ELFOSABI_LINUX objects Message-ID: <20100707181148.GF20208@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list 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. */