From patchwork Tue Aug 1 19:12:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 129439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2878428vqg; Tue, 1 Aug 2023 12:13:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9WI5wXfTiyYC/IcxOtctpwVlga/09t6V6KsoATd+n5VKEh9A4bcPU9Sy3zdFXCt4MY/Sj X-Received: by 2002:a17:906:ef90:b0:99b:ca5d:1467 with SMTP id ze16-20020a170906ef9000b0099bca5d1467mr3018678ejb.60.1690917198962; Tue, 01 Aug 2023 12:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690917198; cv=none; d=google.com; s=arc-20160816; b=tqI2BYDtJ6QpcKCV2xADl3o/XYktyopCvBNvO+ZmJw0OaYYEdJrdindmX2/XIkr3c7 dccW5+gfNuQIQ3WbPYysEu7i9rUy/y00CYtpBtFzuflwHk6g6pSj9nu5ZsmLQL9sjAG0 DBtUgelDjR3RSjIKNNQePnbdJT3Zln0MU0y0yGl+vwqHKWNkUf3r9Ax5r1UFpA0Gox7L 975axbr8PM4tTiR+M4TxeDmpxHqvW2nhaVvjiTlcLtNsyaXeOLOMJPiqHvKcLiioV2wx IAotf5c9tlyCS96hRnVVB96F4lJbE+T3PyZB3hdUX421nfn7bl3DsVI+538a0W7EXJN2 KRbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=JcH/YK6cq/vENHE5nbU49ezQS/y4X6ixAyFlYjaoiEU=; fh=x1h20eC6OEbeS14WK7k/sRqe0Ok+YMWKyKnfNbGv36Y=; b=hGypRsNL+8LFpxtHYf0naBrsGgFB9u7RmjSw9Dn8fzRuh5/FrE4ZoFYuG4LC0Ce4cv ViyI1OIYhNpRbFhhiDaO13I0oe0C3zgF/z7jJHEAQ6+yyXD3rXee/j3MkJ79G/WvrIfp WZst9xBdPicfkU4h7J0E3HmuzXZc6WnY7U6K8dnyEDR6j2Wr9Rz/Vl3LTDgRRoIVO7nV HgTUEsRQLnlslYvnNl97bcYZ6sUccbw2E75MFr+0tz2XYNzwWzV6z87AbsbKuQD3tT6y rTY7m/B2Lm/fqGjbyEeENEAOOa/E+pUJxm49or75KLjPheeo4Ftbl3m8LLNWrspViCrH 558Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Tn8whpRN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z17-20020a170906815100b0099bd5ad1e95si9572268ejw.498.2023.08.01.12.13.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 12:13:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Tn8whpRN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D88523858C5E for ; Tue, 1 Aug 2023 19:13:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D88523858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690917197; bh=JcH/YK6cq/vENHE5nbU49ezQS/y4X6ixAyFlYjaoiEU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Tn8whpRNslRv78gbhVcY2W4d1tESyq6cJip8Hos6U7ddXk7Xh2SIfvp4YM9368NTK LufldXHg7McX5LWRi+QlCQG1O9c94T2WAsS1hhPHRoa1VfeHBQedXv/wKS00WLtctt hXAYFg8FamccLUx4Vu6bnP0/HWNAWQlrrcl3z6I0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 030083858D39 for ; Tue, 1 Aug 2023 19:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 030083858D39 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 371JBiaO006155 for ; Tue, 1 Aug 2023 19:12:29 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3s77rtr8ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 01 Aug 2023 19:12:29 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 371HN4md006119 for ; Tue, 1 Aug 2023 19:12:28 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3s5d3sevk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 01 Aug 2023 19:12:28 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 371JCQkW63439252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 1 Aug 2023 19:12:26 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFF5520043 for ; Tue, 1 Aug 2023 19:12:26 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 929D920040 for ; Tue, 1 Aug 2023 19:12:26 +0000 (GMT) Received: from li-ecc9ffcc-3485-11b2-a85c-e633c5126265.fritz.box (unknown [9.171.88.104]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 1 Aug 2023 19:12:26 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [Committed] IBM Z: Handle unaligned symbols Date: Tue, 1 Aug 2023 21:12:26 +0200 Message-ID: <20230801191226.64464-1-krebbel@linux.ibm.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Dz25ppWMOT9K5XRSg3ud6IY0MZGHuafK X-Proofpoint-GUID: Dz25ppWMOT9K5XRSg3ud6IY0MZGHuafK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-01_16,2023-08-01_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308010171 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Andreas Krebbel via Gcc-patches From: Andreas Krebbel Reply-To: Andreas Krebbel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773055192942030090 X-GMAIL-MSGID: 1773055192942030090 The IBM Z ELF ABI mandates every symbol to reside on a 2 byte boundary in order to be able to use the larl instruction. However, in some situations it is difficult to enforce this, e.g. for common linker scripts as used in the Linux kernel. This patch introduces the -munaligned-symbols option. When that option is used, external symbols without an explicit alignment are considered unaligned and its address will be pushed into GOT or the literal pool. If the symbol in the final linker step turns out end up on a 2 byte boundary the linker is able to take this back and replace the indirect reference with larl again. This should minimize the effect to symbols which are actually unaligned in the end. Bootstrapped and regression tested on s390x. Committed to mainline. Backports to stable branches will follow. gcc/ChangeLog: * config/s390/s390.cc (s390_encode_section_info): Assume external symbols without explicit alignment to be unaligned if -munaligned-symbols has been specified. * config/s390/s390.opt (-munaligned-symbols): New option. gcc/testsuite/ChangeLog: * gcc.target/s390/aligned-1.c: New test. * gcc.target/s390/unaligned-1.c: New test. --- gcc/config/s390/s390.cc | 9 +++++++-- gcc/config/s390/s390.opt | 7 +++++++ gcc/testsuite/gcc.target/s390/aligned-1.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.target/s390/unaligned-1.c | 20 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/aligned-1.c create mode 100644 gcc/testsuite/gcc.target/s390/unaligned-1.c diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index 13970edcb5e..89474fd487a 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -13709,8 +13709,13 @@ s390_encode_section_info (tree decl, rtx rtl, int first) a larl/load-relative instruction. We only handle the cases that can go wrong (i.e. no FUNC_DECLs). All symbols without an explicit alignment are assumed to be 2 - byte aligned as mandated by our ABI. */ - if (DECL_USER_ALIGN (decl) && DECL_ALIGN (decl) % 16) + byte aligned as mandated by our ABI. This behavior can be + overridden for external symbols with the -munaligned-symbols + switch. */ + if (DECL_ALIGN (decl) % 16 + && (DECL_USER_ALIGN (decl) + || (!SYMBOL_REF_LOCAL_P (XEXP (rtl, 0)) + && s390_unaligned_symbols_p))) SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl, 0)); else if (DECL_ALIGN (decl) % 32) SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl, 0)); diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index 344aa551f44..496572046f7 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -329,3 +329,10 @@ Target Undocumented Var(unroll_only_small_loops) Init(0) Save mpreserve-args Target Var(s390_preserve_args_p) Init(0) Store all argument registers on the stack. + +munaligned-symbols +Target Var(s390_unaligned_symbols_p) Init(0) +Assume external symbols to be potentially unaligned. By default all +symbols without explicit alignment are assumed to reside on a 2 byte +boundary as mandated by the IBM Z ABI. + diff --git a/gcc/testsuite/gcc.target/s390/aligned-1.c b/gcc/testsuite/gcc.target/s390/aligned-1.c new file mode 100644 index 00000000000..2dc99cf66bd --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/aligned-1.c @@ -0,0 +1,20 @@ +/* Even symbols without explicite alignment are assumed to reside on a + 2 byte boundary, as mandated by the IBM Z ELF ABI, and therefore + can be accessed using the larl instruction. */ + +/* { dg-do compile } */ +/* { dg-options "-O3 -march=z900 -fno-section-anchors" } */ + +extern unsigned char extern_implicitly_aligned; +extern unsigned char extern_explicitly_aligned __attribute__((aligned(2))); +unsigned char aligned; + +unsigned char +foo () +{ + return extern_implicitly_aligned + extern_explicitly_aligned + aligned; +} + +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,extern_implicitly_aligned\n" 1 } } */ +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,extern_explicitly_aligned\n" 1 } } */ +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,aligned\n" 1 } } */ diff --git a/gcc/testsuite/gcc.target/s390/unaligned-1.c b/gcc/testsuite/gcc.target/s390/unaligned-1.c new file mode 100644 index 00000000000..421330aded1 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/unaligned-1.c @@ -0,0 +1,20 @@ +/* With the -munaligned-symbols option all external symbols without + explicite alignment are assumed to be potentially unaligned and + therefore cannot be accessed with larl. */ + +/* { dg-do compile } */ +/* { dg-options "-O3 -march=z900 -fno-section-anchors -munaligned-symbols" } */ + +extern unsigned char extern_unaligned; +extern unsigned char extern_explicitly_aligned __attribute__((aligned(2))); +unsigned char aligned; + +unsigned char +foo () +{ + return extern_unaligned + extern_explicitly_aligned + aligned; +} + +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,extern_unaligned\n" 0 } } */ +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,extern_explicitly_aligned\n" 1 } } */ +/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,aligned\n" 1 } } */