Re: [PATCH] seq_buf: avoid clang section mismatch from seq_buf_terminate optimization

From: Steven Rostedt

Date: Tue Dec 01 2026 - 17:18:03 EST


On Tue, 1 Dec 2026 14:05:00 -0800
Nick Desaulniers <ndesaulniers@xxxxxxxxxx> wrote:

> On Tue, Dec 1, 2026 at 1:54 PM Arnd Bergmann <arnd@xxxxxxxx> wrote:
> >
> > On Tue, Dec 1, 2026, at 16:13, Steven Rostedt wrote:
> > > On Tue, 1 Dec 2026 10:06:16 +0100 Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
> > >>
> > >> I'm unsure whether this should be considered a bug in clang or the
> > >> kernel, or what the best workaround is. The two options I considered
> > >> are:
> > >
> > > It's definitely a bug in clang. If it created a specialized version of a
>
> I saw this thread earlier and rolled my eyes. This wasn't a compiler
> bug back during the countless other modpost warnings we've fixed in
> kernel sources. It's still not.
>
> commit 2780860eddec ("include/linux/list.h: mark list_add and
> __list_add as __always_inline")
>
> commit f9d2ee3f51d6 ("riscv: Always inline bitops")
>
> commit d5fd042bf4cf ("x86/resctrl: Annotate get_mem_config() functions
> as __init")
>
> commit 1ec2362084a0 ("ARM: imx: Annotate imx7d_enet_init() as __init")

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?

What exactly did the kernel do wrong?

If we had:

static void seq_buf_set_overflow(struct seq_buf *s)
{
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?

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.

-- Steve

>
> > > function and that version is now causing section mismatches, that's a bug
> > > in the compiler. The kernel did nothing wrong.
> >
> > Not sure I understand, do you mean clang should skip the FunctionSpecialization
> > in interprocedural constant propagation altogether when building the kernel,
> > or do you think we should teach clang about the kernel's concept of what
> > functions are allowed to reference .initdata?
> >
> > Is the clang behavior fundamentally different from gcc here? It seems to
> > me that gcc just didn't hit this issue because unlike clang it does
> > inline across sections.
>
> Asserting "clang does not inline across sections" is a _false_
> assertion: https://godbolt.org/z/7TTnxo9Wb (i.e. observe baz jmp'ing
> to bar because foo was inlined, despite being in .woof rather than
> .text).