From patchwork Wed May 15 19:17:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 244152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E052F2C009C for ; Thu, 16 May 2013 05:17:47 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=bm21tHOgeIEWnNm3ODKQZRrSiNCewJvauJlDvzkzrOMkakd1R8tN1 mHmXu8CBLdC/vjhwPA3s6DpE08zpi3wqm7u0Xc260MzhYyOTfr28QNZrboBihm+q UgXjDcKKE6cxI+QaQyvKHhfssoOAljkP6g1SQKZIdkc4Klz9geAS10= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=klI1s2HMPwlqAh9hxsvQMJbwgsk=; b=gJV44DIrB6cPzBZwroDa 7dDnVvgNj9nSS6yCkK2v6PAoeZAjHBiaQUGJlrBgm8wyNLbtOVBXarpmtkUa9BhS pjeX26XONf/X7fib6gT3blX7k596nl+vhUWscMNFejq0PcRj3/YQAfnGKM0Y73Tl Kt4vvjLggnI6Duf4yD9zxGY= Received: (qmail 21927 invoked by alias); 15 May 2013 19:17:41 -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 21900 invoked by uid 89); 15 May 2013 19:17:37 -0000 X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, SPF_PASS autolearn=no version=3.3.1 Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 15 May 2013 19:17:36 +0000 Received: by mail-wg0-f41.google.com with SMTP id y10so5464701wgg.0 for ; Wed, 15 May 2013 12:17:34 -0700 (PDT) X-Received: by 10.180.185.207 with SMTP id fe15mr17043712wic.33.1368645454329; Wed, 15 May 2013 12:17:34 -0700 (PDT) Received: from localhost ([2.28.235.144]) by mx.google.com with ESMTPSA id ek7sm30109412wic.4.2013.05.15.12.17.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 15 May 2013 12:17:33 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [MIPS, committed] Fix PR 57260 (sibling calls vs. lazy binding) Date: Wed, 15 May 2013 20:17:32 +0100 Message-ID: <87vc6kqchf.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 The sibling call optimisation shouldn't prevent functions from being lazily bound. This was a problem for n32 and n64 PIC, because MIPS lazy binding stubs require $gp to be valid on entry, and because $gp is a call-saved register. (o32 is OK because $gp is call-clobbered.) I was going to remove the MIPS_CALL_SIBCALL check in: /* If we're generating PIC, and this call is to a global function, try to allow its address to be resolved lazily. This isn't possible for sibcalls when $gp is call-saved because the value of $gp on entry to the stub would be our caller's gp, not ours. */ if (TARGET_EXPLICIT_RELOCS && !(type == MIPS_CALL_SIBCALL && TARGET_CALL_SAVED_GP) && mips_ok_for_lazy_binding_p (addr)) { addr = mips_got_load (dest, addr, SYMBOL_GOTOFF_CALL); emit_insn (gen_rtx_SET (VOIDmode, dest, addr)); return true; } but it is also used for sibling-style calls in C++ thunks. I think it's valid to override lazy binding in that case, since vtables prevent lazy binding anyway. Tested on mips64-linux-gnu and applied. Richard gcc/ PR target/57260 * config/mips/mips.c (mips_function_ok_for_sibcall): Don't allow sibling calls to functions that would normally be lazily bound, unless $gp is call-clobbered. gcc/testsuite/ PR target/57260 * gcc.target/mips/call-1.c: Restrict to o32. * gcc.target/mips/call-5.c, gcc.target/mips/call-6.c: New test. Index: gcc/config/mips/mips.c =================================================================== --- gcc/config/mips/mips.c 2013-05-14 19:25:06.061932211 +0100 +++ gcc/config/mips/mips.c 2013-05-14 20:21:56.647243683 +0100 @@ -6995,6 +6995,15 @@ mips_function_ok_for_sibcall (tree decl, && mips_call_may_need_jalx_p (decl)) return false; + /* Sibling calls should not prevent lazy binding. Lazy-binding stubs + require $gp to be valid on entry, so sibcalls can only use stubs + if $gp is call-clobbered. */ + if (decl + && TARGET_CALL_SAVED_GP + && !TARGET_ABICALLS_PIC0 + && !targetm.binds_local_p (decl)) + return false; + /* Otherwise OK. */ return true; } Index: gcc/testsuite/gcc.target/mips/call-1.c =================================================================== --- gcc/testsuite/gcc.target/mips/call-1.c 2012-08-27 17:27:13.000000000 +0100 +++ gcc/testsuite/gcc.target/mips/call-1.c 2013-05-14 19:51:06.188573399 +0100 @@ -1,10 +1,12 @@ -/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls" } */ +/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=32" } */ /* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalr\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalr\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,staticfunc\n1:\tjalr\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail\n1:\tjr\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail2\n1:\tjr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail3\n1:\tjr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail4\n1:\tjr\t" } } */ __attribute__ ((noinline)) static void staticfunc () { asm (""); } int normal (); @@ -31,3 +33,17 @@ NOMIPS16 void g () { tail2 (); } + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +} Index: gcc/testsuite/gcc.target/mips/call-5.c =================================================================== --- /dev/null 2013-05-10 09:05:06.836922288 +0100 +++ gcc/testsuite/gcc.target/mips/call-5.c 2013-05-14 19:51:01.492525330 +0100 @@ -0,0 +1,51 @@ +/* Like call-1.c, but for n32. We cannot use sibling calls for tail and tail2 + in this case (PR target/57260). */ +/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=n32" } */ +/* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,staticfunc\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail2\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail3\n1:\tjr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail4\n1:\tjr\t" } } */ + +__attribute__ ((noinline)) static void staticfunc () { asm (""); } +int normal (); +void normal2 (); + +NOMIPS16 f (int *p) +{ + *p = normal (); + normal2 (); + staticfunc (); + return 1; +} + +int tail (); + +NOMIPS16 h () +{ + return tail (); +} + +void tail2 (); + +NOMIPS16 void g () +{ + tail2 (); +} + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +} Index: gcc/testsuite/gcc.target/mips/call-6.c =================================================================== --- /dev/null 2013-05-10 09:05:06.836922288 +0100 +++ gcc/testsuite/gcc.target/mips/call-6.c 2013-05-14 20:15:08.281988889 +0100 @@ -0,0 +1,50 @@ +/* Like call-5.c, but for n64. */ +/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=64" } */ +/* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,staticfunc\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail2\n1:\tjalr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail3\n1:\tjr\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail4\n1:\tjr\t" } } */ + +__attribute__ ((noinline)) static void staticfunc () { asm (""); } +int normal (); +void normal2 (); + +NOMIPS16 f (int *p) +{ + *p = normal (); + normal2 (); + staticfunc (); + return 1; +} + +int tail (); + +NOMIPS16 h () +{ + return tail (); +} + +void tail2 (); + +NOMIPS16 void g () +{ + tail2 (); +} + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +}