# kraj/glibc architecture

> Architecture diagram of the GitHub repository kraj/glibc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kraj/glibc
- Repository: https://github.com/kraj/glibc

## Overview

GNU C Library (glibc) implements the standard C and POSIX-facing runtime used by C and compatible-language programs to access operating-system services. The principal workflow is an application calling a libc API, which provides a result directly or mediates access to the kernel; name-service lookups can additionally be configured to consult provider modules, including files and DNS. The tree and README establish the product’s broad runtime scope, while sampled source supports detail mainly for DNS queries, NSS configuration and service lookup, and NSCD caching; other branches are shown at subsystem level.

Main entry points: [`assert/assert.c`](https://github.com/kraj/glibc/blob/master/assert/assert.c) (C runtime APIs), [`nss/nss_database.c`](https://github.com/kraj/glibc/blob/master/nss/nss_database.c) (NSS configuration), [`resolv/res_query.c`](https://github.com/kraj/glibc/blob/master/resolv/res_query.c) (DNS resolver), [`csu/start.c`](https://github.com/kraj/glibc/blob/master/csu/start.c) (Program startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Process startup"]
  node_entry["Program startup<br/>[start.c]"]
  node_init["Libc initialization<br/>[libc-start.c]"]
end

subgraph group_core["Core runtime"]
  node_api["C runtime APIs<br/>[assert.c]"]
  node_stdio["Buffered I/O"]
  node_strings["String routines<br/>[memcpy_chk.c]"]
  node_characters["Character handling<br/>[ctype.c]"]
  node_threads["Thread runtime<br/>[proc_service.h]"]
end

subgraph group_lookup["Name services"]
  node_nssconfig["NSS configuration<br/>[nss_database.c]"]
  node_nssfiles["Files provider<br/>[files-service.c]"]
  node_hesiod["Hesiod provider<br/>[hesiod-service.c]"]
  node_resolver["DNS resolver<br/>[res_query.c]"]
  node_querypacket["Query construction<br/>[res_mkquery.c]"]
  node_nscd["Lookup cache<br/>[servicescache.c]"]
  node_cacheprotocol["Cache protocol<br/>[nscd-client.h]"]
end

subgraph group_dynamic["Dynamic linking"]
  node_loader["Dynamic loader<br/>[rtld.c]"]
end

node_app(("Application"))
node_kernel(("Operating system"))
node_dns(("DNS servers"))

node_app -->|"starts process"| node_entry
node_entry -->|"transfers control"| node_init
node_init -->|"initializes runtime"| node_api
node_app -->|"calls APIs"| node_api
node_api -->|"requests OS services"| node_kernel
node_api -->|"uses I/O"| node_stdio
node_api -->|"uses routines"| node_strings
node_api -->|"uses classification"| node_characters
node_api -->|"uses threading"| node_threads
node_app -->|"loads objects"| node_loader
node_api -->|"gets provider actions"| node_nssconfig
node_nssconfig -->|"selects provider"| node_nssfiles
node_nssconfig -->|"selects provider"| node_resolver
node_nssconfig -.->|"selects provider"| node_hesiod
node_resolver -->|"constructs queries"| node_querypacket
node_resolver -->|"sends DNS queries"| node_dns
node_api -.->|"requests cached lookup"| node_nscd
node_nscd -->|"uses request types"| node_cacheprotocol
node_nssfiles -->|"reads service files"| node_kernel
node_hesiod -.->|"resolves Hesiod records"| node_resolver

click node_entry "https://github.com/kraj/glibc/blob/master/csu/start.c"
click node_init "https://github.com/kraj/glibc/blob/master/csu/libc-start.c"
click node_api "https://github.com/kraj/glibc/blob/master/assert/assert.c"
click node_stdio "https://github.com/kraj/glibc/tree/master/libio"
click node_strings "https://github.com/kraj/glibc/blob/master/debug/memcpy_chk.c"
click node_characters "https://github.com/kraj/glibc/blob/master/ctype/ctype.c"
click node_threads "https://github.com/kraj/glibc/blob/master/sysdeps/nptl/proc_service.h"
click node_nssconfig "https://github.com/kraj/glibc/blob/master/nss/nss_database.c"
click node_nssfiles "https://github.com/kraj/glibc/blob/master/nss/nss_files/files-service.c"
click node_hesiod "https://github.com/kraj/glibc/blob/master/hesiod/nss_hesiod/hesiod-service.c"
click node_resolver "https://github.com/kraj/glibc/blob/master/resolv/res_query.c"
click node_querypacket "https://github.com/kraj/glibc/blob/master/resolv/res_mkquery.c"
click node_nscd "https://github.com/kraj/glibc/blob/master/nscd/servicescache.c"
click node_cacheprotocol "https://github.com/kraj/glibc/blob/master/nscd/nscd-client.h"
click node_loader "https://github.com/kraj/glibc/blob/master/elf/rtld.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_init toneBlue
class node_api,node_stdio,node_strings,node_characters,node_threads toneAmber
class node_nssconfig,node_nssfiles,node_hesiod,node_resolver,node_querypacket,node_nscd,node_cacheprotocol,node_dns toneMint
class node_loader toneRose
class node_app,node_kernel toneIndigo
```

## Components

### Process startup

- [Program startup](https://github.com/kraj/glibc/blob/master/csu/start.c): `csu/start.c`
- [Libc initialization](https://github.com/kraj/glibc/blob/master/csu/libc-start.c): `csu/libc-start.c`

### Core runtime

- [C runtime APIs](https://github.com/kraj/glibc/blob/master/assert/assert.c): `assert/assert.c`
- [Buffered I/O](https://github.com/kraj/glibc/tree/master/libio): `libio`
- [String routines](https://github.com/kraj/glibc/blob/master/debug/memcpy_chk.c): `debug/memcpy_chk.c`
- [Character handling](https://github.com/kraj/glibc/blob/master/ctype/ctype.c): `ctype/ctype.c`
- [Thread runtime](https://github.com/kraj/glibc/blob/master/sysdeps/nptl/proc_service.h): `sysdeps/nptl/proc_service.h`

### Name services

- [NSS configuration](https://github.com/kraj/glibc/blob/master/nss/nss_database.c): `nss/nss_database.c`
- [Files provider](https://github.com/kraj/glibc/blob/master/nss/nss_files/files-service.c): `nss/nss_files/files-service.c`
- [Hesiod provider](https://github.com/kraj/glibc/blob/master/hesiod/nss_hesiod/hesiod-service.c): `hesiod/nss_hesiod/hesiod-service.c`
- [DNS resolver](https://github.com/kraj/glibc/blob/master/resolv/res_query.c): `resolv/res_query.c`
- [Query construction](https://github.com/kraj/glibc/blob/master/resolv/res_mkquery.c): `resolv/res_mkquery.c`
- [Lookup cache](https://github.com/kraj/glibc/blob/master/nscd/servicescache.c): `nscd/servicescache.c`
- [Cache protocol](https://github.com/kraj/glibc/blob/master/nscd/nscd-client.h): `nscd/nscd-client.h`

### Dynamic linking

- [Dynamic loader](https://github.com/kraj/glibc/blob/master/elf/rtld.c): `elf/rtld.c`

### Other components

- **Application**
- **Operating system**
- **DNS servers**

## Connections

- Application → Program startup: starts process
- Program startup → Libc initialization: transfers control
- Libc initialization → C runtime APIs: initializes runtime
- Application → C runtime APIs: calls APIs
- C runtime APIs → Operating system: requests OS services
- C runtime APIs → Buffered I/O: uses I/O
- C runtime APIs → String routines: uses routines
- C runtime APIs → Character handling: uses classification
- C runtime APIs → Thread runtime: uses threading
- Application → Dynamic loader: loads objects
- C runtime APIs → NSS configuration: gets provider actions
- NSS configuration → Files provider: selects provider
- NSS configuration → DNS resolver: selects provider
- NSS configuration → Hesiod provider: selects provider
- DNS resolver → Query construction: constructs queries
- DNS resolver → DNS servers: sends DNS queries
- C runtime APIs → Lookup cache: requests cached lookup
- Lookup cache → Cache protocol: uses request types
- Files provider → Operating system: reads service files
- Hesiod provider → DNS resolver: resolves Hesiod records
