From patchwork Sun Jan 14 17:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 860487 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-471191-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="riVJGMp7"; 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 3zKNrv1P5Bz9sCZ for ; Mon, 15 Jan 2018 04:34:22 +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=S8RqF jiHhXfuxyzb7SI89wKw04VlxTaRhpHahTPUVLqQBjd4RjmIlwANQehBACNhhPFwy fWx+7bGKkIu8i/+Djar2sGLlL2UNoLX4lAw7CM6dYwrlFGjrG57k/E/KiF92RGvk i9WZr1nlkZm9XsJrwz7mMnS20egHH1U6QGAbOQ= 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=2yJMamMv3P1 oun+Hz+P00k55MKQ=; b=riVJGMp7wQWIb/A04NVZkkv4MWPJ42vgt3b9YuaACac N+p5WXuWaQY+EUK6BYoRsZc0F9lY5luw5EIKJDDP3A7fW5nUmgSRsyFBac0KsEWP yUJ7vVdJ4A/TzxkwomAlYmUw8Z91MigjE9ngSJevsbOY4OcK1mC2f7TW03nFkAOM = Received: (qmail 15106 invoked by alias); 14 Jan 2018 17:34:15 -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 13286 invoked by uid 89); 14 Jan 2018 17:34:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, 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; Sun, 14 Jan 2018 17:34:13 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0EHXh8I058968 for ; Sun, 14 Jan 2018 12:34:11 -0500 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fg0fh3e3u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 14 Jan 2018 12:34:11 -0500 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 14 Jan 2018 12:34:10 -0500 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 14 Jan 2018 12:34:07 -0500 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0EHY64c41550036; Sun, 14 Jan 2018 17:34:07 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FE2E112047; Sun, 14 Jan 2018 12:32:16 -0500 (EST) Received: from BigMac.local (unknown [9.80.219.102]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP id 27966112040; Sun, 14 Jan 2018 12:32:16 -0500 (EST) To: GCC Patches , Segher Boessenkool Cc: David Edelsohn From: Bill Schmidt Subject: [PATCH, rs6000] Executable tests for -msafe-indirect-jumps Date: Sun, 14 Jan 2018 11:34:06 -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: 18011417-0056-0000-0000-00000408B7EB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008376; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00974977; UDB=6.00494109; IPR=6.00754904; BA=6.00005775; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019034; XFM=3.00000015; UTC=2018-01-14 17:34:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011417-0057-0000-0000-00000840132A Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-14_10:, , 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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801140251 X-IsSubscribed: yes Hi, It was pointed out off-list that I should add some executable tests for the new -msafe-indirect-jumps implementation. This patch adds three such tests to demonstrate correct behavior. Tested on powerpc64-linux-gnu and powerpc64le-linux-gnu. Are these tests okay for trunk after the other patch is approved? Thanks, Bill 2018-01-14 Bill Schmidt * gcc.target/powerpc/safe-indirect-jump-4.c: New file. * gcc.target/powerpc/safe-indirect-jump-5.c: New file. * gcc.target/powerpc/safe-indirect-jump-6.c: New file. Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-4.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-4.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-4.c (working copy) @@ -0,0 +1,25 @@ +/* { dg-do run { target { powerpc64le-*-* } } } */ +/* { dg-additional-options "-msafe-indirect-jumps" } */ + +/* Test for deliberate misprediction of indirect calls for ELFv2. */ + +int (*f)(); + +int __attribute__((noinline)) bar () +{ + return (*f) (); +} + +int g () +{ + return 26; +} + +int main () +{ + f = &g; + if (bar () != 26) + __builtin_abort (); + + return 0; +} Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-5.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-5.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-5.c (working copy) @@ -0,0 +1,55 @@ +/* { dg-do run { target { powerpc*-*-* } } } */ +/* { dg-additional-options "-msafe-indirect-jumps -Wno-pedantic" } */ + +/* Test for deliberate misprediction of computed goto. */ + +int __attribute__((noinline)) bar (int i) +{ + return 1960 + i; +} + +int __attribute__((noinline)) baz (int i) +{ + return i * i; +} + +int __attribute__((noinline)) spaz (int i) +{ + return i + 1; +} + +int foo (int x) +{ + static void *labptr[] = { &&lab0, &&lab1, &&lab2 }; + + if (x < 0 || x > 2) + return -1; + + goto *labptr[x]; + + lab0: + return bar (x); + + lab1: + return baz (x) + 1; + + lab2: + return spaz (x) / 2; +} + +int main () +{ + if (foo (0) != 1960) + __builtin_abort (); + + if (foo (1) != 2) + __builtin_abort (); + + if (foo (2) != 1) + __builtin_abort (); + + if (foo (3) != -1) + __builtin_abort (); + + return 0; +} Index: gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-6.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-6.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-6.c (working copy) @@ -0,0 +1,80 @@ +/* { dg-do run { target { powerpc*-*-* } } } */ +/* { dg-additional-options "-msafe-indirect-jumps" } */ + +/* Test for deliberate misprediction of jump tables. */ + +void __attribute__((noinline)) bar () +{ +} + +int foo (int x) +{ + int a; + + switch (x) + { + default: + a = -1; + break; + case 0: + a = x * x + 3; + break; + case 1: + a = x + 1; + break; + case 2: + a = x + x; + break; + case 3: + a = x << 3; + break; + case 4: + a = x >> 1; + break; + case 5: + a = x; + break; + case 6: + a = 0; + break; + case 7: + a = x * x + x; + break; + } + + bar(); + + return a; +} + +int main () +{ + if (foo (0) != 3) + __builtin_abort (); + + if (foo (1) != 2) + __builtin_abort (); + + if (foo (2) != 4) + __builtin_abort (); + + if (foo (3) != 24) + __builtin_abort (); + + if (foo (4) != 2) + __builtin_abort (); + + if (foo (5) != 5) + __builtin_abort (); + + if (foo (6) != 0) + __builtin_abort (); + + if (foo (7) != 56) + __builtin_abort (); + + if (foo (8) != -1) + __builtin_abort (); + + return 0; +}