From 4ccfdb287ef9e8a62ac09f47b0158b17b1d91190 Mon Sep 17 00:00:00 2001 From: John Marino Date: Fri, 10 Mar 2017 19:33:27 +0000 Subject: [PATCH] freebsd-unwind.h: New file. 2017-03-10 John Marino * config/aarch64/freebsd-unwind.h: New file. * config.host: Add aarch64-*-freebsd unwinder. From-SVN: r246052 --- libgcc/ChangeLog | 5 ++ libgcc/config.host | 2 +- libgcc/config/aarch64/freebsd-unwind.h | 108 +++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 libgcc/config/aarch64/freebsd-unwind.h diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index a78bc43468c..4bae69f3961 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,8 @@ +2017-03-10 John Marino + + * config/aarch64/freebsd-unwind.h: New file. + * config.host: Add aarch64-*-freebsd unwinder. + 2017-03-10 Segher Boessenkool * config/rs6000/crtrestvr.s: Use .machine altivec. diff --git a/libgcc/config.host b/libgcc/config.host index 8bab369561f..b279a6458f9 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -340,7 +340,7 @@ aarch64*-*-freebsd*) 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" diff --git a/libgcc/config/aarch64/freebsd-unwind.h b/libgcc/config/aarch64/freebsd-unwind.h new file mode 100644 index 00000000000..b822a7281f5 --- /dev/null +++ b/libgcc/config/aarch64/freebsd-unwind.h @@ -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; +}