Compiling the kernel with another compiler ?

Making abstraction of it is wise, is it possible to compile the freebsd kernel with a clang compiler of choice ?
Is it possible to compile the kernel with gcc or tcc ?
[ Or are the kernel and the compiler version tighthly integrated ?]
 
That's not supported. Probably not entirely impossible, but not a simple thing either.
It seems there is some support for using gcc from ports (in a variant directly targeting FreeBSD) to build world, not sure whether it would apply to the kernel as well, see /usr/src/Makefile.
But then, I just have to ask: What's the point?
 
1. An exercise, or how do you do it, learn something.
2. What are the problems and why ?
3. Compatible software should be independent of the compiler/type/version. Does this apply to the kernel as well ?
 
For instance if you want to use clang to compile in gentoo packages you should:
Code:
CC="clang"
CXX="clang++"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"
LDFLAGS="${LDFLAGS} -fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -Wl,--as-needed"
And for hardening:
Code:
_HARDENING_FLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2"
CFLAGS="${CFLAGS} ${_HARDENING_FLAGS}"
CXXFLAGS="${CXXFLAGS} ${_HARDENING_FLAGS}"
LDFLAGS="${LDFLAGS} -Wl,-z,relro,-z,now"
I try to understand this.
 
Compatible software should be independent of the compiler/type/version. Does this apply to the kernel as well ?
If by "compatible software", you mean code using nothing but standard C, then, sure. That's completely impossible for some parts of an operating system, like e.g. a kernel. The ABI needs to be defined (things like calling conventions, including those for syscalls, sizes of some standard types depending on the machine arch, and so on). For some of that, some assembler code is needed, for other aspects, the compiler must know about it. A kernel needs assembler for other things as well, e.g. bootstrapping code. There are probably lots of other things where "just standard C" won't do.
I try to understand this.
Those are just "standard" (as in convention) variables any sane build system understands. You could use most of them with FreeBSD ports as well (although some of the contents might not match). I don't see how compiling the FreeBSD kernel with a different compiler would ever help understanding these variables. And btw, I strongly recommend against overriding them for port builds. Some ports will probably work, but you will run into very strange issues.
 
Back
Top