Re: objtool warnings for kernel/trace/trace_selftest_dynamic.o

From: Steven Rostedt
Date: Tue Dec 18 2018 - 16:57:19 EST


On Tue, 18 Dec 2018 13:15:01 -0800
Andi Kleen <ak@xxxxxxxxxxxxxxx> wrote:

>
> >
> > I am the developer who introduced attribute noclone to GCC and also the
> > one who advises against using it :-) ...at least without also using the
> > noinline attribute, the combination means "
>
> The function in question uses noinline too.

And that's all I care about.

>
> > I want only one or zero
> > copies of this function in the compiled assembly" which you might need
> > if you do fancy stuff in inline assembly, for example.
>
> For this case we only want one non inlined copy because it is used as a
> test case for a function tracer.

The function tracer selftest should work just fine if there's more than
one copy. Because the test will enable all copies.

>
> LTO comes into play because it originally relied on being in a separate
> file, so it would not be inlined, but with LTO that doesn't work.

The reason for it being in a separate file is because the entire
directory is marked "notrace". That file, and that file alone in that
directory, gets compiled with the -pg flags. As long as the functions
in that file don't get inlined (which will make them notrace as well)
all is good.

Thus, if used and/or noinline prevents the functions from being
inlined, and thus have their profiling removed, we should be good.

Hmm, how does that work? When does LTO do its linker magic? Because the
fentry/mcounts are added when the object is created. Are they removed
if the compiler sees that it can be inlined? Or does LTO just compile
everything in one go?

>
> >
> > I believe that when people use noclone on its own, in 99 out 100 cases
> > they actually want something else. Usually there is something that
>
> AFAIK there is no noclone without noinline in the kernel tree.
>
>
> > references the function from code (such as assembly) or a tool that the
> > compiler does know about and then they should use the "used" attribute.
>
> Neither in the ftrace case, nor in the KVM case (another user which
> has fancy inline assembly that cannot be duplicated) that's the case.
> It's just about having exactly one out of line instance.

Again, that's not the ftrace case. It doesn't care about more than one
out of line instance. Thus, for this particular use, "used" should be
good enough.

-- Steve