diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 707bb91b875de6..da21a10d13d9c3 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -1033,160 +1033,181 @@ let relative = "compiler-rt"; }); in - { - compiler-rt-libc = callPackage ./compiler-rt ( - let - # temp rename to avoid infinite recursion + ( + { + compiler-rt-libc = callPackage ./compiler-rt ( + let + # temp rename to avoid infinite recursion + stdenv = + # Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling. + if args.stdenv.hostPlatform.isDarwin then + overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx + else if args.stdenv.hostPlatform.useLLVM or false then + overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx + else + args.stdenv; + in + { + patches = compiler-rtPatches; + inherit stdenv; + } + // lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) { + libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: { + configureFlags = old.configureFlags ++ [ "--disable-symvers" ]; + }); + } + ); + + compiler-rt-no-libc = callPackage ./compiler-rt { + patches = compiler-rtPatches; + doFakeLibgcc = stdenv.hostPlatform.useLLVM or false; stdenv = # Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling. - if args.stdenv.hostPlatform.isDarwin then - overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx - else if args.stdenv.hostPlatform.useLLVM or false then - overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx + if stdenv.hostPlatform.isDarwin then + overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt else - args.stdenv; - in - { - patches = compiler-rtPatches; - inherit stdenv; - } - // lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) { - libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: { - configureFlags = old.configureFlags ++ [ "--disable-symvers" ]; - }); - } - ); + overrideCC stdenv buildLlvmTools.clangNoLibcNoRt; + }; - compiler-rt-no-libc = callPackage ./compiler-rt { - patches = compiler-rtPatches; - doFakeLibgcc = stdenv.hostPlatform.useLLVM or false; - stdenv = - # Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling. - if stdenv.hostPlatform.isDarwin then - overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt + compiler-rt = + if + stdenv.hostPlatform.libc == null + # Building the with-libc compiler-rt and WASM doesn't yet work, + # because wasilibc doesn't provide some expected things. See + # compiler-rt's file for further details. + || stdenv.hostPlatform.isWasm + # Failing `#include ` in + # `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp` + # sanitizers, not sure where to get it. + || stdenv.hostPlatform.isFreeBSD + then + libraries.compiler-rt-no-libc else - overrideCC stdenv buildLlvmTools.clangNoLibcNoRt; - }; - - compiler-rt = - if - stdenv.hostPlatform.libc == null - # Building the with-libc compiler-rt and WASM doesn't yet work, - # because wasilibc doesn't provide some expected things. See - # compiler-rt's file for further details. - || stdenv.hostPlatform.isWasm - # Failing `#include ` in - # `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp` - # sanitizers, not sure where to get it. - || stdenv.hostPlatform.isFreeBSD - then - libraries.compiler-rt-no-libc - else - libraries.compiler-rt-libc; + libraries.compiler-rt-libc; - stdenv = overrideCC stdenv buildLlvmTools.clang; + stdenv = overrideCC stdenv buildLlvmTools.clang; - libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; - libcxx = callPackage ./libcxx ( - { - patches = - lib.optionals (lib.versionOlder metadata.release_version "16") ( - lib.optional (lib.versions.major metadata.release_version == "15") - # See: - # - https://reviews.llvm.org/D133566 - # - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432 - # !!! Drop in LLVM 16+ - ( - fetchpatch { - url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch"; - hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY="; - } - ) - ++ [ - (substitute { - src = ./libcxxabi/wasm.patch; + libcxx = callPackage ./libcxx ( + { + patches = + lib.optionals (lib.versionOlder metadata.release_version "16") ( + lib.optional (lib.versions.major metadata.release_version == "15") + # See: + # - https://reviews.llvm.org/D133566 + # - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432 + # !!! Drop in LLVM 16+ + ( + fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch"; + hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY="; + } + ) + ++ [ + (substitute { + src = ./libcxxabi/wasm.patch; + substitutions = [ + "--replace-fail" + "/cmake/" + "/llvm/cmake/" + ]; + }) + ] + ++ lib.optional stdenv.hostPlatform.isMusl (substitute { + src = ./libcxx/libcxx-0001-musl-hacks.patch; substitutions = [ "--replace-fail" - "/cmake/" - "/llvm/cmake/" + "/include/" + "/libcxx/include/" ]; }) - ] - ++ lib.optional stdenv.hostPlatform.isMusl (substitute { - src = ./libcxx/libcxx-0001-musl-hacks.patch; - substitutions = [ - "--replace-fail" - "/include/" - "/libcxx/include/" - ]; - }) + ) + ++ + lib.optional + ( + lib.versions.major metadata.release_version == "17" + && stdenv.hostPlatform.isDarwin + && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13" + ) + # https://github.com/llvm/llvm-project/issues/64226 + ( + fetchpatch { + name = "0042-mbstate_t-not-defined.patch"; + url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch"; + hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI="; + } + ) + ++ + lib.optional + ( + lib.versionAtLeast metadata.release_version "18" + && stdenv.hostPlatform.isDarwin + && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13" + ) + # https://github.com/llvm/llvm-project/issues/64226 + (metadata.getVersionFile "libcxx/0001-darwin-10.12-mbstate_t-fix.patch"); + stdenv = + if stdenv.hostPlatform.isDarwin then + overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt + else + overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt; + } + // lib.optionalAttrs (lib.versionOlder metadata.release_version "14") { + # TODO: remove this, causes LLVM 13 packages rebuild. + inherit (metadata) monorepoSrc; # Preserve bug during #307211 refactor. + } + ); + + libunwind = callPackage ./libunwind { + patches = lib.optional (lib.versionOlder metadata.release_version "17") ( + metadata.getVersionFile "libunwind/gnu-install-dirs.patch" + ); + stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt; + }; + + openmp = callPackage ./openmp { + patches = + lib.optional ( + lib.versionAtLeast metadata.release_version "15" && lib.versionOlder metadata.release_version "19" + ) (metadata.getVersionFile "openmp/fix-find-tool.patch") + ++ lib.optional ( + lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18" + ) (metadata.getVersionFile "openmp/gnu-install-dirs.patch") + ++ lib.optional (lib.versionAtLeast metadata.release_version "14") ( + metadata.getVersionFile "openmp/run-lit-directly.patch" ) ++ - lib.optional - ( - lib.versions.major metadata.release_version == "17" - && stdenv.hostPlatform.isDarwin - && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13" - ) - # https://github.com/llvm/llvm-project/issues/64226 + lib.optional (lib.versionOlder metadata.release_version "14") + # Fix cross. ( fetchpatch { - name = "0042-mbstate_t-not-defined.patch"; - url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch"; - hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI="; + url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch"; + hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A="; } - ) - ++ - lib.optional - ( - lib.versionAtLeast metadata.release_version "18" - && stdenv.hostPlatform.isDarwin - && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13" - ) - # https://github.com/llvm/llvm-project/issues/64226 - (metadata.getVersionFile "libcxx/0001-darwin-10.12-mbstate_t-fix.patch"); - stdenv = - if stdenv.hostPlatform.isDarwin then - overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt - else - overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt; - } - // lib.optionalAttrs (lib.versionOlder metadata.release_version "14") { - # TODO: remove this, causes LLVM 13 packages rebuild. - inherit (metadata) monorepoSrc; # Preserve bug during #307211 refactor. - } - ); - - libunwind = callPackage ./libunwind { - patches = lib.optional (lib.versionOlder metadata.release_version "17") ( - metadata.getVersionFile "libunwind/gnu-install-dirs.patch" - ); - stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt; - }; + ); + }; + } + // lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") ( + let + libcPatches = [ + # PR: https://github.com/llvm/llvm-project/pull/118862 + (metadata.getVersionFile "libc/unistd.patch") + ]; + in + { + libc = callPackage ./libc { + isFullBuild = false; + patches = libcPatches; + }; - openmp = callPackage ./openmp { - patches = - lib.optional ( - lib.versionAtLeast metadata.release_version "15" && lib.versionOlder metadata.release_version "19" - ) (metadata.getVersionFile "openmp/fix-find-tool.patch") - ++ lib.optional ( - lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18" - ) (metadata.getVersionFile "openmp/gnu-install-dirs.patch") - ++ lib.optional (lib.versionAtLeast metadata.release_version "14") ( - metadata.getVersionFile "openmp/run-lit-directly.patch" - ) - ++ - lib.optional (lib.versionOlder metadata.release_version "14") - # Fix cross. - ( - fetchpatch { - url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch"; - hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A="; - } - ); - }; - } + libc-full = callPackage ./libc { + isFullBuild = true; + patches = libcPatches; + }; + } + ) + ) ); noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; diff --git a/pkgs/development/compilers/llvm/common/libc/default.nix b/pkgs/development/compilers/llvm/common/libc/default.nix new file mode 100644 index 00000000000000..4b3549db7056d8 --- /dev/null +++ b/pkgs/development/compilers/llvm/common/libc/default.nix @@ -0,0 +1,66 @@ +{ + lib, + stdenv, + llvm_meta, + src ? null, + monorepoSrc ? null, + version, + release_version, + runCommand, + python3, + python3Packages, + patches ? [ ], + cmake, + ninja, + isFullBuild ? true, +}: +let + pname = "libc"; + + src' = + if monorepoSrc != null then + runCommand "${pname}-src-${version}" { } ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + '') + else + src; +in +stdenv.mkDerivation (finalAttrs: { + inherit pname version patches; + + src = src'; + + sourceRoot = + if lib.versionOlder release_version "13" then null else "${finalAttrs.src.name}/${pname}"; + + nativeBuildInputs = + [ cmake ] + ++ (lib.optional (lib.versionAtLeast release_version "15") ninja) + ++ (lib.optionals finalAttrs.passthru.isFullBuild [ + python3 + python3Packages.pyyaml + ]); + + postUnpack = lib.optionalString finalAttrs.passthru.isFullBuild '' + patchShebangs --host $sourceRoot/hdrgen/yaml_to_classes.py + chmod +x $sourceRoot/hdrgen/yaml_to_classes.py + ''; + + cmakeFlags = [ + (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" finalAttrs.passthru.isFullBuild) + (lib.cmakeFeature "Python3_EXECUTABLE" (lib.getExe python3)) + ]; + + # For the update script: + passthru = { + monorepoSrc = monorepoSrc; + inherit isFullBuild; + }; + + meta = llvm_meta // { + homepage = "https://libc.llvm.org/"; + description = "Standard C library for LLVM"; + }; +}) diff --git a/pkgs/development/compilers/llvm/git/libc/unistd.patch b/pkgs/development/compilers/llvm/git/libc/unistd.patch new file mode 100644 index 00000000000000..fdcbd04d3b7cef --- /dev/null +++ b/pkgs/development/compilers/llvm/git/libc/unistd.patch @@ -0,0 +1,577 @@ +From 9f4c2138f7613707d73292e69da194c5d76b8de2 Mon Sep 17 00:00:00 2001 +From: Tristan Ross +Date: Thu, 5 Dec 2024 13:52:05 -0800 +Subject: [PATCH] [libc] Add unistd overlay + +--- + libc/hdr/CMakeLists.txt | 3 ++ + libc/hdr/unistd_macros.h | 2 +- + libc/hdr/unistd_overlay.h | 69 +++++++++++++++++++++++++++++ + libc/src/unistd/dup.h | 2 +- + libc/src/unistd/dup2.h | 2 +- + libc/src/unistd/dup3.h | 2 +- + libc/src/unistd/fork.h | 2 +- + libc/src/unistd/ftruncate.h | 2 +- + libc/src/unistd/getcwd.h | 2 +- + libc/src/unistd/geteuid.h | 2 +- + libc/src/unistd/getopt.h | 2 +- + libc/src/unistd/getpid.h | 2 +- + libc/src/unistd/getppid.h | 2 +- + libc/src/unistd/getuid.h | 2 +- + libc/src/unistd/isatty.h | 2 +- + libc/src/unistd/link.h | 2 +- + libc/src/unistd/linux/ftruncate.cpp | 2 +- + libc/src/unistd/linux/lseek.cpp | 4 +- + libc/src/unistd/linux/sysconf.cpp | 2 +- + libc/src/unistd/linux/truncate.cpp | 2 +- + libc/src/unistd/lseek.h | 2 +- + libc/src/unistd/pread.h | 2 +- + libc/src/unistd/pwrite.h | 2 +- + libc/src/unistd/read.h | 2 +- + libc/src/unistd/readlink.h | 2 +- + libc/src/unistd/readlinkat.h | 2 +- + libc/src/unistd/swab.h | 2 +- + libc/src/unistd/symlink.h | 2 +- + libc/src/unistd/symlinkat.h | 2 +- + libc/src/unistd/syscall.h | 2 +- + libc/src/unistd/sysconf.h | 2 +- + libc/src/unistd/truncate.h | 2 +- + libc/src/unistd/write.h | 2 +- + 33 files changed, 104 insertions(+), 32 deletions(-) + create mode 100644 libc/hdr/unistd_overlay.h + +diff --git a/hdr/CMakeLists.txt b/hdr/CMakeLists.txt +index 5eb311f4bb2298..7f523c50e86943 100644 +--- a/hdr/CMakeLists.txt ++++ b/hdr/CMakeLists.txt +@@ -126,10 +126,13 @@ add_proxy_header_library( + libc.include.llvm-libc-macros.sys_stat_macros + ) + ++add_header_library(unistd_overlay HDRS unistd_overlay.h) + add_proxy_header_library( + unistd_macros + HDRS + unistd_macros.h ++ DEPENDS ++ .unistd_overlay + FULL_BUILD_DEPENDS + libc.include.unistd + libc.include.llvm-libc-macros.unistd_macros +diff --git a/hdr/unistd_macros.h b/hdr/unistd_macros.h +index 132e123280139f..5c2b24354dd3ee 100644 +--- a/hdr/unistd_macros.h ++++ b/hdr/unistd_macros.h +@@ -15,7 +15,7 @@ + + #else // Overlay mode + +-#include ++#include "unistd_overlay.h" + + #endif // LLVM_LIBC_FULL_BUILD + +diff --git a/hdr/unistd_overlay.h b/hdr/unistd_overlay.h +new file mode 100644 +index 00000000000000..f2c9ed8e34ff60 +--- /dev/null ++++ b/hdr/unistd_overlay.h +@@ -0,0 +1,69 @@ ++//===-- Including unistd.h in overlay mode ---------------------------------===// ++// ++// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ++// See https://llvm.org/LICENSE.txt for license information. ++// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception ++// ++//===----------------------------------------------------------------------===// ++ ++#ifndef LLVM_LIBC_HDR_UNISTD_OVERLAY_H ++#define LLVM_LIBC_HDR_UNISTD_OVERLAY_H ++ ++#ifdef LIBC_FULL_BUILD ++#error "This header should only be included in overlay mode" ++#endif ++ ++// Overlay mode ++ ++// glibc header might provide extern inline definitions for few ++// functions, causing external alias errors. They are guarded by ++// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES` ++// macro by defining `__NO_INLINE__` before including . ++// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled ++// with `_FORTIFY_SOURCE`. ++ ++#ifdef _FORTIFY_SOURCE ++#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE ++#undef _FORTIFY_SOURCE ++#endif ++ ++#ifdef __USE_EXTERN_INLINES ++#define LIBC_OLD_USE_EXTERN_INLINES ++#undef __USE_EXTERN_INLINES ++#endif ++ ++#ifdef __USE_FORTIFY_LEVEL ++#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL ++#undef __USE_FORTIFY_LEVEL ++#define __USE_FORTIFY_LEVEL 0 ++#endif ++ ++#ifndef __NO_INLINE__ ++#define __NO_INLINE__ 1 ++#define LIBC_SET_NO_INLINE ++#endif ++ ++#include ++ ++#ifdef LIBC_OLD_FORTIFY_SOURCE ++#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE ++#undef LIBC_OLD_FORTIFY_SOURCE ++#endif ++ ++#ifdef LIBC_SET_NO_INLINE ++#undef __NO_INLINE__ ++#undef LIBC_SET_NO_INLINE ++#endif ++ ++#ifdef LIBC_OLD_USE_FORTIFY_LEVEL ++#undef __USE_FORTIFY_LEVEL ++#define __USE_FORTIFY_LEVEL LIBC_OLD_USE_FORTIFY_LEVEL ++#undef LIBC_OLD_USE_FORTIFY_LEVEL ++#endif ++ ++#ifdef LIBC_OLD_USE_EXTERN_INLINES ++#define __USE_EXTERN_INLINES ++#undef LIBC_OLD_USE_EXTERN_INLINES ++#endif ++ ++#endif // LLVM_LIBC_HDR_UNISTD_OVERLAY_H +diff --git a/src/unistd/dup.h b/src/unistd/dup.h +index 63f093c0ee4365..57601455acc61c 100644 +--- a/src/unistd/dup.h ++++ b/src/unistd/dup.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_DUP_H + #define LLVM_LIBC_SRC_UNISTD_DUP_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/dup2.h b/src/unistd/dup2.h +index 060c112daf08fb..e2cf62389bca87 100644 +--- a/src/unistd/dup2.h ++++ b/src/unistd/dup2.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_DUP2_H + #define LLVM_LIBC_SRC_UNISTD_DUP2_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/dup3.h b/src/unistd/dup3.h +index f3868867123b43..06d9b23dbd200f 100644 +--- a/src/unistd/dup3.h ++++ b/src/unistd/dup3.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_DUP3_H + #define LLVM_LIBC_SRC_UNISTD_DUP3_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/fork.h b/src/unistd/fork.h +index b6fd5763b3a5f6..f55ec740cfb12c 100644 +--- a/src/unistd/fork.h ++++ b/src/unistd/fork.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_FORK_H + #define LLVM_LIBC_SRC_UNISTD_FORK_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/ftruncate.h b/src/unistd/ftruncate.h +index cd8d363727c4ad..88a7d13249e8c1 100644 +--- a/src/unistd/ftruncate.h ++++ b/src/unistd/ftruncate.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_FTRUNCATE_H + #define LLVM_LIBC_SRC_UNISTD_FTRUNCATE_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/getcwd.h b/src/unistd/getcwd.h +index 8b63a91c26b5c7..36ca48141b93fb 100644 +--- a/src/unistd/getcwd.h ++++ b/src/unistd/getcwd.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_GETCWD_H + #define LLVM_LIBC_SRC_UNISTD_GETCWD_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/geteuid.h b/src/unistd/geteuid.h +index 9469797bd3d4ef..5cb4ed53ae88f1 100644 +--- a/src/unistd/geteuid.h ++++ b/src/unistd/geteuid.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_GETEUID_H + #define LLVM_LIBC_SRC_UNISTD_GETEUID_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/getopt.h b/src/unistd/getopt.h +index 1be3331dcd98a4..0be639d8711961 100644 +--- a/src/unistd/getopt.h ++++ b/src/unistd/getopt.h +@@ -10,8 +10,8 @@ + #define LLVM_LIBC_SRC_UNISTD_GETOPT_H + + #include "hdr/types/FILE.h" ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/getpid.h b/src/unistd/getpid.h +index c3c55b0c06b108..4b6011673d06f2 100644 +--- a/src/unistd/getpid.h ++++ b/src/unistd/getpid.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_GETPID_H + #define LLVM_LIBC_SRC_UNISTD_GETPID_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/getppid.h b/src/unistd/getppid.h +index d820791bc06fad..ffe05dde1fa437 100644 +--- a/src/unistd/getppid.h ++++ b/src/unistd/getppid.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_GETPPID_H + #define LLVM_LIBC_SRC_UNISTD_GETPPID_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/getuid.h b/src/unistd/getuid.h +index dd82c7119d4017..c927f95b1eba78 100644 +--- a/src/unistd/getuid.h ++++ b/src/unistd/getuid.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_GETUID_H + #define LLVM_LIBC_SRC_UNISTD_GETUID_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/isatty.h b/src/unistd/isatty.h +index 6dd1b7b817171a..5c8be6541c99cb 100644 +--- a/src/unistd/isatty.h ++++ b/src/unistd/isatty.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_ISATTY_H + #define LLVM_LIBC_SRC_UNISTD_ISATTY_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/link.h b/src/unistd/link.h +index 9b27aa1accf4ea..c1c26c5e0d4948 100644 +--- a/src/unistd/link.h ++++ b/src/unistd/link.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_LINK_H + #define LLVM_LIBC_SRC_UNISTD_LINK_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/linux/ftruncate.cpp b/src/unistd/linux/ftruncate.cpp +index 39cb3b5778faaf..ccbb0634664aad 100644 +--- a/src/unistd/linux/ftruncate.cpp ++++ b/src/unistd/linux/ftruncate.cpp +@@ -11,11 +11,11 @@ + #include "src/__support/OSUtil/syscall.h" // For internal syscall function. + #include "src/__support/common.h" + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" + #include "src/errno/libc_errno.h" + #include // For uint64_t. + #include // For syscall numbers. +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/linux/lseek.cpp b/src/unistd/linux/lseek.cpp +index 9486cecf3b1234..3bf94622d87593 100644 +--- a/src/unistd/linux/lseek.cpp ++++ b/src/unistd/linux/lseek.cpp +@@ -14,8 +14,8 @@ + #include "src/__support/OSUtil/syscall.h" // For internal syscall function. + #include "src/__support/common.h" + +-#include // For syscall numbers. +-#include // For off_t. ++#include "hdr/types/off_t.h" ++#include // For syscall numbers. + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/linux/sysconf.cpp b/src/unistd/linux/sysconf.cpp +index 1540eb499ec12d..f785ff321c7d7e 100644 +--- a/src/unistd/linux/sysconf.cpp ++++ b/src/unistd/linux/sysconf.cpp +@@ -10,11 +10,11 @@ + + #include "src/__support/common.h" + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" + #include "src/errno/libc_errno.h" + #include "src/sys/auxv/getauxval.h" + #include +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/linux/truncate.cpp b/src/unistd/linux/truncate.cpp +index 283cf4098cf457..8236edb480d108 100644 +--- a/src/unistd/linux/truncate.cpp ++++ b/src/unistd/linux/truncate.cpp +@@ -13,9 +13,9 @@ + #include "src/__support/macros/config.h" + #include "src/errno/libc_errno.h" + ++#include "hdr/unistd_macros.h" + #include // For uint64_t. + #include // For syscall numbers. +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/lseek.h b/src/unistd/lseek.h +index a8704ec7058dd2..fdfc7656c4b3ed 100644 +--- a/src/unistd/lseek.h ++++ b/src/unistd/lseek.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_LSEEK_H + #define LLVM_LIBC_SRC_UNISTD_LSEEK_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/pread.h b/src/unistd/pread.h +index 4723675e82a20a..e2cfce6b53ed5f 100644 +--- a/src/unistd/pread.h ++++ b/src/unistd/pread.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_PREAD_H + #define LLVM_LIBC_SRC_UNISTD_PREAD_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/pwrite.h b/src/unistd/pwrite.h +index baffbe48b64371..2f5646b048ec96 100644 +--- a/src/unistd/pwrite.h ++++ b/src/unistd/pwrite.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_PWRITE_H + #define LLVM_LIBC_SRC_UNISTD_PWRITE_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/read.h b/src/unistd/read.h +index 01231cb82e35e5..a12c49e4254eca 100644 +--- a/src/unistd/read.h ++++ b/src/unistd/read.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_READ_H + #define LLVM_LIBC_SRC_UNISTD_READ_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/readlink.h b/src/unistd/readlink.h +index a73e9740c74637..9047097f46b24a 100644 +--- a/src/unistd/readlink.h ++++ b/src/unistd/readlink.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_READLINK_H + #define LLVM_LIBC_SRC_UNISTD_READLINK_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/readlinkat.h b/src/unistd/readlinkat.h +index 6bdd48b537fc8c..10fd8bb6a14b8d 100644 +--- a/src/unistd/readlinkat.h ++++ b/src/unistd/readlinkat.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_READLINKAT_H + #define LLVM_LIBC_SRC_UNISTD_READLINKAT_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/swab.h b/src/unistd/swab.h +index caa9c71001097b..f6fa3414c43f55 100644 +--- a/src/unistd/swab.h ++++ b/src/unistd/swab.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_SWAB_H + #define LLVM_LIBC_SRC_UNISTD_SWAB_H + ++#include "hdr/types/ssize_t.h" + #include "src/__support/macros/config.h" +-#include // For ssize_t + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/symlink.h b/src/unistd/symlink.h +index 47f04f8845b460..c743a32a8930f9 100644 +--- a/src/unistd/symlink.h ++++ b/src/unistd/symlink.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_SYMLINK_H + #define LLVM_LIBC_SRC_UNISTD_SYMLINK_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/symlinkat.h b/src/unistd/symlinkat.h +index 9f8ad517af5a62..6697ce4d537e6a 100644 +--- a/src/unistd/symlinkat.h ++++ b/src/unistd/symlinkat.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_SYMLINKAT_H + #define LLVM_LIBC_SRC_UNISTD_SYMLINKAT_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/syscall.h b/src/unistd/syscall.h +index db70745719cfe3..7f82bd8a452f62 100644 +--- a/src/unistd/syscall.h ++++ b/src/unistd/syscall.h +@@ -9,9 +9,9 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_SYSCALL_H + #define LLVM_LIBC_SRC_UNISTD_SYSCALL_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" + #include +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/sysconf.h b/src/unistd/sysconf.h +index 1b3f39e413508b..470c4d846568c7 100644 +--- a/src/unistd/sysconf.h ++++ b/src/unistd/sysconf.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_SYSCONF_H + #define LLVM_LIBC_SRC_UNISTD_SYSCONF_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/truncate.h b/src/unistd/truncate.h +index 9ba5cf83175291..5206a864bcf5db 100644 +--- a/src/unistd/truncate.h ++++ b/src/unistd/truncate.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_TRUNCATE_H + #define LLVM_LIBC_SRC_UNISTD_TRUNCATE_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { + +diff --git a/src/unistd/write.h b/src/unistd/write.h +index e40ce19e21769c..fa08ae40cf603f 100644 +--- a/src/unistd/write.h ++++ b/src/unistd/write.h +@@ -9,8 +9,8 @@ + #ifndef LLVM_LIBC_SRC_UNISTD_WRITE_H + #define LLVM_LIBC_SRC_UNISTD_WRITE_H + ++#include "hdr/unistd_macros.h" + #include "src/__support/macros/config.h" +-#include + + namespace LIBC_NAMESPACE_DECL { +