From: Petr Pavlu <petr.pavlu@suse.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: masahiroy@kernel.org, nicolas@fjasle.eu, mark.rutland@arm.com,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kbuild: Use -fmin-function-alignment when available
Date: Tue, 13 Feb 2024 15:04:03 +0100 [thread overview]
Message-ID: <23fcc355-c649-430a-b613-e62d71f681c3@suse.com> (raw)
In-Reply-To: <20240213002746.GB3272429@dev-arch.thelio-3990X>
On 2/13/24 01:27, Nathan Chancellor wrote:
> Hi Petr,
>
> On Mon, Feb 12, 2024 at 03:53:55PM +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 <petr.pavlu@suse.com>
>> ---
>> Makefile | 7 ++++++-
>> arch/Kconfig | 8 ++++++++
>> include/linux/compiler_types.h | 10 +++++-----
>> kernel/exit.c | 5 ++++-
>> 4 files changed, 23 insertions(+), 7 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 7e0b2ad98905..9516e43f6e45 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -974,7 +974,12 @@ export CC_FLAGS_CFI
>> endif
>>
>> ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)
>> -KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
>> +# Set the minimal function alignment. Try to use the newer GCC option
>> +# -fmin-function-alignment, or fall back to -falign-funtions. See also
>> +# CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT.
>> +KBUILD_CFLAGS += $(call cc-option, \
>> + -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT), \
>> + -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT))
>> endif
>>
>> # arch Makefile may override CC so keep this after arch Makefile is included
>> diff --git a/arch/Kconfig b/arch/Kconfig
>> index a5af0edd3eb8..e2448f927fae 100644
>> --- a/arch/Kconfig
>> +++ b/arch/Kconfig
>> @@ -1507,4 +1507,12 @@ config FUNCTION_ALIGNMENT
>> default 4 if FUNCTION_ALIGNMENT_4B
>> default 0
>>
>> +config CC_HAS_SANE_FUNCTION_ALIGNMENT
>> + # Detect availability of the GCC option -fmin-function-alignment which
>> + # guarantees minimal alignment for all functions. GCC 13 and older have
>> + # only -falign-functions which the compiler ignores for cold functions
>> + # and this hence requires extra care in the kernel. Clang provides
>> + # strict alignment always when using -falign-functions.
>> + def_bool $(cc-option, -fmin-function-alignment=8) || CC_IS_CLANG
>> +
>
> I think this configuration should be split into something like
> CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT that has the cc-option check then
> CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT can depend on that configuration
> or Clang as you have it here, so that we can drop the cc-option check in
> the main Makefile and have it be:
>
> ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT
> KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
> else
> KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
> endif
>
> It is wasteful to call cc-option twice in my opinion, especially if we
> are checking it in Kconfig.
Makes sense, thanks.
-- Petr
prev parent reply other threads:[~2024-02-13 14:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 14:53 [PATCH] kbuild: Use -fmin-function-alignment when available Petr Pavlu
2024-02-13 0:27 ` Nathan Chancellor
2024-02-13 14:04 ` Petr Pavlu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23fcc355-c649-430a-b613-e62d71f681c3@suse.com \
--to=petr.pavlu@suse.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).