Skip to content

Commit

Permalink
lkl: add lld support for x86_64
Browse files Browse the repository at this point in the history
lld, the LLVM linker, can link recent mainline Linux kernel. It provides
faster link time compared with GNU linker[1]. This commit adds lld support
to lkl for x86_64 Linux host with clang.
To build with lld, invoke command like below:

make -C tools/lkl CC=clang LD=ld.lld

[1] https://lld.llvm.org/

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Oct 24, 2019
1 parent 8a1fc6c commit 2b07681
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion arch/lkl/auto.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export OUTPUT_FORMAT=$(shell $(LD) -r -print-output-format)
ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
CC_TARGET=$(shell $(CC) --version 2>&1 | grep Target | cut -d " " -f2)
ifeq ($(CC_TARGET),x86_64-unknown-linux-gnu)
export OUTPUT_FORMAT=elf64-x86-64
endif
else
export OUTPUT_FORMAT=$(shell $(LD) -r -print-output-format)
endif
export EXEC_FORMAT=$(shell echo $(OUTPUT_FORMAT) | cut -d - -f1)
11 changes: 10 additions & 1 deletion tools/lkl/Makefile.autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ define set_autoconf_var
export LKL_HOST_CONFIG_$(1)=$(2)
endef

define set_output_format
$(eval output_format=$(shell $(LD) -r -print-output-format))
$(if $(filter "",$(output_format)),$(eval target=$(shell $(CC) --version 2>&1 \
| grep Target | cut -d " " -f2)))
$(if $(filter x86_64-unknown-linux-gnu,$(target)),$(eval \
output_format=elf64-x86-64))
$(1) := $$(output_format)
endef

define find_include
$(eval include_paths=$(shell $(CC) -E -Wp,-v -xc /dev/null 2>&1 | grep '^ '))
$(foreach f, $(include_paths), $(wildcard $(f)/$(1)))
Expand Down Expand Up @@ -98,7 +107,7 @@ define do_autoconf
export AR := $(CROSS_COMPILE)ar
$(eval LD := $(CROSS_COMPILE)ld)
$(eval CC := $(CROSS_COMPILE)gcc)
$(eval LD_FMT := $(shell $(LD) -r -print-output-format))
$(eval $(call set_output_format,LD_FMT))
$(eval EXEC_FMT := $(shell echo $(LD_FMT) | cut -d "-" -f1))
$(if $(filter $(EXEC_FMT),$(POSIX_HOSTS)),$(call posix_host,$(LD_FMT)))
$(if $(filter $(EXEC_FMT),$(NT_HOSTS)),$(call nt_host,$(LD_FMT)))
Expand Down

0 comments on commit 2b07681

Please sign in to comment.