From patchwork Thu Oct 29 08:39:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 40915 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 554A73985400; Thu, 29 Oct 2020 08:39:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554A73985400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1603960787; bh=5Kne+4q5vKxnmyCoR7bWKslduMxBE/zoZxCxkO12HDg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M0Wuz+3ktwxSfMttjspJZxhShacSDybxRI0Fs8pcI3cxhCtWRK08Rsw98mwGR0MjL EVCDiStJvIhDMflplSAgAAR2Dht2ZFdAQ6Dq4lfcxmDDfm6z2XU8wrhBBZav8+23px cbFaSq/oSUAE7BvhXtuY6n9h8sbOl+SfJY4umVfQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130070.outbound.protection.outlook.com [40.107.13.70]) by sourceware.org (Postfix) with ESMTPS id E221A3854810 for ; Thu, 29 Oct 2020 08:39:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E221A3854810 Received: from AM5PR0701CA0003.eurprd07.prod.outlook.com (2603:10a6:203:51::13) by AM0PR08MB3699.eurprd08.prod.outlook.com (2603:10a6:208:10c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Thu, 29 Oct 2020 08:39:38 +0000 Received: from AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:51:cafe::74) by AM5PR0701CA0003.outlook.office365.com (2603:10a6:203:51::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.11 via Frontend Transport; Thu, 29 Oct 2020 08:39:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT057.mail.protection.outlook.com (10.152.17.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3520.15 via Frontend Transport; Thu, 29 Oct 2020 08:39:38 +0000 Received: ("Tessian outbound 7c188528bfe0:v64"); Thu, 29 Oct 2020 08:39:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c914f13c2493209f X-CR-MTA-TID: 64aa7808 Received: from 159bf4683a33.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9271C231-7E86-468C-8545-BEC9A0F69C6F.1; Thu, 29 Oct 2020 08:39:31 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 159bf4683a33.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 29 Oct 2020 08:39:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OdEVEFdFGg35OJkOy+SPaTPGUpkyKBExH5CMJKt4/XnMqj/tTAT69bFNfYq5CsQoBdbvckWxdKWwOTqtbB3ncmKpHZwceHZQ0urkjksrY8Hjvx+3X9uUBnsKftUoxP+jqJkQprKh3ErBVwwmBsy/mbBHo6Uf1PcPchCIpgnkBquc+0IOBTZxWpe6YKVGDPdxg5xFVrkdvIl/u3545b72alu41Dp9G/wYthmAJn9jZeIvLJ0QDpgxC5QAzeeD8WHmn+Oom3dJ/ARanz+tJ7UY605kVy5/S0rDlcMhAbMK6wwQnMedRY/ldvY4TXwRnGPxeSheZbpJlPKzFUh5Vl6WNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5Kne+4q5vKxnmyCoR7bWKslduMxBE/zoZxCxkO12HDg=; b=Buxeyn2O/25eAWtHu6NNJwZYDIIYfPsD+1boozvomp+sfs7PtpI6L4HIJzWJYifTTmtdoJ6wquacJ16d/wLCc9lLvExUzAs4NlzPm9FKaK/L4QTpBxgOvumYosOi2MjPr10cIRgoU5Lzksl+cPhprTY1yiwoeLQ7UMttnd+3SUdP5hUvBkTZEYyhQSyrM06dY+Bc9Bb8FqJOvgoP0CZ11Ks/tNesM6AtHKkCgjP1ixQA/1qo2Hj971rkrX1SJDYhU95WQvur9eXvK279n1zR1Ofz2jHuKOoU3G1/pX1Yo4WmyJ8h9NQtu+myBc4HqaEMniUVRMlNThPFKKbPZQatsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) by PR3PR08MB5611.eurprd08.prod.outlook.com (2603:10a6:102:85::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19; Thu, 29 Oct 2020 08:39:31 +0000 Received: from PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::2904:edcf:b299:f792]) by PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::2904:edcf:b299:f792%3]) with mapi id 15.20.3499.024; Thu, 29 Oct 2020 08:39:31 +0000 To: libc-alpha@sourceware.org Subject: [PATCH 2/2] aarch64: Add variant PCS lazy binding test [BZ #26798] Date: Thu, 29 Oct 2020 08:39:23 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0090.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::30) To PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.54) by LO2P265CA0090.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Thu, 29 Oct 2020 08:39:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7aaf6a97-d97a-4b96-397c-08d87be62bd5 X-MS-TrafficTypeDiagnostic: PR3PR08MB5611:|AM0PR08MB3699: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6108;OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: U38PP11dJC1Ar5EE58tM0yiid6mzE3U9d+dRS3qsqi1ZPWfwfjeqli4p/Set2QFmVU13VFA4k/nFYXpX5xz8613Vjz7e9m/ZzxWqT4jV6Q6C4uD12jQBT1/x0jJvGXsubwsftqzfh1uBJW+hTeNFaJNl0DTkGmYpdAZU/okEUQWGe59l0Vb7FmXIZ5VVkBZzewrymZTjUUzverucEY6cGnljs5axDI5AXZSyVsx9VuUaJigU+1JNlLTPCDViCnSNRkxVePZI6vOFZq4ZsCcpXUzl3h5odogp+f8Z4TRIeJ0BDfzWdQMkt0FI6WtLUOYH/L618r1MeH5/dksdtUDcXn5rB1jSbpWg1M53sFxOUjCgv54eetny7XAhDAL+BVlYCvAlybMyarH+BPeNtNKhWLmQe8kU6ba8ms0HvhR+p9U1MShFhFzNlzI3L0oIGeknVIabS9ev25m8QiGwuePetf/bsApVZTAqNi3KRmqJm5U= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PR3PR08MB5564.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(346002)(136003)(376002)(366004)(6916009)(6666004)(316002)(2906002)(30864003)(83380400001)(5660300002)(86362001)(6512007)(36756003)(478600001)(44832011)(8676002)(66946007)(66556008)(66476007)(8936002)(6486002)(956004)(2616005)(52116002)(186003)(6506007)(69590400008)(26005)(16526019)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QeGeViWNz/k1D4wPXkmDtRChMLs19h3i9alhKtjHyju7hBm0aPcgINYBKrLrNl/ikDoO1bnUb0PJuXowRkRVClGJ60BHODQMcg+SOTPuYtZNvZ8Z8A1+/oN/S9y58wPZD9qkNTTtNKPmoTn7T5t/evgNL+jkWfTbm9nxzvtufV1DJ7EYVo9EZko4wKytqOSj8Ddvqz30T/l/l4nVVI2iY1PAF8wcBSub5nyNM1uPOPG4rXhnrEtUn+vA6qlbrmG7zBYBGg1E8YEMVpgJRliUkJq6JJnjCFC2PW/UnQFG0uXYpMPFfw3dinyVcM2F1K6PHlJuuwKzXHuktWSKXC0jxsxCkU2lffoSba7YZyl1gbi9gzATAjBlkt2xXVSRhypJcZzq8scEclFbU6x84gepuicN1IkD6/cvAP60pvbt4dS8Enn8bMrusLvBWtRjgD60Gbh+uSaFqC4kSTTVOaFG5zkrfUSg09EuKnYwNlegqcJoKY9p72r1ePpvf6Ez2UnMegaypLe0HOSiZWiBrD1hYktGIsjg56X6cjxxdfv4C+YBpDDiOyJVSLawdxlISghjaxma5gHAcP5HxQLIqXVhT2Oft2w8rY3+pJLREMySl51bFpA8lUvO0YVcuikoXNS1PllLQ99tkbwAocVCgiYGdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5611 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3cdbb1fd-b563-46bb-330f-08d87be62782 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7c63k4AuQh1VaxfgDLHHlbLDMzyTJ2qrYE3LJzdYnhX52Hqmrj4jOMyiX5oi7er4LaCzuMYTyhM9hNGVitaqtwusc9Ki7KA+CicBUbKyLnhjeHKaHw8sbG790erNRGN6NquFs0NAFGTXbOx3Bo6PwSHPAvvH1x/EwpRkd4t8Ykr6j8AXC4NLJPqBE4m2fiKJUlL705s+EcVz0L3H7gfRbMWTYYUkbFBzrsaeyPXmBIFE4hlb3APg87oOLS+SFRi2k+NKrMZJog7aK2CACYfh6sd6IXQW9ObsU6GdcKjbb8C21rBqRS41eOagpOXSvaRrGuW3B0f+qzTEJCF7pgwsNJrNaZfrUhbcHArK0ouc9yCK0zRgxES4LZFGZ4vulqsj5x/HIjfzRKDgopanficC8KL8BpkuKWcGZEWhMSyyZn3aBo0IXKwyGybUolEuRmmb4zQXAwQsv+/IEtYTNEhkMQcqR7VdQgISrwOOstvKwWcGUQRT2MtspH5B/pmnSXSnbACgqkb5sOWnOdeDyZ3vwA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(346002)(396003)(376002)(136003)(39860400002)(46966005)(69590400008)(26005)(47076004)(316002)(2906002)(86362001)(36906005)(44832011)(6486002)(356005)(82310400003)(8676002)(6512007)(83380400001)(82740400003)(5660300002)(81166007)(956004)(70206006)(30864003)(8936002)(70586007)(6666004)(6506007)(478600001)(336012)(36756003)(186003)(16526019)(6916009)(2616005)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2020 08:39:38.0214 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7aaf6a97-d97a-4b96-397c-08d87be62bd5 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT057.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3699 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This test fails without bug 26798 fixed because some integer registers likely get clobbered by lazy binding and variant PCS only allows x16 and x17 to be clobbered at call time. The test requires binutils 2.32.1 or newer for handling variant PCS symbols. SVE registers are not covered by this test, to avoid the complexity of handling multiple compile- and runtime feature support cases. --- sysdeps/aarch64/Makefile | 7 ++ sysdeps/aarch64/configure | 40 ++++++++++ sysdeps/aarch64/configure.ac | 22 +++++ sysdeps/aarch64/tst-vpcs-mod.S | 141 +++++++++++++++++++++++++++++++++ sysdeps/aarch64/tst-vpcs.c | 78 ++++++++++++++++++ 5 files changed, 288 insertions(+) create mode 100644 sysdeps/aarch64/tst-vpcs-mod.S create mode 100644 sysdeps/aarch64/tst-vpcs.c diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index 7f82fc055e..d8e06d27b2 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -17,6 +17,13 @@ sysdep-dl-routines += tlsdesc dl-tlsdesc gen-as-const-headers += dl-link.sym tests-internal += tst-ifunc-arg-1 tst-ifunc-arg-2 + +ifeq (yes,$(aarch64-variant-pcs)) +tests += tst-vpcs +modules-names += tst-vpcs-mod +LDFLAGS-tst-vpcs-mod.so = -Wl,-z,lazy +$(objpfx)tst-vpcs: $(objpfx)tst-vpcs-mod.so +endif endif ifeq ($(subdir),csu) diff --git a/sysdeps/aarch64/configure b/sysdeps/aarch64/configure index ac3cf6fd36..1f8223725f 100644 --- a/sysdeps/aarch64/configure +++ b/sysdeps/aarch64/configure @@ -255,3 +255,43 @@ if test $libc_cv_aarch64_pac_ret = yes; then $as_echo "#define HAVE_AARCH64_PAC_RET 1" >>confdefs.h fi + +# Check if binutils supports variant PCS symbols. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for variant PCS support" >&5 +$as_echo_n "checking for variant PCS support... " >&6; } +if ${libc_cv_aarch64_variant_pcs+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat > conftest.S <&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } \ + && { ac_try='$READELF -dW conftest.so | grep -q AARCH64_VARIANT_PCS' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + libc_cv_aarch64_variant_pcs=yes + fi + rm -rf conftest.* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_aarch64_variant_pcs" >&5 +$as_echo "$libc_cv_aarch64_variant_pcs" >&6; } +config_vars="$config_vars +aarch64-variant-pcs = $libc_cv_aarch64_variant_pcs" diff --git a/sysdeps/aarch64/configure.ac b/sysdeps/aarch64/configure.ac index 8b042d6d05..da2a8d81d0 100644 --- a/sysdeps/aarch64/configure.ac +++ b/sysdeps/aarch64/configure.ac @@ -61,3 +61,25 @@ EOF if test $libc_cv_aarch64_pac_ret = yes; then AC_DEFINE(HAVE_AARCH64_PAC_RET) fi + +# Check if binutils supports variant PCS symbols. +AC_CACHE_CHECK([for variant PCS support], [libc_cv_aarch64_variant_pcs], [dnl + cat > conftest.S <. */ + + .variant_pcs vpcs_call + .global vpcs_call + .type vpcs_call, %function +vpcs_call: + .cfi_startproc + hint 34 /* bti c. */ + + /* Save register state to *x0. */ + stp x0, x1, [x0] + stp x2, x3, [x0, 16] + stp x4, x5, [x0, 32] + stp x6, x7, [x0, 48] + stp x8, x9, [x0, 64] + stp x10, x11, [x0, 80] + stp x12, x13, [x0, 96] + stp x14, x15, [x0, 112] + stp x16, x17, [x0, 128] + stp x18, x19, [x0, 144] + stp x20, x21, [x0, 160] + stp x22, x23, [x0, 176] + stp x24, x25, [x0, 192] + stp x26, x27, [x0, 208] + stp x28, x29, [x0, 224] + mov x1, sp + stp x30, x1, [x0, 240] + stp q0, q1, [x0, 256] + stp q2, q3, [x0, 288] + stp q4, q5, [x0, 320] + stp q6, q7, [x0, 352] + stp q8, q9, [x0, 384] + stp q10, q11, [x0, 416] + stp q12, q13, [x0, 448] + stp q14, q15, [x0, 480] + stp q16, q17, [x0, 512] + stp q18, q19, [x0, 544] + stp q20, q21, [x0, 576] + stp q22, q23, [x0, 608] + stp q24, q25, [x0, 640] + stp q26, q27, [x0, 672] + stp q28, q29, [x0, 704] + stp q30, q31, [x0, 736] + ret + .cfi_endproc + .size vpcs_call, .-vpcs_call + + .global vpcs_call_regs + .type vpcs_call_regs, %function +vpcs_call_regs: + .cfi_startproc + hint 34 /* bti c. */ + + stp x29, x30, [sp, -160]! + mov x29, sp + + /* Save callee-saved registers. */ + stp x19, x20, [sp, 16] + stp x21, x22, [sp, 32] + stp x23, x24, [sp, 48] + stp x25, x26, [sp, 64] + stp x27, x28, [sp, 80] + stp d8, d9, [sp, 96] + stp d10, d11, [sp, 112] + stp d12, d13, [sp, 128] + stp d14, d15, [sp, 144] + + /* Initialize most registers from *x1, and save x0, x1, x29, x30, + and sp (== x29), so *x1 contains the register state. */ + stp x0, x1, [x1] + str x29, [x1, 232] + ldp x2, x3, [x1, 16] + ldp x4, x5, [x1, 32] + ldp x6, x7, [x1, 48] + ldp x8, x9, [x1, 64] + ldp x10, x11, [x1, 80] + ldp x12, x13, [x1, 96] + ldp x14, x15, [x1, 112] + ldp x16, x17, [x1, 128] + ldp x18, x19, [x1, 144] + ldp x20, x21, [x1, 160] + ldp x22, x23, [x1, 176] + ldp x24, x25, [x1, 192] + ldp x26, x27, [x1, 208] + ldr x28, [x1, 224] + /* Skip x29, x30, sp. */ + ldp q0, q1, [x1, 256] + ldp q2, q3, [x1, 288] + ldp q4, q5, [x1, 320] + ldp q6, q7, [x1, 352] + ldp q8, q9, [x1, 384] + ldp q10, q11, [x1, 416] + ldp q12, q13, [x1, 448] + ldp q14, q15, [x1, 480] + ldp q16, q17, [x1, 512] + ldp q18, q19, [x1, 544] + ldp q20, q21, [x1, 576] + ldp q22, q23, [x1, 608] + ldp q24, q25, [x1, 640] + ldp q26, q27, [x1, 672] + ldp q28, q29, [x1, 704] + ldp q30, q31, [x1, 736] + + /* Emulate a BL using B, but save x30 before the branch. */ + adr x30, .L_return_addr + stp x30, x29, [x1, 240] + b vpcs_call +.L_return_addr: + + /* Restore callee-saved registers. */ + ldp x19, x20, [sp, 16] + ldp x21, x22, [sp, 32] + ldp x23, x24, [sp, 48] + ldp x25, x26, [sp, 64] + ldp x27, x28, [sp, 80] + ldp d8, d9, [sp, 96] + ldp d10, d11, [sp, 112] + ldp d12, d13, [sp, 128] + ldp d14, d15, [sp, 144] + + ldp x29, x30, [sp], 160 + ret + .cfi_endproc + .size vpcs_call_regs, .-vpcs_call_regs diff --git a/sysdeps/aarch64/tst-vpcs.c b/sysdeps/aarch64/tst-vpcs.c new file mode 100644 index 0000000000..92a701eb7c --- /dev/null +++ b/sysdeps/aarch64/tst-vpcs.c @@ -0,0 +1,78 @@ +/* Test that variant PCS calls don't clobber registers with lazy binding. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +struct regs +{ + uint64_t x[32]; + union { + long double q[32]; + uint64_t u[64]; + } v; +}; + +/* Gives the registers in the caller and callee around a variant PCS call. + Most registers are initialized from BEFORE in the caller so they can + have values that likely show clobbers. Register state extensions such + as SVE is not covered here, only the base registers. */ +void vpcs_call_regs (struct regs *after, struct regs *before); + +static int +do_test (void) +{ + struct regs before, after; + int err = 0; + + unsigned char *p = (unsigned char *)&before; + for (int i = 0; i < sizeof before; i++) + p[i] = i & 0xff; + + vpcs_call_regs (&after, &before); + + for (int i = 0; i < 32; i++) + if (before.x[i] != after.x[i]) + { + if (i == 16 || i == 17) + /* Variant PCS allows clobbering x16 and x17. */ + continue; + err++; + printf ("x%d: before: 0x%016llx after: 0x%016llx\n", + i, + (unsigned long long)before.x[i], + (unsigned long long)after.x[i]); + } + for (int i = 0; i < 64; i++) + if (before.v.u[i] != after.v.u[i]) + { + err++; + printf ("v%d: before: 0x%016llx %016llx after: 0x%016llx %016llx\n", + i/2, + (unsigned long long)before.v.u[2*(i/2)+1], + (unsigned long long)before.v.u[2*(i/2)], + (unsigned long long)after.v.u[2*(i/2)+1], + (unsigned long long)after.v.u[2*(i/2)]); + } + if (err) + FAIL_EXIT1 ("The variant PCS call clobbered %d registers.\n", err); + return 0; +} + +#include