Glibc vs GCC vs binutils compatibility
Asked Answered
D

2

8

Is there a sort of official documentation about version compatibility between binutils, glibc and GCC? I found this matrix for binutils vs GCC version compatibility. It would be good to have something like this for GCC vs glibc as well.

The point I'm asking this for is that I need to know if I can build, say, cross GCC 4.9.2 with "embedded" glibc 2.2.4 to be able to support quite old targets like CentOS 5.

Thank you.

Debatable answered 8/3, 2016 at 17:6 Comment(0)
S
4

it's extremely unlikely you'll be able to build such an old version of glibc with such a new version of gcc. glibc documents the min required version of binutils & gcc in its INSTALL file.

glibc-2.23 states:

Recommended Tools for Compilation
GCC 4.7 or newer
GNU 'binutils' 2.22 or later

typically if you want to go newer than those, glibc will generally work with the version of gcc that was in development at the time of the release. e.g. glibc-2.23 was released 18 Feb 2016 and gcc-6 was under development at that time, so glibc-2.23 will work with gcc-4.7 through gcc-6.

so find the version of gcc you want, then find its release date, then look at the glibc releases from around the same time.

all that said, using an old version of glibc is a terrible idea. it will be full of known security vulnerabilities (include remotely exploitable ones). the latest glibc-2.23 release for example fixed CVE-2015-7547 which affects any application doing DNS network resolution and affects versions starting with glibc-2.9. remember: this is not the only bug lurking.

Sympathize answered 8/3, 2016 at 22:4 Comment(2)
Why would you by unable to build an older version of glibc with a much newer version of gcc? (That is not to say that the much newer version of gcc will be able to use said old version of glibc internally, but if I wanted to build an executable for CentOS 5, as the OP states, shouldn't I be able to use even say, GCC 9, checkout the source for glibc 2.22 and build glibc 2.22. Then to build app for CentOS 5, I would compile source with GCC 9, and applicably old -std=c99, and then manually link using LDFLAGS=-nostdlib, and LDLIBS=-l:libc.so.2.2.2?Christianism
there have been many known issues whereby a newer gcc miscompiles an older glibc because glibc relies on behavior that has changed (sometimes on purpose, sometimes by incidentally). it can either fail to compile entirely, or it'll compile & then simply crash when executed. the further apart the releases, the more likely this is to happen.Sympathize
C
1

When building a cross-compiler there are at least two, and sometimes three, platform types to consider:

Platform A is used to BUILD a cross compiler HOSTED on Platform B which TARGETS binaries for embedded Platform C. I used the words BUILD, HOSTED, and TARGETS intentionally, as those are the options passed to configure when building a cross-GCC.


  • BUILD PLATFORM: Platform of machine which will create the cross-GCC
  • HOST PLATFORM: Platform of machine which will use the cross-GCC to create binaries
  • TARGET PLATFORM: Platform of machine which will run the binaries created by the cross-GCC

Consider the following (Canadian Cross Config, BUILD != HOST platform):
A 32-bit x86 Windows PC running the mingw32 toolchain will be used to compile a cross-GCC. This cross-GCC will be used on 64-bit x86 Linux computers. The binaries created by the cross-GCC should run on a 32-bit PowerPC single-board-computer running LynxOS 178 RtOS (Realtime Operating System).

In the above scenario, our platforms are as follows:
BUILD: i686-w32-mingw32
HOST: x86_64-linux-gnu
TARGET: powerpc-lynx-lynxos178

However, this is not the typical configuration. Most often BUILD PLATFORM and HOST PLATFORM are the same.


A more typical scenario (Regular Cross Config, BUILD == HOST platform):
A 64-bit x86 Linux server will be used to compile a cross-GCC. This cross-GCC will also be used on 64-bit x86 Linux computers. The binaries created by the cross-GCC should run on a 32-bit PowerPC single-board-computer running LynxOS 178 RtOS (Realtime Operating System).

In the above scenario, our platforms are as follows:
BUILD: x86_64-linux-gnu
HOST: x86_64-linux-gnu
TARGET: powerpc-lynx-lynxos178


When building the cross-GCC (assuming we are building a Regular Cross Config, where BUILD == HOST Platform), native versions of GNU BinUtils, GCC, glibc, and libstdc++ (among other libraries) will be required to actually compile the cross-GCC. It is less about specific versions of each component, and more about whether each component supports the specific language features required to compile GCC-4.9.2 (note: just because GCC-4.9.2 implements language feature X, does not mean that language feature X must be supported by the version of GCC used to compile GCC-4.9.2. In the same way, just because glibc-X.X.X implements library feature Y, does not mean that the version of GCC used to compile glibc-X.X.X must have been linked against a glibc that implements feature Y.


In your case, you should simply build your cross-GCC 4.9.2 (or if you are not cross compiling, i.e. you are compiling for CentOS 5 on Linux, build native GCC 4.9.2), and then when you link your executable for CentOS 5, explicitly link glibc v2.2.4 using -l:libc.so.2.2.4. You also probably will need to define -std=c99 or -std=gnu99 when you compile, as I highly doubt glibc 2.2.4 supports the C 2011 standard.

Christianism answered 18/10, 2019 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.