From patchwork Mon Feb 14 12:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andre Kempe X-Patchwork-Id: 34282 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:14aa:0:0:0:0 with SMTP id bz10csp5462630nkb; Mon, 14 Feb 2022 04:28:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJypIYSfNEJSWOjLzjXdS8Bk9kkt1ckVWn/GxHRwxE7VNvPcKi851qqPsEaxTrBuNtoiK8sb X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr11459709ejc.322.1644841706923; Mon, 14 Feb 2022 04:28:26 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kx3si20097936ejc.840.2022.02.14.04.28.25; Mon, 14 Feb 2022 04:28:26 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=3YQ0LxVh; dkim=neutral (body hash did not verify) header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=3YQ0LxVh; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2988568AAE6; Mon, 14 Feb 2022 14:28:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.107.21.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C503868AF89 for ; Mon, 14 Feb 2022 14:28:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FrY7rlv95Qt4UdYj0FJLMmfl14nBKoOwmGtpbCbqweE=; b=3YQ0LxVh24fjIbWdPn1TmMYBeOn6ZRYmSylc0LGo0kKzliyTiF4waKv9+1HppCNZTQFvAeT5/eTA9BSySay+PngDYILuGgLOmpPXsX3gd/dphqBq9j9uv3qfXzMLa5d+8J/qt0qplryGPsvBF0tKE8gnJrXj9xLMJLkxsY+jGaM= Received: from DB7PR05CA0005.eurprd05.prod.outlook.com (2603:10a6:10:36::18) by AS8PR08MB7078.eurprd08.prod.outlook.com (2603:10a6:20b:34f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Mon, 14 Feb 2022 12:28:12 +0000 Received: from DB5EUR03FT014.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::34) by DB7PR05CA0005.outlook.office365.com (2603:10a6:10:36::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.18 via Frontend Transport; Mon, 14 Feb 2022 12:28:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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 DB5EUR03FT014.mail.protection.outlook.com (10.152.20.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11 via Frontend Transport; Mon, 14 Feb 2022 12:28:12 +0000 Received: ("Tessian outbound 63bb5eb69ee8:v113"); Mon, 14 Feb 2022 12:28:12 +0000 X-CR-MTA-TID: 64aa7808 Received: from 82f60196293c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2A873AD5-44B7-4F8F-BF78-EEB82203A406.1; Mon, 14 Feb 2022 12:28:07 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 82f60196293c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 14 Feb 2022 12:28:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZsLrgmHxSx14VpKaZC4incVwLPR6PHsC2bJtrGSbbrDevccw3Nut7zCTbVbL5sP67p4u0GZXHsChc12eMMlEmSMoi6XZ+ZRdzwymaTQ7YoCE/QFga6dss/YWWUafE6O6H7pJAOyuhyukCrCjBUm+zkS5Wau7Z5YysESu60fhclFYZeZY04LLie35wMdSzHbcIdOOFQEKtIQWK6ZHNlJKXNDNPy0zm+ca96cKNgjLVqtG/ad4ao3ajDNVYR1TLeFC/hEJVobh79diQKVp9B02NEeFakrzGTaZ1QDm4BCROuF07ZP6wjVawf4OFdrfv/wB76EA/1CnkLkBvCSRgnQyw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FrY7rlv95Qt4UdYj0FJLMmfl14nBKoOwmGtpbCbqweE=; b=iVM1Z8CT8GyyQpkU6+OdqvV2l0thfO99VHn9r5zK07uzIxOi8tJ6B2pKiIUsIaKmYwXULypPneJY+BLDMx+lJgvpRRCba+f26HnL9eFCgB+7dDYR1ig7IPfQ61VcHm1bsw5UK9Xw38jkAS4hxONtx92NGinhfvfsdRn9xVSZ7skfY3GXEymPxv4f8nAInKMg5XMZP4reEzENr5A0vm53lKKzx87ns6iNwR81VGb30g8LZcIAU+U/dmPZtCtDeH869brhe2ZAZIpG1WDIrZTOMuhX9G3V8llD47Rp4mjSU+YwKjiF3vOeYE7uMKU6t4RSXoOYVb/s+GLMwYTpJxKcpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FrY7rlv95Qt4UdYj0FJLMmfl14nBKoOwmGtpbCbqweE=; b=3YQ0LxVh24fjIbWdPn1TmMYBeOn6ZRYmSylc0LGo0kKzliyTiF4waKv9+1HppCNZTQFvAeT5/eTA9BSySay+PngDYILuGgLOmpPXsX3gd/dphqBq9j9uv3qfXzMLa5d+8J/qt0qplryGPsvBF0tKE8gnJrXj9xLMJLkxsY+jGaM= Received: from DBBPR08MB5547.eurprd08.prod.outlook.com (2603:10a6:10:d2::22) by AM4PR08MB2753.eurprd08.prod.outlook.com (2603:10a6:205:b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.18; Mon, 14 Feb 2022 12:28:04 +0000 Received: from DBBPR08MB5547.eurprd08.prod.outlook.com ([fe80::d550:177a:f0d7:2803]) by DBBPR08MB5547.eurprd08.prod.outlook.com ([fe80::d550:177a:f0d7:2803%6]) with mapi id 15.20.4975.015; Mon, 14 Feb 2022 12:28:04 +0000 From: Andre Kempe To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] arm64: Add Armv8.3-A PAC support to assembly files Thread-Index: AdgUbqhMxCe2UZxtRuupUWwOLwDvlg== Date: Mon, 14 Feb 2022 12:28:04 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: E6A6BAAF91E19743B6C9B6EBC8AEB331.0 x-checkrecipientchecked: true Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-exchange-messagesentrepresentingtype: 1 X-MS-Office365-Filtering-Correlation-Id: e6bded02-3ffc-477a-099b-08d9efb57793 x-ms-traffictypediagnostic: AM4PR08MB2753:EE_|DB5EUR03FT014:EE_|AS8PR08MB7078:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: NRnRvMoHQvNTFhyAh3V1FVTyZJiSt/OtkliqYESCMkaaUOPXVxuiaFFdwU1e/c6k6ZtiRzX6f1jlsDpPN5izV4wy9sqJVor7413fL764wm+wUOpz3ywgRCJlqZuW8l+LmSefsYcw5JEfOXQ7qZR/YzHR7A1Pt/g+jF7xTpH11C3QB2N8kiszbR5NSmqnwBtSYwV5I63gchFoQ9uOO4DwZwzRq3Avhw6T1a2pWOuDTZxIayR2BS1nHNULDHQ4maTtY0zzoN1/1W1kSrBOb5nNVYyBRXSFZK/ISNNKmrh9kWm1fdeRlfuhPup2Ahm6ayZ1IQ4+Iz+EpIilNOTjtZdZTAlYw47QQGK/2DWZ0vTi3uItBqYLySfnnzwOOV8MU+Zmwgv3ZUomE2ebDjTdeorW7AHLBA7TDBOB7kqmonVk2OkMoIpKME4OKx406R8hML6+8178CLX6F5uj5zGsooDVir3IDJLWkRTNMQ1YkUvemmN28X5DjSr2omqeGvztFNwdTq36em7/cALmIqY4a92QkP3zCOY23T3nm+J1g//1jeymMEbxqRSFhmbdbvmZb+d694ZRk+3naPZ9vRrY0t+tEmiYvQgvuQV/XpiIcdY2P04s86LhbVdDHgp7aOe85EZ25JTpL1hsUweNKzeSHp/O05SzXA1qqgix/AyIGiaHAD15C+6s59b+OVhkQq1h0yVAsqhpQGWY80wD9GkB8eaESzhksfVuM9gxKcytnG0uh9D9xkFnVqQiwcbyKJdbordI7JWc+vYDf4GrQb87KXA+Fdc2f/o0/MDWvxGs1Iym9YSgEHVuXLxR2zShoCjHHJ/ZzR1wQpTyvMgbgzR3hms7bQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBBPR08MB5547.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(66946007)(76116006)(86362001)(64756008)(66446008)(66556008)(66476007)(8676002)(52536014)(2906002)(122000001)(84970400001)(38100700002)(8936002)(38070700005)(4326008)(44832011)(5660300002)(186003)(26005)(316002)(55016003)(7696005)(71200400001)(6506007)(508600001)(966005)(9686003)(83380400001)(33656002)(6916009); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2753 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1ed83b84-f21f-4cd3-6ffb-08d9efb572ff X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P/tSgw3A17e4J4kY3WzimUT6yDtiNj6nr2iSM3Oh57LQzbgwktxScIblC/hzsnV+OSa1BQL8Ut8EwaHxrQXQcW4ks9gGnHCO95gHM7GpVmLm/ETgh/exx+BqjZYCx87fUEeSQpa43y0qfJ4yQ5/nnp0lybntMiRdaf3icFR0iFaIcS3yw1n18/BJZ1VXSOiyluECweDEafTTTWOMpRgp1de6PkeiMo3I+ALgkvmTCdGI65W6DxooS6Qc+X3HMseCwq0PmXLgQOVbOMJaL+ztsh1VnJ77AgMNJAKgvOH3Ik3VNDZfnPU7NdZr7r3s/DtuH+l7qbj9kJdCfaLutnynnDWN9wAjixYARkwbbajaecrR65UAPriE53NORijbIwquJ5Qu178HvAJ8zYU+wgm9tIloEfgGAod+0o7nVw7zcFfB/EeptV27LOuWYjq6mBEp1YWYHQDpEdRrJDbI9pg1kiS8/hyLVoLauo9NUMqJ1cMp5pSjF6TpoF1qR3SI3LvalwxjYsMTkApQiSKidrPhMJ4d/M+faweySIDac2gL9FAk3+NyyJdAtp5RtRMcNH0vTzkFP8ml52b1LJ/XhCbxmxv5y5+pHmQ97HZVGjkKP8IKQgs2rX7EAcIb1LCUdwtjgHWcJ3P94kDIlUlR39XZxlYXev3YLG/yvl3RuumbWw0HE6eNzuKl8d4dKZW/bRZetskJ1kLva/cUGjyuwNm/fXK0TTBRAtLudNsMru+NoYgNV5BxeV0vXH5zYKc57tWx1UjP/Wh7hZf6DeEl0VJa4RQ9jIKv3TCqwbRVnux+ffyNFNuSIqlki0oWoD42keu8 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(33656002)(81166007)(47076005)(186003)(107886003)(966005)(26005)(8936002)(55016003)(52536014)(5660300002)(40460700003)(36860700001)(356005)(2906002)(84970400001)(70586007)(70206006)(6916009)(82310400004)(316002)(83380400001)(6506007)(7696005)(9686003)(336012)(8676002)(4326008)(508600001)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2022 12:28:12.3723 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e6bded02-3ffc-477a-099b-08d9efb57793 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: DB5EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7078 Subject: [FFmpeg-devel] [PATCH] arm64: Add Armv8.3-A PAC support to assembly files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "martin@martin.st" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WrugSAN9l/SC This patch adds optional support for Arm Pointer Authentication Codes. PAC support is turned on or off at compile time using additional compiler flags. Unless any of these is enabled explicitly, no additional code will be emitted at all. Signed-off-by: André Kempe --- libavcodec/aarch64/fft_neon.S | 3 +- libavcodec/aarch64/mdct_neon.S | 17 ++++- libavcodec/aarch64/synth_filter_neon.S | 2 + libavutil/aarch64/asm.S | 102 +++++++++++++++++++++++-- 4 files changed, 113 insertions(+), 11 deletions(-) -- 2.25.1 IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. diff --git a/libavcodec/aarch64/fft_neon.S b/libavcodec/aarch64/fft_neon.S index b4020fc8c7..dd5f55eb87 100644 --- a/libavcodec/aarch64/fft_neon.S +++ b/libavcodec/aarch64/fft_neon.S @@ -340,7 +340,7 @@ endfunc .macro def_fft n, n2, n4 function fft\n\()_neon, align=6 - AARCH64_VALID_JUMP_TARGET + AARCH64_SIGN_LINK_REGISTER sub sp, sp, #16 stp x28, x30, [sp] add x28, x0, #\n4*2*8 @@ -351,6 +351,7 @@ function fft\n\()_neon, align=6 bl fft\n4\()_neon sub x0, x28, #\n4*2*8 ldp x28, x30, [sp], #16 + AARCH64_VALIDATE_LINK_REGISTER movrel x4, X(ff_cos_\n) mov x2, #\n4>>1 b fft_pass_neon diff --git a/libavcodec/aarch64/mdct_neon.S b/libavcodec/aarch64/mdct_neon.S index 1fd199c972..6091e72022 100644 --- a/libavcodec/aarch64/mdct_neon.S +++ b/libavcodec/aarch64/mdct_neon.S @@ -25,6 +25,7 @@ function ff_imdct_half_neon, export=1 sub sp, sp, #32 stp x19, x20, [sp] + AARCH64_SIGN_LINK_REGISTER str x30, [sp, #16] mov x12, #1 ldr w14, [x0, #28] // mdct_bits @@ -121,6 +122,7 @@ function ff_imdct_half_neon, export=1 ldp x19, x20, [sp] ldr x30, [sp, #16] + AARCH64_VALIDATE_LINK_REGISTER add sp, sp, #32 ret @@ -129,6 +131,7 @@ endfunc function ff_imdct_calc_neon, export=1 sub sp, sp, #32 stp x19, x20, [sp] + AARCH64_SIGN_LINK_REGISTER str x30, [sp, #16] ldr w3, [x0, #28] // mdct_bits mov x19, #1 @@ -160,8 +163,10 @@ function ff_imdct_calc_neon, export=1 subs x19, x19, #16 b.gt 1b - ldp x19, x20, [sp], #16 - ldr x30, [sp], #16 + ldp x19, x20, [sp] + ldr x30, [sp, #16] + AARCH64_VALIDATE_LINK_REGISTER + add sp, sp, #32 ret endfunc @@ -170,6 +175,7 @@ endfunc function ff_mdct_calc_neon, export=1 sub sp, sp, #32 stp x19, x20, [sp] + AARCH64_SIGN_LINK_REGISTER str x30, [sp, #16] mov x12, #1 @@ -317,7 +323,10 @@ function ff_mdct_calc_neon, export=1 st2 {v4.2s,v5.2s}, [x0] st2 {v6.2s,v7.2s}, [x8] - ldp x19, x20, [sp], #16 - ldr x30, [sp], #16 + ldp x19, x20, [sp] + ldr x30, [sp, #16] + AARCH64_VALIDATE_LINK_REGISTER + add sp, sp, #32 + ret endfunc diff --git a/libavcodec/aarch64/synth_filter_neon.S b/libavcodec/aarch64/synth_filter_neon.S index 8fcd71f252..ba79ba9686 100644 --- a/libavcodec/aarch64/synth_filter_neon.S +++ b/libavcodec/aarch64/synth_filter_neon.S @@ -52,6 +52,7 @@ function ff_synth_filter_float_neon, export=1 stp x5, x1, [sp, #16] and x7, x7, #~63 and w8, w8, #511 + AARCH64_SIGN_LINK_REGISTER stp x7, x30, [sp, #32] str w8, [x2] str s0, [sp, #48] @@ -63,6 +64,7 @@ function ff_synth_filter_float_neon, export=1 ldp x2, x4, [sp] // synct_buf_2, window ldp x13, x9, [sp, #16] // out, synth_buf ldp x0, x30, [sp, #32] // *synth_buf_offset + AARCH64_VALIDATE_LINK_REGISTER ldr s0, [sp, #48] add x3, x2, #16*4 // synct_buf_2 + 16 diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S index bee91d59c3..b817eaab22 100644 --- a/libavutil/aarch64/asm.S +++ b/libavutil/aarch64/asm.S @@ -36,10 +36,79 @@ # define __has_feature(x) 0 #endif -/* Support macros for the Armv8.5-A Branch Target Identification feature which - * requires emitting a .note.gnu.property section with the appropriate - * architecture-dependent feature bits set. - * Read more: "ELF for the Arm® 64-bit Architecture" + +/* Support macros for + * - Armv8.3-A Pointer Authentication and + * - Armv8.5-A Branch Target Identification + * features which require emitting a .note.gnu.property section with the + * appropriate architecture-dependent feature bits set. + * + * |AARCH64_SIGN_LINK_REGISTER| and |AARCH64_VALIDATE_LINK_REGISTER| expand to + * PACIxSP and AUTIxSP, respectively. |AARCH64_SIGN_LINK_REGISTER| should be + * used immediately before saving the LR register (x30) to the stack. + * |AARCH64_VALIDATE_LINK_REGISTER| should be used immediately after restoring + * it. Note |AARCH64_SIGN_LINK_REGISTER|'s modifications to LR must be undone + * with |AARCH64_VALIDATE_LINK_REGISTER| before RET. The SP register must also + * have the same value at the two points. For example: + * + * .global f + * f: + * AARCH64_SIGN_LINK_REGISTER + * stp x29, x30, [sp, #-96]! + * mov x29, sp + * ... + * ldp x29, x30, [sp], #96 + * AARCH64_VALIDATE_LINK_REGISTER + * ret + * + * |AARCH64_VALID_CALL_TARGET| expands to BTI 'c'. Either it, or + * |AARCH64_SIGN_LINK_REGISTER|, must be used at every point that may be an + * indirect call target. In particular, all symbols exported from a file must + * begin with one of these macros. For example, a leaf function that does not + * save LR can instead use |AARCH64_VALID_CALL_TARGET|: + * + * .globl return_zero + * return_zero: + * AARCH64_VALID_CALL_TARGET + * mov x0, #0 + * ret + * + * A non-leaf function which does not immediately save LR may need both macros + * because |AARCH64_SIGN_LINK_REGISTER| appears late. For example, the function + * may jump to an alternate implementation before setting up the stack: + * + * .globl with_early_jump + * with_early_jump: + * AARCH64_VALID_CALL_TARGET + * cmp x0, #128 + * b.lt .Lwith_early_jump_128 + * AARCH64_SIGN_LINK_REGISTER + * stp x29, x30, [sp, #-96]! + * mov x29, sp + * ... + * ldp x29, x30, [sp], #96 + * AARCH64_VALIDATE_LINK_REGISTER + * ret + * + * .Lwith_early_jump_128: + * ... + * ret + * + * These annotations are only required with indirect calls. Private symbols that + * are only the target of direct calls do not require annotations. Also note + * that |AARCH64_VALID_CALL_TARGET| is only valid for indirect calls (BLR), not + * indirect jumps (BR). Indirect jumps in assembly are supported through + * |AARCH64_VALID_JUMP_TARGET|. Landing Pads which shall serve for jumps and + * calls can be created using |AARCH64_VALID_JUMP_CALL_TARGET|. + * + * Although not necessary, it is safe to use these macros in 32-bit ARM + * assembly. This may be used to simplify dual 32-bit and 64-bit files. + * + * References: + * - "ELF for the Arm® 64-bit Architecture" + * https: *github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst + * - "Providing protection for complex software" + * https://developer.arm.com/architectures/learn-the-architecture/providing-protection-for-complex-software */ #if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) # define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has BTI @@ -51,7 +120,28 @@ # define AARCH64_VALID_JUMP_TARGET #endif -#if (GNU_PROPERTY_AARCH64_BTI != 0) +#if defined(__ARM_FEATURE_PAC_DEFAULT) +# if ((__ARM_FEATURE_PAC_DEFAULT & (1 << 0)) != 0) // authentication using key A +# define AARCH64_SIGN_LINK_REGISTER paciasp +# define AARCH64_VALIDATE_LINK_REGISTER autiasp +# elif ((__ARM_FEATURE_PAC_DEFAULT & (1 << 1)) != 0) // authentication using key B +# define AARCH64_SIGN_LINK_REGISTER pacibsp +# define AARCH64_VALIDATE_LINK_REGISTER autibsp +# else +# error Pointer authentication defines no valid key! +# endif +# if ((__ARM_FEATURE_PAC_DEFAULT & (1 << 2)) != 0) +# error Authentication of leaf functions is enabled but not supported in FFmpeg! +# endif +# define GNU_PROPERTY_AARCH64_PAC (1 << 1) +#else +# define GNU_PROPERTY_AARCH64_PAC 0 +# define AARCH64_SIGN_LINK_REGISTER +# define AARCH64_VALIDATE_LINK_REGISTER +#endif + + +#if (GNU_PROPERTY_AARCH64_BTI != 0 || GNU_PROPERTY_AARCH64_PAC != 0) .pushsection .note.gnu.property, "a" .balign 8 .long 4 @@ -60,7 +150,7 @@ .asciz "GNU" .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ .long 4 - .long GNU_PROPERTY_AARCH64_BTI + .long (GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_PAC) .long 0 .popsection #endif