From patchwork Wed Jan 17 02:08:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 861987 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-471449-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="NyClg+qf"; 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 3zLrB504JJz9s7h for ; Wed, 17 Jan 2018 13:09:14 +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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=qHJZx DvF5LHbQEFxC3wMrhXD5Qwg9EG/PgrQiOxEoOAYOWPFqqLkVl0MstqyWo7Xagsdx T97xkEW78rjlrApdn5yWZ2F308L8plCIXiwh5CTwwAkIn6LvhSAc+nddtXtKRwze AFv8G+8c5p/qBx32uL91bRozCdyI/AkBoSTkLY= 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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=S0ZDNCjybBh O0x//pahfbBwmtVE=; b=NyClg+qfJc3CuID2fmL/8tmvnn+A3oJ/3zPgYcJfKvp OcPiFXg3/9E6ArfI/Xti1ZYPo2Cj/ivA5Ii0xDmmy2P9/ZTUr1VpetjHndMGCCyT ju4J38XgrJIw2Ixu603bRQOaUINxzpG5lcxBxYXv6O1T6emu7mDjnfT4Ah9le/7U = Received: (qmail 122371 invoked by alias); 17 Jan 2018 02:09:06 -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 122290 invoked by uid 89); 17 Jan 2018 02:09:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Jan 2018 02:09:03 +0000 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0H24gH1020029 for ; Tue, 16 Jan 2018 21:09:02 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fhsfy8cjt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 21:09:01 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 19:09:00 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Jan 2018 19:08:59 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0H28wYJ7471552; Tue, 16 Jan 2018 19:08:58 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 97A03C6042; Tue, 16 Jan 2018 19:08:58 -0700 (MST) Received: from bigmac.rchland.ibm.com (unknown [9.10.86.45]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 4F057C603E; Tue, 16 Jan 2018 19:08:58 -0700 (MST) To: GCC Patches Cc: Segher Boessenkool , David Edelsohn From: Bill Schmidt Subject: [PATCH v2, rs6000] Implement 32- and 64-bit BE handling for -mno-speculate-indirect-jumps Date: Tue, 16 Jan 2018 20:08:57 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18011702-0008-0000-0000-0000092DFA68 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008392; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000246; SDB=6.00976105; UDB=6.00494786; IPR=6.00756033; BA=6.00005781; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019082; XFM=3.00000015; UTC=2018-01-17 02:09:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011702-0009-0000-0000-000045958322 Message-Id: <3e150d8a-f6be-4334-b4ed-63155bfc4119@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-16_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801170027 X-IsSubscribed: yes Hi, This patch supercedes and extends https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01479.html, adding the remaining big-endian support for -mno-speculate-indirect-jumps. This includes 32-bit support for indirect calls and sibling calls, and 64-bit support for indirect calls. The endian-neutral switch handling has already been committed. Using -m32 -O2 on safe-indirect-jumps-1.c results in a test for a sibling call, so this has been added as safe-indirect-jumps-8.c. Also, safe-indirect-jumps-7.c adds a variant that will not generate a sibling call for -m32, so we still get indirect call coverage. Bootstrapped and tested on powerpc64-linux-gnu and powerpc64le-linux-gnu with no regressions. Is this okay for trunk? Thanks, Bill [gcc] 2018-01-16 Bill Schmidt * config/rs6000/rs6000.md (*call_indirect_nonlocal_sysv): Generate different code for -mno-speculate-indirect-jumps. (*call_value_indirect_nonlocal_sysv): Likewise. (*call_indirect_aix): Disable for -mno-speculate-indirect-jumps. (*call_indirect_aix_nospec): New define_insn. (*call_value_indirect_aix): Disable for -mno-speculate-indirect-jumps. (*call_value_indirect_aix_nospec): New define_insn. (*sibcall_nonlocal_sysv): Generate different code for -mno-speculate-indirect-jumps. (*sibcall_value_nonlocal_sysv): Likewise. [gcc/testsuite] 2018-01-16 Bill Schmidt * gcc.target/powerpc/safe-indirect-jump-1.c: Remove endian restriction, but still restrict to 64-bit. * gcc.target/powerpc/safe-indirect-jump-7.c: New file. * gcc.target/powerpc/safe-indirect-jump-8.c: New file. Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 256753) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -10453,10 +10453,35 @@ else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - return "b%T0l"; + if (rs6000_speculate_indirect_jumps + || which_alternative == 1 || which_alternative == 3) + return "b%T0l"; + else + return "crset eq\;beq%T0l-"; } [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr "length" "4,4,8,8")]) + (set (attr "length") + (cond [(and (eq (symbol_ref "which_alternative") (const_int 0)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 0)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "8") + (eq (symbol_ref "which_alternative") (const_int 1)) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "12") + (eq (symbol_ref "which_alternative") (const_int 3)) + (const_string "8")] + (const_string "4")))]) (define_insn_and_split "*call_nonlocal_sysv" [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s")) @@ -10541,10 +10566,35 @@ else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - return "b%T1l"; + if (rs6000_speculate_indirect_jumps + || which_alternative == 1 || which_alternative == 3) + return "b%T1l"; + else + return "crset eq\;beq%T1l-"; } [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr "length" "4,4,8,8")]) + (set (attr "length") + (cond [(and (eq (symbol_ref "which_alternative") (const_int 0)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 0)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "8") + (eq (symbol_ref "which_alternative") (const_int 1)) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "12") + (eq (symbol_ref "which_alternative") (const_int 3)) + (const_string "8")] + (const_string "4")))]) (define_insn_and_split "*call_value_nonlocal_sysv" [(set (match_operand 0 "" "") @@ -10669,11 +10719,22 @@ (use (match_operand:P 2 "memory_operand" ",")) (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] - "DEFAULT_ABI == ABI_AIX" + "DEFAULT_ABI == ABI_AIX && rs6000_speculate_indirect_jumps" " 2,%2\;b%T0l\; 2,%3(1)" [(set_attr "type" "jmpreg") (set_attr "length" "12")]) +(define_insn "*call_indirect_aix_nospec" + [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) + (match_operand 1 "" "g,g")) + (use (match_operand:P 2 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (clobber (reg:P LR_REGNO))] + "DEFAULT_ABI == ABI_AIX && !rs6000_speculate_indirect_jumps" + "crset eq\; 2,%2\;beq%T0l-\; 2,%3(1)" + [(set_attr "type" "jmpreg") + (set_attr "length" "16")]) + (define_insn "*call_value_indirect_aix" [(set (match_operand 0 "" "") (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) @@ -10681,11 +10742,23 @@ (use (match_operand:P 3 "memory_operand" ",")) (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] - "DEFAULT_ABI == ABI_AIX" + "DEFAULT_ABI == ABI_AIX && rs6000_speculate_indirect_jumps" " 2,%3\;b%T1l\; 2,%4(1)" [(set_attr "type" "jmpreg") (set_attr "length" "12")]) +(define_insn "*call_value_indirect_aix_nospec" + [(set (match_operand 0 "" "") + (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) + (match_operand 2 "" "g,g"))) + (use (match_operand:P 3 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (clobber (reg:P LR_REGNO))] + "DEFAULT_ABI == ABI_AIX && !rs6000_speculate_indirect_jumps" + "crset eq\; 2,%3\;beq%T1l-\; 2,%4(1)" + [(set_attr "type" "jmpreg") + (set_attr "length" "16")]) + ;; Call to indirect functions with the ELFv2 ABI. ;; Operand0 is the addresss of the function to call ;; Operand2 is the offset of the stack location holding the current TOC pointer @@ -10909,7 +10982,13 @@ output_asm_insn (\"creqv 6,6,6\", operands); if (which_alternative >= 2) - return \"b%T0\"; + { + if (rs6000_speculate_indirect_jumps) + return \"b%T0\"; + else + /* Can use CR0 since it is volatile across sibcalls. */ + return \"crset eq\;beq%T0-\;b .\"; + } else if (DEFAULT_ABI == ABI_V4 && flag_pic) { gcc_assert (!TARGET_SECURE_PLT); @@ -10919,7 +10998,28 @@ return \"b %z0\"; }" [(set_attr "type" "branch") - (set_attr "length" "4,8,4,8")]) + (set (attr "length") + (cond [(eq (symbol_ref "which_alternative") (const_int 0)) + (const_string "4") + (eq (symbol_ref "which_alternative") (const_int 1)) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "12") + (and (eq (symbol_ref "which_alternative") (const_int 3)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 3)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "16")] + (const_string "4")))]) (define_insn "*sibcall_value_nonlocal_sysv" [(set (match_operand 0 "" "") @@ -10939,7 +11039,13 @@ output_asm_insn (\"creqv 6,6,6\", operands); if (which_alternative >= 2) - return \"b%T1\"; + { + if (rs6000_speculate_indirect_jumps) + return \"b%T1\"; + else + /* Can use CR0 since it is volatile across sibcalls. */ + return \"crset eq\;beq%T1-\;b .\"; + } else if (DEFAULT_ABI == ABI_V4 && flag_pic) { gcc_assert (!TARGET_SECURE_PLT); @@ -10949,7 +11055,28 @@ return \"b %z1\"; }" [(set_attr "type" "branch") - (set_attr "length" "4,8,4,8")]) + (set (attr "length") + (cond [(eq (symbol_ref "which_alternative") (const_int 0)) + (const_string "4") + (eq (symbol_ref "which_alternative") (const_int 1)) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "4") + (and (eq (symbol_ref "which_alternative") (const_int 2)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "12") + (and (eq (symbol_ref "which_alternative") (const_int 3)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 1))) + (const_string "8") + (and (eq (symbol_ref "which_alternative") (const_int 3)) + (eq (symbol_ref "rs6000_speculate_indirect_jumps") + (const_int 0))) + (const_string "16")] + (const_string "4")))]) ;; AIX ABI sibling call patterns. Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-1.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-1.c (revision 256753) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-1.c (working copy) @@ -1,7 +1,7 @@ -/* { dg-do compile { target { powerpc64le-*-* } } } */ +/* { dg-do compile { target { lp64 } } } */ /* { dg-additional-options "-mno-speculate-indirect-jumps" } */ -/* Test for deliberate misprediction of indirect calls for ELFv2. */ +/* Test for deliberate misprediction of indirect calls. */ extern int (*f)(); Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-7.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-7.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-7.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-mno-speculate-indirect-jumps" } */ + +/* Test for deliberate misprediction of indirect calls. */ + +extern int (*f)(); + +int bar () +{ + return (*f) () * 53; +} + +/* { dg-final { scan-assembler "crset eq" } } */ +/* { dg-final { scan-assembler "beqctrl-" } } */ Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-8.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-8.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-8.c (working copy) @@ -0,0 +1,15 @@ +/* { dg-do compile { target { ilp32 } } } */ +/* { dg-additional-options "-O2 -mno-speculate-indirect-jumps" } */ + +/* Test for deliberate misprediction of -m32 sibcalls. */ + +extern int (*f)(); + +int bar () +{ + return (*f) (); +} + +/* { dg-final { scan-assembler "crset eq" } } */ +/* { dg-final { scan-assembler "beqctr-" } } */ +/* { dg-final { scan-assembler "b ." } } */