0001-merge-Kito-Cheng-s-patch-Handle-different-sigcontext.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 1d04f60838519cdb685c293dbd2fb6c63e64c091 Mon Sep 17 00:00:00 2001
  2. From: "max.ma" <max.ma@starfivetech.com>
  3. Date: Wed, 16 Feb 2022 20:09:03 -0800
  4. Subject: [PATCH 01/11] merge Kito Cheng's patch "Handle different sigcontext
  5. struct layout"
  6. ---
  7. libgcc/config/riscv/linux-unwind.h | 31 +++++++++++++++++++++++++++---
  8. 1 file changed, 28 insertions(+), 3 deletions(-)
  9. diff --git a/libgcc/config/riscv/linux-unwind.h b/libgcc/config/riscv/linux-unwind.h
  10. index c86df2f85bc..0c3f8cf888c 100644
  11. --- a/libgcc/config/riscv/linux-unwind.h
  12. +++ b/libgcc/config/riscv/linux-unwind.h
  13. @@ -1,4 +1,4 @@
  14. -/* Copyright (C) 2016-2022 Free Software Foundation, Inc.
  15. +/* Copyright (C) 2016-2021 Free Software Foundation, Inc.
  16. This file is free software; you can redistribute it and/or modify it
  17. under the terms of the GNU General Public License as published by the
  18. @@ -29,6 +29,25 @@
  19. #define ECALL 0x00000073
  20. #define MD_FALLBACK_FRAME_STATE_FOR riscv_fallback_frame_state
  21. +/* RISC-V Glibc has removed its own sigcontext.h and use the linux kernel's
  22. + one, however the struct layout is little different between those two
  23. + version, fortunately they have identical layout, so we just need a
  24. + magical way to detect which one we are used. */
  25. +#ifdef _ASM_RISCV_SIGCONTEXT_H
  26. +#define SIGCONTEXT_PC(SC) (SC)->sc_regs.pc
  27. +#else
  28. +#define SIGCONTEXT_PC(SC) (SC)->gregs[0]
  29. +#endif
  30. +
  31. +/* RISC-V Glibc has removed its own sigcontext.h and use the linux kernel's
  32. + one, however the struct layout is little different between those two
  33. + version, fortunately they have identical layout, so we just need a
  34. + magical way to detect which one we are used. */
  35. +#ifdef _ASM_RISCV_SIGCONTEXT_H
  36. +#define SIGCONTEXT_PC(SC) (SC)->sc_regs.pc
  37. +#else
  38. +#define SIGCONTEXT_PC(SC) (SC)->gregs[0]
  39. +#endif
  40. static _Unwind_Reason_Code
  41. riscv_fallback_frame_state (struct _Unwind_Context *context,
  42. @@ -50,6 +69,9 @@ riscv_fallback_frame_state (struct _Unwind_Context *context,
  43. uint16_t *pc = context->ra;
  44. struct sigcontext *sc;
  45. int i;
  46. + _Unwind_Ptr reg_ptr;
  47. + /* Get regsister offest from register size. */
  48. + _Unwind_Ptr reg_offset = __riscv_xlen / 8;
  49. /* A signal frame will have a return address pointing to
  50. __default_sa_restorer. This code is hardwired as:
  51. @@ -71,19 +93,22 @@ riscv_fallback_frame_state (struct _Unwind_Context *context,
  52. fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__;
  53. fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
  54. + reg_ptr = (_Unwind_Ptr) &sc->sc_regs.pc;
  55. for (i = 0; i < 32; i++)
  56. {
  57. fs->regs.reg[i].how = REG_SAVED_OFFSET;
  58. - fs->regs.reg[i].loc.offset = (_Unwind_Ptr) &sc->gregs[i] - new_cfa;
  59. + fs->regs.reg[i].loc.offset =
  60. + (_Unwind_Ptr) &SIGCONTEXT_PC (sc) + (i * reg_offset) - new_cfa;
  61. }
  62. fs->signal_frame = 1;
  63. fs->retaddr_column = __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__;
  64. fs->regs.reg[fs->retaddr_column].how = REG_SAVED_VAL_OFFSET;
  65. fs->regs.reg[fs->retaddr_column].loc.offset =
  66. - (_Unwind_Ptr) sc->gregs[0] - new_cfa;
  67. + (_Unwind_Ptr) SIGCONTEXT_PC (sc) - new_cfa;
  68. return _URC_NO_REASON;
  69. }
  70. +#undef SIGCONTEXT_PC
  71. #endif
  72. --
  73. 2.25.1