From patchwork Fri May 25 08:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 136797 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3285883lji; Fri, 25 May 2018 01:27:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrEqPe+aB812SN2pk4CII5dhgFws9W+XzsIO2Bs3Svju22ey0tPoGEhATIR5fSoDtMEzF3+ X-Received: by 2002:a62:f80c:: with SMTP id d12-v6mr1560019pfh.159.1527236854195; Fri, 25 May 2018 01:27:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527236854; cv=none; d=google.com; s=arc-20160816; b=qTuvnGPcrQQuLyOhnqTTRUTMMDdRUW15ZB+7YXEIGk8s2qpxck1VKf5uvD4mjBZxam KTKDofQjrAfk5xz42HMbcQkh23ARZ00dOCpWe3kGjnPuTjtzT9aNsQ6so9vd7GnHd60K rMEagOI8FiWnvxpGOqddVlGknDcAGBvBURSGKO2UkP7ZBjy+8x0AWt3s9FWeoq0p45H9 TlDMWp60K0hvJN6jVAQBnGmesoftp/GwI9xzTe+x6GFGifo/jNGusmK+p4NciyjN8mpl 6Eziiaqzd1coF6XBVfgjhetyRLNCfDWNVQk4vkI8RAFy8yFDwcOsLPgXjUUtJIqLT/xE kyug== 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=QIa5niC5Bng+z1rXLwrgnud0I6MLeqEpwK2SrYWqBm4=; b=SIUYonyadv3KYCZhFLTSSpI6LFJD2uDVRndKqpugeME40GB45plqDEAgCFgCyNnPm1 1t4vDReT4OaeuKuktLic2jX7nkuv9keHGzgAieKzdadw1aDpQcht8KwowHrO48h0qUBp Pj+W/WOBzccQtqYAecSV46siCZNk1HLwQRq7OMqOA45nIdFfVK0S0DrvGOmol0kjA1S8 oyD63cj+NZX4F5FXnppn+5ZCZigNkf9FZhiXAfMRDIUkfjicP28l0vSPaeLlPi6sOCFb kToxNozBoyTyrll5uB56L6dlIHR1MDLllXrcqOGd+MV5oLN5SeVN11iqULO+wxs4obJp bczA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GC84wdWD; spf=pass (google.com: domain of gcc-patches-return-478465-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478465-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 p91-v6si23303567plb.457.2018.05.25.01.27.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 01:27:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478465-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=GC84wdWD; spf=pass (google.com: domain of gcc-patches-return-478465-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478465-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=amm p4QeaMchQAd1N7vBHMuLG5qeY2VFsYX2dwzeF5OuWRsBXf7y9jcwQa5gZzI7RtS0 Y5lTFvXaTI/kdgipKBrP7OW8u3vlEIp0w0VO/CZQBfStifwrIeYMIn8kz02qYbHJ gpj6c9mSJ2v3jJViKF8OuYYi/Gnc6OgbM6CZwPIU= 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=NdDuTuj6b VqGfUyfARbE+1iM8wc=; b=GC84wdWD1uQBZB/Kwx/NxK57SiHOHqRBi/vZrnePB pSkuJ8qqwJgBFH89a8wOpNwllQs1eXGVmeCJKUMmmAdGPUGSaGtiQ9ob9At1kA0U 1+xO+tW/6neF68tDCJJWaMGRkfMmH5eBQ0Qgh2SRFbQb9FbnlxjTu+3FWru4ZXiw i4= Received: (qmail 44556 invoked by alias); 25 May 2018 08:08:24 -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 44130 invoked by uid 89); 25 May 2018 08:08:01 -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=sk:search_ 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:59 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fM7lS-0003Zc-Uc for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:07:58 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:53660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fM7lS-0003ZH-Kq for gcc-patches@gcc.gnu.org; Fri, 25 May 2018 04:07:54 -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 w4P7xBxL003910; Fri, 25 May 2018 10:07:53 +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 2j59prjw3y-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 25 May 2018 10:07:53 +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 9EE643A; Fri, 25 May 2018 08:07:52 +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 8702B241D; Fri, 25 May 2018 08:07:52 +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:51 +0200 From: Christophe Lyon To: , Subject: [ARM/FDPIC 11/21] [ARM] FDPIC: Add support to unwind FDPIC signal frame Date: Fri, 25 May 2018 10:03:24 +0200 Message-ID: <20180525080354.13295-12-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 2018-XX-XX Christophe Lyon Mickaël Guêné libgcc/ * unwind-arm-common.inc (ARM_SET_R7_RT_SIGRETURN) (THUMB2_SET_R7_RT_SIGRETURN, FDPIC_LDR_R12_WITH_FUNCDESC) (FDPIC_LDR_R9_WITH_GOT, FDPIC_LDR_PC_WITH_RESTORER) (FDPIC_FUNCDESC_OFFSET, ARM_NEW_RT_SIGFRAME_UCONTEXT) (ARM_UCONTEXT_SIGCONTEXT, ARM_SIGCONTEXT_R0): New. (__gnu_personality_sigframe_fdpic): New. (get_eit_entry): Add FDPIC signal frame support. Change-Id: I7f9527cc50665dd1a731b7badf71c319fb38bf57 -- 2.6.3 diff --git a/libgcc/unwind-arm-common.inc b/libgcc/unwind-arm-common.inc index f5415c1..80d1e88 100644 --- a/libgcc/unwind-arm-common.inc +++ b/libgcc/unwind-arm-common.inc @@ -30,6 +30,21 @@ #include #endif +#if __FDPIC__ +/* Load r7 with rt_sigreturn value. */ +#define ARM_SET_R7_RT_SIGRETURN 0xe3a070ad +#define THUMB2_SET_R7_RT_SIGRETURN 0x07adf04f +/* FDPIC jump to restorer sequence. */ +#define FDPIC_LDR_R12_WITH_FUNCDESC 0xe59fc004 +#define FDPIC_LDR_R9_WITH_GOT 0xe59c9004 +#define FDPIC_LDR_PC_WITH_RESTORER 0xe59cf000 +#define FDPIC_FUNCDESC_OFFSET 12 +/* Signal frame offsets. */ +#define ARM_NEW_RT_SIGFRAME_UCONTEXT 0x80 +#define ARM_UCONTEXT_SIGCONTEXT 0x14 +#define ARM_SIGCONTEXT_R0 0xc +#endif + /* We add a prototype for abort here to avoid creating a dependency on target headers. */ extern void abort (void); @@ -195,6 +210,46 @@ search_EIT_table (const __EIT_entry * table, int nrec, _uw return_address) } } +#if __FDPIC__ +/* FIXME: partial support (VFP not restored) but should be sufficient + to allow unwinding. */ +static _Unwind_Reason_Code +__gnu_personality_sigframe_fdpic (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + unsigned int sp; + unsigned int pc; + unsigned int funcdesc; + unsigned int handler; + unsigned int first_handler_instruction; + int i; + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &sp); + _Unwind_VRS_Get (context, _UVRSC_CORE, R_PC, _UVRSD_UINT32, &pc); + + funcdesc = *(unsigned int *)(pc + FDPIC_FUNCDESC_OFFSET); + handler = *(unsigned int *)(funcdesc); + first_handler_instruction = *(unsigned int *)(handler & ~1); + + /* Adjust SP to point to the start of registers according to + signal type. */ + if (first_handler_instruction == ARM_SET_R7_RT_SIGRETURN + || first_handler_instruction == THUMB2_SET_R7_RT_SIGRETURN) + sp += ARM_NEW_RT_SIGFRAME_UCONTEXT + + ARM_UCONTEXT_SIGCONTEXT + + ARM_SIGCONTEXT_R0; + else + sp += ARM_UCONTEXT_SIGCONTEXT + + ARM_SIGCONTEXT_R0; + /* Restore regs saved on stack by the kernel. */ + for (i = 0; i < 16; i++) + _Unwind_VRS_Set (context, _UVRSC_CORE, i, _UVRSD_UINT32, sp + 4 * i); + + return _URC_CONTINUE_UNWIND; +} +#endif + /* Find the exception index table eintry for the given address. Fill in the relevant fields of the UCB. Returns _URC_FAILURE if an error occurred, _URC_OK on success. */ @@ -218,6 +273,24 @@ get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address) &nrec); if (!eitp) { +#if __FDPIC__ + /* If we are unwinding a signal handler then perhaps we have + reached a trampoline. Try to detect jump to restorer + sequence. */ + _uw *pc = (_uw *)((return_address+2) & ~3); + if (pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC + && pc[1] == FDPIC_LDR_R9_WITH_GOT + && pc[2] == FDPIC_LDR_PC_WITH_RESTORER) + { + struct funcdesc_t *funcdesc = (struct funcdesc_t *) + &__gnu_personality_sigframe_fdpic; + + UCB_PR_ADDR (ucbp) = funcdesc->ptr; + UCB_PR_GOT (ucbp) = funcdesc->got; + + return _URC_OK; + } +#endif UCB_PR_ADDR (ucbp) = 0; return _URC_FAILURE; } @@ -232,6 +305,24 @@ get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address) if (!eitp) { +#if __FDPIC__ + /* If we are unwinding a signal handler then perhaps we have + reached a trampoline. Try to detect jump to restorer + sequence. */ + _uw *pc = (_uw *)((return_address+2) & ~3); + if (pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC + && pc[1] == FDPIC_LDR_R9_WITH_GOT + && pc[2] == FDPIC_LDR_PC_WITH_RESTORER) + { + struct funcdesc_t *funcdesc = (struct funcdesc_t *) + &__gnu_personality_sigframe_fdpic; + + UCB_PR_ADDR (ucbp) = funcdesc->ptr; + UCB_PR_GOT (ucbp) = funcdesc->got; + + return _URC_OK; + } +#endif UCB_PR_ADDR (ucbp) = 0; return _URC_FAILURE; } @@ -240,6 +331,24 @@ get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address) /* Can this frame be unwound at all? */ if (eitp->content == EXIDX_CANTUNWIND) { +#if __FDPIC__ + /* If we are unwinding a signal handler then perhaps we have + reached a trampoline. Try to detect jump to restorer + sequence. */ + _uw *pc = (_uw *)((return_address+2) & ~3); + if (pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC + && pc[1] == FDPIC_LDR_R9_WITH_GOT + && pc[2] == FDPIC_LDR_PC_WITH_RESTORER) + { + struct funcdesc_t *funcdesc = (struct funcdesc_t *) + &__gnu_personality_sigframe_fdpic; + + UCB_PR_ADDR (ucbp) = funcdesc->ptr; + UCB_PR_GOT (ucbp) = funcdesc->got; + + return _URC_OK; + } +#endif UCB_PR_ADDR (ucbp) = 0; return _URC_END_OF_STACK; }