site banner

Friday Fun Thread for January 5, 2024

Be advised: this thread is not for serious in-depth discussion of weighty topics (we have a link for that), this thread is not for anything Culture War related. This thread is for Fun. You got jokes? Share 'em. You got silly questions? Ask 'em.

1
Jump in the discussion.

No email address required.

I finally did some work on my compiler after a long-ass break. That's a hobby project of mine, to write something that emits a standalone executable. Today I tackled calling conventions. I actually tried to write a patch for QBE to support Win64 calling convention first, but QBE is written in very terse C that I really didn't enjoy deciphering. It's not at atw levels of terseness, of course, but I have an additional excuse to not follow down that path: QBE, in true Unix fashion, doesn't do more than necessary: it reads code written in its own "slightly lower level than C" language and emits sufficiently optimized GAS code for the target architecture. After all, all self-respecting distributions have an assembler and a linker, don't they? Except I want a PE/COFF binary for Windows, which means relying on something like MinGW (and if I have to bring MinGW along, why not just program in C?) or writing the necessary modules myself, like Go.

Now all I need is to write some tests, add SysV and preferably Aarch64 (Win/SysV) calling conventions, factor out common functionality and I'll finally be able to generate some assembly and corrupt the stack.

Have you looked at TCC? It claims to support GAS assembly (as input and intermediate code for C compiling) and compiles for windows (and other platforms). I didn't read all the code but it looks reasonably structured. It's small enough you can incorporate it into a larger project, or use it as a library.

Yes, yes I have. The biggest problem with TCC is that it already exists and is practically feature-complete.

Fuck SysV x64 ABI, seriously. MS calling conventions might be slower, but they are so much easier to implement.