From patchwork Fri May 25 08:03:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 136804 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3287207lji; Fri, 25 May 2018 01:29:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZofheXtXX6q4Iy0zTBL4FLE1Czy9Riqwsgzh5w3j/aqy1bXM1ePc6vRE4TtNRJrkCp1IreY X-Received: by 2002:a62:9099:: with SMTP id q25-v6mr1613547pfk.66.1527236957390; Fri, 25 May 2018 01:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527236957; cv=none; d=google.com; s=arc-20160816; b=F41QVbAAQAvT9yPeJhTTlxOycpw34jNqKombeGj9UCJwYSyZLDqcaZUIsoWXNCcTWp SevVd/h6J9/rwtfx4noMNbEDDty+N95mxJzDjxLQgTzkdYbOxy8jFNI4xBWkw/Fjn9Be T42YPzBXoMRtcIj7DiIWKJDMmhYR8N+FqBqIvPPG8Uw6CrRXrjsU/5fcYkXj1A0hJcMM YI0yg+/99MOpNU0KKh/QlUUvIjDFne8uAozpc8CPQYBSxoeR8/gCvMVdbDS5FiFgZftS Fp7AR/hsgWS7bqxHzKkPu5ip1zO9wI/R/11aPO/3nP/xAGzvamewExJtbqj5AC2RhYqb TqbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=RPOeGbdJzFCB1pDYmc4w+c8buGsv5I1hIqeTpZWUk+U=; b=TX+6HHc20DT+NKEYYYRevagvksaw2iHbtFzvVggEgI58eIgJQm4rMJmtJDM/WSVhZA TSZdlJwZ/yzNmK1/zkaE2/m/tKwZVv/OeazkmCeNGndw5l08xE3yw20BLDyShPp0ZyXJ gxIuWNvK74X4JkYRhg3GVkKW1EAza1x8+emEvCjDhvQKKw+QQItj+ZmjvlNU5bY2hlHH Liza6CiWwMkAhjj9TQAwMyz1gr05f33xyY3XnN9EOmZRMBiTIscs2FH2ZThKRNZ0Xu70 bLafQSYepmypi2sBugSCC2pGESQ8S3nNZE42RMTJfB8muxzWA3M0OHZeFY2j3f5G7CiY gwgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LJr5Tc7w; spf=pass (google.com: domain of gcc-patches-return-478473-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478473-patch=linaro.org@gcc.gnu.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v11-v6si13917198plo.130.2018.05.25.01.29.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 01:29:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478473-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 header.s=default header.b=LJr5Tc7w; spf=pass (google.com: domain of gcc-patches-return-478473-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478473-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=jT4 5IBA1qlFth5jwk0ImuoxFoNbs/AhEkl/VQ6zduNAMfOwuHTmQq1oGFqTkWr/UZGq QRgOpTdwoDoZ5WFtLHN7l4kvocXIBZsahaWAKOoXbNJ2MQ99SrxX/OO1eN1lgliD Smnyl1TfgDow19lf/1VzOI8WC6j3gnn2RFLcxkCc= 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:from :to:subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=default; bh=ah7aH7QzR T5DWlSVHVsEuzlFETU=; b=LJr5Tc7wO1+rcAymLjW2yMVmmvpiaIOSW/bzYAoXI Tw7ddAg1vFHB3fi+AcDFNNaMAa/yZ9GA1qiCoQ9ZhWBiVYSx5GsLw3zrpD4eFCqc 434z8PrmArhgi5ZRzG8szs8OyN/GeRfvPWKZ/Rpm21OpUIBEJeHEZL3dFcboRw4O UA= Received: (qmail 74215 invoked by alias); 25 May 2018 08:09:37 -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 43422 invoked by uid 89); 25 May 2018 08:07:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 May 2018 08:06:59 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fM7kV-0003GI-7s for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:06:58 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:10870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fM7kU-0003Fg-UR for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:06:55 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w4P7xBwp003910; Fri, 25 May 2018 10:06:52 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2j59prjvxf-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 25 May 2018 10:06:52 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B6B3434; Fri, 25 May 2018 08:06:51 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node1.st.com [10.75.127.13]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A18282405; Fri, 25 May 2018 08:06:51 +0000 (GMT) Received: from gnb.st.com (10.75.127.51) by SFHDAG5NODE1.st.com (10.75.127.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 25 May 2018 10:06:50 +0200 From: Christophe Lyon To: , Subject: [ARM/FDPIC 08/21] [ARM] FDPIC: Fix corner case of weak symbol Date: Fri, 25 May 2018 10:03:21 +0200 Message-ID: <20180525080354.13295-9-christophe.lyon@st.com> In-Reply-To: <20180525080354.13295-1-christophe.lyon@st.com> References: <20180525080354.13295-1-christophe.lyon@st.com> MIME-Version: 1.0 X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG5NODE1.st.com (10.75.127.13) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-25_03:, , signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 62.209.51.94 X-IsSubscribed: yes When checking the address of a weak symbol in an executable, it is mandatory to use the GOTFUNCDESC scheme so that the address==NULL semantic is valid if the symbol is not present in the final link. 2018-XX-XX Christophe Lyon Mickaël Guêné gcc/ * config/arm/arm.c (arm_local_funcdesc_p): New function. (legitimize_pic_address): Handle weak symbols in FDPIC mode. (arm_assemble_integer): Likewise. Change-Id: I3fa0b63bc0f672903f405aa72cc46052de1c0feb -- 2.6.3 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index bbf8884..025485d 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -3771,6 +3771,46 @@ arm_options_perform_arch_sanity_checks (void) } } +/* Test whether a local function descriptor is canonical, i.e., + whether we can use GOTOFFFUNCDESC to compute the address of the + function. */ +static bool +arm_local_funcdesc_p (rtx fnx) +{ + tree fn; + enum symbol_visibility vis; + bool ret; + + if (!TARGET_FDPIC) + return TRUE; + + if (! SYMBOL_REF_LOCAL_P (fnx)) + return FALSE; + + fn = SYMBOL_REF_DECL (fnx); + + if (! fn) + return FALSE; + + /* Local function declared as weak must use GOTFUNCDESC so their + FUNCDESC is NULL if they are not linked in. */ + if (DECL_WEAK(fn)) + return FALSE; + + vis = DECL_VISIBILITY (fn); + + if (vis == VISIBILITY_PROTECTED) + /* Private function descriptors for protected functions are not + canonical. Temporarily change the visibility to global. */ + vis = VISIBILITY_DEFAULT; + + ret = default_binds_local_p_1 (fn, flag_pic); + + DECL_VISIBILITY (fn) = vis; + + return ret; +} + static void arm_add_gc_roots (void) { @@ -7488,7 +7528,9 @@ legitimize_pic_address (rtx orig, machine_mode mode, rtx reg) || (GET_CODE (orig) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (orig) && (SYMBOL_REF_DECL (orig) - ? !DECL_WEAK (SYMBOL_REF_DECL (orig)) : 1))) + ? !DECL_WEAK (SYMBOL_REF_DECL (orig)) : 1) + && (!SYMBOL_REF_FUNCTION_P(orig) + || arm_local_funcdesc_p (orig)))) && NEED_GOT_RELOC && arm_pic_data_is_text_relative) insn = arm_pic_static_addr (orig, reg); @@ -23072,7 +23114,9 @@ arm_assemble_integer (rtx x, unsigned int size, int aligned_p) || (GET_CODE (x) == SYMBOL_REF && (!SYMBOL_REF_LOCAL_P (x) || (SYMBOL_REF_DECL (x) - ? DECL_WEAK (SYMBOL_REF_DECL (x)) : 0)))) + ? DECL_WEAK (SYMBOL_REF_DECL (x)) : 0) + || (SYMBOL_REF_FUNCTION_P (x) + && !arm_local_funcdesc_p (x))))) { if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x)) fputs ("(GOTFUNCDESC)", asm_out_file);