Building the kernel with clang

2023-11-10

https://lwn.net/Articles/734071/

https://oschina.net/news/89194/linux-build-kernel-with-clang


Building the kernel with clang

By Jake Edge
September 19, 2017
Linux Plumbers Conference

Over the years, there has been a persistent effort to build the Linuxkernel using the Clang C compiler that is part of the LLVM project. Welast looked in on the effort in areport fromthe LLVM microconference at the 2015 Linux Plumbers Conference (LPC), but wehave followed itbefore that aswell. At this year's LPC, two Google kernel engineers, Greg Hackmann andNick Desaulniers, came to theAndroidmicroconference to update the status; at this point, it is possible tobuild two long-term support kernels (4.4 and 4.9) with Clang.

[Nick Desaulniers]

Desaulniers began the presentation by answering the most commonly askedquestion: why build the kernel with Clang? To start with, the Android userspace is all built with Clang these days, so Google would like to reducethe number of toolchains it needs to support. He acknowledged that it isreally only a benefit to Google and is "not super useful" elsewhere. Butthere are other reasons that are beneficial to the wider community.

There are some common bugs that often pop up in kernel code, especiallyout-of-tree code like the third-party drivers that end up in Androiddevices. The developers are interested in using the static analysisavailable in Clang to spotthose bugs, but the kernel needs to be built using Clang to do so. Thereare also a number of dynamic-analysis tools that can be used like thevarioussanitizers(e.g.AddressSanitizeror ASan) and their kernel equivalents (e.g. KernelAddressSanitizer orKASAN).

Clang provides a different set of warnings than GCC does; looking at thosewill result in higher quality code. It is clearly beneficial to all kernelusers to have fewer bugs in it. There are some additional tools that areplanned using Clang. One is a control-flow-analysis tool that couldenumerate valid stack frames at compile time; those could be checked atrun time to eliminatereturn-orientedprogramming (ROP) attacks. There is also work going on for link-timeoptimization (LTO) and profile-guided optimization (PGO) for Clang, which couldprovide better execution speed, especially for hot paths.

Building code with another compiler is a good way to shake out code thatrelies on undefined behaviors. Since the language specification does notdefine certain behaviors, compiler developers can choose whatever isconvenient. That choice could change, so even a GCC upgrade might causemisbehavior if some kernel code is relying on undefined behavior. Thehope, Desaulniers said, is that both the kernel and LLVM/Clang can improvetheir code bases from this effort. The kernel is a big project with a lotof code that can find bugs in the compiler; in fact, it already has.

Greg Kroah-Hartman said that "competition is good"; he was strongly infavor of the effort. Desaulniers was glad to hear that as he and otherswere worried that the tight coupling with GCC was being protected by thekernel developers. Kroah-Hartman said that there have been other compilersbuilding the kernel along the way. Behan Webster also pointed to all ofthe new features that have come about in GCC over the past five years as aresult of the competition with LLVM. Kroah-Hartman said that he wishedthere was a competitor to the Linux kernel.

[Greg Hackmann]

Hackmann related the state of the upstream kernel: "we are very close tohaving a kernel that can be built with Clang". It does require using a recent Clangthat has some fixes, but the x86_64 and ARM64 kernels can be built,though each architecture has one out-of-tree patch that needs to be appliedto do so. There is also one Android-specific Kbuild change that is needed,but only if the Android open-source project (AOSP) pre-built toolchain isbeing used.

As announced on thekernel mailing list, there are patches available for the 4.4 and 4.9kernels. There are also experimental branches of the Android kernelsfor 4.4 and 4.9 available from AOSP. More details can be found in the slides[PDF]. Those branches had just been pushed a few days earlier,Hackmann said, and theHiKey boards were ableto build and boot that code shortly thereafter.

There have been LLVM bugs found in the process, though most of them havebeen fixed at this point, Desaulniers said. The initial work was done with LLVM 4.0, butthey have since updated to 5.0 and are also building with the current LLVMdevelopment tree (which will become 6.0). You can probably build thekernel with 4.0, he said, but it will be much slower than building with 5.0or later.

There are still some outstanding issues. Variable-length arrays asnon-terminal fields in structures are not supported by Clang, there is aGNU C extension for inline functions that is not supported, and the LLVMassembler cannot be used to build the kernel. Hackmann noted that the GNU assembler istoo liberal in what it accepts.

This work has shown that the FUD surrounding using a new toolchain for thekernel is unfounded, Desaulniers said. It is working now, but there are afew asterisks. Clang, the front end, can compile the kernel, butthe assembler and the linker from GNU Binutils are needed to complete thebuild process.

Next up is figuring out how to do automated testing of LLVM and thekernel. Currently, the team is working with two specific LTS kernelbranches and using specific LLVM versions. So he can't quite say thatClang will build any kernel, since there are so many differentconfiguration options. A bot to check whether kernel patches will fail tobuild under Clang is in the works as well. An audience member noted thatkernelci.org is looking at adding othercompilers to its build-and-boot testing.

Hackmann and Desaulniers encouraged others to try building using Clang.All it takes is a simple "make CC=clang" on a properlyequipped system. We are, it seems, quite close to having a two-compilerworld for the Linux kernel.

[I would like to thank LWN's travel sponsor, The Linux Foundation, forassistance in traveling to Los Angeles for LPC.]



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Building the kernel with clang 的相关文章

  • linux强制卸载mysql报错

    error Failed dependencies mysql community client x86 64 gt 8 0 11 is needed by installed mysql community server 8 0 31 1

随机推荐

  • html在线校验器,HTML validate HTML验证

    HTML validate是指HTML验证 它是通过与标准HTML规则进行比较的方式 分析HTML文档 标记出错误和非标准代码的处理过程 Web页面使用HTML进行渲染 而HTML本身采用了HTML规范作为其规则和标准 通过验证HTML代码
  • 驱动开发 作业 day9 9/20

    基于platform实现 head h ifndef HEAD H define HEAD H 构建LED开关的功能码 不添加ioctl第三个参数 define LED ON IO l 1 define LED OFF IO l 0 end
  • 同时安装cuda8和cuda9

    转载自 https blog csdn net lovebyz article details 80704800 为了使用tensorflow目标检测API的所有算法 所以打算升级一下CUDA版本以支持tf gpu 1 5 但原本项目都是基
  • HTML5 canvas标签-1 基本使用

    终于有空使用csdn和大家分享点自己平时学习工作时候的心德啦 第一步 介绍下canvas的基本使用 首先 因为canvas是html5的一个标签 所以保险起见 可以先确认下canvas是否兼容 try document createElem
  • VISIO中的工具栏、菜单栏丢失的原因及解决办法

    症状 在 Microsoft Visio 中 您可能会遇到一个或多个以下症状 您所了解的工具栏是启用是不可见的 找不到菜单栏 按钮从工具栏中消失了
  • k8s搭建部署3个节点服务器

    目录 一 环境准备 二 安装kubeadm kubelet和kubectl 三 部署kubernetes Master 四 node节点加入集群 五 查看集群的状态 Init ImagePullBackOff错误 swap分区没有关闭 没有
  • 华为OD机试真题2023(JavaScript)

    华为机试题库已于5月10号由2022Q4 A卷 切换 为2023 B卷 B卷区地址 华为OD机试真题2023 B卷 JS 华为机试有三道题目 第一道和第二道属于简单或中等题 分值为100分 第三道为中等或困难题 分值为200分 总分为400
  • matlab 平方差,第七章 最小平方差的方法(The Method of Least Square ).doc

    第七章 最小平方差的方法 The Method of Least Square doc 第七章 最小平方差的方法 The Method of Least Square 本章說明利用最小平方差法 找出適合一組資料的曲線 在本章中包含Matla
  • T100客户端接口开发实例(T100对接销售易CRM)

    design bu leezec 296066606 应用实例 T100销售订单推送到CRM 需求分解 1 调用销售易接口校验取得token 2 取得token后按照要求推送数据 1 什么是token 首先 要调用CRM的实际应用场景 就绕
  • ISula 容器学习历程

    容器统一架构图 转自ISula容器引擎 openeuler org 1 下载安装 iSulad容器的下载安装只需要很简单的一条命令 yum install y iSulad 安装完成 2 容器配置 以配置nginx服务器为例 2 1 启动i
  • python 算法基础

    目录 基础算法 一元回归算法 多项式回归 预测 任意函数回归 分类算法 kNN k最邻近算法 聚类算法 k means DBSCAN 推荐算法 暂时不写 降维算法 数据预处理 主成分分析 PCA 因子分析 FactorAnalysis sk
  • 浅谈Web用户体验(一)

    最近一段时间在接触web用户体验 我认为 如果要鼓励用户去使用一个新的网站或软件 首先要做到的是 把用户需要完成的事的难度尽量降低 因为一般用户是没有耐性 有点懒的去做复杂的事的人 要解决这些问题 下面总结了一些方法 第一 尽量告诉用户需要
  • TightVNC H264编解码(二)之硬编码库的编译

    AVCodec codec avcodec find encoder by name nvenc h264 如果是默认的ffmpeg库 返回结果是NULL 看来是不带有硬编码功能的 重新编译分支ffnvcodec 不到半个小时编译完成 返回
  • Git 常用命令 --- git push命令

    git push的一般形式为 git push lt 远程主机名 gt lt 本地分支名 gt lt 远程分支名 gt 例如 git push origin master refs for master 即是将本地的master分支推送到远
  • golang配置国内镜像

    点击进入 golang中文网
  • elementUI图片遍历循环+预览【el-image查看大图+预览】

    我这边接受的数据结构 code 200 msg 图片列表 object id 1 partsName picturesName a jpg picturesUrl http 192 168 3 65 8111 image a jpg typ
  • POI向Excel中插入图片

    package com xiangyu bigdata xycom execl import java awt image BufferedImage import java io ByteArrayOutputStream import
  • flask-sqlalchemy 解决 with_for_update() 行锁不生效、数据滞后问题

    解决方案 我先把解决方案放在前面 后面慢慢阐明拖了我三天的研究过程和原因 若出现带锁的查询修改前 先行commit一次 model db session commit 先行commit一次 user models User query wi
  • Python-字符串str和json格式的转换

    我是精神抖擞王大鹏 不卑不亢 和蔼可亲 计算机硕士 目前小米大数据开发 日常会分享总结一些自己面试实际问题的回答 欢迎一起讨论 公众号 diting dapeng str转json str转换为json格式 前提一定需要保证这个str的格式
  • Building the kernel with clang

    https lwn net Articles 734071 https oschina net news 89194 linux build kernel with clang Building the kernel with clang