From: Kyrill Tkachov <kyrylo.tkachov@foss.arm.com>
To: Christophe Lyon <christophe.lyon@st.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [ARM/FDPIC v5 11/21] [ARM] FDPIC: Add support to unwind FDPIC signal frame
Date: Wed, 04 Sep 2019 14:19:00 -0000 [thread overview]
Message-ID: <06f46aa0-e799-0236-60b4-b1fe708ad247@foss.arm.com> (raw)
In-Reply-To: <20190515124006.25840-12-christophe.lyon@st.com>
Hi Christophe,
On 5/15/19 1:39 PM, Christophe Lyon wrote:
> 2019-XX-XXÂ Christophe Lyon <christophe.lyon@st.com>
>        Mickaël Guêné <mickael.guene@st.com>
>
> Â Â Â Â Â Â Â 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,
> FDPIC_T2_LDR_R12_WITH_FUNCDESC)
> Â Â Â Â Â Â Â (FDPIC_T2_LDR_R9_WITH_GOT, FDPIC_T2_LDR_PC_WITH_RESTORER): New.
> Â Â Â Â Â Â Â (__gnu_personality_sigframe_fdpic): New.
> Â Â Â Â Â Â Â (get_eit_entry): Add FDPIC signal frame support.
>
At this point I'm looking that the code is FDPIC-specific and thus won't
break other targets.
I'll have to trust your testing that this is correct for FDPIC.
Ok.
Thanks,
Kyrill
> Change-Id: I7f9527cc50665dd1a731b7badf71c319fb38bf57
>
> diff --git a/libgcc/unwind-arm-common.inc b/libgcc/unwind-arm-common.inc
> index 0bacc11..c9a82b7 100644
> --- a/libgcc/unwind-arm-common.inc
> +++ b/libgcc/unwind-arm-common.inc
> @@ -30,6 +30,26 @@
> Â #include <sys/sdt.h>
> Â #endif
>
> +#if __FDPIC__
> +/* Load r7 with rt_sigreturn value. */
> +#define ARM_SET_R7_RT_SIGRETURN 0xe3a070ad     /* mov  r7, #0xad */
> +#define THUMB2_SET_R7_RT_SIGRETURN    0x07adf04f     /* mov.w r7,
> #0xad */
> +
> +/* FDPIC jump to restorer sequence. */
> +#define FDPIC_LDR_R12_WITH_FUNCDESC   0xe59fc004     /* ldr  r12,
> [pc, #4] */
> +#define FDPIC_LDR_R9_WITH_GOT         0xe59c9004     /* ldr  r9,
> [r12, #4] */
> +#define FDPIC_LDR_PC_WITH_RESTORER    0xe59cf000     /* ldr  pc,
> [r12] */
> +#define FDPIC_T2_LDR_R12_WITH_FUNCDESC 0xc008f8df    /* ldr.w r12,
> [pc, #8] */
> +#define FDPIC_T2_LDR_R9_WITH_GOT      0x9004f8dc     /* ldr.w r9,
> [r12, #4] */
> +#define FDPIC_T2_LDR_PC_WITH_RESTORER  0xf000f8dc    /* ldr.w pc,
> [r12] */
> +#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);
> @@ -199,6 +219,45 @@ search_EIT_table (const __EIT_entry * table, int
> nrec, _uw return_address)
> Â Â Â Â }
> Â }
>
> +#if __FDPIC__
> +/* VFP is not restored, but this is 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 & ~1) + 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. */
> @@ -222,6 +281,27 @@ 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) & ~1);
> +Â Â Â Â Â Â Â Â if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
> +Â Â Â Â Â Â Â Â Â Â Â Â || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_T2_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;
> Â Â Â Â Â Â Â Â }
> @@ -236,6 +316,27 @@ 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) & ~1);
> +Â Â Â Â Â if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
> +Â Â Â Â Â Â Â Â || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_T2_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;
> Â Â Â Â }
> @@ -244,6 +345,27 @@ 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) & ~1);
> +Â Â Â Â Â if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
> +Â Â Â Â Â Â Â Â || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
> +Â Â Â Â Â Â Â Â Â Â Â Â && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
> +Â Â Â Â Â Â Â Â Â Â Â Â && pc[2] == FDPIC_T2_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;
> Â Â Â Â }
> --
> 2.6.3
>
next prev parent reply other threads:[~2019-09-04 14:19 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 12:40 [ARM/FDPIC v5 00/21] FDPIC ABI for ARM Christophe Lyon
2019-05-15 12:40 ` [ARM/FDPIC v5 01/21] [ARM] FDPIC: Add -mfdpic option support Christophe Lyon
2019-07-16 10:18 ` Richard Sandiford
2019-08-29 15:08 ` Christophe Lyon
2019-08-30 10:06 ` Richard Sandiford
2019-05-15 12:41 ` [ARM/FDPIC v5 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture Christophe Lyon
2019-07-16 12:33 ` Richard Sandiford
2019-08-20 17:13 ` Christophe Lyon
2019-08-29 15:39 ` Christophe Lyon
2019-09-02 16:12 ` Richard Sandiford
2019-09-02 20:04 ` Christophe Lyon
2019-09-03 8:40 ` Richard Sandiford
2019-09-04 19:59 ` Christophe Lyon
2019-09-05 8:03 ` Richard Sandiford
2019-05-15 12:41 ` [ARM/FDPIC v5 03/21] [ARM] FDPIC: Force FDPIC related options unless -mno-fdpic is provided Christophe Lyon
2019-05-15 13:55 ` Szabolcs Nagy
2019-05-15 14:37 ` Rich Felker
2019-05-15 15:12 ` Christophe Lyon
2019-05-15 15:37 ` Rich Felker
2019-05-15 15:59 ` Szabolcs Nagy
2019-05-15 16:07 ` Rich Felker
2019-05-21 15:29 ` Christophe Lyon
2019-05-21 15:48 ` Rich Felker
2019-05-22 8:39 ` Szabolcs Nagy
2019-05-22 8:45 ` Christophe Lyon
2019-05-23 12:45 ` Christophe Lyon
2019-07-16 10:38 ` Richard Sandiford
2019-07-16 20:00 ` Rich Felker
2019-08-01 10:13 ` Christophe Lyon
2019-08-06 14:28 ` Richard Sandiford
2019-08-29 15:14 ` Christophe Lyon
2019-08-30 9:40 ` Richard Sandiford
2019-05-15 12:41 ` [ARM/FDPIC v5 02/21] [ARM] FDPIC: Handle arm*-*-uclinuxfdpiceabi in configure scripts Christophe Lyon
2019-07-12 7:44 ` Richard Sandiford
2019-07-12 13:25 ` Christophe Lyon
2019-07-12 13:28 ` Richard Sandiford
2019-08-29 15:14 ` Christophe Lyon
2019-08-30 9:30 ` Richard Sandiford
2019-08-30 14:48 ` Christophe Lyon
2019-08-30 15:15 ` Richard Sandiford
2019-09-02 7:51 ` Christophe Lyon
2019-09-02 8:31 ` Richard Sandiford
2019-08-30 14:40 ` Jonathan Wakely
2019-05-15 12:41 ` [ARM/FDPIC v5 05/21] [ARM] FDPIC: Fix __do_global_dtors_aux and frame_dummy generation Christophe Lyon
2019-07-12 6:49 ` Richard Sandiford
2019-07-12 14:25 ` Christophe Lyon
2019-08-29 15:39 ` Christophe Lyon
2019-08-30 8:41 ` Richard Sandiford
2019-05-15 12:42 ` [ARM/FDPIC v5 07/21] [ARM] FDPIC: Avoid saving/restoring r9 on stack since it is read-only Christophe Lyon
2019-07-16 10:42 ` Kyrill Tkachov
2019-05-15 12:42 ` [ARM/FDPIC v5 06/21] [ARM] FDPIC: Add support for c++ exceptions Christophe Lyon
2019-08-30 9:31 ` Kyrill Tkachov
2019-08-30 14:44 ` Jonathan Wakely
2019-05-15 12:43 ` [ARM/FDPIC v5 08/21] [ARM] FDPIC: Enforce local/global binding for function descriptors Christophe Lyon
2019-07-16 10:51 ` Kyrill Tkachov
2019-05-15 12:43 ` [ARM/FDPIC v5 10/21] [ARM] FDPIC: Implement TLS support Christophe Lyon
2019-09-04 14:16 ` Kyrill Tkachov
2019-09-04 20:03 ` Christophe Lyon
2019-09-09 8:54 ` Christophe Lyon
2019-05-15 12:43 ` [ARM/FDPIC v5 09/21] [ARM] FDPIC: Add support for taking address of nested function Christophe Lyon
2019-07-16 11:53 ` Kyrill Tkachov
2019-07-16 13:31 ` Kyrill Tkachov
2019-07-31 14:48 ` Christophe Lyon
2019-08-29 15:40 ` Christophe Lyon
2019-08-30 8:54 ` Kyrill Tkachov
2019-05-15 12:44 ` [ARM/FDPIC v5 11/21] [ARM] FDPIC: Add support to unwind FDPIC signal frame Christophe Lyon
2019-09-04 14:19 ` Kyrill Tkachov [this message]
2019-05-15 12:44 ` [ARM/FDPIC v5 12/21] [ARM] FDPIC: Restore r9 after we call __aeabi_read_tp Christophe Lyon
2019-08-29 15:40 ` Christophe Lyon
2019-08-29 15:44 ` Kyrill Tkachov
2019-05-15 12:44 ` [ARM/FDPIC v5 13/21] [ARM] FDPIC: Force LSB bit for PC in Cortex-M architecture Christophe Lyon
2019-08-29 15:37 ` Kyrill Tkachov
2019-09-05 8:30 ` Christophe Lyon
2019-09-05 8:32 ` Christophe Lyon
2019-09-05 20:56 ` Ian Lance Taylor
2019-09-05 9:03 ` Kyrill Tkachov
2019-09-09 8:58 ` Christophe Lyon
2019-05-15 12:45 ` [ARM/FDPIC v5 16/21] [ARM][testsuite] FDPIC: Skip tests that don't work in PIC mode Christophe Lyon
2019-07-19 8:56 ` Kyrill Tkachov
2019-05-15 12:45 ` [ARM/FDPIC v5 14/21] [ARM][testsuite] FDPIC: Skip unsupported tests Christophe Lyon
2019-07-19 8:52 ` Kyrill Tkachov
2019-05-15 12:45 ` [ARM/FDPIC v5 15/21] [ARM][testsuite] FDPIC: Adjust scan-assembler patterns Christophe Lyon
2019-07-19 8:54 ` Kyrill Tkachov
2019-05-15 12:46 ` [ARM/FDPIC v5 17/21] [ARM][testsuite] FDPIC: Handle *-*-uclinux* Christophe Lyon
2019-07-19 8:57 ` Kyrill Tkachov
2019-07-22 19:37 ` Mike Stump
2019-05-15 12:46 ` [ARM/FDPIC v5 18/21] [ARM][testsuite] FDPIC: Enable tests on pie_enabled targets Christophe Lyon
2019-07-19 8:59 ` Kyrill Tkachov
2019-07-22 19:50 ` Mike Stump
2019-05-15 12:46 ` [ARM/FDPIC v5 19/21] [ARM][testsuite] FDPIC: Adjust pr43698.c to avoid clash with uclibc Christophe Lyon
2019-07-19 9:00 ` Kyrill Tkachov
2019-05-15 12:47 ` [ARM/FDPIC v5 20/21] [ARM][testsuite] FDPIC: Skip tests using architectures unsupported by FDPIC Christophe Lyon
2019-07-19 9:03 ` Kyrill Tkachov
2019-09-06 8:01 ` Christophe Lyon
2019-09-06 8:28 ` Kyrill Tkachov
2019-09-06 9:10 ` Christophe Lyon
2019-09-06 17:44 ` Christophe Lyon
2019-09-09 8:38 ` Christophe Lyon
2019-05-15 12:47 ` [ARM/FDPIC v5 21/21] [ARM] FDPIC: Handle stack-protector combined patterns Christophe Lyon
2019-07-19 9:40 ` Kyrill Tkachov
2019-05-23 12:46 ` [ARM/FDPIC v5 00/21] FDPIC ABI for ARM Christophe Lyon
2019-06-04 12:57 ` Christophe Lyon
2019-06-06 12:36 ` Christophe Lyon
2019-06-17 11:42 ` Christophe Lyon
2019-07-01 12:16 ` Christophe Lyon
2019-07-08 14:28 ` Christophe Lyon
2019-07-16 9:13 ` Christophe Lyon
2019-08-29 14:54 ` Christophe Lyon
2019-08-29 16:29 ` Christophe Lyon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=06f46aa0-e799-0236-60b4-b1fe708ad247@foss.arm.com \
--to=kyrylo.tkachov@foss.arm.com \
--cc=christophe.lyon@st.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).