gcc 配置选项说明

gcc configure option explanations

我想通过构建最新的 gcc 6.3.0 来研究解决我的其他问题 (gcc: Strip unused functions) 的方法。

我想尝试 https://gcc.gnu.org/install/configure.html and https://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html 中的一些选项,但不明白它们的含义。

具体来说,这些是我想尝试的标志:

虽然我一直用--enable-lto,但是用ld.bfd,跟大名鼎鼎的gold linker比起来好像没啥用

如果您认为我应该尝试更多标志,请告诉我!

--disable-libstdcxx-verbose: I rarely use exceptions so I am not very familiar with how it works. I have never seen the "verbose messages" it mentioned before.

+1,您通常不会 运行 进入 errors,这会触发这些友好的错误消息,您可以避免为它们付费。

--enable-linker-build-id and --enable-gnu-unique-object: Simply don't understand what the explanations are trying to say. What are the benefits exactly?

有none.

唯一对象是一项设计糟糕的功能,它会阻止包含对全局使用对象(通常是 vtables)的引用的共享库在 dlclose 上卸载。 AFAIR 它默认启用(因为它需要在共享库环境中模拟 C++ 语义)。

需要构建 ID 才能支持 separate debuginfo

--enable-cxx-flags="-ffunction-sections -fstrict-aliasing -fno-exceptions":

您不会受益于 -fstrict-aliasing,因为它默认在 -O2 及更高版本启用。

-ffunction-sections is used, but where to put -Wl,-gc-sections?

也到 --enable-cxx-flags(注意它需要双破折号,即 -Wl,--gc-sections)。

Although I always use --enable-lto, but with ld.bfd, it seems to be quite useless compared to the famous gold linker.

这个标志只是在 GCC 中启用 LTO 支持(实际上相当于将 lto 添加到 --enable-languages)。除非您在 CXXFLAGS 中也启用 -flto,否则它不会造成任何差异。请记住,LTO 通常会增加可执行文件的大小(因为编译器将有更多内联机会)。

If you have more flags you think I should try, please let me know!

说到大小缩减,我想说 -ffunction-sections 是你最好的选择(一定要验证配置机制是否正确传递了所有选项,并且 libstdc++.a 确实每个函数都有一个部分)。您还可以添加 -fdata-sections.