LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


View Poll Results: Have you successfully built the kernel with LLVM/Clang?
Yes 1 33.33%
No 2 66.67%
Other (please explain in post) 0 0%
Voters: 3. You may not vote on this poll

Reply
  Search this Thread
Old 12-17-2020, 11:21 AM   #1
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Has anyone been able to actually build the Linux kernel with LLVM/Clang?


Because I've tried and failed several times now, with the same errors too, no matter what I try to do. And yes I've looked at the kernel docs at kernel.org and tried what it said, along with a few other things as well.

To be clear, I'm not really asking for help at this point (although if anyone here has done it successfully, feel free to share exactly how you done it by all means). This is really just a poll to see how many members here might have done it successfully - as in you built it with LLVM/Clang and it boots.
 
Old 12-17-2020, 12:57 PM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,706
Blog Entries: 19

Rep: Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506
You're not the only one who's had trouble. There's an interesting article here which describes some of the problems. They seem to be recommending a two-step process: compile to assembler with clang, then assemble and link with binutils. The LLVM assembler won't do, apparently.

PS: This is also interesting. It follows on from an attempt to build LFS with clang and lists the packages that won't build. The kernel is one of them.

Last edited by hazel; 12-17-2020 at 01:20 PM. Reason: Added postscript
 
1 members found this post helpful.
Old 12-17-2020, 07:34 PM   #3
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks Hazel.

It's strange because it does seem to compile the object code for both the modules and the kernel's executable, but seems to fail when trying to link it. If I change the kernel config to the frame pointer unwinder, it does seem to get further, but still ultimately fails.

I haven't tried the guess unwinder though, but suspect that will probably fail too.

Although, I know it can be done, as I've seen reports that others have managed to build the kernel with LLVM/Clang and the distro developers for my distro have built it's kernel with LLVM/Clang.
 
Old 12-17-2020, 09:54 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,347

Rep: Reputation: Disabled
According to a recent post on the LKML titled "New objtool warning..", Linus Torvalds himself runs a kernel built using clang:
Quote:
I only see this on my laptop, but that's probably because my desktop is built using clang. So it's a gcc code generation interaction, I suspect..
 
Old 12-18-2020, 04:11 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,706
Blog Entries: 19

Rep: Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506Reputation: 4506
Suppose you build it with clang but link it with ld from binutils. Does that work?
 
1 members found this post helpful.
Old 12-19-2020, 09:09 AM   #6
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by hazel View Post
Suppose you build it with clang but link it with ld from binutils. Does that work?
After hours of compiling and failing and then trying again, it looks like I just might have done it. Well put it this way: make hasn't given me any error message after it finished.

So if this,

Code:
BUILD   arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready  (#1)
is a good sign, then I think I've done it.

So yes, it seems you are correct that you need to use GNU ld linker to link it.

PS: sorry for the late reply, as I was going to reply earlier, but it was taking forever to compile it.
 
Old 12-21-2020, 01:26 AM   #7
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thumbs up

So I managed to compile and build kernel 5.10.1 and it works!

Although since I used make defconfig to create the kernel config the first time I got it to actually build, it only built about maybe 5 or 6 kernel modules - which was nowhere near enough to even just boot the system. So I had to copy the config from kernel 5.9.14 over and answer a few questions, although thankfully it was only a few since there wasn't a hell of a lot of new config options. But since for whatever reason the build didn't build an initrd, and I forgot to update the one I built before having to rebuild the kernel to include the rest of the modules it didn't build the first time, my system didn't boot. But after updating initrd, I got it to fully boot the system. But for whatever reason X died because there was no dbus socket for it to connect to;

Code:
[   221.377] (EE) dbus-core: error connecting to system bus: org.freedesktop.DBus.Error.FileNotFound (Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory)
I checked and that socket wasn't there when I booted kernel 5.10.1 that I built myself ...but I don't have any problems if I boot the kernel from OpenMandriva's kernel package though...

Whata gip!

In any case, the trick is to use GNU's linker with the BFD libraries, and not LLVM's linker. I knew it was possible to build the kernel with LLVM/Clang!
 
  


Reply

Tags
clang, development, kernel, llvm



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LLVM 9.0.0 Clang segfault Firefox build TheRealGrogan Slackware 6 04-06-2020 01:11 PM
LXer: Students Can Help Improve LLVM & Clang, Make The Kernel Build LXer Syndicated Linux News 0 03-05-2014 12:50 AM
LXer: LLVM Clang 3.3, Early Clang 3.4 Benchmarks LXer Syndicated Linux News 0 06-23-2013 10:00 PM
LXer: Debian Is Still Being Made To Build With LLVM/Clang LXer Syndicated Linux News 0 02-10-2013 01:50 PM
LXer: LLVM/Clang Can Build LibreOffice LXer Syndicated Linux News 0 10-22-2011 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration