[libc-commits] [libc] [libc] Major docs refresh (PR #241609)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Sat Nov 14 09:00:18 PST 2026


================
@@ -0,0 +1,200 @@
+(code_organization)=
+
+# Where Code Goes
+
+This page explains how to decide where a piece of code belongs: in an
+entrypoint, in a helper next to it, in `src/__support/`, or in `shared/`. It
+also covers which build modes and targets a new function is enabled for.
+{ref}`source_tree_layout` describes the directories themselves.
+
+## Three kinds of code
+
+It helps to sort code in a libc into three kinds:
+
+- **OS independent**: pure computation with no system interaction, such as
+  the math and string functions.
+- **OS agnostic**: standard interfaces whose behavior is the same everywhere
+  but whose implementation needs the system, such as `fopen` or `assert`.
+- **OS specific**: interfaces that are specific to a platform. This can be a
+  thin interface like a syscall wrapper or a substantial integration like
+  `popen`.
+
+The source tree does not separate these three as cleanly as it should, and
+moving toward that separation is a long-term goal. When adding code, decide
+which kind it is and keep OS-specific details out of the first two.
+
+## Entrypoints do not call entrypoints
+
+An entrypoint is the definition of one public function. It may contain its
+whole implementation. As soon as any part of that implementation is needed
+somewhere else, that part moves into a separate internal header or library.
+
+**An entrypoint must not call another entrypoint.** This is the most common
+mistake in new code. Calling `strlen` from `strdup`, or `fseek` from
+`fsetpos`, is the natural way to write the function. It is wrong here because
+every entrypoint is a separate public symbol in its own separate object file
+that each target enables or leaves out individually. A dependency between two
+entrypoints means that they must be pulled in together.
+
+Instead, put the shared logic in an internal function and call it from both
+entrypoints:
+
+```c++
----------------
bassiounix wrote:

I remember in the old days that markdown only accepted `cpp` and not `c++` nor `cc`
I'm not sure if this is still the case or not
The only way to verify is to look at the generated docs for this section specifically.

https://github.com/llvm/llvm-project/pull/241609


More information about the libc-commits mailing list