[libc-commits] [libc] [libc] Enable arpa/inet.h entrypoints in overlay mode (PR #198270)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon May 18 03:35:55 PDT 2026


https://github.com/labath created https://github.com/llvm/llvm-project/pull/198270

Two of these depend on in_addr_t and struct in_addr, but these are types whose layout is defined by POSIX and OS ABIs, and they are simpler than struct sockaddr_in, which we enabled in #195035.

>From deaf0ef1426d1760e8b145b1b919c5e0ad65de50 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Fri, 15 May 2026 16:07:59 +0000
Subject: [PATCH] [libc] Enable arpa/inet.h entrypoints in overlay mode

Two of these depend on the in_addr_t and struct in_addr, but these are
types whose layout is defined by POSIX and OS ABIs, and they are simpler
than struct sockaddr_in, which we enabled in #195035.
---
 libc/config/linux/x86_64/entrypoints.txt | 16 +++++++-------
 libc/hdr/CMakeLists.txt                  |  9 ++++++++
 libc/hdr/netinet_in_macros.h             | 27 ++++++++++++++++++++++++
 libc/hdr/types/CMakeLists.txt            | 18 ++++++++++++++++
 libc/hdr/types/in_addr_t.h               | 26 +++++++++++++++++++++++
 libc/hdr/types/struct_in_addr.h          | 26 +++++++++++++++++++++++
 libc/src/CMakeLists.txt                  |  2 +-
 libc/src/arpa/inet/CMakeLists.txt        |  8 +++----
 libc/src/arpa/inet/inet_addr.cpp         |  6 +++---
 libc/src/arpa/inet/inet_addr.h           |  2 +-
 libc/src/arpa/inet/inet_aton.h           |  2 +-
 libc/test/src/CMakeLists.txt             |  2 +-
 12 files changed, 125 insertions(+), 19 deletions(-)
 create mode 100644 libc/hdr/netinet_in_macros.h
 create mode 100644 libc/hdr/types/in_addr_t.h
 create mode 100644 libc/hdr/types/struct_in_addr.h

diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index c91cb55b9414b..29f698e45cbcc 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1,4 +1,12 @@
 set(TARGET_LIBC_ENTRYPOINTS
+    # arpa/inet.h entrypoints
+    libc.src.arpa.inet.htonl
+    libc.src.arpa.inet.htons
+    libc.src.arpa.inet.inet_addr
+    libc.src.arpa.inet.inet_aton
+    libc.src.arpa.inet.ntohl
+    libc.src.arpa.inet.ntohs
+
     # ctype.h entrypoints
     libc.src.ctype.isalnum
     libc.src.ctype.isalpha
@@ -1192,14 +1200,6 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.dirent.opendir
     libc.src.dirent.readdir
 
-    # arpa/inet.h entrypoints
-    libc.src.arpa.inet.htonl
-    libc.src.arpa.inet.htons
-    libc.src.arpa.inet.inet_addr
-    libc.src.arpa.inet.inet_aton
-    libc.src.arpa.inet.ntohl
-    libc.src.arpa.inet.ntohs
-
     # pthread.h entrypoints
     libc.src.pthread.pthread_atfork
     libc.src.pthread.pthread_attr_destroy
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index a941d63f7d216..c2111d81fa578 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -77,6 +77,15 @@ add_proxy_header_library(
     libc.include.fenv
 )
 
+add_proxy_header_library(
+  netinet_in_macros
+  HDRS
+    netinet_in_macros.h
+  FULL_BUILD_DEPENDS
+    libc.include.netinet_in
+    libc.include.llvm-libc-macros.netinet_in_macros
+)
+
 add_proxy_header_library(
   pthread_macros
   HDRS
diff --git a/libc/hdr/netinet_in_macros.h b/libc/hdr/netinet_in_macros.h
new file mode 100644
index 0000000000000..bbb67283bcacb
--- /dev/null
+++ b/libc/hdr/netinet_in_macros.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of macros from netinet/in.h.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_NETINET_IN_MACROS_H
+#define LLVM_LIBC_HDR_NETINET_IN_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/netinet-in-macros.h"
+
+#else // Overlay mode
+
+#include <netinet/in.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_NETINET_IN_MACROS_H
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index a511944547d8a..dfe2c851f915b 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -420,6 +420,24 @@ add_proxy_header_library(
     libc.include.sys_socket
 )
 
+add_proxy_header_library(
+  struct_in_addr
+  HDRS
+    struct_in_addr.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_in_addr
+    libc.include.arpa_inet
+)
+
+add_proxy_header_library(
+  in_addr_t
+  HDRS
+    in_addr_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.in_addr_t
+    libc.include.arpa_inet
+)
+
 add_proxy_header_library(
   struct_sockaddr
   HDRS
diff --git a/libc/hdr/types/in_addr_t.h b/libc/hdr/types/in_addr_t.h
new file mode 100644
index 0000000000000..e2b48603ad06b
--- /dev/null
+++ b/libc/hdr/types/in_addr_t.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for in_addr_t.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_IN_ADDR_T_H
+#define LLVM_LIBC_HDR_TYPES_IN_ADDR_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/in_addr_t.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_IN_ADDR_T_H
diff --git a/libc/hdr/types/struct_in_addr.h b/libc/hdr/types/struct_in_addr.h
new file mode 100644
index 0000000000000..563ce6693be3d
--- /dev/null
+++ b/libc/hdr/types/struct_in_addr.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct in_addr.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IN_ADDR_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IN_ADDR_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_in_addr.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IN_ADDR_H
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 4ca42ddc4f870..97e9a91e7003e 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_subdirectory(__support)
 
+add_subdirectory(arpa)
 add_subdirectory(complex)
 add_subdirectory(ctype)
 add_subdirectory(dlfcn)
@@ -38,7 +39,6 @@ if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
 
-add_subdirectory(arpa)
 add_subdirectory(assert)
 add_subdirectory(compiler)
 add_subdirectory(locale)
diff --git a/libc/src/arpa/inet/CMakeLists.txt b/libc/src/arpa/inet/CMakeLists.txt
index 7b421c30e07fa..c4019dd4bbd29 100644
--- a/libc/src/arpa/inet/CMakeLists.txt
+++ b/libc/src/arpa/inet/CMakeLists.txt
@@ -30,7 +30,7 @@ add_entrypoint_object(
     inet_aton.h
   DEPENDS
     libc.include.arpa_inet
-    libc.include.llvm-libc-types.struct_in_addr
+    libc.hdr.types.struct_in_addr
     libc.src.__support.common
     libc.src.__support.str_to_integer
 )
@@ -43,9 +43,9 @@ add_entrypoint_object(
     inet_addr.h
   DEPENDS
     libc.include.arpa_inet
-    libc.include.llvm-libc-macros.netinet_in_macros
-    libc.include.llvm-libc-types.struct_in_addr
-    libc.include.llvm-libc-types.in_addr_t
+    libc.hdr.netinet_in_macros
+    libc.hdr.types.struct_in_addr
+    libc.hdr.types.in_addr_t
     libc.src.__support.common
     libc.src.arpa.inet.inet_aton
 )
diff --git a/libc/src/arpa/inet/inet_addr.cpp b/libc/src/arpa/inet/inet_addr.cpp
index 00a4a5ad22ecd..95be59118a935 100644
--- a/libc/src/arpa/inet/inet_addr.cpp
+++ b/libc/src/arpa/inet/inet_addr.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/arpa/inet/inet_addr.h"
-#include "include/llvm-libc-macros/netinet-in-macros.h"
-#include "include/llvm-libc-types/in_addr_t.h"
-#include "include/llvm-libc-types/struct_in_addr.h"
+#include "hdr/types/in_addr_t.h"
+#include "hdr/types/struct_in_addr.h"
+#include "hdr/netinet_in_macros.h"
 #include "src/__support/common.h"
 #include "src/arpa/inet/inet_aton.h"
 
diff --git a/libc/src/arpa/inet/inet_addr.h b/libc/src/arpa/inet/inet_addr.h
index 66f1ae80dd5a0..8e2251fa6ccea 100644
--- a/libc/src/arpa/inet/inet_addr.h
+++ b/libc/src/arpa/inet/inet_addr.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_ARPA_INET_INET_ADDR_H
 #define LLVM_LIBC_SRC_ARPA_INET_INET_ADDR_H
 
-#include "include/llvm-libc-types/in_addr_t.h"
+#include "hdr/types/in_addr_t.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/arpa/inet/inet_aton.h b/libc/src/arpa/inet/inet_aton.h
index 5d97ad5547016..31e9cee33504a 100644
--- a/libc/src/arpa/inet/inet_aton.h
+++ b/libc/src/arpa/inet/inet_aton.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_ARPA_INET_INET_ATON_H
 #define LLVM_LIBC_SRC_ARPA_INET_INET_ATON_H
 
-#include "include/llvm-libc-types/struct_in_addr.h"
+#include "hdr/types/struct_in_addr.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index b877c7455fc34..e80c02b418967 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -58,6 +58,7 @@ function(add_fp_unittest name)
 endfunction(add_fp_unittest)
 
 add_subdirectory(__support)
+add_subdirectory(arpa)
 add_subdirectory(complex)
 add_subdirectory(ctype)
 add_subdirectory(errno)
@@ -97,7 +98,6 @@ if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
 
-add_subdirectory(arpa)
 add_subdirectory(assert)
 add_subdirectory(compiler)
 add_subdirectory(dirent)



More information about the libc-commits mailing list