Building FreeBSD with clang/llvm

This is work in progress, play at your own risk

The kernel builds and boots multiuser with clang/llvm trunk.

Needed files and patches

memmove for freestanding environment

http://www.vlakno.cz/~rdivacky/memmove.c

hook memmove up to build

http://www.vlakno.cz/~rdivacky/memmove.patch

ANSI vs. K&R prototype integer promotion

http://www.vlakno.cz/~rdivacky/int-promotion.patch

clang/llvm bugs tracked

Bug

Reason

URL

ccc/clang should recognize code generator target features

build system integration with ccc

http://llvm.org/bugs/show_bug.cgi?id=3604

clang refuses wchar_t foo[]

blocks userland build

http://llvm.org/bugs/show_bug.cgi?id=3097

error: cannot codegen this constant expression yet

blocks i386 kernel

http://llvm.org/bugs/show_bug.cgi?id=3463

Quickstart

Install the llvm-devel port.

# cd /usr/ports/devel/llvm-devel/
# make install

Copy this ccc wrapper script and make it executable.

# !/bin/sh

skip=0
for i in "$@" ; do
    if test $skip = 1; then
        skip=0
        continue
    fi
    skip=0
    case $i in
        -include) skip=1 ;;
        -I*) ;;
        hack.c) ;;
        *.c)
            asm=`basename $i |  sed s/"[.]c"/.s/`
            ccc -S -Xclang -code-model=kernel -Xclang -mcpu=i686 \
                -Xclang -mattr=-mmx,-3dnow -Xclang -disable-red-zone \
                -femit-all-decls "$@"
            gcc -g -mcmodel=kernel -c -x assembler $asm
            exit $? ;;
        *) ;;
    esac
done
exec ccc "$@"

Start the build.

# cd /sys/amd64/conf
# config -d /usr/obj/llvm GENERIC
# cd /usr/obj/llvm
# env CC=<path to script> COPTFLAGS=-O WERROR= make
# make KERNEL=llvm install

Boot it.

OK boot llvm

Known issues