Skip to contentSkip to conversation

init/Kconfig: add config support for detecting linker

PATCH In review [email protected] 6 participants 19 messages Feb 7, 2019 – Feb 11, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 init/Kconfig: add config support for detecting linker

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

Cc Nathan Chancellor <[email protected]>
Cc Sami Tolvanen <[email protected]>
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
init/Kconfig +9 -0
index c9386a365eea..b6046dcf7794 100644
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
 	def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
 	bool
 	depends on !UML
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#1 lore raw

PATCH 2/4 Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD

This causes an issue when trying to build with make LD=ld.lld if ld.lld and the rest of your cross tools aren't in the same directory (ex. /usr/local/bin) (as is the case for Android's build system), as the GCC_TOOLCHAIN_DIR then gets set based on which $(LD) which will point where LLVM tools are, not GCC/binutils tools are located.

Instead, select the GCC_TOOLCHAIN_DIR based on another tool provided by binutils for which LLVM does not provide a substitute for, such as elfedit.

Fixes commit 785f11aa595b ("kbuild: Add better clang cross build support")

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 3142e67d03f1..0eae4277206e 100644
@@ -492,7 +492,7 @@ endif
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	:= --target=$(notdir $(CROSS_COMPILE:%-=%))
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Reviewed-by Tested-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD

Quoted 10 lines · On Thu, Feb 07, 2019 at 02:01:50PM -0800, [email protected] wrote:

This causes an issue when trying to build with make LD=ld.lld if ld.lld and the rest of your cross tools aren't in the same directory (ex. /usr/local/bin) (as is the case for Android's build system), as the GCC_TOOLCHAIN_DIR then gets set based on which $(LD) which will point where LLVM tools are, not GCC/binutils tools are located.

Instead, select the GCC_TOOLCHAIN_DIR based on another tool provided by binutils for which LLVM does not provide a substitute for, such as elfedit.

Quoted 5 lines

Fixes commit 785f11aa595b ("kbuild: Add better clang cross build support")

Quoted 20 lines
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 3142e67d03f1..0eae4277206e 100644
@@ -492,7 +492,7 @@ endif
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	:= --target=$(notdir $(CROSS_COMPILE:%-=%))
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#3 lore raw

PATCH 3/4 Makefile: lld: tell clang to use lld

In reply to [email protected]

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS	+= -no-integrated-as
 KBUILD_CFLAGS	+= $(CLANG_FLAGS)
 KBUILD_AFLAGS	+= $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS	+= -fuse-ld=lld
+endif
 export CLANG_FLAGS
 endif
 
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Reviewed-by Tested-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

Quoted 17 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +0 -0
index 0eae4277206e..6307c17259ea 100644

Makefile endif · line 507

Quoted 6 lines
Makefile +3 -0
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS	+= -no-integrated-as
 KBUILD_CFLAGS	+= $(CLANG_FLAGS)
 KBUILD_AFLAGS	+= $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS	+= -fuse-ld=lld
+endif

This section needs to be moved up above KBUILD_CFLAGS otherwise it never actually gets passed along.

With that change, please add:

Quoted 6 lines
Makefile +0 -0
 export CLANG_FLAGS
 endif
 
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
#5 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

Quoted 14 lines · Nathan Chancellor
Quoted 12 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 10 lines

Makefile endif · line 506

Quoted 10 lines
Makefile +2 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld

Sorry, Sedat reports [0] that this is not quite correct; if $(LD) matches LLD, then we need to set -fuse-ld=$(LD), not -fuse-ld=lld, since you may have lld installed as lld-7 or lld-8, for example:
https://github.com/ClangBuiltLinux/linux/issues/358

Quoted 16 lines

Makefile endif · line 507

Quoted 1 line
Makefile +1 -0
+endif

This section needs to be moved up above KBUILD_CFLAGS otherwise it never actually gets passed along.

With that change, please add:

Quoted 6 lines
Makefile +0 -1
 export CLANG_FLAGS
 endif
 
--

2.20.1.791.gb4d0f1c61a-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#6 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

Quoted 16 lines · Nick Desaulniers
Quoted 14 lines · Nathan Chancellor
Quoted 12 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 16 lines
Quoted 10 lines

Makefile endif · line 506

Quoted 10 lines
Makefile +2 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld

Sorry, Sedat reports [0] that this is not quite correct; if $(LD) matches LLD, then we need to set -fuse-ld=$(LD), not -fuse-ld=lld, since you may have lld installed as lld-7 or lld-8, for example:
https://github.com/ClangBuiltLinux/linux/issues/358

We'll need to make sure that it is compatible with the way that Clang expects arguments to '-fuse-ld=' because it looks like 'ld.' is automatically appended.

https://github.com/llvm/llvm-project/blob/5be3dbdb082ffba4f846e3572ea802d156dd8d34/clang/lib/Driver/ToolChain.cpp#L438-L468

Quoted 22 lines
Quoted 16 lines

Makefile endif · line 507

Quoted 1 line
Makefile +1 -0
+endif

This section needs to be moved up above KBUILD_CFLAGS otherwise it never actually gets passed along.

With that change, please add:

Quoted 6 lines
Makefile +0 -1
 export CLANG_FLAGS
 endif
 
--

2.20.1.791.gb4d0f1c61a-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#7 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

In reply to Nick Desaulniers
Quoted 9 lines · Nick Desaulniers
Quoted 6 lines · Nathan Chancellor
Quoted 4 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

What do you mean by 'problematic' ?

I see no build error in
arch/arm64/kernel/vdso/Makefile, at least.

Clang uses BFD linker by default,
which may not match to the $(LD) passed in.

Is this what you mean?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 15 lines
Quoted 10 lines

Makefile endif · line 506

Quoted 10 lines
Makefile +2 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld

Sorry, Sedat reports [0] that this is not quite correct; if $(LD) matches LLD, then we need to set -fuse-ld=$(LD), not -fuse-ld=lld, since you may have lld installed as lld-7 or lld-8, for example:
https://github.com/ClangBuiltLinux/linux/issues/358

Hmm, $(LD) might be a full path.

Looks like Clang can take a full-path for -fuse-ld=, but does it work for GCC?

Quoted 22 lines
Quoted 16 lines

Makefile endif · line 507

Quoted 1 line
Makefile +1 -0
+endif

This section needs to be moved up above KBUILD_CFLAGS otherwise it never actually gets passed along.

With that change, please add:

Quoted 6 lines
Makefile +0 -1
 export CLANG_FLAGS
 endif
 
--

2.20.1.791.gb4d0f1c61a-goog

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Best Regards
Masahiro Yamada
#8 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

On Mon, Feb 11, 2019 at 4:33 PM Masahiro Yamada
<[email protected]> wrote:
[ ... ]

Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 15 lines
Quoted 10 lines

Makefile endif · line 506

Quoted 10 lines
Makefile +2 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld

Sorry, Sedat reports [0] that this is not quite correct; if $(LD) matches LLD, then we need to set -fuse-ld=$(LD), not -fuse-ld=lld, since you may have lld installed as lld-7 or lld-8, for example:
https://github.com/ClangBuiltLinux/linux/issues/358

Quoted 5 lines

Hmm, $(LD) might be a full path.

Looks like Clang can take a full-path for -fuse-ld=, but does it work for GCC?

Nope. GCC expects "-fuse-ld={bfd,gold,lld} ".
Adding suffix "$-VER" was not recognized while building a llvm-toolchain, so I guess this will be the same for the Linux kernel side.

- Sedat -

[1] https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
[2] https://github.com/ClangBuiltLinux/linux/issues/358

#9 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

Quoted 30 lines · Sedat Dilek

On Mon, Feb 11, 2019 at 4:33 PM Masahiro Yamada
<[email protected]> wrote:
[ ... ]

Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 15 lines
Quoted 10 lines

Makefile endif · line 506

Quoted 10 lines
Makefile +2 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld

Sorry, Sedat reports [0] that this is not quite correct; if $(LD) matches LLD, then we need to set -fuse-ld=$(LD), not -fuse-ld=lld, since you may have lld installed as lld-7 or lld-8, for example:
https://github.com/ClangBuiltLinux/linux/issues/358

Hmm, $(LD) might be a full path.

Quoted 8 lines
Quoted 3 lines

Looks like Clang can take a full-path for -fuse-ld=, but does it work for GCC?

Nope. GCC expects "-fuse-ld={bfd,gold,lld} ".
Adding suffix "$-VER" was not recognized while building a llvm-toolchain, so I guess this will be the same for the Linux kernel side.

Well for now, let's add support for just ld.lld since a build of llvm will create such a symlink. If folks really need to differentiate between different versions of lld, let's cross that bridge when we get there.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#10 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

In reply to Masahiro Yamada
Quoted 14 lines · Masahiro Yamada
Quoted 9 lines · Nick Desaulniers
Quoted 6 lines · Nathan Chancellor
Quoted 4 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

What do you mean by 'problematic' ?

Quoted 7 lines

I see no build error in
arch/arm64/kernel/vdso/Makefile, at least.

Clang uses BFD linker by default,
which may not match to the $(LD) passed in.

Is this what you mean?

Right, when using a linker other than BFD, we want cc-ldoption to tell us whether that linker supports a linker flag or not.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#11 lore raw

Re: [PATCH 3/4] Makefile: lld: tell clang to use lld

In reply to Nathan Chancellor
Quoted 14 lines · Nathan Chancellor
Quoted 12 lines · On Thu, Feb 07, 2019 at 02:01:51PM -0800, [email protected] wrote:

This is needed because clang doesn't select which linker to use based on $LD but rather -fuse-ld=$(LD). This is problematic especially for cc-ldoption, which checks for linker flag support via invoking the compiler, rather than the linker.

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 14 lines

Makefile endif · line 507

Quoted 11 lines
Makefile +3 -0
index 0eae4277206e..6307c17259ea 100644
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS  += -no-integrated-as
 KBUILD_CFLAGS        += $(CLANG_FLAGS)
 KBUILD_AFLAGS        += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS  += -fuse-ld=lld
+endif

This section needs to be moved up above KBUILD_CFLAGS otherwise it never actually gets passed along.

Great catch! I had that correct in my Pixel kernel patches; messed that up forward porting them. Included in v2 (sending imminently).

Signature · 2 lines
Thanks,
~Nick Desaulniers
#12 lore raw

PATCH 4/4 Makefile: lld: set -O2 linker flag when linking with LLD

In reply to [email protected]

-O2 enables tail merging of string table strings.

For arm64:
0.34% size improvement with lld -O2 over lld for vmlinux. 3.30% size improvement with lld -O2 over lld for Image.lz4-dtb.

---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Makefile +4 -0
index 6307c17259ea..c07208ec49d4 100644
@@ -718,6 +718,10 @@ else
 KBUILD_CFLAGS += -Wno-unused-but-set-variable
 endif
 
+ifdef CONFIG_LD_IS_LLD
+KBUILD_LDFLAGS += -O2
+endif
+
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Reviewed-by Tested-by on v1 4/4
#13 lore raw

Re: [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD

Quoted 10 lines · On Thu, Feb 07, 2019 at 02:01:52PM -0800, [email protected] wrote:

-O2 enables tail merging of string table strings.

For arm64:
0.34% size improvement with lld -O2 over lld for vmlinux. 3.30% size improvement with lld -O2 over lld for Image.lz4-dtb.

Quoted 22 lines
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Makefile +4 -0
index 6307c17259ea..c07208ec49d4 100644
@@ -718,6 +718,10 @@ else
 KBUILD_CFLAGS += -Wno-unused-but-set-variable
 endif
 
+ifdef CONFIG_LD_IS_LLD
+KBUILD_LDFLAGS += -O2
+endif
+
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Reviewed-by on v1 1/4
#14 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, Feb 7, 2019 at 10:02 PM <[email protected]> wrote:

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

Cc Nathan Chancellor <[email protected]>
Cc Sami Tolvanen <[email protected]>

-Kees

Quoted 27 lines
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
init/Kconfig +9 -1
index c9386a365eea..b6046dcf7794 100644
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
        def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+       def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+       def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+       def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
        bool
        depends on !UML
--

2.20.1.791.gb4d0f1c61a-goog

Signature · 1 line
Kees Cook
#15 lore raw
In reply to [email protected]
Quoted 6 lines · ----- [email protected] wrote:

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

What guarantees that the linker used for e.g. make defconfig is the same linker used for make ?

Is it required with this patch ?

How does it work in a cross compile environment ?

Thanks,

Mathieu

Quoted 31 lines
Cc Nathan Chancellor <[email protected]>
Cc Sami Tolvanen <[email protected]>
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
init/Kconfig +9 -0
index c9386a365eea..b6046dcf7794 100644
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
 	def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
 	bool
 	depends on !UML
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#16 lore raw
Quoted 9 lines · Mathieu Desnoyers
Quoted 6 lines · ----- [email protected] wrote:

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

Hi Mathieu,

Quoted 4 lines

What guarantees that the linker used for e.g. make defconfig is the same linker used for make ?

Is it required with this patch ?

The build system ensures that the compiler (and after this patch, the linker) config values are correct before compiling (and prompting the user for the new choices that are available to them in that case).

For example:

$ make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu- defconfig
...
$ rg "CONFIG_CC_IS|CONFIG_LD_IS" .config
10:CONFIG_CC_IS_CLANG=y
12:CONFIG_LD_IS_BFD=y
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LD=ld.lld
scripts/kconfig/conf  --syncconfig Kconfig
*
* Restart config...
*
*
* General architecture-dependent options
*
Kprobes (KPROBES) [N/y/?] n
Optimize very unlikely/likely branches (JUMP_LABEL) [N/y/?] (NEW)
Stack Protector buffer overflow detection (STACKPROTECTOR) [Y/n/?] y
  Strong Stack Protector (STACKPROTECTOR_STRONG) [Y/n/?] y
Use a virtually-mapped stack (VMAP_STACK) [Y/n/?] y
Perform full reference count validation at the expense of speed (REFCOUNT_FULL) [Y/?] y
*
* GCC plugins
*
GCC plugins (GCC_PLUGINS) [N/y/?] (NEW)
...
$ rg "CONFIG_CC_IS|CONFIG_LD_IS" .config
9:CONFIG_CC_IS_GCC=y
13:CONFIG_LD_IS_LLD=y
Quoted 2 lines

How does it work in a cross compile environment ?

Since $(LD) is defined based on $(CROSS_COMPILE), it should work fine. I tested it with both arm64 and x86_64 and CONFIG_LD_IS_BFD gets set by default and I can see CONFIG_LD_IS_GOLD get set with both LD=aarch64-linux-gnu-ld.gold and LD=ld.gold.

If I misunderstood the questions or my explanation wasn't correct, please let me know!

Cheers,
Nathan

Quoted 41 lines

Thanks,

Mathieu

Quoted 31 lines
Cc Nathan Chancellor <[email protected]>
Cc Sami Tolvanen <[email protected]>
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
init/Kconfig +9 -0
index c9386a365eea..b6046dcf7794 100644
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
 	def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
 	bool
 	depends on !UML
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#17 lore raw
Quoted 59 lines · Nathan Chancellor
Quoted 9 lines · Mathieu Desnoyers
Quoted 6 lines · ----- [email protected] wrote:

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

Hi Mathieu,

Quoted 4 lines

What guarantees that the linker used for e.g. make defconfig is the same linker used for make ?

Is it required with this patch ?

The build system ensures that the compiler (and after this patch, the linker) config values are correct before compiling (and prompting the user for the new choices that are available to them in that case).

For example:

$ make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu- defconfig
...
$ rg "CONFIG_CC_IS|CONFIG_LD_IS" .config
10:CONFIG_CC_IS_CLANG=y
12:CONFIG_LD_IS_BFD=y
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LD=ld.lld
scripts/kconfig/conf  --syncconfig Kconfig
*
* Restart config...
*
*
* General architecture-dependent options
*
Kprobes (KPROBES) [N/y/?] n
Optimize very unlikely/likely branches (JUMP_LABEL) [N/y/?] (NEW)
Stack Protector buffer overflow detection (STACKPROTECTOR) [Y/n/?] y
  Strong Stack Protector (STACKPROTECTOR_STRONG) [Y/n/?] y
Use a virtually-mapped stack (VMAP_STACK) [Y/n/?] y
Perform full reference count validation at the expense of speed (REFCOUNT_FULL) [Y/?] y
*
* GCC plugins
*
GCC plugins (GCC_PLUGINS) [N/y/?] (NEW)
...
$ rg "CONFIG_CC_IS|CONFIG_LD_IS" .config
9:CONFIG_CC_IS_GCC=y
13:CONFIG_LD_IS_LLD=y
Quoted 2 lines

How does it work in a cross compile environment ?

Quoted 7 lines

Since $(LD) is defined based on $(CROSS_COMPILE), it should work fine. I tested it with both arm64 and x86_64 and CONFIG_LD_IS_BFD gets set by default and I can see CONFIG_LD_IS_GOLD get set with both LD=aarch64-linux-gnu-ld.gold and LD=ld.gold.

If I misunderstood the questions or my explanation wasn't correct, please let me know!

With this patch,

include/config/auto.conf.cmd will include the following:

ifneq "$(LD)" "ld"
include/config/auto.conf: FORCE
endif

When $(LD) is changed, Kconfig will be re-run.

--
Best Regards
Masahiro Yamada

Reviewed-by Tested-by on v1 1/4
#18 lore raw
In reply to [email protected]
Quoted 10 lines · On Thu, Feb 07, 2019 at 02:01:49PM -0800, [email protected] wrote:

Similar to how we differentiate between CONFIG_CC_IS_GCC and CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things for different linkers.

Cc Nathan Chancellor <[email protected]>
Cc Sami Tolvanen <[email protected]>
Quoted 27 lines
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
init/Kconfig +9 -0
index c9386a365eea..b6046dcf7794 100644
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
 	def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
 	bool
 	depends on !UML
Signature · 1 line
2.20.1.791.gb4d0f1c61a-goog