From patchwork Sun Mar 6 18:59:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 51603 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEB973858427 for ; Sun, 6 Mar 2022 19:09:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEB973858427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1646593758; bh=9FsTg5wASkDjwxb9ULwWw1D/R+hUZTj8g0Bhay2W3+8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yJ9NsHKdksz+QXHIh7oEkjd5UazrgpIKqMXBU/kQzxkqbGRUsIXICbE6ntrKUrNOW 6M5YTq0nc1iD1dNOmRGnbgOOf7+2XD/fyEB4uxiZnX6dCuOTspo9QenhsTEUr+/R2R TzAZL1pmj9lcG1kjqck3yoa3zVYXo0G0Gk1P2Eoo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTP id C7C543858D35; Sun, 6 Mar 2022 19:08:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7C543858D35 Received: from localhost (ip5f5ae040.dynamic.kabel-deutschland.de [95.90.224.64]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id bccb90bf (TLSv1.3:AEAD-AES256-GCM-SHA384:256:YES); Sun, 6 Mar 2022 20:08:45 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] libgo: Don't use pt_regs member in mcontext_t Date: Sun, 6 Mar 2022 19:59:24 +0100 Message-Id: <20220306185921.21496-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220102163713.26299-1-soeren@soeren-tempel.net> References: <20220102163713.26299-1-soeren@soeren-tempel.net> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: soeren--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: soeren@soeren-tempel.net Cc: dalias@libc.org, schwab@linux-m68k.org, iant@golang.org, gofrontend-dev@googlegroups.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Sören Tempel 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 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) {