From patchwork Fri May 25 08:03:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 136805 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3287346lji; Fri, 25 May 2018 01:29:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqOMuzQdFxgvVtf4S44BgwFcWgXP88W2EJLLE8MeRuuUp8LEU4fh7Hmn1heANij4Dj+wEA1 X-Received: by 2002:a17:902:680c:: with SMTP id h12-v6mr1629620plk.113.1527236968972; Fri, 25 May 2018 01:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527236968; cv=none; d=google.com; s=arc-20160816; b=fWhYc4Abp65bx1MtZaOrW/7PEy/eWf/XP0W+u41IzzjiYt+fOtJ0cSHZiz8vg1W8li Ih4l6GYAtzYGfIR90PdM1Fq/D40A+dLzi4IMDKGx6CuH1XWd/EF7TA/VZ8/X621w9oQU euo2lX7wiA5NdNib+yiW8UO+acUHngrz8DvCP4QViNEjBUw3gnwl4XPMEphcYzMiSA2+ Ea+XUVBLZ+wX2bCL88GL1zSNb3e18yit1ZTMYw0hE4Nng1bbp0MBCA8j6N3DJwvIOPsm J7mfqvqWvQYAGqJvD0oU4dp7nHao3z2ysxLVFv+UG3AHmYrFDNnJ9NEu+zNKeYZfbiDD vZ5A== 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=tL/A3FT8gDscc6QuJLCaN28uJoetqQ6vF++Ae3qkXIE=; b=RXuPOMJejEFab+Bt4L/g7H3vMG7rXrtTEeeWO/ChKCVb5/rlgjZ8bbvJhzdGxBOzN4 eAGknDe5beQNm/YD3d1kPmgd6EpSyrlbbovuMCS+YH6rqe+hfLsDZZqs6IIL6JBwjNAS RBnicQcj03lbabbzl5cSQdLD5oqs0Fxw4/f+WMyTc2ntkTProtdTVIqzks7V5TInY6rO m7fDXTcfiymXU7VOoHUYQl3jpqk7FIptqKUef4vw91xLdcW686GjpOJ3k1J/ch+ymD+W UxEpE1Yvjyi93Fscz4gMVKpqzk9SM6Y4i2+wAclzQ+QLrO/kLjbTpNW9yyuXASmGxiyP IL0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jJCCDIqL; spf=pass (google.com: domain of gcc-patches-return-478472-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478472-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 k189-v6si18482237pgc.414.2018.05.25.01.29.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 01:29:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478472-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=jJCCDIqL; spf=pass (google.com: domain of gcc-patches-return-478472-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478472-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=B7N K+aANb2t/IPsQ8ki7mhHCGfohPkFKaNLsyWwiTXLtRKc2rsryBPCdr6hax/yKmJB 3Mt86L7VA+0wKIhhIXlal5K8JISID4oWM7J2CZvtH33JXOZN7TgEitKthWdra/xU gcrh17HU8gv2+aqHY8LkFMLwrGpJXW7vFaRpmMQ0= 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=skZ6pxPB2 mgj5LQgvIr+SxIdb80=; b=jJCCDIqL9jIMULYkTVAFy2eNDjizwmwQv68eZlBDh A/gCh67ETD8ZA6BYTPMPaZ23OMD2O09lYRqfAOpz7q5f+gEHlbEFNXPv1/+TK6r7 Wv67KSR6ytG1vSD7vVSlBUR4YcZc4q6/9k39Q57tl1akm4HW6clrYge2tXAnXsIu zs= Received: (qmail 74194 invoked by alias); 25 May 2018 08:09:36 -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 43644 invoked by uid 89); 25 May 2018 08:07:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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:07:21 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fM7kq-0003MY-By for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:07:19 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:62178 helo=mx07-00178001.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fM7kq-0003MC-1P for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:07:16 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w4P7wZNA011595; Fri, 25 May 2018 10:07:14 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2j59qwu473-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 25 May 2018 10:07:14 +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 AEA463D; Fri, 25 May 2018 08:07:12 +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 02F06241C; Fri, 25 May 2018 08:07:11 +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:07:11 +0200 From: Christophe Lyon To: , Subject: [ARM/FDPIC 09/21] [ARM] FDPIC: Add support for taking address of nested function Date: Fri, 25 May 2018 10:03:22 +0200 Message-ID: <20180525080354.13295-10-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: 91.207.212.93 X-IsSubscribed: yes 2018-XX-XX Christophe Lyon Mickaël Guêné gcc/ * config/arm/arm.c (arm_asm_trampoline_template): Add FDPIC support. (arm_trampoline_init): Likewise. (arm_trampoline_init): Likewise. * config/arm/arm.h (TRAMPOLINE_SIZE): Likewise. Change-Id: I4b5127261a9aefa0f0318f110574ec07a856aeb1 -- 2.6.3 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 025485d..2434602 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -3967,7 +3967,27 @@ arm_asm_trampoline_template (FILE *f) { fprintf (f, "\t.syntax unified\n"); - if (TARGET_ARM) + if (TARGET_FDPIC) + { + /* The first two words are a function descriptor to jump into + the trampoline code just below. */ + if (TARGET_ARM) fprintf (f, "\t.arm\n"); + else if (TARGET_THUMB2) fprintf (f, "\t.thumb\n"); + else fprintf (f, "\t.code\t16\n"); + + assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); + assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); + /* Trampoline code which sets the static chain register but also + PIC register before jumping into real code. */ + asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", + STATIC_CHAIN_REGNUM, PC_REGNUM, TARGET_THUMB2?8:4); + asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", + PIC_OFFSET_TABLE_REGNUM, PC_REGNUM, TARGET_THUMB2?8:4); + asm_fprintf (f, "\tldr\t%r, [%r, #%d]\n", + PC_REGNUM, PC_REGNUM, TARGET_THUMB2?8:4); + assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); + } + else if (TARGET_ARM) { fprintf (f, "\t.arm\n"); asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM); @@ -4008,12 +4028,37 @@ arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) emit_block_move (m_tramp, assemble_trampoline_template (), GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); - mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12); - emit_move_insn (mem, chain_value); + if (TARGET_FDPIC) + { + rtx funcdesc = XEXP (DECL_RTL (fndecl), 0); + rtx fnaddr = gen_rtx_MEM (Pmode, funcdesc); + rtx gotaddr = gen_rtx_MEM (Pmode, plus_constant (Pmode, funcdesc, 4)); + rtx trampolineCodeStart + = plus_constant (Pmode, XEXP (m_tramp, 0), TARGET_THUMB2 ? 9 : 8); + + /* Write initial funcdesc which will jump into trampoline. */ + mem = adjust_address (m_tramp, SImode, 0); + emit_move_insn (mem, trampolineCodeStart); + mem = adjust_address (m_tramp, SImode, 4); + emit_move_insn (mem, gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM)); + /* Setup static chain. */ + mem = adjust_address (m_tramp, SImode, 20); + emit_move_insn (mem, chain_value); + /* GOT + real function entry point. */ + mem = adjust_address (m_tramp, SImode, 24); + emit_move_insn (mem, gotaddr); + mem = adjust_address (m_tramp, SImode, 28); + emit_move_insn (mem, fnaddr); + } + else + { + mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12); + emit_move_insn (mem, chain_value); - mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16); - fnaddr = XEXP (DECL_RTL (fndecl), 0); - emit_move_insn (mem, fnaddr); + mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16); + fnaddr = XEXP (DECL_RTL (fndecl), 0); + emit_move_insn (mem, fnaddr); + } a_tramp = XEXP (m_tramp, 0); emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"), @@ -4027,7 +4072,9 @@ arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) static rtx arm_trampoline_adjust_address (rtx addr) { - if (TARGET_THUMB) + /* For FDPIC don't fix trampoline address since it's a function + descriptor and not a function address. */ + if (TARGET_THUMB && !TARGET_FDPIC) addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx, NULL, 0, OPTAB_LIB_WIDEN); return addr; diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index e8ef439..db17ef2 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -1578,7 +1578,7 @@ typedef struct #define INIT_EXPANDERS arm_init_expanders () /* Length in units of the trampoline for entering a nested function. */ -#define TRAMPOLINE_SIZE (TARGET_32BIT ? 16 : 20) +#define TRAMPOLINE_SIZE (TARGET_FDPIC ? 32 : (TARGET_32BIT ? 16 : 20)) /* Alignment required for a trampoline in bits. */ #define TRAMPOLINE_ALIGNMENT 32