Exploring mullender.c – A deep dive into the first IOCCC winner
lainsystems.com
lainsystems.com
char code[] = { /* put your bytes here */ };
((void(*)())code)();
I believe it is technically UB, but it does exactly what you'd think it does, and if compilers started doing funny things with it, you wouldn't be able to write things like JITs at all. A tiny demonstration of this can be found at the bottom of C4x86: https://github.com/EarlGray/c4/blob/master/c4x86.cWorks on x86/x86_64 Linux:
char main[] __attribute__ ((section(".text"))) = "\xe8\x0d\0\0\0Hello world!\n"
#ifdef __x86_64__
"\x31\xc0\x8d\x50\x0d\xff\xc0\x89\xc7\x5e\x0f\x05\x31\xff\x8d\x47\x3c\x0f\x05";
#else
"\x31\xdb\x8d\x53\x0d\x59\x8d\x43\x04\x43\xcd\x80\x31\xdb\x8d\x43\x01\xcd\x80";
#endif
The meaning of "obfuscated C" as the contest requires was not well-defined at that time and had to be amended for a very long time. There are at least 5 more entries that abused and subsequently changed the rules at that time [1] [2] [3] [4] [5]. ([6] is an exception; this kind of abuse of the rules is allowed and now common.)
> [...] if compilers started doing funny things with it, you wouldn't be able to write things like JITs at all.
Well, see [7].
[1] https://www.ioccc.org/1987/biggar/hint.html
[2] https://www.ioccc.org/1988/spinellis.hint
[3] https://www.ioccc.org/1989/jar.1.hint
[4] https://www.ioccc.org/1993/lmfjyh.hint
[5] https://www.ioccc.org/1994/smr.hint
As it stands, it's very interesting to read but most examples are hard to run and I always end up going away unfulfilled.
This sort of trick should still be possible with modern compilers. GCC has the charming warning
warning: ‘main’ is usually a function [-Wmain]
if main is declared as something other than a function.Here’s someone who got it to work in 2015, anyway: http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-...
He didn't even try to get it to work by changing that one bit!
Anyway, this is the error I got if you're curious. (I left such things out because the article was getting long as is)
warning: variable named 'main' with external linkage has undefined behavior [-Wmain] short main[] = { 16, 18 };
This is on OS X so it's clang 11.0.3.
I realise this was a minor observation on your part, and I was remarking on it in that spirit. I’m sorry not to have made that clearer. I’ve found it rather dispiriting when writing of mine has been posted here, and the comments have seemed like nitpicking criticism, so I regret having given you that impression. One has to remind oneself that people who enjoy the article and have nothing to add will usually not leave comments, and so the comments give a misleading impression of how people felt about it.
The message you quote above appears to be a warning, rather than an error.
Anyway, I'm glad you found it interesting =)
https://www.ioccc.org/years.html#2001_anonymous
Which I believe was a runner up, and was a PPC to x86 binary translator
and his winning entry:
https://www.ioccc.org/years.html#2004_gavin
Which was a protected mode multitasking operating system with a windowing system/gui.
because of course.
claire: {4} cc --version
cc (nb3 20190319) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
claire: {5} cc mullender.c -o mullender
claire: {6} ./mullender
:-)
claire: {7} uname -p
vaxBut the real surprise is the Docker image. Can we have pdp-11 and Ibm 360 one? Tired of firing the dos mode version.
In the future I'm going to dissect more complicated obfuscated programs so I hope you'll get to enjoy those.