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. This commit
adds lld support to lkl for x86_64 Linux host with clang.
To build with lld, invoke make like below:

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

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Oct 21, 2019
1 parent 8a1fc6c commit 66208e2
Show file tree
Hide file tree
Showing 2 changed files with 21 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)
14 changes: 13 additions & 1 deletion tools/lkl/Makefile.autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ define set_autoconf_var
export LKL_HOST_CONFIG_$(1)=$(2)
endef

define output_format
$(if $(shell $(LD) --version 2>&1 | head -n 1 \
| grep LLD),$(eval lld=yes),$(eval lld=no))
$(if $(filter yes,$(lld)),$(eval target=$(shell $(CC) --version 2>&1 \
| grep Target | cut -d " " -f2)))
$(if $(filter x86_64-unknown-linux-gnu,$(target)),$(call \
set_autoconf_var,OUTPUT_FORMAT,"elf64-x86-64"))
$(if $(filter no,$(lld)),$(call set_autoconf_var,OUTPUT_FORMAT,"$(shell \
$(LD) -r -print-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 +109,8 @@ 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))
$(call output_format)
$(eval LD_FMT := $(shell echo $(LKL_HOST_CONFIG_OUTPUT_FORMAT)))
$(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 66208e2

Please sign in to comment.