One of the reasons is that GCC can be built and used on (e.g. proprietary Unix systems like MacOSX, Solaris, HPUX or some FreeBSD) systems having their own C standard library.

Even on Linux, you can have a C standard library which is not the GNU Glibc. In particular, you can build GCC (or use it) on Linux systems with musl-libc or with Bionic (Android systems) or with dietlibc, etc. And a Linux system could have the GNU Glibc and use some other C compiler (like Clang or TinyCC).

Also, the C library heavily depends upon the Linux kernel. Some old versions of the kernel might require some particular kind (or version) of libc

And GCC is buildable as a cross-compiler.

And details like "how to call a main function" also depends on the compiler, but in fact, those details are supplied by libc.so on a Linux system.

That is not exactly correct. The main function is called (in a hosted environment) by the crt0 stuff, some of which is provided by GCC (e.g. /usr/lib/gcc/x86_64-linux-gnu/6/crtbegin.o on my Debian/Sid/x86-64 is from the libgcc-6-dev package). Read also about libgcc

Actually, there is some half-hidden relation between libc and GCC, e.g. because many libc headers are (optionally) using some gcc builtins or function attributes.

(hence the GCC developers and the GNU libc developers do have to interact)

.... if I change the compiler to work with another ABI...

You'll need to .../configure the GCC compiler and rebuild it, and you might even need to patch the GCC compiler (to describe your ABI and calling conventions). The x32 ABI is a good example.

At last, some contributors to or maintainers of GCC (including me) have signed a copyright assignment which covers GCC but not the GNU glibc.

(regarding GCC license, read carefully GCC runtime library exception)

Notice that some standard headers, like <limits.h> or <stdint.h> are provided by GCC; others, like <stdlib.h> are "fixed" during GCC build: the compiler build procedure takes them from the Libc implementation and patches them. Still, other standard headers (probably <stdio.h> and the internal headers it is including) are taken from the libc. Read more about GCC FIXINCLUDES and Fixed Header Files.

(the fixincludes thing is something I (Basile) still don't understand well)

You could compile with gcc -v -H to understand more precisely which actual programs are run (since gcc is a driver, running the cc1 compiler, the ld & collect2 linkers, the as assembler, etc...) and which headers are included, which libraries and object files are linked (even implicitly, including the C standard library and the crt0). Read more about GCC options.

BTW, you can use a C standard library different of the one your GCC expects or was built for (e.g. musl-libc or some dietlibc), bypassing appropriate extra arguments to gcc ...

Answer from Basile Starynkevitch on Stack Exchange
🌐
Quora
quora.com › What-is-the-difference-between-glibc-and-libgcc
What is the difference between glibc and libgcc? - Quora
Answer (1 of 3): To add what Prathik said, glibc or GNU C Library is the fundamental library on a linux-like machine that provides access to basic facilities such as opening files, allocating memory, creating threads. One of its main functions is to encapsulate "system calls" - allowing user mode...
Top answer
1 of 2
30

One of the reasons is that GCC can be built and used on (e.g. proprietary Unix systems like MacOSX, Solaris, HPUX or some FreeBSD) systems having their own C standard library.

Even on Linux, you can have a C standard library which is not the GNU Glibc. In particular, you can build GCC (or use it) on Linux systems with musl-libc or with Bionic (Android systems) or with dietlibc, etc. And a Linux system could have the GNU Glibc and use some other C compiler (like Clang or TinyCC).

Also, the C library heavily depends upon the Linux kernel. Some old versions of the kernel might require some particular kind (or version) of libc

And GCC is buildable as a cross-compiler.

And details like "how to call a main function" also depends on the compiler, but in fact, those details are supplied by libc.so on a Linux system.

That is not exactly correct. The main function is called (in a hosted environment) by the crt0 stuff, some of which is provided by GCC (e.g. /usr/lib/gcc/x86_64-linux-gnu/6/crtbegin.o on my Debian/Sid/x86-64 is from the libgcc-6-dev package). Read also about libgcc

Actually, there is some half-hidden relation between libc and GCC, e.g. because many libc headers are (optionally) using some gcc builtins or function attributes.

(hence the GCC developers and the GNU libc developers do have to interact)

.... if I change the compiler to work with another ABI...

You'll need to .../configure the GCC compiler and rebuild it, and you might even need to patch the GCC compiler (to describe your ABI and calling conventions). The x32 ABI is a good example.

At last, some contributors to or maintainers of GCC (including me) have signed a copyright assignment which covers GCC but not the GNU glibc.

(regarding GCC license, read carefully GCC runtime library exception)

Notice that some standard headers, like <limits.h> or <stdint.h> are provided by GCC; others, like <stdlib.h> are "fixed" during GCC build: the compiler build procedure takes them from the Libc implementation and patches them. Still, other standard headers (probably <stdio.h> and the internal headers it is including) are taken from the libc. Read more about GCC FIXINCLUDES and Fixed Header Files.

(the fixincludes thing is something I (Basile) still don't understand well)

You could compile with gcc -v -H to understand more precisely which actual programs are run (since gcc is a driver, running the cc1 compiler, the ld & collect2 linkers, the as assembler, etc...) and which headers are included, which libraries and object files are linked (even implicitly, including the C standard library and the crt0). Read more about GCC options.

BTW, you can use a C standard library different of the one your GCC expects or was built for (e.g. musl-libc or some dietlibc), bypassing appropriate extra arguments to gcc ...

2 of 2
-5

The short answer is that if the two were 'bundled' together, glibc would be licensed under the GPL*, and it would therefore be completely unsuitable for proprietary projects. While the FSF and GNU project has no love for proprietary software, glibc was licensed LGPL as a strategic choice to advance adoption of GCC and the free software ecosystem. GCC is actually licensed under the GPL with a specific runtime linking exception, because the situation is somewhat muddy. glibc is licensed per the LGPL to permit sensible shared-library situations.

https://www.gnu.org/licenses/gcc-exception-faq.html

Additionally, glibc has all kinds of shims and other components to adapt it for varying operating systems, and distributing that as the same package as gcc would also make things messy.

*Alternativly, GCC could be licensed under something other GPL, though the FSF's thoughts on that would be along the lines of "over my dead body".

Discussions

Questions about C standard library, glibc and gcc
gcc provides all freestanding implementation header files when you use the -ffreestanding , but will provide the rest if you are using it in a hosted environment . The C Standard implementation for bare-metal environments doesnt necessarily need to act like a hosted environment either. More on reddit.com
🌐 r/C_Programming
8
23
July 15, 2020
linker - difference between -lgcc_s and gcc - Stack Overflow
what is the difference between linking against gcc_s and gcc by means of LDFLAGS? Is gcc_s a static library and gcc shared library? Because I was looking for a solution where it is mentioned to l... More on stackoverflow.com
🌐 stackoverflow.com
c - Do I really need libgcc? - Stack Overflow
I've been using GCC 4.6.2 on Mac OS X 10.6. I use the -static-libgcc option when I compile, otherwise my binaries look for libgcc on the system and I'm not sure anything over GCC 4.2 is supported o... More on stackoverflow.com
🌐 stackoverflow.com
c++ - Glibc vs GCC vs binutils compatibility - Stack Overflow
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 someth... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/linuxquestions › what is the relationship between gcc , libstdc++ , glibc , binutils ?
r/linuxquestions on Reddit: What is the relationship between gcc , libstdc++ , glibc , binutils ?
December 22, 2013 -

what is exactly the relationship between those , and why they are seperate?

and if i was to upgrade them what is the hiearchy , should i upgrade gcc first then use that new gcc to compile the rest or what exactly?

Top answer
1 of 3
27
These things are separate because turning a set of C or C++ source files into an executable is a multi-step process. gcc is the GNU Compiler Collection. It deals with turning source files into architecture-dependant assembly code. It's the first step in compilation, and is typically the only user-invoked bit of the process (gcc typically deals with calling the assembler and linker automatically) glibc is the GNU implementation of the Standard C library. The Standard C library is a set of C header files that provide core definitions and low-level functionality needed for non-trivial programs to operate. See here http://en.wikipedia.org/wiki/C_standard_library libstdc++ is the C++ standard library. It provides the same core definitions and low-level functionality as the Standard C library, plus a whole heap of other stuff too. (stuff that, if you'd done the program in C, would need additional external libraries linked in) See here http://en.wikipedia.org/wiki/C%2B%2B_standard_library binutils are programs for translating assembly language into object code, and various manipulation techniques for linking object files together. http://en.wikipedia.org/wiki/Binutils An example might be helpful here, so here goes. main.c int main() { hello(); bye(); } hello.c #include void hello() { printf ("Hello World!\n"); } bye.c #include void bye() { printf ("Goodbye World!\n"); } As you can see from the source files, we're including the input/output functions from the Standard C library. Calling gcc in the conventional way will just compile the thing in one go, without showing you any of the intermediate steps. gcc -o foo main.c hello.c bye.c You get an executable foo However, if you tell gcc not to do anything other than compile to assembly, you can see the intermediate steps. gcc -S -o main.S main.c gcc -S -o hello.S hello.c gcc -S -o bye.S bye.c Now you have 3 assembly files, translated from the C source code. View these in a text editor to see the assembly hello.S .file "hello.c" .section .rodata .LC0: .string "Hello World!" .text .globl hello .type hello, @function hello: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $.LC0, %edi call puts popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size hello, .-hello .ident "GCC: (Gentoo 4.8.2 p1.0, pie-0.5.8) 4.8.2" .section .note.GNU-stack,"",@progbits Then you can run the assembly through the assembler to get the 3 object files as -o main.o main.S as -o hello.o hello.S as -o bye.o bye.S These object files are binary, so not viewable by a text editor. Then you can link the 3 object files together into a single executable (ld is a pain to use directly, so I'm using it via gcc) gcc -o foo main.o hello.o bye.o Bingo, your foo executable.
2 of 3
5
Ideally somebody else will point you to a writeup on this, but here's quick overview as I understand it. Here I'm writing from the perspective of building a cross-compiler, which isn't quite what you're asking, but it's the sequence I know and may be of help: binutils. You need to build these first, and these you get a set of tools including the assembler, linker, etc. Bootstrapping a cross-compiling gcc is a pain in the arse. My memory is that the next step is to build a basic gcc. Next we can build glibc, the C run time library. Now we can rebuild gcc including the C++ compiler. Finally libstdc++, the C++ run time library, can be built with our shiny new C++ compiler. The last time I had to play this game I used crosstool-NG to do the heavy lifting for me.
🌐
OSDev Wiki
wiki.osdev.org › Libgcc
Libgcc - OSDev Wiki
The GNU Compiler Collection uses a special library called libgcc during code generation, which contains shared code that would be inefficient to duplicate every time as well as auxiliary helper routines and runtime support. Its exact contents depends on the particular target, configuration ...
🌐
Linux-m68k
linux-m68k.org › faq › glibcinfo.html
What's the difference between glibc and libc6?
libc6 and glibc are the same version of libc; officially, it's version 2 of the GNU C Library (but it's the sixth major version of the Linux C library).
🌐
Etalabs
etalabs.net › compare_libcs.html
Comparison of C/POSIX standard library implementations for Linux
Part of what makes the shared libraries larger than their static equivalents is that they include parts of libgcc for long division and other math functions. The size totals for glibc include the size of iconv modules, roughly 5M, in the “Complete .so set” figure.
🌐
GitHub
github.com › gcc-mirror › gcc › blob › master › libgcc › config › libgcc-glibc.ver
gcc/libgcc/config/libgcc-glibc.ver at master · gcc-mirror/gcc
# create a libgcc.so, glibc reexported a number of routines from libgcc.a. # By now choosing the same version tags for these specific routines, we · # maintain enough binary compatibility to allow future versions of glibc · # to defer implementation of these routines to libgcc.so via DT_AUXILIARY.
Author   gcc-mirror
🌐
GNU
gcc.gnu.org › onlinedocs › gccint › Libgcc.html
Libgcc (GNU Compiler Collection (GCC) Internals)
Most of the routines in libgcc handle arithmetic operations that the target processor cannot perform directly. This includes integer multiply and divide on some machines, and all floating-point and fixed-point operations on other machines.
Find elsewhere
🌐
Narkive
gnu.gcc.help.narkive.com › 5fD1HYIU › what-is-the-different-between-glibc-and-libc-so-libstdc
what is the different between glibc.* and libc.so.*/libstdc++*
ld-linux is responsible for loading each of your executable dependencies, relocating them so they can call each other, etc. libstcd++ provides C++ runtime support: std::cout, etc. libgcc_s provides other C++ runtime support, mostly to do with exceptions. libc provides the interface to the OS: your ...
🌐
Reddit
reddit.com › r/c_programming › questions about c standard library, glibc and gcc
r/C_Programming on Reddit: Questions about C standard library, glibc and gcc
July 15, 2020 -

I downloaded glibc source from https://sourceware.org/git/?p=glibc.git and was expecting that I would be able to find all the header files from https://en.wikipedia.org/wiki/C_standard_library#Application_programming_interface and their implementation.

(also found on the latest draft for the latest C standard here https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf)

Fortunately my expectations weren't met and I am now on a journey of understanding things a bit better.

This prompted me to search for the missing header files and I found them in /usr/lib/gcc/{triple}/{version}/include folder

Now according to the standard and the question here https://stackoverflow.com/questions/37385899/cannot-find-iso646-h-in-glibc there are 2 forms of conforming implementation:

  1. The freestanding implementation confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>

  2. The hosted implementation which accepts any strictly conforming program i.e. all 29 headers.

Questions:

  1. Why does glibc also contain files float.h and limits.h?

  2. Why is there an equivalent file to the ones in the freestanding implementation in glibc in the folder glibc_root/conform/data/[freestanding_file.h]-data

  3. Does gcc only provide the freestanding implementation headers?

  4. Are the freestanding implementation headers header-only (no linkable code)?

  5. Do the C standard implementation libraries for bare-metal need to implement all the functionality in the rest of the 20 headers? Or does each implementation implement only a subset?

  6. Will arm-none-eabi-gcc and gcc both always provide all the freestanding implementation header files? Or is there an impementation e.g. musl that will implement/provide some of the freestanding headers?

Thanks for any help.

Top answer
1 of 5
6
gcc provides all freestanding implementation header files when you use the -ffreestanding , but will provide the rest if you are using it in a hosted environment . The C Standard implementation for bare-metal environments doesnt necessarily need to act like a hosted environment either.
2 of 5
5
This page gives some more detail about what GCC does and doesn't provide (specifically, it provides some but not all parts of the "freestanding environment" demanded by the standard). Basically, the "C runtime" consists of several components that are automagically linked into any normal userspace program you build, but are usually disabled by stuff like kernels and embedded firmware: The C library: this is your usual glibc, musl or whatever. Almost(?) all the normal functions defined in the C standard are in here, including things from the "freestanding environment" like memcpy. The reason for that is that memcpy can get very complicated (it is probably the most commonly called function ever, so people care very much about optimizing it and there are many possible trade-offs to make) and GCC cannot easily provide a "one size fits all" version. The -nolibc flag can tell GCC not to link this if you want to write your own. The "startup files": the exact details here are architecture and OS dependent, but usually this is a file called crt0.o (you can probably find and disassemble that in your /lib or /usr/lib if you're curious) that defines the function _start, which is where the real entry point of the program is. It handles a few odd features like library constructors (code that a library wants to run before the program starts, can be written with __attribute__((constructor))), assembles the command line arguments in the commonly expected form, and then calls main. This can be disabled with -nostartfiles if you're writing something that's not a userspace program (you probably want a linker script as well). libgcc: this is the library installed directly by GCC (unlike libc) that you found under /usr/lib/gcc. It contains stuff that needs to be so tightly coupled to the compiler that expecting other libc developers to provide it wouldn't make much sense. I believe is here, and things like software emulation for math operations that an architecture doesn't support in hardware. The -nostdlib flag even disables this one (in addition to all of the above) and then you can find fun issues like when you think you just have "pure" C code like a / b somewhere but you suddenly get an undefined reference error for something called _uldivmod, because it turns out that your architecture doesn't natively support 64-bit division and libgcc has just always been software-emulating it for you behind your back.
Top answer
1 of 1
3

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.

🌐
musl libc
wiki.musl-libc.org › functional-differences-from-glibc.html
musl libc - Functional differences from glibc
On software FPU platforms without hardware register for floating-point status flags the software emulation library (provided by the compiler, eg. libgcc) can emulate the status flags with thread storage duration. Currently the status flags are not emulated, so musl is non-conforming on such platforms (neither errno nor fp exceptions are supported). Traditional resolvers, including glibc’s, make use of multiple nameserver lines in resolv.conf by trying each one in sequence and falling to the next after one times out.
🌐
GNU
gcc.gnu.org › legacy-ml › gcc › 2011-11 › msg00235.html
Joseph S. Myers - Re: gcc vs. glibc bootstrapping of libgcc_eh.a
November 9, 2011 - On Wed, 9 Nov 2011, Linas Vepstas wrote: > I've run into a bootstrapping issue which I'd like to solve > "the right way", instead of continuing to hack around it. > > Briefly: I can't build glibc without libgcc_eh.a, which is > provided by gcc. However, libgcc_eh.a is not built, unless > I ...
Top answer
1 of 1
28

Yes, you do need it .... probably. If you don't need it then statically linking it is harmless. You can tell if you need it by using the -t link trace option (I think).

There are various things that you cant do in one instruction (typically things like 64-bit operations on 32-bit architectures). These things can be done, but if they use a non-trivial number of instructions then it's more space-efficient to have them all in one place.

When you disable optimization using -O0 (that's actually the default anyway) then GCC pretty much always uses the libgcc routines.

When you enable speed optimization then GCC may choose to insert the instruction sequence directly into the code (if it knows how). You may find that it ends up using none of the libgcc versions - it will certainly use fewer libgcc calls.

When you enable size optimizations then GCC may prefer the function call, or may not - it depends on what the GCC developers think is the best speed/size trade-off in each case. Note that even when you tell it to optimize for speed, the compiler may judge that some functions are unlikely to be used, and optimize those for size - even more so if you use PGO.

Basically, you can think of it in the same way as memcpy or the math-library functions: the compiler will inline functions it judges to be beneficial, and call library functions otherwise. The compiler can "inline" standard functions and libgcc function without looking at the library definition, of course - it just "knows" what they do.

Whether to use static or dynamic libgcc is an interesting trade-off. On the one hand, a dynamic (shared) library will use less memory across your whole system, and is more likely to be cached, etc. On the other hand, a static libgcc has a lower call overhead.

The most important thing though is compatibility. Obviously the libgcc library has to be present for your program to run, but it also has to be a compatible version. You're ok on a Linux distro with a stable GCC version, but otherwise static linking is safer.

I hope that answers your questions.

🌐
Collabora
collabora.com › news-and-blog › blog › 2023 › 01 › 17 › a-brave-new-world-building-glibc-with-llvm
A brave new world: building glibc with LLVM
January 17, 2023 - Considering how many C language implementations and toolchains have been developed in the past 45+ years (yes, it's been that long!), it is surprising that such a critical, central, and long-lived component of our modern systems, such as glibc, is still only buildable with a single toolchain, the venerable old GNU/GCC, despite LLVM becoming the clear dominant alternative.
🌐
Cprogramming
cboard.cprogramming.com › tech-board › 88685-difference-between-glibc-standard-c-library.html
Difference between GLIBC and Standard C library
glibc is an implementation of the C runtime library, along with some additional stuff required by POSIX or just thought useful by the developers. However, some really compiler-specific parts of the CRT are not part of glibc and are instead expected to be provided by the compiler.
🌐
MaskRay
maskray.me › blog › 2022-05-29-glibc
Everything I know about glibc | MaskRay
January 20, 2026 - If libgcc_s.so.1:_Unwind_Backtrace ... cause issues if the _Unwind_Context created by libgcc is accessed by libunwind, as the two have different layouts of _Unwind_Context. ChromeOS has an issue related to this problem in glibc on AArch32....
Top answer
1 of 2
5

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.

2 of 2
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.

🌐
Stack Overflow
stackoverflow.com › questions › 78613107 › what-is-the-difference-between-libgcc-and-libc
c - What is the difference between libgcc and libc? - Stack Overflow
June 12, 2024 - Per the documentation, libgcc is a low-level runtime library, that is used by gcc internals "automatically".