[libc-commits] [libc] [libc][docs] Link C23 sections to cppreference in docgen (PR #240746)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 00:04:29 PST 2026


https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/240746

Header status tables currently render C23 section numbers as static badges, forcing readers to look up standard definitions manually while POSIX columns already link directly to the Open Group specification.

Add c-reference-root and optional per-symbol c-reference paths to the C23 docgen YAML catalogues so numeric C standard sections render as links to their corresponding cppreference.com pages.  Non-section annotations such as glibc extension notes remain plain badges.

Assisted-by: Automated tooling, human reviewed.

>From 458672cb2becd36aed5ad56b5ac6cd00eccecc65 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Fri, 6 Nov 2026 16:25:13 +0000
Subject: [PATCH] [libc][docs] Link C23 sections to cppreference in docgen

Header status tables currently render C23 section numbers as static
badges, forcing readers to look up standard definitions manually while
POSIX columns already link directly to the Open Group specification.

Add c-reference-root and optional per-symbol c-reference paths to the
C23 docgen YAML catalogues so numeric C standard sections render as
links to their corresponding cppreference.com pages.  Non-section
annotations such as glibc extension notes remain plain badges.

Assisted-by: Automated tooling, human reviewed.
---
 libc/docs/_static/status.css     |  23 +++++-
 libc/utils/docgen/assert.yaml    |   1 +
 libc/utils/docgen/ctype.yaml     |   1 +
 libc/utils/docgen/docgen.py      | 109 +++++++++++++++++++++-----
 libc/utils/docgen/docgen_test.py | 129 ++++++++++++++++++++++++++++++-
 libc/utils/docgen/errno.yaml     |   4 +
 libc/utils/docgen/fenv.yaml      |  30 +++++++
 libc/utils/docgen/float.yaml     |   3 +
 libc/utils/docgen/inttypes.yaml  |   7 ++
 libc/utils/docgen/locale.yaml    |   7 ++
 libc/utils/docgen/setjmp.yaml    |   1 +
 libc/utils/docgen/signal.yaml    |  10 +++
 libc/utils/docgen/stdbit.yaml    |  88 +++++++++++++++++++++
 libc/utils/docgen/stdio.yaml     |  19 +++++
 libc/utils/docgen/stdlib.yaml    |  48 ++++++++++++
 libc/utils/docgen/string.yaml    |   2 +
 libc/utils/docgen/threads.yaml   |   3 +
 libc/utils/docgen/time.yaml      |   1 +
 libc/utils/docgen/uchar.yaml     |   1 +
 libc/utils/docgen/wchar.yaml     |  39 ++++++++++
 libc/utils/docgen/wctype.yaml    |   1 +
 21 files changed, 499 insertions(+), 28 deletions(-)

diff --git a/libc/docs/_static/status.css b/libc/docs/_static/status.css
index f1828153559c8d..1b4a30df5e8b40 100644
--- a/libc/docs/_static/status.css
+++ b/libc/docs/_static/status.css
@@ -132,21 +132,38 @@ body[data-theme="dark"] {
   white-space: nowrap;
 }
 
+.hc-c-link,
 .hc-posix-link {
   display: inline-flex;
   align-items: center;
   gap: 3px;
   font-size: 0.76rem;
-  font-weight: 500;
   color: var(--hc-blue-text);
   background: var(--hc-blue-bg);
   border: 1px solid var(--hc-blue-border);
-  padding: 1px 7px;
-  border-radius: 999px;
   text-decoration: none;
   white-space: nowrap;
 }
 
+.hc-c-link {
+  font-family: var(--font-stack--monospace, monospace);
+  padding: 1px 6px;
+  border-radius: 4px;
+}
+
+.hc-posix-link {
+  font-weight: 500;
+  padding: 1px 7px;
+  border-radius: 999px;
+}
+
+.hc-c-link:hover,
 .hc-posix-link:hover {
   text-decoration: underline;
 }
+
+.hc-c-link:focus-visible,
+.hc-posix-link:focus-visible {
+  outline: 2px solid var(--hc-blue-text);
+  outline-offset: 2px;
+}
diff --git a/libc/utils/docgen/assert.yaml b/libc/utils/docgen/assert.yaml
index 0afd4e2d3c063f..58175aceb2fc3d 100644
--- a/libc/utils/docgen/assert.yaml
+++ b/libc/utils/docgen/assert.yaml
@@ -1,3 +1,4 @@
+c-reference-root: error/assert
 macros:
   __STDC_VERSION_ASSERT_H__:
     c-definition: 7.2.1
diff --git a/libc/utils/docgen/ctype.yaml b/libc/utils/docgen/ctype.yaml
index 027d8f38c71f97..2f855dc2b6e242 100644
--- a/libc/utils/docgen/ctype.yaml
+++ b/libc/utils/docgen/ctype.yaml
@@ -1,3 +1,4 @@
+c-reference-root: string/byte
 functions:
   isalnum:
     c-definition: 7.4.1.1
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 3714eca6254d8c..f9f019eb595025 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -8,13 +8,16 @@
 # ===----------------------------------------------------------------------===##
 from argparse import ArgumentParser, Namespace
 import html
-from pathlib import Path
-from typing import Callable, Dict
 import os
+from pathlib import Path
+import re
 import sys
+from typing import Callable, Dict, Optional
 
 from header import Header
 
+_CPPREFERENCE_BASE = "https://en.cppreference.com/w/c"
+
 
 class DocgenAPIFormatError(Exception):
     """Raised on fatal formatting errors with a description of a formatting error"""
@@ -51,6 +54,8 @@ def check_api(header: Header, api: Dict):
     :param api: docgen yaml file contents parsed into a dict
     """
     errors = []
+    if "c-reference-root" in api and not isinstance(api["c-reference-root"], str):
+        errors.append("error: c-reference-root must be a string")
     # We require entries to have at least one of these.
     possible_keys = [
         "c-definition",
@@ -75,6 +80,8 @@ def check_api(header: Header, api: Dict):
             if not any(k in obj for k in possible_keys):
                 err = f"error: Macro {name} does not contain at least one required property: {possible_keys}"
                 errors.append(err)
+            if "c-reference" in obj and not isinstance(obj["c-reference"], str):
+                errors.append(f"error: Macro {name} c-reference must be a string")
 
     # Validate functions
     if "functions" in api:
@@ -91,6 +98,8 @@ def check_api(header: Header, api: Dict):
             if not any(k in obj for k in possible_keys):
                 err = f"error: function {name} does not contain at least one required property: {possible_keys}"
                 errors.append(err)
+            if "c-reference" in obj and not isinstance(obj["c-reference"], str):
+                errors.append(f"error: function {name} c-reference must be a string")
 
     if errors:
         raise DocgenAPIFormatError("\n".join(errors))
@@ -110,29 +119,84 @@ def _status_badge_html(implemented: bool) -> str:
     )
 
 
-def _c_section_html(item: Dict) -> str:
-    sec = item.get("c-definition")
-    if sec:
-        return f'<span class="hc-sec-badge">{html.escape(str(sec))}</span>'
-    return '<span class="hc-status-no" aria-label="Not in C23">–</span>'
-
-
-def _posix_link_html(header: Header, name: str, kind: str, item: Dict) -> str:
-    base = (
-        f"functions/{name}.html"
-        if kind == "function"
+def cppreference_url(
+    header: Header,
+    symbol_name: str = "",
+    kind: str = "function",
+    item: Optional[Dict] = None,
+    api: Optional[Dict] = None,
+) -> str:
+    if item and "c-reference" in item:
+        ref = item["c-reference"]
+        return f"{_CPPREFERENCE_BASE}/{ref}" if ref else ""
+    root = (api if api is not None else header.api).get("c-reference-root")
+    if not root:
+        return ""
+    if (
+        not symbol_name
+        or symbol_name.startswith("__")
+        or kind not in ("function", "family")
+    ):
+        return f"{_CPPREFERENCE_BASE}/{root}"
+    return f"{_CPPREFERENCE_BASE}/{root}/{symbol_name}"
+
+
+def posix_url(header: Header, symbol_name: str, kind: str, item: Dict) -> str:
+    subpath = (
+        f"functions/{symbol_name}.html"
+        if kind in ("function", "family") and symbol_name
         else f"basedefs/{header.name.replace('/', '_')}.html"
     )
     if "in-latest-posix" in item:
-        url = f"https://pubs.opengroup.org/onlinepubs/9799919799/{base}"
-        return f'<a class="hc-posix-link" href="{url}">POSIX.1-2024 ↗</a>'
+        return f"https://pubs.opengroup.org/onlinepubs/9799919799/{subpath}"
     if "removed-in-posix-2008" in item:
-        url = f"https://pubs.opengroup.org/onlinepubs/007904875/{base}"
-        return f'<a class="hc-posix-link" href="{url}">Removed (2008) ↗</a>'
+        return f"https://pubs.opengroup.org/onlinepubs/007904875/{subpath}"
     if "removed-in-posix-2024" in item:
-        url = f"https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/{base}"
-        return f'<a class="hc-posix-link" href="{url}">Removed (2024) ↗</a>'
-    return '<span class="hc-status-no" aria-label="Not in POSIX">–</span>'
+        return f"https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/{subpath}"
+    return ""
+
+
+_C_SECTION_RE = re.compile(r"^([0-9]+|[FGHJK])\.")
+
+
+def _c_section_html(
+    header: Header,
+    name: str,
+    kind: str,
+    item: Dict,
+    api: Optional[Dict] = None,
+) -> str:
+    sec = item.get("c-definition")
+    if not sec:
+        return '<span class="hc-status-no" aria-label="Not in C23">–</span>'
+    label = html.escape(str(sec))
+    if _C_SECTION_RE.match(str(sec)):
+        url = cppreference_url(header, name, kind, item, api)
+        if url:
+            href = html.escape(url, quote=True)
+            return (
+                f'<a class="hc-c-link" href="{href}" '
+                f'title="C23 section {label} on cppreference.com">'
+                f'{label} <span aria-hidden="true">↗</span></a>'
+            )
+    return f'<span class="hc-sec-badge">{label}</span>'
+
+
+def _posix_link_html(header: Header, name: str, kind: str, item: Dict) -> str:
+    url = posix_url(header, name, kind, item)
+    if not url:
+        return '<span class="hc-status-no" aria-label="Not in POSIX">–</span>'
+    if "removed-in-posix-2008" in item:
+        label = "Removed (2008)"
+    elif "removed-in-posix-2024" in item:
+        label = "Removed (2024)"
+    else:
+        label = "POSIX.1-2024"
+    href = html.escape(url, quote=True)
+    return (
+        f'<a class="hc-posix-link" href="{href}">'
+        f'{label} <span aria-hidden="true">↗</span></a>'
+    )
 
 
 def print_symbol_table_md(
@@ -142,6 +206,7 @@ def print_symbol_table_md(
     items: Dict,
     is_implemented_fn: Callable[[str], bool],
     kind: str,
+    api: Optional[Dict] = None,
 ):
     print(
         f"## {section_title}\n\n```{{raw}} html\n"
@@ -156,7 +221,7 @@ def print_symbol_table_md(
         obj = items[name] or {}
         row_id = html.escape(f"{kind}-{name.replace(' ', '-')}", quote=True)
         status = _status_badge_html(is_implemented_fn(name))
-        c_sec = _c_section_html(obj)
+        c_sec = _c_section_html(header, name, kind, obj, api)
         posix = _posix_link_html(header, name, kind, obj)
         print(
             f'    <tr id="{row_id}">'
@@ -179,6 +244,7 @@ def print_header_status_md(header: Header, api: Dict):
             api["macros"],
             header.implements_macro,
             "macro",
+            api,
         )
 
     if api.get("functions"):
@@ -189,6 +255,7 @@ def print_header_status_md(header: Header, api: Dict):
             api["functions"],
             header.implements_fn,
             "function",
+            api,
         )
 
 
diff --git a/libc/utils/docgen/docgen_test.py b/libc/utils/docgen/docgen_test.py
index 27a3af3c10bea3..d68344817703a8 100644
--- a/libc/utils/docgen/docgen_test.py
+++ b/libc/utils/docgen/docgen_test.py
@@ -8,7 +8,7 @@
 # ===----------------------------------------------------------------------===##
 """Unit tests for docgen and header implementation status evaluation."""
 
-from contextlib import redirect_stdout
+from contextlib import redirect_stderr, redirect_stdout
 import io
 from pathlib import Path
 import sys
@@ -16,7 +16,7 @@
 import unittest
 
 sys.path.insert(0, str(Path(__file__).parent))
-from docgen import print_header_status_md
+from docgen import check_api, cppreference_url, posix_url, print_header_status_md
 from header import Header, _is_stub_file
 
 
@@ -78,10 +78,20 @@ def test_implements_macro(self):
     def test_md_output_generation(self):
         hdr = Header("stdio.h")
         api = {
+            "c-reference-root": "io",
             "macros": {"EOF": {"c-definition": "7.23.1", "in-latest-posix": None}},
             "functions": {
-                "printf": {"c-definition": "7.23.6.3", "in-latest-posix": None},
+                "printf": {
+                    "c-definition": "7.23.6.3",
+                    "c-reference": "io/fprintf",
+                    "in-latest-posix": None,
+                },
+                "printf_s": {
+                    "c-definition": "K.3.5.3.3",
+                    "c-reference": "io/fprintf",
+                },
                 "missing_fn": {"c-definition": "7.23.6.99"},
+                "gnu_fn": {"c-definition": "TODO: glibc extension"},
             },
         }
         buf = io.StringIO()
@@ -97,7 +107,9 @@ def test_md_output_generation(self):
             any(
                 'id="macro-EOF"' in l
                 and 'title="Implemented"' in l
+                and 'href="https://en.cppreference.com/w/c/io"' in l
                 and "basedefs/stdio.h.html" in l
+                and '<span aria-hidden="true">↗</span>' in l
                 for l in lines
             )
         )
@@ -105,16 +117,125 @@ def test_md_output_generation(self):
             any(
                 'id="function-printf"' in l
                 and 'title="Implemented"' in l
+                and 'href="https://en.cppreference.com/w/c/io/fprintf"' in l
                 and "functions/printf.html" in l
                 for l in lines
             )
         )
         self.assertTrue(
             any(
-                'id="function-missing_fn"' in l and 'title="Not Implemented"' in l
+                'id="function-printf_s"' in l
+                and 'href="https://en.cppreference.com/w/c/io/fprintf"' in l
                 for l in lines
             )
         )
+        self.assertTrue(
+            any(
+                'id="function-missing_fn"' in l
+                and 'title="Not Implemented"' in l
+                and 'href="https://en.cppreference.com/w/c/io/missing_fn"' in l
+                for l in lines
+            )
+        )
+        self.assertTrue(
+            any(
+                'id="function-gnu_fn"' in l
+                and '<span class="hc-sec-badge">TODO: glibc extension</span>' in l
+                for l in lines
+            )
+        )
+
+    def test_external_urls(self):
+        cases = [
+            (
+                "stdio.h",
+                "fopen",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/io/fopen",
+            ),
+            (
+                "stdio.h",
+                "printf",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/io/fprintf",
+            ),
+            (
+                "stdio.h",
+                "SEEK_SET",
+                "macro",
+                "macros",
+                "https://en.cppreference.com/w/c/io/fseek",
+            ),
+            (
+                "stdlib.h",
+                "malloc",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/memory/malloc",
+            ),
+            (
+                "stdlib.h",
+                "strfromd128",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/string/byte/strfromf",
+            ),
+            (
+                "stdbit.h",
+                "stdc_bit_ceil_ui",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/numeric/bit/stdc_bit_ceil",
+            ),
+            (
+                "time.h",
+                "clock",
+                "function",
+                "functions",
+                "https://en.cppreference.com/w/c/chrono/clock",
+            ),
+            ("unistd.h", "fork", "function", "functions", ""),
+        ]
+        for hname, sym, kind, sec, expected in cases:
+            hdr = Header(hname)
+            item = (hdr.api.get(sec) or {}).get(sym, {})
+            with self.subTest(header=hname, symbol=sym):
+                self.assertEqual(cppreference_url(hdr, sym, kind, item), expected)
+        with redirect_stderr(io.StringIO()):
+            for yf in sorted(Path(__file__).parent.rglob("*.yaml")):
+                rel = yf.relative_to(Path(__file__).parent).with_suffix(".h").as_posix()
+                hdr = Header(rel)
+                check_api(hdr, hdr.api)
+        self.assertEqual(
+            posix_url(
+                Header("sys/stat.h"), "chmod", "function", {"in-latest-posix": None}
+            ),
+            "https://pubs.opengroup.org/onlinepubs/9799919799/functions/chmod.html",
+        )
+        self.assertEqual(
+            posix_url(
+                Header("sys/stat.h"), "S_IRUSR", "macro", {"in-latest-posix": None}
+            ),
+            "https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_stat.h.html",
+        )
+        self.assertEqual(
+            posix_url(
+                Header("strings.h"), "bcmp", "function", {"removed-in-posix-2008": None}
+            ),
+            "https://pubs.opengroup.org/onlinepubs/007904875/functions/bcmp.html",
+        )
+        self.assertEqual(
+            posix_url(
+                Header("sys/time.h"),
+                "gettimeofday",
+                "function",
+                {"removed-in-posix-2024": None},
+            ),
+            "https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/gettimeofday.html",
+        )
+        self.assertEqual(posix_url(Header("stdio.h"), "printf", "function", {}), "")
 
 
 if __name__ == "__main__":
diff --git a/libc/utils/docgen/errno.yaml b/libc/utils/docgen/errno.yaml
index da41552bc3a180..d2bdeaa4daae75 100644
--- a/libc/utils/docgen/errno.yaml
+++ b/libc/utils/docgen/errno.yaml
@@ -1,12 +1,16 @@
+c-reference-root: error/errno
 macros:
   EDOM:
     c-definition: '7.5'
+    c-reference: error/errno_macros
     in-latest-posix: ''
   EILSEQ:
     c-definition: '7.5'
+    c-reference: error/errno_macros
     in-latest-posix: ''
   ERANGE:
     c-definition: '7.5'
+    c-reference: error/errno_macros
     in-latest-posix: ''
   errno:
     c-definition: '7.5'
diff --git a/libc/utils/docgen/fenv.yaml b/libc/utils/docgen/fenv.yaml
index 1d73697f36becf..48d5e408b3c7bb 100644
--- a/libc/utils/docgen/fenv.yaml
+++ b/libc/utils/docgen/fenv.yaml
@@ -1,52 +1,71 @@
+c-reference-root: numeric/fenv
 functions:
   fe_dec_getround:
     c-definition: 7.6.5.3
+    c-reference: numeric/fenv
   fe_dec_setround:
     c-definition: 7.6.5.6
+    c-reference: numeric/fenv
   feclearexcept:
     c-definition: 7.6.4.1
+    c-reference: numeric/fenv/feexcept
     in-latest-posix: ''
   fegetenv:
     c-definition: 7.6.6.1
+    c-reference: numeric/fenv/feenv
     in-latest-posix: ''
   fegetexceptflag:
     c-definition: 7.6.4.2
+    c-reference: numeric/fenv/feexcept
     in-latest-posix: ''
   fegetmode:
     c-definition: 7.6.5.1
+    c-reference: numeric/fenv
   fegetround:
     c-definition: 7.6.5.2
+    c-reference: numeric/fenv/feround
     in-latest-posix: ''
   feholdexcept:
     c-definition: 7.6.6.2
+    c-reference: numeric/fenv/feenv
     in-latest-posix: ''
   feraiseexcept:
     c-definition: 7.6.4.3
+    c-reference: numeric/fenv/feexcept
     in-latest-posix: ''
   fesetenv:
     c-definition: 7.6.6.3
+    c-reference: numeric/fenv/feenv
     in-latest-posix: ''
   fesetexcept:
     c-definition: 7.6.4.4
+    c-reference: numeric/fenv/feexcept
   fesetexceptflag:
     c-definition: 7.6.4.5
+    c-reference: numeric/fenv/feexcept
     in-latest-posix: ''
   fesetmode:
     c-definition: 7.6.5.4
+    c-reference: numeric/fenv
   fesetround:
     c-definition: 7.6.5.5
+    c-reference: numeric/fenv/feround
     in-latest-posix: ''
   fetestexcept:
     c-definition: 7.6.4.7
+    c-reference: numeric/fenv/feexcept
     in-latest-posix: ''
   fetestexceptflag:
     c-definition: 7.6.4.6
+    c-reference: numeric/fenv/feexcept
   feupdateenv:
     c-definition: 7.6.6.4
+    c-reference: numeric/fenv/feenv
     in-latest-posix: ''
 macros:
   FE_ALL_EXCEPT:
     c-definition: 7.6.12
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_DEC_DOWNWARD:
     c-definition: 7.6.14
@@ -60,37 +79,48 @@ macros:
     c-definition: 7.6.14
   FE_DFL_ENV:
     c-definition: 7.6.17
+    c-reference: numeric/fenv/FE_DFL_ENV
     in-latest-posix: ''
   FE_DFL_MODE:
     c-definition: 7.6.11
   FE_DIVBYZERO:
     c-definition: 7.6.9
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_DOWNWARD:
     c-definition: 7.6.13
+    c-reference: numeric/fenv/FE_round
     in-latest-posix: ''
   FE_INEXACT:
     c-definition: 7.6.9
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_INVALID:
     c-definition: 7.6.9
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_OVERFLOW:
     c-definition: 7.6.9
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_TONEAREST:
     c-definition: 7.6.13
+    c-reference: numeric/fenv/FE_round
     in-latest-posix: ''
   FE_TONEARESTFROMZERO:
     c-definition: 7.6.13
+    c-reference: numeric/fenv/FE_round
   FE_TOWARDZERO:
     c-definition: 7.6.13
+    c-reference: numeric/fenv/FE_round
     in-latest-posix: ''
   FE_UNDERFLOW:
     c-definition: 7.6.9
+    c-reference: numeric/fenv/FE_exceptions
     in-latest-posix: ''
   FE_UPWARD:
     c-definition: 7.6.13
+    c-reference: numeric/fenv/FE_round
     in-latest-posix: ''
   __STDC_VERSION_FENV_H__:
     c-definition: 7.6.5
diff --git a/libc/utils/docgen/float.yaml b/libc/utils/docgen/float.yaml
index a8840b91be55b4..af2539f30c48dc 100644
--- a/libc/utils/docgen/float.yaml
+++ b/libc/utils/docgen/float.yaml
@@ -1,3 +1,4 @@
+c-reference-root: types/limits
 macros:
   DBL_DECIMAL_DIG:
     c-definition: 5.3.5.3.3
@@ -95,6 +96,7 @@ macros:
     in-latest-posix: ''
   INFINITY:
     c-definition: 5.3.5.3.3
+    c-reference: numeric/math/INFINITY
   LDBL_DECIMAL_DIG:
     c-definition: 5.3.5.3.3
     in-latest-posix: ''
@@ -138,6 +140,7 @@ macros:
     in-latest-posix: ''
   NAN:
     c-definition: 5.3.5.3.3
+    c-reference: numeric/math/NAN
   __STDC_VERSION_FLOAT_H__:
     c-definition: '7.7'
 
diff --git a/libc/utils/docgen/inttypes.yaml b/libc/utils/docgen/inttypes.yaml
index cbf50592ef072d..7927ef11efc3b4 100644
--- a/libc/utils/docgen/inttypes.yaml
+++ b/libc/utils/docgen/inttypes.yaml
@@ -1,20 +1,27 @@
+c-reference-root: types/integer
 functions:
   imaxabs:
     c-definition: 7.8.2.1
+    c-reference: numeric/math/abs
     in-latest-posix: ''
   imaxdiv:
     c-definition: 7.8.2.2
+    c-reference: numeric/math/div
     in-latest-posix: ''
   strtoimax:
     c-definition: 7.8.2.3
+    c-reference: string/byte/strtoimax
     in-latest-posix: ''
   strtoumax:
     c-definition: 7.8.2.3
+    c-reference: string/byte/strtoimax
     in-latest-posix: ''
   wcstoimax:
     c-definition: 7.8.2.4
+    c-reference: string/wide/wcstoimax
     in-latest-posix: ''
   wcstoumax:
     c-definition: 7.8.2.4
+    c-reference: string/wide/wcstoimax
     in-latest-posix: ''
 
diff --git a/libc/utils/docgen/locale.yaml b/libc/utils/docgen/locale.yaml
index eea91a885ff49e..523c13a7acee21 100644
--- a/libc/utils/docgen/locale.yaml
+++ b/libc/utils/docgen/locale.yaml
@@ -1,3 +1,4 @@
+c-reference-root: locale
 functions:
   duplocale:
     in-latest-posix: ''
@@ -18,20 +19,26 @@ functions:
 macros:
   LC_ALL:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
   LC_COLLATE:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
   LC_CTYPE:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
   LC_MONETARY:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
   LC_NUMERIC:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
   LC_TIME:
     c-definition: '7.11'
+    c-reference: locale/LC_categories
     in-latest-posix: ''
 
diff --git a/libc/utils/docgen/setjmp.yaml b/libc/utils/docgen/setjmp.yaml
index 123739d1a6ceb0..1c2b5edb04a0a6 100644
--- a/libc/utils/docgen/setjmp.yaml
+++ b/libc/utils/docgen/setjmp.yaml
@@ -1,3 +1,4 @@
+c-reference-root: program
 functions:
   longjmp:
     c-definition: 7.13.2.1
diff --git a/libc/utils/docgen/signal.yaml b/libc/utils/docgen/signal.yaml
index 1023d6b60cf9a4..a8fe3bfc0fd724 100644
--- a/libc/utils/docgen/signal.yaml
+++ b/libc/utils/docgen/signal.yaml
@@ -1,3 +1,4 @@
+c-reference-root: program
 functions:
   kill:
     in-latest-posix: ''
@@ -26,6 +27,7 @@ functions:
 macros:
   SIGABRT:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGALRM:
     in-latest-posix: ''
@@ -37,14 +39,17 @@ macros:
     in-latest-posix: ''
   SIGFPE:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGHUP:
     in-latest-posix: ''
   SIGILL:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGINT:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGKILL:
     in-latest-posix: ''
@@ -62,6 +67,7 @@ macros:
     in-latest-posix: ''
   SIGSEGV:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGSTOP:
     in-latest-posix: ''
@@ -69,6 +75,7 @@ macros:
     in-latest-posix: ''
   SIGTERM:
     c-definition: 7.14.3
+    c-reference: program/SIG_types
     in-latest-posix: ''
   SIGTRAP:
     in-latest-posix: ''
@@ -92,13 +99,16 @@ macros:
     in-latest-posix: ''
   SIG_DFL:
     c-definition: 7.14.3
+    c-reference: program/SIG_strategies
     in-latest-posix: ''
   SIG_ERR:
     c-definition: 7.14.3
+    c-reference: program/SIG_strategies
     in-latest-posix: ''
   SIG_HOLD:
     in-latest-posix: ''
   SIG_IGN:
     c-definition: 7.14.3
+    c-reference: program/SIG_strategies
     in-latest-posix: ''
 
diff --git a/libc/utils/docgen/stdbit.yaml b/libc/utils/docgen/stdbit.yaml
index 976221601e9cb0..9989e30b2ef9b4 100644
--- a/libc/utils/docgen/stdbit.yaml
+++ b/libc/utils/docgen/stdbit.yaml
@@ -1,179 +1,267 @@
+c-reference-root: numeric/bit
 functions:
   stdc_bit_ceil_uc:
     c-definition: 7.18.16
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_ceil_ui:
     c-definition: 7.18.16
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_ceil_ul:
     c-definition: 7.18.16
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_ceil_ull:
     c-definition: 7.18.16
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_ceil_us:
     c-definition: 7.18.16
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_floor_uc:
     c-definition: 7.18.15
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_floor_ui:
     c-definition: 7.18.15
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_floor_ul:
     c-definition: 7.18.15
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_floor_ull:
     c-definition: 7.18.15
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_floor_us:
     c-definition: 7.18.15
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_width_uc:
     c-definition: 7.18.14
+    c-reference: numeric/bit/stdc_bit_width
   stdc_bit_width_ui:
     c-definition: 7.18.14
+    c-reference: numeric/bit/stdc_bit_width
   stdc_bit_width_ul:
     c-definition: 7.18.14
+    c-reference: numeric/bit/stdc_bit_width
   stdc_bit_width_ull:
     c-definition: 7.18.14
+    c-reference: numeric/bit/stdc_bit_width
   stdc_bit_width_us:
     c-definition: 7.18.14
+    c-reference: numeric/bit/stdc_bit_width
   stdc_count_ones_uc:
     c-definition: 7.18.12
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_ones_ui:
     c-definition: 7.18.12
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_ones_ul:
     c-definition: 7.18.12
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_ones_ull:
     c-definition: 7.18.12
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_ones_us:
     c-definition: 7.18.12
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_zeros_uc:
     c-definition: 7.18.11
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_count_zeros_ui:
     c-definition: 7.18.11
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_count_zeros_ul:
     c-definition: 7.18.11
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_count_zeros_ull:
     c-definition: 7.18.11
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_count_zeros_us:
     c-definition: 7.18.11
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_first_leading_one_uc:
     c-definition: 7.18.8
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_one_ui:
     c-definition: 7.18.8
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_one_ul:
     c-definition: 7.18.8
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_one_ull:
     c-definition: 7.18.8
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_one_us:
     c-definition: 7.18.8
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_zero_uc:
     c-definition: 7.18.7
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_leading_zero_ui:
     c-definition: 7.18.7
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_leading_zero_ul:
     c-definition: 7.18.7
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_leading_zero_ull:
     c-definition: 7.18.7
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_leading_zero_us:
     c-definition: 7.18.7
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_trailing_one_uc:
     c-definition: 7.18.10
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_one_ui:
     c-definition: 7.18.10
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_one_ul:
     c-definition: 7.18.10
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_one_ull:
     c-definition: 7.18.10
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_one_us:
     c-definition: 7.18.10
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_zero_uc:
     c-definition: 7.18.9
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_first_trailing_zero_ui:
     c-definition: 7.18.9
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_first_trailing_zero_ul:
     c-definition: 7.18.9
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_first_trailing_zero_ull:
     c-definition: 7.18.9
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_first_trailing_zero_us:
     c-definition: 7.18.9
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_has_single_bit_uc:
     c-definition: 7.18.13
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_has_single_bit_ui:
     c-definition: 7.18.13
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_has_single_bit_ul:
     c-definition: 7.18.13
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_has_single_bit_ull:
     c-definition: 7.18.13
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_has_single_bit_us:
     c-definition: 7.18.13
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_leading_ones_uc:
     c-definition: 7.18.4
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_ones_ui:
     c-definition: 7.18.4
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_ones_ul:
     c-definition: 7.18.4
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_ones_ull:
     c-definition: 7.18.4
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_ones_us:
     c-definition: 7.18.4
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_zeros_uc:
     c-definition: 7.18.3
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_leading_zeros_ui:
     c-definition: 7.18.3
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_leading_zeros_ul:
     c-definition: 7.18.3
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_leading_zeros_ull:
     c-definition: 7.18.3
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_leading_zeros_us:
     c-definition: 7.18.3
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_trailing_ones_uc:
     c-definition: 7.18.6
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_ones_ui:
     c-definition: 7.18.6
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_ones_ul:
     c-definition: 7.18.6
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_ones_ull:
     c-definition: 7.18.6
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_ones_us:
     c-definition: 7.18.6
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_zeros_uc:
     c-definition: 7.18.5
+    c-reference: numeric/bit/stdc_trailing_zeros
   stdc_trailing_zeros_ui:
     c-definition: 7.18.5
+    c-reference: numeric/bit/stdc_trailing_zeros
   stdc_trailing_zeros_ul:
     c-definition: 7.18.5
+    c-reference: numeric/bit/stdc_trailing_zeros
   stdc_trailing_zeros_ull:
     c-definition: 7.18.5
+    c-reference: numeric/bit/stdc_trailing_zeros
   stdc_trailing_zeros_us:
     c-definition: 7.18.5
+    c-reference: numeric/bit/stdc_trailing_zeros
 macros:
   __STDC_ENDIAN_BIG__:
     c-definition: 7.18.2.2
+    c-reference: numeric/bit/endian
   __STDC_ENDIAN_LITTLE__:
     c-definition: 7.18.2.2
+    c-reference: numeric/bit/endian
   __STDC_ENDIAN_NATIVE__:
     c-definition: 7.18.2.2
+    c-reference: numeric/bit/endian
   __STDC_VERSION_STDBIT_H__:
     c-definition: 7.18.1.2
   stdc_bit_ceil:
     c-definition: 7.18.16.1
+    c-reference: numeric/bit/stdc_bit_ceil
   stdc_bit_floor:
     c-definition: 7.18.15.1
+    c-reference: numeric/bit/stdc_bit_floor
   stdc_bit_width:
     c-definition: 7.18.14.1
+    c-reference: numeric/bit/stdc_bit_width
   stdc_count_ones:
     c-definition: 7.18.12.1
+    c-reference: numeric/bit/stdc_count_ones
   stdc_count_zeros:
     c-definition: 7.18.11.1
+    c-reference: numeric/bit/stdc_count_zeros
   stdc_first_leading_one:
     c-definition: 7.18.8.1
+    c-reference: numeric/bit/stdc_first_leading_one
   stdc_first_leading_zero:
     c-definition: 7.18.7.1
+    c-reference: numeric/bit/stdc_first_leading_zero
   stdc_first_trailing_one:
     c-definition: 7.18.10.1
+    c-reference: numeric/bit/stdc_first_trailing_one
   stdc_first_trailing_zero:
     c-definition: 7.18.9.1
+    c-reference: numeric/bit/stdc_first_trailing_zero
   stdc_has_single_bit:
     c-definition: 7.18.13.1
+    c-reference: numeric/bit/stdc_has_single_bit
   stdc_leading_ones:
     c-definition: 7.18.4.1
+    c-reference: numeric/bit/stdc_leading_ones
   stdc_leading_zeros:
     c-definition: 7.18.3.1
+    c-reference: numeric/bit/stdc_leading_zeros
   stdc_trailing_ones:
     c-definition: 7.18.6.1
+    c-reference: numeric/bit/stdc_trailing_ones
   stdc_trailing_zeros:
     c-definition: 7.18.5.1
+    c-reference: numeric/bit/stdc_trailing_zeros
 
diff --git a/libc/utils/docgen/stdio.yaml b/libc/utils/docgen/stdio.yaml
index 9dabee44a51c8e..46c0b3de5d5758 100644
--- a/libc/utils/docgen/stdio.yaml
+++ b/libc/utils/docgen/stdio.yaml
@@ -1,3 +1,4 @@
+c-reference-root: io
 macros:
   __STDC_VERSION_STDIO_H__:
     c-definition: '7.23.1'
@@ -31,24 +32,30 @@ macros:
     in-latest-posix: ''
   SEEK_CUR:
     c-definition: '7.23.1'
+    c-reference: io/fseek
     in-latest-posix: ''
   SEEK_END:
     c-definition: '7.23.1'
+    c-reference: io/fseek
     in-latest-posix: ''
   SEEK_SET:
     c-definition: '7.23.1'
+    c-reference: io/fseek
     in-latest-posix: ''
   TMP_MAX:
     c-definition: '7.23.1'
     in-latest-posix: ''
   stderr:
     c-definition: '7.23.1'
+    c-reference: io/std_streams
     in-latest-posix: ''
   stdin:
     c-definition: '7.23.1'
+    c-reference: io/std_streams
     in-latest-posix: ''
   stdout:
     c-definition: '7.23.1'
+    c-reference: io/std_streams
     in-latest-posix: ''
 functions:
   remove:
@@ -89,18 +96,23 @@ functions:
     in-latest-posix: ''
   printf:
     c-definition: '7.23.6.3'
+    c-reference: io/fprintf
     in-latest-posix: ''
   scanf:
     c-definition: '7.23.6.4'
+    c-reference: io/fscanf
     in-latest-posix: ''
   snprintf:
     c-definition: '7.23.6.5'
+    c-reference: io/fprintf
     in-latest-posix: ''
   sprintf:
     c-definition: '7.23.6.6'
+    c-reference: io/fprintf
     in-latest-posix: ''
   sscanf:
     c-definition: '7.23.6.7'
+    c-reference: io/fscanf
     in-latest-posix: ''
   vfprintf:
     c-definition: '7.23.6.8'
@@ -110,18 +122,23 @@ functions:
     in-latest-posix: ''
   vprintf:
     c-definition: '7.23.6.10'
+    c-reference: io/vfprintf
     in-latest-posix: ''
   vscanf:
     c-definition: '7.23.6.11'
+    c-reference: io/vfscanf
     in-latest-posix: ''
   vsnprintf:
     c-definition: '7.23.6.12'
+    c-reference: io/vfprintf
     in-latest-posix: ''
   vsprintf:
     c-definition: '7.23.6.13'
+    c-reference: io/vfprintf
     in-latest-posix: ''
   vsscanf:
     c-definition: '7.23.6.14'
+    c-reference: io/vfscanf
     in-latest-posix: ''
   fgetc:
     c-definition: '7.23.7.1'
@@ -137,12 +154,14 @@ functions:
     in-latest-posix: ''
   getc:
     c-definition: '7.23.7.5'
+    c-reference: io/fgetc
     in-latest-posix: ''
   getchar:
     c-definition: '7.23.7.6'
     in-latest-posix: ''
   putc:
     c-definition: '7.23.7.7'
+    c-reference: io/fputc
     in-latest-posix: ''
   putchar:
     c-definition: '7.23.7.8'
diff --git a/libc/utils/docgen/stdlib.yaml b/libc/utils/docgen/stdlib.yaml
index a2df11f6a20f65..e4807c021b84b2 100644
--- a/libc/utils/docgen/stdlib.yaml
+++ b/libc/utils/docgen/stdlib.yaml
@@ -1,3 +1,4 @@
+c-reference-root: program
 functions:
   _Exit:
     c-definition: 7.24.4.5
@@ -7,9 +8,11 @@ functions:
     in-latest-posix: ''
   abs:
     c-definition: 7.24.6.1
+    c-reference: numeric/math/abs
     in-latest-posix: ''
   aligned_alloc:
     c-definition: 7.24.3.1
+    c-reference: memory/aligned_alloc
     in-latest-posix: ''
   at_quick_exit:
     c-definition: 7.24.4.3
@@ -19,141 +22,186 @@ functions:
     in-latest-posix: ''
   atof:
     c-definition: 7.24.1.1
+    c-reference: string/byte/atof
     in-latest-posix: ''
   atoi:
     c-definition: 7.24.1.2
+    c-reference: string/byte/atoi
     in-latest-posix: ''
   atol:
     c-definition: 7.24.1.2
+    c-reference: string/byte/atoi
     in-latest-posix: ''
   atoll:
     c-definition: 7.24.1.2
+    c-reference: string/byte/atoi
     in-latest-posix: ''
   bsearch:
     c-definition: 7.24.5.1
+    c-reference: algorithm/bsearch
     in-latest-posix: ''
   calloc:
     c-definition: 7.24.3.2
+    c-reference: memory/calloc
     in-latest-posix: ''
   div:
     c-definition: 7.24.6.2
+    c-reference: numeric/math/div
     in-latest-posix: ''
   exit:
     c-definition: 7.24.4.4
     in-latest-posix: ''
   free:
     c-definition: 7.24.3.3
+    c-reference: memory/free
     in-latest-posix: ''
   free_aligned_sized:
     c-definition: 7.24.3.5
+    c-reference: memory/free_aligned_sized
   free_sized:
     c-definition: 7.24.3.4
+    c-reference: memory/free_sized
   getenv:
     c-definition: 7.24.4.6
     in-latest-posix: ''
   labs:
     c-definition: 7.24.6.1
+    c-reference: numeric/math/abs
     in-latest-posix: ''
   ldiv:
     c-definition: 7.24.6.2
+    c-reference: numeric/math/div
     in-latest-posix: ''
   llabs:
     c-definition: 7.24.6.1
+    c-reference: numeric/math/abs
     in-latest-posix: ''
   lldiv:
     c-definition: 7.24.6.2
+    c-reference: numeric/math/div
     in-latest-posix: ''
   malloc:
     c-definition: 7.24.3.6
+    c-reference: memory/malloc
     in-latest-posix: ''
   mblen:
     c-definition: 7.24.7.1
+    c-reference: string/multibyte/mblen
     in-latest-posix: ''
   mbstowcs:
     c-definition: 7.24.8.1
+    c-reference: string/multibyte/mbstowcs
     in-latest-posix: ''
   mbtowc:
     c-definition: 7.24.7.2
+    c-reference: string/multibyte/mbtowc
     in-latest-posix: ''
   memalignment:
     c-definition: 7.24.9.1
+    c-reference: memory/memalignment
   qsort:
     c-definition: 7.24.5.2
+    c-reference: algorithm/qsort
     in-latest-posix: ''
   quick_exit:
     c-definition: 7.24.4.7
     in-latest-posix: ''
   rand:
     c-definition: 7.24.2.1
+    c-reference: numeric/random/rand
     in-latest-posix: ''
   realloc:
     c-definition: 7.24.3.7
+    c-reference: memory/realloc
     in-latest-posix: ''
   reallocarray:
     in-latest-posix: ''
   srand:
     c-definition: 7.24.2.2
+    c-reference: numeric/random/srand
     in-latest-posix: ''
   strfromd:
     c-definition: 7.24.1.3
+    c-reference: string/byte/strfromf
   strfromd128:
     c-definition: 7.24.1.4
+    c-reference: string/byte/strfromf
   strfromd32:
     c-definition: 7.24.1.4
+    c-reference: string/byte/strfromf
   strfromd64:
     c-definition: 7.24.1.4
+    c-reference: string/byte/strfromf
   strfromf:
     c-definition: 7.24.1.3
+    c-reference: string/byte/strfromf
   strfroml:
     c-definition: 7.24.1.3
+    c-reference: string/byte/strfromf
   strtod:
     c-definition: 7.24.1.5
+    c-reference: string/byte/strtod
     in-latest-posix: ''
   strtod128:
     c-definition: 7.24.1.6
+    c-reference: string/byte/strtod
   strtod32:
     c-definition: 7.24.1.6
+    c-reference: string/byte/strtod
   strtod64:
     c-definition: 7.24.1.6
+    c-reference: string/byte/strtod
   strtof:
     c-definition: 7.24.1.5
+    c-reference: string/byte/strtod
     in-latest-posix: ''
   strtol:
     c-definition: 7.24.1.7
+    c-reference: string/byte/strtol
     in-latest-posix: ''
   strtold:
     c-definition: 7.24.1.5
+    c-reference: string/byte/strtod
     in-latest-posix: ''
   strtoll:
     c-definition: 7.24.1.7
+    c-reference: string/byte/strtol
     in-latest-posix: ''
   strtoul:
     c-definition: 7.24.1.7
+    c-reference: string/byte/strtoul
     in-latest-posix: ''
   strtoull:
     c-definition: 7.24.1.7
+    c-reference: string/byte/strtoul
     in-latest-posix: ''
   system:
     c-definition: 7.24.4.8
     in-latest-posix: ''
   wcstombs:
     c-definition: 7.24.8.2
+    c-reference: string/multibyte/wcstombs
     in-latest-posix: ''
   wctomb:
     c-definition: 7.24.7.3
+    c-reference: string/multibyte/wctomb
     in-latest-posix: ''
 macros:
   EXIT_FAILURE:
     c-definition: '7.24'
+    c-reference: program/EXIT_status
     in-latest-posix: ''
   EXIT_SUCCESS:
     c-definition: '7.24'
+    c-reference: program/EXIT_status
     in-latest-posix: ''
   MB_CUR_MAX:
     c-definition: '7.24'
+    c-reference: types/limits
     in-latest-posix: ''
   RAND_MAX:
     c-definition: '7.24'
+    c-reference: numeric/random/RAND_MAX
     in-latest-posix: ''
   __STDC_VERSION_STDLIB_H__:
     c-definition: '7.24'
diff --git a/libc/utils/docgen/string.yaml b/libc/utils/docgen/string.yaml
index 94a6756bed8c07..53816a1c010f08 100644
--- a/libc/utils/docgen/string.yaml
+++ b/libc/utils/docgen/string.yaml
@@ -1,3 +1,4 @@
+c-reference-root: string/byte
 functions:
   memccpy:
     c-definition: 7.26.2.2
@@ -68,6 +69,7 @@ functions:
     in-latest-posix: ''
   strnlen_s:
     c-definition: K.3.7.4.4
+    c-reference: string/byte/strlen
     in-latest-posix: ''
   strpbrk:
     c-definition: 7.26.5.5
diff --git a/libc/utils/docgen/threads.yaml b/libc/utils/docgen/threads.yaml
index 83db0992dc45da..3aa2b08305ef04 100644
--- a/libc/utils/docgen/threads.yaml
+++ b/libc/utils/docgen/threads.yaml
@@ -1,3 +1,4 @@
+c-reference-root: thread
 functions:
   call_once:
     c-definition: 7.28.2.1
@@ -77,9 +78,11 @@ functions:
 macros:
   ONCE_FLAG_INIT:
     c-definition: 7.28.1
+    c-reference: thread/call_once
     in-latest-posix: ''
   TSS_DTOR_ITERATIONS:
     c-definition: 7.28.1
+    c-reference: thread/TSS_DTOR_ITERATIONS
     in-latest-posix: ''
   __STDC_NO_THREADS__:
     c-definition: 7.28.1
diff --git a/libc/utils/docgen/time.yaml b/libc/utils/docgen/time.yaml
index af3cfed8d889b0..9635e42986893a 100644
--- a/libc/utils/docgen/time.yaml
+++ b/libc/utils/docgen/time.yaml
@@ -1,3 +1,4 @@
+c-reference-root: chrono
 functions:
   asctime:
     c-definition: 7.27.2.1
diff --git a/libc/utils/docgen/uchar.yaml b/libc/utils/docgen/uchar.yaml
index 580af0f5483363..746d9feff3373d 100644
--- a/libc/utils/docgen/uchar.yaml
+++ b/libc/utils/docgen/uchar.yaml
@@ -1,3 +1,4 @@
+c-reference-root: string/multibyte
 functions:
   c16rtomb:
     c-definition: 7.30.2.5
diff --git a/libc/utils/docgen/wchar.yaml b/libc/utils/docgen/wchar.yaml
index 85bfbe31085d15..1d0d91c1860143 100644
--- a/libc/utils/docgen/wchar.yaml
+++ b/libc/utils/docgen/wchar.yaml
@@ -1,56 +1,83 @@
+c-reference-root: string/wide
 functions:
   btowc:
     c-definition: 7.31.6.2.1
+    c-reference: string/multibyte/btowc
   fgetwc:
     c-definition: 7.31.3.1
+    c-reference: io/fgetwc
   fgetws:
     c-definition: 7.31.3.2
+    c-reference: io/fgetws
   fputwc:
     c-definition: 7.31.3.3
+    c-reference: io/fputwc
   fputws:
     c-definition: 7.31.3.4
+    c-reference: io/fputws
   fwide:
     c-definition: 7.31.3.5
+    c-reference: io/fwide
   fwprintf:
     c-definition: 7.31.2.2
+    c-reference: io/fwprintf
   fwscanf:
     c-definition: 7.31.2.3
+    c-reference: io/fwscanf
   getwc:
     c-definition: 7.31.3.6
+    c-reference: io/fgetwc
   getwchar:
     c-definition: 7.31.3.7
+    c-reference: io/getwchar
   mbrlen:
     c-definition: 7.31.6.4.2
+    c-reference: string/multibyte/mbrlen
   mbrtowc:
     c-definition: 7.31.6.4.3
+    c-reference: string/multibyte/mbrtowc
   mbsinit:
     c-definition: 7.31.6.3.1
+    c-reference: string/multibyte/mbsinit
   mbsrtowcs:
     c-definition: 7.31.6.5.2
+    c-reference: string/multibyte/mbsrtowcs
   putwc:
     c-definition: 7.31.3.8
+    c-reference: io/fputwc
   putwchar:
     c-definition: 7.31.3.9
+    c-reference: io/putwchar
   swprintf:
     c-definition: 7.31.2.4
+    c-reference: io/fwprintf
   swscanf:
     c-definition: 7.31.2.5
+    c-reference: io/fwscanf
   ungetwc:
     c-definition: 7.31.3.10
+    c-reference: io/ungetwc
   vfwprintf:
     c-definition: 7.31.2.6
+    c-reference: io/vfwprintf
   vfwscanf:
     c-definition: 7.31.2.7
+    c-reference: io/vfwscanf
   vswprintf:
     c-definition: 7.31.2.8
+    c-reference: io/vfwprintf
   vswscanf:
     c-definition: 7.31.2.9
+    c-reference: io/vfwscanf
   vwprintf:
     c-definition: 7.31.2.10
+    c-reference: io/vfwprintf
   vwscanf:
     c-definition: 7.31.2.11
+    c-reference: io/vfwscanf
   wcrtomb:
     c-definition: 7.31.6.4.4
+    c-reference: string/multibyte/wcrtomb
   wcscat:
     c-definition: 7.31.4.4.1
   wcschr:
@@ -69,6 +96,7 @@ functions:
     c-definition: 7.31.4.6.3
   wcsftime:
     c-definition: 7.31.5.1
+    c-reference: chrono/wcsftime
   wcslen:
     c-definition: 7.31.4.7.1
   wcsncat:
@@ -83,18 +111,23 @@ functions:
     c-definition: 7.31.4.6.5
   wcsrtombs:
     c-definition: 7.31.6.5.3
+    c-reference: string/multibyte/wcsrtombs
   wcsspn:
     c-definition: 7.31.4.6.6
   wcsstr:
     c-definition: 7.31.4.6.7
   wcstod:
     c-definition: 7.31.4.2.2
+    c-reference: string/wide/wcstof
   wcstod128:
     c-definition: 7.31.4.2.3
+    c-reference: string/wide/wcstof
   wcstod32:
     c-definition: 7.31.4.2.3
+    c-reference: string/wide/wcstof
   wcstod64:
     c-definition: 7.31.4.2.3
+    c-reference: string/wide/wcstof
   wcstof:
     c-definition: 7.31.4.2.2
   wcstok:
@@ -103,16 +136,20 @@ functions:
     c-definition: 7.31.4.2.4
   wcstold:
     c-definition: 7.31.4.2.2
+    c-reference: string/wide/wcstof
   wcstoll:
     c-definition: 7.31.4.2.4
+    c-reference: string/wide/wcstol
   wcstoul:
     c-definition: 7.31.4.2.4
   wcstoull:
     c-definition: 7.31.4.2.4
+    c-reference: string/wide/wcstoul
   wcsxfrm:
     c-definition: 7.31.4.5.5
   wctob:
     c-definition: 7.31.6.2.2
+    c-reference: string/multibyte/wctob
   wmemchr:
     c-definition: 7.31.4.6.9
   wmemcmp:
@@ -125,8 +162,10 @@ functions:
     c-definition: 7.31.4.7.2
   wprintf:
     c-definition: 7.31.2.12
+    c-reference: io/fwprintf
   wscanf:
     c-definition: 7.31.2.13
+    c-reference: io/fwscanf
 macros:
   WEOF:
     c-definition: 7.31.1
diff --git a/libc/utils/docgen/wctype.yaml b/libc/utils/docgen/wctype.yaml
index c57ecd7d283ab3..d7dd7c631c502d 100644
--- a/libc/utils/docgen/wctype.yaml
+++ b/libc/utils/docgen/wctype.yaml
@@ -1,3 +1,4 @@
+c-reference-root: string/wide
 functions:
   iswalnum:
     c-definition: 7.32.2.1.1



More information about the libc-commits mailing list