linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nicolas Schier <nicolas@fjasle.eu>,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH] kbuild: get lib-y objects back to static library
Date: Sat, 26 Aug 2023 09:06:18 +0900	[thread overview]
Message-ID: <CAK7LNAQZUYjhFeXip3m5NrNOUBZ93pHdL+qrn-M4OeRpC5q9LA@mail.gmail.com> (raw)
In-Reply-To: <CAKwvOdm+oPs1kV+RCa0Y_v95dfUuvYCGAGE-HDASq8ajE56uDg@mail.gmail.com>

On Sat, Aug 26, 2023 at 6:45 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Thu, Aug 24, 2023 at 11:59 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > On Wed, Aug 23, 2023 at 01:20:42PM -0700, Nathan Chancellor wrote:
> > > Hi Masahiro,
> > >
> > > On Wed, Aug 23, 2023 at 09:08:16PM +0900, Masahiro Yamada wrote:
> > > > Revert the following two commits:
> > > >
> > > >  - 7273ad2b08f8 ("kbuild: link lib-y objects to vmlinux forcibly when CONFIG_MODULES=y")
> > > >  - 7f2084fa55e6 ("[kbuild] handle exports in lib-y objects reliably")
> > > >
> > > > Now, lib-y is back to static library again, and the link order is
> > > > consistent w/wo CONFIG_MODULES.
> > > >
> > > > Since commit ddb5cdbafaaa ("kbuild: generate KSYMTAB entries by
> > > > modpost"), .vmlinux.export.c contains references to exported symbols.
> > > > If a symbol in a lib-y object is exported, that object is always linked
> > > > even without any explicit user in vmlinux.
> > > >
> > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > > ---
> > > >
> > > >  Makefile | 5 -----
> > > >  1 file changed, 5 deletions(-)
> > > >
> > > > diff --git a/Makefile b/Makefile
> > > > index 87a9eef3fb4b..71e9c65d9eae 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -1113,12 +1113,7 @@ export ARCH_DRIVERS  := $(drivers-y) $(drivers-m)
> > > >  # Externally visible symbols (used by link-vmlinux.sh)
> > > >
> > > >  KBUILD_VMLINUX_OBJS := ./built-in.a
> > > > -ifdef CONFIG_MODULES
> > > > -KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
> > > > -KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
> > > > -else
> > > >  KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
> > > > -endif
> > > >
> > > >  export KBUILD_VMLINUX_LIBS
> > > >  export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds
> > > > --
> > > > 2.39.2
> > > >
> > >
> > > The build error that prompted 7273ad2b08f8 from [1] appears to return
> > > with this patch, for example:
> > >
> > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig all
> > > ...
> > > ERROR: modpost: "__memcat_p" [drivers/hwtracing/stm/stm_core.ko] undefined!
> > > ...
> > >
> > > [1]: https://github.com/ClangBuiltLinux/linux/issues/515
> >
> > One thing I forgot to note with this is this occurs when targeting arm,
> > arm64, hexagon, i386, powerpc, s390, and x86_64 with various in-tree
> > configurations (I can provide a list if necessary).
>
> shot in the dark here, but does this help? (Nathan indicates it does,
> at least for `ARCH=arm64 virtconfig`)
> ```
> diff --git a/lib/Makefile b/lib/Makefile
> index 1ffae65bb7ee..289ab15f8659 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -33,9 +33,11 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
>          flex_proportions.o ratelimit.o \
>          is_single_threaded.o plist.o decompress.o kobject_uevent.o \
>          earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
> -        nmi_backtrace.o win_minmax.o memcat_p.o \
> +        nmi_backtrace.o win_minmax.o \
>          buildid.o
>
> +obj-y  += memcat_p.o
> +


No. it is not a solution.

We will end up with a whack-a-mole game
because this kind of issue (EXPORT_SYMBOL from lib-y)
happens in general.






>  lib-$(CONFIG_PRINTK) += dump_stack.o
>  lib-$(CONFIG_SMP) += cpumask.o
>
> ```
> Masahiro,
> I don't fully understand "when to use obj-y vs lib-y" in a kernel
> Makefile.  I've read Documentation/kbuild/makefiles.rst and I still
> don't get it.  Is this answered elsewhere in the docs? Can you explain
> it to me?  Do we need to update the docs?


The original intention (that existed before I became the Kbuild maintainer) was:

 obj-y     linked to vmlinux unconditionally

 lib-y  :  the compiled object goes into a static library. Hence,
conditionally linked.
           (If no symbol in lib-y object is referenced, it is not linked at all)





If ARCH supports CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
it is more optimal.


With lib-y, objects are conditionally linked.

With CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
symbols are conditionally linked.





One solution could be to delete lib-y entirely.


-- 
Best Regards
Masahiro Yamada

  reply	other threads:[~2023-08-26  0:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 12:08 [PATCH] kbuild: get lib-y objects back to static library Masahiro Yamada
2023-08-23 20:20 ` Nathan Chancellor
2023-08-24 18:59   ` Nathan Chancellor
2023-08-25 16:58     ` Nick Desaulniers
2023-08-26  0:06       ` Masahiro Yamada [this message]
2023-08-26  0:55         ` Nick Desaulniers
2023-08-24  1:44 ` Masahiro Yamada
2023-08-26  2:37 ` kernel test robot

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=CAK7LNAQZUYjhFeXip3m5NrNOUBZ93pHdL+qrn-M4OeRpC5q9LA@mail.gmail.com \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolas@fjasle.eu \
    /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;
as well as URLs for NNTP newsgroup(s).