Skip to content

[libc] Remove the #include <stdlib.h> header #114453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 commits merged into from Nov 2, 2024
Merged

[libc] Remove the #include <stdlib.h> header #114453

5 commits merged into from Nov 2, 2024

Conversation

ghost
Copy link

@ghost ghost commented Oct 31, 2024

No description provided.

@llvmbot llvmbot added the libc label Oct 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-libc

Author: Job Henandez Lara (Jobhdez)

Changes

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 --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]

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

@ghost
Copy link
Author

ghost commented Nov 1, 2024

Thanks for the patch!

no problem!

@ghost ghost requested a review from michaelrj-google November 1, 2024 21:57
@ghost ghost merged commit 33bdb53 into llvm:main Nov 2, 2024
7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 2, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building libc at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7927

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...

CMake Error at /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/benchmarks/gpu/CMakeLists.txt:35 (add_dependencies):
  The dependency target "libc.benchmarks.gpu.src.math.sin_benchmark" of
  target "gpu-benchmark" does not exist.
Call Stack (most recent call first):
  /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/benchmarks/gpu/src/math/CMakeLists.txt:27 (add_benchmark)


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
FAILED: runtimes/runtimes-amdgcn-amd-amdhsa-stamps/runtimes-amdgcn-amd-amdhsa-configure /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-stamps/runtimes-amdgcn-amd-amdhsa-configure 
cd /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-bins && /usr/local/cmake/bin/cmake --no-warn-unused-cli -DCMAKE_C_COMPILER=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -DCMAKE_CXX_COMPILER=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ -DCMAKE_ASM_COMPILER=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -DCMAKE_LINKER=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/ld.lld -DCMAKE_AR=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-ar -DCMAKE_RANLIB=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-ranlib -DCMAKE_NM=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-nm -DCMAKE_OBJDUMP=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-objdump -DCMAKE_OBJCOPY=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-objcopy -DCMAKE_STRIP=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-strip -DCMAKE_READELF=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/llvm-readelf -DCMAKE_C_COMPILER_TARGET=amdgcn-amd-amdhsa -DCMAKE_CXX_COMPILER_TARGET=amdgcn-amd-amdhsa -DCMAKE_ASM_COMPILER_TARGET=amdgcn-amd-amdhsa -DCMAKE_INSTALL_PREFIX=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.inst -DLLVM_BINARY_DIR=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build -DLLVM_CONFIG_PATH=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/llvm-config -DLLVM_ENABLE_WERROR=OFF -DLLVM_HOST_TRIPLE=x86_64-unknown-linux-gnu -DLLVM_HAVE_LINK_VERSION_SCRIPT=1 -DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=OFF -DLLVM_USE_RELATIVE_PATHS_IN_FILES=OFF "-DLLVM_LIT_ARGS=-vv --show-unsupported --show-xfail -j 32" -DLLVM_SOURCE_PREFIX= -DPACKAGE_VERSION=20.0.0git -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCOMPILER_RT_BUILD_BUILTINS=OFF -DLLVM_INCLUDE_TESTS=ON -DLLVM_ENABLE_PROJECTS_USED=ON -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_CXX_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON -DLLVM_RUNTIMES_TARGET=amdgcn-amd-amdhsa -DHAVE_LLVM_LIT=ON -DCLANG_RESOURCE_DIR= -DLLVM_DEFAULT_TARGET_TRIPLE=amdgcn-amd-amdhsa -DLIBC_HDRGEN_EXE=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/libc-hdrgen -DLLVM_LIBC_GPU_BUILD=ON -DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/amdhsa-loader -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON "-DLLVM_ENABLE_RUNTIMES=openmp;compiler-rt;offload" -DLLVM_USE_LINKER= -DLIBC_GPU_TEST_ARCHITECTURE=gfx906 -DLLVM_ENABLE_RUNTIMES=libc -DLIBC_GPU_LOADER_EXECUTABLE=/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/amdhsa-loader -DLLVM_LIBC_FULL_BUILD=ON -GNinja -C/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/projects/runtimes-amdgcn-amd-amdhsa/tmp/runtimes-amdgcn-amd-amdhsa-cache-Release.cmake /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/llvm/runtimes/../../runtimes && /usr/local/cmake/bin/cmake -E touch /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-stamps//runtimes-amdgcn-amd-amdhsa-configure
ninja: build stopped: subcommand failed.

smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
ghost pushed a commit that referenced this pull request Nov 3, 2024
…the header `#include <stdlib.h> (#114690)

This finishes the work from
#114453 by adding proxy headers
for `malloc`, `realloc`, `free` and `aligned_alloc`.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
…the header `#include <stdlib.h> (llvm#114690)

This finishes the work from
llvm#114453 by adding proxy headers
for `malloc`, `realloc`, `free` and `aligned_alloc`.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants