PDA

View Full Version : Extra "stuff" in compiled binary - why?



Krupski
April 7th, 2009, 10:52 PM
Hi all,

I noticed that some text gets inserted into the binary files which result from compiling my C source.

Unless I'm debugging, I want the smallest possible binary possible. The stuff I see appears to be useless (code-wise) as I can zero-overwrite it and the executable still works.

Here's a screenshot of the text as seen in "hexedit":



http://home.roadrunner.com/~krupski/images/screen.jpg


I've seen programs (pre-compiled binaries) from other sources that had no "advertising" in them.

Is this unique to the Ubuntu release of GCC and G++?

What does it mean? Why is it in there?

And, is there a way to remove it?

Thanks!

-- Roger

movieman
April 7th, 2009, 11:13 PM
It's probably debugging info: run 'strip' on the file and see if it goes away.

Note that debug info shouldn't be loaded into memory unless you need it, so it only really increases the size of the executable on disk, not in RAM.

Krupski
April 7th, 2009, 11:43 PM
It's probably debugging info: run 'strip' on the file and see if it goes away.

Note that debug info shouldn't be loaded into memory unless you need it, so it only really increases the size of the executable on disk, not in RAM.

No, it's not debug info. The file HAS debug info in it (and I know what it looks like).

That "Ubuntu" stuff is even present in non debug, stripped "release" versions of a binary.

NathanB
April 7th, 2009, 11:57 PM
To eliminate all of the "extra stuff", you will want to generate the ELF header by hand. This tutorial will walk you through the details:

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

Krupski
April 8th, 2009, 12:45 AM
To eliminate all of the "extra stuff", you will want to generate the ELF header by hand. This tutorial will walk you through the details:

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

That's really interesting info... but not really the answer to the question.

Frank Kotler
April 8th, 2009, 12:13 PM
Try "strip -R.comment myfile". (but if you *really* want a small file, follow Nathan's advice!)

Best,
Frank

dwhitney67
April 8th, 2009, 12:22 PM
It's probably debugging info: run 'strip' on the file and see if it goes away.

Note that debug info shouldn't be loaded into memory unless you need it, so it only really increases the size of the executable on disk, not in RAM.
Unless of course, the RAM is your "disk". Not all systems have a HDD.

nvteighen
April 8th, 2009, 02:44 PM
It's just compiler information. Not "adverstising" and not particular to Ubuntu either... :)

Krupski
April 9th, 2009, 12:07 AM
It's just compiler information. Not "adverstising" and not particular to Ubuntu either... :)

Well, in a roundabout way, I got my answer. The utility "strip" is what removes unnecessary things from executables.

And, to remove the "advertising" (compiler information), "strip" is used like this:



strip -s -R .comment -R .gnu.version executable


So, thanks everyone for the help and comments!

-- Roger

Krupski
April 9th, 2009, 12:08 AM
Try "strip -R.comment myfile". (but if you *really* want a small file, follow Nathan's advice!)

Best,
Frank

At first I thought that was a GCC command line argument! :)

It wasn't until later that I found out that "strip" is a separate program!

-- Roger