QBE - Compiler Backend: Version 1.3

55 points by orib 5 hours ago on lobsters | 6 comments

lorddimwit | 2 hours ago

One of my long-running hobbyist projects is a TRIPOS/Amiga Exec style little OS. No memory protection, flat memory map, message passing is just passing a pointer.

Having such a system be self-hosted is much easier with a small compiler that can produce PIE/PIC. Amiga-style libraries of course have to be PIC (obviously), but it’s also nice to not have to do a lot of extra load time patching of executables when they are loaded somewhere in the shared memory map.

GCC and Clang of course can do it but they’re enormous. TCC last I checked couldn’t do PIC. I need to look more into QBE.

I'm working on my own flat-memory-map, all PIE, syscalls-are-functioncalls OS called Ashet OS.

It's fairly advanced already, and is cross-platform.

I doubt i'll be able to self-host soon, as i need Thumb-2 codegen, and the only way i can get that running is writing my own compiler. This is sadly due to the constraint that everything must run from 8 MB of available RAM (excluding kernel code).

I use my own executable format .ashex which is created by converting an elf file. This process consumes a special section which is basically just an absolute jump, rewritten by the app loader to the actual syscall address.

The issue with flat memory systems is having nice support for shared objects, as i need compiler support for accessing all dynamic symbols through a register-stored variable, as otherwide you would not be able to share code between different applications.

Riolku | 2 hours ago

Does this project have overlapping goals with Cranelift? Can't quite seem to figure out when one would use QBE

acatton | 2 hours ago

QBE is the "OpenBSD" of compiler backends, simplicity and minimalism are their philosophy, in their own words, they aim "to provide 70% of the performance of industrial optimizing compilers in 10% of the code." Its competition are indeed Cranelift and LLVM.

Unfortunately in the past it has mostly been used by hobbyist languages and compiler implementation such as myrddin a new-C (I see it was the OG zig, hare or odin) which seems dead, or cproc a hobbyist C compiler implementation which is still alive.

But since it has been picked up by Hare, my hopes have been up. Here is the answer to your question: https://harelang.org/documentation/faq.html#why-qbe-instead-of-llvm

dysoco | 2 hours ago

I think it does, as well with LLVM.

I'm not that familiar with them, but there are plenty of comparisons out there. As far as I know QBE is supposed to be way simpler than those other two.

Really happy to have the new extern keyword. Although not mentioned in the release notes, this also works with thread, enabling initial-exec TLS. This is needed to access thread-local globals defined in other shared libraries (needed for ctype.h on FreeBSD). extern is also needed for regular global access in shared libraries (such as stderr) on platforms like macOS and Haiku. QBE-based compilers are now able to support a much larger set of operating systems and use-cases.

The performance improvements by Roland are also very appreciated. He did some really great work!