From patchwork Fri Feb 2 00:16:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 868481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-472510-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rUsvNvjU"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zXcxG35wbz9sBZ for ; Fri, 2 Feb 2018 11:17:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=aR/I+3KBUtnvhdhIpFFN+YlGxq7Lgmy4fZbxlAPPRuc57e DegqPm3kxG52v/chPcMy4iBFhHNHh3kwl6TBsdm7DwrBRxLXdOVc3XqV/QCz8DY2 aDffTww7c8Dar/WWijpa0bWY9tMovfuAeV0wZQMeVtdCSD6sIrCv945AKRCwY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=F1t99+vuJvMcAzPNClNWsH8uUww=; b=rUsvNvjUEtwFbnTkP7kw qPW4G09c7ChEsx63OiVjLjAbQNcBQP/OoYMBs6s5EK97WnQrgrolSqxXhPLFZS1+ oI/wrNuWQmYtP+4yEFaIyrS6dqQ3PF5fTcuP4JwryC04n1EZhWJA5tuQVToUDv88 2M6YGfJ0WvMIzTtpYxkRjfk= Received: (qmail 9038 invoked by alias); 2 Feb 2018 00:16:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9026 invoked by uid 89); 2 Feb 2018 00:16:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-8.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, LONGWORDS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=asleep, H*r:sk:j21-v6s, Scanning, 8332 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Feb 2018 00:16:48 +0000 Received: by mail-wm0-f52.google.com with SMTP id j21-v6so136717wmh.1 for ; Thu, 01 Feb 2018 16:16:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=E7qBPrtzQMw4wYvswVz98zgCd/8U3gNCZ3ij+aHmf1I=; b=O/StkExJ69sB5T36D4VWagEL8Kn7YRQoZrnDy8LsS9cHW7zG7RbfX4CmHQHokEhE3L 7KHf7m+tjboO8r+Wnlu3dPCbTHvbSWWNevfLPnTNBkFYunmFU6v4POdT7OhceerQLVK6 rGxfVgOq6kYKn08fFhxtBDw2IjesjR/Pt4RspEpRH0wtBQRZIVNLgMNweNPMmqxEAtBB IxMJaNMW4GrJud20eO1aU2oCCl3MMUJYPW9I7fhZovpBeP8Jcgt/gMdWZm/2aamL9fJJ fFL3RAnl3ZKYXs9mnCG2RuunPWwwbefh9da9r4DwCYcM35W98BpJkBYwzo00q/UeMPuD x9sw== X-Gm-Message-State: AKwxytcyrR9QIMJdkQhaX3gR0E453OCyfdAi3cpI/kgWCcXDzv1jq1S0 ADfzKRv7WUG619ttngWmBZNAHAHKj3Mrf8I7P72ai6jf X-Google-Smtp-Source: AH8x225Ihpm93dRuyfdJGhFd35EilOaa7adehXCY/d4A1V+SKOZI6Ykt/355qlF+9LzcUl5T2F6yMyr9o5PajOAlCAQ= X-Received: by 10.80.183.170 with SMTP id h39mr63736097ede.124.1517530606153; Thu, 01 Feb 2018 16:16:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.134.56 with HTTP; Thu, 1 Feb 2018 16:16:45 -0800 (PST) From: Ian Lance Taylor Date: Thu, 1 Feb 2018 16:16:45 -0800 Message-ID: Subject: libgo patch committed: scan register backing store on ia64 To: gcc-patches , gofrontend-dev@googlegroups.com This libgo patch by James Clarke scans the register backing store on ia64 when doing a Go garbage collection. On ia64, a separate stack is used for saving/restoring register frames, occupying the other end of the stack mapping. This must also be scanned for pointers into the heap. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 257319) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -e148068360699f24118950b728f23a5c98e1f85e +5e8a91bf239c253d7b5c84bd2c1dd3ecb18980e9 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: libgo/go/runtime/runtime2.go =================================================================== --- libgo/go/runtime/runtime2.go (revision 257312) +++ libgo/go/runtime/runtime2.go (working copy) @@ -409,11 +409,15 @@ type g struct { // gcnextsegment: unused // gcnextsp: current SP while executing a syscall // gcinitialsp: g0: top of stack; others: start of stack memory + // gcnextsp2: current secondary stack pointer (if present) + // gcinitialsp2: start of secondary stack (if present) gcstack uintptr gcstacksize uintptr gcnextsegment uintptr gcnextsp uintptr gcinitialsp unsafe.Pointer + gcnextsp2 uintptr + gcinitialsp2 unsafe.Pointer // gcregs holds the register values while executing a syscall. // This is set by getcontext and scanned by the garbage collector. Index: libgo/runtime/proc.c =================================================================== --- libgo/runtime/proc.c (revision 257312) +++ libgo/runtime/proc.c (working copy) @@ -308,6 +308,7 @@ runtime_mcall(FuncVal *fv) // Ensure that all registers are on the stack for the garbage // collector. __builtin_unwind_init(); + flush_registers_to_secondary_stack(); gp = g; mp = gp->m; @@ -322,6 +323,7 @@ runtime_mcall(FuncVal *fv) // We have to point to an address on the stack that is // below the saved registers. gp->gcnextsp = (uintptr)(&afterregs); + gp->gcnextsp2 = (uintptr)(secondary_stack_pointer()); #endif gp->fromgogo = false; getcontext(ucontext_arg(&gp->context[0])); @@ -500,6 +502,8 @@ runtime_mstart(void *arg) // is the top of the stack, not the bottom. gp->gcstacksize = 0; gp->gcnextsp = (uintptr)(&arg); + gp->gcinitialsp2 = secondary_stack_pointer(); + gp->gcnextsp2 = (uintptr)(gp->gcinitialsp2); #endif // Save the currently active context. This will return @@ -576,6 +580,8 @@ setGContext(void) gp->gcstack = 0; gp->gcstacksize = 0; gp->gcnextsp = (uintptr)(&val); + gp->gcinitialsp2 = secondary_stack_pointer(); + gp->gcnextsp2 = (uintptr)(gp->gcinitialsp2); #endif getcontext(ucontext_arg(&gp->context[0])); @@ -654,6 +660,7 @@ doentersyscall(uintptr pc, uintptr sp) void *v; g->gcnextsp = (uintptr)(&v); + g->gcnextsp2 = (uintptr)(secondary_stack_pointer()); } #endif @@ -694,6 +701,7 @@ doentersyscallblock(uintptr pc, uintptr void *v; g->gcnextsp = (uintptr)(&v); + g->gcnextsp2 = (uintptr)(secondary_stack_pointer()); } #endif @@ -756,6 +764,7 @@ runtime_malg(bool allocatestack, bool si *ret_stacksize = (uintptr)stacksize; newg->gcinitialsp = *ret_stack; newg->gcstacksize = (uintptr)stacksize; + newg->gcinitialsp2 = initial_secondary_stack_pointer(*ret_stack); #endif } return newg; @@ -807,6 +816,7 @@ resetNewG(G *newg, void **sp, uintptr *s if(*spsize == 0) runtime_throw("bad spsize in resetNewG"); newg->gcnextsp = (uintptr)(*sp); + newg->gcnextsp2 = (uintptr)(newg->gcinitialsp2); #endif } Index: libgo/runtime/runtime.h =================================================================== --- libgo/runtime/runtime.h (revision 257312) +++ libgo/runtime/runtime.h (working copy) @@ -437,6 +437,23 @@ void runtime_check(void) // the stacks are allocated by the splitstack library. extern uintptr runtime_stacks_sys; +/* + * ia64's register file is spilled to a separate stack, the register backing + * store, on window overflow, and must also be scanned. This occupies the other + * end of the normal stack allocation, growing upwards. + * We also need to ensure all register windows are flushed to the backing + * store, as unlike SPARC, __builtin_unwind_init doesn't do this on ia64. + */ +#ifdef __ia64__ +# define secondary_stack_pointer() __builtin_ia64_bsp() +# define initial_secondary_stack_pointer(stack_alloc) (stack_alloc) +# define flush_registers_to_secondary_stack() __builtin_ia64_flushrs() +#else +# define secondary_stack_pointer() nil +# define initial_secondary_stack_pointer(stack_alloc) nil +# define flush_registers_to_secondary_stack() +#endif + struct backtrace_state; extern struct backtrace_state *__go_get_backtrace_state(void); extern _Bool __go_file_line(uintptr, int, String*, String*, intgo *); Index: libgo/runtime/stack.c =================================================================== --- libgo/runtime/stack.c (revision 257312) +++ libgo/runtime/stack.c (working copy) @@ -34,6 +34,7 @@ void doscanstack(G *gp, void* gcw) { // Save registers on the stack, so that if we are scanning our // own stack we will see them. __builtin_unwind_init(); + flush_registers_to_secondary_stack(); doscanstack1(gp, gcw); } @@ -82,21 +83,32 @@ static void doscanstack1(G *gp, void *gc #else byte* bottom; byte* top; + byte* nextsp2; + byte* initialsp2; if(gp == runtime_g()) { // Scanning our own stack. bottom = (byte*)&gp; + nextsp2 = secondary_stack_pointer(); } else { // Scanning another goroutine's stack. // The goroutine is usually asleep (the world is stopped). bottom = (void*)gp->gcnextsp; if(bottom == nil) return; + nextsp2 = (void*)gp->gcnextsp2; } top = (byte*)(void*)(gp->gcinitialsp) + gp->gcstacksize; if(top > bottom) scanstackblock(bottom, (uintptr)(top - bottom), gcw); else scanstackblock(top, (uintptr)(bottom - top), gcw); + if (nextsp2 != nil) { + initialsp2 = (byte*)(void*)(gp->gcinitialsp2); + if(initialsp2 > nextsp2) + scanstackblock(nextsp2, (uintptr)(initialsp2 - nextsp2), gcw); + else + scanstackblock(initialsp2, (uintptr)(nextsp2 - initialsp2), gcw); + } #endif }