From patchwork Tue May 20 20:04:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 350825 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A125314008A for ; Wed, 21 May 2014 06:04:57 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=GYLDHAR9s8wZYMbqaamZ8/w4NGo/CAoxp5aDq2AweEkm0EDuFbFwt 5k9umMOumdNl22AqhGxnCjbe3/2dsFQz872wL8JRcX9hKFnKaryuiHyieqqXv+/1 FqKcmSCDtwgMUUQ10v1PxYZe83NccrarjztROOLxsIWb9xDyAsU4fU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ceFxtXBdKYq4eGPle+bFHVVhkx8=; b=O9T8c0m+5KmA8dXqmsrM C22xC5WxQm4vaGjaq0/coiB6TnCSpLbaaFOye8fqscV27fyQ9yG4keh9pHrTgmYh mi1m9EIKeu9yr5Q45UD1Ob8souVOUGK6djvk8zUomQa4gdjGFdpXSssHU/v3d2kG 9Y2gjRW2NhYAJjdH4+Gg04w= Received: (qmail 734 invoked by alias); 20 May 2014 20:04:43 -0000 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 Received: (qmail 649 invoked by uid 89); 20 May 2014 20:04:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 20 May 2014 20:04:36 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id BCBAC540670; Tue, 20 May 2014 22:04:32 +0200 (CEST) Date: Tue, 20 May 2014 22:04:32 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Add flag to optionally ignore ELF interposition Message-ID: <20140520200432.GA609@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, as disucssed some time ago, our assumption that every symbol of shared library can be interposed at runtime is expensive and prevents a lot of useful optimizations, including inlining or IPA propagation. While this is useful feature, it is rather incommon to use it for bigger C++ projects, like firefox and at least clang seems to ignore the ELF interposition rules and always inline/propagate. This patch adds flag to control the behaviour. Symbols explicitly delcared WEAK are still considered as interposable. Bootstrapped/regtested x86_64-linux, will commit it tomorrow if there are no complains. (Feedback is welcome!) Honza * doc/invoke.texi (-fsemantic-interposition): New flag. * common.opt (fsemantic-interposition): Use it. * varasm.c (decl_replaceable_p): Use it. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 210653) +++ doc/invoke.texi (working copy) @@ -411,6 +411,7 @@ Objective-C and Objective-C++ Dialects}. -fschedule-insns -fschedule-insns2 -fsection-anchors @gol -fselective-scheduling -fselective-scheduling2 @gol -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops @gol +-fsemantic-interposition @gol -fshrink-wrap -fsignaling-nans -fsingle-precision-constant @gol -fsplit-ivs-in-unroller -fsplit-wide-types -fstack-protector @gol -fstack-protector-all -fstack-protector-strong -fstrict-aliasing @gol @@ -7709,6 +7710,22 @@ This option has no effect unless one of When pipelining loops during selective scheduling, also pipeline outer loops. This option has no effect unless @option{-fsel-sched-pipelining} is turned on. +@item -fsemantic-interposition +@opindex fsemantic-interposition +Some object formats, like ELF, allow interposing of symbols by dynamic linker. +This means that for symbols exported from the DSO compiler can not perform +inter-procedural propagation, inlining and other optimizations in anticipation +that the function or variable in question may change. While this feature is +useful, for example, to rewrite memory allocation functions by a debugging +implementation, it is expensive in the terms of code quality. +With @option{-fno-semantic-inteposition} compiler assumest that if interposition +happens for functions the overwritting function will have +precisely same semantics (and side effects). Similarly if interposition happens +for variables, the constructor of the variable will be the same. The flag +has no effect for functions explicitly declared inline, where +interposition changing semantic is never allowed and for symbols explicitly +declared weak. + @item -fshrink-wrap @opindex fshrink-wrap Emit function prologues only before parts of the function that need it, Index: common.opt =================================================================== --- common.opt (revision 210653) +++ common.opt (working copy) @@ -1854,6 +1854,10 @@ fsel-sched-reschedule-pipelined Common Report Var(flag_sel_sched_reschedule_pipelined) Init(0) Optimization Reschedule pipelined regions without pipelining +fsemantic-interposition +Common Report Var(flag_semantic_interposition) Init(1) +Allow interposing function (or variables) by ones with different semantics (or initializer) respectively by dynamic linker + ; sched_stalled_insns means that insns can be moved prematurely from the queue ; of stalled insns into the ready list. fsched-stalled-insns Index: varasm.c =================================================================== --- varasm.c (revision 210654) +++ varasm.c (working copy) @@ -6870,6 +6870,9 @@ decl_replaceable_p (tree decl) gcc_assert (DECL_P (decl)); if (!TREE_PUBLIC (decl) || DECL_COMDAT (decl)) return false; + if (!flag_semantic_interposition + && !DECL_WEAK (decl)) + return false; return !decl_binds_to_current_def_p (decl); }