Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Arnd Bergmann <arnd@arndb.de>, Arnd Bergmann <arnd@kernel.org>,
	Kees Cook <kees@kernel.org>, Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Alexei Starovoitov <ast@kernel.org>,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization
Date: Wed, 2 Dec 2026 15:18:17 -0700	[thread overview]
Message-ID: <20261202221817.GC2468262@ax162> (raw)
In-Reply-To: <20261201171753.575cd2ee@gandalf.local.home>

On Tue, Dec 01, 2026 at 05:17:53PM -0500, Steven Rostedt wrote:
> My question is, if this wasn't an inline to begin with and was just a
> static function in that file, would it still warn?

Yes, I believe so, at least with the example that you provide.

> What exactly did the kernel do wrong?

I would not say the kernel did anything wrong here but I would not say
the compiler did either. I think this is merely a case where the kernel
has assigned some additional meaning to these sections (".init.* is only
available once then discarded") that the compiler is unaware of (so it
cannot alter its behavior because this transformation is normally safe)
and the kernel's post processing does/can not do CFG analysis to see
that bootup_event_seq is only referred to in an init function.

> If we had:
> 
> static void seq_buf_set_overflow(struct seq_buf *s)

I assume this should be seq_buf_terminate()?

> {
> 	if (s->len < s->size)
> 		memset(s->buffer + s->len, 0, s->size - s->len);
> 
> 	s->len = s->size + 1;
> }
> 
> static struct seq_buf bootup_event_seq __initdata = {
> 	.buffer = bootup_event_buf,
> 	.size = sizeof(bootup_event_buf),
> };
> 
> static __init int event_trace_enable(void)
> {
> [..]
> 	seq_buf_terminate(&bootup_event_seq);
> [..]
> }
> 
> Is that a legitimate section mismatch?

No, definitely not.

> I'm OK if we take this patch to convert to always_inline, but I do not see
> it as a kernel fix but simply a workaround to the section matching issue,
> as it appears to be as side effect of optimizations and nothing more.

Sure, I don't see this any different from inlining certain functions for
noinstr and such. Sometimes you need to be explicit for the compiler to
behave as expected and it is not really anyone's fault.

-- 
Cheers,
Nathan

      reply	other threads:[~2026-12-02 22:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:06 [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization Arnd Bergmann
2026-12-01 15:13 ` Steven Rostedt
2026-12-01 21:53   ` Arnd Bergmann
2026-12-01 22:05     ` Nick Desaulniers
2026-12-01 22:17       ` Steven Rostedt
2026-12-02 22:18         ` Nathan Chancellor [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=20261202221817.GC2468262@ax162 \
    --to=nathan@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=ast@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=ndesaulniers@google.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    /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