Re: Using GNU AS from a selfmade binutils v2.35.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux