Re: [POC][RFC][PATCH] build: Make weak functions visible in kallsyms

From: Steven Rostedt
Date: Thu Dec 26 2024 - 22:45:33 EST


On Thu, 26 Dec 2024 19:35:18 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Thu, 26 Dec 2024 at 13:49, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > But then, when the linker removes these functions because they were
> > overridden, the code does not disappear, leaving the pointers in the
> > __mcount_loc locations.
>
> Btw, does this actually happen when the compiler does the mcount thing for us?

Yes.

I believe the issue is that the mcount_loc is created during the
compile phase, and it just points to the call to fentry/mcount. The
linker phase doesn't remove the code, just the symbols that are
overridden. That means the pointer to the fentry/mcount calls still
point to the same locations, as the code is still there.

I even sent an email about this to the gcc folks, and Peter responded
basically explaining the above.

https://lore.kernel.org/all/20241014210841.5a4764de@xxxxxxxxxxxxxxxxxx/

-- Steve