Linux: Sources, patches, step-by-step ?

Created on 21 Nov 2018  路  7Comments  路  Source: ClangBuiltLinux/linux

Hi, is there any step-by-step how-to compile it ?
I assyme that this linux github repo does carry all you patches that enables LLVM/clang compiler and does compile with it ?

I'm asking as OpenMandriva contributor, where we are using since 2014 LLVM/Clang as our default compiler. Almost all of our rpm packages are compiled with LLVM/clang and ofcourse Linux kernel is one of couple that is still compiled with gcc. Do you have any patches for binutils, elfutils, glibc to enable LLVM/clang for them?

question

Most helpful comment

@tpgxyz Hi! As @dileks mentioned, there are a few variables with regards to compiling the Linux kernel with Clang.

It's kind of hard to pin down the lowest supported version of Clang given that a lot of bugs have been fixed over time; if you can use at least Clang 7, that will give you a huge leg up.

We are testing support for compiling 4.4, 4.9, 4.14, 4.19, 4.20-rc, and linux-next in our continuous integration repo, on arm, arm64, x86_64, and powerpc. 4.4 and 4.9 support should be added upstream shortly; for now, we are just applying the patches before building. Only x86_64 on 4.17 and higher requires one out of tree patch, just to work around an upstream decision to force asm-goto. That support is being added to Clang, it will just take some time. powerpc requires a few patches that have been accepted upstream; once those land, we should be able to have them send to stable (I can provide them if needed ahead of time).

Our driver script and our wiki page should show you how to build the kernel with Clang and we have started providing a Docker image to give people a consistent starting environment for doing that (plus it doesn't mess with their current setup). See that repo's README for more info.

If you run into any issues, feel free to reply to this issue or file another one. The more coverage and people we get involved, the better!

All 7 comments

You missed some fundamental informations as I don#T know OpenMandriva.

Which Linux kernel release?
Which version of LLVM/Clang?
What arch?

I can speak for testing Linux/x86-64 and Linux v4.19.y with clang-7 on Debian/testing AMD64.

You need two patches (see [1]).

Some kernel configs are not supported or known to be "BROKEN" with LLVM/Clang.
I am using Debian's kernel-config as a base and have additionally:

CONFIG_HARDENED_USERCOPY=n
CONFIG_DRM_AMDGPU=n

For building I use the builddeb script shipped with the Linux kernel sources.

[1] https://github.com/ClangBuiltLinux/continuous-integration/tree/master/patches/4.19/x86_64

@tpgxyz Hi! As @dileks mentioned, there are a few variables with regards to compiling the Linux kernel with Clang.

It's kind of hard to pin down the lowest supported version of Clang given that a lot of bugs have been fixed over time; if you can use at least Clang 7, that will give you a huge leg up.

We are testing support for compiling 4.4, 4.9, 4.14, 4.19, 4.20-rc, and linux-next in our continuous integration repo, on arm, arm64, x86_64, and powerpc. 4.4 and 4.9 support should be added upstream shortly; for now, we are just applying the patches before building. Only x86_64 on 4.17 and higher requires one out of tree patch, just to work around an upstream decision to force asm-goto. That support is being added to Clang, it will just take some time. powerpc requires a few patches that have been accepted upstream; once those land, we should be able to have them send to stable (I can provide them if needed ahead of time).

Our driver script and our wiki page should show you how to build the kernel with Clang and we have started providing a Docker image to give people a consistent starting environment for doing that (plus it doesn't mess with their current setup). See that repo's README for more info.

If you run into any issues, feel free to reply to this issue or file another one. The more coverage and people we get involved, the better!

@dileks @nathanchance we are using LLVM/clang-7.0 as I pointed to our GitHub sources.
We also have an build farm https://abf.openmandriva.org/ for building rpms and isos. Currently we are supporting i686, x86_64, znver1, aarch64 and armv7hnl architectures with kernel 4.19.x

I'll get back to you when I'll finish reading what you gave me in previous message.

There's one problem -- asm goto support (mandatory for x86_64) isn't in clang 7.0 yet.
The other arches should be ok, for x86_64/znver1 we'll need to backport asm-goto support from clang master.

I don't presume anyone has a backport patch for that floating around already?

asm goto is not implemented in Clang yet. Prototype patches exist, but it has not yet landed.

The patch is only for LLVM, not Clang. Though it should be relatively easy to add support to Clang once LLVM patch is accepted.

Thanks for the interest. Please let me know if there's information missing from our Wiki that you would find helpful. Closing for now.
https://github.com/ClangBuiltLinux/linux/wiki

Was this page helpful?
0 / 5 - 0 ratings