Skip to content

Commit

Permalink
Merge pull request torvalds#512 from rodionov/master
Browse files Browse the repository at this point in the history
Enable LLVM toolchain for building LKL targets.
  • Loading branch information
tavip authored Jan 27, 2023
2 parents 1f97f6e + 9bc2d46 commit b00f0fb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
os: windows
runs_on: windows-2019
shell: msys2 {0}
- displayTargetName: clang-build
os: unix
runs_on: ubuntu-22.04
shell: bash
build_options: "LLVM=1 CROSS_COMPILE=x86_64-linux-gnu"
timeout-minutes: 100
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
Expand Down Expand Up @@ -93,6 +98,11 @@ jobs:
run: |
sudo apt update -y
sudo apt install -y ccache libjsmn-dev
- name: Install clang toolchain
if: runner.os == 'Linux'
run: |
sudo apt update -y
sudo apt install -y clang lld llvm
- name: Install patched binutils for Windows
if: runner.os == 'Windows'
run: |
Expand Down
18 changes: 18 additions & 0 deletions arch/lkl/kernel/misc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#include <linux/seq_file.h>

// TODO: Functions __generic_xchg_called_with_bad_pointer and wrong_size_cmpxchg
// are called in __generic_xchg and __generic_cmpxchg_local respectively.
// They should be optimized out by the compiler due to the function
// inlining. However, when building with clang there are some instances
// where the functions aren't inlined and, thus, the compile-time optimization
// doesn't eliminate them entirely. As a result, the linker throws
// unresololved symbols error. As a workaround, the fix below define these
// functions to bypass the link-time error.
void __generic_xchg_called_with_bad_pointer(void)
{
panic("%s shouldn't be executed\n", __func__);
}
unsigned long wrong_size_cmpxchg(volatile void *ptr)
{
panic("%s shouldn't be executed\n", __func__);
return 0;
}

#ifdef CONFIG_PROC_FS
static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
{
Expand Down
3 changes: 3 additions & 0 deletions tools/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ $(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF)
$(Q)if ! [ -e $@ ]; then ln -s $< $@; fi

clean:
$(call QUIET_CLEAN, vmlinux)$(MAKE) -C ../.. ARCH=lkl $(KOPT) clean
$(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\
-delete -o -name '\.*.d' -delete
$(call QUIET_CLEAN, headers)$(RM) -r $(OUTPUT)/include/lkl/
Expand All @@ -113,6 +114,8 @@ clean:

clean-conf: clean
$(call QUIET_CLEAN, Makefile.conf)$(RM) $(OUTPUT)/Makefile.conf
$(call QUIET_CLEAN, kernel_config.h)$(RM) $(OUTPUT)/include/kernel_config.h
$(call QUIET_CLEAN, kernel.config)$(RM) $(OUTPUT)/kernel.config

headers_install: $(TARGETS)
$(call QUIET_INSTALL, headers) \
Expand Down
23 changes: 22 additions & 1 deletion tools/lkl/Makefile.autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,35 @@ define kasan_enable
$(if $(filter yes,$(kasan_test)), $(call kasan_test_enable))
endef

define do_autoconf
define do_autoconf_gnu
export CROSS_COMPILE := $(CROSS_COMPILE)
export CC := $(CROSS_COMPILE)gcc
export LD := $(CROSS_COMPILE)ld
export AR := $(CROSS_COMPILE)ar
$(eval LD := $(CROSS_COMPILE)ld)
$(eval CC := $(CROSS_COMPILE)gcc)
$(eval LD_FMT := $(shell $(LD) -r -print-output-format))
endef

define llvm_target_to_ld_fmt
$(if $(filter $(CROSS_COMPILE),x86_64-linux-gnu),elf64-x86-64,\
$(error Unsupported LLVM target $(CROSS_COMPILE)))
endef

define do_autoconf_llvm
$(eval LLVM_PREFIX := $(if $(filter %/,$(LLVM)),$(LLVM)))
$(eval LLVM_SUFFIX := $(if $(filter -%,$(LLVM)),$(LLVM)))
export CROSS_COMPILE := $(CROSS_COMPILE)
export CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
export LD := $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
export AR := $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
$(eval LD := $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX))
$(eval CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX))
$(eval LD_FMT := $(call llvm_target_to_ld_fmt))
endef

define do_autoconf
$(if $(LLVM),$(call do_autoconf_llvm),$(call do_autoconf_gnu))
$(eval EXEC_FMT := $(shell echo $(LD_FMT) | cut -d "-" -f1))
$(call set_kernel_config,OUTPUT_FORMAT,\"$(LD_FMT)\")
$(if $(or $(filter $(EXEC_FMT),elf64),$(filter $(LD_FMT),pe-x86-64)),$(call 64bit_host))
Expand Down

0 comments on commit b00f0fb

Please sign in to comment.