Compiling DragonFly BSD using llvm/clang

Overview

This page tracks the progress on an effort to compile DragonFly with llvm/clang instead of gcc.

How?

cd /usr/src
env WORLD_CCVER=clang make -DNO_GCC44 buildworld
env WORLD_CCVER=clang make buildkernel KERNCONF=...

Notes

llvm/clang bug #3812 was reopened as it seems to be an actual bug. The patch (atomic.patch) is only intended to be TEMPORARY and will kill gcc compatibility! I will update this as soon as a llvm/clang is fixed.

Status (Kernel/pc32)

Type llvm/clang revisionStatus Remarks
GENERIC 66925 Doesn't compileFiled llvm/clang bug #3805
GENERIC 67025 Doesn't link (ncr, nsp, tmc) This commit should fix it
GENERIC 67025 Compiles, doesn't boot(see Current Log) - Filed llvm/clang bug #3812.
GENERIC 67025 Boots, seems to work ok network adapters removed from system
GENERIC 67025 Boots, survives stress test (buildworld)This patch temporarily fixes the previous boot issue (see NOTES), no further problems so far.
LINT 69545 Doesn't compile Filed llvm/clang bug #4022, also: clang doesn't know itry and another issue possibly related to the bug report

Status (Userland/pc32)

Type llvm/clang revisionStatus Problem areaRemarks
world 67025 Doesn't compile all Filed llvm/clang bug #3853
world 69545 Partially compiles lib/libcIssue with zero-size arrays (see note below), filed llvm/clang bug #4020

Zero-size arrays

While currently no decision has been made by the llvm/clang team on whether to support zero-size arrays or not, imho we should remove all its uses. Main problem currently occurs with genassym and related code (e.g. asmcontext.c (lib/libc)), as the output is not correct for clang due to some array sizes being 1 instead of 0. (see llvm/clang oddities - zero-size arrays)

Related llvm/clang bug reports

Bug #Bug DescriptionAffects Status
3805ccc ignores -x assembler-with-cppbuild of locore.sFixed
3812assembler doesn't properly process clobber,input and output register listsatomic_intr_cond_try in atomic.hOpen
3822failed assertion with -O2build of GENERIC with -O2Fixed
3853__thread keyword not supportedbuild of all userland base toolsFixed
4007 clang doesn't know -Werror-foo is the same as -Werror=foobarrage of warnings during make dependFixed
4020clang doesn't allow zero-sized arraysbuild of lib/libcNew
4022incorrect handling of __inlinebuild of LINTNew

Current Log

This is the log of the previous problem which already was solved with a temporary fix (see atomic.patch above) and which was reported to llvm/clang for a permanent fix.
Page fault during DHCP configuration at boot:
Fatal trap 12: page fault while in kernel mode
Fault virtual address = 0x0
fault code = supervisor write, page not present
code segment = base 0x0
Stopped at atomic_intr_cond_try+0xC: btsl $0x1f, 0(%eax)

llvm/clang oddities

zero-size arrays

llvm/clang doesn't support zero sized arrays and automatically generates arrays with a size 1 when a zero-size array is specified. This causes problems with current genassym and asmcontext.c (lib/libc) as these rely on zero-sized arrays.
This also makes it impossible to use make depend with clang for sys.

__i386__ vs i386

NOTE: This issue has been fixed in this commit.