Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is GLIBC? What is it used for?

People also ask

Is glibc part of Linux?

glibc By far the most widely used C library on Linux is the GNU C Library ⟨http://www.gnu.org/software/libc/⟩, often referred to as glibc. This is the C library that is nowadays used in all major Linux distributions.

What's the difference between gcc and glibc?

GCC is the C compiler. Glibc is the C library. However, isn't it an absolute necessity for a compiler and the standard library bundled together as a C implementation? For example, the C library contains ABI and compiler specific stuff like <limits.


Its the implementation of Standard C library described in C standards plus some extra useful stuffs which are not strictly standard but used frequently.

Its main contents are :

1) C library described in ANSI,c99,c11 standards. It includes macros, symbols, function implementations etc.(printf(),malloc() etc)

2) POSIX standard library. The "userland" glue of system calls. (open(),read() etc. Actually glibc does not "implement" system calls. kernel does it. But glibc provides the user land interface to the services provided by kernel so that user application can use a system call just like a ordinary function.

3) Also some nonstandard but useful stuff.

"use the force, read the source "

$git clone git://sourceware.org/git/glibc.git

(I was recently pretty enlightened when i looked through malloc.c in glibc)


There are several implementations of the standard. Glibc is the implementation that most Linuxes use, but there are others. Glibc also contains (as Aftnix states) the glue functions which set up the scene for jumps into the kernel (also known as system calls). So many of glibc's 'functions' don't do the actual work but only delegate to the kernel.

To read the source of Glibc, just google for it. There are myriad sites which carry it, and also several variations.

Windows uses Microsoft's own implementation, which I believe is called MSVCR.DLL. I doubt that you will find the source code to that library anywhere. Also note that some functions which a Linux hacker might think of as 'standard', simply don't exist on Windows (notably fork). The reverse is also true.

Other systems will have their own libc.


The glibc package contains standard libraries which are used by multiple programs on the system. In order to save disk space and memory, as well as to make upgrading easier, common system code iskept in one place and shared between programs. This particular package contains the most important sets of shared libraries: the standard C library and the standard math library. Without these two libraries, a Linux system will not function. The glibc package also contains national language (locale) support.


Yes, It's the implementation of standard library functions.

More specifically, it is the implementation for all GNU systems and in almost all *NIX systems that use the Linux kernel.


Here are a few "hands-on" points of view:

  • it implements the POSIX C API on top of the Linux kernel: What is the meaning of "POSIX"?
  • it contains several assembly hand-optimized versions of ANSI C functions for several different architectures, e.g. strlen:
    • sysdeps/x86_64/strlen.S
    • sysdeps/aarch64/strlen.S
  • how to modify its source, recompile and use it understand it better: How to compile my own glibc C standard library from source and use it?
  • how to GDB step debug it with QEMU and Buildroot: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/9693c23fe6b2ae1409010a1a29ff0c1b7bd4b39e#gdbserver-libc