-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Meta] Compiling the Linux kernel with clang #4440
Comments
assigned to @nickdesaulniers |
Some other notes on what I had to do to build the kernel with llvm-gcc:
|
[patch needed for llvm-gcc and clang to workaround lack of support for -fno-strict-overflowhttps://user-images.githubusercontent.com/92601246/143739225-38459eaf-8511-4be3-a29e-7bdf58e510a5.gz) |
For reference I attached the 2 original patches I used when building the kernel with llvm-gcc: http://llvm.org/bugs/attachment.cgi?id=2896 http://llvm.org/bugs/attachment.cgi?id=2897 They may be useful when building with clang too. |
.config that builds $ clang -v Workaround for clang bugs applied:
} /* extern void tty_driver_kref_put(struct tty_driver *driver); |
An update: If boot is compiled with llvm, then kernel doesn't boot at all, and if vdso is compiled with llvm there's a message during the boot that What I used: llvm-gcc compiled Linux boots, clang compiled Linux only boots up to the point it launches init. After that it shows the login prompt, but its broken, won't let me login, and also init didn't start any of the other boot scripts (like the script that launches udev). Boot messages diff is attached. |
llvm-gcc needs these patches to Linux kernel: clang needs these patches to Linux kernel: boot is not built correctly by llvm because it relies on .code16gcc. I haven't investigated why vdso is not built properly. |
I have successfully built a Linux 2.6.36 kernel with clang. It can self host itself, boot to runlevel 5 successfully, SMP works, X works, networking works, etc (posting this message from a machine running a self-hosted linux kernel built with clang :)). There's still a lot that's buggy, but clang can definitely compile Linux! |
I'll post to the ML with more details and stats. In the morning I should have a chance to put together the patches and instructions for how to do this. |
As far as I know, all functionality blocking bugs are fixed for building the linux kernel. The one thing that is missing is a warning (-Wframe-larger-than=2048), which is tracked by llvm/llvm-bugzilla-archive#4072 (see the PR for the menuconfig option to disable the warning). Edwin (or anyone else interested!), it would be great to see if you could build the kernel and if you run into any other issues. Since this bug was filed, we switched to the integrated assembler, so I wouldn't be too shocked if there were other minor things, but they should be easy to fix. The LLVM 2.9 release branches on March 6th, it would be great to be able to say that it can build a good kernel, as it would be great to get more of the linux kernel development community off of GCC :-) |
Hey Chris! I've been using a Clang compiled Linux kernel on my Macbook 5.1 since late I believe there were some news posts and a list post that I myself made when I I, admittedly, have been neglectful in getting my patches into Clang, and I I do not feel that I have the experience or discipline to take a central role My email is admin-at-thefireflyproject.us or blelbach-at-cct.lsu.edu. |
Hi Chris, I think these are the most important clang bugs: It is debatable whether the other bugs I opened are bugs in Linux kernel or Clang, depending if you consider that the C standard allows you to break the code, or if you want a useful C language where you at least warn that you'll break the code, and preferably don't break it if you can. There are also some bugs in clang's warnings, but I didn't mark those as blocking this bug. They are way too noisy, I had to use this: And we should do something about #9254, since now it also prevents iptables from being compiled (it only used to be crypto). Which probably means someone will have to patch the kernel if clang will not implement this: |
hi, is there a git branch of linux somewhere that include the patchs for compiling the kernel with clang ? |
I have my patches attached to various bugreports, I can cleanup my local branch |
I am trying to compile an unmodified linux kernel source tree with the latest svn clang, and I get a bunch of the error below, on top of a fair number of warnings. Is there some patch to the kernel that I should be applying before attempting this build? This is just a wild guess, but is the problem with the assembly below that it's using %eax for a byte-level instruction? Should it be 'movl' rather than 'movb'? init/main.c:511:12: error: invalid operand for instruction define smp_processor_id() raw_smp_processor_id()
In file included from init/main.c:13: define smp_processor_id() raw_smp_processor_id()
In file included from init/main.c:13: |
Looks like a kernel bug, "movb %gs:cpu_number,%eax" is invalid because you can't "movb" into a 32-bit register. |
It's a bit more complicated than that; see bug 9322. |
4898 is an optimization hint, it doesn't block this. |
Some of us have gotten together and started working on this collaboratively, https://github.com/lll-project. |
We have a project called LLVMLinux which brings together all the various efforts around compiling the Linux kernel with Clang. Our project has also recently merged with the lll-project team. Our intentions are to submit patches to Clang/LLVM project as well as the Linux kernel in order to make it possible to fully compile the Linux kernel with Clang. You can learn more at our website: http://llvm.linuxfoundation.org/ |
Added 15676, a new bug which is a segfault when cross-compiling the linux Kernel for ARM. |
This is about my successful experience in bringing up Ubuntu 17.10 x86_64 on the clang-built Linux 4.15.7 kernel(latest stable as of now) and clang-built proprietary Nvidia 390.25(latest as of now) driver for my Nvidia GTX GeForce 860M graphics card. I wanted to share the same here for any similarly interested people out here and also as an update for the progress of clang/Linux kernel compatibility as I have used, researched and observed. I have shared a complete report on this in the below places -- "Success : Ubuntu 17.10 x86_64 on LLVM/clang-built kernel with Nvidia 390.25 driver" :
Cheers. |
Hello, This is about successful experience of bringing-up Android ARM(32-bit) LLVM/clang-built Linux kernel on Nexus 5(hammerhead) Android Smartphone. In this effort of mine, I have successfully brought up the Android ARM(32-bit) kernel built with 4 different LLVM/clang toolchains/versions :
Complete reports on this research project of mine can be found here : "Success: Bring-up of LLVM/clang-built Linux ARM(32-bit) kernel for Android - Nexus 5" - https://ubuntuforums.org/showthread.php?t=2394035 Cheers. |
Hello, This is an update to my above initial report of x86_64 LLVM/clang-built kernel for my system hardware running Ubuntu 17.10 x86_64. After having used the latest LLVM/clang versions for my above Android ARM(32-bit) Linux kernel, I was interested in trying out the same for my system hardware running Ubuntu 17.10 x86_64. So, I tried using clang-6.0 as well as the clang-7.0(developmental version/built from LLVM source - same as the one used for my recent above reported Android ARM(32-bit) Linux kernel's case) in separate attempts. With additional effort, I was able to bring-up Ubuntu 17.10 x86_64 on my system hardware with both of these kernels individually, along with other kernel driver modules including that of NVIDIA, VirtualBox, VMware Player, etc with all of them fully working on my system hardware - for the hypervisors(their kernel modules, to be precise) with all the so far clang-built host kernels, verified using a fully working Ubuntu 17.10 x86_64 guest - for the NVIDIA case, have verified the availability of graphics hardware acceleration, Ubuntu's system/GUI stability, etc in all of the clang-built kernel cases - so far there have been no issues. Details of this above update(using clang-6.0 and clang-7.0 for building and bringing-up the kernel) can be found in my original post towards the end of it here : Here are the mappings of the updates in the above thread, onto the kernel versions, all for Ubuntu 17.10 x86_64 on my system hardware :
As a relevant update, in addition to VirtualBox(Version 5.2.8 r120774) kernel modules using LLVM/clang, I have been successful As another relevant update, in addition to building VMware Player(14.1.2 build-8497320) kernel modules using LLVM/clang, I have been able to successfully bring-up Cheers. |
Hello, This is an update to my above successful bringing-up LLVM/clang-built ARM(32-bit) Android Linux kernel for different Android(Marshmallow to Nougat to Oreo) on Nexus 5 Android Smartphone. As of now, a total of 10 Android custom ROMS including AOSP(latest factory image) have been successfully brought-up with their respective kernel sources built using LLVM/clang. This includes 9 more(AOSP + 8 other popular Android custom ROMs) along with the initial Resurrection Remix Android custom ROM. Below is the complete list of these 10 Android ROMs including AOSP.
Here's my final and complete report on this research of mine here : and https://victorymindtalk.blogspot.com/2018/08/success-bring-up-of-llvmclang-built.html Cheers. |
…-lazy [lldb] Add the SwiftEnableBareSlashRegexOnPlayground setting
Extended Description
This is a meta-bug, other bugs that prevent building the Linux kernel with clang will be made to depend on it.
We should keep this bug open, until someone boots a kernel built with clang :)
The text was updated successfully, but these errors were encountered: