Re: [PATCH] kbuild: rust: add AutoFDO support

From: Gary Guo

Date: Thu Mar 19 2026 - 15:09:38 EST


On Thu Mar 19, 2026 at 4:33 PM GMT, Alice Ryhl wrote:
> On Thu, Mar 19, 2026 at 12:47 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>>
>> On Thu Mar 19, 2026 at 11:44 AM GMT, Alice Ryhl wrote:
>> > On Thu, Mar 19, 2026 at 12:31 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>> >>
>> >> On Thu Mar 19, 2026 at 11:22 AM GMT, Alice Ryhl wrote:
>> >> > This patch enables AutoFDO build support for Rust code within the Linux
>> >> > kernel. This allows Rust code to be profiled and optimized based on the
>> >> > profile.
>> >> >
>> >> > This was verified by inspecting the object files and confirming that
>> >> > they look correct. It was also verified in conjuction with my helpers
>> >> > inlining series, and it also appears to have worked correctly when
>> >> > combined with that series once one missing thing [1] was fixed in the
>> >> > helpers inlining series.
>> >> >
>> >> > Link: https://lore.kernel.org/all/aasPsbMEsX6iGUl8@xxxxxxxxxx/ [1]
>> >> > Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
>> >> > ---
>> >> > scripts/Makefile.autofdo | 6 +++++-
>> >> > scripts/Makefile.lib | 3 +++
>> >> > 2 files changed, 8 insertions(+), 1 deletion(-)
>> >> >
>> >> > diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo
>> >> > index 1caf2457e585..3f08acab4549 100644
>> >> > --- a/scripts/Makefile.autofdo
>> >> > +++ b/scripts/Makefile.autofdo
>> >> > @@ -3,14 +3,18 @@
>> >> > # Enable available and selected Clang AutoFDO features.
>> >> >
>> >> > CFLAGS_AUTOFDO_CLANG := -fdebug-info-for-profiling -mllvm -enable-fs-discriminator=true -mllvm -improved-fs-discriminator=true
>> >> > +RUSTFLAGS_AUTOFDO_CLANG := -Zdebug-info-for-profiling -Cllvm-args=-enable-fs-discriminator=true -Cllvm-args=-improved-fs-discriminator=true
>> >>
>> >> I get that it's currently named as AUTOFDO_CLANG, but this really ought to be
>> >> AUTOFDO_LLVM...
>> >>
>> >> The flag translations look correct to me.
>> >
>> > Do you think it's worth having Rust not match the CFLAGS here?
>> >
>>
>> I think the C flags should probably be renamed AUTOFDO_LLVM too. After call, all
>> the perf tools involved here are called llvm-foobar as well.
>
> But isn't it just called this because the config option is
> CONFIG_AUTOFDO_CLANG? So it's the CFLAGS or RUSTFLAGS related to that
> particular config option. It may make sense to rename
> CONFIG_AUTOFDO_CLANG to CONFIG_AUTOFDO, but that's out-of-scope for
> this change, in my opinion.

I get that it's an existing config name, but previously it is a correct
description, while after this change it is no longer accurate.

I don't know if there's an established practice on renaming CONFIG options when
this sort thing happens though. Perhaps one way is to have add
CONFIG_AUTOFDO_CLANG that selects CONFIG_AUTOFDO.

Best,
Gary