Skip to content

Commit f0b58c1

Browse files
authored
[libc][docs][NFC] Expand entrypoints technical reference (#4) (llvm#188255)
Expanded entrypoints.rst with details about definitions, registration rules, and the lifecycle of an entrypoint. Updated multiple documents to remove redundant technical details and link to the centralized entrypoints reference: - libc/docs/dev/cmake_build_rules.rst - libc/docs/dev/implementation_standard.rst - libc/docs/porting.rst - libc/docs/dev/source_tree_layout.rst
1 parent a5a7f62 commit f0b58c1

7 files changed

Lines changed: 148 additions & 45 deletions

File tree

libc/docs/dev/cmake_build_rules.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@ task.
1212
Targets for entrypoints
1313
-----------------------
1414

15-
Every entrypoint in LLVM-libc has its own build target. This target is listed
16-
using the ``add_entrypoint_object`` rule. This rule generates a single object
17-
file containing the implementation of the entrypoint.
15+
Every entrypoint in LLVM-libc has its own build target, listed using the
16+
``add_entrypoint_object`` rule. This rule generates a single object file
17+
containing the implementation.
1818

19-
Targets for redirecting entrypoints are also listed using the
20-
``add_entrypoint_object`` rule. However, one will have to additionally specify
21-
the ``REDIRECTED`` option with the rule.
19+
For more technical details on how to register entrypoints, see the
20+
:ref:`entrypoints` documentation.
2221

2322
Targets for entrypoint libraries
2423
--------------------------------
2524

2625
Standards like POSIX require that a libc provide certain library files like
2726
``libc.a``, ``libm.a``, etc. The targets for such library files are listed in
28-
the ``lib`` directory as ``add_entrypoint_library`` targets. An
29-
``add_entrypoint_library`` target takes a list of ``add_entrypoint_object``
30-
targets and produces a static library containing the object files corresponding
31-
to the ``add_entrypoint_targets``.
27+
the ``lib`` directory as ``add_entrypoint_library`` targets.
28+

libc/docs/dev/entrypoints.rst

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,116 @@
11
.. _entrypoints:
22

3+
========================
34
Entrypoints in LLVM libc
4-
------------------------
5+
========================
56

67
A public function or a global variable provided by LLVM-libc is called an
7-
entrypoint. The notion of entrypoints is ingrained in LLVM-libc's
8-
source layout, build system and source code.
8+
*entrypoint*. The notion of entrypoints is central to LLVM-libc's source layout,
9+
build system, and configuration management. This document provides a technical
10+
reference for how entrypoints are defined, implemented, and integrated into
11+
the final library.
12+
13+
What is an Entrypoint?
14+
----------------------
15+
16+
In a typical C library, all functions are part of a monolithic archive. In
17+
LLVM-libc, each function (e.g., ``malloc``, ``printf``, ``isalpha``) is treated
18+
as a discrete "entrypoint" unit. This allows for:
19+
20+
- **Granular build targets**: You can build just the objects you need.
21+
- **Configuration-driven selection**: Different operating systems and
22+
architectures can pick specific implementations for the same function.
23+
- **Support for multiple build modes**: Selectively replacing parts of a host's
24+
libc in :ref:`overlay_mode` or building a complete library in :ref:`full_host_build`.
25+
26+
The Lifecycle of an Entrypoint
27+
------------------------------
28+
29+
1. **Implementation**: The function is implemented in a ``.cpp`` file using
30+
LLVM-libc's coding and implementation standards.
31+
2. **Registration**: The entrypoint is defined as a CMake target using the
32+
``add_entrypoint_object`` rule.
33+
3. **Configuration**: The target name is added to an ``entrypoints.txt`` file
34+
to include it in a specific OS/Architecture configuration.
35+
36+
Implementation Standards
37+
------------------------
38+
39+
Implementations live in the ``src/`` directory, organized by the public header
40+
they belong to (e.g., ``src/ctype/isalpha.cpp`` for ``ctype.h``).
41+
42+
Header File Structure
43+
^^^^^^^^^^^^^^^^^^^^^
44+
45+
Every entrypoint has an internal implementation header file (e.g.,
46+
``src/ctype/isalpha.h``). This header declares the function within the
47+
``LIBC_NAMESPACE_DECL`` namespace::
48+
49+
namespace LIBC_NAMESPACE_DECL {
50+
int isalpha(int c);
51+
} // namespace LIBC_NAMESPACE_DECL
52+
53+
Source File Structure
54+
^^^^^^^^^^^^^^^^^^^^^
55+
56+
The implementation file (e.g., ``src/ctype/isalpha.cpp``) defines the function
57+
using the ``LLVM_LIBC_FUNCTION`` macro. This macro handles C-linkage and
58+
aliasing::
59+
60+
namespace LIBC_NAMESPACE_DECL {
61+
LLVM_LIBC_FUNCTION(int, isalpha, (int c)) {
62+
// ... implementation ...
63+
}
64+
} // namespace LIBC_NAMESPACE_DECL
65+
66+
For more details on implementation conventions, see the
67+
:ref:`implementation_standard` page.
68+
69+
Registration: CMake Rules
70+
-------------------------
71+
72+
Entrypoints are registered as CMake targets to make them available to the
73+
build system. These rules are usually defined in the ``CMakeLists.txt`` file
74+
within the function's source directory.
75+
76+
``add_entrypoint_object``
77+
^^^^^^^^^^^^^^^^^^^^^^^^^
78+
79+
This rule generates a single object file containing the implementation of the
80+
entrypoint.
81+
82+
.. code-block:: cmake
83+
84+
add_entrypoint_object(
85+
isalpha
86+
SRCS isalpha.cpp
87+
HDRS isalpha.h
88+
DEPENDS
89+
.some_internal_dependency
90+
)
91+
92+
For redirecting entrypoints (e.g., when one function is a simple alias for
93+
another), the ``REDIRECTED`` option can be specified to the rule.
94+
95+
``add_entrypoint_library``
96+
^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
98+
Standard library files like ``libc.a`` and ``libm.a`` are produced by
99+
aggregating multiple entrypoint objects. The ``add_entrypoint_library`` target
100+
takes a list of ``add_entrypoint_object`` targets and produces a static library.
101+
102+
Configuration: ``entrypoints.txt``
103+
----------------------------------
104+
105+
The final selection of which entrypoints are included in a specific build is
106+
determined by ``entrypoints.txt`` files located in the ``libc/config`` tree.
107+
108+
- **Location**: Typically found in ``libc/config/<os>/entrypoints.txt`` or
109+
``libc/config/<os>/<arch>/entrypoints.txt``.
110+
- **Role**: This file acts as the "source of truth" for what is supported on a
111+
given platform. A typical bring-up procedure involves progressively adding
112+
targets to this file as they are implemented and tested.
113+
114+
If you are implementing a new entrypoint, you must add its target name to the
115+
relevant ``entrypoints.txt`` files for it to be included in the library build.
116+
For more details on platform configuration, see the :ref:`porting` guide.

libc/docs/dev/fuzzing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _fuzzing:
2+
13
Fuzzing for LLVM-libc functions
24
===============================
35

libc/docs/dev/implementation_standard.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
.. _implementation_standard:
2+
13
Convention for implementing entrypoints
24
=======================================
35

4-
LLVM-libc entrypoints are defined in the entrypoints document. In this document,
5-
we explain how the entrypoints are implemented. The source layout document
6-
explains that, within the high level ``src`` directory, there exists one
7-
directory for every public header file provided by LLVM-libc. The
8-
implementations of entrypoints live in the directory for the header they belong
9-
to. Some entrypoints are platform specific, and so their implementations are in
10-
a subdirectory with the name of the platform (e.g. ``stdio/linux/remove.cpp``).
6+
The implementations of LLVM-libc entrypoints live in the ``src/`` directory,
7+
organized by the public header they belong to. Some entrypoints are platform-
8+
specific, and so their implementations are in a subdirectory with the name of
9+
the platform (e.g., ``stdio/linux/remove.cpp``).
10+
11+
For a complete overview of what an entrypoint is and how it is managed in the
12+
build system, see the :ref:`entrypoints` documentation.
13+
1114

1215
Implementation of entrypoints can span multiple ``.cpp`` and ``.h`` files, but
1316
there will be at least one header file with name of the form

libc/docs/dev/source_tree_layout.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public libraries ``libc.a``, ``libm.a`` etc.
9090
The ``src`` directory
9191
---------------------
9292

93-
This directory contains the implementations of the llvm-libc entrypoints. It is
94-
further organized as follows:
93+
This directory contains the implementations of the llvm-libc entrypoints. For
94+
more details on what an entrypoint is and how it is implemented, see the
95+
:ref:`entrypoints` documentation. It is further organized as follows:
9596

9697
1. There is a top-level CMakeLists.txt file.
9798
2. For every public header file provided by llvm-libc, there exists a

libc/docs/dev/undefined_behavior.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _undefined_behavior:
2+
13
===========================
24
Defining Undefined Behavior
35
===========================

libc/docs/porting.rst

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,19 @@ architecture.
4949
The entrypoints.txt file
5050
------------------------
5151

52-
One of the important pieces of config information is listed in a file named
53-
``entrypoints.txt``. This file lists the targets for the entrypoints (see
54-
:ref:`entrypoints`) you want to include in the static archive of the libc (for
55-
the :ref:`overlay_mode` and/or the :ref:`full_host_build`.) If you are doing an
56-
architecture specific bring up, then an ``entrypoints.txt`` file should be
57-
created in the architecture subdirectory for each architecture. Else, having a
58-
single ``entrypoints.txt`` in the operating system directory is sufficient.
59-
60-
The Linux config has an ``entrypoint.txt`` for each individual target
61-
architecture separately: `aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/aarch64>`_,
62-
`arm32 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/arm>`_ and
63-
`x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/linux/x86_64>`_. On the
64-
other hand, the Windows config has a single ``entrypoints.txt``
65-
`file <https://github.com/llvm/llvm-project/tree/main/libc/config/windows/entrypoints.txt>`_.
66-
67-
A typical bring up procedure will normally bring up a small group of entrypoints
68-
at a time. The usual practice is to progressively add the targets for those
69-
entrypoints to the ``entrypoints.txt`` file as they are being brought up. The
70-
same is the case if one is implementing a new entrypoint - the target for the
71-
new entrypoint should be added to the relevant ``entrypoints.txt`` file. If
72-
the implementation of the new entrypoint supports multiple operating systems and
73-
target architectures, then multiple ``entrypoints.txt`` files will have to be
74-
updated.
52+
The ``entrypoints.txt`` file lists the targets for the entrypoints to be
53+
included in the build for a specific platform. For more technical details on
54+
what entrypoints are and how they are registered as targets, see the
55+
:ref:`entrypoints` documentation.
56+
57+
If you are doing an architecture specific bring-up, then an ``entrypoints.txt``
58+
file should be created in the architecture subdirectory for each architecture.
59+
Else, having a single ``entrypoints.txt`` in the operating system directory is
60+
sufficient.
61+
62+
A typical bring-up procedure will normally involve progressively adding targets
63+
to this file as they are implemented and tested.
64+
7565

7666
The headers.txt file
7767
--------------------

0 commit comments

Comments
 (0)