Message ID | 20240201223545.728028-1-maskray@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp68211dyc; Thu, 1 Feb 2024 14:37:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHf/DaSNspzSf/cVw3KsJqn1uNUcgqAuuT3ZS310/sELSrLQiKEh5EbESa9Mn9YOLFSYvH X-Received: by 2002:a05:622a:18a1:b0:42a:853e:1a4 with SMTP id v33-20020a05622a18a100b0042a853e01a4mr6694264qtc.36.1706827036312; Thu, 01 Feb 2024 14:37:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706827036; cv=pass; d=google.com; s=arc-20160816; b=yvPukUB0CS7x9S7VZN/dCyfrEDYBDdIKaUonsn14glsyAsO6CSNEejT8S7n+HhWQKE NotPwVPRmxELEeVEwNm6dg71LXnMUkYjxBjq4CxCg3UbFOeZQwvwmWJroghtQKXH+sRR Adynm4/J/Lpv0lxXS43MhmU4L4K1Zpo42uK3+4E37JsGbIiKe8/A+P0NMCGaqRLMwMTI tPD22onvpuUvlTgDaAJgOCW7hibW0LXVrVVd1QpnrlTP3MH8hk4bSsjM06fUTelXPcuG Z+Iro6Zekyu7L6JOzkcl4q1jk7AOrEOg5WxCr44bnfA6j403B4pNAWn/HM3P5cnVL86Y muuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=3B3tF1HYvRY1UkQ2K7cnSqpuGaSyeDgjRqaJd9RSiXg=; fh=nEYMAEcLnboWezMQhAxbZHegQwvukrxjj16o1Kwnlg4=; b=rmw+r2BSSqq6IOLYNmKyLSqcppTqKpgCTdi0rTfjzjQlq37c/5BETQ+CAs6tk2I5mZ V675LDCH4SboC1g+XeuFh8LPMDnaweoaP2dqx7MGzLa7ASCtJUbnMfdx5WcjNJ/Q1BvZ h3Xnkm9Tx8k8YlZQrhkPH4HH997GyVq0wFmZq5kKYRl60oJ+UHSPHNLfP3CbwIzA4Wzh N5VhZ6pcxSNlln503qW7bx/1QPqzfgEKA6q97do8Yb3M4coiH+UqIo9YMy2sntSALEj2 r/WsrLwoptw8Pn1SSROhNngKrqmuFGYVbJxhbtTP13v45R3BUHCGuJ0j5X8lDBRf/8vH PDqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zUrQV2Up; arc=pass (i=1 spf=pass spfdomain=flex--maskray.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUJ5dpIHKsKIvWOP0vT/3jO5hme0gYyhDlbkuxK6oHFSyUUFh+8vqBUKmDRxV2kYZ0NMhCqCm1kWVeDUWt/jiE56D9P6Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bp11-20020a05622a1b8b00b0042bf8f59cc3si534692qtb.378.2024.02.01.14.37.16 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:37:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zUrQV2Up; arc=pass (i=1 spf=pass spfdomain=flex--maskray.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48951-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 214401C22AF6 for <ouuuleilei@gmail.com>; Thu, 1 Feb 2024 22:37:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3122C4122C; Thu, 1 Feb 2024 22:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zUrQV2Up" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDEF23FB1D for <linux-kernel@vger.kernel.org>; Thu, 1 Feb 2024 22:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706827023; cv=none; b=epv29azH9CG58p0d6iCKfE1Ka/qmwQBOgVmFA/3J4Yy4lsxt2C5olrmsrjX+rx8Zrbs+70GWDz/URbkYy5K0/VgboTyRXRzw3kay8vuxESAqKP6G5r0NROR931MsbDH0mbumcXQ6ic5gCmesNMaRYgxUz32UvKeOxITgP1c24Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706827023; c=relaxed/simple; bh=C1Td7LS6mQYWKcz4HPRMpRrQao7T6kT+I564bAgKsBU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=pmZb8wSnC4kazbLHEoRgjgValAzKYAaThQH/qg6tCfwFFqVo7BlPhILOn/+blyGO1oxQiNVciYnDOibD8N/dcYi4+umci/W3FL4Lekh30Yp/rd0kbCBNDCjC+nEuSVSpM4FV+n+sfuojNkMupTCel8ALZsHZ+TJfygL5bSS8zKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zUrQV2Up; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso2114982276.0 for <linux-kernel@vger.kernel.org>; Thu, 01 Feb 2024 14:37:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706827021; x=1707431821; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3B3tF1HYvRY1UkQ2K7cnSqpuGaSyeDgjRqaJd9RSiXg=; b=zUrQV2Upjx8/DfFBOJflmwchTh9DcgyYDnSJXqn3q5/OwLg5BLdy8Ah8HZfKJYtlJS 28Nc+A+2y8rrdqcetumgwLd1QBqm2nzHrV/AHX6rTWyaP93zmLl6z1GqX8oEoChaaEjp tcQmn2OakN+SUmpSU6B6Cn59B3bCyFcssKyH2Sn30EGoFbSBoosWgHezncRzeq71YmnM H3MmsplIjTHtElydFCsQTSc1BvIicbnl1+DdWFDlRFkaMFxrzD4qUHqV68xys0prd3Q6 4wqmRhDfPyC/yYA4H+gBqMA27L1EJryhphVVPS2Il/nZDyeOZFR4r6+khYwKz5Pzet8a XCJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706827021; x=1707431821; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3B3tF1HYvRY1UkQ2K7cnSqpuGaSyeDgjRqaJd9RSiXg=; b=Uk5r86SfktO1MfavuKIp/ZlXLLeKV8HmMjJI27F98bbQs67w/Uj1gmeUVFKvYSMhMu bEXznZtZLo3WvTqXlCFalnxfuYoQLWgRVf+lTFTVXeq9s+mGSb2b1w5jWT+Ae1oMepy2 Ydmc189IJnUWoa8BlKXItM8oU6dT3CKxFbciFEScYIR0QKJCv3pi+D2la+s+kgX0SZEQ RX1YWQJQ+N7P0N6ZoZRAyd7qTdoExN9lvRcvOBk4BMqQaEBVQJTUe10nVPiu7renA5Zp 0HN0Ri6lr4UQLeyMM20D++e+97Ow69xsbgqVN25Aoxeoz+iAaMfa0lQJRCsLQUePsRRt J2zw== X-Gm-Message-State: AOJu0YxSM4u98CZpzX2nkbKOmzsJMBA/sm81uCdsaYdegabSLHbE9uQO TxY+PpMVzqtREgALOfFOqJrlwHD3jVgEFibUb0xtYzDr9YMM5wY1aoZVfSdrg8SmchXn8uYlICt epdHR9Q== X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:7de7:721a:241f:7455]) (user=maskray job=sendgmr) by 2002:a05:6902:cc9:b0:dc2:57c9:b44d with SMTP id cq9-20020a0569020cc900b00dc257c9b44dmr149539ybb.8.1706827021012; Thu, 01 Feb 2024 14:37:01 -0800 (PST) Date: Thu, 1 Feb 2024 14:35:45 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 Message-ID: <20240201223545.728028-1-maskray@google.com> Subject: [PATCH] arm64: jump_label: use constraints "Si" instead of "i" From: Fangrui Song <maskray@google.com> To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, linux-arm-kernel@lists.infradead.org Cc: Jisheng Zhang <jszhang@kernel.org>, Dave Martin <Dave.Martin@arm.com>, Ard Biesheuvel <ardb@kernel.org>, Peter Smith <peter.smith@arm.com>, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Fangrui Song <maskray@google.com> Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789737866416428728 X-GMAIL-MSGID: 1789737866416428728 |
Series |
arm64: jump_label: use constraints "Si" instead of "i"
|
|
Commit Message
Fangrui Song
Feb. 1, 2024, 10:35 p.m. UTC
The generic constraint "i" seems to be copied from x86 or arm (and with
a redundant generic operand modifier "c"). It works with -fno-PIE but
not with -fPIE/-fPIC in GCC's aarch64 port.
The machine constraint "S", which denotes a symbol or label reference
with a constant offset, supports PIC and has been available in GCC since
2012 and in Clang since 7.0. However, Clang before 19 does not support
"S" on a symbol with a constant offset [1] (e.g.
`static_key_false(&nf_hooks_needed[pf][hook])` in
include/linux/netfilter.h), so we use "i" as a fallback.
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Fangrui Song <maskray@google.com>
Link: https://github.com/llvm/llvm-project/pull/80255 [1]
---
Changes from
arm64: jump_label: use constraint "S" instead of "i" (https://lore.kernel.org/all/20240131065322.1126831-1-maskray@google.com/)
* Use "Si" as Ard suggested to support Clang<19
* Make branch a separate operand
---
arch/arm64/include/asm/jump_label.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Comments
On Fri, 2 Feb 2024 at 16:56, Dave Martin <Dave.Martin@arm.com> wrote: > > On Thu, Feb 01, 2024 at 02:35:45PM -0800, Fangrui Song wrote: > > The generic constraint "i" seems to be copied from x86 or arm (and with > > a redundant generic operand modifier "c"). It works with -fno-PIE but > > not with -fPIE/-fPIC in GCC's aarch64 port. > > > > The machine constraint "S", which denotes a symbol or label reference > > with a constant offset, supports PIC and has been available in GCC since > > 2012 and in Clang since 7.0. However, Clang before 19 does not support > > "S" on a symbol with a constant offset [1] (e.g. > > `static_key_false(&nf_hooks_needed[pf][hook])` in > > include/linux/netfilter.h), so we use "i" as a fallback. > > > > Suggested-by: Ard Biesheuvel <ardb@kernel.org> > > Signed-off-by: Fangrui Song <maskray@google.com> > > Link: https://github.com/llvm/llvm-project/pull/80255 [1] > > > > --- > > Changes from > > arm64: jump_label: use constraint "S" instead of "i" (https://lore.kernel.org/all/20240131065322.1126831-1-maskray@google.com/) > > > > * Use "Si" as Ard suggested to support Clang<19 > > * Make branch a separate operand > > --- > > arch/arm64/include/asm/jump_label.h | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h > > index 48ddc0f45d22..1f7d529be608 100644 > > --- a/arch/arm64/include/asm/jump_label.h > > +++ b/arch/arm64/include/asm/jump_label.h > > @@ -15,6 +15,10 @@ > > > > #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE > > > > +/* > > + * Prefer the constraint "S" to support PIC with GCC. Clang before 19 does not > > + * support "S" on a symbol with a constant offset, so we use "i" as a fallback. > > + */ > > static __always_inline bool arch_static_branch(struct static_key * const key, > > const bool branch) > > { > > @@ -23,9 +27,9 @@ static __always_inline bool arch_static_branch(struct static_key * const key, > > " .pushsection __jump_table, \"aw\" \n\t" > > " .align 3 \n\t" > > " .long 1b - ., %l[l_yes] - . \n\t" > > - " .quad %c0 - . \n\t" > > + " .quad %0 + %1 - . \n\t" > > " .popsection \n\t" > > - : : "i"(&((char *)key)[branch]) : : l_yes); > > + : : "Si"(key), "i"(branch) : : l_yes); > > Is the meaning of multi-alternatives well defined if different arguments > specify different numbers of alternatives? The GCC documentation says: > > https://gcc.gnu.org/onlinedocs/gcc/Multi-Alternative.html: > > -8<- > > [...] All operands for a single instruction must have the same number of > alternatives. > > ->8- > AIUI that does not apply here. That reasons about multiple arguments having more than one constraint, where not all combinations of those constraints are supported by the instruction. > Also, I still think it may be redundant to move the addition inside the > asm, so long as Clang is happy with the symbol having an offset. > Older Clang is not happy with the symbol having an offset. And given that the key pointer and the 'branch' boolean are two distinct inputs to this function, I struggle to understand why you feel it is better to combine them in the argument. 'branch' is used to decide whether or not to set bit 0, independently of the value of key. Using array indexing to combine those values together to avoid an addition in the asm obfuscates the code. > I.e., leave the .quad the same and revert to the one-liner > > - : : "i"(&((char *)key)[branch]) : : l_yes); > + : : "Si"(&((char *)key)[branch]) : : l_yes); > > This remains a bit nasty, but splitting the arguments and adding them > inside the asm is not really any cleaner. Changing the way this works > doesn't seem relevant to what this patch is fixing (and apologies if I > created confusion here...) > > > > > return false; > > l_yes: > > @@ -40,9 +44,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke > > " .pushsection __jump_table, \"aw\" \n\t" > > " .align 3 \n\t" > > " .long 1b - ., %l[l_yes] - . \n\t" > > - " .quad %c0 - . \n\t" > > + " .quad %0 + %1 - . \n\t" > > " .popsection \n\t" > > - : : "i"(&((char *)key)[branch]) : : l_yes); > > + : : "Si"(key), "i"(branch) : : l_yes); > > Ditto. > > [...] > > Cheers > ---Dave
On Fri, 2 Feb 2024 at 23:51, Fangrui Song <maskray@google.com> wrote: > > On 2024-02-02, Dave Martin wrote: > >On Fri, Feb 02, 2024 at 05:32:33PM +0100, Ard Biesheuvel wrote: > >> On Fri, 2 Feb 2024 at 16:56, Dave Martin <Dave.Martin@arm.com> wrote: > >> > > >> > On Thu, Feb 01, 2024 at 02:35:45PM -0800, Fangrui Song wrote: > >> > > The generic constraint "i" seems to be copied from x86 or arm (and with > >> > > a redundant generic operand modifier "c"). It works with -fno-PIE but > >> > > not with -fPIE/-fPIC in GCC's aarch64 port. > >> > > > >> > > The machine constraint "S", which denotes a symbol or label reference > >> > > with a constant offset, supports PIC and has been available in GCC since > >> > > 2012 and in Clang since 7.0. However, Clang before 19 does not support > >> > > "S" on a symbol with a constant offset [1] (e.g. > >> > > `static_key_false(&nf_hooks_needed[pf][hook])` in > >> > > include/linux/netfilter.h), so we use "i" as a fallback. > >> > > > >> > > Suggested-by: Ard Biesheuvel <ardb@kernel.org> > >> > > Signed-off-by: Fangrui Song <maskray@google.com> > >> > > Link: https://github.com/llvm/llvm-project/pull/80255 [1] > >> > > > >> > > --- > >> > > Changes from > >> > > arm64: jump_label: use constraint "S" instead of "i" (https://lore.kernel.org/all/20240131065322.1126831-1-maskray@google.com/) > >> > > > >> > > * Use "Si" as Ard suggested to support Clang<19 > >> > > * Make branch a separate operand > >> > > --- > >> > > arch/arm64/include/asm/jump_label.h | 12 ++++++++---- > >> > > 1 file changed, 8 insertions(+), 4 deletions(-) > >> > > > >> > > diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h > >> > > index 48ddc0f45d22..1f7d529be608 100644 > >> > > --- a/arch/arm64/include/asm/jump_label.h > >> > > +++ b/arch/arm64/include/asm/jump_label.h > >> > > @@ -15,6 +15,10 @@ > >> > > > >> > > #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE > >> > > > >> > > +/* > >> > > + * Prefer the constraint "S" to support PIC with GCC. Clang before 19 does not > >> > > + * support "S" on a symbol with a constant offset, so we use "i" as a fallback. > >> > > + */ > >> > > static __always_inline bool arch_static_branch(struct static_key * const key, > >> > > const bool branch) > >> > > { > >> > > @@ -23,9 +27,9 @@ static __always_inline bool arch_static_branch(struct static_key * const key, > >> > > " .pushsection __jump_table, \"aw\" \n\t" > >> > > " .align 3 \n\t" > >> > > " .long 1b - ., %l[l_yes] - . \n\t" > >> > > - " .quad %c0 - . \n\t" > >> > > + " .quad %0 + %1 - . \n\t" > >> > > " .popsection \n\t" > >> > > - : : "i"(&((char *)key)[branch]) : : l_yes); > >> > > + : : "Si"(key), "i"(branch) : : l_yes); > >> > > >> > Is the meaning of multi-alternatives well defined if different arguments > >> > specify different numbers of alternatives? The GCC documentation says: > >> > > >> > https://gcc.gnu.org/onlinedocs/gcc/Multi-Alternative.html: > >> > > >> > -8<- > >> > > >> > [...] All operands for a single instruction must have the same number of > >> > alternatives. > >> > > >> > ->8- > >> > > >> > >> AIUI that does not apply here. That reasons about multiple arguments > >> having more than one constraint, where not all combinations of those > >> constraints are supported by the instruction. > > > >Ah, scratch that: I'm confusing multi-alternatives with simple > >constraints: all arguments must have the same number of comma-separated > >lists of constraint letters, but each list can contain as many or as few > >letters as are needed to match the operand. > > > >So "Si"(), "i"() is fine. > > "Si" is fine for GCC and Clang. > "i" is fine for Clang but not for GCC PIC. > > https://maskray.me/blog/2024-01-30-raw-symbol-names-in-inline-assembly#aarch64 > > In gcc/config/aarch64, LEGITIMATE_PIC_OPERAND_P(X) disallows any symbol > reference, which means that "i" and "s" cannot be used for PIC. Instead, > the constraint "S" has been supported since the initial port (2012) to > reference a symbol or label. > > I am also not familiar with > https://gcc.gnu.org/onlinedocs/gcc/Multi-Alternative.html (comma in a > constraint string). Thankfully we don't need this powerful construct:) > > >> > Also, I still think it may be redundant to move the addition inside the > >> > asm, so long as Clang is happy with the symbol having an offset. > >> > > >> > >> Older Clang is not happy with the symbol having an offset. > >> > >> And given that the key pointer and the 'branch' boolean are two > >> distinct inputs to this function, I struggle to understand why you > >> feel it is better to combine them in the argument. 'branch' is used to > >> decide whether or not to set bit 0, independently of the value of key. > >> Using array indexing to combine those values together to avoid an > >> addition in the asm obfuscates the code. > > > >This was more about not making changes that don't need to be made, > >unless it clearly makes the code better. > > > >But if some verions of Clang accept "S" but choke if there's an offset, > >then moving the addition into the asm seems the way to go. > > > >(I may have misread the commit message on this point.) > > > >[...] > > > >Cheers > >---Dave > > I am convinced by Ard' argument that two inputs (key, branch) deserve > two operands. > The existing "i"(&((char *)key)[branch]) is kinda ugly and also longer:) If it helps clarify things, we might do something like ".quad (%[key] - .) + %[bit0]" : : [key]"Si"(key), [bit0]"i"(branch) : : l_yes);
diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h index 48ddc0f45d22..1f7d529be608 100644 --- a/arch/arm64/include/asm/jump_label.h +++ b/arch/arm64/include/asm/jump_label.h @@ -15,6 +15,10 @@ #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE +/* + * Prefer the constraint "S" to support PIC with GCC. Clang before 19 does not + * support "S" on a symbol with a constant offset, so we use "i" as a fallback. + */ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) { @@ -23,9 +27,9 @@ static __always_inline bool arch_static_branch(struct static_key * const key, " .pushsection __jump_table, \"aw\" \n\t" " .align 3 \n\t" " .long 1b - ., %l[l_yes] - . \n\t" - " .quad %c0 - . \n\t" + " .quad %0 + %1 - . \n\t" " .popsection \n\t" - : : "i"(&((char *)key)[branch]) : : l_yes); + : : "Si"(key), "i"(branch) : : l_yes); return false; l_yes: @@ -40,9 +44,9 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke " .pushsection __jump_table, \"aw\" \n\t" " .align 3 \n\t" " .long 1b - ., %l[l_yes] - . \n\t" - " .quad %c0 - . \n\t" + " .quad %0 + %1 - . \n\t" " .popsection \n\t" - : : "i"(&((char *)key)[branch]) : : l_yes); + : : "Si"(key), "i"(branch) : : l_yes); return false; l_yes: