All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	 Nicolas Schier <nicolas@fjasle.eu>,
	Nick Desaulniers <ndesaulniers@google.com>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	 Sam Ravnborg <sam@ravnborg.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH 2/2] kbuild: userprogs: use lld to link through clang
Date: Fri, 14 Feb 2025 08:40:22 +0100	[thread overview]
Message-ID: <20250214081034-a5fd06c6-9cb5-4efc-ad2b-69e6acfb08bd@linutronix.de> (raw)
In-Reply-To: <20250213175437.GA2756218@ax162>

On Thu, Feb 13, 2025 at 10:54:37AM -0700, Nathan Chancellor wrote:
> Hi Thomas,
> 
> On Thu, Feb 13, 2025 at 03:55:18PM +0100, Thomas Weißschuh wrote:
> > The userprog infrastructure links objects files through $(CC).
> > Either explicitly by manually calling $(CC) on multiple object files or
> > implicitly by directly compiling a source file to an executable.
> > The documentation at Documentation/kbuild/llvm.rst indicates that ld.lld would
> > be used for linking if LLVM=1 is specified.
> > However clang instead will use either a globally installed cross linker from
> > $PATH called ${target}-ld or fall back to the system linker, which probably
> > does not support crosslinking.
> > For the normal kernel build this is not an issue because the linker is always
> > executed directly, without the compiler being involved.
> > 
> > Fix this by passing -fuse-lld and let clang find its matching lld.
> > 
> > Fixes: 7f3a59db274c ("kbuild: add infrastructure to build userspace programs")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 
> First of all, thank you for catching and noticing this!
> 
> > ---
> >  Makefile | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/Makefile b/Makefile
> > index bb5737ce7f9e79f4023c9c1f578a49a951d1e239..b4c208ae4041c1f4e32c2a158322422ce7353d06 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -510,6 +510,7 @@ OBJCOPY		= $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
> >  OBJDUMP		= $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
> >  READELF		= $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
> >  STRIP		= $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
> > +KBUILD_USERLDFLAGS += -fuse-ld=lld
> 
> Now that our minimum supported version upstream is 13.0.1, I think we
> can make this
> 
>   KBUILD_USERLDFLAGS += --ld-path=$(LD)
> 
> as it should respect the user's choice of linker a little bit more, such
> as if they specific LLVM=<prefix>/bin/ or LLVM=-20. That reminds me that
> I can clean up what I did in commit 4406b12214f6 ("powerpc/vdso: Link
> with ld.lld when requested").

That is much better, thanks!
I looked for something like this but could't find it.

> Additionally, this would not fix someone using CC=clang and LD=ld.lld
> (it is uncommon but still techincally supported) so could we use a check
> like
> 
>   ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy)
>   KBUILD_USERLDFLAGS += --ld-path=$(LD)
>   endif
> 
> further down in Makefile to make it more robust?

Ack.

> The stable backport may want to use cc-option like I did for the powerpc
> vdso since there is a lower minimum supported version of LLVM there.

Ack.


FYI, in case you want to have a look:
The kunit config for powerpc is currently broken on LLVM=1.

$ ./tools/testing/kunit/kunit.py run --arch powerpc --make_options LLVM=1

arch/powerpc/boot/wrapper manually inspects with CROSS_COMPILE, which does not
exist when LLVM=1. Instead it falls back to the system objcopy, etc.

> >  else
> >  CC		= $(CROSS_COMPILE)gcc
> >  LD		= $(CROSS_COMPILE)ld

  reply	other threads:[~2025-02-14  7:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-13 14:55 [PATCH 0/2] kbuild: userprogs: two fixes for LLVM=1 Thomas Weißschuh
2025-02-13 14:55 ` [PATCH 1/2] kbuild: userprogs: fix bitsize and target detection on clang Thomas Weißschuh
2025-02-13 17:55   ` Nathan Chancellor
2025-02-15 18:10   ` Masahiro Yamada
2025-02-13 14:55 ` [PATCH 2/2] kbuild: userprogs: use lld to link through clang Thomas Weißschuh
2025-02-13 17:54   ` Nathan Chancellor
2025-02-14  7:40     ` Thomas Weißschuh [this message]
2025-02-15  4:15       ` Nathan Chancellor

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=20250214081034-a5fd06c6-9cb5-4efc-ad2b-69e6acfb08bd@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=justinstitt@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolas@fjasle.eu \
    --cc=sam@ravnborg.org \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.