From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43E1E263C7F for ; Thu, 21 May 2026 21:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779400685; cv=none; b=h1UmziurLx3zdi6eOcEwmdAZR9LOWSJ+uJll1XmXWGaTe52/SzyicwL/llOmq3haoqcZjflVL37neBSPUyVCPKt2MAeulifwxQmNCpY6DImQZQ7KwrnuAUoA4Ghf1aOjWwX2k5TJ1DrwHJ/v0c8WjghfZMmam2f4N7zd6zytblw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779400685; c=relaxed/simple; bh=Mxf1jXR/CBm3wwejtWpRffvFdHsdbjefILglGCLKuss=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=phsNu/khjKPiE26/QczWV+5L2Cxt36OctqSK058qH3OkpDRWL4/oujdXUKoDcyFD9D13cCbEHayRYE3/dKLpeF6N9BPtZw3wSYM51oJ7nSbhw+NLivWgnLbsOWJMEkAaF5Zl0n/UdpthT6WFTuhupaYQCJMJXukuj0paPUihtY0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lc8pWsbi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lc8pWsbi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AF0A1F000E9; Thu, 21 May 2026 21:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779400683; bh=8WE6if+wLI2gYZBQrnON+xs9MINnS1FYTnSN4CJZVRE=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=lc8pWsbiUfhFAMONJASMWyilul+V42F7RTYLrdDD52xZdOn+Ye4Mr7pGGZ4xWOQns WVtk21KqlPPKkKSes/IPPFrRn2spoZPOqU4ok3fqJn5Uca8oIB+xWQErjJZOke1hEF fSNrLbJxPw+5TN1G3Z8Z9b0SJyjlMAu053XNHscjX9TzkzeLR3TIvSwKK0UOeZwSXC o0bfN5Ydqfx1MvXcJMotUMfR/7e4CXwiEDZT2UTnWj+PVFsZ8EIxhLcayLxb+Sq8Hn 8S5QvpX2ktyi0iRqrFwZnsPAU18zCNitfHV+l2qZl5NPoCQqljOEJj/MWpYCcAxJq+ 21ZOGVlTHH00A== Date: Thu, 21 May 2026 15:57:59 -0600 (MDT) From: Paul Walmsley To: Marco Elver cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: Implement _THIS_IP_ using inline asm In-Reply-To: <20260521000436.3931067-1-elver@google.com> Message-ID: References: <20260521000436.3931067-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 On Thu, 21 May 2026, 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 Thanks, queued for v7.2. - Paul