Re: [PATCH 1/1] scripts: kstack_erase: use relative stackleak plugin path

Nathan Chancellor <[email protected]>
Newsgroups gmane.linux.kbuild.devel,gmane.linux.kernel
Message-ID <20260803181217.GB1067866@ax162>
On Fri, Jul 24, 2026 at 10:18:57PM +0200, Nicolas Schier wrote:
> On Wed, Jul 22, 2026 at 07:00:43PM +0000, Jaihind Yadav wrote:
> > 
> > Hi Nicolas Schier,
> > 
> > Thanks for the suggestion. I tested the proposed change:
> > 
> > -kstack-erase-cflags-y += -fplugin=$(objtree)/scripts/gcc-plugins/stackleak_plugin.so
> > +kstack-erase-cflags-y += -fplugin=scripts/gcc-plugins/stackleak_plugin.so
> > 
> > 
> > Unfortunately, it does not work for the out-of-tree module builds in
> > my environment.
> 
> Thanks for checking; and yes I forgot out-of-tree modules.  When
> building them, Kbuild changes to their respective output directory so my
> suggestion had to fail for oot kmods.

Technically, this is only a problem for out of tree kernel modules,
right? When building in-tree kernel modules, objtree is always '.', so
we will never have the output directory path in the debug information
(at least based on my brief testing).

> > Given that the proposed relative path breaks out-of-tree module
> > builds, could you please take a look at the patch I posted? If the
> > approach looks reasonable, I would appreciate your review and
> > consideration for merging it.
> 
> I am not sure, if we can take your path, as 'readlink --relative-to' is
> only available in coreutils/Linux but coreutils are not a documented
> requirement for Linux builds (cp. Documentation/process/changes.rst),
> thus this would probably kill Linux builds on BSDs and Darwin/MacOS.
> 
> But let me think about that a few days;  and perhaps someone else comes
> up with an idea.

Yeah, I don't really like 'realpath --relative-to' either, it feels a
bit like a hack since it will only avoid including a full path if the
module output directory includes part of the build directory. For
example:

  O=/mnt/build/kernel
  MO=/mnt/build/extmod

$ realpath -m --relative-to /mnt/build/extmod /mnt/build/kernel
../kernel

vs.

  O=/home/nathan/build/kernel
  MO=/mnt/build/extmod

$ realpath -m --relative-to /mnt/build/extmod /home/nathan/build/kernel
../../../home/nathan/build/kernel

Furthermore, this patch only fixes KSTACK_ERASE but we have other GCC
plugins that presumably have the same problem.

I do not have a good solution for this either but since it only affects
external kernel modules, I am not particularly inclined to think too
hard about it.

-- 
Cheers,
Nathan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.