All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Sedat Dilek <sedat.dilek@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Clang-Built-Linux ML <clang-built-linux@googlegroups.com>,
	linux-kbuild@vger.kernel.org
Subject: Re: Using GNU AS from a selfmade binutils v2.35.2
Date: Fri, 5 Feb 2021 14:36:51 -0700	[thread overview]
Message-ID: <20210205213651.GA16907@Ryzen-5-4500U.localdomain> (raw)
In-Reply-To: <CA+icZUUjb_71mWwWFMYN_OPZir2vStLq1kDY1O+JCFjtmEEBjA@mail.gmail.com>

On Fri, Feb 05, 2021 at 11:56:55AM +0100, Sedat Dilek wrote:
> Hi Masahiro and ClangBuiltLinux folks,
> 
> I am trying to use binaries from GNU/binutils v2.35.2 for my
> Linux-kernel builds.
> 
> Background is I am doing some testing for BTF + pahole with GCC-10 and LLVM-12.

TL;DR: GCC will use the first "as" that is found in your PATH while
clang will:
1. Use the "as" present in the folder that it is installed in.
2. Use the first "as" that is found in your PATH.

To override clang's behavior, you can pass '--prefix=' to it.

GCC:

$ echo | gcc -### -c -x assembler -o /dev/null -
...
 as --64 -o /dev/null -
...

You can prove that this works with a symlink to /bin/false.

$ cd "$(mktemp -d)"

$ ln -s /bin/false as

$ echo | gcc -c -x assembler -o /dev/null -

$ echo ${?}
0

$ echo | PATH=${PWD}:${PATH} gcc -c -x assembler -o /dev/null -

$ echo ${?}
1

As you will notice, PATH has no affect when there is an "as" binary in
the same location as "clang":

$ which clang
/usr/bin/clang

$ which as
/usr/bin/as

$ echo | clang -### -no-integrated-as -c -x assembler -o /dev/null -
...
 "/usr/bin/as" "--64" "-o" "/dev/null" "-"

$ echo | PATH=${PWD}:${PATH} clang -### -no-integrated-as -c -x assembler -o /dev/null -
...
 "/usr/bin/as" "--64" "-o" "/dev/null" "-"

But '--prefix=' does:

$ echo | clang -### --prefix=${PWD} -no-integrated-as -c -x assembler -o /dev/null -
...
 "/tmp/tmp.B8BdCWZJTL/as" "--64" "-o" "/dev/null" "-"

When there is no "as" binary in the same location as "clang", PATH works:

$ echo | /usr/lib/llvm-10/bin/clang -### -no-integrated-as -c -x assembler -o /dev/null -
...
 "/usr/bin/as" "--64" "-o" "/dev/null" "-"

$ echo | PATH=${PWD}:${PATH} /usr/lib/llvm-10/bin/clang -### -no-integrated-as -c -x assembler -o /dev/null -
...
 "/tmp/tmp.B8BdCWZJTL/as" "--64" "-o" "/dev/null" "-"

If you want to use a separate binutils while building the kernel with
clang, you can:

1. Symlink your LLVM and binutils binaries into one folder.
2. Pass '--prefix=' via KCFLAGS:

make KCFLAGS=--prefix=<binutils_bin_folder>

It is entirely possible that '--prefix=' should always be present though:

diff --git a/Makefile b/Makefile
index f5842126e89d..409822f45bfd 100644
--- a/Makefile
+++ b/Makefile
@@ -562,10 +562,10 @@ endif
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
+endif
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
 GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
 ifneq ($(GCC_TOOLCHAIN),)
 CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif

Hopefully that helps.

Cheers,
Nathan

  reply	other threads:[~2021-02-05 21:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 10:56 Sedat Dilek
2021-02-05 21:36 ` Nathan Chancellor [this message]
2021-02-05 21:44   ` Nick Desaulniers
2021-02-05 21:53     ` Sedat Dilek
2021-02-05 21:55     ` Nathan Chancellor
2021-02-05 22:05       ` Nick Desaulniers
2021-02-06 12:41 ` Sedat Dilek

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=20210205213651.GA16907@Ryzen-5-4500U.localdomain \
    --to=nathan@kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=sedat.dilek@gmail.com \
    --cc=yamada.masahiro@socionext.com \
    --subject='Re: Using GNU AS from a selfmade binutils v2.35.2' \
    /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

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.