mov eax , cr0
or eax , 0x01
mov cr0 , eax



back to months list

Project : The "Microkernel" Operating System

Journal Entry Date : 2025.11.01

Okay, I made a huge decision..

I decided to change the kernel's compiler to clang!

First, it's because I realized x86_64-elf cross compiler is not really universal, and I want to make the kernel compilable for every platform. Why didn't I choose gcc? Although gcc is a good option, and I've been using it for a very long time, clang is cross-compiled in default, which makes it easier to implement architecturally flexible build system. Also, there's lots of missed errors that x86_64-elf gcc didn't catch that clang caught, so I think clang is better in terms of reporting errors and bugs.

One problem is that.. when I changed the compiler to clang, I thought everything's gonna be all the same, but apparently there's lots of unidentifiable errors that only occurs when compiled in clang. I don't know why, but whenever the kernel reaches the device driver initialization, it just throws Invalid Opcode exception. I think it's something to do with new operations, and my guess is that something in my code has corrupted the code segment of the kernel, and the kernel has executed that portion of the code, which is an invalid opcode.

As you see in the picture, pmem_alloc is the point where the invalid opcode occurs. When I debugged the kernel, pmem_alloc works fine until at some point during the execution it throws Invalid Opcode exception. That behavior feels like a sign that the code is being corrupted during execution. I don't know why changing the compiler into clang is creating this error, but I suspect it might be because there was some bug in a code that wasn't apparent when compiled in x86_64-elf, but became apparent in clang due to the difference in how both compilers work.

So, my plan here is to implement KASan first. I'm gonna make a new copy of kernel called "microkernel-kasan", and implement the KASan from there. Why don't I do this to the main kernel? Because, I want to completely remove the potentially buggy code(device driver parts) and work soley on making kernel infrastructures more secure and not error-prone. I'm removing all the device driver related codes and work on the bug catching mechanisms from that.