LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH 1/4] init/Kconfig: add config support for detecting linker
@ 2019-02-07 22:01 ndesaulniers
  2019-02-07 22:01 ` [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD ndesaulniers
                   ` (5 more replies)
  0 siblings, 6 replies; 21+ messages in thread
From: ndesaulniers @ 2019-02-07 22:01 UTC (permalink / raw)
  To: yamada.masahiro
  Cc: Nick Desaulniers, Nathan Chancellor, Sami Tolvanen,
	Andrew Morton, Peter Zijlstra (Intel),
	Johannes Weiner, Kees Cook, Dominik Brodowski, Nicholas Piggin,
	Mathieu Desnoyers, Vasily Gorbik, Adrian Reber,
	Richard Guy Briggs, linux-kernel

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 <natechancellor@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 init/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index c9386a365eea..b6046dcf7794 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
@ 2019-02-07 22:01 ` ndesaulniers
  2019-02-08  5:45   ` Nathan Chancellor
  2019-02-07 22:01 ` [PATCH 3/4] Makefile: lld: tell clang to use lld ndesaulniers
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 21+ messages in thread
From: ndesaulniers @ 2019-02-07 22:01 UTC (permalink / raw)
  To: yamada.masahiro
  Cc: Nick Desaulniers, Nathan Chancellor, Michal Marek, linux-kbuild,
	linux-kernel

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")

Link: https://github.com/ClangBuiltLinux/linux/issues/341
Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3142e67d03f1..0eae4277206e 100644
--- a/Makefile
+++ b/Makefile
@@ -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
-- 
2.20.1.791.gb4d0f1c61a-goog


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
  2019-02-07 22:01 ` [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD ndesaulniers
@ 2019-02-07 22:01 ` ndesaulniers
  2019-02-08  5:50   ` Nathan Chancellor
  2019-02-07 22:01 ` [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD ndesaulniers
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 21+ messages in thread
From: ndesaulniers @ 2019-02-07 22:01 UTC (permalink / raw)
  To: yamada.masahiro
  Cc: Nick Desaulniers, Nathan Chancellor, Michal Marek, linux-kbuild,
	linux-kernel

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.

Link: https://github.com/ClangBuiltLinux/linux/issues/342
Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Makefile b/Makefile
index 0eae4277206e..6307c17259ea 100644
--- a/Makefile
+++ b/Makefile
@@ -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
 
-- 
2.20.1.791.gb4d0f1c61a-goog


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
  2019-02-07 22:01 ` [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD ndesaulniers
  2019-02-07 22:01 ` [PATCH 3/4] Makefile: lld: tell clang to use lld ndesaulniers
@ 2019-02-07 22:01 ` ndesaulniers
  2019-02-08  6:07   ` Nathan Chancellor
  2019-02-08  0:48 ` [PATCH 1/4] init/Kconfig: add config support for detecting linker Kees Cook
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 21+ messages in thread
From: ndesaulniers @ 2019-02-07 22:01 UTC (permalink / raw)
  To: yamada.masahiro
  Cc: Nick Desaulniers, Rui Ueyama, Nathan Chancellor, Michal Marek,
	linux-kbuild, linux-kernel

-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.

Link: https://github.com/ClangBuiltLinux/linux/issues/343
Suggested-by: Rui Ueyama <ruiu@google.com>
Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 6307c17259ea..c07208ec49d4 100644
--- a/Makefile
+++ b/Makefile
@@ -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
-- 
2.20.1.791.gb4d0f1c61a-goog


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] init/Kconfig: add config support for detecting linker
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
                   ` (2 preceding siblings ...)
  2019-02-07 22:01 ` [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD ndesaulniers
@ 2019-02-08  0:48 ` Kees Cook
  2019-02-08  0:57 ` Mathieu Desnoyers
  2019-02-08  5:14 ` Nathan Chancellor
  5 siblings, 0 replies; 21+ messages in thread
From: Kees Cook @ 2019-02-08  0:48 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Nathan Chancellor, Sami Tolvanen, Andrew Morton,
	Peter Zijlstra (Intel),
	Johannes Weiner, Dominik Brodowski, Nicholas Piggin,
	Mathieu Desnoyers, Vasily Gorbik, Adrian Reber,
	Richard Guy Briggs, LKML

On Thu, Feb 7, 2019 at 10:02 PM <ndesaulniers@google.com> 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 <natechancellor@gmail.com>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  init/Kconfig | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index c9386a365eea..b6046dcf7794 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -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
>


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] init/Kconfig: add config support for detecting linker
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
                   ` (3 preceding siblings ...)
  2019-02-08  0:48 ` [PATCH 1/4] init/Kconfig: add config support for detecting linker Kees Cook
@ 2019-02-08  0:57 ` Mathieu Desnoyers
  2019-02-08  5:41   ` Nathan Chancellor
  2019-02-08  5:14 ` Nathan Chancellor
  5 siblings, 1 reply; 21+ messages in thread
From: Mathieu Desnoyers @ 2019-02-08  0:57 UTC (permalink / raw)
  To: ndesaulniers
  Cc: yamada masahiro, Nathan Chancellor, Sami Tolvanen, Andrew Morton,
	Peter Zijlstra (Intel),
	Johannes Weiner, Kees Cook, Dominik Brodowski, Nicholas Piggin,
	Vasily Gorbik, Adrian Reber, Richard Guy Briggs, linux-kernel


----- ndesaulniers@google.com 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


> 
> Cc: Nathan Chancellor <natechancellor@gmail.com>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  init/Kconfig | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index c9386a365eea..b6046dcf7794 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -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
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] init/Kconfig: add config support for detecting linker
  2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
                   ` (4 preceding siblings ...)
  2019-02-08  0:57 ` Mathieu Desnoyers
@ 2019-02-08  5:14 ` Nathan Chancellor
  5 siblings, 0 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08  5:14 UTC (permalink / raw)
  To: ndesaulniers
  Cc: yamada.masahiro, Sami Tolvanen, Andrew Morton,
	Peter Zijlstra (Intel),
	Johannes Weiner, Kees Cook, Dominik Brodowski, Nicholas Piggin,
	Mathieu Desnoyers, Vasily Gorbik, Adrian Reber,
	Richard Guy Briggs, linux-kernel

On Thu, Feb 07, 2019 at 02:01:49PM -0800, ndesaulniers@google.com 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 <natechancellor@gmail.com>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  init/Kconfig | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index c9386a365eea..b6046dcf7794 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -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
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] init/Kconfig: add config support for detecting linker
  2019-02-08  0:57 ` Mathieu Desnoyers
@ 2019-02-08  5:41   ` Nathan Chancellor
  2019-02-11 15:08     ` Masahiro Yamada
  0 siblings, 1 reply; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08  5:41 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: ndesaulniers, yamada masahiro, Sami Tolvanen, Andrew Morton,
	Peter Zijlstra (Intel),
	Johannes Weiner, Kees Cook, Dominik Brodowski, Nicholas Piggin,
	Vasily Gorbik, Adrian Reber, Richard Guy Briggs, linux-kernel

On Thu, Feb 07, 2019 at 07:57:20PM -0500, Mathieu Desnoyers wrote:
> 
> ----- ndesaulniers@google.com 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,

> 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

> 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

> Thanks,
> 
> Mathieu
> 
> 
> > 
> > Cc: Nathan Chancellor <natechancellor@gmail.com>
> > Cc: Sami Tolvanen <samitolvanen@google.com>
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> >  init/Kconfig | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/init/Kconfig b/init/Kconfig
> > index c9386a365eea..b6046dcf7794 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -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
> > 
> 
> -- 
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD
  2019-02-07 22:01 ` [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD ndesaulniers
@ 2019-02-08  5:45   ` Nathan Chancellor
  0 siblings, 0 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08  5:45 UTC (permalink / raw)
  To: ndesaulniers; +Cc: yamada.masahiro, Michal Marek, linux-kbuild, linux-kernel

On Thu, Feb 07, 2019 at 02:01:50PM -0800, ndesaulniers@google.com 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.
> 
> Fixes commit 785f11aa595b ("kbuild: Add better clang cross build support")
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/341
> Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 3142e67d03f1..0eae4277206e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
> -- 
> 2.20.1.791.gb4d0f1c61a-goog
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-07 22:01 ` [PATCH 3/4] Makefile: lld: tell clang to use lld ndesaulniers
@ 2019-02-08  5:50   ` Nathan Chancellor
  2019-02-08 17:27     ` Nick Desaulniers
  2019-02-11 19:26     ` Nick Desaulniers
  0 siblings, 2 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08  5:50 UTC (permalink / raw)
  To: ndesaulniers; +Cc: yamada.masahiro, Michal Marek, linux-kbuild, linux-kernel

On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/342
> Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  Makefile | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 0eae4277206e..6307c17259ea 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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:

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

>  export CLANG_FLAGS
>  endif
>  
> -- 
> 2.20.1.791.gb4d0f1c61a-goog
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD
  2019-02-07 22:01 ` [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD ndesaulniers
@ 2019-02-08  6:07   ` Nathan Chancellor
  0 siblings, 0 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08  6:07 UTC (permalink / raw)
  To: ndesaulniers
  Cc: yamada.masahiro, Rui Ueyama, Michal Marek, linux-kbuild, linux-kernel

On Thu, Feb 07, 2019 at 02:01:52PM -0800, ndesaulniers@google.com 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.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/343
> Suggested-by: Rui Ueyama <ruiu@google.com>
> Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 6307c17259ea..c07208ec49d4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
> -- 
> 2.20.1.791.gb4d0f1c61a-goog
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-08  5:50   ` Nathan Chancellor
@ 2019-02-08 17:27     ` Nick Desaulniers
  2019-02-08 17:45       ` Nathan Chancellor
  2019-02-11 15:32       ` Masahiro Yamada
  2019-02-11 19:26     ` Nick Desaulniers
  1 sibling, 2 replies; 21+ messages in thread
From: Nick Desaulniers @ 2019-02-08 17:27 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Masahiro Yamada, Michal Marek, Linux Kbuild mailing list, LKML,
	sedat.dilek

On Thu, Feb 7, 2019 at 9:51 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> >  Makefile | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/Makefile b/Makefile
> > index 0eae4277206e..6307c17259ea 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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

> > +endif
>
> This section needs to be moved up above KBUILD_CFLAGS otherwise it never
> actually gets passed along.
>
> With that change, please add:
>
> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
> Tested-by: Nathan Chancellor <natechancellor@gmail.com>
>
> >  export CLANG_FLAGS
> >  endif
> >
> > --
> > 2.20.1.791.gb4d0f1c61a-goog
> >



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-08 17:27     ` Nick Desaulniers
@ 2019-02-08 17:45       ` Nathan Chancellor
  2019-02-11 15:32       ` Masahiro Yamada
  1 sibling, 0 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08 17:45 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Michal Marek, Linux Kbuild mailing list, LKML,
	sedat.dilek

On Fri, Feb 08, 2019 at 09:27:19AM -0800, Nick Desaulniers wrote:
> On Thu, Feb 7, 2019 at 9:51 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > > ---
> > >  Makefile | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index 0eae4277206e..6307c17259ea 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -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

> > > +endif
> >
> > This section needs to be moved up above KBUILD_CFLAGS otherwise it never
> > actually gets passed along.
> >
> > With that change, please add:
> >
> > Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
> > Tested-by: Nathan Chancellor <natechancellor@gmail.com>
> >
> > >  export CLANG_FLAGS
> > >  endif
> > >
> > > --
> > > 2.20.1.791.gb4d0f1c61a-goog
> > >
> 
> 
> 
> -- 
> Thanks,
> ~Nick Desaulniers

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] init/Kconfig: add config support for detecting linker
  2019-02-08  5:41   ` Nathan Chancellor
@ 2019-02-11 15:08     ` Masahiro Yamada
  0 siblings, 0 replies; 21+ messages in thread
From: Masahiro Yamada @ 2019-02-11 15:08 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Mathieu Desnoyers, Nick Desaulniers, Sami Tolvanen,
	Andrew Morton, Peter Zijlstra (Intel),
	Johannes Weiner, Kees Cook, Dominik Brodowski, Nicholas Piggin,
	Vasily Gorbik, Adrian Reber, Richard Guy Briggs,
	Linux Kernel Mailing List

On Fri, Feb 8, 2019 at 2:42 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Thu, Feb 07, 2019 at 07:57:20PM -0500, Mathieu Desnoyers wrote:
> >
> > ----- ndesaulniers@google.com 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,
>
> > 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
>
> > 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!




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

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-08 17:27     ` Nick Desaulniers
  2019-02-08 17:45       ` Nathan Chancellor
@ 2019-02-11 15:32       ` Masahiro Yamada
  2019-02-11 16:05         ` Sedat Dilek
  2019-02-11 19:27         ` Nick Desaulniers
  1 sibling, 2 replies; 21+ messages in thread
From: Masahiro Yamada @ 2019-02-11 15:32 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Nathan Chancellor, Michal Marek, Linux Kbuild mailing list, LKML,
	Sedat Dilek

On Sat, Feb 9, 2019 at 2:27 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Thu, Feb 7, 2019 at 9:51 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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?





> > > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > > ---
> > >  Makefile | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index 0eae4277206e..6307c17259ea 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -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?






> > > +endif
> >
> > This section needs to be moved up above KBUILD_CFLAGS otherwise it never
> > actually gets passed along.
> >
> > With that change, please add:
> >
> > Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
> > Tested-by: Nathan Chancellor <natechancellor@gmail.com>
> >
> > >  export CLANG_FLAGS
> > >  endif
> > >
> > > --
> > > 2.20.1.791.gb4d0f1c61a-goog
> > >
>
>
>
> --
> Thanks,
> ~Nick Desaulniers



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-11 15:32       ` Masahiro Yamada
@ 2019-02-11 16:05         ` Sedat Dilek
  2019-02-11 19:30           ` Nick Desaulniers
  2019-02-11 19:27         ` Nick Desaulniers
  1 sibling, 1 reply; 21+ messages in thread
From: Sedat Dilek @ 2019-02-11 16:05 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Nick Desaulniers, Nathan Chancellor, Michal Marek,
	Linux Kbuild mailing list, LKML

On Mon, Feb 11, 2019 at 4:33 PM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
[ ... ]
> > > > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > > > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > > > ---
> > > >  Makefile | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/Makefile b/Makefile
> > > > index 0eae4277206e..6307c17259ea 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -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?
>

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

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-08  5:50   ` Nathan Chancellor
  2019-02-08 17:27     ` Nick Desaulniers
@ 2019-02-11 19:26     ` Nick Desaulniers
  1 sibling, 0 replies; 21+ messages in thread
From: Nick Desaulniers @ 2019-02-11 19:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Masahiro Yamada, Michal Marek, Linux Kbuild mailing list, LKML

On Thu, Feb 7, 2019 at 9:51 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> >  Makefile | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/Makefile b/Makefile
> > index 0eae4277206e..6307c17259ea 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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).

-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-11 15:32       ` Masahiro Yamada
  2019-02-11 16:05         ` Sedat Dilek
@ 2019-02-11 19:27         ` Nick Desaulniers
  1 sibling, 0 replies; 21+ messages in thread
From: Nick Desaulniers @ 2019-02-11 19:27 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Nathan Chancellor, Michal Marek, Linux Kbuild mailing list, LKML,
	Sedat Dilek

On Mon, Feb 11, 2019 at 7:33 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> On Sat, Feb 9, 2019 at 2:27 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Thu, Feb 7, 2019 at 9:51 PM Nathan Chancellor
> > <natechancellor@gmail.com> wrote:
> > >
> > > On Thu, Feb 07, 2019 at 02:01:51PM -0800, ndesaulniers@google.com 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?

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

-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-11 16:05         ` Sedat Dilek
@ 2019-02-11 19:30           ` Nick Desaulniers
  0 siblings, 0 replies; 21+ messages in thread
From: Nick Desaulniers @ 2019-02-11 19:30 UTC (permalink / raw)
  To: Sedat Dilek
  Cc: Masahiro Yamada, Nathan Chancellor, Michal Marek,
	Linux Kbuild mailing list, LKML

On Mon, Feb 11, 2019 at 8:05 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Mon, Feb 11, 2019 at 4:33 PM Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
> [ ... ]
> > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/342
> > > > > Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
> > > > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > > > > ---
> > > > >  Makefile | 3 +++
> > > > >  1 file changed, 3 insertions(+)
> > > > >
> > > > > diff --git a/Makefile b/Makefile
> > > > > index 0eae4277206e..6307c17259ea 100644
> > > > > --- a/Makefile
> > > > > +++ b/Makefile
> > > > > @@ -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?
> >
>
> 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.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
  2019-02-08 14:21 [PATCH 3/4] Makefile: lld: tell clang to use lld Sedat Dilek
@ 2019-02-08 16:24 ` Nathan Chancellor
  0 siblings, 0 replies; 21+ messages in thread
From: Nathan Chancellor @ 2019-02-08 16:24 UTC (permalink / raw)
  To: Sedat Dilek
  Cc: Masahiro Yamada, Nick Desaulniers, Michal Marek, linux-kbuild,
	linux-kernel

On Fri, Feb 08, 2019 at 03:21:15PM +0100, Sedat Dilek wrote:
> Hi Nick,
> 
> why don't you simply check for CONFIG_LD_IS_LLD existing (when [1] applied)?
> 

Hi Sedat,

This section runs before Kconfig so we can't rely on the symbols it
generates. See commit 995167420797 ("kbuild: remove cc-name variable")
for Masahiro's explanation.

> If you want a specific version of ld.lld (you mentioned kernel module
> linking failure was fixed recently) why not transfer this into a
> scripts/lld-version.sh file?
> 

We'll probably need that eventually but given that lld isn't ready for
widespread use, I don't think it's necessary.

> Greetings,
> - Sedat -
> 
> [1] https://lore.kernel.org/patchwork/patch/1039719/ ("[1/4]
> init/Kconfig: add config support for detecting linker")

Nathan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] Makefile: lld: tell clang to use lld
@ 2019-02-08 14:21 Sedat Dilek
  2019-02-08 16:24 ` Nathan Chancellor
  0 siblings, 1 reply; 21+ messages in thread
From: Sedat Dilek @ 2019-02-08 14:21 UTC (permalink / raw)
  To: Masahiro Yamada, Nick Desaulniers, Nathan Chancellor,
	Michal Marek, linux-kbuild, linux-kernel

Hi Nick,

why don't you simply check for CONFIG_LD_IS_LLD existing (when [1] applied)?

If you want a specific version of ld.lld (you mentioned kernel module
linking failure was fixed recently) why not transfer this into a
scripts/lld-version.sh file?

Greetings,
- Sedat -

[1] https://lore.kernel.org/patchwork/patch/1039719/ ("[1/4]
init/Kconfig: add config support for detecting linker")

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, back to index

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 22:01 [PATCH 1/4] init/Kconfig: add config support for detecting linker ndesaulniers
2019-02-07 22:01 ` [PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD ndesaulniers
2019-02-08  5:45   ` Nathan Chancellor
2019-02-07 22:01 ` [PATCH 3/4] Makefile: lld: tell clang to use lld ndesaulniers
2019-02-08  5:50   ` Nathan Chancellor
2019-02-08 17:27     ` Nick Desaulniers
2019-02-08 17:45       ` Nathan Chancellor
2019-02-11 15:32       ` Masahiro Yamada
2019-02-11 16:05         ` Sedat Dilek
2019-02-11 19:30           ` Nick Desaulniers
2019-02-11 19:27         ` Nick Desaulniers
2019-02-11 19:26     ` Nick Desaulniers
2019-02-07 22:01 ` [PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD ndesaulniers
2019-02-08  6:07   ` Nathan Chancellor
2019-02-08  0:48 ` [PATCH 1/4] init/Kconfig: add config support for detecting linker Kees Cook
2019-02-08  0:57 ` Mathieu Desnoyers
2019-02-08  5:41   ` Nathan Chancellor
2019-02-11 15:08     ` Masahiro Yamada
2019-02-08  5:14 ` Nathan Chancellor
2019-02-08 14:21 [PATCH 3/4] Makefile: lld: tell clang to use lld Sedat Dilek
2019-02-08 16:24 ` Nathan Chancellor

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox