From patchwork Tue Mar 12 12:41:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 227013 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 167F12C02A2 for ; Tue, 12 Mar 2013 23:41:43 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1363696904; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=NTtXkUNLua0a+ImNlBzT2y44kT0=; b=wEuh9lNu5V5EF2J S6GRm8AxcG4o6fDySaqHZ903gL8Otq4KBS5o58MPZG1OHdvnjZRrufpskU/6R9v8 L3ggUanQeNmORNVmIhnvlceWZduOsVQqff9CU26U5mAPOzOFvr7J3FEE5iTKEAfL N4MLfQ9/w3h9jsDQFy1x4qlWdrgM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=u/WxTcqJGwmMSLV909kiOssy+NrLhcwZAoDbt+p/cGbwYONVc129HYC2mLcalu Mx0z/xL5Cfe+uVcOWt28ro/83QwRvlb2xinr2ao8X6ZZOB6uVTE1cVg/FxZS9A24 aYTaWe63xKPQ2YqJ83B95zD7cSfD4zzY+jIGHnWCEu1w0=; Received: (qmail 27889 invoked by alias); 12 Mar 2013 12:41:33 -0000 Received: (qmail 27697 invoked by uid 22791); 12 Mar 2013 12:41:31 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Mar 2013 12:41:20 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id AAE325418AF; Tue, 12 Mar 2013 13:41:17 +0100 (CET) Date: Tue, 12 Mar 2013 13:41:17 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Do not output references from external vtables into LTO symbol table Message-ID: <20130312124117.GA9858@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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, this patch fixes GCC side of PR 56557 where we fail to link #include int main() { std::fstream x; } with -flto -rdynamic because we do not see definition of _ZTCSt13basic_fstreamIcSt11char_traitsIcEE0_Sd. This symbol mistakely appears in lto symbol table because it is used from external constructor that is kept around only for optimization. There is also BFD linker bug that create stale dynamic table entries for these kind of symbols. Bootstrapped®tested x86_64-linux, tested on Mozilla and Qt LTO build, comitted. Honza PR lto/56557 * lto-streamer-out.c (output_symbol_p): Skip references from constructors of external variables. Index: lto-streamer-out.c =================================================================== --- lto-streamer-out.c (revision 196611) +++ lto-streamer-out.c (working copy) @@ -1265,17 +1265,36 @@ bool output_symbol_p (symtab_node node) { struct cgraph_node *cnode; - struct ipa_ref *ref; - if (!symtab_real_symbol_p (node)) return false; /* We keep external functions in symtab for sake of inlining and devirtualization. We do not want to see them in symbol table as - references. */ + references unless they are really used. */ cnode = dyn_cast (node); - if (cnode && DECL_EXTERNAL (cnode->symbol.decl)) - return (cnode->callers - || ipa_ref_list_referring_iterate (&cnode->symbol.ref_list, 0, ref)); + if (cnode && DECL_EXTERNAL (cnode->symbol.decl) + && cnode->callers) + return true; + + /* Ignore all references from external vars initializers - they are not really + part of the compilation unit until they are used by folding. Some symbols, + like references to external construction vtables can not be referred to at all. + We decide this at can_refer_decl_in_current_unit_p. */ + if (DECL_EXTERNAL (node->symbol.decl)) + { + int i; + struct ipa_ref *ref; + for (i = 0; ipa_ref_list_referring_iterate (&node->symbol.ref_list, + i, ref); i++) + { + if (ref->use == IPA_REF_ALIAS) + continue; + if (is_a (ref->referring)) + return true; + if (!DECL_EXTERNAL (ref->referring->symbol.decl)) + return true; + } + return false; + } return true; }