diff options
author | SquallATF <squallatf@gmail.com> | 2022-05-26 20:33:16 +0800 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2022-07-05 09:26:54 -0400 |
commit | 2404761083de5644dccd064dc4d08b0a331a185f (patch) | |
tree | e0b3626fd085170e1defd824d5f3ebc90f2bbb88 | |
parent | 8995a0d05fc6ac0afba71d484f0efb71639d9843 (diff) | |
download | meta-clang-2404761083de5644dccd064dc4d08b0a331a185f.tar.gz |
Add instructions for kernel build with clang
-rw-r--r-- | README.md | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -100,6 +100,46 @@ in `local.conf` | |||
100 | CLANGSDK = "1" | 100 | CLANGSDK = "1" |
101 | ``` | 101 | ``` |
102 | 102 | ||
103 | # Kernel build with clang | ||
104 | Newer kernels and Android kernels support clang compilation, and even support LTO, The following takes [rockchip](https://github.com/JeffyCN/meta-rockchip)'s kernel as an example to configure clang compilation. x86, arm and arm64 kernel supported full LLVM toolchain, other arch only support clang. more info https://docs.kernel.org/kbuild/llvm.html | ||
105 | |||
106 | - linux-rockchip_%bbappend | ||
107 | ```shell | ||
108 | TOOLCHAIN:forcevariable = "clang" | ||
109 | |||
110 | DEPENDS:append:toolchain-clang = " clang-cross-${TARGET_ARCH}" | ||
111 | KERNEL_CC:toolchain-clang = "${CCACHE}clang ${HOST_CC_KERNEL_ARCH} -fuse-ld=lld ${DEBUG_PREFIX_MAP} -fdebug-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH}" | ||
112 | KERNEL_LD:toolchain-clang = "${CCACHE}ld.lld" | ||
113 | KERNEL_AR:toolchain-clang = "${CCACHE}llvm-ar" | ||
114 | ``` | ||
115 | if you want use LLVM integrated assembler for some older kernel, newer vesion is enabled default. | ||
116 | ```shell | ||
117 | do_compile:prepend:toolchain-clang() { | ||
118 | export LLVM_IAS=1 | ||
119 | } | ||
120 | |||
121 | do_compile_kernelmodules:prepend:toolchain-clang() { | ||
122 | export LLVM_IAS=1 | ||
123 | } | ||
124 | ``` | ||
125 | if you want enable LTO, append follow content. | ||
126 | ``` | ||
127 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" | ||
128 | SRC_URI:append:toolchain-clang = "\ | ||
129 | file://lto.cfg \ | ||
130 | " | ||
131 | ``` | ||
132 | |||
133 | `CONFIG_LTO_CLANG`is need for some android based kernel, mainline kernel will do auto detect. | ||
134 | |||
135 | - lto.cfg | ||
136 | ``` | ||
137 | CONFIG_LTO_CLANG=y | ||
138 | CONFIG_LTO=y | ||
139 | CONFIG_LTO_CLANG_THIN=y | ||
140 | ``` | ||
141 | |||
142 | |||
103 | # Building | 143 | # Building |
104 | 144 | ||
105 | Below we build for qemuarm machine as an example | 145 | Below we build for qemuarm machine as an example |