TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

C compiler with support for structs written in Assembly

241 pointsby z29LiTp5qUC30nover 6 years ago

17 comments

mmastracover 6 years ago
I started working on a similar VM-based bootstrap for getting from bare metal to C compiler. If anyone is interested in collaborating let me know.<p>The idea is that you implement a simple, ASCII-based VM for your platform and that&#x27;s enough to bootstrap a number of different assemblers, to a basic C compiler, to a full-fledged C compiler and (very minimal) POSIX environment.<p>The goal is twofold: a base for trusted compilation like this one, and a way to guarantee long-term executability of various archiving programs (ie: guarantee that you can unrar a file in 20 years with minimal work).<p>EDIT: very rough repo is here - <a href="https:&#x2F;&#x2F;github.com&#x2F;mmastrac&#x2F;bootstrap" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mmastrac&#x2F;bootstrap</a>
评论 #17852132 未加载
评论 #17854256 未加载
评论 #17855102 未加载
评论 #17852120 未加载
Filligreeover 6 years ago
As for &#x27;why bootstrap&#x27;...<p>Since Reflections on Trusting Trust has been linked already, I&#x27;m going to offer something else. Today&#x27;s nightmare: <a href="https:&#x2F;&#x2F;www.teamten.com&#x2F;lawrence&#x2F;writings&#x2F;coding-machines&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.teamten.com&#x2F;lawrence&#x2F;writings&#x2F;coding-machines&#x2F;</a>
评论 #17856211 未加载
评论 #17856005 未加载
评论 #17856312 未加载
exikyutover 6 years ago
Vital details:<p>From <a href="http:&#x2F;&#x2F;git.savannah.nongnu.org&#x2F;cgit&#x2F;stage0.git&#x2F;tree&#x2F;README" rel="nofollow">http:&#x2F;&#x2F;git.savannah.nongnu.org&#x2F;cgit&#x2F;stage0.git&#x2F;tree&#x2F;README</a> (which also declares GPL3):<p>&gt; <i>This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of Compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.</i><p>&gt; <i>Additionally, all code must be able to be understood by 70% of the population of programmers. If the code can not be understood by that volume, it needs to be altered until it satifies the above requirement.</i><p>From <a href="https:&#x2F;&#x2F;savannah.nongnu.org&#x2F;projects&#x2F;stage0&#x2F;" rel="nofollow">https:&#x2F;&#x2F;savannah.nongnu.org&#x2F;projects&#x2F;stage0&#x2F;</a>:<p>&gt; <i>A class of minimal bootstrap binaries that has a reproducible build on all platforms. Providing a verifiable base for defeating the trusting trust attack.</i><p><i>Cooooooool.</i>
评论 #17851741 未加载
gmuecklover 6 years ago
It would be kind of cool to start small with entirely verifiable hardware for the first bootstrapping stages.<p>I am phantasizing about a sort of ceremony in which the whole bootstrap process is done live in front of an audience starting with a discrete computer (using e.g. this board as a CPU <a href="https:&#x2F;&#x2F;monster6502.com" rel="nofollow">https:&#x2F;&#x2F;monster6502.com</a>), absolutely no electronic non-volatile memory and the first programs read into the computer from punch cards or punch tape. This would be used to create later stages for more powerful hardware and the end result (after maybe one or two hardware switches) is hopefully a minimal C compiler or similar that can be used to bootstrap production compilers like GCC. Ideally, this binary is shown to be completely identical to a binary built by a typical build process.<p>Even if such a ceremony is ultimately not very useful, it could still be seen as a kind of artistic performance.
pnathanover 6 years ago
Very, very nice. Not often you get to study non-trivial assembly programs.<p>Some context is this: <a href="https:&#x2F;&#x2F;bootstrapping.miraheze.org&#x2F;wiki&#x2F;Stage0" rel="nofollow">https:&#x2F;&#x2F;bootstrapping.miraheze.org&#x2F;wiki&#x2F;Stage0</a>
评论 #17853349 未加载
lboassoover 6 years ago
Bootstrapping a compiler is fun. I wrote a self-hosting compiler for the Oberon-07 language, targeting the JVM: <a href="https:&#x2F;&#x2F;github.com&#x2F;lboasso&#x2F;oberonc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lboasso&#x2F;oberonc</a><p>Initially the project was written in Java, after enough features were working the bootstrap phase could start.
pomeover 6 years ago
If someone is interesting about how to bootstrapping, this[0][1] tutorial is just awesome, tiny compiler from nothing (raw machine codes and hex!) to the self-hosting!<p>[0] <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20120712111627&#x2F;http:&#x2F;&#x2F;www.rano.org&#x2F;bcompiler.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20120712111627&#x2F;http:&#x2F;&#x2F;www.rano.o...</a> [1] <a href="https:&#x2F;&#x2F;github.com&#x2F;certik&#x2F;bcompiler" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;certik&#x2F;bcompiler</a> (Fork in GitHub)<p>Also worth check - <a href="https:&#x2F;&#x2F;www.t3x.org&#x2F;t3x&#x2F;book.html" rel="nofollow">https:&#x2F;&#x2F;www.t3x.org&#x2F;t3x&#x2F;book.html</a> :-)
sandovover 6 years ago
Then how do they usually bootstrap C? Do they write a C compiler without structs, then program a C with structs compiler using C without structs?
评论 #17851850 未加载
tempodoxover 6 years ago
What assembler syntax is this? The comments don&#x27;t say.
评论 #17852052 未加载
评论 #17852056 未加载
userbinatorover 6 years ago
I don&#x27;t recognise the architecture despite it saying x86, but it reminds me of ARM.<p>Recursive descent seems to be the go-to parsing technique for compilers both big and small now. I like how all the repetitive functions for each level have been refactored into a &quot;general_recursion&quot; function, but if you want to make it even simpler and yet more extendable, table-driven precedence climbing would be ideal:<p><a href="http:&#x2F;&#x2F;www.engr.mun.ca&#x2F;~theo&#x2F;Misc&#x2F;exp_parsing.htm#climbing" rel="nofollow">http:&#x2F;&#x2F;www.engr.mun.ca&#x2F;~theo&#x2F;Misc&#x2F;exp_parsing.htm#climbing</a>
评论 #17852832 未加载
评论 #17853079 未加载
pecgover 6 years ago
This program looks interesting. Maybe it could help in the bootstrap process of tcc, though I don&#x27;t know if it is written in ANSI C. On a related note, I will try to test compiling lua&#x27;s runtime environment and interpreter, because I&#x27;m sure it is written using standard C already.
评论 #17852361 未加载
评论 #17852124 未加载
another-cuppaover 6 years ago
Just a few hours ago there was a conversation in #gentoo-chat about the Thompson attack. I wondered how difficult it would be to write a C compiler that can compile GCC. How far away is this?
评论 #17851944 未加载
评论 #17851933 未加载
评论 #17852061 未加载
sam0x17over 6 years ago
This is super impressive. What might be some compelling technical reasons to use this over existing C implementations? I just don&#x27;t know so I thought I&#x27;d ask.
pavelbrover 6 years ago
If I wanted to actually run this compiler, how would I build it?
评论 #17853089 未加载
newnewpdroover 6 years ago
I&#x27;d appreciate a bare minimum C compiler capable of building gcc written in either assembly or x86 machine code that can be trivially audited in as-executed form.
jacquesmover 6 years ago
That&#x27;s impressive.<p>I wished I had time today to put this through its paces.
评论 #17853095 未加载
maxpertover 6 years ago
Mind blown