“gcc -s”和“gcc -s”有什么区别?以及“条带”。命令?
我想知道这两者之间有什么区别:
gcc -s
:从可执行文件中删除所有符号表和重定位信息。strip
:丢弃目标文件中的符号。
它们有相同的含义吗?
您使用哪一个来:
- 减少可执行文件的大小?
- 加快其运行速度?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
gcc
作为一个编译器/链接器,它的-s
选项是在链接时完成的。它也是不可配置的——它有一组信息被删除,不多也不少。strip
是可以在已编译的目标文件上运行的东西。它还具有各种命令行选项,您可以使用它们来配置要删除的信息。例如,-g
仅删除gcc -g
添加的调试信息。请注意,
strip
不是 bash 命令,尽管您可能是从 bash shell 运行它。它是一个完全独立于 bash 的命令,是 GNU 二进制实用程序套件的一部分。gcc
being a compiler/linker, its-s
option is something done while linking. It's also not configurable - it has a set of information which it removes, no more no less.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 whichgcc -g
adds.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.接受的答案非常好,但只是为了补充您的进一步问题(也可以作为最终到达这里的任何人的参考)。
他们都做同样的事情,完全删除符号表。然而,正如 @JimLewis 指出的那样,条带可以进行更精细的控制。例如,在可重定位对象中,
strip --strip-unneeded
不会删除其全局符号。但是,strip
或strip --strip-all
将删除完整的符号表。符号表是二进制文件的不可分配部分。这意味着它永远不会被加载到 RAM 内存中。它存储可用于调试目的的信息,例如,在发生崩溃时打印堆栈跟踪。删除符号表有意义的情况是存储容量受到严重限制(在这方面,
gcc -Os -s
或make CXXFLAGS="- Os -s" ...
很有用,因为它会产生一个较小的较慢的二进制文件,并且也会被剥离以进一步减小大小)。我认为删除符号表不会因评论的原因而导致速度增益。最后,我推荐这个关于剥离共享对象的链接:http://www.technovelty.org/linux/stripping -共享库.html
The accepted answer is very good but just to complement your further questions (and also as reference for anyone that end up here).
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
orstrip --strip-all
would remove the complete symbols table.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
ormake 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.Lastly, I recommend this link about stripping shared objects: http://www.technovelty.org/linux/stripping-shared-libraries.html
“gcc -s”删除重定位信息以及符号表,这是“strip”未完成的。请注意,删除重定位信息会对地址空间布局随机化产生一些影响 >。请参阅此链接。
"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.
它们做类似的事情,但是 strip 允许更细粒度地控制从中删除的内容
文件。
They do similar things, but strip allows finer grained control over what gets removed from
the file.