LWN.net Logo

LFCS 2012: LLVM and Linux

By Jake Edge
April 25, 2012

The LLVM compiler, and its Clang C-family front-end, are getting increasing attention as they mature. At last year's Linux Foundation Collaboration Summit (LFCS), Bryce Lelbach talked about building the kernel with Clang. This year, Mark Charlebois of the Qualcomm Innovation Center (QuIC) picked up where Lelbach left off and, along with his Qualcomm colleague David Kipping, gave a talk at this year's LFCS about LLVM, what its attractions are, and where things stand in building the Linux kernel with Clang.

An introduction to LLVM

Kipping started off with a brief introduction to LLVM, which came from an experiment in compiler construction that Chris Lattner started as part of his PhD. work in 2000. It is a framework for building compilers, rather than a compiler itself. The idea is that components can be assembled into a compiler, and that those components can be reused by other tools. For example, he said, debuggers can use the same parser that the compiler does. But one of the basic premises that underlies LLVM is that no one component is able to serve all of the possible use-cases, so there is no "one true register allocator", no single scheduler, nor a required optimization order in LLVM, he said.

A secondary mission of the LLVM project was to build compilers using the components. "LLVM" is an overloaded term these days, and many use it when they really mean "Clang", Kipping said. LLVM is actually an "umbrella project" with multiple sub-projects.

Clang is the best known of these sub-projects, and is a front-end that supports C, C++, and Objective-C. Clang is known as a fast-to-run compiler, but it is getting slower as more features, optimizations in particular, are added. But it is still a fast compiler, he said. It is designed for conformance with standards and, at least to some extent, compatibility with GCC.

Clang is a strict compiler that is known for the quality of its error messages. It will complain about things that GCC does not, which is part of what led Google to become a "large supporter of LLVM". Google does simultaneous builds of its internal code, using GCC for the code generation and Clang for its static analysis and error/warning messages. By reworking some of the code that Clang was complaining about, Google actually found some "potential problems" in its source code, he said.

Another project under the umbrella is DragonEgg, which is a plug-in that implements a back-end for GCC. That can either provide more GCC compatibility for LLVM code generation or allow one to use GCC language front-ends, like Fortran, that there is no LLVM compiler for. The LLVM debugger (LLDB) is still probably two years away from being ready for production but, because of LLVM's component model, it provides some opportunities for better debugger integration. "Polly" is another area of work for the project. It implements polyhedral optimization, which is an "immature technology" that shows promise for improving the amount of parallelization and vectorization in generated code.

Clang architecture

Clang has a fairly common architecture, with front, middle, and back-ends. It has a "fairly clean" architecture-independent intermediate representation called "Bitcode", though it does have some architecture dependencies, which can cause problems for some back-ends. But, Bitcode can be separated by "space, time, and architecture", so it can be used for code generation at a later time or on a different machine or architecture.

That separability means that Clang can not only be used as a static compiler, but also as JIT compiler. For example, in using Renderscript for Android, developers can package up the Bitcode into the .apk file and the actual code generation is done for the proper target when the app is run for the first time. For example, scalar code would be generated for an ARMv7, but vectorized code would be generated for a Neon core.

LLVM development is "accelerating", Kipping said, with a lot of activity taking place in the last few years. The Android adoption of LLVM for Renderscript in its Honeycomb (3.0) and Qualcomm's contribution of VLIW (very long instruction word) support for LLVM in just the last year or so are some examples he gave of this acceleration. In addition, LLVM is being adopted widely for graphics (e.g. Renderscript, LLVMpipe), parallel programming (e.g. OpenCL), and for things like the Chrome Portable Native Client (PNaCl).

LLVM is also becoming more important in academia. Kipping noted that Lattner gave a keynote speech at the 2012 International Symposium on Code Generation and Optimization, which is one of the most important technical conferences for compiler technology. This year's Proceedings has 103 references to LLVM, which is up from 34 the previous year, he said.

The performance of LLVM's generated code is improving as well. Comparing it to that of GCC, which is the "gold standard today", shows that the LLVM tip is within 1-3% of GCC 4.6 performance for ARM, and within about 4% for x86. The tests need to be re-run for GCC 4.7, he said.

Qualcomm is interested in LLVM because of the "exceedingly complex" nature of ARM system-on-chips (SoCs), with multiple processor cores and multiple graphics pipelines. Code may run on a DSP in one configuration, or on the CPU or GPU in another. The decision on where to run the code may be made based on power saving scenarios. Having a common toolchain that generates code for any of those situations is helpful. In addition, any optimizations that are done in LLVM will be available for multiple code generators, he said.

LLVM is "not there yet" to do complete Linux system builds, Kipping said, which would be a good way to reduce build complexity while getting the advantages of bug fixes and optimizations that have been going into LLVM. Linux is a great source of code that can be used to test and improve LLVM as well. LLVM has a "great community" that is open for participation in various ways including LLVM.org, developer meetings, and conferences. With that, he turned the floor over to Charlebois to talk about LLVM and Linux.

Compiling Linux with Clang

Charlebois began with an explanation of the reasons to build the kernel using Clang. One reason is to get to the point where Clang can be the compiler for the whole system, as Kipping described, and the kernel is a core part of that system. The better diagnostics produced by Clang, which show the actual code where the problem is, are useful, he said. In addition, the kernel uses lots of GCC extensions, which Clang helps find.

The "fix-it" hints that are produced by Clang are very helpful as well because they not only show the problem that produced the warning or error, but also often show how to fix the code. Another area where Clang shines is that it fully expands macros in the diagnostics, which makes it easier to spot problems with macros. Clang has a "still maturing" static analyzer that can show code flow paths. Bringing these kinds of diagnostics to the kernel "will be great", he said.

MINIX has switched to Clang as its default compiler and FreeBSD is working on building its system using Clang. FreeBSD is also using LLVM and KLEE for automatic test generation. LLVM is also being used in graphics applications, like Renderscript for Android and LLVMpipe for Gallium3D. In addition, he noted Sylvestre Ledru's efforts to build Debian with Clang, which LWN also looked at in March.

Most of Charlebois's work on building Linux with Clang focused on cross-compiling for ARM. One of the difficulties he encountered was in finding the right parameters for cross-compilation. The Clang mailing list is very helpful with suggestions, but it is an unsupported configuration and getting all of the flags (e.g. the "triplet") just right can be difficult.

Most of the conversations on the mailing list centered on solving this configuration problem "the right way", which involves a "universal driver" for Clang. That driver would have access to all of the information on the location for the compilers and other tools needed, and users would just point it at a configuration file that specified the target. It's a great idea, he said, but he hasn't seen much movement on it yet.

Another project that he mentioned is ELLCC (Embedded LLVM Compiler Collection), which is a single cross-compiler code base that is based on Clang and LLVM and targets many different architectures (ARM, x86, MIPS, PowerPC, ...). The project has a live web page where you can submit source code, choose a target, and examine the generated code. He said he is "quite impressed" with ELLCC.

Challenges

There are, of course, some challenges building with Clang. Cross-compilation is not a supported configuration, and it is dependent on a GNU cross-toolchain for its assembler and linker. There are lots of warnings produced by Clang which slows down compilation, for example all of the functions that are called (e.g. memcpy()) where the return value is ignored. There are also some bugs in Clang and LLVM for ARM, he said, which he has reported and QuIC has worked on fixing some of them.

The kernel expects to be able to use some GCC behavior that is not supported by Clang. The scripts/Kbuild.include files are GCC-specific, for example. Clang does not have a way to check which options are supported, while GCC does. Clang warns for unused options, but not unsupported ones. In addition, GCC returns false when it it gives an error that there is an unsupported flag, while Clang returns true when it warns about unused flags. There are also "a bunch" of unsupported GCC flags, he said.

There is a master LLVM bug for building the kernel with Clang. The blockers are mostly x86-specific and there are 8-11 of them currently. That bug is a good way to keep track of the status, he said.

The problem with variable-length arrays in structures that Lelbach reported persists. Charlebois patched the kernel to avoid those constructs. It is a non-standard feature of C that is a "GCC-ism", he said. It may come from the fact that GCC supports Ada, so it was probably easy to throw that into C as well.

Explicit register variables are also not supported by Clang, so things like putting the stack pointer into a named variable do not work. In fact, Clang sets the value to null, which doesn't make for a very good stack pointer. Nested functions are also not supported, but they are only present in the Thinkpad driver; since he has been focusing on ARM, he hasn't looked into that.

There are thousands of instances where return values are unused in the kernel, which causes a huge number of warnings when using -Wunused in Clang. It's not desirable to turn off that warning, he said, so he patched around the problem in the kernel. The semantics of the inline keyword for functions is different between GCC's gnu89 and Clang's C99 behavior. There is a gnu89 compatibility flag for Clang, but he has not used it because he wanted to get the kernel to build with Clang's semantics. In addition, EXPORT_SYMBOL() for inline functions makes Clang crash, he said.

There are also missing features or bugs in Clang/LLVM for ARM that he has had to work around. The -mabi-linux flag is not fully supported for Linux. GCC uses four bytes for all enums, while Clang has variable-length enums, which creates incorrect structure offsets, so he doesn't use -mabi-linux in Clang.

64-bit parameter passing requires paired registers in ARM, which is broken in LLVM. There are also problems accessing the upper 32 bits of 64-bit atomic types, which use GCC-specific features to do so in Linux. QuIC has submitted a patch for the first 64-bit problem and is developing one for the second, he said; once they are merged, he can uncomment the affected code in the kernel he is building.

The Clang integrated assembler (IA) is not the default for ARM, because it is still not finished. Finding the right "triplet" for the kernel vs. the one for user-space programs is a problem as "arm-none-linux-gnueabi", for example, works fine for user space, but not for the kernel. Using just "arm" or "armv7" works for the kernel, but gives warnings about not having EABI support. There is also difference in the definition of __kernel_size_t (which is an unsigned long) and size_t (which is defined by Clang to be an unsigned int) which required him to patch the kernel definition to avoid warnings for different argument types for various library functions.

Building

A project has been set up at llvm.linuxfoundation.org that has an automated build framework. It will download the latest LLVM, Clang, QEMU, and the kernel, then patch and build the kernel, and run it in QEMU. It supports the ARM Versatile Express board and Qualcomm's MSM processor, though there is no QEMU target for the MSM, so you can only build for that platform. The Versatile Express boots a 3.3 kernel and runs a toybox user space.

The project site also has Git trees with the patches that he made to the kernel for some of the problems he mentioned earlier. No patches are applied to Clang or LLVM, he said. It is easy to add new architectures to the build framework, and he would love to see people add things like x86, MIPS, and other targets. There is a set of Python tools available to help manage any patches required.

There are still lots of things left to do, of course, and Charlebois wrapped up with his list. First up was to check the status of the problems that Lelbach had reported a year ago. The status of the ARM IA for Clang is also something he needs to look into, as are some of the bugs and problems he mentioned earlier in the talk (inline differences, segment linkage differences, etc.). He would like to build the Linux Test Project with Clang onto a virtual SD card filesystem to use with QEMU and do some regression testing using that. The last item on his list was to set up a test suite for known LLVM bugs so that fixes for those bugs can be detected in newer releases.

It is "pretty exciting" that he can build and run Linux using Clang for one of the ARM architectures, he said. None of the changes that he has made to the kernel stop it from building with GCC, they "just make the kernel less dependent on GCC". He has not tried to merge any of his work upstream, yet, but he hopes that at some point there is interest in making Clang an officially supported compiler for building the kernel. If that happens, he is hopeful that his patches will be helpful in that endeavor.


(Log in to post comments)

LFCS 2012: LLVM and Linux

Posted Apr 26, 2012 3:18 UTC (Thu) by pr1268 (subscriber, #24648) [Link]

Interesting article. As someone who recently (two days ago) compiled and installed LLVM and Clang, I've been having fun lately rebuilding and benchmarking my own simple utilities (written in C or C++).

The short summary of my observation: Clang's compiled code runs slightly faster than GCC's (not to mention Clang code compiles faster), but the stripped ELFs are about the same size. Of course, I am aware that linking in pre-compiled libraries (e.g. glibc) means I'm including code outside the scope of Clang's compilation.

One weird Clang issue (I'll keep it brief): In a Mersenne Twister-based PRNG I've written, if I split a single source code .c file's two functions into their own files, and then recompile (separate .o files), then link everything together, my program doesn't run right (actually it doesn't run at all, but it appears to terminate normally). This only happens with Clang-compiled code (and only if I split the file's two functions into separate files), and not with GCC. Weird...

Regardless, I'm fascinated by the research and development emanating from the LLVM project. It'll be even more fun to see what's yet to come...

LFCS 2012: LLVM and Linux

Posted Apr 26, 2012 8:36 UTC (Thu) by juliank (subscriber, #45896) [Link]

Please note that clang is not always faster than GCC, and clang may perform some optimisations at -O2 that gcc only performs at -O3 (in my case, I have seen it inline non-static functions when compiling a complete program).

Clang has some better optimizations in some parts, gcc in others. Sometimes clang might also optimize less and thus cause smaller code, which might improve performance as well.

In general, performance should be roughly equally I'd say.

"gold standard"?

Posted Apr 26, 2012 3:25 UTC (Thu) by cpeterso (guest, #305) [Link]

Is GCC really the "gold standard" of optimized code performance? GCC's optimizer used to have a bad reputation compared to Intel's ICC compiler and ARM's ARMCC compiler.

Have Intel or ARM contributed to Clang/LLVM? I've always been surprised that they maintain their own proprietary, closed-source compilers rather than contributing more resources to GCC (or Clang/LLVM).

"gold standard"?

Posted Apr 26, 2012 15:48 UTC (Thu) by davide.del.vento (guest, #59196) [Link]

No, gcc is the slowest compiler, AFAIK. Its advantage is being very portable across architectures, which isn't true for Intel's or ARM's.

And what's about the (recently re-opensources) Pathsscale? It is on par with Intel, in my experience. And then there is the PGI.... The compiler's game is a large race and GCC and LLVM are not the only two horses in it.

I believe Intel does its own closed source compiler to show the best it can on its hardware. They don't want that "best" being available on other vendor's hardware.

"gold standard"?

Posted Apr 26, 2012 21:12 UTC (Thu) by robert_s (subscriber, #42402) [Link]

"No, gcc is the slowest compiler, AFAIK."

Believe me, there are plenty of much slower compilers.

As for hardware vendors' compilers, it would be pretty embarrassing for them (not to mention pointless) if they _couldn't_ outperform competitors on their own hardware.

I'm also not so convinced by any "4% off gcc" claims about LLVM. Phoronix (yes, caveats aside) routinely test LLVM releases and it's common for LLVM to be a good 50% behind gcc. A lot of these claims you hear about LLVM's speed often turn out to be "when compared to a 3 year old gcc".

Not that I'm not an LLVM fan though. It's just important to be realistic.

"gold standard"?

Posted Apr 26, 2012 21:40 UTC (Thu) by daglwn (subscriber, #65432) [Link]

> Believe me, there are plenty of much slower compilers.

Yes there are but I believe the statement is true if one considers "regularly used" compilers. gcc's generated code is notoriously slow. Still, it will always win on some codes simply because no one compiler can completely dominate every other.

gcc's great strength is in its portability and cross-compile capabilities, which no other compiler can touch and won't any time soon.

> As for hardware vendors' compilers, it would be pretty embarrassing for
> them (not to mention pointless) if they _couldn't_ outperform
> competitors on their own hardware.

They will not outperform competitors on every possible code. I know of compilers that handily beat icc for x86 on some codes but also get trounced by icc on other codes. And it is not terribly difficult to examine the generated code of a compiler and figure out a bit of what it's doing to get performance. Reproducing it is sometimes tricky but in most cases it isn't. The techniques are known. The devil's in the tuning.

The problem is mostly one of time and compiler developer resources. By focusing/specializing on a key set of codes or operating arenas (embedded, HPC, etc.) a compiler team can create something that will beat a vendor compiler on those codes or in that particular arena.

"gold standard"?

Posted Apr 26, 2012 22:57 UTC (Thu) by stevenb (guest, #11536) [Link]

"gcc's generated code is notoriously slow."

There are plenty benchmarks and user stories that say otherwise. IMHO there is a perception problem that is being perpetuated because complaints about GCC (or any other compiler) are always shouted out louder than compliments. And saying anything positive about GCC seems to be salon unfaehig anyway in many Linux discussion forums (especially LKML)...

"gold standard"?

Posted Apr 27, 2012 1:07 UTC (Fri) by daglwn (subscriber, #65432) [Link]

As I said, one can show gcc generating faster executables than other compilers on some codes. This will always be so. But the gcc team does not focus on performance exclusively, nor should it.

For all-out performance over a wide range of codes, it's hard to beat compilers that focus on it, such as icc, pathscale and pgi.

"gold standard"?

Posted Apr 29, 2012 8:24 UTC (Sun) by ebiederm (subscriber, #35028) [Link]

A lot depends on what you mean by performance.

Compiling your kernel of numerical code fast is one thing, and there are certainly compilers that specialize in that and all kinds of cpu architecture extensions to take advantage of it.

Where I have seen gcc excel is in making the work-a-day integer code lean and tight and cache friendly.

Most codes are integer codes and we need good work-a-day compilers not the hotrod numerical code wonders that are fast when the compiler does not ICE or generate incorrect code.

With luck clang can catch up to gcc and be a good work-a-day compiler but it seems clear that clang is not there yet.

"gold standard"?

Posted Apr 27, 2012 3:02 UTC (Fri) by davide.del.vento (guest, #59196) [Link]

> Believe me, there are plenty of much slower compilers.

A couple of names?

"gold standard"?

Posted Apr 27, 2012 10:02 UTC (Fri) by robert_s (subscriber, #42402) [Link]

Phew ok, PCC, digital mars, from what I've seen MSVC, Open64 probably more than half the time (though the situations where it wins can be impressive...), I don't think OpenWatcom can really keep up these days...

...and now LLVM.

"gold standard"?

Posted Apr 27, 2012 10:25 UTC (Fri) by daglwn (subscriber, #65432) [Link]

LLVM is not a compiler.

"gold standard"?

Posted Apr 27, 2012 11:49 UTC (Fri) by dgm (subscriber, #49227) [Link]

> from what I've seen MSVC

It certainly wasn't that way back when gcc 3.4 was the current release. I know because I benchmarked it for my university. MSCC both compiled faster and produced faster binaries, and by a good margin.

I think that it's time to redo those benchmarks...

"gold standard"?

Posted Apr 30, 2012 18:06 UTC (Mon) by robert_s (subscriber, #42402) [Link]

"gold standard"?

Posted May 2, 2012 11:37 UTC (Wed) by dgm (subscriber, #49227) [Link]

Uh, OK. My wife wants to thank you for saving me a weekend. Hummmm.

AFAICS, MSVC is still *much* faster compiling than GCC (between two and four times faster). Also, MSVC generated code is smaller and runs faster, but the difference is not as big as it used to be.

"gold standard"?

Posted May 13, 2012 10:13 UTC (Sun) by robert_s (subscriber, #42402) [Link]

"Also, MSVC generated code is smaller and runs faster, but the difference is not as big as it used to be."

Well no, according the the "average" page gcc 4.6.3 maxes out at "1.18" for runtime while msvc 2010 maxes out at "1.24".

But, y'know, benchmarks and all that...

"gold standard"?

Posted May 2, 2012 8:29 UTC (Wed) by nwmcsween (guest, #62367) [Link]

> I'm also not so convinced by any "4% off gcc" claims about LLVM. Phoronix (yes, caveats aside) routinely test LLVM releases and it's common for LLVM to be a good 50% behind gcc

50% on very biased benchmarks that utilize openmp, which isn't supported as of now in clang/llvm.

LFCS 2012: LLVM and Linux

Posted Apr 26, 2012 16:21 UTC (Thu) by kmccarty (subscriber, #12085) [Link]

For what it's worth, I've found two severe issues in my attempts at experimenting with Clang at the company I work for. (Our production compiler for Linux is currently GCC 4.2.4)

Issue 1 is that it doesn't support OpenMP pragmas for parallelization, which is an absolute blocker to any possibility of our using it for production code. We are currently using it only for its compiler warnings as a static analyzer.

Issue 2 is that if one has installed a version of GCC in /usr/local, it seems to be impossible to build Clang such that by default it will use that GCC version's object files (crtbegin.o, etc.) and libstdc++ headers without actually hacking the portions of the Clang source code where these paths are defined. Perhaps this has improved since the version of Clang I'm at (SVN trunk from Sept. 30, 2011), but I experienced so much pain in getting this to work that I'm very reluctant to attempt to upgrade from this: it looks like all of the relevant Clang code has changed since then, which will cause serious merge conflicts with my local hacks.

At least as of that version of Clang, rather than support different GCC installation locations and default linker arguments with arguments to the configure script, the authors have actually defined the header and library search paths by putting them into the C++ source code, with various if statements based on what Linux distribution and version thereof, as well as what GCC version, that the program appears to be being compiled on.

This makes things easier for distributors, I suppose, although it means Clang will forever be playing catch-up with new versions. For anyone else building Clang, code like the following snippets is so incredibly ill-thought-out that it gives me misgivings about the rest of the project.

  static const char* GccVersions[] = {"4.6.1", "4.6.0", "4.6",
                                      "4.5.3", "4.5.2", "4.5.1", "4.5",
                                      "4.4.6", "4.4.5", "4.4.4", "4.4.3", "4.4",
                                      "4.3.4", "4.3.3", "4.3.2", "4.3",
                                      "4.2.4", "4.2.3", "4.2.2", "4.2.1",
                                      "4.2", "4.1.1"};

...

        if (GccTriple == "i386-linux-gnu") {
          // Ubuntu 11.04 uses an unusual path.
          std::string t4 =
              std::string(*it + "lib/i386-linux-gnu/gcc/i686-linux-gnu/") +
              GccVersions[i];
          if (!llvm::sys::fs::exists(t4 + "/crtbegin.o", Exists) && Exists)
            return t4;
        }

...

    else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux",
             Exists) && Exists)
      GccTriple = "x86_64-redhat-linux";
    else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux",
             Exists) && Exists)
      GccTriple = "x86_64-suse-linux";

...

  LinuxDistro Distro = DetectLinuxDistro(Arch);

  if (IsOpenSuse(Distro) || IsUbuntu(Distro)) {
    ExtraOpts.push_back("-z");
    ExtraOpts.push_back("relro");
  }

...

  if (IsDebian(Distro) || IsOpenSuse(Distro) || Distro == UbuntuLucid ||
      Distro == UbuntuJaunty || Distro == UbuntuKarmic)
    ExtraOpts.push_back("--hash-style=both");

[All excerpts above are from lib/Driver/ToolChains.cpp at SVN rev 140874]

LFCS 2012: LLVM and Linux

Posted May 1, 2012 14:53 UTC (Tue) by jwakely (subscriber, #60262) [Link]

Issue 2 is that if one has installed a version of GCC in /usr/local, it seems to be impossible to build Clang such that by default it will use that GCC version's object files (crtbegin.o, etc.) and libstdc++ headers without actually hacking the portions of the Clang source code where these paths are defined. Perhaps this has improved since the version of Clang I'm at (SVN trunk from Sept. 30, 2011)
Yes, it changed. At one time you needed to hack the source. Then you needed to use --with-cxx-include-root and --with-cxx-include-arch at configure-time, now you just use --with-gcc-toolchain and it does the right thing. It took a while getting there though.

LFCS 2012: LLVM and Linux

Posted May 1, 2012 22:29 UTC (Tue) by kmccarty (subscriber, #12085) [Link]

Yes, it changed. At one time you needed to hack the source. Then you needed to use --with-cxx-include-root and --with-cxx-include-arch at configure-time, now you just use --with-gcc-toolchain and it does the right thing. It took a while getting there though.

Thanks much for the update, this appears to work as advertised. I guess it is only available in SVN trunk, though, not in the 3.0 release?

I can get rid of my local Clang patches except for a couple lines to disable adding the --no-add-needed linker option when "IsRedhat(Distro)" returns true. (I'm not sure whether this distro autodetection is still enabled when GCC_INSTALL_PREFIX is pre-#define'd, but I didn't want to chance having to do yet another rebuild.)

I was even able to remove a bunch of -isystem flags pointing at GCC headers from the Clang-invoking wrapper scripts I have. I can't say that the relevant parts of Clang source code got very much prettier, though ;-)

LFCS 2012: LLVM and Linux

Posted May 2, 2012 9:00 UTC (Wed) by jwakely (subscriber, #60262) [Link]

> I guess it is only available in SVN trunk, though, not in the 3.0 release?

Dunno, sorry, I only use trunk

LFCS 2012: LLVM and Linux

Posted May 2, 2012 16:04 UTC (Wed) by kmccarty (subscriber, #12085) [Link]

(Replying to myself)

I was even able to remove a bunch of -isystem flags pointing at GCC headers from the Clang-invoking wrapper scripts I have.

Sadly I spoke too soon -- Clang compiled with --with-gcc-toolchain is not finding omp.h, which is under the GCC installation at <gccroot>/lib/gcc/x86_64-unknown-linux-gnu/4.2.4/include together with a few other things like float.h, varargs.h and limits.h. Ought I to file a bug?

Universal JITs

Posted Apr 26, 2012 21:33 UTC (Thu) by daglwn (subscriber, #65432) [Link]

[Preface: I love LLVM and we use it at work extensively.]

> For example, in using Renderscript for Android, developers can package
> up the Bitcode into the .apk file and the actual code generation is done
> for the proper target when the app is run for the first time. For
> example, scalar code would be generated for an ARMv7, but vectorized
> code would be generated for a Neon core.

Before anyone goes off to claim that LLVM bitcode is a universal IR, it ain't so. There are too many target-specific semantics in C for that to be possible. Struct layout is just one example. One cannot have a completely target-agnostic representation of a C program.

As stated in the quote, it probably can work within an architecture family (but note it won't between x86-32 and x86-64). However, the dream of a universal distribution format is going to have to wait for a higher-level language to overtake C.

Universal JITs

Posted Apr 27, 2012 8:16 UTC (Fri) by kugel (subscriber, #70540) [Link]

> One cannot have a completely target-agnostic representation of a C program.

Except the C source code :)

Universal JITs

Posted Apr 27, 2012 10:29 UTC (Fri) by daglwn (subscriber, #65432) [Link]

Ok smartypants,

One cannot have a completely target-agnostic representation of every C program.

:)

LFCS 2012: LLVM and Linux

Posted Apr 26, 2012 23:06 UTC (Thu) by modernjazz (guest, #4185) [Link]

LLVM is also being used to do fun new things in languages, like this one:
http://julialang.org/

related wisdom

Posted Apr 27, 2012 9:58 UTC (Fri) by wingo (guest, #26929) [Link]

LFCS 2012: LLVM and Linux

Posted May 3, 2012 7:13 UTC (Thu) by mlopezibanez (guest, #66088) [Link]

Clang/LLVM are indeed awesome, and it is good that there is the option to compile the kernel with it.

But I really don't understand all this hate for GCC coming from the Linux kernel guys.

LFCS 2012: LLVM and Linux

Posted May 4, 2012 20:39 UTC (Fri) by juliank (subscriber, #45896) [Link]

I assume that's mostly because almost every new GCC release breaks kernel building?

LFCS 2012: LLVM and Linux

Posted May 6, 2012 1:57 UTC (Sun) by vonbrand (subscriber, #4458) [Link]

Mostly due to kernel developers exploiting nooks and cranies of the current compiler to the hilt, and changes in it break all sorts of unwarranted assumptions... Been there (I routinely compiled the kernel with gcc snapshots way back when) and thoroughly enjoyed the resulting fireworks.

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