Skip to content

Commit 85c54a5

Browse files
authored
[Docs] Document freestanding requirements (#132232)
This adds some initial documentation about freestanding requirements for Clang. The most critical part of the documentation is spelling out that a conforming freestanding C Standard Library is required; Clang will not be providing the headers for <string.h> in C23 which expose a number of symbols in freestanding mode. The docs also make it clear that in addition to a conforming freestanding C standard library, the library must provide some additional symbols which LLVM requires. These docs are not comprehensive, this is just getting the bare bones in place so that they can be expanded later. This also updates the C status page to make it clear that we don't have anything to do for WG14 N2524 which adds string interfaces to freestanding mode.
1 parent 82c078c commit 85c54a5

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

clang/docs/CommandGuide/clang.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ Language Selection and Mode Options
262262
.. option:: -ffreestanding
263263

264264
Indicate that the file should be compiled for a freestanding, not a hosted,
265-
environment. Note that it is assumed that a freestanding environment will
266-
additionally provide `memcpy`, `memmove`, `memset` and `memcmp`
267-
implementations, as these are needed for efficient codegen for many programs.
265+
environment. Note that a freestanding build still requires linking against a C
266+
Standard Library which supports the freestanding interfaces for the specified
267+
language mode and target environment. This includes functions like `memcpy`,
268+
`memmove`, and `memset`.
268269

269270
.. option:: -fno-builtin
270271

clang/docs/UsersManual.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,35 @@ inputs. Here is some example of ``$``-prefixed options:
10731073
Language and Target-Independent Features
10741074
========================================
10751075

1076+
Freestanding Builds
1077+
-------------------
1078+
Passing the ``-ffreestanding`` flag causes Clang to build for a freestanding
1079+
(rather than a hosted) environment. The flag has the following effects:
1080+
1081+
* the ``__STDC_HOSTED__`` predefined macro will expand to ``0``,
1082+
* builtin functions are disabled by default (``-fno-builtins``),
1083+
* unwind tables are disabled by default
1084+
(``fno-asynchronous-unwind-tables -fno-unwind-tables``), and
1085+
* does not treat the global ``main`` function as a special function.
1086+
1087+
An implementation of the following runtime library functions must always be
1088+
provided with the usual semantics, as Clang will generate calls to them:
1089+
1090+
* ``memcpy``,
1091+
* ``memmove``, and
1092+
* ``memset``.
1093+
1094+
Clang does not, by itself, provide a full "conforming freestanding
1095+
implementation". If you wish to have a conforming freestanding implementation,
1096+
you must provide a freestanding C library. While Clang provides some of the
1097+
required header files, it does not provide all of them, nor any library
1098+
implementations.
1099+
1100+
Conversely, when ``-ffreestanding`` is specified, Clang does not require you to
1101+
provide a conforming freestanding implementation library. Clang will not make
1102+
any assumptions as to the availability or semantics of standard-library
1103+
functions other than those mentioned above.
1104+
10761105
Controlling Errors and Warnings
10771106
-------------------------------
10781107

clang/www/c_status.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,6 @@ <h2 id="c2x">C23 implementation status</h2>
534534
<td class="full" align="center">Clang 16</td>
535535
</tr>
536536
<!-- Apr 2021 Papers -->
537-
<tr>
538-
<td>String functions for freestanding implementations</td>
539-
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2524.htm">N2524</a></td>
540-
<td class="none" align="center">No</td>
541-
</tr>
542537
<tr>
543538
<td>Digit separators</td>
544539
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2626.pdf">N2626</a></td>

0 commit comments

Comments
 (0)