Upgrading GCC/zh-cn

本文档将指导用户完成GCC的升级.

介绍
这篇文章讲述 升级 GCC. GCC降级可能会有不愿看到的副作用. 对于一些报告中常见的问题请查阅故障排除一节.

下一节将给出GCC升级的快速指南（这件事太容易了）. 如果你想要阅读升级GCC背后冗长的材料，请继续阅读GCC升级详解.

Short version
如果你正在升级GCC，那么你需要做的事情只有改变编译器版本和重新构建libtool.

If you upgrade GCC from a version earlier than 3.4.0 (for the 3.x series) or 4.1, you will need to run revdep-rebuild as well:

检查当前版本并卸载旧版本

这样就完成了！

介绍
GCC upgrading has always been mystified, with suggestions ranging from "You do not need to do anything" up to "You will need to rebuild your entire system twice". Most of this FUD comes from the confusion surrounding ABI incompatibility. But first a quick pointer towards libtool.

libtool 和 fix_libtool_files.sh
早前在 Gentoo 上安装 GCC 需要你运行一个叫  的特定命令. 一段时间之后，安装包（通过 toolchain eclass）集成了自动执行这个命令，因此用户不需要再手动执行.

The reason we need to rebuild libtool after the upgrade of gcc versions is because of its main purpose: libtool is a toolset that aggregates platform-specific code in a generic interface, allowing applications to build against shared libraries without needing to deal with the platform specific aspects of shared libraries. To fulfill its function properly, the libtool script uses various library locations that have hard-coded gcc version information in them.

ABI changes
An ABI, or Application Binary Interface, is a set of conventions used by all tools that deal with binary representation of programs, including compilers, assemblers, linkers and language runtime support (source: GCC Binary Compatibility). When the ABI used for binary applications and libraries is changed, you will risk getting linker errors or malfunctioning programs unless you rebuild all libraries that use C++ code.

Yes, C++, since most incompatibilities occur within the C++ ABI. If you are upgrading to GCC 4.1, or GCC 5.1, you would probably encounter ABI issues. This is also why we use the revdep-rebuild command against the (from GCC 3 to GCC 4.1), or  (from GCC 4 to GCC 5.1).

So why is this only needed up to GCC 3.4.0/4.1/5.1? That's because from that version onward, GCC uses a forward compatible ABI, which removes the need for rebuilding applications and libraries. Of course, guarantees can never be given indefinitely, but when an incompatibility occurs again, we'll definitely document it here. In that case, the version of the library will probably be increased.

Rebuilding everything
一些人认为当新版本的GCC安装好之后,他们需要重新编译他们系统上的已经安装过的应用,当然,这被认为是没有意义的,因为这里有很多应用在编译和构建的时候并没有用到GCC,所以更新不会影响到它们.

That however doesn't mean they are completely incorrect: newer GCC versions often include better support for the processors' instruction set, which might influence the performance of some applications in a positive way. Although it is expected that this improvement is generally only marginally, in some cases (especially CPU intensive applications) this might yield notable improvements.

There are also known cases where packages need to be built with the same compiler. Although these packages are usually bumped by Gentoo simultaneously (so that they are always built with the same GCC version) cherry-picking re-installs on these packages might prove to be troublesome. The various packages are a nice example on this matter.

libstdc++.so.6: version `GLIBCXX_3.4.15' not found
During updates, you might encounter an error like the following:

This means that you are trying to build a package with an older GCC version than with which some depending libraries were built. Remember when we told that the C++ ABI is forward-compatible? That is true, but it ensures only that higher (or same) GCC versions can be used when building applications and linking libraries (compared to the GCC version used to build those libraries).

To rebuild all the packages depending on libstdc++ the next bash script can be executed.

Which packages are known to need a rebuild?
The following table gives the packages that, if installed, need to be rebuild and why.