2

Ubuntu 20.04 LTS (at least the core docker image) is distributed with libgcc-s1 and gcc-10-base version 10.3.0(-1ubuntu1~20.04), see, e.g., the manifest at https://partner-images.canonical.com/core/focal/20211103/ubuntu-focal-core-cloudimg-amd64.manifest .

The default version of GCC in 20.04 LTS is GCC 9, not GCC 10.

What is the explanation for this apparent discrepancy? - Why not distribute the 9.x versions of those packages? Is this related to the version of GCC used to compile C-based packages in 20.04LTS? Are most(all?) C-based packages of 20.04 LTS compiled with GCC 10?

jme52
  • 73
  • gcc & gcc-10-base are different packages. Ubuntu 20.04 LTS uses gcc gcc | 4:9.3.0-1ubuntu2 | focal | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x but gcc-10 is also available (https://packages.ubuntu.com/focal/gcc-10) with it used for compiling some options. – guiverc Dec 09 '21 at 10:29
  • So some (all?) C-based packages of 20.04 LTS are compiled with GCC 10? – jme52 Dec 09 '21 at 10:38
  • Sorry I can't speak with authority on what compiled what; I would expect kernel related packages to be compiled by a newer version but I don't monitor gcc that closely sorry. – guiverc Dec 09 '21 at 11:04
  • Ubuntu 20.04 "focal-updates universe" : gcc-10 (10.3.0-1ubuntu1~20.04) https://packages.ubuntu.com/focal-updates/gcc-10 ......... ( The default gcc is still v9 ). – Knud Larsen Dec 09 '21 at 22:58

1 Answers1

2

Disclaimer: I am fairly new to Ubuntu. I have a reasonable amount of experience with RHEL and SLES, and have had to learn Ubuntu LTS versions recently because of some ARM64 hardware that doesn't want to boot anything else.

Summary

Ubuntu releases do, indeed, often come with some components from a later GCC than the releases' default GCC. They apparently do this so that they can provide later compiler versions, if you want to use them.

  • The gcc-10-base package just provides documentation.
  • The libgcc-s1 package provides an important library, libgcc_s.so.1. That provides helper functions for code generated by the compiler: I know it as important for handling C++ exceptions being thrown through a C call stack.
  • Another important library is libstdc++.so.6. That provides C++ support functions.
  • Glibc (libc.so.6, libm.so.6 and other libraries) is also important, but is not tied to a GCC version.

All of these libraries have very strong compatibility rules. Essentially, a later version of the library will always be compatible with earlier versions, discounting some ancient versions from the early history of GCC and Linux.

It isn’t obvious at first why Ubuntu and Debian provide run-times that are later than the compiler, but it gets clearer when you look at the range of GCC versions available on recent Ubuntu LTS versions:

Distribution Released Debian GCC run-times Default GCC Additional GCCs
Ubuntu 16.04 Apr 2016 9.x 5.x 5.4 4.7, 4.8, 4.9
Ubuntu 18.04 Apr 2018 10.x 8.x 7.5 4.8, 5.5, 6.5. 8.4
Ubuntu 20.04 Apr 2020 11.x 9.x & 10.x 9.3 7.4, 8.4, 10.3
Ubuntu 22.04 Apr 2022 12.x 12.x 11.4 9.5, 10.5, 12.3

At that that point, it becomes reasonably obvious. Ubuntu 20.04 has the run-times for code compiled with GCC 9.x and 10.x (GCC 10.x doesn't demand any additional library functions that GCC 9.x didn't use). You can install any mixture of GCC 7.4, 8.4 and 10.3 as extra compilers, and they'll all work. The run-time libraries on Ubuntu 20.04 will support code compiled with any of those compilers.

Why not ship GCC 10.3 with Ubuntu 20.04? Run-time libraries are generally more stable than compilers. GCC 10 would have been first released (as 10.1) about the time that 20.04 was being put together. Building an LTS release with a brand-new compiler would be foolhardy; shipping new run-time libraries, after testing them with code built with GCC 9, is a lot safer and allows GCC 10 to be added when it has stabilised.

Canonical don't provide GCC 11 for 20.04 because it doesn't have the necessary run-times. For those, you need a later Ubuntu.

How to find all this stuff out

/usr/share/doc/gcc/README.Debian has some information.

dpkg-query --listfiles gcc-10-base shows us that gcc-10-base only provides documentation.

dpkg-query --listfiles libgcc-s1 shows us that libgcc-s1 provides /lib/x86_64-linux-gnu/libgcc_s.so.1, which is one of the basic run-time libraries for GCC.

The other basic run-time libraries for C/C++ are glibc, which is independent of GCC, and libstdc++. dpkg-query -list | grep libstdc shows us two packages:

ii libstdc++-9-dev:amd64 9.3.0-17ubuntu1~20.04 amd64 GNU Standard C++ Library v3 ...
ii libstdc++6:amd64 10.3.0-1ubuntu1~20.04 amd64 GNU Standard C++ Library v3

libstdc++6 is the GCC 10.3 version; the -dev package is the GCC 9.3 version.

dpkg-query --listfiles libstdc++-9-dev shows us that this package provides header files, archive libraries and documentation for developing in C++ with GCC 9.

dpkg-query --listfiles libstdc++6 shows us that this package provides documentation, some Python scripts and two really important files:

/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28

The .so.6 file is what programs are linked against. It is actually a softlink to the .so.6.028 file. That’s the name of the GCC 10 version of libstdc++, the GCC support library for C++. You can get the mapping between those names and GCC versions here. Scroll down, and you’ll find some tables.

GCC used for building Ubuntu

The easiest thing to check is glibc. Building this with a different compiler from the rest of the OS would be crazy, and you can find out what compiler was used to build it just by asking:

/usr/lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.7) stable release version 2.31.
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 9.3.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs.

  • Thank you, your answer fully clarifies the discrepancy part of the question. Regarding the last question, am I correct in understanding that 20.04 LTS packages are compiled with GCC 9? (Including the GCC 10 runtimes?) – jme52 Mar 10 '22 at 11:52
  • @jme52: I don't know, but I'll see if I can find out. Would you care to nominate some packages to be checked? – John Dallman Mar 10 '22 at 15:19
  • 1
    @jme52: Sorted. It is indeed GCC 9.3. – John Dallman Mar 14 '22 at 14:08