https://gcc.gnu.org/g:e6bf7e6fa54d131346c1772f1ef8d33d7c01bf06
commit r17-6026-ge6bf7e6fa54d131346c1772f1ef8d33d7c01bf06 Author: Douglas Rupp <[email protected]> Date: Thu Mar 19 01:14:07 2026 -0300 [PATCH] Provide MD_FROB_UPDATE_CONTEXT for powerpc*-vxworks VxWorks on PowerPC requires similar mechanisms as other OSes to allow unwinding through linker stubs. This patch provides an implementation of MD_FROB_UPDATE_CONTEXT to this effect, very close to the Linux versions. libgcc/ * config/rs6000/vxworks-unwind.h: New file. * config.host (powerpc*-wrs-vxworks7*): Set md_unwind_header to use it. Diff: --- libgcc/config.host | 1 + libgcc/config/rs6000/vxworks-unwind.h | 83 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/libgcc/config.host b/libgcc/config.host index 319d6cfe0eff..ba44a49cc0eb 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -1325,6 +1325,7 @@ powerpc*-wrs-vxworks7*) exit 1 ;; esac + md_unwind_header=rs6000/vxworks-unwind.h ;; powerpc-wrs-vxworks*) tmake_file="$tmake_file rs6000/t-vxworks rs6000/t-savresfgpr t-fdpbit" diff --git a/libgcc/config/rs6000/vxworks-unwind.h b/libgcc/config/rs6000/vxworks-unwind.h new file mode 100644 index 000000000000..2a76696cd3ec --- /dev/null +++ b/libgcc/config/rs6000/vxworks-unwind.h @@ -0,0 +1,83 @@ +/* DWARF2 EH unwinding support for PowerPC and PowerPC64 VxWorks. + Copyright (C) 2004-2020 Free Software Foundation, Inc. + + 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 + <http://www.gnu.org/licenses/>. */ + +#define R_LR 65 + +#ifdef __powerpc64__ +#if _CALL_ELF == 2 +#define TOC_SAVE_SLOT 24 +#else +#define TOC_SAVE_SLOT 40 +#endif +#endif + +#define MD_FROB_UPDATE_CONTEXT frob_update_context + +static void +frob_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs ATTRIBUTE_UNUSED) +{ + const unsigned int *pc = (const unsigned int *) context->ra; + +#ifdef __powerpc64__ + if (fs->regs.how[2] == REG_UNSAVED) + { + /* If the current unwind info (FS) does not contain explicit info + saving R2, then we have to do a minor amount of code reading to + figure out if it was saved. The big problem here is that the + code that does the save/restore is generated by the linker, so + we have no good way to determine at compile time what to do. */ + if (pc[0] == 0xF8410000 + TOC_SAVE_SLOT +#if _CALL_ELF != 2 + /* The ELFv2 linker never generates the old PLT stub form. */ + || ((pc[0] & 0xFFFF0000) == 0x3D820000 + && pc[1] == 0xF8410000 + TOC_SAVE_SLOT) +#endif + ) + { + /* We are in a plt call stub or r2 adjusting long branch stub, + before r2 has been saved. Keep REG_UNSAVED. */ + } + else + { + unsigned int *insn + = (unsigned int *) _Unwind_GetGR (context, R_LR); + if (insn && *insn == 0xE8410000 + TOC_SAVE_SLOT) + _Unwind_SetGRPtr (context, 2, context->cfa + TOC_SAVE_SLOT); +#if _CALL_ELF != 2 + /* ELFv2 does not use this function pointer call sequence. */ + else if (pc[0] == 0x4E800421 + && pc[1] == 0xE8410000 + TOC_SAVE_SLOT) + { + /* We are at the bctrl instruction in a call via function + pointer. gcc always emits the load of the new R2 just + before the bctrl so this is the first and only place + we need to use the stored R2. */ + _Unwind_Word sp = _Unwind_GetGR (context, 1); + _Unwind_SetGRPtr (context, 2, (void *)(sp + TOC_SAVE_SLOT)); + } +#endif + } + } +#endif +}
