diff options
author | Nick Desaulniers <nickdesaulniers@users.noreply.github.com> | 2024-04-11 10:11:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-11 10:11:58 -0700 |
commit | f626a35086d90f25986e3f06e01a54cca91250d8 (patch) | |
tree | 33c399a67324e2bbf39ffe228e3f36685d768881 /libc/docs | |
parent | 5122a2c2320c7b14f6585e63b7fc43ac82a550c2 (diff) | |
download | llvm-f626a35086d90f25986e3f06e01a54cca91250d8.zip llvm-f626a35086d90f25986e3f06e01a54cca91250d8.tar.gz llvm-f626a35086d90f25986e3f06e01a54cca91250d8.tar.bz2 |
[libc] Codify header inclusion policy (#87017)
When supporting "overlay" vs "fullbuild" modes, "what ABI are you
using?" becomes a fundamental question to have concrete answers for.
Overlay mode MUST match the ABI of the system being overlayed onto;
fullbuild more flexible (the only system ABI relevant is the OS kernel).
When implementing llvm-libc we generally prefer the include-what-you use
style of avoiding transitive dependencies (since that makes refactoring
headers more painful, and slows down build times). So what header do you
include for any given type or function declaration? For any given
userspace program, the answer is straightforward. But for llvm-libc
which is trying to support multiple ABIs (at least one per
configuration), the answer is perhaps less clear.
This proposal seeks to add one layer of indirection relative to what's
being done today.
It then converts users of sigset_t and struct epoll_event and the epoll
implemenations over to this convention as an example.
Diffstat (limited to 'libc/docs')
-rw-r--r-- | libc/docs/dev/code_style.rst | 33 | ||||
-rw-r--r-- | libc/docs/usage_modes.rst | 6 |
2 files changed, 38 insertions, 1 deletions
diff --git a/libc/docs/dev/code_style.rst b/libc/docs/dev/code_style.rst index 22a18b7..ee4e425 100644 --- a/libc/docs/dev/code_style.rst +++ b/libc/docs/dev/code_style.rst @@ -186,3 +186,36 @@ We expect contributions to be free of warnings from the `minimum supported compiler versions`__ (and newer). .. __: https://libc.llvm.org/compiler_support.html#minimum-supported-versions + +Header Inclusion Policy +======================= + +Because llvm-libc supports +`Overlay Mode <https://libc.llvm.org/overlay_mode.html>`__ and +`Fullbuild Mode <https://libc.llvm.org/fullbuild_mode.html>`__ care must be +taken when ``#include``'ing certain headers. + +The ``include/`` directory contains public facing headers that users must +consume for fullbuild mode. As such, types defined here will have ABI +implications as these definitions may differ from the underlying system for +overlay mode and are NEVER appropriate to include in ``libc/src/`` without +preprocessor guards for ``LLVM_LIBC_FULL_BUILD``. + +Consider the case where an implementation in ``libc/src/`` may wish to refer to +a ``sigset_t``, what header should be included? ``<signal.h>``, ``<spawn.h>``, +``<sys/select.h>``? + +None of the above. Instead, code under ``src/`` should ``#include +"hdr/types/sigset_t.h"`` which contains preprocessor guards on +``LLVM_LIBC_FULL_BUILD`` to either include the public type (fullbuild mode) or +the underlying system header (overlay mode). + +Implementations in ``libc/src/`` should NOT be ``#include``'ing using ``<>`` or +``"include/*``, except for these "proxy" headers that first check for +``LLVM_LIBC_FULL_BUILD``. + +These "proxy" headers are similarly used when referring to preprocessor +defines. Code under ``libc/src/`` should ``#include`` a proxy header from +``hdr/``, which contains a guard on ``LLVM_LIBC_FULL_BUILD`` to either include +our header from ``libc/include/`` (fullbuild) or the corresponding underlying +system header (overlay). diff --git a/libc/docs/usage_modes.rst b/libc/docs/usage_modes.rst index 11c1062..8e5dcca 100644 --- a/libc/docs/usage_modes.rst +++ b/libc/docs/usage_modes.rst @@ -6,6 +6,10 @@ The libc can used in two different modes: #. The **overlay** mode: In this mode, the link order semantics are exploited to overlay implementations from LLVM's libc over the system libc. See - :ref:`overlay_mode` for more information about this mode. + :ref:`overlay_mode` for more information about this mode. In this mode, libc + uses the ABI of the system it's being overlayed onto. Headers are NOT + generated. libllvmlibc.a is the only build artifact. #. The **fullbuild** mode: In this mode, LLVM's libc is used as the only libc for the binary. See :ref:`fullbuild_mode` for information about this mode. + In this mode, libc uses its own ABI. Headers are generated along with a + libc.a. |