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 revision | Status | Remarks |
GENERIC | 66925 | Doesn't compile | Filed 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 revision | Status | Problem area | Remarks |
world | 67025 | Doesn't compile | all | Filed llvm/clang bug #3853 |
world | 69545 | Partially compiles | lib/libc | Issue 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 Description | Affects | Status |
3805 | ccc ignores -x assembler-with-cpp | build of locore.s | Fixed |
3812 | assembler doesn't properly process clobber,input and output register lists | atomic_intr_cond_try in atomic.h | Open |
3822 | failed assertion with -O2 | build of GENERIC with -O2 | Fixed |
3853 | __thread keyword not supported | build of all userland base tools | Fixed |
4007 | clang doesn't know -Werror-foo is the same as -Werror=foo | barrage of warnings during make depend | Fixed |
4020 | clang doesn't allow zero-sized arrays | build of lib/libc | New |
4022 | incorrect handling of __inline | build of LINT | New |
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.