Difference between revisions of "Upgrading GCC"

From Gentoo Wiki
Jump to:navigation Jump to:search
(actually, this doesn't really make sense in this context (I don't think); fix tyo)
(various copyediting and additions, trying to explain why one might want to rebuild the entire system -- see Talk for context)
Line 131: Line 131:
 
{{Emerge|sys-devel/libtool sys-devel/llvm sys-devel/clang|params+=--oneshot --verbose}}
 
{{Emerge|sys-devel/libtool sys-devel/llvm sys-devel/clang|params+=--oneshot --verbose}}
  
To be completely sure that your system is in a sane state, you ''must'' rebuild the toolchain and then world to make use of the new compiler.
+
<!--T:26-->
 
+
Some collections of packages need to be built with the same compiler (for example, the various {{Path|qt-*}} packages). Such packages are usually bumped by package maintainers simultaneously, so they will always be built with the same GCC version. Cherry-picking re-installs on these packages might prove to be troublesome.
{{Emerge|@system|params+=--emptytree --verbose}}
 
{{Emerge|@world|params+=--emptytree --verbose}}
 
  
 
=== Rebuilding everything ===  
 
=== Rebuilding everything ===  
Line 143: Line 141:
 
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.
 
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.
  
<!--T:26-->
+
Apart from such "benign" benefits, rebuilding everything from scratch may be necessary in some cases to fix problems that don't seem to have any obvious cause.
Some packages need to be built with the same compiler. Although these packages are usually bumped by package maintainers 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 {{Path|qt-*}} packages are a an example of this matter.
+
Some software problems are inherently difficult to diagnose and yet could be solved by simply rebuilding one or more appropriate packages. If such a problem has arisen following a GCC upgrade and persists after using the revdep-rebuild approach described above (and after rebuilding any other obviously relevant packages), a complete system rebuild may be the answer.
 +
 
 +
The "safest" (but also most time-consuming) way to accomplish this is to use the --emptytree (-e) option of emerge to rebuild the "system" set and then the "world" set:
 +
 
 +
{{Emerge|@system|params+=--emptytree}}
 +
{{Emerge|@world|params+=--emptytree}}
 +
 
 +
Users are urged to try this approach before reporting any bugs that might have been caused by a GCC upgrade.
 +
 
 +
(Note that the commands above will cause the packages in the "system" set to be rebuilt twice, which is necessary to be ''absoutely certain'' that every package gets built in the same [presumably] "problem-free" environment. Any problems that remain after doing this are due to either "genuine bugs" that should be reported or poor system configuration.)
  
 
== Troubleshooting == <!--T:27-->
 
== Troubleshooting == <!--T:27-->

Revision as of 04:37, 20 November 2017

This document guides users through the process of upgrading to modern versions of GCC.

Please note that downgrading GCC might have unwanted side effects. Refer to the troubleshooting section for some commonly reported issues.

Short version

This section is a quick primer on GCC upgrades (and how easy they are). More details are given in the next section, GCC upgrading explained.

Most GCC upgrades are as simple as switching the compiler version (here from 4.4.5 to 4.5.3) and rebuilding libtool:

root #emerge --ask --oneshot sys-devel/gcc
root #gcc-config --list-profiles
[1] i686-pc-linux-gnu-4.4.5 *
[2] i686-pc-linux-gnu-4.5.3
root #gcc-config 2
root #env-update && source /etc/profile
root #emerge --ask --oneshot sys-devel/libtool

If upgrading GCC from a version earlier than 3.4, be sure to also run revdep-rebuild (provided by app-portage/gentoolkit):

root #revdep-rebuild --library 'libstdc++.so.5' -- --exclude gcc

(Versions of gentoolkit before 0.3.1 require escape characters in the library name: 'libstdc\+\+\.so\.5', because it is interpreted as a regular expression.)

Beyond GCC 3.4, revdep-rebuild is usually only necessary when upgrading to a new major version (i.e., 3.x to 4.x, or 4.x to 5.x):

root #revdep-rebuild --library 'libstdc++.so.6' -- --exclude gcc

Note that libstdc++.so.6 was introduced with GCC 3.4.0 and is still in use as of GCC 8.0.0.[1]

Check the current version number and then uninstall the old version:

root #gcc --version
root #emerge --ask --depclean =sys-devel/gcc-4.4.5

Enjoy the new compiler!

GCC upgrading explained

GCC upgrading has always been mystified, with suggestions ranging from "users do not need to do anything" to "users will need to rebuild the entire system twice". Most of this fear, uncertainty and doubt comes from the confusion surrounding ABI incompatibility. But first a quick pointer towards libtool.

libtool and fix_libtool_files.sh

Earlier installments of GCC on Gentoo required you to run a specific command called fix_libtool_files.sh. Some time ago, the execution of this command has been integrated in the package deployments itself (through the toolchain eclass) so there is no need for users to call this themselves anymore.

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 libstdc++.so.5 (from GCC 3 to GCC 4.1), or libstdc++.so.6 (from GCC 4 to GCC 5.1).

Users of gentoolkit-0.3.1 and later should run:

root #revdep-rebuild --library 'libstdc++.so.6' -- --exclude gcc

Users of earlier gentoolkit versions need to use escape characters in the library name:

root #revdep-rebuild --library 'libstdc\+\+\.so\.6' -- --exclude gcc

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 libstdc++.so library will probably be increased.

The special case C++11 (and C++14)

While GCC (or more specifically, libstdc++) goes to great lengths to guarantee stability of the ABI, this guarantee does not extend to all parts of C++ within libstdc++. Formally, with versions starting from 3.4, GCC/libstdc++ only guarantees C++98/C++03 ABI stability and not more. This is crucial for packages that depend on C++11. GCC only makes C++11 ABI stability guarantees beginning with version 5.1. This means that switching (even minor) versions of gcc (say from 4.7.3 -> 4.7.4) might cause ABI breakage for binaries built from C++11 code.

For more information and some examples, see:

Which packages are known to need a rebuild?

The following table gives the packages that, if installed, need to be rebuilt and why.

Package Rebuild needed because ...
sys-devel/libtool libtool application has hardcoded paths towards GCC internal libraries.
sys-devel/llvm depends on exact gcc version, may encounter linking errors with other ebuilds making use of LLVM (e.g. media-libs/mesa) if not rebuilt.
sys-devel/clang depending on exact gcc version, may be affected by sys-devel/llvm.
root #emerge --ask --oneshot --verbose sys-devel/libtool sys-devel/llvm sys-devel/clang

Some collections of packages need to be built with the same compiler (for example, the various qt-* packages). Such packages are usually bumped by package maintainers simultaneously, so they will always be built with the same GCC version. Cherry-picking re-installs on these packages might prove to be troublesome.

Rebuilding everything

Some people swear that they need to rebuild every single package on their system when a new GCC version is made available. Of course, that doesn't make sense, since there are many applications that are not using GCC for their build and install process anyhow, so they would never be affected by such changes.

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.

Apart from such "benign" benefits, rebuilding everything from scratch may be necessary in some cases to fix problems that don't seem to have any obvious cause.

Some software problems are inherently difficult to diagnose and yet could be solved by simply rebuilding one or more appropriate packages. If such a problem has arisen following a GCC upgrade and persists after using the revdep-rebuild approach described above (and after rebuilding any other obviously relevant packages), a complete system rebuild may be the answer.

The "safest" (but also most time-consuming) way to accomplish this is to use the --emptytree (-e) option of emerge to rebuild the "system" set and then the "world" set:

root #emerge --ask --emptytree @system
root #emerge --ask --emptytree @world

Users are urged to try this approach before reporting any bugs that might have been caused by a GCC upgrade.

(Note that the commands above will cause the packages in the "system" set to be rebuilt twice, which is necessary to be absoutely certain that every package gets built in the same [presumably] "problem-free" environment. Any problems that remain after doing this are due to either "genuine bugs" that should be reported or poor system configuration.)

Troubleshooting

rebuild of boost

If dev-libs/boost needs to be rebuilt, one will get the following error message:

root #emerge ...
 
checking for the Boost _____ library... no
configure: error: cannot find the flags to link with Boost _____

One can rebuild with:

root #emerge --ask --oneshot --verbose dev-libs/boost

libstdc++.so.6: version `GLIBCXX_3.4.15' not found

During updates, you might encounter an error like the following:

CODE GLIBCXX_x.y.z not found
cmake_bootstrap_28021_test: /usr/lib/gcc/i486-pc-linux-gnu/4.1.2/libstdc++.so.6:
version `GLIBCXX_3.4.11' not found

This means that you are trying to build a package with an older GCC version than that 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++, see the revdep-rebuild instructions above.

See also

References

  1. ABI Policy and Guidelines, in Appendix B of The GNU C++ Library Manual (see "3. Release versioning on the libstdc++.so binary").