From patchwork Thu Dec 1 14:27:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 86064 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp717203qgi; Thu, 1 Dec 2016 06:28:26 -0800 (PST) X-Received: by 10.84.175.234 with SMTP id t97mr85193747plb.145.1480602506631; Thu, 01 Dec 2016 06:28:26 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g80si407621pfb.21.2016.12.01.06.28.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2016 06:28:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443215-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443215-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443215-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=Lx2d/yThAZwFx6e 1hU4Bldlq+1t78zYABYqy13teWD8tCtNzTF4a8WC5unmN2o2p7yAXdiPLSz97AVH d/FNMLJO7jbi1SEeCg7NvJ2b0oc6skafQHQzue37uHMk007jbfd9fse2Jwdl8YX1 oRD4g1ey9SKvwpi7ez8xgo8vBCyQ= 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=w+9pfNVZRTiR8d/1/hwMo BS94gA=; b=lzLYMr7TT+XDUsPDgYrKm8TyoOv3G2a1zr5blr+gydB2stCNNTUR/ lp1n3m5urCdS2qGvyPA29QTkw/K/3aiCQsgADOIZAhuXmDPuSn4yqxnGf/WJ6Lur hNLUIOCt7cBX1czxX3RUZvW+NYQo12mh4UjzXCjZuY76faldz9S9uo= Received: (qmail 18104 invoked by alias); 1 Dec 2016 14:27:30 -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 17955 invoked by uid 89); 1 Dec 2016 14:27:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:Richard, U*Richard.Earnshaw, GOTOFF, sk:legitim X-HELO: mail-qk0-f174.google.com Received: from mail-qk0-f174.google.com (HELO mail-qk0-f174.google.com) (209.85.220.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Dec 2016 14:27:19 +0000 Received: by mail-qk0-f174.google.com with SMTP id q130so58496209qke.1 for ; Thu, 01 Dec 2016 06:27:19 -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:from:date :message-id:subject:to:cc; bh=tWRt0tzdpu9Bw7TAlhGYvmnOZgVAg2V0BEFOJ/2M/Zw=; b=OerN+IBXFepj/yCFuxjgWe3f2fV5W2fhYcHgsUQ2c6ijZX0rKyIVgNG4e84wEcVJuK N49D/3YCjP+jeeU42htFSYBmOIbZIqHV8rWLT+Q/C//OX222RGe+YZ47Pu5fgB5RlX5U 1fUFc2xMr/8Rmo5FaTxvKwIKicw2pbKn8x5oAHwQJq7Ylr5hVpDuzPUZvZ2OOK+4uXL+ 5GVHKCFxcU3IoldmpxSOUxO3RHgRdmH6L806LvP+HJow5UCwyr4Fv1KaUiIJZSREAaWl JoW6tBs4dg0Ey4YzGNUNNreLxDKKLjsB+CtPi6FQSkQkkyU9MjO4NR//zmD5Mqf+MjbM 4eJQ== X-Gm-Message-State: AKaTC03Rw9/BBdU+BK59n3EcUyG7PJgRbp0O7/JFWirlr5vt5F7u74SYhjytWbaD3qlnRGZq41lASRF/HWs1YAuC X-Received: by 10.55.75.17 with SMTP id y17mr25501289qka.26.1480602437608; Thu, 01 Dec 2016 06:27:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.101.144 with HTTP; Thu, 1 Dec 2016 06:27:16 -0800 (PST) In-Reply-To: References: <22e91ae6-7a21-3fd6-c85f-7021571b0c5e@foss.arm.com> From: Christophe Lyon Date: Thu, 1 Dec 2016 15:27:16 +0100 Message-ID: Subject: Re: [ARM] PR 78253 do not resolve weak ref locally To: Richard Earnshaw Cc: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes Hi, On 10 November 2016 at 15:10, Christophe Lyon wrote: > On 10 November 2016 at 11:05, Richard Earnshaw > wrote: >> On 09/11/16 21:29, Christophe Lyon wrote: >>> Hi, >>> >>> PR 78253 shows that the handling of weak references has changed for >>> ARM with gcc-5. >>> >>> When r220674 was committed, default_binds_local_p_2 gained a new >>> parameter (weak_dominate), which, when true, implies that a reference >>> to a weak symbol defined locally will be resolved locally, even though >>> it could be overridden by a strong definition in another object file. >>> >>> With r220674, default_binds_local_p forces weak_dominate=true, >>> effectively changing the previous behavior. >>> >>> The attached patch introduces default_binds_local_p_4 which is a copy >>> of default_binds_local_p_2, but using weak_dominate=false, and updates >>> the ARM target to call default_binds_local_p_4 instead of >>> default_binds_local_p_2. >>> >>> I ran cross-tests on various arm* configurations with no regression, >>> and checked that the test attached to the original bugzilla now works >>> as expected. >>> >>> I am not sure why weak_dominate defaults to true, and I couldn't >>> really understand why by reading the threads related to r220674 and >>> following updates to default_binds_local_p_* which all deal with other >>> corner cases and do not discuss the weak_dominate parameter. >>> >>> Or should this patch be made more generic? >>> >> >> I certainly don't think it should be ARM specific. > That was my feeling too. > >> >> The questions I have are: >> >> 1) What do other targets do today. Are they the same, or different? > > arm, aarch64, s390 use default_binds_local_p_2 since PR 65780, and > default_binds_local_p before that. Both have weak_dominate=true > i386 has its own version, calling default_binds_local_p_3 with true > for weak_dominate > > But the behaviour of default_binds_local_p changed with r220674 as I said above. > See https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=220674 and > notice how weak_dominate was introduced > > The original bug report is about a different case: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32219 > > The original patch submission is > https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00410.html > and the 1st version with weak_dominate is in: > https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00469.html > but it's not clear to me why this was introduced > >> 2) If different why? > on aarch64, although binds_local_p returns true, the relocations used when > building the function pointer is still the same (still via the GOT). > > aarch64 has different logic than arm when accessing a symbol > (eg aarch64_classify_symbol) > >> 3) Is the current behaviour really what was intended by the patch? ie. >> Was the old behaviour actually wrong? >> > That's what I was wondering. > Before r220674, calling a weak function directly or via a function > pointer had the same effect (in other words, the function pointer > points to the actual implementation: the strong one if any, the weak > one otherwise). > > After r220674, on arm the function pointer points to the weak > definition, which seems wrong to me, it should leave the actual > resolution to the linker. > > After looking at the aarch64 port, I think that references to weak symbols have to be handled carefully, to make sure they cannot be resolved by the assembler, since the weak symbol can be overridden by a strong definition at link-time. Here is a new patch which does that. Validated on arm* targets with no regression, and I checked that the original testcase now executes as expected. Christophe >> R. >>> Thanks, >>> >>> Christophe >>> >> gcc/ChangeLog: 2016-12-01 Christophe Lyon PR target/78253 * config/arm/arm.c (legitimize_pic_address): Handle reference to weak symbol. (arm_assemble_integer): Likewise. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 74cb64c..258ceb1 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -6923,10 +6923,13 @@ legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) same segment as the GOT. Unfortunately, the flexibility of linker scripts means that we can't be sure of that in general, so assume that GOTOFF is never valid on VxWorks. */ + /* References to weak symbols cannot be resolved locally: they + may be overridden by a strong definition at link time. */ rtx_insn *insn; if ((GET_CODE (orig) == LABEL_REF - || (GET_CODE (orig) == SYMBOL_REF && - SYMBOL_REF_LOCAL_P (orig))) + || (GET_CODE (orig) == SYMBOL_REF + && SYMBOL_REF_LOCAL_P (orig) + && (SYMBOL_REF_DECL(orig) ? !DECL_WEAK(SYMBOL_REF_DECL(orig)) : 1))) && NEED_GOT_RELOC && arm_pic_data_is_text_relative) insn = arm_pic_static_addr (orig, reg); @@ -21583,8 +21586,13 @@ arm_assemble_integer (rtx x, unsigned int size, int aligned_p) { /* See legitimize_pic_address for an explanation of the TARGET_VXWORKS_RTP check. */ + /* References to weak symbols cannot be resolved locally: + they may be overridden by a strong definition at link + time. */ if (!arm_pic_data_is_text_relative - || (GET_CODE (x) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (x))) + || (GET_CODE (x) == SYMBOL_REF + && (!SYMBOL_REF_LOCAL_P (x) + || (SYMBOL_REF_DECL(x) ? DECL_WEAK(SYMBOL_REF_DECL(x)) : 0)))) fputs ("(GOT)", asm_out_file); else fputs ("(GOTOFF)", asm_out_file);