public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: soeren@soeren-tempel.net
To: gcc-patches@gcc.gnu.org
Cc: iant@golang.org, gofrontend-dev@googlegroups.com,
	schwab@linux-m68k.org, dalias@libc.org
Subject: [PATCH v2] libgo: Don't use pt_regs member in mcontext_t
Date: Sun,  6 Mar 2022 19:59:24 +0100	[thread overview]
Message-ID: <20220306185921.21496-1-soeren@soeren-tempel.net> (raw)
In-Reply-To: <20220102163713.26299-1-soeren@soeren-tempel.net>

From: Sören Tempel <soeren+git@soeren-tempel.net>

The .regs member is primarily intended to be used in conjunction with
ptrace. Since this code is not using ptrace, using .regs is a bad idea.
Furthermore, the code currently fails to compile on musl since the
pt_regs type (used by .regs) is in an incomplete type which has to be
completed by inclusion of the asm/ptrace.h Kernel header. Contrary to
glibc, this header is not indirectly included by musl through other
header files.

This patch fixes compilation of this code with musl libc by accessing
the register values via .gp_regs/.gregs (depending on 32-bit or 64-bit
PowerPC) instead of using .regs. For more details, see
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591261.html

For the offsets in gp_regs refer to the Kernel asm/ptrace.h header.

This patch has been tested on Alpine Linux ppc64le (uses musl libc).

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>

ChangeLog:

	* libgo/runtime/go-signal.c (defined): Use .gp_regs/.gregs
	  to access ppc64/ppc32 registers.
	(dumpregs): Ditto.
---
Changes since v1: Use .gp_regs/.gregs instead of .regs based on
feedback by Rich Felker, thereby avoiding the need to include
asm/ptrace.h for struct pt_regs.

 libgo/runtime/go-signal.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
index d30d1603adc..647ad606019 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -224,7 +224,11 @@ getSiginfo(siginfo_t *info, void *context __attribute__((unused)))
 #elif defined(__alpha__) && defined(__linux__)
 	ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.sc_pc;
 #elif defined(__PPC__) && defined(__linux__)
-	ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.regs->nip;
+#ifdef __PPC64__
+	ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gp_regs[32];
+#else
+	ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[32];
+#endif
 #elif defined(__PPC__) && defined(_AIX)
 	ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.jmp_context.iar;
 #elif defined(__aarch64__) && defined(__linux__)
@@ -338,16 +342,21 @@ dumpregs(siginfo_t *info __attribute__((unused)), void *context __attribute__((u
 #elif defined(__PPC__) && defined(__LITTLE_ENDIAN__) && defined(__linux__)
 	  {
 		mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
+#ifdef __PPC64__
+		greg_t *gp = &m->gp_regs;
+#else
+		greg_t *gp = &m->gregs;
+#endif
 		int i;
 
 		for (i = 0; i < 32; i++)
-			runtime_printf("r%d %X\n", i, m->regs->gpr[i]);
-		runtime_printf("pc  %X\n", m->regs->nip);
-		runtime_printf("msr %X\n", m->regs->msr);
-		runtime_printf("cr  %X\n", m->regs->ccr);
-		runtime_printf("lr  %X\n", m->regs->link);
-		runtime_printf("ctr %X\n", m->regs->ctr);
-		runtime_printf("xer %X\n", m->regs->xer);
+			runtime_printf("r%d %X\n", i, gp[i]);
+		runtime_printf("pc  %X\n", gp[32]);
+		runtime_printf("msr %X\n", gp[33]);
+		runtime_printf("cr  %X\n", gp[38]);
+		runtime_printf("lr  %X\n", gp[36]);
+		runtime_printf("ctr %X\n", gp[35]);
+		runtime_printf("xer %X\n", gp[37]);
 	  }
 #elif defined(__PPC__) && defined(_AIX)
 	  {

  parent reply	other threads:[~2022-03-06 19:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-02 16:37 [PATCH] libgo: include asm/ptrace.h for pt_regs definition on PowerPC soeren
2022-02-20 10:43 ` Sören Tempel
2022-02-21 17:25   ` [gofrontend-dev] " Ian Lance Taylor
2022-03-06 12:49     ` Sören Tempel
2022-03-06 15:22     ` Rich Felker
2022-03-06 16:59       ` Rich Felker
2022-02-20 11:01 ` Andreas Schwab
2022-03-06 18:59 ` soeren [this message]
2022-03-06 21:21   ` [PATCH v2] libgo: Don't use pt_regs member in mcontext_t Rich Felker
2022-03-07  7:09     ` [PATCH v3] " soeren
2022-03-07 22:59       ` Ian Lance Taylor
2022-03-08 13:23         ` Rich Felker
2022-03-09  7:26         ` Sören Tempel
2022-03-09 11:52           ` Rich Felker
2022-03-11  7:34             ` [PATCH v4] " soeren
2022-03-31 16:41               ` Sören Tempel
2022-03-31 20:26                 ` Ian Lance Taylor
2022-04-02  8:21                   ` Sören Tempel
2022-04-03  2:02                     ` Ian Lance Taylor
2022-04-03  9:28                       ` Sören Tempel
2022-04-11 17:25                         ` Sören Tempel
2022-04-11 17:35                           ` Ian Lance Taylor
2022-04-11 18:28                             ` Sören Tempel
2022-04-14 22:15                               ` Ian Lance Taylor
2022-04-21  0:50                                 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220306185921.21496-1-soeren@soeren-tempel.net \
    --to=soeren@soeren-tempel.net \
    --cc=dalias@libc.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    --cc=iant@golang.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).