Results 1 to 5 of 5

Thread: g++ includes larg zero block in small program

  1. #1
    Join Date
    May 2014
    Location
    Germany
    Beans
    158
    Distro
    Ubuntu 16.04 Xenial Xerus

    g++ includes larg zero block in small program

    Hi everyone,

    trying to learn something new, I just installed a hex editor (ghex) and was playing around with it. I took a peek at the binary file of a small C++ program I had written some time ago, and was rather surprised at how many zeros it contains. There's a big chunk full of zeros right in the middle of the file. So I'm wondering why the compiler inserts them? Isn't that inefficient?

    If you want to replicate, you'll find the source code at www.launchpad.net/comp. I compiled it with g++, no extra options passed (as seen in the install.sh file).

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: g++ includes larg zero block in small program

    Maybe the source code that you obtained was written by an amateur programmer, and it has a static string chock full of zeros. Why not peer review the source code, and get back to UF if you see something in the code that warrants more interest.

  3. #3
    Join Date
    Dec 2013
    Beans
    Hidden!

    Re: g++ includes larg zero block in small program

    Quote Originally Posted by veddox View Post
    There's a big chunk full of zeros right in the middle of the file. So I'm wondering why the compiler inserts them? Isn't that inefficient?

    I suspect the culprit is the linker, etc, not the compiler.

  4. #4
    Join Date
    May 2014
    Location
    Germany
    Beans
    158
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: g++ includes larg zero block in small program

    Sorry guys, I missed your replies

    In case you still see this:

    Maybe the source code that you obtained was written by an amateur programmer, and it has a static string chock full of zeros. Why not peer review the source code, and get back to UF if you see something in the code that warrants more interest.
    Yes, the source code was written by an amateur programmer - that would be me And I can guarantee you, I did not load if full of zeros...

    I suspect the culprit is the linker, etc, not the compiler.
    Why that?

  5. #5
    Join Date
    Dec 2013
    Beans
    Hidden!

    Re: g++ includes larg zero block in small program

    Quote Originally Posted by veddox View Post
    Why that?
    The compiler's job is to turn human readable/writable code into machine language. It's the linker's job to format the machine language file(s) into a loadable executable.

    You can compile a source file without linking (g++ -c). You'll get a *.o file (object file). You can use the hex editor on the object file to see if that block of zeroes is there before linking.

    If your interested in what the linker does, how it formats, etc, google 'Executable and Linkable Format' (ELF).

    https://en.wikipedia.org/wiki/Execut...inkable_Format

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •