how can I make a hello world executable as big as possible?

K

K4 Monk

I'm curious, how can I, either on windows or linux, compile a program
so that all it does is "hello world" but is heavily bloated? Is there
a way to statically link as many libraries as possible without using
them? I'm inspired by the fake interview in which Bjarne Stroustrup
claimed that g++ gives a 0.5 MB executable for hello world:
http://www.nsbasic.com/ce/info/interview.shtml
 
K

Keith Thompson

Kenneth Brody said:
That said, I did see a version of "Hello, world" that took command line
arguments, including things like "--help" and "--version", as well as
handled localization. A quick search doesn't find it, however.

You're probably thinking of GNU hello, available at
<ftp://ftp.gnu.org/gnu/hello/>.

It's designed to be a canonical example of a GNU package.
 
D

David Thompson

This technique will make the program as arbitrarily large as your
system can stand:

#include <stdio.h>
int main( void )
{
static char message[0x100000] = { "Hello, World!" };
puts( message );
return 0;
}
Probably. Many popular systems have IDATA regions which occupy as much
space in the (object and) executable as their runtime size, and BSS
regions which occupy no space in the executable (only runtime).
The names may be different, but the concepts are widespread.

But one system I worked on had a single data region in the executable,
and compressed out all-zero pages (of 2048 bytes). Your example would
only store one page, no matter how big you declare the array (up to a
limit, which IIRC was 27 bits = 128M minus overhead). You'd need
something like C99's
static char message[0x1000000] = { 'a',
[0x800] = 'b', [0x1000] = 'c', [0x1800] = 'd', etc etc }
(and when I used this system it was before 1999).

OTOH, it had a complicated symbol-info format, and #include'ing a
bunch of headers whose contents you didn't actually use would give a
huge executable without increasing runtime memory. <G>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top