0029-RISC-V-Handle-different-sigcontext-struct-layout.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From 6933ee285c67042cb88d0e898df75ee86ecae2fc Mon Sep 17 00:00:00 2001
  2. From: Kito Cheng <kito.cheng@sifive.com>
  3. Date: Tue, 18 Jan 2022 17:44:18 +0800
  4. Subject: [PATCH 29/30] RISC-V: Handle different sigcontext struct layout.
  5. RISC-V glibc intend to removed its own `sigcontext.h`[1] and use the
  6. linux
  7. kernel's one, however the struct layout is slightly different between
  8. those two
  9. version, fortunately they have identical layout, so we just need a
  10. magical way to detect which one we are used.
  11. libgcc/ChangeLog:
  12. * config/riscv/linux-unwind.h (SIGCONTEXT_PC): New.
  13. (riscv_fallback_frame_state): Use SIGCONTEXT_PC rather than
  14. sc->gregs[i].
  15. [1] https://sourceware.org/pipermail/libc-alpha/2022-January/135417.html
  16. ---
  17. libgcc/config/riscv/linux-unwind.h | 14 ++++++++++++--
  18. 1 file changed, 12 insertions(+), 2 deletions(-)
  19. diff --git a/libgcc/config/riscv/linux-unwind.h b/libgcc/config/riscv/linux-unwind.h
  20. index 931c2f2795d..3f83d10ffe1 100644
  21. --- a/libgcc/config/riscv/linux-unwind.h
  22. +++ b/libgcc/config/riscv/linux-unwind.h
  23. @@ -30,6 +30,16 @@
  24. #define MD_FALLBACK_FRAME_STATE_FOR riscv_fallback_frame_state
  25. +/* RISC-V Glibc has removed its own sigcontext.h and use the linux kernel's
  26. + one, however the struct layout is little different between those two
  27. + version, fortunately they have identical layout, so we just need a
  28. + magical way to detect which one we are used. */
  29. +#ifdef _ASM_RISCV_SIGCONTEXT_H
  30. +#define SIGCONTEXT_PC(SC) (SC)->sc_regs.pc
  31. +#else
  32. +#define SIGCONTEXT_PC(SC) (SC)->gregs[0]
  33. +#endif
  34. +
  35. static _Unwind_Reason_Code
  36. riscv_fallback_frame_state (struct _Unwind_Context *context,
  37. _Unwind_FrameState * fs)
  38. @@ -74,14 +84,14 @@ riscv_fallback_frame_state (struct _Unwind_Context *context,
  39. for (i = 0; i < 32; i++)
  40. {
  41. fs->regs.how[i] = REG_SAVED_OFFSET;
  42. - fs->regs.reg[i].loc.offset = (_Unwind_Ptr) &sc->gregs[i] - new_cfa;
  43. + fs->regs.reg[i].loc.offset = (_Unwind_Ptr) &SIGCONTEXT_PC (sc) + (i * __riscv_xlen / 8) - new_cfa;
  44. }
  45. fs->signal_frame = 1;
  46. fs->retaddr_column = __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__;
  47. fs->regs.how[fs->retaddr_column] = REG_SAVED_VAL_OFFSET;
  48. fs->regs.reg[fs->retaddr_column].loc.offset =
  49. - (_Unwind_Ptr) sc->gregs[0] - new_cfa;
  50. + (_Unwind_Ptr) SIGCONTEXT_PC (sc) - new_cfa;
  51. return _URC_NO_REASON;
  52. }
  53. --
  54. 2.25.1