Skip to content

Commit

Permalink
BACKPORT: FROMLIST: Makefile: lld: tell clang to use lld
Browse files Browse the repository at this point in the history
This is needed because clang doesn't select which linker to use based on
$LD but rather -fuse-ld={bfd,gold,lld,<absolute path to linker>}.  This
is problematic especially for cc-ldoption, which checks for linker flag
support via invoking the compiler, rather than the linker.

Select the linker via absolute path from $PATH via `which`. This allows
you to build with:

$ make LD=ld.lld
$ make LD=ld.lld-8
$ make LD=/path/to/ld.lld

Add -Qunused-arguments to KBUILD_CPPFLAGS sooner, as otherwise
Clang likes to complain about -fuse-lld= being unused when compiling but
not linking (-c) such as when cc-option is used. There's no need to
guard with cc-option.

Link: ClangBuiltLinux/linux#342
Link: ClangBuiltLinux/linux#366
Link: ClangBuiltLinux/linux#357
Suggested-by: Nathan Chancellor <natechancellor@gmail.com>
Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
(am from https://lore.kernel.org/patchwork/patch/1057183/)
[kdrag0n: Backported to k4.14 with the following changes:
           - Replaced full version check with ld-name call because we
             added support for lld to ld-name
]
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
  • Loading branch information
nickdesaulniers authored and kondors1995 committed Oct 18, 2019
1 parent 3d8ab20 commit 3eb20a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
CLANG_FLAGS += -no-integrated-as
CLANG_FLAGS += -Werror=unknown-warning-option
ifeq ($(ld-name),lld)
CLANG_FLAGS += -fuse-ld=$(shell which $(LD))
endif
KBUILD_CPPFLAGS += -Qunused-arguments
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
export CLANG_FLAGS
Expand Down Expand Up @@ -750,7 +754,6 @@ endif
KBUILD_CFLAGS += $(stackp-flag)

ifeq ($(cc-name),clang)
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
KBUILD_CFLAGS += $(call cc-disable-warning, duplicate-decl-specifier)
Expand Down

0 comments on commit 3eb20a1

Please sign in to comment.