21 Commits

Author SHA1 Message Date
Muhammad Bassiouni
45b15946b1
[libc][hdrgen] Fix hdrgen when using macros as guards in stdlib.yaml. (#152732) 2025-08-08 18:39:47 +03:00
Roland McGrath
123c0040d4
[libc] Define (stub) dl_iterate_phdr (#131436)
This fleshes out the <link.h> a little more, including the
`struct dl_phdr_info` type and declaring the dl_iterate_phdr
function.  There is only a no-op implementation without tests, as
for the existing dlfcn functions.
2025-03-18 11:38:33 -07:00
Tristan Ross
bb694998d2
[libc] init uefi (#131246)
Initial UEFI OS target support after the headers. This just defines
enough that stuff might try and compile. Test with:
```
$ cmake -S llvm -B build -G Ninja -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true -DCMAKE_C_COMPILER_WORKS=true -DCMAKE_CXX_COMPILER_WORKS=true -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBCXX=true -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm -DCMAKE_INSTALL_LIBDIR=build/target/lib
$ ninja -C build
```
2025-03-14 20:15:24 -07:00
Alexey Samsonov
829e2a5526
[libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)
Move the hdrgen code under a subdirectory to treat it as a Python
module.

This mimics the structure used by llvm/utils/lit and
llvm/utils/mlgo-utils and simplifies integration of hdrgen to the build
system which rely on Python modules. In addition to that, it clarifies
which imports are coming from the hdrgen-specific helpers (e.g. "from
type import ..." becomes "from hdrgen.type import ...".

Leave the entrypoints (top-level main.py and yaml_to_classes.py) as-is:
they can keep being referred by the CMake build system w/o any changes.
2025-02-26 15:41:30 -08:00
Roland McGrath
86f0e6dc11
[libc] Add --json mode for hdrgen (#127847)
This adds a feature to hdrgen to emit JSON summaries of header
files for build system integration.  For now the summaries have
only the basic information about each header that is relevant for
build and testing purposes: the standards and includes lists.
2025-02-19 16:07:45 -08:00
Roland McGrath
2157aecfe4
[libc] Produce standard-compliant header guard macros in hdrgen (#127356)
Macros starting with alphabetic characters such as "LLVM" are in
the application name space and cannot be defined or used by a
conforming implementation's headers.  This fixes the headers that
are entirely generated, and the __llvm-libc-common.h header to
use a conforming macro name for the header guard.  That is, it
starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers
starting with an underscore followed by a capital letter are in
the name space reserved for the implementation.

The remaining headers either will be fixed implicitly by removal
of their custom template files, or will need to be fixed by hand.
2025-02-15 17:36:44 -08:00
Roland McGrath
68a82a2298
[libc] Elide extra space in hdrgen function declarations (#127287)
When the return type's rendering already doesn't end with an
identifier character, such as when it's `T *`, then idiomatic
syntax does not include a space before the `(` and arguments.
2025-02-14 17:09:58 -08:00
Roland McGrath
9f6e72bd0c
[libc] Add merge_yaml_files feature to hdrgen (#127269)
This allows a sort of "include" mechanism in the YAML files.  A
file can have a "merge_yaml_files" list of paths (relative to the
containing file's location).  These are YAML files in the same
syntax, except they cannot have their own "header" entry.  Only
the lists (types, enums, macros, functions, objects) can appear.
The main YAML file is then processed just as if each of its lists
were the (sorted) union of each YAML file's corresponding list.

This will enable maintaining a single source of truth for each
function signature and other such details, where it is necessary
to generate the same declaration in more than one header.
2025-02-14 15:34:40 -08:00
Roland McGrath
303f241544
[libc] Make template_header optional for hdrgen (#127259)
This allows a YAML file to omit `template_header` and have no
`.h.def` file.  A default template is generated based purely on
the information in the YAML file.  This should handle most of the
cases.  For now, it's exercised (aside from the hdrgen tests)
only for one of the simplest cases: <ctype.h>.

This includes making the parser notice the "standards" YAML field
at the top (header) level, not just in "functions" lists.  The
standards listed for the header overall and for the individual
functions both feed into how a fully-generated header describes
itself in comments.  To go with this, files using the default
generated template must stick to a new uniform set of spellings
for the "standards" lists.  As more custom template files are
retired, the corresponding YAML files will need all their
standards lists normalized.  For now, ctype.yaml is updated
with correct attribution for the POSIX `_l` extensions.
2025-02-14 14:01:18 -08:00
Roland McGrath
dcfc30ca6b
[libc] Fix hdrgen to be compatible with Python 3.8 (#127265) 2025-02-14 13:51:14 -08:00
Roland McGrath
aa500a79fc
[libc] Make hdrgen deduce header type lists from function signatures (#127251)
With this, the `types` list in YAML files should only be used to
list the types that a standard specifies should be in that header
per se.  All the types referenced in function signatures will be
collected automatically.
2025-02-14 12:54:46 -08:00
Roland McGrath
d2dd8021fd
[libc] Make hdrgen emit correct relative paths for llvm-libc-types (#127150)
This makes hdrgen emit `#include "..."` lines using the correct
relative path (number of `../` steps, if any) for the containing
header, and includes this in the sorted block of `#include` lines
also used for the macro headers.
2025-02-14 11:01:26 -08:00
Roland McGrath
6d3bfddb9d
[libc] Make hdrgen support macro_header YAML field. (#123265)
A macro can specify macro_header instead of macro_value to
indicate that an llvm-libc-macros/ header file is supposed to
define this macro.  This is used for dlfcn.h, which previously
bogusly redefined the RTLD_* macros to empty.
2025-02-13 16:07:06 -08:00
Roland McGrath
906cbbbd3c
[libc] Fix hdrgen output for no-argument functions (#123245)
The hdrgen output is C, not C++.
2025-01-16 19:20:53 -08:00
Roland McGrath
cdbba15c6c
[libc] Add --write-if-changed switch to hdrgen/main.py (#122037)
This avoids touching the output file when it hasn't changed.  The
cmake build integration now uses this so that touching a .yaml or
.h.def file in ways that don't affect the generated header output
won't cause unnecessary recompilations.
2025-01-08 11:00:31 -08:00
Michael Jones
ca3fd63369
[libc] clean up the hdrgen docs a bit (#121974)
Since the files have been reorganized, the readme is out of date. This
patch updates it to be more accurate.
2025-01-07 16:29:01 -08:00
Roland McGrath
6ad0dcf67f
[libc] Revamp hdrgen command line and build integration (#121522)
This adds a new main command-line entry point for hdrgen, in the
new main.py.  This new interface is used for generating a header.
The old ways of invoking yaml_to_classes.py for other purposes
are left there for now, but `--e` is renamed to `--entry-point`
for consistency with the new CLI.

The YAML schema is expanded with the `header_template` key where
the corresponding `.h.def` file's path is given relative to where
the YAML file is found.  The build integration no longer gives
the `.h.def` path on the command line.  Instead, the script now
emits a depfile that's used by the cmake rules to track that.
The output file is always explicit in the script command line
rather than sometimes being derived from a directory path.
2025-01-07 15:56:12 -08:00
Roland McGrath
508929d42a
[libc] Make GpuHeaderFile a subclass (#121445)
Replace copy&paste from HeaderFile to GpuHeaderFile with
subclassing.  Only the __str__ method differs.
2025-01-01 18:16:32 -08:00
Roland McGrath
62cd050b63
[libc] Move hdrgen yaml files into include/ (#121443)
The .yaml files should live next to the corresponding .h.def
files in libc/include/, rather than next to the implementation of
the tool in libc/utils/hdrgen/.  As with the .h.def files, there
is no need for a yaml/ subdirectory under include/.  This simpler
layout is more natural for maintenance and also simplifies build
integration outside the LLVM CMake build.
2025-01-01 17:03:35 -08:00
Roland McGrath
07e13b764d
[libc] Remove unnecessary subdirectory layers in utils/hdrgen (#121363)
Two extra layers of subdirectory for a handful of single-symbol
Python source files did not improve anything, and it complicated
integration of the hdrgen Python outside the LLVM CMake build.
2024-12-30 17:28:59 -08:00
Roland McGrath
9abcca5e25
[libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00