From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [104.156.224.86]) (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 4563F3D25D2 for ; Thu, 21 May 2026 13:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.156.224.86 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779369050; cv=none; b=DGKZNHSgPfU0D8rUMJzEc9Kxw94rCQ2MZhlY7s51eUv5MRRl1trzfxsGoQ6B5dC1cB7XGfs+bu2RC1IsIcTJkHpkIOdSHYYzAGpzfzw564EjHyFJVE139A/UHFcD+mTRA8cqTS11G1cDpGcFzP737bGt8/beMy07LsydmV9W6vU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779369050; c=relaxed/simple; bh=cAgWOltKleMCB5V/a2eK/27ZhEOliJOKDJGXOcZYd2k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=haRuLb9MFrIPwzrRwUIokQbgqLn+/IkNKqG1l78984nm0uPMSgjit+Pjp+J2I9tOhJNv9Vsy5TByFQ0K7kJM1k60k5Bw8j3hyv9/vglCQhBlAs+l1h5YP3WyfvTPO5K3JJhmc0bPg8eUfiDvREahTWwuwSdqmJLp4xIvur1Wo5o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=libc.org; spf=pass smtp.mailfrom=aerifal.cx; arc=none smtp.client-ip=104.156.224.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=libc.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aerifal.cx Date: Thu, 21 May 2026 08:55:37 -0400 From: Rich Felker To: Marco Elver Cc: Yoshinori Sato , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: Re: [PATCH] sh: Implement _THIS_IP_ using inline asm Message-ID: <20260521125537.GA25906@brightrain.aerifal.cx> References: <20260521123205.146268-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260521123205.146268-1-elver@google.com> User-Agent: Mutt/1.9.5 (2018-04-13) On Thu, May 21, 2026 at 02:31:58PM +0200, Marco Elver wrote: > Both GCC [1] and Clang [2] consider the generic version of _THIS_IP_ to > be broken: > > #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) > > In particular, the address of a label is only expected to be used with a > computed goto. > > While the generic version more or less works today, it is known to be > brittle and may break with current and future optimizations. For > example, Clang -O2 always returns 1 when this function is inlined: > > static inline unsigned long get_ip(void) > { return ({ __label__ __here; __here: (unsigned long)&&__here; }); } > > Fix it by overriding _THIS_IP_ in (which is included by > ) using an architecture-specific inline asm > version. Additionally, avoiding taking the address of a label prevents > compilers from emitting spurious indirect branch targets (e.g. ENDBR or > BTI) under control-flow integrity schemes. > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071 [1] > Link: https://github.com/llvm/llvm-project/issues/138272 [2] > Signed-off-by: Marco Elver > --- > arch/sh/include/asm/linkage.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/sh/include/asm/linkage.h b/arch/sh/include/asm/linkage.h > index 7c2fa27a43f8..af56b38b6001 100644 > --- a/arch/sh/include/asm/linkage.h > +++ b/arch/sh/include/asm/linkage.h > @@ -5,4 +5,6 @@ > #define __ALIGN .balign 4 > #define __ALIGN_STR ".balign 4" > > +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("mova 1f, %0\n1:" : "=z" (__ip)); __ip; }) > + > #endif > -- > 2.54.0.746.g67dd491aae-goog Does this need an alignment directive before the label? mova can only emit 32-bit-aligned addresses, and I think the assembler will complain (since you'll be getting the wrong result) if the address isn't aligned. Rich