From patchwork Fri May 29 11:46:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1300650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49YN8P57YQz9sSn for ; Fri, 29 May 2020 21:47:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2DBC388C008; Fri, 29 May 2020 11:46:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id ADE9A3840C00 for ; Fri, 29 May 2020 11:46:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ADE9A3840C00 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@gnu.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id D17527864; Fri, 29 May 2020 13:46:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qR3SODZ0Tjfa; Fri, 29 May 2020 13:46:50 +0200 (CEST) Received: from function (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id D9A4264C5; Fri, 29 May 2020 13:46:50 +0200 (CEST) Received: from samy by function with local (Exim 4.93) (envelope-from ) id 1jedTO-0078Ki-5m; Fri, 29 May 2020 13:46:50 +0200 Date: Fri, 29 May 2020 13:46:50 +0200 From: Samuel Thibault To: gcc-patches@gcc.gnu.org, bug-hurd@gnu.org Subject: [PATCH] hurd: libgcc unwinding support over signal trampolines Message-ID: <20200529114650.tent6dxgq4bzbkdz@function> Mail-Followup-To: gcc-patches@gcc.gnu.org, bug-hurd@gnu.org MIME-Version: 1.0 Content-Disposition: inline Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello, libgcc is currently missing the support for unwinding over signal trampolines on GNU/Hurd. The attached patch implements it. Samuel hurd: libgcc unwinding support over signal trampolines * libgcc/config.host (md_unwind_header): Set to i386/gnu-unwind.h on i[34567]86-*-gnu*. * src/libgcc/config/i386/gnu-unwind.h: New file. diff --git a/libgcc/config.host b/libgcc/config.host index 2cd42097167..044b34d53cc 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -734,11 +734,17 @@ i[34567]86-*-linux*) tm_file="${tm_file} i386/elf-lib.h" md_unwind_header=i386/linux-unwind.h ;; -i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu) +i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu) extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" tm_file="${tm_file} i386/elf-lib.h" ;; +i[34567]86-*-gnu*) + extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" + tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" + tm_file="${tm_file} i386/elf-lib.h" + md_unwind_header=i386/gnu-unwind.h + ;; x86_64-*-linux*) extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" diff --git a/src/libgcc/config/i386/gnu-unwind.h b/src/libgcc/config/i386/gnu-unwind.h new file mode 100644 index 00000000000..db47f0ac1d4 --- /dev/null +++ b/src/libgcc/config/i386/gnu-unwind.h @@ -0,0 +1,107 @@ +/* DWARF2 EH unwinding support for GNU Hurd: x86. + Copyright (C) 2020 Free Software Foundation, Inc. + Contributed by Samuel Thibault + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +/* Do code reading to identify a signal frame, and set the frame + state data appropriately. See unwind-dw2.c for the structs. */ + +#ifndef inhibit_libc + +#include + +#define MD_FALLBACK_FRAME_STATE_FOR x86_gnu_fallback_frame_state + +static _Unwind_Reason_Code +x86_gnu_fallback_frame_state +(struct _Unwind_Context *context, _Unwind_FrameState *fs) +{ + struct handler_args { + int signo; + int sigcode; + struct sigcontext *scp; + } *handler_args; + struct sigcontext *scp; + unsigned long usp; + +/* + * i386 sigtramp frame we are looking for follows. + * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly) + * + * rpc_wait_trampoline: + * 0: b8 e7 ff ff ff mov $-25,%eax mach_msg_trap + * 5: 9a 00 00 00 00 07 00 lcall $7,$0 + * 12: 89 01 movl %eax, (%ecx) + * 14: 89 dc movl %ebx, %esp switch to signal stack + * + * trampoline: + * 16: ff d2 call *%edx call the handler function + * RA HERE + * 18: 83 c4 0c addl $12, %esp pop its args + * 21: c3 ret return to sigreturn + * + * firewall: + * 22: f4 hlt + */ + + if (!( *(unsigned int *)(context->ra ) == 0xc30cc483 + && *(unsigned char *)(context->ra + 4) == 0xf4 + + && *(unsigned int *)(context->ra - 4) == 0xd2ffdc89 + && *(unsigned int *)(context->ra - 8) == 0x01890007 + && *(unsigned int *)(context->ra - 12) == 0x00000000 + && *(unsigned int *)(context->ra - 16) == 0x9affffff + && *(unsigned short *)(context->ra - 18) == 0xe7b8)) + return _URC_END_OF_STACK; + + handler_args = context->cfa; + scp = handler_args->scp; + usp = scp->sc_uesp; + + fs->regs.cfa_how = CFA_REG_OFFSET; + fs->regs.cfa_reg = 4; + fs->regs.cfa_offset = usp - (unsigned long) context->cfa; + + fs->regs.reg[0].how = REG_SAVED_OFFSET; + fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp; + fs->regs.reg[1].how = REG_SAVED_OFFSET; + fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp; + fs->regs.reg[2].how = REG_SAVED_OFFSET; + fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp; + fs->regs.reg[3].how = REG_SAVED_OFFSET; + fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp; + fs->regs.reg[5].how = REG_SAVED_OFFSET; + fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp; + fs->regs.reg[6].how = REG_SAVED_OFFSET; + fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp; + fs->regs.reg[7].how = REG_SAVED_OFFSET; + fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp; + fs->regs.reg[8].how = REG_SAVED_OFFSET; + fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp; + fs->retaddr_column = 8; + fs->signal_frame = 1; + + return _URC_NO_REASON; +} + +#endif /* ifndef inhibit_libc */