“gcc -s”和“strip”命令有什么不同?

时间:2022-08-06 02:18:17

I wonder what is the difference between these two:

我想知道这两者之间的区别是什么:

  • gcc -s: Remove all symbol table and relocation information from the executable.

    从可执行文件中删除所有符号表和重新定位信息。

  • strip: Discard symbols from object files.

    条:从对象文件中丢弃符号。

Do they have the same meaning?

Which one do you use to:

  • reduce the size of executable?
  • 减少可执行文件的大小?
  • speed up its running?
  • 加速它的运行?

4 个解决方案

#1


45  

gcc being a compiler/linker, its -s option is something done while compiling and linking. It's also not configurable - it has a set of information which it removes, no more no less.

gcc是一个编译器/链接器,它的-s选项是在编译和链接时完成的。它也不是可配置的-它有一组信息,它会删除,不会更多。

strip is something which can be run on an object file which is already compiled. It also has a variety of command-line options which you can use to configure which information will be removed. For example, -g strips only the debug information which gcc -g adds.

带是可以在已经编译的对象文件上运行的东西。它还有各种命令行选项,您可以使用这些选项来配置哪些信息将被删除。例如,-g只删除gcc -g添加的调试信息。

Note that strip is not a bash command, though you may be running it from a bash shell. It is a command totally separate from bash, part of the GNU binary utilities suite.

注意,strip不是bash命令,尽管您可以从bash shell中运行它。它是一个完全独立于bash的命令,它是GNU二进制实用程序套件的一部分。

#2


31  

The accepted answer is very good but just to complement your further questions (and also as reference for anyone that end up here).

被接受的答案很好,但只是补充你的进一步的问题(同时也作为最后的参考)。

What's the equivalent to gcc -s in terms of strip with some of its options?

在带一些选项的情况下,gcc的等效值是多少?

They both do the same thing, removing the symbols table completely. However, as @JimLewis pointed out strip allows finer control. For example, in a relocatable object, strip --strip-unneeded won't remove its global symbols. However, strip or strip --strip-all would remove the complete symbols table.

它们都做同样的事情,完全移除符号表。然而,正如@JimLewis指出的,条带允许更好的控制。例如,在一个可重定位的对象中,条带——不需要的条带不会移除它的全局符号。然而,条带或条带——条带——都将移除完整的符号表。

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

您使用哪一种方法来减少可执行文件的大小并加快其运行速度?

The symbols table is a non-allocable section of the binary. This means that it never gets loaded in RAM memory. It stores information that can be useful for debugging purporses, for instance, to print out a stacktrace when a crash happens. A case where it could make sense to remove the symbols table would be a scenario where you have serious constraints of storage capacity (in that regard, gcc -Os -s or make CXXFLAGS="-Os -s" ... is useful as it will result in a smaller slower binary that is also stripped to reduce size further). I don't think removing the symbols table would result into a speed gain for the reasons commented.

符号表是二进制的非可分配部分。这意味着它永远不会加载到RAM内存中。它存储可以用于调试purporses的信息,例如,在发生崩溃时打印堆栈跟踪。如果您有严重的存储容量限制(在这方面,gcc -Os -s或make CXXFLAGS=“-Os -s”,那么删除符号表是有意义的。是有用的,因为它将导致一个较小的较慢的二进制,也被剥去进一步减小尺寸。我不认为删除符号表会导致速度增益,原因是注释。

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

最后,我推荐这个关于剥离共享对象的链接:http://www.technovelty.org/linux/stripping-shar-libraries.html。

#3


8  

"gcc -s" removes the relocation information along with the symbol table which is not done by "strip". Note that, removing relocation information would have some effect on Address space layout randomization. See this link.

“gcc -s”将迁移信息和符号表一起删除,而符号表不是由“strip”完成的。注意,删除搬迁信息会对地址空间布局的随机化有一定的影响。看到这个链接。

#4


5  

They do similar things, but strip allows finer grained control over what gets removed from the file.

它们也做类似的事情,但是带允许更好地控制从文件中删除的内容。

#1


45  

gcc being a compiler/linker, its -s option is something done while compiling and linking. It's also not configurable - it has a set of information which it removes, no more no less.

gcc是一个编译器/链接器,它的-s选项是在编译和链接时完成的。它也不是可配置的-它有一组信息,它会删除,不会更多。

strip is something which can be run on an object file which is already compiled. It also has a variety of command-line options which you can use to configure which information will be removed. For example, -g strips only the debug information which gcc -g adds.

带是可以在已经编译的对象文件上运行的东西。它还有各种命令行选项,您可以使用这些选项来配置哪些信息将被删除。例如,-g只删除gcc -g添加的调试信息。

Note that strip is not a bash command, though you may be running it from a bash shell. It is a command totally separate from bash, part of the GNU binary utilities suite.

注意,strip不是bash命令,尽管您可以从bash shell中运行它。它是一个完全独立于bash的命令,它是GNU二进制实用程序套件的一部分。

#2


31  

The accepted answer is very good but just to complement your further questions (and also as reference for anyone that end up here).

被接受的答案很好,但只是补充你的进一步的问题(同时也作为最后的参考)。

What's the equivalent to gcc -s in terms of strip with some of its options?

在带一些选项的情况下,gcc的等效值是多少?

They both do the same thing, removing the symbols table completely. However, as @JimLewis pointed out strip allows finer control. For example, in a relocatable object, strip --strip-unneeded won't remove its global symbols. However, strip or strip --strip-all would remove the complete symbols table.

它们都做同样的事情,完全移除符号表。然而,正如@JimLewis指出的,条带允许更好的控制。例如,在一个可重定位的对象中,条带——不需要的条带不会移除它的全局符号。然而,条带或条带——条带——都将移除完整的符号表。

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

您使用哪一种方法来减少可执行文件的大小并加快其运行速度?

The symbols table is a non-allocable section of the binary. This means that it never gets loaded in RAM memory. It stores information that can be useful for debugging purporses, for instance, to print out a stacktrace when a crash happens. A case where it could make sense to remove the symbols table would be a scenario where you have serious constraints of storage capacity (in that regard, gcc -Os -s or make CXXFLAGS="-Os -s" ... is useful as it will result in a smaller slower binary that is also stripped to reduce size further). I don't think removing the symbols table would result into a speed gain for the reasons commented.

符号表是二进制的非可分配部分。这意味着它永远不会加载到RAM内存中。它存储可以用于调试purporses的信息,例如,在发生崩溃时打印堆栈跟踪。如果您有严重的存储容量限制(在这方面,gcc -Os -s或make CXXFLAGS=“-Os -s”,那么删除符号表是有意义的。是有用的,因为它将导致一个较小的较慢的二进制,也被剥去进一步减小尺寸。我不认为删除符号表会导致速度增益,原因是注释。

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

最后,我推荐这个关于剥离共享对象的链接:http://www.technovelty.org/linux/stripping-shar-libraries.html。

#3


8  

"gcc -s" removes the relocation information along with the symbol table which is not done by "strip". Note that, removing relocation information would have some effect on Address space layout randomization. See this link.

“gcc -s”将迁移信息和符号表一起删除,而符号表不是由“strip”完成的。注意,删除搬迁信息会对地址空间布局的随机化有一定的影响。看到这个链接。

#4


5  

They do similar things, but strip allows finer grained control over what gets removed from the file.

它们也做类似的事情,但是带允许更好地控制从文件中删除的内容。