374
160
Introduction
You're probably familiar with zip bombs, XML bombs, etc. Put simply, they are (relatively) small files which produce enormous output when interpreted by naïve software. The challenge here is to abuse a compiler in the same way.
Challenge
Write some source code which occupies 512 bytes or less and which compiles into a file which occupies the most possible space. Largest output file wins!
Rules
OK, so there are a few important clarifications, definitions and restrictions;
- The output of the compilation must be an ELF file, a Windows Portable Executable (.exe), or virtual bytecode for the JVM or .Net's CLR (other types of virtual bytecode are also likely to be OK if asked for). Update: Python's .pyc / .pyo output also counts.
- If your language-of-choice can't be compiled directly into one of those formats, transpilation followed by compilation is also allowed (Update: you can transpile multiple times, just so long as you never use the same language more than once).
- Your source code can consist of multiple files, and even resource files, but the summed size of all these files must not exceed 512 bytes.
- You cannot use any other input than your source file(s) and the standard library of your language-of-choice. Static linking standard libraries is OK when it's supported. Specifically, no third party libraries or OS libraries.
- It must be possible to invoke your compilation using a command or series of commands. If you require specific flags when compiling, these count towards your byte limit (e.g. if your compile line is
gcc bomb.c -o bomb -O3 -lm
, the-O3 -lm
part (7 bytes) will be counted (note the initial leading space isn't counted). - Preprocessors are permitted only if they are a standard compilation option for your language.
- The environment is up to you, but in the interests of making this verifiable, please stick to recent (i.e. available) compiler versions and operating systems (and obviously specify which you're using).
- It must compile without errors (warnings are OK), and crashing the compiler doesn't count for anything.
- What your program actually does is irrelevant, though it can't be anything malicious. It doesn't even have to be able to start.
Example 1
The C program
main(){return 1;}
Compiled with Apple LLVM version 7.0.2 (clang-700.1.81)
on OS X 10.11 (64-bit):
clang bomb.c -o bomb -pg
Produces a file of 9228 bytes. The total source size is 17+3 (for the -pg
) = 20 bytes, which is easily within size limit.
Example 2
The Brainfuck program:
++++++[->++++++++++++<]>.----[--<+++>]<-.+++++++..+++.[--->+<]>-----.--
-[-<+++>]<.---[--->++++<]>-.+++.------.--------.-[---<+>]<.[--->+<]>-.
Transpiled with awib to c with:
./awib < bomb.bf > bomb.c
Then compiled with Apple LLVM version 7.0.2 (clang-700.1.81)
on OS X 10.11 (64-bit):
clang bomb.c
Produces a file of 8464 bytes. The total input here is 143 bytes (since @lang_c
is the default for awib it didn't need to be added to the source file, and there are no special flags on either command).
Also note that in this case, the temporary bomb.c file is 802 bytes, but this counts towards neither the source size nor the output size.
Final Note
If an output of more than 4GB is achieved (perhaps if somebody finds a turing complete preprocessor), the competition will be for the smallest source which produces a file of at least that size (it's just not practical to test submissions which get too big).
If using a transpiler, does the output source code need to be under 512 bytes as well as the input source code? – trichoplax – 2016-01-11T23:57:41.150
@trichoplax only the original source needs to be within the byte limit. The source after transpilation can be as big as you like (the Brainfuck example has an intermediate size of 802 bytes, for example) – Dave – 2016-01-11T23:59:40.887
3Is repeated transpilation allowed? – orlp – 2016-01-12T00:02:21.523
@orip interesting; I think I'll say: only if you never have to the same language more than once. So for example, Befunge -> Java -> C would be OK, but Fortran -> Java -> Fortran wouldn't. – Dave – 2016-01-12T00:08:25.410
So interpreted languages, unless transpiled, cannot be used for this challenge, correct? – LegionMammal978 – 2016-01-12T00:11:26.883
3@LegionMammal978 yes it has to produce one of the file types I specified. But if you think you've found something which is more virtual-machine than interpreted-language, ask about it specifically and it's possible I'll allow it (it's a bit subjective so I wanted to be very restrictive to begin, with the option of opening it up) – Dave – 2016-01-12T00:21:37.923
Python is an example of a language regarded as interpreted that compiles to bytecode. – trichoplax – 2016-01-12T00:40:48.593
@trichoplax speak of the devil. I was literally about to ask Dave if python compiles to one of his specified formats. Thanks! – Ashwin Gupta – 2016-01-12T00:51:48.153
3@trichoplax I wasn't aware of that, but from some reading it looks like yes; compiling to Python bytecode absolutely counts. So for python, the output size would be the sum total size of all your pyc/pyo files. I'll update the question soon with these comment-based updates. – Dave – 2016-01-12T00:58:24.413
OK, all updated. I'm off for now (it's late in England!). I'll be back to answer any other questions tomorrow. Good luck! – Dave – 2016-01-12T01:27:48.277
A "turing-complete preprocessor" is generally not a preprocessor (step that happens before parsing) at all, but a metaprogramming system that gets executed at some point between parsing and codegen. There are several languages that have one, or have had one grafted on in some way. – Mason Wheeler – 2016-01-12T18:38:31.590
How about modifying the source code of a compiler so that anything it compiles is really big? And then use it to compile itself.... – WGroleau – 2016-01-13T04:21:39.097
Don't forget fork bombs, which does something similar to your CPU capacity.
– Mast – 2016-01-13T08:52:18.270@WGroleau generally in code challenges you can't use anything which was specially-built for the purpose. In fact, using anything developed since the question was posted is generally not allowed. – Dave – 2016-01-13T14:27:12.260
When you say 4GB, do you mean 4,294,967,296 bytes (4 * 2^30), or 4,000,000,000 bytes (4 * 10^9)? – Patrick Roberts – 2016-01-13T21:00:36.560
@PatrickRoberts well 4GB officially means 4,000,000,000 bytes (it's GiB for 1024^3), but I can't imagine it would make a lot of difference to any answer. The rule is only there to keep things vaguely sane! – Dave – 2016-01-13T21:15:51.440
@Dave reason I ask is because of the footnote about scoring. If you're shooting for as close to 4GB as possible, then it actually matters which of the two it is. – Patrick Roberts – 2016-01-13T22:04:34.740
"perhaps if somebody finds a turing complete preprocessor" Common Lisp's macros have the full language available. It'd be easy to add a literal 4GB array to the source. – Joshua Taylor – 2016-01-14T21:27:31.113
Even the humble C preprocessor is close enough to Turing complete as makes no difference. Although to be honest that says more about the utter uselessness of Turing-completeness as a real-world measurement of power than anything else (for practical engineering TC is rarely useful, and rarely even used; has more negative consequences than positive).
– Leushenko – 2016-01-14T22:10:26.970Related: http://codegolf.stackexchange.com/questions/8882/create-a-c-program-that-takes-the-longest-period-of-time-to-compile-in-gcc
– dmckee --- ex-moderator kitten – 2016-01-16T22:24:39.870Are only "commercially available" compilers allowed or would it be allowed to write an own compiler? – Martin Rosenau – 2016-01-17T15:19:23.840
2@MartinRosenau - WGroleau already asked a similar question; it's standard in coding challenges that you can use anything which already existed when the challenge began. – Dave – 2016-01-17T17:09:57.083
Why the 4GB limit? before I saw that rule, I was imagining seeing code one-liners that would create enough material to fill a data-center, which would be awesome. – GiantCowFilms – 2016-01-19T01:53:00.043
@GiantCowFilms: You can still find many such solutions here, ie. ones which can be freely scaled by changing the exponent. (Eg. change the
4**7
in my original solution to2**32
, and it would theoretically generate 8 exabytes of output) As the rule mentions, it exists because no-one would be able to test solutions which fill a data-center or use a terabyte of RAM, so they would be theoretical at best. (I, for one, had problems testing my own solution, with a machine that has 16GB of RAM, even though the output is only 8.5GB, since it uses significantly more RAM than that :P) – Aleksi Torhamo – 2016-01-19T03:54:49.223@Dave can it be a batch file being compiled with http://www.f2ko.de/en/b2e.php ?
– rahuldottech – 2016-12-10T10:04:48.823@Rahul2001 yes that would be allowed, but technically it would have to be a version from before Jan 11 this year (when the question was asked), which looking at the internet archive means version 2.3.4. Of course it might be tricky to get an old version, so as long as it would theoretically be about the same result on the old version, that's fine (i.e. no use of newer features). – Dave – 2016-12-10T10:16:46.017
@Dave Okay thanks... I'll see if I can get this code which I have in mind to get to work... – rahuldottech – 2016-12-10T10:18:03.680