From patchwork Fri Nov 6 22:18:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1395958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=p9tb2Dk6; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CSZXM0gF9z9sSf for ; Sat, 7 Nov 2020 09:18:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDA9A386EC54; Fri, 6 Nov 2020 22:18:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDA9A386EC54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1604701088; bh=NYSzxCi5rY9eoEKyaBQY5EHlV4NSf6jmRwlA6BlpXp8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=p9tb2Dk6l5pmG6srAadXMLVVVNd0oADUkbTcHbuioAeEGm+mj07eX0QJAgmNkHU1D gtwPkx15Z/Uil77TY0CGR1ixCpgNAVu2mYhl3RAwY4hBg20VVLA82cFtehWl/sFr3y Om9mJFWA0IEOJeWpYMjmCM9suSTYLTNXyw+DmR1M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 981A6386EC54 for ; Fri, 6 Nov 2020 22:18:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 981A6386EC54 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A6M3AYm123037; Fri, 6 Nov 2020 17:18:04 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com with ESMTP id 34n3jpnssq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Nov 2020 17:18:04 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0A6M7rNf011591; Fri, 6 Nov 2020 22:18:03 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma01dal.us.ibm.com with ESMTP id 34h0s89ryt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Nov 2020 22:18:03 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0A6MI2ke62652780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Nov 2020 22:18:02 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87119B2064; Fri, 6 Nov 2020 22:18:02 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B172AB2066; Fri, 6 Nov 2020 22:18:01 +0000 (GMT) Received: from [9.211.80.128] (unknown [9.211.80.128]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 6 Nov 2020 22:18:01 +0000 (GMT) To: Segher Boessenkool Subject: [PATCH] rs6000: Fix default alignment ABI break caused by MMA base support Message-ID: Date: Fri, 6 Nov 2020 16:18:00 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-06_06:2020-11-05, 2020-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 adultscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011060151 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Peter Bergner via Gcc-patches From: Peter Bergner Reply-To: Peter Bergner Cc: Bill Schmidt , Tulio Magno Quites Machado Filho , GCC Patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" As part of the MMA base support, we incremented BIGGEST_ALIGNMENT in order to align the __vector_pair and __vector_quad types to 256 and 512 bits respectively. This had the unintended effect of changing the default alignment used by __attribute__ ((__aligned__)) which causes an ABI break because of some dodgy code in GLIBC's struct pthread (GLIBC is going to fix that too). The fix in GCC is to revert the BIGGEST_ALIGNMENT change and to force the alignment on the type itself rather than the mode used by the type. This passes bootstrap and regtesting on powerpc64le-linux with no regressions. Ok for mainline and the GCC 10 release branch after some burn in? Peter gcc/ * config/rs6000/rs6000.h (BIGGEST_ALIGNMENT): Revert previous commit so as not to break the ABI. * config/rs6000/rs6000-call.c (rs6000_init_builtins): Set the ABI mandated alignment for __vector_pair and __vector_quad types. gcc/testsuite/ * gcc.target/powerpc/mma-alignment.c: New test. diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index bbd8060e143..5a47aa14722 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -776,8 +776,10 @@ extern unsigned rs6000_pointer_size; /* Allocation boundary (in *bits*) for the code of a function. */ #define FUNCTION_BOUNDARY 32 -/* No data type wants to be aligned rounder than this. */ -#define BIGGEST_ALIGNMENT (TARGET_MMA ? 512 : 128) +/* No data type is required to be aligned rounder than this. Warning, if + BIGGEST_ALIGNMENT is changed, then this may be an ABI break. An example + of where this can break an ABI is in GLIBC's struct _Unwind_Exception. */ +#define BIGGEST_ALIGNMENT 128 /* Alignment of field after `int : 0' in a structure. */ #define EMPTY_FIELD_BOUNDARY 32 diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 92378e958a9..3bd89a79bad 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -13191,12 +13191,14 @@ rs6000_init_builtins (void) if (TARGET_EXTRA_BUILTINS) { vector_pair_type_node = make_unsigned_type (256); + SET_TYPE_ALIGN (vector_pair_type_node, 256); SET_TYPE_MODE (vector_pair_type_node, POImode); layout_type (vector_pair_type_node); lang_hooks.types.register_builtin_type (vector_pair_type_node, "__vector_pair"); vector_quad_type_node = make_unsigned_type (512); + SET_TYPE_ALIGN (vector_quad_type_node, 512); SET_TYPE_MODE (vector_quad_type_node, PXImode); layout_type (vector_quad_type_node); lang_hooks.types.register_builtin_type (vector_quad_type_node, diff --git a/gcc/testsuite/gcc.target/powerpc/mma-alignment.c b/gcc/testsuite/gcc.target/powerpc/mma-alignment.c new file mode 100644 index 00000000000..09818931b48 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/mma-alignment.c @@ -0,0 +1,41 @@ +/* { dg-do run } */ +/* { dg-require-effective-target hard_float } */ +/* { dg-options "-O2 -mhard-float" } */ + +#include + +/* The MMA types below are enabled for pre-power10 compiles, because the + built-ins that use them must always be initialized in case the user has + a target attribute or pragma on a function that uses the MMA built-ins. + Since the test below doesn't need any other MMA support, we can enable + this test case on basically any cpu that has hard floating point + registers. */ + +struct +{ + int __attribute__ ((__aligned__)) ivar; + __vector_pair pair; + __vector_quad quad; +} s; + +int +main (void) +{ + /* Verify default alignment is 16-byte aligned (BIGGEST_ALIGNMENT). + This may change in the future, but that is an ABI break, so this + hardcoded test case is here to be a noisy FAIL as a warning, in + case the ABI change was unintended and unwanted. An example of where + this can break an ABI is in glibc's struct _Unwind_Exception. */ + if (__alignof__ (s.ivar) != 16) + abort (); + + /* Verify __vector_pair types are 32-byte aligned. */ + if (__alignof__ (s.pair) != 32) + abort (); + + /* Verify __vector_quad types are 64-byte aligned. */ + if (__alignof__ (s.quad) != 64) + abort (); + + return 0; +}