From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8568 invoked by alias); 3 Feb 2015 21:36:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8534 invoked by uid 89); 3 Feb 2015 21:36:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_50,KAM_STOCKGEN,RCVD_IN_DNSWL_LOW,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail-vc0-f173.google.com Received: from mail-vc0-f173.google.com (HELO mail-vc0-f173.google.com) (209.85.220.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 03 Feb 2015 21:35:59 +0000 Received: by mail-vc0-f173.google.com with SMTP id id10so17643205vcb.4 for ; Tue, 03 Feb 2015 13:35:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=RO/2KSnTR/t+17LHBNSYeBGOPrl3Kp71yJNd5PuY3ag=; b=GzTmL8doBO2G8p+18fArM8HbJ14uk8TJjW+9k6vudnnUkyv+ejHrPgqzX/5F33ySii Lc0IiO1Dlp/jQkZp5exkV6uSL7+JxppAK5pqLDuoAp585yf15GbVMAzpMcoB1mrHvSCo U5MhxBqWIUXmKbL6XHyP70Z52f3Lj6SipS2VxNoT7qZpfqoui+Dpl/7VtK6uL9m5ibTZ rbpvUxc7+qPJgy7nwRLs8ZbiwM8xmUeFh50R9XYRU3s6IzwEcr4WuZhgE0l7wWS59Cs3 KpWzZB9M3GQcdqmaE6hmGCTpE+ULmKD4kPFmdCwtsOitj5xWPZsCzHOGmIVYg1oFqIK4 V8fw== X-Gm-Message-State: ALoCoQkfGGkabvYKAbEhbFkY0sVSpr2FXHlj1O81/jRc9Yli/yRlT59TT/WP+cWC8xLG5BzlAvwi MIME-Version: 1.0 X-Received: by 10.221.64.73 with SMTP id xh9mr17574375vcb.71.1422999357501; Tue, 03 Feb 2015 13:35:57 -0800 (PST) Received: by 10.52.37.114 with HTTP; Tue, 3 Feb 2015 13:35:57 -0800 (PST) In-Reply-To: References: <20150203193615.GZ1746@tucnak.redhat.com> Date: Tue, 03 Feb 2015 21:36:00 -0000 Message-ID: Subject: Re: [PATCH x86_64] Optimize access to globals in "-fpie -pie" builds with copy relocations From: Sriraman Tallam To: "H.J. Lu" Cc: Jakub Jelinek , Uros Bizjak , "gcc-patches@gcc.gnu.org" , David Li , Cary Coutant Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-02/txt/msg00166.txt.bz2 On Tue, Feb 3, 2015 at 1:29 PM, H.J. Lu wrote: > On Tue, Feb 3, 2015 at 1:20 PM, Sriraman Tallam wrote: >> On Tue, Feb 3, 2015 at 11:36 AM, Jakub Jelinek wrote: >>> On Tue, Feb 03, 2015 at 11:25:38AM -0800, Sriraman Tallam wrote: >>>> This was the original patch to i386.c to let global accesses take >>>> advantage of copy relocations and avoid the GOT. >>>> >>>> >>>> @@ -13113,7 +13113,11 @@ legitimate_pic_address_disp_p (rtx disp) >>>> return true; >>>> } >>>> else if (!SYMBOL_REF_FAR_ADDR_P (op0) >>>> - && SYMBOL_REF_LOCAL_P (op0) >>>> + && (SYMBOL_REF_LOCAL_P (op0) >>>> + || (HAVE_LD_PIE_COPYRELOC >>>> + && flag_pie >>>> + && !SYMBOL_REF_WEAK (op0) >>>> + && !SYMBOL_REF_FUNCTION_P (op0))) >>>> && ix86_cmodel != CM_LARGE_PIC) >>>> >>>> I do not understand here why weak global data access must go through >>>> the GOT and not use copy relocations. Ultimately, there is only going >>>> to be one copy of the global either defined in the executable or the >>>> shared object right? >>>> >>>> Can we remove the check for SYMBOL_REF_WEAK? >>> >>> So, what will then happen if the weak undef symbol isn't defined anywhere? >>> In non-PIE binaries that is fine, the linker will store 0. >>> But in PIE binaries, the 0 would be biased by the PIE load bias and thus >>> wouldn't be NULL. >> >> Thanks for clarifying. >> >>> You can only optimize weak vars if there is some weak definition in the >>> current TU. >> >> Would this be fine then? Replace !SYMBOL_REF_WEAK (op0) with >> >> !(SYMBOL_REF_WEAK (op0) && SYMBOL_REF_EXTERNAL_P (op0)) >> > > The full condition is: > > && (SYMBOL_REF_LOCAL_P (op0) > || (HAVE_LD_PIE_COPYRELOC > && flag_pie > && !SYMBOL_REF_WEAK (op0) > && !SYMBOL_REF_FUNCTION_P (op0))) > > If the weak op0 is defined in the current TU, shouldn't > SYMBOL_REF_LOCAL_P (op0) be true for PIE? Thats not what I see for this: zap.cc --------- __attribute__((weak)) int glob; int main() { printf("%d\n", glob); } (gdb) p debug_rtx(op0) (symbol_ref/i:DI ("glob") ) (gdb) p SYMBOL_REF_LOCAL_P(op0) $4 = false (gdb) p SYMBOL_REF_WEAK (op0) $5 = 1 (gdb) p SYMBOL_REF_EXTERNAL_P (op0) $6 = false Thanks Sri > > -- > H.J.