c4
stage0
Our great sponsors
c4 | stage0 | |
---|---|---|
11 | 22 | |
9,076 | 869 | |
- | - | |
0.0 | 3.9 | |
3 months ago | about 2 months ago | |
C | Assembly | |
GNU General Public License v3.0 only | GNU General Public License v3.0 only |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
c4
- A tiny hand crafted CPU emulator, C compiler, and Operating System
-
Running the "Reflections on Trusting Trust" Compiler
The C4 compiler [https://github.com/rswier/c4] is a self-hosting compiler for a subset of the C programming language that produces executable x86 code. You can understand and audit this code in a couple of hours (its 528 lines).
It could be an interesting exercise to bootstrap up from something like this to a working linux environment based solely on source code compilation : no binary inputs. Of course a full linux environment has way too much source code for one person or team to audit, but at least it rules out RoTT style binary compiler contamination.
- AoikC4x86Study: Line-by-line comments to c4.c and c4x86.c files
-
Flattening ASTs (and Other Compiler Data Structures)
I was surprised to see nodes still have two pointers ("references") given that you now know that that the first pointer will always point exactly to the next node. I've see https://github.com/rswier/c4 use that. Granted it doesn't make for the most readable code, but it's even smaller and faster.
-
vermin_vm: Virtual Machine(~400 lines) + Assembler(~800 lines) written in C
VMs with simple instruction sets is a fun topic. Some years ago I got inspired by the amazing rswier/c4 compiler by Robert Swierczek and explored the smallest instruction set I could get away with to create VMs that could run non-trivial workloads.
-
Hand-optimizing the TCC code generator
C4 comes to mind (C in 4 functions), https://github.com/rswier/c4.
have you considered adding a backend for LLVM? perhaps a bit heavyweight, but it could be a good way to get C/C++, fortran, rust, etc. if that's something you'd like!
- What is the simplest self-compiling subset of C?
-
Compilers Are Hard
...or in other words, "they're hard only because you make them hard".
That said, I think C4 makes a better example of how simple it can be:
https://github.com/rswier/c4/blob/master/c4.c
(Previously on HN at https://news.ycombinator.com/item?id=8558822 and https://news.ycombinator.com/item?id=22353532)
stage0
- Running the "Reflections on Trusting Trust" Compiler
- Goodbye to the C++ Implementation of Zig
-
Nixpacks takes a source directory and produces an OCI compliant image
Somewhat tangential, but I'm curious how big the bootstrap seed for Nix is. That is, if you wanted to build the entire world, what's a minimum set of binaries you'd need?
Guix has put quite a bit of work into this, AFAIU, and it's getting close to being bootstrappable all the way from stage0 [0]. Curious if some group is also working on similar things for Nix.
-
Common libraries and data structures for C
Even if they aren't, people absolutely should be able to bootstrap new platforms from scratch. It's important to have confidence in our tools, in our ability to rebuild from scratch, and to be safe against the "trusting trust" attack among other things.
Lately I've been catching up on the state of the art in bootstrapping. Check out the live-bootstrap project. stage0 starts with a seed "compiler" of a couple hundred bytes that basically turns hex codes into bytes while stripping comments. A series of such text files per architecture work their way up to a full macro assembler, which is then used to write a mostly architecture-independent minimal C compiler, which then builds a larger compiler written in this subset of C. This then bootstraps a Scheme in which a full C compiler (mescc) is written, which then builds TinyCC, which then builds GCC 4, which works its way up to modern GCC for C++... It's a fascinating read:
https://github.com/oriansj/stage0
https://github.com/fosslinux/live-bootstrap/blob/master/part...
Even if no one is "using" this it should still be a primary motivator for keeping C simple.
- A minimal C compiler in x86 assembly
- My boundaries as an open source developer
-
Bitcoin v22.0 and Guix; Stronger defense against the "Trusting Trust Attack"
Stage0 Project
- Trojan Source: Invisible Vulnerabilities
-
Trustworthy Computing in 2021
It's great to see that more people are still working on this and that people have an interest.
If you are interested in this kind of thing, then you'll also want to check out LibreBoot[1] and Bootstrappable Builds[2]. The latter is working with stage0 [3] and mes [4] to bootstrap Guix (among other projects.) All of that is further down the chain, but we'll need it if we want to build trustworthy systems.
2. https://www.bootstrappable.org
-
[Rust advocates] demean software that's not memory safe the way that politicians use their words to sow anger. C has won, and Rust blew it's shot aiming at C++ instead.
Bootstrap compiler != PL compiler. See also stage0. Compiler can be cross-compiled to architectures, whereas a bootstrap compiler can not. For other differences see the stage0 repository.
What are some alternatives?
rizin - UNIX-like reverse engineering framework and command-line toolset.
arocc - A C compiler written in Zig.
chibicc - A small C compiler
libcperciva - BSD-licensed C99/POSIX library code shared between tarsnap, scrypt, kivaloo, spiped, and bsdiff.
bug - Scala 2 bug reports only. Please, no questions — proper bug reports only.
swc - Rust-based platform for the Web
bcompiler - Mirror of http://www.rano.org/bcompiler.tar.gz, with a bootstrap script
sc - Common libraries and data structures for C.
pkgconf - package compiler and linker metadata toolkit
qbe-rs - QBE IR in natural Rust data structures
ccan - The C Code Archive Network