From patchwork Thu Feb 16 19:21:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Tobler X-Patchwork-Id: 728881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vPQyZ5YX3z9s7D for ; Fri, 17 Feb 2017 06:22:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wjYlu+JH"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=KoxxH3HHAC9fKna2+s6cbaEKTVJkDhtP43x4ZO8jOxKxXhgf0N xEe3FSM+ao1Ljy07/cVF/YxpB7wxtLC6EYmeUQ5m28CZHr9AnPshhULMpObIhLzq TP0sSWI8dFsXclZRM3hvhzyp/rnRVAQYWXFQMRP7ezUj/qXPyUZB22U+8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=tyiZx9UEJmgArDBAJGPtO4+fK+k=; b=wjYlu+JHfJMHSvyxhDKI g6kRKRWDuVZPoLaXbTNu5OokBJ4MvqJVMRLQbdra0mympN4+FH8maiDXUdFAVC0g 8MNyy0GAOPqihXwcQgm1+Y58elmTXWbUoN8N9u+BN8BDhOaId6WAMebkyQCO+Mdy SHUMcfMrChIcrYECL4g4DRU= Received: (qmail 99480 invoked by alias); 16 Feb 2017 19:22:03 -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 98763 invoked by uid 89); 16 Feb 2017 19:22:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.1 required=5.0 tests=AWL, BAYES_05, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=tia, H*Ad:D*ch, aarch64*-*-linux*, sk:md_unwi X-HELO: smtp.fgznet.ch Received: from smtp.fgznet.ch (HELO smtp.fgznet.ch) (157.161.14.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Feb 2017 19:21:52 +0000 Received: from [192.168.225.14] (dhclient-91-190-14-19.flashcable.ch [91.190.14.19]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by fgznet.ch (Postfix) with ESMTPSA id AC723C6B7D; Thu, 16 Feb 2017 20:21:49 +0100 (CET) To: GCC Patches Cc: gnugcc@marino.st From: Andreas Tobler Subject: [PATCH, aarch64] add unwind support for aarch64-*-freebsd* Message-ID: <35429be2-c1f0-a119-f0c3-a27242c0f0b7@fgznet.ch> Date: Thu, 16 Feb 2017 20:21:49 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi all, the attached patch adds unwind support for aarch64-*-freebsd*. John used to catch unwind tests in ada. So far it bootstraps and I see no regressions. is this ok for trunk? TIA, Andreas 2017-02-16 John Marino * config/aarch64/freebsd-unwind.h: New file. * config.host: Add aarch64-*-freebsd unwinder. Index: config.host =================================================================== --- config.host (revision 245512) +++ config.host (working copy) @@ -340,7 +340,7 @@ extra_parts="$extra_parts crtfastmath.o" tmake_file="${tmake_file} ${cpu_type}/t-aarch64" tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm" - md_unwind_header=aarch64/aarch64-unwind.h + md_unwind_header=aarch64/freebsd-unwind.h ;; aarch64*-*-linux*) extra_parts="$extra_parts crtfastmath.o" Index: config/aarch64/freebsd-unwind.h =================================================================== --- config/aarch64/freebsd-unwind.h (nonexistent) +++ config/aarch64/freebsd-unwind.h (working copy) @@ -0,0 +1,108 @@ +/* DWARF2 EH unwinding support for FreeBSD/ARM64 (aarch64). + Copyright (C) 2017 Free Software Foundation, Inc. + Contributed by John Marino + +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 +. */ + +/* Identify a signal frame, and set the frame state data appropriately. + See unwind-dw2.c for the structs. */ + +/* Always include AArch64 unwinder header file. */ +#include "config/aarch64/aarch64-unwind.h" + +#include +#include +#include +#include +#include +#include +#include + +#define REG_NAME(reg) mc_gpregs.gp_## reg +#define XREG(num) mc_gpregs.gp_x[num] +#define DARC __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__ + +#define MD_FALLBACK_FRAME_STATE_FOR aarch64_freebsd_fallback_frame_state + +static int +aarch64_outside_sigtramp_range (unsigned char *pc) +{ + static int sigtramp_range_determined = 0; + static unsigned char *sigtramp_start, *sigtramp_end; + + if (sigtramp_range_determined == 0) + { + struct kinfo_sigtramp kst = {0}; + size_t len = sizeof (kst); + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP, getpid() }; + + sigtramp_range_determined = 1; + if (sysctl (mib, 4, &kst, &len, NULL, 0) == 0) + { + sigtramp_range_determined = 2; + sigtramp_start = kst.ksigtramp_start; + sigtramp_end = kst.ksigtramp_end; + } + } + if (sigtramp_range_determined < 2) /* sysctl failed if < 2 */ + return 1; + + return (pc < sigtramp_start || pc >= sigtramp_end); +} + +static _Unwind_Reason_Code +aarch64_freebsd_fallback_frame_state +(struct _Unwind_Context *context, _Unwind_FrameState *fs) +{ + int n; + struct sigframe *sf; + mcontext_t *sc; + _Unwind_Ptr new_cfa; + + if (aarch64_outside_sigtramp_range(context->ra)) + return _URC_END_OF_STACK; + + sf = (struct sigframe *) context->cfa; + sc = &sf->sf_uc.uc_mcontext; + + new_cfa = (_Unwind_Ptr) sc; + fs->regs.cfa_how = CFA_REG_OFFSET; + fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__; + fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa; + + for (n = 0; n < 32; n++) + fs->regs.reg[n].how = REG_SAVED_OFFSET; + + for (n = 0; n < 30; n++) + fs->regs.reg[n].loc.offset = (_Unwind_Ptr) &(sc->XREG(n)) - new_cfa; + + fs->regs.reg[30].loc.offset = (_Unwind_Ptr) &(sc->REG_NAME(lr)) - new_cfa; + fs->regs.reg[31].loc.offset = (_Unwind_Ptr) &(sc->REG_NAME(sp)) - new_cfa; + + fs->regs.reg[DARC].how = REG_SAVED_OFFSET; + fs->regs.reg[DARC].loc.offset = (_Unwind_Ptr) &(sc->REG_NAME(elr)) - new_cfa; + + fs->retaddr_column = DARC; + fs->signal_frame = 1; + + return _URC_NO_REASON; +}