13 ms·
Obfuscated Tiny C Compiler
- lnyan 6y agoPast discussion: 2018 https://news.ycombinator.com/item?id=17335856 https://news.ycombinator.com/item?id=17335856 ------ Tiny C Compiler is also a great project: https://bellard.org/tcc/ https://bellard.org/tcc/ https://news.ycombinator.com/item?id=23617461 https://news.ycombinator.com/item?id=23617461
- whitten 6y agoIs the an annotated unobfuscated version ?
- ghaberek 6y agoIt started as that but it's since turned into completely usable C compiler that supports 32-bit and 64-bit x86 and ARM platforms. There are still developers adding to the project every day. https://repo.or.cz/w/tinycc.git https://repo.or.cz/w/tinycc.git https://lists.nongnu.org/archive/html/tinycc-devel/ https://lists.nongnu.org/archive/html/tinycc-devel/
- funkisjazz 6y agois it practical in any way?
- mythz 6y agoYes, for winning IOCCC competitions! Which would normally be a great CV badge to demonstrate your skills to prospective employers, but likely of little consequence if you're Fabrice.
- jacquesm 6y ago> Which would normally be a great CV badge to demonstrate your skills to prospective employers Not many employers would know of the IOCCC.
- bregma 6y ago> Not many employers would know of the IOCCC. Sure. But who wants to work flipping burgers, greeting shoppers, or doing web front-ends for the rest of their life?
- regularfry 6y agoIf you have the sort of brain that makes winning IOCCC entries, it is highly probable that a candidate employer who has not heard of it is not, in fact, prospective.
- bidirectional 6y agoAnyone interviewing an IOCCC winner probably has.
- f00zz 6y agocan confirm source: won the IOCCC
- em500 6y agoIt's probably of little consequence for his employment, but Bellard has won a few IOCCC prices: https://www.ioccc.org/winners.html#B https://www.ioccc.org/winners.html#B
- scruffyherder 6y agoAt one point a variation of it could compile a Linux kernel (very fast too!) and boot from the same ISO. Of course GCC or LLVM produced better optimised code, but TCC, being so small runs so much faster.
- notorandit 6y agoIt isn't as it compiles a subset of c. Nonetheless it's a gem!
- wolf550e 6y agoSuppose you want to defeat a "Reflections on Trusting Trust" attack and bootstrap a toolchain source code you believe is clean to produce binaries that are clean. You need to compile llvm/clang (or gcc). You start with something small you can audit manually, use it to build binaries that can compile llvm, then use llvm to build itself to get an optimized compiler that doesn't have malicious code to recognize the password check inside the login binary and emit machine code that is not faithful to the source code.
- Drakim 6y agoHow do you know that your text editors aren't compiled to hide the payload when examining this compiler, thus perpetuating the hidenness?
- xmodem 6y agoIf you wanted to solve for that, you would have to build a computer like the monster6502 [1] to run the compiler on, and visually inspect the memory contents. 1: https://monster6502.com/ https://monster6502.com/
- MawKKe 6y agoHow do you know the person who designed that isn't in on it?
- archi42 6y agoThe thing is pretty easy to verify. The ultimate question is: How far do you need to go until you believe that the earth is indeed not flat? Do you trust your teachers? Stand on a tall building? Take a balloon ride? A plane? A spaceship? Then still, at which point can you rule out that the earth just appears to be a ball due to some yet-to-be-explained phenomenon (gravitational anomaly?) but is indeed flat? (The correct answer of course is "turtles all the way down").
- 6y ago
- cb321 6y agoAnother practical application is using tinycc as a backend compiler for Nim [1]. I set up my nim.cfg to default to this for a rapid edit-compile-test cycle (usually under 250 millisec), with a quick define switch to move to gcc-optimized code. Similar is likely possible for other prog.langs that emit C. One helpful feature for the full round-trip to an executable file is a built-in object file linker. Also, libtcc can be used as a library to "compile a string" and then run it which is the JIT application mentioned elsewhere in this thread. [1] https://nim-lang.org https://nim-lang.org
- caf 6y agoAndroid once included a library "libacc", (the Android "Almost" C Compiler") which was based on the deobfuscated version of this. https://android.googlesource.com/platform/system/core/+/eclair-release/libacc/acc.cpp https://android.googlesource.com/platform/system/core/+/ecla...
- ar7hur 6y agoFabrice Bellard should receive a Turing award. Who agrees?
- enriquto 6y agoI don't see the point. But Turing would have received the Bellard award, in a saner timeline.
- varispeed 6y agoMaybe the big unicorns who surely got hefty profits off of his work should pool together a billion dollar reward for him.
- sn41 6y agoAlso, in a saner timeline, Turing might have well received the Fields medal. His contributions to probability theory, and morphogenesis are amazing in addition to being the father of computer science, and codebreaker. All of the work was done before he was 40. [1] https://www.jstor.org/stable/2974762?seq=1#metadata_info_tab_contents https://www.jstor.org/stable/2974762?seq=1#metadata_info_tab...
- sillysaurusx 6y agoI absolutely adore TCC, fwiw. It’s the base project that this one is derived from. Like all of bellard’s work, this is legit and also extraordinarily high quality. At one point before I got bored I basically had a game engine that took C source code as scripting inputs. Totally stupid, and worked great thanks to this.
- jfk13 6y ago> [TCC is] the base project that this one is derived from The relationship is actually the other way around, at least according to this page: "NOTE: My other project TinyCC which is a fully featured ISOC99 C compiler was written by starting from the source code of OTCC"
- sillysaurusx 6y agoOh! Thank you for the correction! I wasn't sure which was which, but TCC is so lovely. It's cool to hear some of its history.
- kybernetikos 6y agoSpeaking of mad genius ideas, my mind was blown by https://bellard.org/tcc/tccboot.html https://bellard.org/tcc/tccboot.html a boot loader able to compile and boot a Linux kernel directly from source code.
- mark-r 6y agoI love his JSLinux that allows you to boot Linux (or DOS or Windows!) in your browser. https://bellard.org/jslinux/ https://bellard.org/jslinux/
- iso8859-1 6y agoWhat do you think about chibicc in comparison? It supports C11. https://github.com/rui314/chibicc#chibicc-a-small-c-compiler https://github.com/rui314/chibicc#chibicc-a-small-c-compiler
- murkle 6y agoWebAssembly backend would be cool http://nongnu.13855.n7.nabble.com/WebAssembly-backend-td239060.html http://nongnu.13855.n7.nabble.com/WebAssembly-backend-td2390...
- vermilingua 6y agoI thought I could follow at least some of the unobsfucated C, and then this monstrosity: t = "++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!=\'g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b"; Could someone please explain what is going on in that routine?
- jedisct1 6y agoLooks like a type definition in Rust.
- neilalexander 6y agoThis made me smile :-)
- scoutt 6y agoIf it doesn't end with .unwrap() then it isn't Rust.
- cztomsik 6y agotrue :(
- bombcar 6y agoT is being assigned a string value that looks like line noise. I assume it's Perl.
- hu3 6y agoHaha. Thanks I needed that Monday morning laugh.
- userbinator 6y agoIt's funny to see the Perl comparison when APL-family languages normally have code that looks like that: https://github.com/Co-dfns/Co-dfns/tree/master/cmp https://github.com/Co-dfns/Co-dfns/tree/master/cmp
- smlckz 6y agobellard is a programming genius and true C hacker. his works are so great but how humble is his website! why doesn't he write blog posts? why he has so little online presence? hmm. let us wish him a long and productive life.
- jhoechtl 6y agoHe is concentrating on being creative = create = work. Valley startup hipster culture doesn't get this.
- mindhash 6y agoFound this article that seems to talk more about him than his own website. https://smartbear.com/blog/fabrice-bellard-portrait-of-a-super-productive-pro/ https://smartbear.com/blog/fabrice-bellard-portrait-of-a-sup... "Bellard doesn’t appear to promote himself—he politely declined to be interviewed for this profile"
- yuribro 6y ago>> why doesn't he write blog posts? why he has so little online presence? >> bellard is a programming genius and true C hacker. his works are so great ... It's probably related. Obviously it's his and only his decision, but I wonder if him slowing down to share the knowledge and skills could have been more productive in the sense that others could do similar work.
- cvlamp 6y agoI wonder if we could regain the level of intellectual maturity of the 19th and 20th century and not criticize those who already give away so much that they are not working hard enough. This is literally Animal Farm / team lead "multiplier" nonsense. And like in Animal Farm, the pigs profit.
- tccfan 6y agoHe shares the demystified code here: https://bellard.org/otcc/otccn.c https://bellard.org/otcc/otccn.c the TCC documentation sheds further light: https://bellard.org/tcc/tcc-doc.html#devel https://bellard.org/tcc/tcc-doc.html#devel
- ducktective 6y agoI wonder does Fabrice hang-out on HN, Reddit or some chat channels? I very much like to know his views on topics like Rust, RISC-V, Blockchain etc... I'm curious about his workflow, dev. machine, preferred distros, editors and the like :D An AMA or a technical interview done by someone knowledgeable in the field would be awesome!
- smlckz 6y agoHe has his own emacs clone named QEmacs[1] which I think he uses personally. He uses Subversion as his version control system (at least in developing QuickJS) according to this post[2] by him in quickjs-devel mailing list. [1]: https://bellard.org/qemacs/ https://bellard.org/qemacs/ [2]: https://www.freelists.org/post/quickjs-devel/Please-consider-moving-the-project-to-GitHub,5 https://www.freelists.org/post/quickjs-devel/Please-consider...
- ducktective 6y agoThanks! Good to know! I knew about his Emacs clone...I think Linus Torvalds uses something similar.
- mhd 6y agoLinus has his own port of the venerable MicroEmacs[1]. As does Walter Bright[2], by the way. qemacs is actually quite advanced, and even includes a basic HTML renderer (for the help). I was half joking that with quickjs, one now can make a reasonably modern web browser out of bellard-ware… [1]: https://github.com/torvalds/uemacs https://github.com/torvalds/uemacs [2]: https://github.com/DigitalMars/med https://github.com/DigitalMars/med
- freakynit 6y agoFabrice is a genius... how he manages to build all such stuff he builds?
- jacquesm 6y agoLack of distractions, doesn't care about fashion, intimate familiarity with tools and deep mathematical insight combined with hardcore coding skills.
- rsiqueira 6y agoHe also created QuickJS, that's javascript server side, like NodeJS but much faster to start programs. Just type "qjs your-script.js". I use it in my server because of its low overhead to start and run my microservices. https://bellard.org/quickjs/ https://bellard.org/quickjs/
- the_duke 6y agoAnd qemu... and ffmpeg. The productivity of Bellard is truly admirable.
- kizer 6y agoI wonder if TCC could be used in a JIT.
- my123 6y agoYes, it's an officially supported use case.
- zserge 6y agoI did in my music/generative art app, where I compiled math expressions into native code using TCC as a backend. Actually, it was _so_ much easier than dynasm and other JIT libraries, and so little code, and yet, it was a great performance boost already.
- newswasboring 6y agoIf I recall correctly the maximum binary data you can fit in the largest QR code is 2,953 bytes. This C compiler can fit on a qr code.
- kibwen 6y agoTrue, although "the largest QR code" is substantially more dense than most people have ever encountered: https://en.m.wikipedia.org/wiki/File:Qr-code-ver-40.svg https://en.m.wikipedia.org/wiki/File:Qr-code-ver-40.svg . People might not realize that QR codes scale up and down very gracefully; most QR codes that people have ever seen probably encode less than 80 bits.
- gregsadetsky 6y agoReminds me of a project a friend and I took part in, sending each other source code via postal mail. I ended up sending a QR code printed on film negative [0] to pack about 1k of bytes. Bellard's code is way more "information-dense" of course..! :-) [0] https://greg.technology/img/postal-codes.jpg https://greg.technology/img/postal-codes.jpg Edit: incredibly, pointing the iPhone camera app at the low-ish resolution photo of the QR code above works -- the QR code does decode. That's crazy.
- igravious 6y agoHiya, how did you print these on negative film?
- mirekrusin 6y agoYou drill a hole in lead plate, take uranium rock, rasberry pi and...
- gregsadetsky 6y agoIn Montreal, the really really great people at Borealis [0] made it extremely easy. I sent them a 300 DPI file by email, and they printed negatives from those files in a few days. Each negative cost about $8 to print. Finding a lab that did this online was pretty difficult at the time. If others have recommendations -- please chime in! Otherwise, I would strongly recommend considering Borealis (who I'm sure can ship the negatives by mail -- otherwise reach out and I can facilitate the mailing as I live here ha) [0] http://www2.borealislab.qc.ca/borealis/en-home http://www2.borealislab.qc.ca/borealis/en-home
- api 6y agoI really like this kind of minimal programming. If you like this check out /r/tinycode
- knuthsat 6y agoWhen I look at Knuth code snippets in CWEB I get the same vibes. He has a full implementation of garbage collecting zero suppressed binary decision diagrams that he used to count various stuff and it’s insanely elegant and minimal.
- api 6y agoThe way I approach programming in general is to put a ton of thought in up front about how to do the least amount of work possible. Is there a very simple elegant way to do this? Can I collapse it down even more? Could I do it in just one or a few source code files of reasonable size?
- zserge 6y agoMany years, and still impressing. I wonder if similar projects exist for other languages (preferably, without a use of `eval()` and friends).
- kmm 6y agoI'm sorry if this is a stupid question, but why wouldn't the non-obfuscated versions be able to compile themselves?
- xmodem 6y agoWithout having looked at the code I'm guessing he used unimplemented language features in the non-obfuscated version, then re-wrote to avoid using them in the obfuscated version.
- GuB-42 6y agoTCC, the actually useful and non-obfuscated version can compile itself of course. https://bellard.org/tcc/ https://bellard.org/tcc/ But the fact a C compiler can compile itself is not very impressive. Making it fit into 2048 bytes of obfuscated code is.
- jaywalk 6y agoIt's literally explained in the first line on the page, where he says he wrote it "in order to win the International Obfuscated C Code Contest (IOCCC) in 2002." So it's not that it wouldn't work, but it obviously wouldn't have worked for that contest.
- anta40 6y agoI wonder if someone already modified this so it also runs on Windows & Mac. Hmm....
- stephen82 6y agoTo be personally Fabrice Bellard is the Leonardo da Vinci of technology with specialization in C. This guy knows how to push the language's limits and he is the main reason I switched back to C for good.
- stephen82 6y ago*to ME...ugh, all these typos lately /facepalm...
- bor100003 6y agoI always check the topics on Bellard here on HN, really insightful. Let's don't forget the obligatory: "Can he invert a binary tree on a whiteboard though?"
- chromanoid 6y ago> Let's don't forget the obligatory: "Can he invert a binary tree on a whiteboard though?" Probably yes.
- bidirectional 6y agoThe funniest thing about the 'invert a binary tree' meme is that it genuinely is a simple, 5-liner problem that most programmers could solve in five minutes, it just sounds intimidating.
- varispeed 6y agoFor some reason the thought that I will never be as productive as himself brings me peace. Huge respect. I remember looking at his entry in 2002 like it was yesterday, that was a pleasurable mind fk.
- dang 6y agoIf curious see also 2018 https://news.ycombinator.com/item?id=17335856 https://news.ycombinator.com/item?id=17335856 2011 (a bit): https://news.ycombinator.com/item?id=2722494 https://news.ycombinator.com/item?id=2722494
- mark-r 6y agoI knew Bellard had written a very functional Tiny C compiler. I had no idea he wrote it more than once. My respect for him just continues to grow.
- userbinator 6y agoIf you find this level of density interesting, it may be illuminating to know that there are programmers who work with code that is as dense if not more so, every day as part of their job, not even trying to be dense or win the IOCCC. Of course, I am referring to the users of APL family languages: https://news.ycombinator.com/item?id=25902615 https://news.ycombinator.com/item?id=25902615 https://news.ycombinator.com/item?id=13565743 https://news.ycombinator.com/item?id=13565743 If you are not ready for APLs, then you can inspect this, not "obfuscated", but still dense, self-compiling C-subset JIT: https://news.ycombinator.com/item?id=8746054 https://news.ycombinator.com/item?id=8746054