Skip to content

Commit

Permalink
[ALPS05556626] kernel: introduce LLVM=1 and gas toolchain to kenv.mk
Browse files Browse the repository at this point in the history
Linux can now be built with LLVM=1, all necessary llvm params
such as CC, LD, OBJCOPY, and NM will be set correctly.

Introduce LLVM=1 to kenv.mk and drop legacy approach.
To make it work, we have to also change build.config.mtk* files.

With commit commit 2c71673913c12528c77bd0f75ce2c6adc9ac5059
("Revert "ANDROID: Kbuild, LLVMLinux: allow overriding clang target triple""),
we must not use "CLANG_TRIPLE" in build commands, otherwise well
have boot failures.

MTK-Commit-Id: 52ced0a041efb0231efb134de7f821b3f678ced8

Change-Id: I76f2ec556e14d8ed28a89bc13e3b551fda625037
CR-Id: ALPS05556626
Feature: [Module]Kernel Maintenance
Signed-off-by: Miles Chen <[email protected]>
  • Loading branch information
milesdotchen committed Mar 5, 2021
1 parent e9bb9b1 commit 890057d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 57 deletions.
20 changes: 13 additions & 7 deletions build.config.mtk.aarch64
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
ARCH=arm64
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=aarch64-linux-androidkernel-
CC=clang
LD=ld.lld
CROSS_COMPILE=aarch64-linux-gnu-
LLVM=1
LLVM_IAS=1
LD_LIBRARY_PATH=prebuilts/clang/host/linux-x86/clang-r383902/lib64:$$LD_LIBRARY_PATH
NM=llvm-nm
OBJCOPY=llvm-objcopy
# DEFCONFIG=defconfig
KERNEL_DIR=kernel-4.19
CLANG_PREBUILT_BIN=prebuilts/clang/host/linux-x86/clang-r383902/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
# for check scripts
CC=clang
LD=ld.lld
AR=llvm-ar
NM=llvm-nm
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
READELF=llvm-readelf
OBJSIZE=llvm-size
STRIP=llvm-strip
20 changes: 13 additions & 7 deletions build.config.mtk.aarch64.kasan
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
ARCH=arm64
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=aarch64-linux-androidkernel-
CC=clang
LD=ld.lld
CROSS_COMPILE=aarch64-linux-gnu-
LLVM=1
LLVM_IAS=1
LD_LIBRARY_PATH=prebuilts/clang/host/linux-x86/clang-r383902/lib64:$$LD_LIBRARY_PATH
NM=llvm-nm
OBJCOPY=llvm-objcopy
# DEFCONFIG=defconfig
KERNEL_DIR=kernel-4.19
CLANG_PREBUILT_BIN=prebuilts/clang/host/linux-x86/clang-r383902/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
# for check scripts
CC=clang
LD=ld.lld
AR=llvm-ar
NM=llvm-nm
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
READELF=llvm-readelf
OBJSIZE=llvm-size
STRIP=llvm-strip
20 changes: 13 additions & 7 deletions build.config.mtk.aarch64.ubsan
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
ARCH=arm64
CLANG_TRIPLE=aarch64-linux-gnu-
CROSS_COMPILE=aarch64-linux-androidkernel-
CC=clang
LD=ld.lld
CROSS_COMPILE=aarch64-linux-gnu-
LLVM=1
LLVM_IAS=1
LD_LIBRARY_PATH=prebuilts/clang/host/linux-x86/clang-r383902/lib64:$$LD_LIBRARY_PATH
NM=llvm-nm
OBJCOPY=llvm-objcopy
# DEFCONFIG=defconfig
KERNEL_DIR=kernel-4.19
CLANG_PREBUILT_BIN=prebuilts/clang/host/linux-x86/clang-r383902/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
# for check scripts
CC=clang
LD=ld.lld
AR=llvm-ar
NM=llvm-nm
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
READELF=llvm-readelf
OBJSIZE=llvm-size
STRIP=llvm-strip
20 changes: 15 additions & 5 deletions build.config.mtk.arm
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
ARCH=arm
CLANG_TRIPLE=arm-linux-gnueabi-
CROSS_COMPILE=arm-linux-androidkernel-
CC=clang
LD=ld.lld

CROSS_COMPILE=arm-linux-gnueabi-
LLVM=1

# DEFCONFIG=defconfig
KERNEL_DIR=kernel-4.19
CLANG_PREBUILT_BIN=prebuilts/clang/host/linux-x86/clang-r383902/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gas/linux-x86
# for check scripts
CC=clang
LD=ld.lld
AR=llvm-ar
NM=llvm-nm
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
READELF=llvm-readelf
OBJSIZE=llvm-size
STRIP=llvm-strip
61 changes: 30 additions & 31 deletions kenv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,37 @@ ifneq ($(strip $(TARGET_NO_KERNEL)),true)
endif

ARGS := CROSS_COMPILE=$(CROSS_COMPILE)
ifneq ($(CLANG_TRIPLE),)
ARGS += CLANG_TRIPLE=$(CLANG_TRIPLE)
endif
ifneq ($(LD),)
ARGS += LD=$(LD)
endif
ifneq ($(LD_LIBRARY_PATH),)
ARGS += LD_LIBRARY_PATH=$(KERNEL_ROOT_DIR)/$(LD_LIBRARY_PATH)
endif
ifneq ($(NM),)
ARGS += NM=$(NM)
endif
ifneq ($(OBJCOPY),)
ARGS += OBJCOPY=$(OBJCOPY)
endif
ifeq ("$(CC)", "gcc")
CC :=
endif

ifneq ($(filter-out false,$(USE_CCACHE)),)
CCACHE_EXEC ?= /usr/bin/ccache
CCACHE_EXEC := $(abspath $(wildcard $(CCACHE_EXEC)))
else
CCACHE_EXEC :=
endif
ifneq ($(CCACHE_EXEC),)
ifneq ($(CC),)
ARGS += CCACHE_CPP2=yes CC='$(CCACHE_EXEC) $(CC)'
ifneq ($(LLVM),)
ARGS += LLVM=1
ifneq ($(filter-out false,$(USE_CCACHE)),)
CCACHE_EXEC ?= /usr/bin/ccache
CCACHE_EXEC := $(abspath $(wildcard $(CCACHE_EXEC)))
else
CCACHE_EXEC :=
endif
else
ifneq ($(CC),)
ARGS += CC=$(CC)
ifneq ($(CCACHE_EXEC),)
ARGS += CCACHE_CPP2=yes CC='$(CCACHE_EXEC) clang'
else
ARGS += CC=clang
endif
ifneq ($(LLVM_IAS),)
ARGS += LLVM_IAS=$(LLVM_IAS)
endif
ifeq ($(HOSTCC),)
ifneq ($(CC),)
ARGS += HOSTCC=$(CC)
endif
else
ARGS += HOSTCC=$(HOSTCC)
endif
ifneq ($(LD),)
ARGS += LD=$(LD) HOSTLD=$(LD)
ifneq ($(suffix $(LD)),)
ARGS += HOSTLDFLAGS=-fuse-ld=$(subst .,,$(suffix $(LD)))
endif
endif
ifneq ($(LD_LIBRARY_PATH),)
ARGS += LD_LIBRARY_PATH=$(KERNEL_ROOT_DIR)/$(LD_LIBRARY_PATH)
endif
endif

Expand Down

0 comments on commit 890057d

Please sign in to comment.