What is the difference between "gcc -s" and the "strip" command?

I wonder what the difference is between the two:

  • gcc -s : remove the entire character table and move information from the executable.

  • strip : Discard characters from object files.

Do they have the same meaning?

Which one do you use for:

  • reduce the size of the executable file?
  • speed up the work?
+46
gcc symbol strip
Aug 28 '09 at 20:28
source share
4 answers

gcc is a compiler / linker, its -s is something that is done when compiling and linking. It also is not configurable - it has a set of information that it deletes, nothing more.

strip is what you can run in an object file that has already been compiled. It also has many command line options that you can use to configure which information will be deleted. For example, -g only separates the debugging information added by gcc -g .

Note that strip not a bash command, although you can run it from a bash shell. This command is completely divided into bash, part of the GNU utility suite.

+41
Aug 28 '09 at 20:42
source share

The accepted answer is very good, but only in order to supplement your further questions (as well as a link for everyone here).

What is equivalent to gcc -s in terms of a strip with some of its parameters?

They both do the same, completely deleting the character table. However, as @JimLewis explained, the strip allows for finer control. For example, in a moveable object strip --strip-unneeded will not remove its global characters. However, strip or strip --strip-all will strip --strip-all full character table.

Which one do you use to reduce the size of the executable file and speed up its launch

A character table is an unallocated section of a binary file. This means that it never loads into RAM. It stores information that can be useful for debugging fiorites, for example, for printing a still image in case of failure. The case where it would be advisable to delete the symbol table will be a scenario where you have serious storage capacity limitations (in this regard, it is useful to use gcc -Os -s or make CXXFLAGS="-Os -s" ... since this will lead to slower binary algorithm, which is also devoid of further downsizing). I do not think that deleting the symbol table will increase the speed for the reasons commented out.

Finally, I recommend this link about deleting shared objects: http://www.technovelty.org/linux/stripping-shared-libraries.html

+27
Oct 24 '13 at 11:11
source share

"gcc -s" deletes move information along with a character table that is not executed by strip. Note that deleting relocation information will affect the randomization of the location of the address space . See this link.

+6
Apr 30 '15 at 3:23
source share

They do similar things, but the bar allows finer-grained control over what is removed from the file.

+4
Aug 28 '09 at 20:41
source share



All Articles