GNU C Library (glibc)

repository·master·Indexed 23 days ago

https://github.com/bminor/glibc

The standard system C library for GNU systems, providing the essential system API for C and C-compatible languages as the interface between applications and the operating system. Documentation covers security advisory formats and CVE processing, the microbenchmark suite for performance measurement, the Hesiod NSS module for name service data, and locale data compilation using localedef.

Tokens
8K
Snippets
12
Records
48
Agent score
81%

What's inside glibc

  1. Overview of bundled files in support/bundled

    master
    The support/bundled directory contains files that are included verbatim from external sources. These files are specifically used to build the support/ infrastructure of glibc. One of the primary subdirectories is linux/, which contains selected files from the Linux 6.10 source tree.
  2. Overview of glibc Python pretty printers

    master

    The glibc Python pretty printers are GDB extensions designed to transform raw, complex C structures into human-readable information during debugging. For example, instead of seeing the internal bitfields and raw memory of a pthread_mutex_t, a pretty printer allows GDB to display high-level state such as Type = Normal, Status = Not acquired, and Protocol = Priority protect.

    How they work

    • Triggering: The printers use gdb.RegexpCollectionPrettyPrinter, meaning they are triggered when the type of the variable being printed matches a specific regular expression (e.g., ^pthread_mutex_t$).
    • Registration: They are registered for the current object file using gdb.printing.register_pretty_printer().
    • Constants: Printers often rely on constant files generated from C headers during the glibc build process. These files must be in the Python search path for the printers to load correctly.
  3. How multiple execution units work in benchtests

    master

    You can partition a single input file into multiple distinct benchmark groups using the ##name: directive. This is useful for measuring different input domains (like different bit-precisions in math functions) separately.

    Partitioning by Domain

    Use ##name: <label> to start a new section. All inputs following the directive belong to that label until the next ##name: directive or the end of the file. Each group is output separately in benchtests/bench.out.

    Workload Traces

    To measure latency or throughput of a real-world workload trace, use the ##name: workload-<name> directive. In this mode, the entire trace is iterated over multiple times rather than repeating every individual input multiple times.

  4. Configure extra constraints using libm-test-ulps

    master

    A libm-test-ulps file is used to define maximal error constraints in Units of Least Precision (ULP). If a function's error exceeds these values, the test fails.

    Syntax and Keywords

    Specify the function name followed by the allowed error for each floating-point type. Supported keywords are float, double, ldouble, and float128.

    Function "yn":
    float: 2
    double: 6

    Testing Different Rounding Modes

    By default, tests use FE_TONEAREST. To test other rounding modes, prepend the function name with an underscore and the mode name:

    • _downward (FE_DOWNWARD)
    • _towardzero (FE_TOWARDZERO)
    • _upward (FE_UPWARD)

    Example for FE_DOWNWARD:

    Function "yn_downward":
    float: 3
    double: 7
  5. How the Hesiod NSS module works

    master

    The Hesiod NSS module provides access to Hesiod name service data for the group, passwd, and services databases.

    Limitations:

    • You cannot iterate over the entire database using getgrent(), getpwent(), or getservent().
    • It does not support looking up services by port; it only supports looking up services by name.

    Supported Lookups: Because of these limitations, the Hesiod name service is only consulted when using the following functions (or their reentrant counterparts):

    • getgrname(), getgrgid()
    • getpwname(), getpwuid()
    • getservbyname()
  6. Requirements for using Linux kernels

    master

    When working with Linux kernels, this version of the GNU C Library has the following requirements:

    • Kernel Version: Requires Linux kernel version 3.2 or later.
    • Dependencies: The shared version of the libgcc_s library must be installed for the pthread library to function correctly.
  7. Understand the libm-test math test suite architecture

    master

    The libm-test suite evaluates math functions in the GNU C library by comparing results against precomputed values and ISO C99 requirements. It tests special IEEE 754 values (infinities, NaNs, minus zero) and various random values.

    Core Components

    • Templates (libm-test-<func>.inc): Platform-independent test templates for math functions.
    • Generated Files: The Python script gen-libm-test.py processes templates and auto-libm-test-out-<func> files to produce platform-specific C files (libm-test-<func>.c) and a ULPs header (libm-test-ulps.h).
    • Test Drivers: Generated by the Makefile, these drivers test specific floating-point types:
      • test-float-<func>.c: Tests float implementation.
      • test-double-<func>.c: Tests double implementation.
      • test-ldouble-<func>.c: Tests long double implementation.
    • Test Case Generation: The gen-auto-libm-tests program generates auto-libm-test-out-<func> files from auto-libm-test-in files.
  8. Understand the role of the POSIX locale definition

    master
    The POSIX locale definition file in this directory is not intended to be used as an input file for localedef. Instead, it serves as a reference showing the values built into the libc binaries as default values when no legal locale is found or when the "C" or "POSIX" locale is explicitly selected.
  9. Understand the GNU C Library Security Advisory Format

    master

    Security advisories in the advisories directory use a git commit log format consisting of a heading and a free-format description. Key information is extracted using specific tags.

    References to code changes follow the pattern: Tag-name: <commit-ref> (release-version)

    Where:

    • <commit-ref> is the specific git commit.
    • release-version is derived from git-describe (e.g., 2.34-NNN). If the -NNN suffix is absent, the change is in the release tarball. If present, the change is on the release/2.YY/master branch and not in a released tarball.
  10. How the glibc Tunables framework works

    master

    The Tunables framework allows glibc modules to register variables that can be modified via environment variables at runtime. This enables application authors and distribution maintainers to adjust library behavior to match specific workloads without recompiling.

    Tunables are organized into a hierarchical namespace structure: TOP_NAMESPACE (defaults to glibc) -> NAMESPACE -> TUNABLE.

    Key Constraints:

    • The tunable list becomes read-only after the dynamic linker relocates itself. Therefore, setting tunable values is generally limited to the dynamic linker itself and must occur before relocation.
  11. How the resolver handles thread-local state

    master

    In glibc, the _res symbol is redefined as a macro to provide access to a per-thread resolver state when the program is linked with -lpthread.

    This mechanism allows different threads to maintain their own DNS configuration and state without interfering with each other. This is the same pattern used for errno. This per-thread state is also utilized by the gethostby* family of functions to ensure thread safety (e.g., gethostbyname_r).

    Warning for Multi-threaded programs: If you manipulate the _res structure in threads other than the "main" thread, calls to traditional (non-n prefixed) functions like gethostbyname will not be influenced by those changes, as they still reference the main thread's state.

  12. Use compiled locale data with setlocale

    master
    Once locale data files are compiled and placed in the appropriate directory, they can be used by GNU libc functions. For detailed information on how to apply these locales to your application, refer to the GNU libc manual section describing the setlocale function.