Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1426225rdb; Fri, 16 Feb 2024 16:08:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbpBxfNs8EkCOQg4NUliPHYmRFHvT8hK4bDAMSoTBfBtD3j8HkN6fR4gdKIbjkv3uyFXw7vtpIqM0zvCDedm9MQojXBpwW/YdM17+4pg== X-Google-Smtp-Source: AGHT+IEl7p8hwHoR7pcsz5MulUpwSDQ/S7OeajLi5zZirnPBShAskRqWaw4FZe6xC5UamCQiTZTc X-Received: by 2002:a17:906:a298:b0:a3d:8366:e31f with SMTP id i24-20020a170906a29800b00a3d8366e31fmr4054785ejz.42.1708128490464; Fri, 16 Feb 2024 16:08:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708128490; cv=pass; d=google.com; s=arc-20160816; b=AW+3xR14Xg99Dpo5BS1G6UJBQ71C9gkoheahvr74Ub1E4OzSFPNJtcbqDgjE0ulAI4 Tff1TRA0EM1hnwEEOS8ySCdViJ0VygVSaUHm1hSRPJsYRAkibWys70Gp6NRKygpqBxlm cQ+Fbv2HDBZuNAjWx9IPLbxrlde526IeVyzPZQay8huqDB8OLWvhjFNSMPX8VOovgEtm s9O+KgrKhjtRTmyhb79qG5dUBoKueTTtramRPXzHfuzbblbM5PkhT8hL4/bKuconokV2 vtBhTFZ/edtBDoOrBomGPDxzZEOVr1iZU8E6n8sjthnSA5w+owBrJ9lEGEDAnqfhs25f Lf2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=blQIQsBjP6IdeHz0VCJZKaauBQxlPHBJwKxqwVH1O0U=; fh=Fn+7NgkVu6TknzlanDHZ+oHKccaM+xgvEeNomxtU/NU=; b=lcOttKydeH/+6HUJRKpiF5UBBA/MqPWzMd2qaDQa3KET4CwqmCWb7A4y/YZuqULT9b iXxPJjCFoy48bJ95oOrT1k/XhmxvzL+3Qoa6sdRxsr5gGyPlLyaH4SLWeFyNsa7lfGSv zSmUBqYW6xs/TdPcTL004snNWefXeIDjOzLluo818S4ctAQx0/H2U81mz9qcVC4VqH1J QQlRIGPJNrrDQ1iou4XoOCppkPkqbw+igrlBz7/P3BO1ItKQuuCfw3Lc3E4nazjws3Y6 1sTWSxh8t/bMIiBt/JOqTay+Olmo5BTi1gIgHmrbPjKM2Tke336y3Pq1329q6oIhFTzG XXkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R0gLWjb+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69522-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h11-20020a170906110b00b00a3d496b7c2esi377983eja.35.2024.02.16.16.08.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:08:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R0gLWjb+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69522-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69522-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 11BC41F22BF6 for ; Sat, 17 Feb 2024 00:08:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A5883D68; Sat, 17 Feb 2024 00:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R0gLWjb+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 98FE0173; Sat, 17 Feb 2024 00:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708128481; cv=none; b=MhEfG0AQ8gAC+fbcFy8Qqs998WrKUZXIgXULsBob6XtNMzi1sgFL1itURVuz3BIWWWrel5Wheud0JWIs0KYIWblvsdyxyNMQfCfIv0nlWyQQsTHFUly8QD4oEhPhlWQXIOm8ZJrFqkjn9oz4sEhlhJpVMqDzZl8HkfkJ5QlJPZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708128481; c=relaxed/simple; bh=9F5kBkR+QD3RmrjVjEGCYqMELge2iCuTz8j5HrnXFRA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jnb+L3Y4iDYS4I6b1tQ9MtgAM9e0a+MP5n91jqXjPTENGIzHapbhxAu4YJSONl7lKEmm8rqu+F8nQs0d1NOUUbeX6h1WcmD5DRdZJGkNNBJH6lA5qk++mP4NSfhP/TY+Cbl468zYo/6ZRK8qvbR/kCXAvt11J/bIZ7e4r1mSGNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R0gLWjb+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B68AC433C7; Sat, 17 Feb 2024 00:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708128481; bh=9F5kBkR+QD3RmrjVjEGCYqMELge2iCuTz8j5HrnXFRA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=R0gLWjb+FDPxs1UMz1jUt5NMr+iSpu9SkvJC+xuB18X9VFCkWKMdr4aToDfwxk8D7 rrjG4s9uO0be7A/t9cdH+lcxY9E+vgqSccWa87tVU4UN00xA4lszstIsOQ/sapgvgs Vox2FK7TV1EnOyDtv6/GPBhh3kUNQOcPwDmHNVxMlVMZKtm2niuhIXi5mTNJ84VN55 qfDoL9TPl288IO+0ZhadsSZD+wzboDW4Q+JfINR683Uw4XiwKwXAW9HfvIq+RHm5tc //2evRp21wsRu3tgGui20PJfUSXQ0DM8CvIohZHUb5A5kq+YZey+ZvKjpedqqzDEx9 AFPoSo4cIMkDQ== Date: Fri, 16 Feb 2024 17:07:59 -0700 From: Nathan Chancellor To: Petr Pavlu Cc: masahiroy@kernel.org, nicolas@fjasle.eu, mark.rutland@arm.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] kbuild: Use -fmin-function-alignment when available Message-ID: <20240217000759.GA3808452@dev-arch.thelio-3990X> References: <20240215151642.8970-1-petr.pavlu@suse.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: <20240215151642.8970-1-petr.pavlu@suse.com> On Thu, Feb 15, 2024 at 04:16:42PM +0100, Petr Pavlu wrote: > GCC recently added option -fmin-function-alignment, which should appear > in GCC 14. Unlike -falign-functions, this option causes all functions to > be aligned at the specified value, including the cold ones. > > Detect availability of -fmin-function-alignment and use it instead of > -falign-functions when present. Introduce CC_HAS_SANE_FUNCTION_ALIGNMENT > and make the workarounds for the broken function alignment conditional > on this setting. > > Signed-off-by: Petr Pavlu Thanks, this looks good to me from a Kbuild perspective. Reviewed-by: Nathan Chancellor > --- > > Changes since v1 [1]: > - Check the availability of -fmin-function-alignment only in one place. > > [1] https://lore.kernel.org/linux-kbuild/20240212145355.1050-1-petr.pavlu@suse.com/ > > Makefile | 7 +++++++ > arch/Kconfig | 12 ++++++++++++ > include/linux/compiler_types.h | 10 +++++----- > kernel/exit.c | 5 ++++- > 4 files changed, 28 insertions(+), 6 deletions(-) > > diff --git a/Makefile b/Makefile > index 7e0b2ad98905..6f20ab5e2e44 100644 > --- a/Makefile > +++ b/Makefile > @@ -974,8 +974,15 @@ export CC_FLAGS_CFI > endif > > ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) > +# Set the minimal function alignment. Use the newer GCC option > +# -fmin-function-alignment if it is available, or fall back to -falign-funtions. > +# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT. > +ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT > +KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT) > +else > KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) > endif > +endif > > # arch Makefile may override CC so keep this after arch Makefile is included > NOSTDINC_FLAGS += -nostdinc > diff --git a/arch/Kconfig b/arch/Kconfig > index a5af0edd3eb8..bd6c6335efac 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -1507,4 +1507,16 @@ config FUNCTION_ALIGNMENT > default 4 if FUNCTION_ALIGNMENT_4B > default 0 > > +config CC_HAS_MIN_FUNCTION_ALIGNMENT > + # Detect availability of the GCC option -fmin-function-alignment which > + # guarantees minimal alignment for all functions, unlike > + # -falign-functions which the compiler ignores for cold functions. > + def_bool $(cc-option, -fmin-function-alignment=8) > + > +config CC_HAS_SANE_FUNCTION_ALIGNMENT > + # Set if the guaranteed alignment with -fmin-function-alignment is > + # available or extra care is required in the kernel. Clang provides > + # strict alignment always, even with -falign-functions. > + def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG > + > endmenu > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > index 663d8791c871..f0152165e83c 100644 > --- a/include/linux/compiler_types.h > +++ b/include/linux/compiler_types.h > @@ -99,17 +99,17 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } > * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute > * > * When -falign-functions=N is in use, we must avoid the cold attribute as > - * contemporary versions of GCC drop the alignment for cold functions. Worse, > - * GCC can implicitly mark callees of cold functions as cold themselves, so > - * it's not sufficient to add __function_aligned here as that will not ensure > - * that callees are correctly aligned. > + * GCC drops the alignment for cold functions. Worse, GCC can implicitly mark > + * callees of cold functions as cold themselves, so it's not sufficient to add > + * __function_aligned here as that will not ensure that callees are correctly > + * aligned. > * > * See: > * > * https://lore.kernel.org/lkml/Y77%2FqVgvaJidFpYt@FVFF77S0Q05N > * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345#c9 > */ > -#if !defined(CONFIG_CC_IS_GCC) || (CONFIG_FUNCTION_ALIGNMENT == 0) > +#if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || (CONFIG_FUNCTION_ALIGNMENT == 0) > #define __cold __attribute__((__cold__)) > #else > #define __cold > diff --git a/kernel/exit.c b/kernel/exit.c > index dfb963d2f862..5a6fed4ad3df 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -1920,7 +1920,10 @@ EXPORT_SYMBOL(thread_group_exited); > * > * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345#c11 > */ > -__weak __function_aligned void abort(void) > +#ifndef CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT > +__function_aligned > +#endif > +__weak void abort(void) > { > BUG(); > > > base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de > -- > 2.35.3 >