HeadlinesBriefing favicon HeadlinesBriefing.com

GitHub Chibil: C Compiler for .NET Bridges Legacy and Modern

Hacker News •
×

Chibil is a C compiler rewritten in C# to target .NET IL (MSIL), enabling developers to compile C code for modern .NET ecosystems. Its most notable achievement is running DOOM (PureDOOM), demonstrating its ability to handle complex legacy applications. The tool operates by generating COFF OBJ files, which are binary-compatible with MSVC output in /clr mode, allowing seamless integration with Visual Studio’s link.exe for final linking. This compatibility lets users mix chibil-produced object files with C++/CLI code, expanding its utility in hybrid projects.

The technical foundation relies on converting C source to assembly via asm2obj, which produces COFF objects. A minimal C runtime stub in the crt directory provides a runnable `main` function, dispatching to standard C semantics. While this setup works for standalone executables, consuming compiled code from .NET requires reflection—methods like `Module.GetMethod` must locate and invoke chibil’s functions. This limitation highlights the tool’s current focus on execution rather than seamless integration.

Practical applications extend to domains needing C code in .NET, such as game engines or embedded systems. Tools like coffobjdumper.cs aid in debugging by exposing COFF OBJ structures, complementing ILDASM and dumpbin.exe. However, chibil’s lack of a full C standard library and reflection-based interoperability constraints mean it’s not yet a drop-in replacement for traditional compilers. Its value lies in bridging legacy C code with .NET’s modern toolchain, offering a pragmatic solution for specific use cases rather than a universal replacement.