Skip to content

Commit 43f783f

Browse files
[libc][docs] Update implementation docs (#73590)
Some of the files in the docs/ directory are from 2019 and haven't been updated since. This patch updates implementation_standard.rst, source_tree_layout.rst, and has some minor fixes for strings.rst. It also marks the most severely out of date files with a warning. These files will be updated in a later patch.
1 parent 6c62f7c commit 43f783f

File tree

6 files changed

+105
-73
lines changed

6 files changed

+105
-73
lines changed

libc/docs/dev/api_test.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
========
44
API Test
55
========
6+
7+
.. warning::
8+
This page is severely out of date. Much of the information it contains may be
9+
incorrect. Please only remove this warning once the page has been updated.
10+
611
The implementation of libc-project is unique because our public C header files
712
are generated using information from ground truth captured in TableGen files.
813
Unit tests only exercise the internal C++ implementations and don't ensure the

libc/docs/dev/clang_tidy_checks.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
LLVM libc clang-tidy checks
44
===========================
5+
6+
7+
.. warning::
8+
This page is severely out of date. Much of the information it contains may be
9+
incorrect. Please only remove this warning once the page has been updated.
10+
511
These are the clang-tidy checks designed to help enforce implementation
612
standards.
713
The configuration file is ``src/.clang-tidy``.

libc/docs/dev/header_generation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Generating Public and Internal headers
22
======================================
33

4+
.. warning::
5+
This page is severely out of date. Much of the information it contains may be
6+
incorrect. Please only remove this warning once the page has been updated.
7+
48
Other libc implementations make use of preprocessor macro tricks to make header
59
files platform agnostic. When macros aren't suitable, they rely on build
610
system tricks to pick the right set of files to compile and export. While these

libc/docs/dev/implementation_standard.rst

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,81 +5,69 @@ LLVM-libc entrypoints are defined in the entrypoints document. In this document,
55
we explain how the entrypoints are implemented. The source layout document
66
explains that, within the high level ``src`` directory, there exists one
77
directory for every public header file provided by LLVM-libc. The
8-
implementations of related group of entrypoints will also live in a directory of
9-
their own. This directory will have a name indicative of the related group of
10-
entrypoints, and will be under the directory corresponding to the header file of
11-
the entrypoints. For example, functions like ``fopen`` and ``fclose`` cannot be
12-
tested independent of each other and hence will live in a directory named
13-
``src/stdio/file_operations``. On the other hand, the implementation of the
14-
``round`` function from ``math.h`` can be tested by itself, so it will live in
15-
the directory of its own named ``src/math/round/``.
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``).
1611

1712
Implementation of entrypoints can span multiple ``.cpp`` and ``.h`` files, but
1813
there will be at least one header file with name of the form
19-
``<entrypoint name>.h`` for every entrypoint. This header file is called as the
20-
implementation header file. For the ``round`` function, the path to the
21-
implementation header file will be ``src/math/round/round.h``. The rest of this
22-
document explains the structure of implementation header files and ``.cpp``
23-
files.
14+
``<entrypoint name>.h`` for every entrypoint. This header file is called the
15+
implementation header file. For the ``isalpha`` function, the path to the
16+
implementation header file is ``src/ctype/isalpha.h``.
2417

2518
Implementation Header File Structure
2619
------------------------------------
2720

28-
We will use the ``round`` function from the public ``math.h`` header file as an
29-
example. The ``round`` function will be declared in an internal header file
30-
``src/math/round/round.h`` as follows::
21+
We will use the ``isalpha`` function from the public ``ctype.h`` header file as an
22+
example. The ``isalpha`` function will be declared in an internal header file
23+
``src/ctype/isalpha.h`` as follows::
3124

32-
// --- round.h --- //
33-
#ifndef LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
34-
#define LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
25+
// --- isalpha.h --- //
26+
#ifndef LLVM_LIBC_SRC_CTYPE_ISALPHA_H
27+
#define LLVM_LIBC_SRC_CTYPE_ISALPHA_H
3528

3629
namespace LIBC_NAMESPACE {
3730

38-
double round(double);
31+
int isalpha(int c);
3932

4033
} // namespace LIBC_NAMESPACE
4134

42-
#endif LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
35+
#endif LLVM_LIBC_SRC_CTYPE_ISALPHA_H
4336

44-
Notice that the ``round`` function declaration is nested inside the namespace
45-
``LIBC_NAMESPACE``. All implementation constructs in LLVM-libc are declared within
46-
the namespace ``LIBC_NAMESPACE``.
37+
Notice that the ``isalpha`` function declaration is nested inside the namespace
38+
``LIBC_NAMESPACE``. All implementation constructs in LLVM-libc are declared
39+
within the namespace ``LIBC_NAMESPACE``.
4740

4841
``.cpp`` File Structure
4942
-----------------------
5043

51-
The implementation can span multiple ``.cpp`` files. However, the signature of
52-
the entrypoint function should make use of a special macro. For example, the
53-
``round`` function from ``math.h`` should be defined as follows, say in the file
54-
``src/math/math/round.cpp``::
44+
The main ``.cpp`` file is named ``<entrypoint name>.cpp`` and is usually in the
45+
same folder as the header. It contains the signature of the entrypoint function,
46+
which must be defined with the ``LLVM_LIBC_FUNCTION`` macro. For example, the
47+
``isalpha`` function from ``ctype.h`` is defined as follows, in the file
48+
``src/ctype/isalpha.cpp``::
5549

56-
// --- round.cpp --- //
50+
// --- isalpha.cpp --- //
5751

5852
namespace LIBC_NAMESPACE {
5953

60-
double LLVM_LIBC_ENTRYPOINT(round)(double d) {
54+
LLVM_LIBC_FUNCTION(int, isalpha, (int c)) {
6155
// ... implementation goes here.
6256
}
6357

6458
} // namespace LIBC_NAMESPACE
6559

66-
Notice the use of the macro ``LLVM_LIBC_ENTRYPOINT``. This macro helps us define
67-
an C alias symbol for the C++ implementation. The C alias need not be added by
68-
the macro by itself. For example, for ELF targets, the macro is defined as
69-
follows::
60+
Notice the use of the macro ``LLVM_LIBC_FUNCTION``. This macro helps us define
61+
a C alias symbol for the C++ implementation. For example, for a library build,
62+
the macro is defined as follows::
7063

71-
#define ENTRYPOINT_SECTION_ATTRIBUTE(name) \
72-
__attribute__((section(".llvm.libc.entrypoint."#name)))
73-
#define LLVM_LIBC_ENTRYPOINT(name) ENTRYPOINT_SECTION_ATTRIBUTE(name) name
64+
#define LLVM_LIBC_FUNCTION(type, name, arglist)
65+
LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
66+
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
67+
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name)
68+
__##name##_impl__ __asm__(#name);
69+
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]];
70+
type __##name##_impl__ arglist
7471

75-
The macro places the C++ function in a unique section with name
76-
``.llvm.libc.entrypoint.<function name>``. This allows us to add a C alias using
77-
a post build step. For example, for the ``round`` function, one can use
78-
``objcopy`` to add an alias symbol as follows::
79-
80-
objcopy --add-symbol round=.llvm.libc.entrypoint.round:0,function round.o
81-
82-
NOTE: We use a post build ``objcopy`` step to add an alias instead of using
83-
the ``__attribute__((alias))``. For C++, this ``alias`` attribute requires
84-
mangled names of the referees. Using the post build ``objcopy`` step helps
85-
us avoid putting mangled names with ``alias`` attributes.
72+
The LLVM_LIBC_FUNCTION_ATTR macro is normally defined to nothing, but can be
73+
defined by vendors who want to set their own attributes.

libc/docs/dev/source_tree_layout.rst

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,39 @@ At the top-level, LLVM-libc source tree is organized in to the following
88
directories::
99

1010
+ libc
11+
- benchmarks
1112
- cmake
13+
- config
1214
- docs
15+
- examples
1316
- fuzzing
1417
- include
1518
- lib
16-
- startup
19+
- spec
1720
- src
21+
- startup
1822
- test
1923
- utils
2024

21-
Each of these directories is explained in detail below.
25+
Each of these directories is explained breifly below.
26+
27+
The ``benchmarks`` directory
28+
----------------------------
29+
30+
The ``benchmarks`` directory contains LLVM-libc's benchmarking utilities. These
31+
are mostly used for the memory functions. This also includes the automemcpy
32+
subdirectory for automatic generation of optimized memory functions.
33+
34+
The ``config`` directory
35+
------------------------
36+
37+
The ``config`` directory contains the default configurations for the targets
38+
LLVM-libc supports. These are files in the ``config/<platform>/<architecture>/``
39+
subdirectory called ``entrypoints.txt``, ``exclude.txt``, ``headers.txt``, and
40+
``config.json``. These tell cmake which entrypoints are available, which
41+
entrypoints to exclude, which headers to generate, and what options to set for
42+
the current target respectively. There are also other platform specific files in
43+
the ``config/<platform>/`` subdirectory.
2244

2345
The ``cmake`` directory
2446
-----------------------
@@ -35,34 +57,36 @@ this document on source layout.
3557
The ``fuzzing`` directory
3658
-------------------------
3759

38-
This directory contains fuzzing tests for the various components of llvm-libc. The
39-
directory structure within this directory mirrors the directory structure of the
40-
top-level ``libc`` directory itself. For more details, see :doc:`fuzzing`.
60+
This directory contains fuzzing tests for the various components of LLVM-libc.
61+
The directory structure within this directory mirrors the directory structure
62+
of the top-level ``libc`` directory itself. For more details, see
63+
:doc:`fuzzing`.
4164

4265
The ``include`` directory
4366
-------------------------
4467

4568
The ``include`` directory contains:
4669

47-
1. Self contained public header files - These are header files which are
48-
already in the form that get installed when LLVM-libc is installed on a user's
49-
computer.
50-
2. ``*.h.def`` and ``*.h.in`` files - These files are used to construct the
51-
generated public header files.
52-
3. A ``CMakeLists.txt`` file - This file lists the targets for the self
53-
contained and generated public header files.
70+
1. ``*.h.def`` files - These files are used to construct the generated public
71+
header files.
72+
2. Self contained public header files - These are header files which are
73+
already in the form that get installed when LLVM-libc is installed on a
74+
user's computer. These are mostly in the ``llvm-libc-macros`` and
75+
``llvm-libc-types`` subdirectories.
5476

5577
The ``lib`` directory
5678
---------------------
5779

5880
This directory contains a ``CMakeLists.txt`` file listing the targets for the
5981
public libraries ``libc.a``, ``libm.a`` etc.
6082

61-
The ``startup`` directory
62-
-------------------------
83+
The ``spec`` directory
84+
----------------------
6385

64-
This directory contains the implementations of the application startup objects
65-
like ``crt1.o`` etc.
86+
This directory contains the specifications for the types, macros, and entrypoint
87+
functions. These definitions come from the various standards and extensions
88+
LLVM-libc supports, and they are used along with the ``*.h.def`` files and the
89+
config files to generate the headers for fullbuild mode.
6690

6791
The ``src`` directory
6892
---------------------
@@ -78,10 +102,16 @@ further organized as follows:
78102
implementation standard document explains more about the *header*
79103
directories.
80104

105+
The ``startup`` directory
106+
-------------------------
107+
108+
This directory contains the implementations of the application startup objects
109+
like ``crt1.o`` etc.
110+
81111
The ``test`` directory
82112
----------------------
83113

84-
This directory contains tests for the various components of llvm-libc. The
114+
This directory contains tests for the various components of LLVM-libc. The
85115
directory structure within this directory mirrors the directory structure of the
86116
toplevel ``libc`` directory itself. A test for, say the ``mmap`` function, lives
87117
in the directory ``test/src/sys/mman/`` as implementation of ``mmap`` lives in
@@ -90,6 +120,6 @@ in the directory ``test/src/sys/mman/`` as implementation of ``mmap`` lives in
90120
The ``utils`` directory
91121
-----------------------
92122

93-
This directory contains utilities used by other parts of the llvm-libc system.
94-
See the `README` files, in the sub-directories within this directory, to learn
123+
This directory contains utilities used by other parts of the LLVM-libc system.
124+
See the `README` files in the subdirectories within this directory to learn
95125
about the various utilities.

libc/docs/strings.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,21 @@ String Error Functions
135135
============= =========
136136
Function Name Available
137137
============= =========
138-
strerror
139-
strerror_s
140-
strerrorlen_s
138+
strerror |check|
139+
strerror_r |check|
141140
============= =========
142141

143142
Localized String Functions
144143
==========================
145144

146-
These functions require locale.h, and will be added when locale support is
145+
These functions require locale.h, and will be finished when locale support is
147146
implemented in LLVM-libc.
148147

149148
============= =========
150149
Function Name Available
151150
============= =========
152-
strcoll
153-
strxfrm
151+
strcoll Partially
152+
strxfrm Partially
154153
============= =========
155154

156155
---------------------------

0 commit comments

Comments
 (0)