[libc-commits] [libc] [libc] Add proxy headers to handle memory allocation associated with the header `#include <stdlib.h> (PR #114690)

Job Henandez Lara via libc-commits libc-commits at lists.llvm.org
Sun Nov 3 11:18:41 PST 2024


https://github.com/Jobhdez updated https://github.com/llvm/llvm-project/pull/114690

>From 8d779e0a0d1ad3fe0b9891be9bd7b92b9a772ba3 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 18:11:53 -0700
Subject: [PATCH 1/9] add memory allocation and free

---
 libc/hdr/CMakeLists.txt                       | 40 +++++++++++++++++++
 libc/hdr/aligned_alloc.h                      | 21 ++++++++++
 libc/hdr/free.h                               | 21 ++++++++++
 libc/hdr/malloc.h                             | 21 ++++++++++
 libc/hdr/realloc.h                            | 21 ++++++++++
 libc/src/__support/CMakeLists.txt             |  3 ++
 libc/src/__support/CPP/CMakeLists.txt         |  8 +++-
 libc/src/__support/CPP/new.cpp                |  2 +-
 libc/src/__support/CPP/new.h                  |  4 +-
 libc/src/__support/CPP/string.h               |  4 +-
 libc/src/__support/File/CMakeLists.txt        |  1 +
 libc/src/__support/File/file.cpp              |  1 +
 libc/src/__support/char_vector.h              |  5 ++-
 libc/src/stdio/printf_core/CMakeLists.txt     |  5 ++-
 .../stdio/printf_core/vasprintf_internal.h    |  5 ++-
 15 files changed, 153 insertions(+), 9 deletions(-)
 create mode 100644 libc/hdr/aligned_alloc.h
 create mode 100644 libc/hdr/free.h
 create mode 100644 libc/hdr/malloc.h
 create mode 100644 libc/hdr/realloc.h

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index c63eadab6f5d77..34dd60ae629b1e 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -23,6 +23,16 @@ function(add_proxy_header_library target_name)
   )
 endfunction()
 
+add_proxy_header_library(
+  aligned_alloc
+  HDRS
+    aligned_alloc.h
+  DEPENDS
+    .stdlib_overlay.h
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
 add_proxy_header_library(
   math_macros
   HDRS
@@ -152,6 +162,16 @@ add_proxy_header_library(
     libc.include.float
 )
 
+add_proxy_header_library(
+  free
+  HDRS
+    free.h
+  DEPENDS
+    .stdlib_overlay.h
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
 add_proxy_header_library(
   limits_macros
   HDRS
@@ -170,6 +190,26 @@ add_proxy_header_library(
     libc.include.link
 )
 
+add_proxy_header_library(
+  malloc
+  HDRS
+    malloc.h
+  DEPENDS
+    .stdlib_overlay.h
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
+add_proxy_header_library(
+  realloc
+  HDRS
+    realloc.h
+  DEPENDS
+    .stdlib_overlay.h
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
 add_proxy_header_library(
   sys_auxv_macros
   HDRS
diff --git a/libc/hdr/aligned_alloc.h b/libc/hdr/aligned_alloc.h
new file mode 100644
index 00000000000000..95518e5d1feed6
--- /dev/null
+++ b/libc/hdr/aligned_alloc.h
@@ -0,0 +1,21 @@
+//===-- Definition of the aligned_alloc.h proxy ---------------------------===//
+//
+// 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_ALIGNED_ALLOC_H
+#define LLVM_LIBC_HDR_ALIGNED_ALLOC_H
+
+#ifdef LIBC_FULL_BUILD
+extern "C" void* aligned_alloc(size_t, size_t);
+
+#else // Overlay mode
+
+#include "stdlib_overlay.h"
+
+#endif
+
+#endif
diff --git a/libc/hdr/free.h b/libc/hdr/free.h
new file mode 100644
index 00000000000000..43bf4e989f8a74
--- /dev/null
+++ b/libc/hdr/free.h
@@ -0,0 +1,21 @@
+//===-- Definition of the free.h proxy ------------------------------------===//
+//
+// 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_FREE_H
+#define LLVM_LIBC_HDR_FREE_H
+
+#ifdef LIBC_FULL_BUILD
+extern "C" void free(void*);
+
+#else // Overlay mode
+
+#include "stdlib_overlay.h"
+
+#endif
+
+#endif
diff --git a/libc/hdr/malloc.h b/libc/hdr/malloc.h
new file mode 100644
index 00000000000000..051dc743f6158b
--- /dev/null
+++ b/libc/hdr/malloc.h
@@ -0,0 +1,21 @@
+//===-- Definition of the malloc.h proxy ----------------------------------===//
+//
+// 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_MALLOC_H
+#define LLVM_LIBC_HDR_MALLOC_H
+
+#ifdef LIBC_FULL_BUILD
+extern "C" void* malloc(size_t);
+
+#else // Overlay mode
+
+#include "stdlib_overlay.h"
+
+#endif
+
+#endif
diff --git a/libc/hdr/realloc.h b/libc/hdr/realloc.h
new file mode 100644
index 00000000000000..7d045225bf3dbd
--- /dev/null
+++ b/libc/hdr/realloc.h
@@ -0,0 +1,21 @@
+//===-- Definition of the realloc.h proxy ---------------------------------===//
+//
+// 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_REALLOC_H
+#define LLVM_LIBC_HDR_REALLOC_H
+
+#ifdef LIBC_FULL_BUILD
+extern "C" void* realloc(void* ptr, size_t new_size);
+
+#else // Overlay mode
+
+#include "stdlib_overlay.h"
+
+#endif
+
+#endif
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 14a3acff8fae93..448cfa64c32157 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -236,6 +236,9 @@ add_header_library(
   HDRS
     char_vector.h
   DEPENDS
+    libc.hdr.free
+    libc.hdr.malloc
+    libc.hdr.realloc
     libc.src.__support.common
 )
 
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 774668be42e56d..cc2e48bb81abf1 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -80,7 +80,9 @@ add_header_library(
   HDRS
     string.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.free
+    libc.hdr.malloc
+    libc.hdr.realloc 
     .string_view
     libc.src.__support.common
     libc.src.__support.integer_to_string
@@ -199,7 +201,9 @@ add_object_library(
   HDRS
     new.h
   DEPENDS
-    libc.include.stdlib
+    libc.hdr.free
+    libc.hdr.malloc
+    libc.hdr.aligned_alloc 
     libc.src.__support.common
     libc.src.__support.macros.properties.os
 )
diff --git a/libc/src/__support/CPP/new.cpp b/libc/src/__support/CPP/new.cpp
index 8316329fb10b0b..969bd5b1231562 100644
--- a/libc/src/__support/CPP/new.cpp
+++ b/libc/src/__support/CPP/new.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "new.h"
-#include <stdlib.h> // For free, etc
+#include "hdr/free.h" // For free, etc
 
 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..677185798c7703 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -14,7 +14,9 @@
 #include "src/__support/macros/properties/os.h"
 
 #include <stddef.h> // For size_t
-#include <stdlib.h> // For malloc, free etc.
+#include "hdr/malloc.h"
+#include "hdr/free.h"
+#include "hdr/aligned_alloc.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/CPP/string.h b/libc/src/__support/CPP/string.h
index 64d4c276e84281..ba9eb2619816a5 100644
--- a/libc/src/__support/CPP/string.h
+++ b/libc/src/__support/CPP/string.h
@@ -17,7 +17,9 @@
 #include "src/string/string_utils.h" // string_length
 
 #include <stddef.h> // size_t
-#include <stdlib.h> // malloc, free
+#include "hdr/malloc.h"
+#include "hdr/free.h"
+#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace cpp {
diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt
index 1b390a12424d04..b04606ab27ae6b 100644
--- a/libc/src/__support/File/CMakeLists.txt
+++ b/libc/src/__support/File/CMakeLists.txt
@@ -18,6 +18,7 @@ add_object_library(
     libc.src.__support.error_or
     libc.hdr.types.off_t
     libc.hdr.stdio_macros
+    libc.hdr.realloc
 )
 
 add_object_library(
diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp
index 51811a27c1acd6..39abeed2a50a70 100644
--- a/libc/src/__support/File/file.cpp
+++ b/libc/src/__support/File/file.cpp
@@ -14,6 +14,7 @@
 #include "src/__support/CPP/span.h"
 #include "src/__support/macros/config.h"
 #include "src/errno/libc_errno.h" // For error macros
+#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index df109da5d81278..cfe1099795afc7 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -13,7 +13,10 @@
 #include "src/__support/macros/config.h"
 
 #include <stddef.h> // size_t
-#include <stdlib.h> // malloc, realloc, free
+
+#include "hdr/malloc.h"
+#include "hdr/free.h"
+#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 8172fda1e866ed..a192ea863be3f9 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -132,8 +132,9 @@ add_header_library(
     libc.src.__support.arg_list
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdlib.malloc
-    libc.src.stdlib.realloc
+    libc.hdr.malloc
+    libc.hdr.free
+    libc.hdr.realloc
 )
 
 if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index e3448eebd302b7..47b803fdf0626c 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -11,7 +11,10 @@
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
-#include <stdlib.h> // malloc, realloc, free
+//#include <stdlib.h> // malloc, realloc, free
+#include "hdr/free.h"
+#include "hdr/malloc.h"
+#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace printf_core {

>From cd6da88ed603c734bc13b14d71adff3fb8872425 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 18:12:11 -0700
Subject: [PATCH 2/9] fomat code

---
 libc/hdr/aligned_alloc.h                        | 2 +-
 libc/hdr/free.h                                 | 2 +-
 libc/hdr/malloc.h                               | 2 +-
 libc/hdr/realloc.h                              | 2 +-
 libc/src/__support/CPP/new.h                    | 6 +++---
 libc/src/__support/CPP/string.h                 | 4 ++--
 libc/src/__support/File/file.cpp                | 2 +-
 libc/src/__support/char_vector.h                | 2 +-
 libc/src/stdio/printf_core/vasprintf_internal.h | 2 +-
 9 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libc/hdr/aligned_alloc.h b/libc/hdr/aligned_alloc.h
index 95518e5d1feed6..11d0d0331bd81f 100644
--- a/libc/hdr/aligned_alloc.h
+++ b/libc/hdr/aligned_alloc.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_HDR_ALIGNED_ALLOC_H
 
 #ifdef LIBC_FULL_BUILD
-extern "C" void* aligned_alloc(size_t, size_t);
+extern "C" void *aligned_alloc(size_t, size_t);
 
 #else // Overlay mode
 
diff --git a/libc/hdr/free.h b/libc/hdr/free.h
index 43bf4e989f8a74..f40593ff96aeca 100644
--- a/libc/hdr/free.h
+++ b/libc/hdr/free.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_HDR_FREE_H
 
 #ifdef LIBC_FULL_BUILD
-extern "C" void free(void*);
+extern "C" void free(void *);
 
 #else // Overlay mode
 
diff --git a/libc/hdr/malloc.h b/libc/hdr/malloc.h
index 051dc743f6158b..be002440cd25bf 100644
--- a/libc/hdr/malloc.h
+++ b/libc/hdr/malloc.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_HDR_MALLOC_H
 
 #ifdef LIBC_FULL_BUILD
-extern "C" void* malloc(size_t);
+extern "C" void *malloc(size_t);
 
 #else // Overlay mode
 
diff --git a/libc/hdr/realloc.h b/libc/hdr/realloc.h
index 7d045225bf3dbd..140d175d5462b7 100644
--- a/libc/hdr/realloc.h
+++ b/libc/hdr/realloc.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_HDR_REALLOC_H
 
 #ifdef LIBC_FULL_BUILD
-extern "C" void* realloc(void* ptr, size_t new_size);
+extern "C" void *realloc(void *ptr, size_t new_size);
 
 #else // Overlay mode
 
diff --git a/libc/src/__support/CPP/new.h b/libc/src/__support/CPP/new.h
index 677185798c7703..71e9c1e23c27df 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -13,10 +13,10 @@
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/os.h"
 
-#include <stddef.h> // For size_t
-#include "hdr/malloc.h"
-#include "hdr/free.h"
 #include "hdr/aligned_alloc.h"
+#include "hdr/free.h"
+#include "hdr/malloc.h"
+#include <stddef.h> // For size_t
 
 // 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/CPP/string.h b/libc/src/__support/CPP/string.h
index ba9eb2619816a5..ea3096b6ca68c4 100644
--- a/libc/src/__support/CPP/string.h
+++ b/libc/src/__support/CPP/string.h
@@ -16,10 +16,10 @@
 #include "src/string/memory_utils/inline_memset.h"
 #include "src/string/string_utils.h" // string_length
 
-#include <stddef.h> // size_t
-#include "hdr/malloc.h"
 #include "hdr/free.h"
+#include "hdr/malloc.h"
 #include "hdr/realloc.h"
+#include <stddef.h> // size_t
 
 namespace LIBC_NAMESPACE_DECL {
 namespace cpp {
diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp
index 39abeed2a50a70..7528780df2b0bc 100644
--- a/libc/src/__support/File/file.cpp
+++ b/libc/src/__support/File/file.cpp
@@ -8,13 +8,13 @@
 
 #include "file.h"
 
+#include "hdr/realloc.h"
 #include "hdr/stdio_macros.h"
 #include "hdr/types/off_t.h"
 #include "src/__support/CPP/new.h"
 #include "src/__support/CPP/span.h"
 #include "src/__support/macros/config.h"
 #include "src/errno/libc_errno.h" // For error macros
-#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index cfe1099795afc7..e44d037a9a042f 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -14,8 +14,8 @@
 
 #include <stddef.h> // size_t
 
-#include "hdr/malloc.h"
 #include "hdr/free.h"
+#include "hdr/malloc.h"
 #include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index 47b803fdf0626c..26cf7b98053de4 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -11,7 +11,7 @@
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
-//#include <stdlib.h> // malloc, realloc, free
+// #include <stdlib.h> // malloc, realloc, free
 #include "hdr/free.h"
 #include "hdr/malloc.h"
 #include "hdr/realloc.h"

>From 1196fb31de3b23eac8c1e12269ce7537d110e9d5 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 18:32:37 -0700
Subject: [PATCH 3/9] address review

---
 libc/src/__support/CPP/new.cpp                  | 2 +-
 libc/src/__support/CPP/new.h                    | 2 +-
 libc/src/__support/CPP/string.h                 | 2 +-
 libc/src/__support/char_vector.h                | 5 ++---
 libc/src/stdio/printf_core/vasprintf_internal.h | 1 -
 5 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/libc/src/__support/CPP/new.cpp b/libc/src/__support/CPP/new.cpp
index 969bd5b1231562..28ffe5ee1966d2 100644
--- a/libc/src/__support/CPP/new.cpp
+++ b/libc/src/__support/CPP/new.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "new.h"
-#include "hdr/free.h" // For free, etc
+#include "hdr/free.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 71e9c1e23c27df..2a1097b8c4d997 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -12,10 +12,10 @@
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/os.h"
-
 #include "hdr/aligned_alloc.h"
 #include "hdr/free.h"
 #include "hdr/malloc.h"
+
 #include <stddef.h> // For size_t
 
 // Defining members in the std namespace is not preferred. But, we do it here
diff --git a/libc/src/__support/CPP/string.h b/libc/src/__support/CPP/string.h
index ea3096b6ca68c4..d82725769b0fdf 100644
--- a/libc/src/__support/CPP/string.h
+++ b/libc/src/__support/CPP/string.h
@@ -15,10 +15,10 @@
 #include "src/string/memory_utils/inline_memcpy.h"
 #include "src/string/memory_utils/inline_memset.h"
 #include "src/string/string_utils.h" // string_length
-
 #include "hdr/free.h"
 #include "hdr/malloc.h"
 #include "hdr/realloc.h"
+
 #include <stddef.h> // size_t
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index e44d037a9a042f..96a43b991fff3a 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -11,13 +11,12 @@
 
 #include "src/__support/common.h" // LIBC_INLINE
 #include "src/__support/macros/config.h"
-
-#include <stddef.h> // size_t
-
 #include "hdr/free.h"
 #include "hdr/malloc.h"
 #include "hdr/realloc.h"
 
+#include <stddef.h> // size_t
+
 namespace LIBC_NAMESPACE_DECL {
 
 // This is very simple alternate of the std::string class. There is no
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index 26cf7b98053de4..c43a6910eee8ce 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -11,7 +11,6 @@
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
-// #include <stdlib.h> // malloc, realloc, free
 #include "hdr/free.h"
 #include "hdr/malloc.h"
 #include "hdr/realloc.h"

>From 4b40e74852440927214c5dc4749abea344f1dc7a Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 18:32:51 -0700
Subject: [PATCH 4/9] format code

---
 libc/src/__support/CPP/new.h                    | 6 +++---
 libc/src/__support/CPP/string.h                 | 6 +++---
 libc/src/__support/char_vector.h                | 4 ++--
 libc/src/stdio/printf_core/vasprintf_internal.h | 6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libc/src/__support/CPP/new.h b/libc/src/__support/CPP/new.h
index 2a1097b8c4d997..2a3092acf3d555 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
 
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/os.h"
 #include "hdr/aligned_alloc.h"
 #include "hdr/free.h"
 #include "hdr/malloc.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/os.h"
 
 #include <stddef.h> // For size_t
 
diff --git a/libc/src/__support/CPP/string.h b/libc/src/__support/CPP/string.h
index d82725769b0fdf..b634756faeb2ee 100644
--- a/libc/src/__support/CPP/string.h
+++ b/libc/src/__support/CPP/string.h
@@ -9,15 +9,15 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
 
+#include "hdr/free.h"
+#include "hdr/malloc.h"
+#include "hdr/realloc.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/integer_to_string.h" // IntegerToString
 #include "src/__support/macros/config.h"
 #include "src/string/memory_utils/inline_memcpy.h"
 #include "src/string/memory_utils/inline_memset.h"
 #include "src/string/string_utils.h" // string_length
-#include "hdr/free.h"
-#include "hdr/malloc.h"
-#include "hdr/realloc.h"
 
 #include <stddef.h> // size_t
 
diff --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index 96a43b991fff3a..858e0519fb8d0a 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -9,11 +9,11 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
 #define LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
 
-#include "src/__support/common.h" // LIBC_INLINE
-#include "src/__support/macros/config.h"
 #include "hdr/free.h"
 #include "hdr/malloc.h"
 #include "hdr/realloc.h"
+#include "src/__support/common.h" // LIBC_INLINE
+#include "src/__support/macros/config.h"
 
 #include <stddef.h> // size_t
 
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index c43a6910eee8ce..1672a27e0ec479 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/free.h"
+#include "hdr/malloc.h"
+#include "hdr/realloc.h"
 #include "src/__support/arg_list.h"
 #include "src/stdio/printf.h"
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
-#include "hdr/free.h"
-#include "hdr/malloc.h"
-#include "hdr/realloc.h"
 
 namespace LIBC_NAMESPACE_DECL {
 namespace printf_core {

>From a9f959f823dfdd2517dd794fca860e501ccc09e9 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 18:56:46 -0700
Subject: [PATCH 5/9] address review

---
 libc/hdr/CMakeLists.txt                   | 10 ++++++----
 libc/src/__support/CPP/CMakeLists.txt     |  2 +-
 libc/src/stdio/printf_core/CMakeLists.txt |  6 +++---
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 34dd60ae629b1e..fb9f09eb976d4b 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -28,7 +28,7 @@ add_proxy_header_library(
   HDRS
     aligned_alloc.h
   DEPENDS
-    .stdlib_overlay.h
+    .stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
 )
@@ -91,6 +91,8 @@ add_proxy_header_library(
     libc.include.signal
 )
 
+add_header_library(stdlib_overlay HDRS stdlib_overlay.h)
+
 add_proxy_header_library(
   stdlib_macros
   HDRS
@@ -167,7 +169,7 @@ add_proxy_header_library(
   HDRS
     free.h
   DEPENDS
-    .stdlib_overlay.h
+    .stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
 )
@@ -195,7 +197,7 @@ add_proxy_header_library(
   HDRS
     malloc.h
   DEPENDS
-    .stdlib_overlay.h
+    .stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
 )
@@ -205,7 +207,7 @@ add_proxy_header_library(
   HDRS
     realloc.h
   DEPENDS
-    .stdlib_overlay.h
+    .stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
 )
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index cc2e48bb81abf1..6acf61bcf78f66 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -80,10 +80,10 @@ add_header_library(
   HDRS
     string.h
   DEPENDS
+    .string_view
     libc.hdr.free
     libc.hdr.malloc
     libc.hdr.realloc 
-    .string_view
     libc.src.__support.common
     libc.src.__support.integer_to_string
     libc.src.string.memory_utils.inline_memcpy
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index a192ea863be3f9..7eb6da37a466e0 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -129,12 +129,12 @@ add_header_library(
   HDRS
     vasprintf_internal.h
   DEPENDS
-    libc.src.__support.arg_list
-    libc.src.stdio.printf_core.printf_main
-    libc.src.stdio.printf_core.writer
     libc.hdr.malloc
     libc.hdr.free
     libc.hdr.realloc
+    libc.src.__support.arg_list
+    libc.src.stdio.printf_core.printf_main
+    libc.src.stdio.printf_core.writer
 )
 
 if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)

>From 48c4deb4a923f648f9cdd1606f7eb30417383fc1 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sat, 2 Nov 2024 19:01:45 -0700
Subject: [PATCH 6/9] address review

---
 libc/hdr/CMakeLists.txt | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index fb9f09eb976d4b..8b086149c282cd 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -23,16 +23,6 @@ function(add_proxy_header_library target_name)
   )
 endfunction()
 
-add_proxy_header_library(
-  aligned_alloc
-  HDRS
-    aligned_alloc.h
-  DEPENDS
-    .stdlib_overlay
-  FULL_BUILD_DEPENDS
-    libc.include.stdlib
-)
-
 add_proxy_header_library(
   math_macros
   HDRS
@@ -104,6 +94,16 @@ add_proxy_header_library(
     libc.include.llvm-libc-macros.stdlib_macros
 )
 
+add_proxy_header_library(
+  aligned_alloc
+  HDRS
+    aligned_alloc.h
+  DEPENDS
+    .stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
 add_header_library(stdio_overlay HDRS stdio_overlay.h)
 
 add_proxy_header_library(

>From 3b93df7434921520906c33d6be8c260c358181f1 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sun, 3 Nov 2024 09:24:50 -0800
Subject: [PATCH 7/9] address review

---
 libc/hdr/CMakeLists.txt                       | 41 +------------------
 libc/hdr/func/CMakeLists.txt                  | 40 ++++++++++++++++++
 libc/hdr/{ => func}/aligned_alloc.h           |  3 +-
 libc/hdr/{ => func}/free.h                    |  3 +-
 libc/hdr/{ => func}/malloc.h                  |  3 +-
 libc/hdr/{ => func}/realloc.h                 |  3 +-
 libc/src/__support/CMakeLists.txt             |  6 +--
 libc/src/__support/CPP/CMakeLists.txt         | 12 +++---
 libc/src/__support/CPP/new.cpp                |  2 +-
 libc/src/__support/CPP/new.h                  |  6 +--
 libc/src/__support/CPP/string.h               |  6 +--
 libc/src/__support/File/CMakeLists.txt        |  2 +-
 libc/src/__support/File/file.cpp              |  2 +-
 libc/src/__support/char_vector.h              |  6 +--
 libc/src/stdio/printf_core/CMakeLists.txt     |  6 +--
 .../stdio/printf_core/vasprintf_internal.h    |  6 +--
 16 files changed, 76 insertions(+), 71 deletions(-)
 create mode 100644 libc/hdr/func/CMakeLists.txt
 rename libc/hdr/{ => func}/aligned_alloc.h (90%)
 rename libc/hdr/{ => func}/free.h (89%)
 rename libc/hdr/{ => func}/malloc.h (89%)
 rename libc/hdr/{ => func}/realloc.h (89%)

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 8b086149c282cd..93da271f5e040b 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -94,16 +94,6 @@ add_proxy_header_library(
     libc.include.llvm-libc-macros.stdlib_macros
 )
 
-add_proxy_header_library(
-  aligned_alloc
-  HDRS
-    aligned_alloc.h
-  DEPENDS
-    .stdlib_overlay
-  FULL_BUILD_DEPENDS
-    libc.include.stdlib
-)
-
 add_header_library(stdio_overlay HDRS stdio_overlay.h)
 
 add_proxy_header_library(
@@ -164,16 +154,6 @@ add_proxy_header_library(
     libc.include.float
 )
 
-add_proxy_header_library(
-  free
-  HDRS
-    free.h
-  DEPENDS
-    .stdlib_overlay
-  FULL_BUILD_DEPENDS
-    libc.include.stdlib
-)
-
 add_proxy_header_library(
   limits_macros
   HDRS
@@ -192,26 +172,6 @@ add_proxy_header_library(
     libc.include.link
 )
 
-add_proxy_header_library(
-  malloc
-  HDRS
-    malloc.h
-  DEPENDS
-    .stdlib_overlay
-  FULL_BUILD_DEPENDS
-    libc.include.stdlib
-)
-
-add_proxy_header_library(
-  realloc
-  HDRS
-    realloc.h
-  DEPENDS
-    .stdlib_overlay
-  FULL_BUILD_DEPENDS
-    libc.include.stdlib
-)
-
 add_proxy_header_library(
   sys_auxv_macros
   HDRS
@@ -235,3 +195,4 @@ add_proxy_header_library(
 )
 
 add_subdirectory(types)
+add_subdirectory(func)
diff --git a/libc/hdr/func/CMakeLists.txt b/libc/hdr/func/CMakeLists.txt
new file mode 100644
index 00000000000000..1fc47c4f66dece
--- /dev/null
+++ b/libc/hdr/func/CMakeLists.txt
@@ -0,0 +1,40 @@
+add_proxy_header_library(
+  aligned_alloc
+  HDRS
+    aligned_alloc.h
+  DEPENDS
+    libc.hdr.stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+    libc.hdr.types.size_t
+)
+
+add_proxy_header_library(
+  malloc
+  HDRS
+    malloc.h
+  DEPENDS
+    libc.hdr.stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
+add_proxy_header_library(
+  realloc
+  HDRS
+    realloc.h
+  DEPENDS
+    libc.hdr.stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
+
+add_proxy_header_library(
+  free
+  HDRS
+    free.h
+  DEPENDS
+    libc.hdr.stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
diff --git a/libc/hdr/aligned_alloc.h b/libc/hdr/func/aligned_alloc.h
similarity index 90%
rename from libc/hdr/aligned_alloc.h
rename to libc/hdr/func/aligned_alloc.h
index 11d0d0331bd81f..22566569061393 100644
--- a/libc/hdr/aligned_alloc.h
+++ b/libc/hdr/func/aligned_alloc.h
@@ -10,11 +10,12 @@
 #define LLVM_LIBC_HDR_ALIGNED_ALLOC_H
 
 #ifdef LIBC_FULL_BUILD
+#include "hdr/types/size_t.h"
 extern "C" void *aligned_alloc(size_t, size_t);
 
 #else // Overlay mode
 
-#include "stdlib_overlay.h"
+#include "hdr/stdlib_overlay.h"
 
 #endif
 
diff --git a/libc/hdr/free.h b/libc/hdr/func/free.h
similarity index 89%
rename from libc/hdr/free.h
rename to libc/hdr/func/free.h
index f40593ff96aeca..23ae85286f65fa 100644
--- a/libc/hdr/free.h
+++ b/libc/hdr/func/free.h
@@ -10,11 +10,12 @@
 #define LLVM_LIBC_HDR_FREE_H
 
 #ifdef LIBC_FULL_BUILD
+#include "hdr/types/size_t.h"
 extern "C" void free(void *);
 
 #else // Overlay mode
 
-#include "stdlib_overlay.h"
+#include "hdr/stdlib_overlay.h"
 
 #endif
 
diff --git a/libc/hdr/malloc.h b/libc/hdr/func/malloc.h
similarity index 89%
rename from libc/hdr/malloc.h
rename to libc/hdr/func/malloc.h
index be002440cd25bf..177e819fc820e2 100644
--- a/libc/hdr/malloc.h
+++ b/libc/hdr/func/malloc.h
@@ -10,11 +10,12 @@
 #define LLVM_LIBC_HDR_MALLOC_H
 
 #ifdef LIBC_FULL_BUILD
+#include "hdr/types/size_t.h"
 extern "C" void *malloc(size_t);
 
 #else // Overlay mode
 
-#include "stdlib_overlay.h"
+#include "hdr/stdlib_overlay.h"
 
 #endif
 
diff --git a/libc/hdr/realloc.h b/libc/hdr/func/realloc.h
similarity index 89%
rename from libc/hdr/realloc.h
rename to libc/hdr/func/realloc.h
index 140d175d5462b7..8c268b57a6a1c6 100644
--- a/libc/hdr/realloc.h
+++ b/libc/hdr/func/realloc.h
@@ -10,11 +10,12 @@
 #define LLVM_LIBC_HDR_REALLOC_H
 
 #ifdef LIBC_FULL_BUILD
+#include "hdr/types/size_t.h"
 extern "C" void *realloc(void *ptr, size_t new_size);
 
 #else // Overlay mode
 
-#include "stdlib_overlay.h"
+#include "hdr/stdlib_overlay.h"
 
 #endif
 
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 448cfa64c32157..763ad372a4aa0f 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -236,9 +236,9 @@ add_header_library(
   HDRS
     char_vector.h
   DEPENDS
-    libc.hdr.free
-    libc.hdr.malloc
-    libc.hdr.realloc
+    libc.hdr.func.free
+    libc.hdr.func.malloc
+    libc.hdr.func.realloc
     libc.src.__support.common
 )
 
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 6acf61bcf78f66..15fad9de0ed6d2 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -81,9 +81,9 @@ add_header_library(
     string.h
   DEPENDS
     .string_view
-    libc.hdr.free
-    libc.hdr.malloc
-    libc.hdr.realloc 
+    libc.hdr.func.free
+    libc.hdr.func.malloc
+    libc.hdr.func.realloc 
     libc.src.__support.common
     libc.src.__support.integer_to_string
     libc.src.string.memory_utils.inline_memcpy
@@ -201,9 +201,9 @@ add_object_library(
   HDRS
     new.h
   DEPENDS
-    libc.hdr.free
-    libc.hdr.malloc
-    libc.hdr.aligned_alloc 
+    libc.hdr.func.free
+    libc.hdr.func.malloc
+    libc.hdr.func.aligned_alloc 
     libc.src.__support.common
     libc.src.__support.macros.properties.os
 )
diff --git a/libc/src/__support/CPP/new.cpp b/libc/src/__support/CPP/new.cpp
index 28ffe5ee1966d2..65f80de3734851 100644
--- a/libc/src/__support/CPP/new.cpp
+++ b/libc/src/__support/CPP/new.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "new.h"
-#include "hdr/free.h"
+#include "hdr/func/free.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 2a3092acf3d555..8694d9c4755075 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
 
-#include "hdr/aligned_alloc.h"
-#include "hdr/free.h"
-#include "hdr/malloc.h"
+#include "hdr/func/aligned_alloc.h"
+#include "hdr/func/free.h"
+#include "hdr/func/malloc.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/os.h"
diff --git a/libc/src/__support/CPP/string.h b/libc/src/__support/CPP/string.h
index b634756faeb2ee..dbc0ae04e5e6ff 100644
--- a/libc/src/__support/CPP/string.h
+++ b/libc/src/__support/CPP/string.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
 #define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
 
-#include "hdr/free.h"
-#include "hdr/malloc.h"
-#include "hdr/realloc.h"
+#include "hdr/func/free.h"
+#include "hdr/func/malloc.h"
+#include "hdr/func/realloc.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/integer_to_string.h" // IntegerToString
 #include "src/__support/macros/config.h"
diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt
index b04606ab27ae6b..5a4af5e70e2894 100644
--- a/libc/src/__support/File/CMakeLists.txt
+++ b/libc/src/__support/File/CMakeLists.txt
@@ -18,7 +18,7 @@ add_object_library(
     libc.src.__support.error_or
     libc.hdr.types.off_t
     libc.hdr.stdio_macros
-    libc.hdr.realloc
+    libc.hdr.func.realloc
 )
 
 add_object_library(
diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp
index 7528780df2b0bc..972249fef96bcf 100644
--- a/libc/src/__support/File/file.cpp
+++ b/libc/src/__support/File/file.cpp
@@ -8,7 +8,7 @@
 
 #include "file.h"
 
-#include "hdr/realloc.h"
+#include "hdr/func/realloc.h"
 #include "hdr/stdio_macros.h"
 #include "hdr/types/off_t.h"
 #include "src/__support/CPP/new.h"
diff --git a/libc/src/__support/char_vector.h b/libc/src/__support/char_vector.h
index 858e0519fb8d0a..d0837a8af3f467 100644
--- a/libc/src/__support/char_vector.h
+++ b/libc/src/__support/char_vector.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
 #define LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
 
-#include "hdr/free.h"
-#include "hdr/malloc.h"
-#include "hdr/realloc.h"
+#include "hdr/func/free.h"
+#include "hdr/func/malloc.h"
+#include "hdr/func/realloc.h"
 #include "src/__support/common.h" // LIBC_INLINE
 #include "src/__support/macros/config.h"
 
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 7eb6da37a466e0..9eaffe2f7ed621 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -129,9 +129,9 @@ add_header_library(
   HDRS
     vasprintf_internal.h
   DEPENDS
-    libc.hdr.malloc
-    libc.hdr.free
-    libc.hdr.realloc
+    libc.hdr.func.malloc
+    libc.hdr.func.free
+    libc.hdr.func.realloc
     libc.src.__support.arg_list
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index 1672a27e0ec479..0e446f856e4381 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "hdr/free.h"
-#include "hdr/malloc.h"
-#include "hdr/realloc.h"
+#include "hdr/func/free.h"
+#include "hdr/func/malloc.h"
+#include "hdr/func/realloc.h"
 #include "src/__support/arg_list.h"
 #include "src/stdio/printf.h"
 #include "src/stdio/printf_core/core_structs.h"

>From 87da5a22d04b963e0cce638a2c5f92418225cf18 Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sun, 3 Nov 2024 10:14:34 -0800
Subject: [PATCH 8/9] address review

---
 libc/hdr/func/CMakeLists.txt                | 10 ++++++++++
 libc/hdr/func/_Exit.h                       | 21 +++++++++++++++++++++
 libc/hdr/func/aligned_alloc.h               |  4 ++--
 libc/hdr/func/free.h                        |  4 ++--
 libc/hdr/func/malloc.h                      |  4 ++--
 libc/hdr/func/realloc.h                     |  4 ++--
 libc/test/src/stdlib/CMakeLists.txt         |  2 ++
 libc/test/src/stdlib/at_quick_exit_test.cpp |  1 +
 libc/test/src/stdlib/atexit_test.cpp        |  1 +
 9 files changed, 43 insertions(+), 8 deletions(-)
 create mode 100644 libc/hdr/func/_Exit.h

diff --git a/libc/hdr/func/CMakeLists.txt b/libc/hdr/func/CMakeLists.txt
index 1fc47c4f66dece..fa4966d0557aaf 100644
--- a/libc/hdr/func/CMakeLists.txt
+++ b/libc/hdr/func/CMakeLists.txt
@@ -38,3 +38,13 @@ add_proxy_header_library(
   FULL_BUILD_DEPENDS
     libc.include.stdlib
 )
+
+add_proxy_header_library(
+  _Exit
+  HDRS
+    _Exit.h
+  DEPENDS
+    libc.hdr.stdlib_overlay
+  FULL_BUILD_DEPENDS
+    libc.include.stdlib
+)
diff --git a/libc/hdr/func/_Exit.h b/libc/hdr/func/_Exit.h
new file mode 100644
index 00000000000000..575b0426e508c6
--- /dev/null
+++ b/libc/hdr/func/_Exit.h
@@ -0,0 +1,21 @@
+//===-- Definition of the _Exit proxy -------------------------------------===//
+//
+// 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_FUNC_EXIT_H
+#define LLVM_LIBC_HDR_FUNC_EXIT_H
+
+#ifdef LIBC_FULL_BUILD
+extern "C" void _Exit(int);
+
+#else // Overlay mode
+
+#include "hdr/stdlib_overlay.h"
+
+#endif
+
+#endif // LLVM_LIBC_HDR_EXIT_H
diff --git a/libc/hdr/func/aligned_alloc.h b/libc/hdr/func/aligned_alloc.h
index 22566569061393..b3436dfee1f233 100644
--- a/libc/hdr/func/aligned_alloc.h
+++ b/libc/hdr/func/aligned_alloc.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_HDR_ALIGNED_ALLOC_H
-#define LLVM_LIBC_HDR_ALIGNED_ALLOC_H
+#ifndef LLVM_LIBC_HDR_FUNC_ALIGNED_ALLOC_H
+#define LLVM_LIBC_HDR_FUNC_ALIGNED_ALLOC_H
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
diff --git a/libc/hdr/func/free.h b/libc/hdr/func/free.h
index 23ae85286f65fa..086e257671a43a 100644
--- a/libc/hdr/func/free.h
+++ b/libc/hdr/func/free.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_HDR_FREE_H
-#define LLVM_LIBC_HDR_FREE_H
+#ifndef LLVM_LIBC_HDR_FUNC_FREE_H
+#define LLVM_LIBC_HDR_FUNC_FREE_H
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
diff --git a/libc/hdr/func/malloc.h b/libc/hdr/func/malloc.h
index 177e819fc820e2..b395f41f2bce26 100644
--- a/libc/hdr/func/malloc.h
+++ b/libc/hdr/func/malloc.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_HDR_MALLOC_H
-#define LLVM_LIBC_HDR_MALLOC_H
+#ifndef LLVM_LIBC_HDR_FUNC_MALLOC_H
+#define LLVM_LIBC_HDR_FUNC_MALLOC_H
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
diff --git a/libc/hdr/func/realloc.h b/libc/hdr/func/realloc.h
index 8c268b57a6a1c6..0096045e8330b5 100644
--- a/libc/hdr/func/realloc.h
+++ b/libc/hdr/func/realloc.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_HDR_REALLOC_H
-#define LLVM_LIBC_HDR_REALLOC_H
+#ifndef LLVM_LIBC_HDR_FUNC_REALLOC_H
+#define LLVM_LIBC_HDR_FUNC_REALLOC_H
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 2683eefd032b76..3d5c4e2bedd461 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -387,6 +387,7 @@ if(LLVM_LIBC_FULL_BUILD)
       libc.src.stdlib.exit
       libc.src.stdlib.atexit
       libc.src.__support.CPP.array
+      libc.hdr.func._Exit 
   )
 
   add_libc_test(
@@ -401,6 +402,7 @@ if(LLVM_LIBC_FULL_BUILD)
       libc.src.stdlib.quick_exit
       libc.src.stdlib.at_quick_exit
       libc.src.__support.CPP.array
+      libc.hdr.func._Exit 
   )
 
   add_libc_test(
diff --git a/libc/test/src/stdlib/at_quick_exit_test.cpp b/libc/test/src/stdlib/at_quick_exit_test.cpp
index e0a258d9fb2d96..8049fe58d29bd3 100644
--- a/libc/test/src/stdlib/at_quick_exit_test.cpp
+++ b/libc/test/src/stdlib/at_quick_exit_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/func/_Exit.h"
 #include "src/__support/CPP/array.h"
 #include "src/__support/CPP/utility.h"
 #include "src/stdlib/at_quick_exit.h"
diff --git a/libc/test/src/stdlib/atexit_test.cpp b/libc/test/src/stdlib/atexit_test.cpp
index 8a785ccb8cce20..9e19423f730860 100644
--- a/libc/test/src/stdlib/atexit_test.cpp
+++ b/libc/test/src/stdlib/atexit_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/func/_Exit.h"
 #include "src/__support/CPP/array.h"
 #include "src/__support/CPP/utility.h"
 #include "src/stdlib/atexit.h"

>From d96acb140da1b26da1de94a14c33e6af8e2f306f Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Sun, 3 Nov 2024 11:18:12 -0800
Subject: [PATCH 9/9] address review

---
 libc/hdr/func/CMakeLists.txt        | 2 ++
 libc/hdr/func/free.h                | 1 -
 libc/test/src/stdlib/CMakeLists.txt | 5 ++---
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libc/hdr/func/CMakeLists.txt b/libc/hdr/func/CMakeLists.txt
index fa4966d0557aaf..714b7ec9b48809 100644
--- a/libc/hdr/func/CMakeLists.txt
+++ b/libc/hdr/func/CMakeLists.txt
@@ -17,6 +17,7 @@ add_proxy_header_library(
     libc.hdr.stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
+    libc.hdr.types.size_t
 )
 
 add_proxy_header_library(
@@ -27,6 +28,7 @@ add_proxy_header_library(
     libc.hdr.stdlib_overlay
   FULL_BUILD_DEPENDS
     libc.include.stdlib
+    libc.hdr.types.size_t
 )
 
 add_proxy_header_library(
diff --git a/libc/hdr/func/free.h b/libc/hdr/func/free.h
index 086e257671a43a..b1190a777da327 100644
--- a/libc/hdr/func/free.h
+++ b/libc/hdr/func/free.h
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_HDR_FUNC_FREE_H
 
 #ifdef LIBC_FULL_BUILD
-#include "hdr/types/size_t.h"
 extern "C" void free(void *);
 
 #else // Overlay mode
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 3d5c4e2bedd461..4ea894cf48724d 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -382,12 +382,11 @@ if(LLVM_LIBC_FULL_BUILD)
     SRCS
       atexit_test.cpp
     DEPENDS
-      libc.include.stdlib
+      libc.hdr.func._Exit 
       libc.src.stdlib._Exit
       libc.src.stdlib.exit
       libc.src.stdlib.atexit
       libc.src.__support.CPP.array
-      libc.hdr.func._Exit 
   )
 
   add_libc_test(
@@ -399,10 +398,10 @@ if(LLVM_LIBC_FULL_BUILD)
     SRCS
       at_quick_exit_test.cpp
     DEPENDS
+      libc.hdr.func._Exit 
       libc.src.stdlib.quick_exit
       libc.src.stdlib.at_quick_exit
       libc.src.__support.CPP.array
-      libc.hdr.func._Exit 
   )
 
   add_libc_test(



More information about the libc-commits mailing list