[libc-commits] [libc] [libc] Remove the #include <stdlib.h> header (PR #114453)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 31 12:06:59 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Job Henandez Lara (Jobhdez)

<details>
<summary>Changes</summary>



---

Patch is 24.45 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/114453.diff


45 Files Affected:

- (modified) libc/hdr/CMakeLists.txt (+11) 
- (added) libc/hdr/stdlib_macros.h (+22) 
- (added) libc/hdr/stdlib_overlay.h (+36) 
- (modified) libc/hdr/types/CMakeLists.txt (+41) 
- (added) libc/hdr/types/div_t.h (+22) 
- (added) libc/hdr/types/ldiv_t.h (+22) 
- (added) libc/hdr/types/lldiv_t.h (+22) 
- (added) libc/hdr/types/size_t.h (+23) 
- (modified) libc/src/__support/CPP/new.cpp (-1) 
- (modified) libc/src/__support/CPP/new.h (+1-1) 
- (modified) libc/src/__support/File/dir.h (-1) 
- (modified) libc/src/stdlib/CMakeLists.txt (+6-7) 
- (modified) libc/src/stdlib/div.h (+1-1) 
- (modified) libc/src/stdlib/exit.h (-1) 
- (modified) libc/src/stdlib/free.h (-1) 
- (modified) libc/src/stdlib/ldiv.h (+1-1) 
- (modified) libc/src/stdlib/lldiv.h (+1-1) 
- (modified) libc/src/stdlib/malloc.h (+1-1) 
- (modified) libc/src/stdlib/qsort.h (+1-1) 
- (modified) libc/src/stdlib/qsort_r.h (+1-1) 
- (modified) libc/src/stdlib/rand.h (+1-1) 
- (modified) libc/src/stdlib/srand.h (-1) 
- (modified) libc/src/string/CMakeLists.txt (+1-1) 
- (modified) libc/src/string/strdup.cpp (+1-2) 
- (modified) libc/src/unistd/linux/CMakeLists.txt (-1) 
- (modified) libc/src/unistd/linux/getcwd.cpp (-1) 
- (modified) libc/test/src/__support/File/CMakeLists.txt (+1-1) 
- (modified) libc/test/src/__support/File/file_test.cpp (+1-1) 
- (modified) libc/test/src/__support/str_to_float_comparison_test.cpp (-2) 
- (modified) libc/test/src/stdio/CMakeLists.txt (+1-1) 
- (modified) libc/test/src/stdio/fopencookie_test.cpp (+1-1) 
- (modified) libc/test/src/stdlib/CMakeLists.txt (+5-8) 
- (modified) libc/test/src/stdlib/_Exit_test.cpp (-2) 
- (modified) libc/test/src/stdlib/abort_test.cpp (-1) 
- (modified) libc/test/src/stdlib/bsearch_test.cpp (+1-1) 
- (modified) libc/test/src/stdlib/div_test.cpp (+1-2) 
- (modified) libc/test/src/stdlib/ldiv_test.cpp (+1-2) 
- (modified) libc/test/src/stdlib/lldiv_test.cpp (+1-2) 
- (modified) libc/test/src/stdlib/qsort_r_test.cpp (+1-1) 
- (modified) libc/test/src/stdlib/rand_test.cpp (-1) 
- (modified) libc/test/src/string/CMakeLists.txt (-2) 
- (modified) libc/test/src/string/strdup_test.cpp (-2) 
- (modified) libc/test/src/string/strlcat_test.cpp (+1-1) 
- (modified) libc/test/src/string/strlcpy_test.cpp (-1) 
- (modified) libc/test/src/string/strndup_test.cpp (-1) 


``````````diff
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 80545ee4b359f4..c63eadab6f5d77 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -81,6 +81,17 @@ add_proxy_header_library(
     libc.include.signal
 )
 
+add_proxy_header_library(
+  stdlib_macros
+  HDRS
+    stdlib_macros.h
+  DEPENDS
+    .stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+    libc.include.llvm-libc-macros.stdlib_macros
+)
+
 add_header_library(stdio_overlay HDRS stdio_overlay.h)
 
 add_proxy_header_library(
diff --git a/libc/hdr/stdlib_macros.h b/libc/hdr/stdlib_macros.h
new file mode 100644
index 00000000000000..3faeb3a8fe36e1
--- /dev/null
+++ b/libc/hdr/stdlib_macros.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from stdlib.h --------------------------------===//
+//
+// 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_STDLIB_MACROS_H
+#define LLVM_LIBC_HDR_STDLIB_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/stdlib-macros.h"
+
+#else // Overlay mode
+
+#include "stdlib_overlay.h"
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_STDLIB_MACROS_H
diff --git a/libc/hdr/stdlib_overlay.h b/libc/hdr/stdlib_overlay.h
new file mode 100644
index 00000000000000..f095cafe5e0bce
--- /dev/null
+++ b/libc/hdr/stdlib_overlay.h
@@ -0,0 +1,36 @@
+//===-- Including stdlib.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_STDLIB_OVERLAY_H
+#define LLVM_LIBC_HDR_STDLIB_OVERLAY_H
+
+#ifdef LIBC_FULL_BUILD
+#error "This header should only be included in overlay mode"
+#endif
+
+// Overlay mode
+
+// glibc <stdlib.h> header might provide extern inline definitions for few
+// functions, causing external alias errors.  They are guarded by
+// `__USE_FORTIFY_LEVEL`, which will be temporarily disabled.
+
+#ifdef __USE_FORTIFY_LEVEL
+#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
+#undef __USE_FORTIFY_LEVEL
+#define __USE_FORTIFY_LEVEL 0
+#endif
+
+#include <stdlib.h>
+
+#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
+
+#endif
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index e45979857d7955..928bde71278166 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -1,3 +1,36 @@
+add_proxy_header_library(
+  div_t
+  HDRS
+    div_t.h
+  DEPENDS
+    ../stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.div_t
+    libc.include.stdlib
+)
+
+add_proxy_header_library(
+  ldiv_t
+  HDRS
+    ldiv_t.h
+  DEPENDS
+    ../stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.ldiv_t
+    libc.include.stdlib
+)
+
+add_proxy_header_library(
+  lldiv_t
+  HDRS
+    lldiv_t.h
+  DEPENDS
+    ../stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.lldiv_t
+    libc.include.stdlib
+)
+
 add_proxy_header_library(
   sigset_t
   HDRS
@@ -46,6 +79,14 @@ add_proxy_header_library(
     libc.include.llvm-libc-types.struct_timespec
 )
 
+add_proxy_header_library(
+  size_t
+  HDRS
+    size_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.size_t
+)
+
 add_proxy_header_library(
   mode_t
   HDRS
diff --git a/libc/hdr/types/div_t.h b/libc/hdr/types/div_t.h
new file mode 100644
index 00000000000000..29c355f079e104
--- /dev/null
+++ b/libc/hdr/types/div_t.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from div_t.h ---------------------------------===//
+//
+// 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_TYPES_DIV_T_H
+#define LLVM_LIBC_HDR_TYPES_DIV_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/div_t.h"
+
+#else // Overlay mode
+
+#include "hdr/stdlib_overlay.h"
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_DIV_T_H
diff --git a/libc/hdr/types/ldiv_t.h b/libc/hdr/types/ldiv_t.h
new file mode 100644
index 00000000000000..c7023f5077bd0c
--- /dev/null
+++ b/libc/hdr/types/ldiv_t.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from ldiv_t.h --------------------------------===//
+//
+// 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_TYPES_LDIV_T_H
+#define LLVM_LIBC_HDR_TYPES_LDIV_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/ldiv_t.h"
+
+#else // Overlay mode
+
+#include "hdr/stdlib_overlay.h"
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_LDIV_T_H
diff --git a/libc/hdr/types/lldiv_t.h b/libc/hdr/types/lldiv_t.h
new file mode 100644
index 00000000000000..cd41886674a16d
--- /dev/null
+++ b/libc/hdr/types/lldiv_t.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from lldiv_t.h -------------------------------===//
+//
+// 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_TYPES_LLDIV_T_H
+#define LLVM_LIBC_HDR_TYPES_LLDIV_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/lldiv_t.h"
+
+#else // Overlay mode
+
+#include "hdr/stdlib_overlay.h"
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_LLDIV_T_H
diff --git a/libc/hdr/types/size_t.h b/libc/hdr/types/size_t.h
new file mode 100644
index 00000000000000..1d9f26db3bbb3a
--- /dev/null
+++ b/libc/hdr/types/size_t.h
@@ -0,0 +1,23 @@
+//===-- Proxy for size_t --------------------------------------------------===//
+//
+// 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_TYPES_SIZE_T_H
+#define LLVM_LIBC_HDR_TYPES_SIZE_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/size_t.h"
+
+#else
+
+#define __need_size_t
+#include <stddef.h>
+#undef __need_size_t
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_SIZE_T_H
diff --git a/libc/src/__support/CPP/new.cpp b/libc/src/__support/CPP/new.cpp
index 88db8377b2fac4..5c67f856058d81 100644
--- a/libc/src/__support/CPP/new.cpp
+++ b/libc/src/__support/CPP/new.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "new.h"
-#include <stdlib.h>
 
 void operator delete(void *mem) noexcept { ::free(mem); }
 
diff --git a/libc/src/__support/CPP/new.h b/libc/src/__support/CPP/new.h
index c1b6b95033f84c..5476781c377988 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -14,7 +14,7 @@
 #include "src/__support/macros/properties/os.h"
 
 #include <stddef.h> // For size_t
-#include <stdlib.h> // For malloc, free etc.
+#include <stdlib.h>
 
 // Defining members in the std namespace is not preferred. But, we do it here
 // so that we can use it to define the operator new which takes std::align_val_t
diff --git a/libc/src/__support/File/dir.h b/libc/src/__support/File/dir.h
index 136c266524a011..247ac1225ceea3 100644
--- a/libc/src/__support/File/dir.h
+++ b/libc/src/__support/File/dir.h
@@ -15,7 +15,6 @@
 #include "src/__support/threads/mutex.h"
 
 #include <dirent.h>
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index d997cd41e630fa..14d06534a6049a 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -221,7 +221,7 @@ add_entrypoint_object(
   HDRS
     div.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.div_t
     libc.src.__support.integer_operations
 )
 
@@ -232,7 +232,7 @@ add_entrypoint_object(
   HDRS
     ldiv.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.ldiv_t
     libc.src.__support.integer_operations
 )
 
@@ -243,7 +243,7 @@ add_entrypoint_object(
   HDRS
     lldiv.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.lldiv_t
     libc.src.__support.integer_operations
 )
 
@@ -277,7 +277,7 @@ add_entrypoint_object(
     qsort.h
   DEPENDS
     .qsort_util
-    libc.include.stdlib
+    libc.hdr.types.size_t
 )
 
 add_entrypoint_object(
@@ -288,7 +288,7 @@ add_entrypoint_object(
     qsort_r.h
   DEPENDS
     .qsort_util
-    libc.include.stdlib
+    libc.hdr.types.size_t
 )
 
 add_object_library(
@@ -309,7 +309,7 @@ add_entrypoint_object(
     rand.h
   DEPENDS
     .rand_util
-    libc.include.stdlib
+    libc.hdr.stdlib_macros
     libc.src.__support.threads.sleep
 )
 
@@ -321,7 +321,6 @@ add_entrypoint_object(
     srand.h
   DEPENDS
     .rand_util
-    libc.include.stdlib
 )
 
 if(NOT LIBC_TARGET_OS_IS_GPU)
diff --git a/libc/src/stdlib/div.h b/libc/src/stdlib/div.h
index e76f79bbeee5fa..4917ac1973c5b6 100644
--- a/libc/src/stdlib/div.h
+++ b/libc/src/stdlib/div.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_DIV_H
 #define LLVM_LIBC_SRC_STDLIB_DIV_H
 
+#include "hdr/types/div_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/exit.h b/libc/src/stdlib/exit.h
index 1f0153b98c1f44..3c9d37a342eb98 100644
--- a/libc/src/stdlib/exit.h
+++ b/libc/src/stdlib/exit.h
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_SRC_STDLIB_EXIT_H
 
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/free.h b/libc/src/stdlib/free.h
index 1b250f3d3a7aa5..77d00a5810e715 100644
--- a/libc/src/stdlib/free.h
+++ b/libc/src/stdlib/free.h
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 #ifndef LLVM_LIBC_SRC_STDLIB_FREE_H
 #define LLVM_LIBC_SRC_STDLIB_FREE_H
diff --git a/libc/src/stdlib/ldiv.h b/libc/src/stdlib/ldiv.h
index 56b71fd044b189..b6b799775c2009 100644
--- a/libc/src/stdlib/ldiv.h
+++ b/libc/src/stdlib/ldiv.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_LDIV_H
 #define LLVM_LIBC_SRC_STDLIB_LDIV_H
 
+#include "hdr/types/ldiv_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/lldiv.h b/libc/src/stdlib/lldiv.h
index ad688e00289ef8..9c4899172c672d 100644
--- a/libc/src/stdlib/lldiv.h
+++ b/libc/src/stdlib/lldiv.h
@@ -8,8 +8,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_LLDIV_H
 #define LLVM_LIBC_SRC_STDLIB_LLDIV_H
 
+#include "hdr/types/lldiv_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/malloc.h b/libc/src/stdlib/malloc.h
index 1974f5d3a78154..074df254bf9353 100644
--- a/libc/src/stdlib/malloc.h
+++ b/libc/src/stdlib/malloc.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/types/size_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 #ifndef LLVM_LIBC_SRC_STDLIB_MALLOC_H
 #define LLVM_LIBC_SRC_STDLIB_MALLOC_H
diff --git a/libc/src/stdlib/qsort.h b/libc/src/stdlib/qsort.h
index 38988312f90147..2060584c0cdff6 100644
--- a/libc/src/stdlib/qsort.h
+++ b/libc/src/stdlib/qsort.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_QSORT_H
 #define LLVM_LIBC_SRC_STDLIB_QSORT_H
 
+#include "hdr/types/size_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/qsort_r.h b/libc/src/stdlib/qsort_r.h
index 574968a528711f..51a459c3f76338 100644
--- a/libc/src/stdlib/qsort_r.h
+++ b/libc/src/stdlib/qsort_r.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_QSORT_R_H
 #define LLVM_LIBC_SRC_STDLIB_QSORT_R_H
 
+#include "hdr/types/size_t.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/rand.h b/libc/src/stdlib/rand.h
index df217b569aa8a4..65693197164bf5 100644
--- a/libc/src/stdlib/rand.h
+++ b/libc/src/stdlib/rand.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_RAND_H
 #define LLVM_LIBC_SRC_STDLIB_RAND_H
 
+#include "hdr/stdlib_macros.h"
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdlib/srand.h b/libc/src/stdlib/srand.h
index c9fce46ddd2bc8..3c40c744aebef9 100644
--- a/libc/src/stdlib/srand.h
+++ b/libc/src/stdlib/srand.h
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_SRC_STDLIB_SRAND_H
 
 #include "src/__support/macros/config.h"
-#include <stdlib.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index b33cbc5358d60d..d6e300754d4f9c 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -239,7 +239,7 @@ add_entrypoint_object(
   DEPENDS
     .memory_utils.inline_memcpy
     .string_utils
-    libc.include.stdlib
+    libc.hdr.stdlib_macros
     libc.src.errno.errno
     libc.include.llvm-libc-types.size_t
 )
diff --git a/libc/src/string/strdup.cpp b/libc/src/string/strdup.cpp
index 4e09c87099425b..4cf4173a27bf3f 100644
--- a/libc/src/string/strdup.cpp
+++ b/libc/src/string/strdup.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/string/strdup.h"
+#include "hdr/stdlib_macros.h"
 #include "src/__support/macros/config.h"
 #include "src/errno/libc_errno.h"
 #include "src/string/allocating_string_utils.h"
@@ -14,8 +15,6 @@
 
 #include "src/__support/common.h"
 
-#include <stdlib.h>
-
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(char *, strdup, (const char *src)) {
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 472438ca72e49e..05b6e02ad0c882 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -179,7 +179,6 @@ add_entrypoint_object(
   HDRS
     ../getcwd.h
   DEPENDS
-    libc.include.stdlib
     libc.include.unistd
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
diff --git a/libc/src/unistd/linux/getcwd.cpp b/libc/src/unistd/linux/getcwd.cpp
index a10c5004d0e061..1bb11a7c8e7ba2 100644
--- a/libc/src/unistd/linux/getcwd.cpp
+++ b/libc/src/unistd/linux/getcwd.cpp
@@ -15,7 +15,6 @@
 
 #include "src/errno/libc_errno.h"
 #include <linux/limits.h> // This is safe to include without any name pollution.
-#include <stdlib.h>
 #include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/__support/File/CMakeLists.txt b/libc/test/src/__support/File/CMakeLists.txt
index 9fa3b518421ccb..04205166bf5337 100644
--- a/libc/test/src/__support/File/CMakeLists.txt
+++ b/libc/test/src/__support/File/CMakeLists.txt
@@ -15,7 +15,7 @@ add_libc_test(
     LibcMemoryHelpers
   DEPENDS
     libc.include.stdio
-    libc.include.stdlib
+    libc.hdr.types.size_t
     libc.src.errno.errno 
     libc.src.__support.CPP.new
     libc.src.__support.File.file
diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp
index 5977ea7c8e0b57..b3c9f2ba49bced 100644
--- a/libc/test/src/__support/File/file_test.cpp
+++ b/libc/test/src/__support/File/file_test.cpp
@@ -12,7 +12,7 @@
 #include "test/UnitTest/MemoryMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include <stdlib.h>
+#include "hdr/types/size_t.h"
 
 using ModeFlags = LIBC_NAMESPACE::File::ModeFlags;
 using MemoryView = LIBC_NAMESPACE::testing::MemoryView;
diff --git a/libc/test/src/__support/str_to_float_comparison_test.cpp b/libc/test/src/__support/str_to_float_comparison_test.cpp
index 7641c594c3d3b8..7937167322f0cb 100644
--- a/libc/test/src/__support/str_to_float_comparison_test.cpp
+++ b/libc/test/src/__support/str_to_float_comparison_test.cpp
@@ -8,8 +8,6 @@
 
 // #include "src/__support/str_float_conv_utils.h"
 
-#include <stdlib.h>
-
 // #include "src/__support/FPUtil/FPBits.h"
 
 #include <cstdint>
diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index ec94f5aaaf9b62..e17f8d8c101a96 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -98,7 +98,7 @@ add_libc_test(
     fopencookie_test.cpp
   DEPENDS
     libc.include.stdio
-    libc.include.stdlib
+    libc.hdr.types.size_t
     libc.src.errno.errno
     libc.src.stdio.clearerr
     libc.src.stdio.fclose
diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp
index 016722aa11ab82..61ce2a207fa199 100644
--- a/libc/test/src/stdio/fopencookie_test.cpp
+++ b/libc/test/src/stdio/fopencookie_test.cpp
@@ -19,8 +19,8 @@
 #include "test/UnitTest/Test.h"
 
 #include "hdr/stdio_macros.h"
+#include "hdr/types/size_t.h"
 #include "src/errno/libc_errno.h"
-#include <stdlib.h>
 
 using MemoryView = LIBC_NAMESPACE::testing::MemoryView;
 
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index c68627a6687419..2683eefd032b76 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -259,7 +259,7 @@ add_libc_test(
   HDRS
     DivTest.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.div_t
     libc.src.stdlib.div
 )
 
@@ -272,7 +272,7 @@ add_libc_test(
   HDRS
     DivTest.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.ldiv_t
     libc.src.stdlib.ldiv
 )
 
@@ -285,7 +285,7 @@ add_libc_test(
   HDRS
     DivTest.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.lldiv_t
     libc.src.stdlib.lldiv
 )
 
@@ -296,7 +296,7 @@ add_libc_test(
   SRCS
     bsearch_test.cpp
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.size_t
     libc.src.stdlib.bsearch
 )
 
@@ -343,7 +343,7 @@ add_libc_test(
   SRCS
     qsort_r_test.cpp
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.types.size_t
     libc.src.stdlib.qsort_r
 )
 
@@ -354,7 +354,6 @@ add_libc_test(
   SRCS
     rand_test.cpp
   DEPENDS
-    libc.include.stdlib
     libc.src.stdlib.rand
     libc.src.stdlib.srand
 )
@@ -370,7 +369,6 @@ if(LLVM_LIBC_FULL_BUILD)
     SRCS
       _Exit_test.cpp
     DEPENDS
-      libc.include.stdlib
       libc.src.stdlib._Exit
       libc.src.stdlib.exit
   )
@@ -414,7 +412,6 @@ if(LLVM_LIBC_FULL_BUILD)
     SRCS
       abort_test.cpp
     DEPENDS
-      libc.include.stdlib
       libc.include.signal
       libc.src.stdlib.abort
       libc.src.stdlib._Exit
diff --git a/libc/test/src/stdlib/_Exit_test.cpp b/libc/test/src/stdlib/_Exit_test.cpp
index 9ca0fc51aab812..333277dc01dca0 100644
--- a/libc/test/src/stdlib/_Exit_test.cpp
+++ b/libc/test/src/stdlib/_Exit_test.cpp
@@ -10,8 +10,6 @@
 #include "src/stdlib/exit.h"
 #include "test/UnitTest/Test.h"
 
-#include <stdlib.h>
-
 TEST(LlvmLibcStdlib, _Exit) {
   EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(1); }, 1);
   EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(65); }, 65);
diff --git a/libc/test/src/stdlib/abort_test.cpp b/libc/test/src/stdlib/abort_test.cpp
index 766c8d5fbb21a1..8c5fd0c97abbc0 100644
--- a/libc/test/src/stdlib/abort_test.cpp
+++ b/libc/test/src/stdlib/abort_test.cpp
@@ -10,7 +10,6 @@
 #include "test/UnitTest/Test.h"
 
 #include <signal.h>
-#include <stdlib.h>
 
 TEST(LlvmLibcStdlib, abort) {
   // -1 matches against any signal, which is necessary for now until
diff --git a/libc/test/src/stdlib/bsearch_test.cpp b/libc/test/src/stdlib/bsearch_test.cpp
index 689145806ba8d3..4240adc953a860 100644
--- a/libc/test/src/stdli...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list