|
|
Subscribe / Log in / New account

Clang builds a working 2.6.36 Kernel

From:  Bryce Lelbach <admin-3q1HvbVIrc72AbsnzC34Jknl3mk2Ux8O-AT-public.gmane.org>
To:  cfe-dev-Tmj1lob9twqVc3sceRu5cw-AT-public.gmane.org
Subject:  Clang builds a working Linux Kernel (Boots to RL5 with SMP, networking and X, self hosts)
Date:  Mon, 25 Oct 2010 02:28:50 -0400
Message-ID:  <20101025022850.0f08836a@Pegasus>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Clang can now compile a functional Linux Kernel (version 2.6.36, SMP).

General Details
===============

  * Development and testing environment is a Macbook 5.1 (Intel C2D, x86_64)
    running Debian GNU/Linux.

  * The kernel can successfully boot to runlevel 5 (aka X + networking) on the
    Macbook, both on bare metal and in Qemu.

  * The kernel can successfully boot to runlevel 3 on a secondary test machine,
    a microATX desktop box (Intel Atom). I haven't tried to start X on this box
    yet.

  * The kernel can self-host; I am currently running a "fourth generation" self-
    hosted Linux kernel built by a "fourth generation" Clang.

Major Subsystems Successfully Built
===================================

  I have likely left out a few things here.

  * Core kernel stuff, Filesystems, Bus, PCI jazz, ACPI - No problems here that
    I've run into. I'm sure there are issues under the hood here, just haven't
    gotten to stress testing these yet.

  * SMP, SMT, SysV, pthreads, and POSIX IPC - I have tested these fairly
    extensively, (using the tiobench and rt-tests Debian packages, as well as
    the proposed Boost.Process library and the Boost.Thread). Multithreading and
    Multiprocessing in the compiled kernel seems to be functioning fine, but
    multitasking has a couple of intermittent issues when used in user space
    code (see below). The kernel -IS- doing a concurrent boot in runlevel 2,
    though. 

  * NUMA, swap, mm, slab allocator - Memory seems to be fine. I've compiled both
    LLVM + Clang and Linux multiple times on the clang built kernel, and I threw
    some "eat your memoryez" programs from the Debian repositories at it;
    doesn't look like there's trouble here.

  * Network stack (IPv4) - The IPv4 stack is fine, except for IPSec (see the
    notes on crypto support below). Netfilter and IPv6 both (separately) caused
    ICEs when I initially tried to build the network stack. I think I fixed
    this issue elsewhere (getting harddrive drivers to compile), so this may
    not be in bad shape at all (harddrive issue was an ICE caused by some
    seemingly legal conditional operators semantics in the kernel. The problem
    is specifically in CodeGen, which is the part of the clang that I've hacked
    the most, so it's likely this is a bug I introduced on my local fork).

  * Drivers and Firmware Stuff - Drivers have all been relatively well behaved
    thus far. However, I've had to be very picky, as any driver that depends on
    crypto stuff (even the basic kernel crc routines) breaks things. Mostly,
    I've just compiled what my laptop has needed and the generic drivers needed
    for my microATX desktop box/running the kernel in Qemu. I have added some
    of less obscure drivers to the build configuration, though. Here's a short
    list of things that work on my laptop (all the open source drivers are
    clang-compiled):

      * Graphics and sound. I installed Flash and listened to some BoostCon
        videos from last year to confirm this.
      * Keyboard. No backlight, though, but I never had that working in the
        first place.
      * DVD/CDROM.
      * Touchpad.
      * Various USB stuff.
      * iSight.
      * Speaker
 
Non-Essential Subsystems Failing at Compile Time
================================================

  Again, I'm possibly forgetting things here. I should also note that it's very
  possible that my hacks to either clang, Linux or the Linux build setup caused
  this.

  * SELinux, Posix ACLs, IPSec, eCrypt, anything that uses the crypto API - None
    of these will compile, due to either an ICE or variable-length arrays in
    structures (don't remember which, it's in my notes somewhere). If it's
    variable-length arrays or another intentionally unsupported GNUtension, I'm
    hoping it's just used in some isolated implementation detail (or details),
    and not a fundamental part of the crypto API (honestly just haven't had a
    chance to dive into the crypto source yet). I'm really hoping it's an issue
    in Clang, though, as it's easier for me to hack Clang and I'm trying to
    avoid kernel patches as much as possible.

  * IPv6 and Netfilters/Router stuff - Some of this is tied to the above issues
    with the crypto API, but IPv6 and Netfilters each have their own fatal
    errors. 
  * Virtualization - Virtualization is the only thing I haven't done any work on
    yet. I tried compiling minimal Xen support, ran into a fatal error, and put
    it on my "Get the basics functional first". 

Fatal Subsystem Failures Temporarily Averted by Compiling with GCC
==================================================================

  These two issues were already known when I started working on this, and
  conveniently, people had patched the Linux build system to build these systems
  with GCC, but were still unable to build a usable kernel. As I'm lazy, I took
  this work and reused it.

  * VDSO - VDSO breaks in strange ways with clang, at least, it did a week ago
    when I put some time into investigating this. ATM, building VDSO with GCC
    works, but I believe that this is still causing issues. I think the issue
    here is similiar in nature to the issue with LKMs. 

  * Boot - The very early kernel boot code breaks with clang, because of obscure
    inline assembly GNUtensions (.code16gcc stuff). I have no clue what needs to
    be done to fix this, but as I actually know where this problem is, it should
    be (relatively) easy to fix.

Crippling Problems
==================

  * Modules - Module loading is totally broken. I'm pretty sure I just figured
    out why, though (I'd elaborate, but this is pretty lengthy, and I might as
    well just go implement it).

Brief closing notes - I'm adapting a slightly aged POSIX test suite developed by
some Intel hackers for use in stress testing/functionality testing/unit testing
clang compiled kernels. This is something of a side project for me (I have school
and what not), but my intention is to maintain a Linux git repo with the source
patches/build set up needed to compile with a matching Clang git repo. Hopefully
in a few weeks/couple of months, with intensive automated testing and fixes to
the above issues, Clang + Linux will be feasible for producing production quality
Linux kernels.

I'm going to try to clean up some of my modifications to Clang (mostly hacks in
CodeGen stuff, local labels (not 100% done yet), explicit register variables, 
a more complete implementation of GNU inline assembly constraints). Some of my
changes implement the sort of cryptic GNUtensions that I sense most Clang devs
would find distasteful (I haven't added support for anything explicitly stated
as unsupported on the clang website).

P.S. boot logs:

http://gist.github.com/644488
http://gist.github.com/644490

I saved build times somewhere. Depending on how the configuration is tweaked/the
SMP support of the kernel that I'm building on top of, Clang builds Linux in about
13-15 minutes. 

Back to hacking :)

- -- 
Bryce Lelbach aka wash
http://groups.google.com/group/ariel_devel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkzFI6IACgkQO/fqqIuE2t7RRQCaAzpFjAC7T9qTHunR69NNZzfk
Sj8AnR28NvtaRQv0fqM8S8gA+1UieqLj
=3ZwN
-----END PGP SIGNATURE-----



to post comments

What is ICE?

Posted Oct 25, 2010 23:22 UTC (Mon) by gjmarter (guest, #5777) [Link] (1 responses)

I am unable to find what ICE means in this context. Can anyone decode that? Thanks.

What is ICE?

Posted Oct 25, 2010 23:29 UTC (Mon) by BenHutchings (subscriber, #37955) [Link]

Internal compiler error.

Clang builds a working 2.6.36 Kernel

Posted Oct 25, 2010 23:32 UTC (Mon) by BenHutchings (subscriber, #37955) [Link] (10 responses)

The references to runlevels are a bit strange, as they are not defined by the kernel and the Debian system doesn't distinguish runlevels 2-5 either (it's left to the administrator).

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 0:35 UTC (Tue) by rgmoore (✭ supporter ✭, #75) [Link] (9 responses)

I'm pretty sure that the reference to runlevels is a shorthand for how much he's gotten to work. So the runlevel 3 on his Atom machine means he has tested networking but not X11, while runlevel 5 on the Macbook means he can run X11.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 0:54 UTC (Tue) by xorbe (guest, #3165) [Link]

I was about to say the same thing.

1: single user
3: multi-user
5: mu + X

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 8:09 UTC (Tue) by wash (guest, #70825) [Link] (7 responses)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 12:50 UTC (Tue) by sorpigal (guest, #36106) [Link] (6 responses)

Despite the fact that many people list runlevels with these meanings, in Linux it's just a convention used by some people and not intrinsic or a commonly accepted rule. I boot to runlevel 2 always, because higher numbers are ostentatious.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:45 UTC (Tue) by jengelh (guest, #33263) [Link] (5 responses)

Yeah it's kinda stupid that in Ubuntu, which uses the "rl 2" semantics, you can't deactivate network by changing to another rl.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:06 UTC (Tue) by sorpigal (guest, #36106) [Link] (4 responses)

You certainly can, you just need to configure a runlevel of your choice to work that way.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 19:51 UTC (Tue) by xorbe (guest, #3165) [Link] (3 responses)

The average user can figure out how to change runlevels. The average user is going to stumble attempting to configure a custom runlevel.

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 12:01 UTC (Wed) by Kamilion (guest, #42576) [Link] (1 responses)

The average user will either unplug the ethernet cable, or click on the NetworkManager applet, instead of mucking with their runlevels at all.

Clang builds a working 2.6.36 Kernel

Posted Oct 30, 2010 11:29 UTC (Sat) by k8to (guest, #15413) [Link]

The average user lives in bangladesh, is 3/5ths female, subsistitence farms, and has 5 children.

Clang builds a working 2.6.36 Kernel

Posted Oct 28, 2010 8:42 UTC (Thu) by ekj (guest, #1524) [Link]

The average user in my household has never heard of "runlevels"

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 4:47 UTC (Tue) by error27 (subscriber, #8346) [Link] (2 responses)

The 2.6.37 kernel may pose new challenges because it uses asm labels and local __label__ declarations. :)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 5:28 UTC (Tue) by wash (guest, #70825) [Link] (1 responses)

That would be if we didn't have support for local labels. As of ten minutes ago, we do :).

- Bryce Lelbach

Clang builds a working 2.6.36 Kernel

Posted Oct 28, 2010 16:11 UTC (Thu) by mingo (guest, #31122) [Link]

Btw, a few days ago we found out that the jump label support code is broken in GCC, it messes up the stack offset which crashes the kernel.

So LLVM might be the first compiler on the planet to have working GCC jump label support ;-)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 5:27 UTC (Tue) by rilder (guest, #59804) [Link] (20 responses)

One important missing piece here is performance. Not that it may be slower than gcc build but how much slower is the question.

Also
"Depending on how the configuration is tweaked/the
SMP support of the kernel that I'm building on top of, Clang builds Linux in about 13-15 minutes."

It will be interesting to see if clang builds faster than gcc with similar level of optimizations enabled.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 6:31 UTC (Tue) by wash (guest, #70825) [Link] (1 responses)

As far as compiling, as my original post states, the clang-compiled kernel self hosts. Before I had SMP working, it took about 17ish minutes to build (the result of that build was a kernel with SMP). I'm using a self-hosted Linux kernel that was built with Clang right now. I don't have hard numbers, but compiling doesn't seem to be too much slower. This isn't an optimized kernel build, though.

I've been unable to find a usable kernel test suite. I've tried a few, and been disappointed by all of them, most of all by the Linux Testing Project.

The best test suite I've found so far is a debian package called posixtestsuite. It's a few years old, and looks to have been written by a bunch of Intel hackers. It has a number of desirable features, such as the ability to be compiled without hair pulling, and documentation.

I'm open to suggestions regarding broader performance testing solutions.

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 11:27 UTC (Wed) by i3839 (guest, #31386) [Link]

A good start would be to post the kernel sizes, both the optimized for size and for speed builts, and compare them to the GCC ones.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:11 UTC (Tue) by juliank (guest, #45896) [Link] (17 responses)

> One important missing piece here is performance. Not that it
> may be slower than gcc build but how much slower is the question.
I have a fairly normal calculation program that, compiled using clang, is much (100 times IIRC) faster than those compiled using gcc.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:59 UTC (Tue) by jwakely (subscriber, #60262) [Link] (16 responses)

compiles 100 times faster or runs 100 times faster? the latter would be more surprising than the former, though either would be an impressive result

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 12:32 UTC (Tue) by juliank (guest, #45896) [Link] (15 responses)

> compiles 100 times faster or runs 100 times faster?

Run time. The following code runs much faster when compiled clang++ (0.003s) than when compiled using g++ (1.593s):


#include <iostream>
#include <boost/thread.hpp>

#define len 1000000000L

static void f(unsigned long a, unsigned long b, unsigned long *va)
{
    for (*va = 0; a < b; a++)
        *va += a;
}
    
int main()
{
    unsigned long va = 0;
    boost::thread a(f, 0l,  2* len, &va);
    a.join();
    std::cout << va  << std::endl;
    return 0;
}

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:04 UTC (Tue) by juliank (guest, #45896) [Link] (14 responses)

It might be that clang is able to optimize (-O2)

for (*va = 0; a < b; a++)
    *va += a;

to

*va = (1 + b)*(b/2) - b

- as per Gauss: 1+2+...+N=(1 + N)*(N/2)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:13 UTC (Tue) by juliank (guest, #45896) [Link] (13 responses)

In
*va = (1 + b)*(b/2) - b

I missed a, and the solution was wrong. The correct way to calculate the sum of all values {x | a <= x < b} is:

*va = (b)*(b-1)/2 - (a)*(a-1)/2

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:38 UTC (Tue) by jwakely (subscriber, #60262) [Link] (12 responses)

Or maybe instead of using an identity it just inlines the call through &f (which is quite impressive) then finds that all the values are known at compile-time, so the loop can be completely unrolled. Pretty cool either way.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:01 UTC (Tue) by juliank (guest, #45896) [Link] (8 responses)

In any case, I simplified it to C and posted it to my blog at http://juliank.wordpress.com/2010/10/26/simple-code-clang-creates-1600x-faster-executable-than-gcc/

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:12 UTC (Tue) by rahulsundaram (subscriber, #21946) [Link] (1 responses)

You might want to report this to the GCC developers via mailing list or bugzilla.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:35 UTC (Tue) by jwakely (subscriber, #60262) [Link]

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:32 UTC (Tue) by tzafrir (subscriber, #11501) [Link] (5 responses)

It also becomes way faster in gcc (4.4.5 here) once you remove "__attribute__((noinline))". This looks like a simpler explanation for the simpler code you posted there.

I didn't check it with clang.

And just to provide a working link:

http://juliank.wordpress.com/2010/10/26/simple-code-clang...

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:37 UTC (Tue) by juliank (guest, #45896) [Link] (4 responses)

> It also becomes way faster in gcc (4.4.5 here) once
> you remove "__attribute__((noinline))". This looks
> like a simpler explanation for the simpler code you posted there.

Then gcc calculates the result of f() at compile-time and just has a constant integer in the assembler code. Clang does not appear to do this (there's callq f in clang's assembly)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:29 UTC (Tue) by gmaxwell (guest, #30048) [Link] (3 responses)

"Clang 100x faster than GCC!"

"But.. why did you handicap GCC?"

"Cause if I didn't GCC was much faster!"

(just saying… :) )

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:31 UTC (Tue) by juliank (guest, #45896) [Link] (1 responses)

> "Clang 100x faster than GCC!"
> "But.. why did you handicap GCC?"
> "Cause if I didn't GCC was much faster!"
> (just saying… :) )

GCC 4.5 at -O3 is as fast as clang, although not if you call the function via a pointer. GCC 4.4 has the same slow speed at -O2, -O3, -O4, -O9.

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 9:27 UTC (Wed) by jwakely (subscriber, #60262) [Link]

-O4 and -O9 don't exist, no surprise they aren't any better than -O3

GCC 4.5 has apparently already improved. Are you also comparing with a version of Clang from 18 months ago, when GCC 4.4 was released?

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 21:47 UTC (Tue) by tzafrir (subscriber, #11501) [Link]

To make this "handicap" more realistic, replace the constant with a command-line parameter.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:19 UTC (Tue) by mjw (subscriber, #16740) [Link] (2 responses)

If so, try -funroll-loops, which isn't automatically done with gcc/g++, because it might create larger object code:
   -funroll-loops
       Unroll loops whose number of iterations can be determined at
       compile time or upon entry to the loop.  -funroll-loops implies
       -frerun-cse-after-loop, -fweb and -frename-registers.  It also
       turns on complete loop peeling (i.e. complete removal of loops with
       small constant number of iterations).  This option makes code
       larger, and may or may not make it run faster.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:38 UTC (Tue) by juliank (guest, #45896) [Link] (1 responses)

> If so, try -funroll-loops, which isn't automatically
> done with gcc/g++, because it might create larger object code:

Brings it down to 0.200s

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:32 UTC (Tue) by gmaxwell (guest, #30048) [Link]

I believe that unrolling is enabled by default in GCC if you do a profile guided build.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 8:07 UTC (Tue) by HelloWorld (guest, #56129) [Link]

Great! Now let's try it with MSVC :o)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 8:36 UTC (Tue) by micka (subscriber, #38720) [Link] (6 responses)

I find it strange to say "clang builds a linux kernel" until it really does... From the report that was made, it doesn't : ICE on some parts, unsupported dialect in some other. Actually, the final result is an hybrid clang/GCC binary.
That's the way to go, but only when you can take a vanilla tarball of a kernel (even in a pre-defined version), set the compiler, and launch 'make menuconfig' ; 'make all', to have a booting kernel, it will be considered done.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 8:42 UTC (Tue) by tcourbon (guest, #60669) [Link] (5 responses)

I think that the milestone is important enough to mention it as if I understand correctly the kernel is bootable and functional.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 10:12 UTC (Tue) by ledow (guest, #11753) [Link] (4 responses)

Bootable if you put in a GCC-compiled bootstrap object file, and exclude lots of drivers, and don't test things too thoroughly.

At least, according to the post here, and that only took two seconds to find.

It's like saying that the Linux build process is now usable without Perl... so long as you have Perl installed and compile a couple of kernel parts with it first, or do that elsewhere.

I have to agree: when "make" builds a working kernel from (even patched) source, then you have a reason to shout. Even self-hosting is a bit dubious if you haven't actually tested that the kernel you're using is stable and/or working even vaguely right except on a single example computer and a lot of hope.

When it's possible for *anyone* to compile a kernel without having to do more than apply a patch or two, (i.e. no more complicated than your average unsupported compiler) then they can rejoice. Until then, it's an interesting intellectual exercise that is *nearing* success.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:01 UTC (Tue) by tzafrir (subscriber, #11501) [Link]

TCC did make headlines building a patched kernel.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:23 UTC (Tue) by PaXTeam (guest, #24616) [Link] (1 responses)

> I have to agree: when "make" builds a working kernel from (even patched) source, then you have a reason to shout.

then see http://lwn.net/Articles/409614/ ;). i posted a detailed email with the minimal patch last night to cfe-dev but apparently it's still held up in moderation, so i might bite the bullet and subscribe ;P.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 13:59 UTC (Tue) by PaXTeam (guest, #24616) [Link]

Clang builds a working 2.6.36 Kernel

Posted Nov 6, 2010 3:08 UTC (Sat) by efexis (guest, #26355) [Link]

"It's like saying that the Linux build process is now usable without Perl"

No it's not. If it says "without gcc" then you would be correct, but it never says "without gcc", it only says "with clang". An inclusive is not the same as an exclusive.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:42 UTC (Tue) by ibukanov (subscriber, #3942) [Link] (7 responses)

> variable-length arrays or another intentionally unsupported GNUtension

variable-length arrays is a part of C99. Does that "intentionally unsupported" implies that CLang would not fully support C99?

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:50 UTC (Tue) by jwakely (subscriber, #60262) [Link] (6 responses)

does the kernel compile as C99? or does it compile as C90 with GNU extensions such as VLAs?

I wouldn't be surprised if Clang only supports VLAs in C99 mode

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 11:55 UTC (Tue) by jwakely (subscriber, #60262) [Link] (4 responses)

http://clang.llvm.org/compatibility.html#vla
that's in the context of C++, apparently Clang defaults to C99 for C (which is correct as that's the current standard) so I wonder why VLAs are described as unsupported - maybe a mistake

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 23:07 UTC (Tue) by wash (guest, #70825) [Link] (3 responses)

Very much so a mistake, my apologizes. I meant to refer to the GNU extension that allows variable length arrays in structures.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 23:45 UTC (Tue) by Trelane (subscriber, #56877) [Link] (1 responses)

by "VLAs in structs" are you referring to flexible array members?

Clang builds a working 2.6.36 Kernel

Posted Oct 30, 2010 12:32 UTC (Sat) by viro (subscriber, #7872) [Link]

Much worse than that. It allows (and kernel does *not* use, unless something has drastically and cretinously changed) things like that:

extern void g(int *);
void f(int m, int n)
{
struct foo {
int a[n];
int b[n][m + 69];
} x;
g(&x.b[1][1]);
}

Yes, gcc is that sick.

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 9:36 UTC (Wed) by jwakely (subscriber, #60262) [Link]

Flexible array members are also standard C99, and I assume supported by Clang. *zero* length array members are a GNU extension:
http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

Clang builds a working 2.6.36 Kernel

Posted Oct 28, 2010 21:12 UTC (Thu) by jengelh (guest, #33263) [Link]

>does the kernel compile as C99? or does it compile as C90 with GNU extensions such as VLAs?

In Rome, do as the Romans do: ICC (which is said to be able to compile the kernel) also supports the GNUisms. :)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 12:54 UTC (Tue) by clugstj (subscriber, #4020) [Link] (13 responses)

Seems like a strange goal. The Linux kernel is not what I'd call standards-compliant code. I would think that standards-compliance would be a useful goal for a compiler. And I fail to see why it is so important. And why it warrants at the very least, extreme exaggeration. The title of the message is false:

"Clang can now compile a functional Linux Kernel (version 2.6.36, SMP)."

No, it cannot, if you need to compile certain modules w/ GCC in order to get it to boot. Unless you don't consider booting to be something a kernel must do to be "functional".

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:27 UTC (Tue) by mpr22 (subscriber, #60784) [Link] (5 responses)

It seems to me that a compiler that won't build the Linux kernel probably wouldn't even get considered as the default compiler for a Linux distribution, while a compiler that will build the kernel might.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:58 UTC (Tue) by oak (guest, #2786) [Link]

According to latest mail by Bryce this morning:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-October/0...

Many of the issues listed in above article are already handled, and GCC isn't anymore needed:
"GCC is no longer needed at all during the build process. GNU ld is still needed; GNU's assembler is not. Linux successfully compiles with the integrated-assembler."

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:02 UTC (Tue) by ewan (guest, #5533) [Link] (3 responses)

Yup. Can't imagine anyone ever shipping a distribution that requires a special copy of GCC just for the kernel, I mean, what would you call it- 'kgcc' or something?

Hard to see if it was sarcasm or not...

Posted Oct 26, 2010 22:22 UTC (Tue) by khim (subscriber, #9252) [Link] (2 responses)

If you are being sarcastic then please use "<sarcasm>" tag in the future...

And if it was not sarcasm then I want to remind you that RedHat did exactly that in version 7.x (and yes, package was called kgcc).

Hard to see if it was sarcasm or not...

Posted Oct 27, 2010 17:03 UTC (Wed) by chad.netzer (subscriber, #4257) [Link] (1 responses)

Maybe for sarcasm, we should instead use the <blink> tag. :)

Hard to see if it was sarcasm or not...

Posted Nov 6, 2010 3:12 UTC (Sat) by efexis (guest, #26355) [Link]

Surely if it's sarcasm it should just be a <wink> tag rather than a <blink> tag? ;-)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 14:57 UTC (Tue) by wash (guest, #70825) [Link] (6 responses)

No offense, but I'm not really interested in your opinion. This is a project I am working on in my spare time; I made a post about it to a development list. Parties unknown to me (who obviously felt it was of some significance - note that I do not particularly agree with them, as this is just one of many milestones Clang has recently passed) decided to publicize this.

A lot of people have put many hours of work into getting Clang to this stage. I am not one of them; I'm relatively new to the Clang community. In particular, Alp Toker from Nuanti and his team should be recognized for all the work they've been doing on this.

Anyways, the Linux Kernel can now be built entirely by Clang. Loadable modules work, the crypto and network stacks are fully functional, and SELinux is supported. I am now building with the Clang integrated assembler; the only part of the GNU toolchain still involved in the process is the GNU linker. I have been unable to find any other linker (which is not derived from GNU's), so for now, this toolchain will use ld.

The version source code for my local copies of Clang/LLVM and Linux will be put up on Github later this week, as well as instructions for building.

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 15:33 UTC (Tue) by loevborg (guest, #51779) [Link]

FWIW I thought this piece was newsworthy and interesting. Thanks for your impressive work with clang!

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 15:55 UTC (Tue) by jwakely (subscriber, #60262) [Link] (3 responses)

the obvious other linker to try is gold, although of course that's part of GNU binutils too ... there is a reason why people call it GNU/Linux, y'know ;)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 16:53 UTC (Tue) by MisterIO (guest, #36192) [Link] (1 responses)

Isn't gold still unable to link usable kernels? Or is it just something that debian folks have fun writing?:)

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 18:34 UTC (Tue) by rriggs (guest, #11598) [Link]

Clang builds a working 2.6.36 Kernel

Posted Oct 26, 2010 17:05 UTC (Tue) by nteon (subscriber, #53899) [Link]

As of a couple of months ago, gold was unable to link a working kernel for me. Seems to still be the case: http://fedoraproject.org/wiki/Features/GoldLinkerDefault

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 4:29 UTC (Wed) by Lefty (guest, #51528) [Link]

I agree that this is both interesting and newsworthy. Clang is making excellent progress, and this is a very significant milestone.

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 5:28 UTC (Wed) by dterei (guest, #45237) [Link] (1 responses)

I'm curious as to what has been done to handle the GNU Global Register Variables extension? I know clang didn't use to support this (or at least not with the same semantics as GCC, the registers weren't actually reserved for exclusive use by the variable). Does the linux kernel just not make use of this extension?

Clang builds a working 2.6.36 Kernel

Posted Oct 27, 2010 6:58 UTC (Wed) by wash (guest, #70825) [Link]

It doesn't. But also, I have a patch to make clang support GNU-style explicit register variables.


Copyright © 2010, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds