It is possible to use the host compiler when you target i686, but that's NOT a good idea. And, believe me, adding "-m32 -march=i686" is not really THE problem here at all, as kernel projects require passing a ton of options to the compiler anyway.
The
first problem when using the host compiler comes when you need to build software (usermode programs) that will run on your kernel, not the kernel itself. That's a problem because
very likely your project won't be 100% compatible with Linux and Glibc. The majority of the kernel projects are not compatible with Linux at
binary level. But, some of them still offer a POSIX interface with a
custom libc implementation. So, now, how you will use the host compiler to build a regular program with a different libc? It's possible with GCC, but it's a
great mess. It requires the use of special "GCC scripts" to be passed with the "-specs" option and also compiler-wrapper scripts to have a simpler pseudo-regular compiler interface for the build system. A GCC script will set new include paths for system headers, the object file to use for _start, the default libc to link with and other stuff like that. But, that will not work with clang. You'll need a different solution for that compiler. Also, that approach has a
TON of traps and pitfalls. It's not worth in 99% of the cases.
The
second problem is that, if you write a kernel compatible with Linux, your project still
won't be 100% compatible with all the modern and advanced syscalls that glibc will use,
for years. So, even if you won't need to write a custom libc, you will still need to use lighter libc implementation like
libmusl or
uclibc-ng to build apps for your kernel. In this case you STILL will need a custom toolchain. I avoided building a custom toolchain myself by using prebuilt libmusl gcc-toolchains from:
https://toolchains.bootlin.com/. But, again, that comes at the price of being compatible with Linux at
binary level.
Most projects here don't do that, by choice.
The
third problem with using the host compiler is that generally it
won't work if you want to target anything other than i686. So, if you want to build for AARM64, you will still need to build a custom toolchain or, at least, a linux pre-built toolchain if you're in my case.