4 ms·
Zig specifics aside… build it from source using what? Another compiler. Okay, so you can compile that one from source. But what does that? Another compiler. Un
by amscanne 5y ago
Zig specifics aside… build it from source using what? Another compiler. Okay, so you can compile that one from source. But what does that? Another compiler.
Unless you’re recording memory contents and executing instructions by hand, you’ve just discovered the Ken Thompson hack. At some point the pragmatic thing is to trust some bits from a trusted source (e.g. downloaded from an official repo w/ a known cert, etc.).
- randyrand 5y agoYou just need 1 compiler written in assembly, and work your way up from there. C17 -> assembly of your choice, written in assembly Zig -> C17 “transpiler”, written in C17
- drfuchs 5y agoWhy do you trust the assembler you got from somewhere any more than a compiler?
- randyrand 5y agoBecause hand written assembly is readable!
- chongli 5y agoI believe GP used assembler to refer to the program which reads your hand-written assembly and produces a binary. That program was presumably given to you so you need to trust it. No, the only way to solve this problem is to start with a computer entirely devoid of code and bit-bang your assembler into the machine with switches, the way the first users of the MITS Altair did it.
- ByteJockey 5y agoYou can also bootstrap the way lisp did and write the fist compiler in the language and get a bunch of grad students to hand-compile it. But, yeah if you don't have a bunch of grad students at the ready, an assembler hand-written in machine code is the only option if you want to trust the entire stack. Though I'm not sure what that would get you. I don't know of any higher language compilers that are written directly in assembly these days, so you'd never be able to compile your C/C++ compiler.
- chongli 5y agoThere was a C compiler written in assembly posted on HN 4 years ago [1]! So yeah, if you wanted to, you could bit-bang an assembler capable of assembling a simple C compiler, then in your simple subset of C you could implement a full C compiler, and from there you can do anything you want! The grad student approach also sounds interesting. A basic Lisp interpreter can easily fit on a single letter-sized sheet of paper. A single person could hand-compile that, it would just take longer. But, if you're living alone in a cabin in the woods with your own hand-built computer and a personal library of computer books in hard copy, that would be a totally feasible project. [1] https://news.ycombinator.com/item?id=17851311 https://news.ycombinator.com/item?id=17851311
- ByteJockey 5y agoI wasn't aware that there were any existing C compilers made in asm for modern architectures. I guess I shouldn't be too surprised. That's cool, thanks for showing me.
- pjmlp 5y agoIt might be, but have you also validated the microcode executing it? Or the Verilog/VHDL for the logic gates used by the CPU, for that matter?
- randyrand 5y agoSecurity is multifaceted. Ideally, yes. But you still will be more secure than having multiple security holes.
- chakkepolja 5y agoSee https://dwheeler.com/trusting-trust/ https://dwheeler.com/trusting-trust/
- MichaelBurge 5y agoRice's Theorem makes the Ken Thompson hack impossible in general. He only executed his hack in a single short-term demonstration against a specific target, but it's not possible to make a "long-con" against an open-source project with lots of activity and lots of people building it even if you find a way to infect nearly all of those people.