Skip to content

Commit b00f0fb

Browse files
authored
Merge pull request torvalds#512 from rodionov/master
Enable LLVM toolchain for building LKL targets.
2 parents 1f97f6e + 9bc2d46 commit b00f0fb

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ jobs:
2626
os: windows
2727
runs_on: windows-2019
2828
shell: msys2 {0}
29+
- displayTargetName: clang-build
30+
os: unix
31+
runs_on: ubuntu-22.04
32+
shell: bash
33+
build_options: "LLVM=1 CROSS_COMPILE=x86_64-linux-gnu"
2934
timeout-minutes: 100
3035
env:
3136
CCACHE_DIR: ${{ github.workspace }}/.ccache
@@ -93,6 +98,11 @@ jobs:
9398
run: |
9499
sudo apt update -y
95100
sudo apt install -y ccache libjsmn-dev
101+
- name: Install clang toolchain
102+
if: runner.os == 'Linux'
103+
run: |
104+
sudo apt update -y
105+
sudo apt install -y clang lld llvm
96106
- name: Install patched binutils for Windows
97107
if: runner.os == 'Windows'
98108
run: |

arch/lkl/kernel/misc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#include <linux/seq_file.h>
22

3+
// TODO: Functions __generic_xchg_called_with_bad_pointer and wrong_size_cmpxchg
4+
// are called in __generic_xchg and __generic_cmpxchg_local respectively.
5+
// They should be optimized out by the compiler due to the function
6+
// inlining. However, when building with clang there are some instances
7+
// where the functions aren't inlined and, thus, the compile-time optimization
8+
// doesn't eliminate them entirely. As a result, the linker throws
9+
// unresololved symbols error. As a workaround, the fix below define these
10+
// functions to bypass the link-time error.
11+
void __generic_xchg_called_with_bad_pointer(void)
12+
{
13+
panic("%s shouldn't be executed\n", __func__);
14+
}
15+
unsigned long wrong_size_cmpxchg(volatile void *ptr)
16+
{
17+
panic("%s shouldn't be executed\n", __func__);
18+
return 0;
19+
}
20+
321
#ifdef CONFIG_PROC_FS
422
static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
523
{

tools/lkl/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ $(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF)
105105
$(Q)if ! [ -e $@ ]; then ln -s $< $@; fi
106106

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

114115
clean-conf: clean
115116
$(call QUIET_CLEAN, Makefile.conf)$(RM) $(OUTPUT)/Makefile.conf
117+
$(call QUIET_CLEAN, kernel_config.h)$(RM) $(OUTPUT)/include/kernel_config.h
118+
$(call QUIET_CLEAN, kernel.config)$(RM) $(OUTPUT)/kernel.config
116119

117120
headers_install: $(TARGETS)
118121
$(call QUIET_INSTALL, headers) \

tools/lkl/Makefile.autoconf

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,35 @@ define kasan_enable
142142
$(if $(filter yes,$(kasan_test)), $(call kasan_test_enable))
143143
endef
144144

145-
define do_autoconf
145+
define do_autoconf_gnu
146146
export CROSS_COMPILE := $(CROSS_COMPILE)
147147
export CC := $(CROSS_COMPILE)gcc
148148
export LD := $(CROSS_COMPILE)ld
149149
export AR := $(CROSS_COMPILE)ar
150150
$(eval LD := $(CROSS_COMPILE)ld)
151151
$(eval CC := $(CROSS_COMPILE)gcc)
152152
$(eval LD_FMT := $(shell $(LD) -r -print-output-format))
153+
endef
154+
155+
define llvm_target_to_ld_fmt
156+
$(if $(filter $(CROSS_COMPILE),x86_64-linux-gnu),elf64-x86-64,\
157+
$(error Unsupported LLVM target $(CROSS_COMPILE)))
158+
endef
159+
160+
define do_autoconf_llvm
161+
$(eval LLVM_PREFIX := $(if $(filter %/,$(LLVM)),$(LLVM)))
162+
$(eval LLVM_SUFFIX := $(if $(filter -%,$(LLVM)),$(LLVM)))
163+
export CROSS_COMPILE := $(CROSS_COMPILE)
164+
export CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
165+
export LD := $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
166+
export AR := $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
167+
$(eval LD := $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX))
168+
$(eval CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX))
169+
$(eval LD_FMT := $(call llvm_target_to_ld_fmt))
170+
endef
171+
172+
define do_autoconf
173+
$(if $(LLVM),$(call do_autoconf_llvm),$(call do_autoconf_gnu))
153174
$(eval EXEC_FMT := $(shell echo $(LD_FMT) | cut -d "-" -f1))
154175
$(call set_kernel_config,OUTPUT_FORMAT,\"$(LD_FMT)\")
155176
$(if $(or $(filter $(EXEC_FMT),elf64),$(filter $(LD_FMT),pe-x86-64)),$(call 64bit_host))

0 commit comments

Comments
 (0)