Skip to content

Commit

Permalink
lkl: add lld support for x86_64/i386
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/i386 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 26, 2019
1 parent 8a1fc6c commit 0ffdab2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
25 changes: 24 additions & 1 deletion arch/lkl/auto.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
export OUTPUT_FORMAT=$(shell $(LD) -r -print-output-format)
ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
ifneq (,$(shell $(CC) --version 2>&1 | grep clang | head -n 1))
TRIPLE=$(shell $(CC) --version 2>&1 | grep Target | cut -d " " -f2)
else
TRIPLE=$(shell $(CC) -dumpmachine)
endif
TRIPLE_ARCH=$(shell echo $(TRIPLE) | cut -d - -f1)
TRIPLE_VENDOR=$(shell echo $(TRIPLE) | cut -d - -f2)
TRIPLE_OS=$(shell echo $(TRIPLE) | cut -d - -f3)
ifneq (,$(filter linux,$(TRIPLE_VENDOR)))
TRIPLE_OS=$(TRIPLE_VENDOR)
endif
ifneq (,$(filter x86_64,$(TRIPLE_ARCH)))
ifneq (,$(filter linux,$(TRIPLE_OS)))
export OUTPUT_FORMAT=elf64-x86-64
endif
else ifneq (,$(filter i386 i686,$(TRIPLE_ARCH)))
ifneq (,$(filter linux,$(TRIPLE_OS)))
export OUTPUT_FORMAT=elf32-i386
endif
endif
else
export OUTPUT_FORMAT=$(shell $(LD) -r -print-output-format)
endif
export EXEC_FORMAT=$(shell echo $(OUTPUT_FORMAT) | cut -d - -f1)
18 changes: 17 additions & 1 deletion tools/lkl/Makefile.autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ 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 $(output_format),,$(if $(shell $(CC) --version 2>&1 | grep clang),$(eval \
triple=$(shell $(CC) --version 2>&1 | grep Target | cut -d " " -f2)),$(eval \
triple=$(shell $(CC) -dumpmachine))))
$(eval arch=$(shell echo $(triple) | cut -d - -f1))
$(eval vendor=$(shell echo $(triple) | cut -d - -f2))
$(eval os=$(shell echo $(triple) | cut -d - -f3))
$(if $(filter linux,$(vendor)),$(eval os=$(vendor)))
$(if $(filter x86_64,$(arch)),$(if $(filter linux,$(os)),$(eval \
output_format=elf64-x86-64)))
$(if $(filter i386 i686,$(arch)),$(if $(filter linux,$(os)),$(eval \
output_format=elf32-i386)))
$(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 +114,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 0ffdab2

Please sign in to comment.