Clang/LLVM to compile Linux kernel

What are the benefits of LLVM?

http://stackoverflow.com/questions/172863/what-are-the-greatest-benefits-of-llvm

Why is the LLVM important:

http://en.wikipedia.org/wiki/Static_single_assignment_form

http://www.cs.utexas.edu/users/mckinley/380C/lecs/07.pdf

Introduction:

http://www.cs.sfu.ca/~wsumner/teaching/LLVMIntro.pdf

Its basic construct:

http://llvm.org/docs/LangRef.html

As started by Apple using LLVM to compile its OS, now the movement is spreading to Linux kernel as well.

https://www.youtube.com/watch?v=YffCWR3nqP4 (Reinventing the compiler – Clang)

Current status for Linux kernel:

http://llvm.linuxfoundation.org/index.php/Main_Page#Why_use_Clang.2FLLVM_with_the_Linux_Kernel.3F

Create a working compiler with the LLVM framework, Part 1

http://www.ibm.com/developerworks/library/os-createcompilerllvm1/index.html

http://llvm.org/docs/tutorial/index.html

http://llvm.linuxfoundation.org/index.php/Main_Page

http://www.phoronix.com/scan.php?page=news_item&px=MTY2MjY

http://llvm.org/devmtg/2014-02/slides/moller-llvmlinux.pdf

http://llvm.org/devmtg/2012-04-12/Slides/Mark_Charlebois.pdf

http://clang.llvm.org/features.html

LLVM and its varied libraries (reusable by all other languages – not just Clang, so create ONCE, reused many times):

http://llvm.org/releases/2.7/docs/UsingLibraries.html

LLVM LInk Time Optimization:

http://www.slideshare.net/vivekpansara/llvm-seminar

http://llvm.org/docs/Passes.html

Good thing is: these LLVM tools are reusable on binary output generated from different frontend (eg, Ruby, ActionScript etc) and not just Clang.

Advertisements

4 responses to this post.

  1. raspberry pi kernel compiled using Clang:

    http://llvm.linuxfoundation.org/index.php/Demo

    Reply

  2. Steps as given here:

    http://llvm.linuxfoundation.org/index.php/Main_Page

    Get the latest SVN version of clang (v3.5 or higher: You need named register support which isn’t in v3.4)

    Use the LLVMLinux kernel tree (recent mainline with latest LLVMLinux patches applied)
    git clone git://git.linuxfoundation.org/llvmlinux/kernel.git
    Build your kernel, making sure to set HOSTCC/CC and optionally ARCH/CROSS_COMPILE.

    For native compiling (like for x86_64): make HOSTCC=clang CC=clang
    For cross: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- HOSTCC=clang CC=clang
    For cross: make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- HOSTCC=clang CC=clang
    You may find you need to set GCC_TOOLCHAIN= if the above doesn’t work.

    The compilation output captured here:

    http://pastebin.com/QyviYA2U

    Some of the compilation were still done using gcc, and replacing with clang-3.5:

    + clang-3.5 -Wp,-MD,arch/x86/kernel/.bootflag.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include -I/sda1/home/tteikhua/Downloads/linux-3.15.7/arch/x86/include -Iarch/x86/include/generated -Iinclude -I/sda1/home/tteikhua/Downloads/linux-3.15.7/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/sda1/home/tteikhua/Downloads/linux-3.15.7/include/uapi -Iinclude/generated/uapi -include /sda1/home/tteikhua/Downloads/linux-3.15.7/include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m32 -msoft-float -mregparm=3 -freg-struct-return -mno-mmx -mno-sse -fno-pic -mpreferred-stack-boundary=2 -march=i686 -mtune=generic -maccumulate-outgoing-args -Wa,-mtune=generic32 -ffreestanding -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DCC_HAVE_ASM_GOTO -DKBUILD_STR(s)=#s -DKBUILD_BASENAME=KBUILD_STR(bootflag) -DKBUILD_MODNAME=KBUILD_STR(bootflag) -c -o arch/x86/kernel/.tmp_bootflag.o arch/x86/kernel/bootflag.c
    clang: error: unknown argument: ‘-mpreferred-stack-boundary=2’
    clang: error: unknown argument: ‘-maccumulate-outgoing-args’
    clang: error: unknown argument: ‘-fconserve-stack’
    clang: error: unsupported argument ‘-mtune=generic32’ to option ‘Wa,’
    clang: warning: optimization flag ‘-fno-delete-null-pointer-checks’ is not supported

    Reply

  3. More errors type:

    Doing a “git clone” of LLVM kernel:

    git clone git://git.linuxfoundation.org/llvmlinux/kernel.git

    And modifying specify gcc to use clang (not using the standard gcc):

    clang: error: unknown argument: ‘-mfentry’
    clang: error: unknown argument: ‘-mno-80387’
    clang: error: unknown argument: ‘-mno-fp-ret-in-387’
    clang: error: unknown argument: ‘-maccumulate-outgoing-args’
    clang: error: unknown argument: ‘-fno-var-tracking-assignments’
    clang: error: unknown argument: ‘-mfentry’
    clang: error: unknown argument: ‘-fconserve-stack’
    clang: warning: optimization flag ‘-fno-delete-null-pointer-checks’ is not supported

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: